25#include "kspread_plugininsertcalendar.h"
27#include "kspread_insertcalendardialog.h"
29#include "../../kspread_view.h"
30#include "../../kspread_doc.h"
31#include "../../selection.h"
32#include "../../kspread_sheet.h"
34#include <kcalendarsystem.h>
35#include <kcalendarsystemfactory.h>
36#include <tdeaboutdata.h>
37#include <kgenericfactory.h>
39#include <kofficeversion.h>
40#include <tdemessagebox.h>
49typedef KGenericFactory<PluginInsertCalendar> InsertCalendarFactory;
50K_EXPORT_COMPONENT_FACTORY( libkspreadinsertcalendar, InsertCalendarFactory(
"kspreadinsertcalendar"))
53PluginInsertCalendar::PluginInsertCalendar( TQObject *parent, const
char *name, const TQStringList& )
56 this->m_kspreadView = NULL;
59 if (parent->inherits(
"KSpread::View"))
61 this->m_kspreadView = (
View*)parent;
65 kdWarning() <<
"Parent does not inherit View!!!" << endl;
70 kdWarning() <<
"Plugin created without a parent!!!" << endl;
74 this->m_dialog = NULL;
76 (void)
new TDEAction( i18n(
"Insert Calendar..."), TDEShortcut::null(),
77 this, TQ_SLOT( slotShowDialog() ), actionCollection(),
"kspreadinsertcalendar");
80PluginInsertCalendar::~PluginInsertCalendar()
84TDEAboutData* PluginInsertCalendar::createAboutData()
86 TDEAboutData * aboutData =
new TDEAboutData(
87 "kspreadinsertcalendar",
88 I18N_NOOP(
"Insert Calendar"),
89 KOFFICE_VERSION_STRING,
90 I18N_NOOP(
"KSpread Insert Calendar Plugin"),
91 TDEAboutData::License_BSD,
92 I18N_NOOP(
"(c) 2005, The KSpread Team"),
94 aboutData->addAuthor(
"Raphael Langerhorst", 0,
"Raphael.Langerhorst@kdemail.net");
99void PluginInsertCalendar::slotShowDialog()
101 kdDebug() <<
"slotShowDialog..." << endl;
103 if (this->m_dialog == NULL)
105 this->m_dialog =
new InsertCalendarDialog();
109 connect(m_dialog,TQ_SIGNAL(insertCalendar(
const TQDate&,
const TQDate&)),
110 this,TQ_SLOT(slotInsertCalendar(
const TQDate&,
const TQDate&)));
119void PluginInsertCalendar::slotInsertCalendar(
const TQDate &start,
const TQDate &end)
122 kdDebug() <<
"slotInsert... still to be implemented" << endl;
124 Doc* document = m_kspreadView->doc();
128 KMessageBox::error(NULL,i18n(
"Can't insert calendar because no document is set!"),i18n(
"Error"));
134 KMessageBox::error(NULL,i18n(
"End date is before start date! Please make sure that end date comes after start date."),i18n(
"Error"));
138 if (start.daysTo(end) > 3652)
140 KMessageBox::error(NULL,i18n(
"Calendars shouldn't be longer than 10 years. If you really need such long periods you need to split them up."),i18n(
"Error"));
146 if (KMessageBox::No == KMessageBox::warningYesNo(NULL,i18n(
"Start and end dates are equal! Only one day will be inserted, do you want to continue?"),i18n(
"Warning")))
150 if (start.daysTo(end)> 366)
152 if (KMessageBox::No == KMessageBox::warningYesNo(NULL,i18n(
"Creating a calendar for a longer period than a year can take up a lot of space, do you want to continue?"),i18n(
"Warning")))
156 Selection* selection_info = m_kspreadView->selectionInfo();
158 Q_ASSERT(selection_info);
160 TQPoint selection = selection_info->selection().topLeft();
162 Sheet* sheet = m_kspreadView->activeSheet();
175 int sizeY = 4 + (int)(0.5*(
float)(start.daysTo(end)));
177 if (!sheet->areaIsEmpty(TQRect(selection,TQSize(sizeX,sizeY))))
179 if (KMessageBox::No == KMessageBox::warningYesNo(NULL,i18n(
"The area where the calendar is inserted is NOT empty, are you sure you want to continue, overwriting existing data? If you choose No the area that would be required for the desired calendar will be selected so you can see what data would be overwritten."),i18n(
"Warning")))
182 selection_info->initialize(TQRect(selection.x(),selection.y(),sizeX,sizeY));
187 KCalendarSystem* cs = KCalendarSystemFactory::create();
191 document->emitBeginOperation();
193 int row = selection.y();
194 int col = selection.x();
196 sheet->setText(row,colstart,i18n(
"Calendar from %1 to %2").arg(start.toString()).arg(end.toString()));
198 TQDate current(start);
200 bool yearheader =
true;
201 bool monthheader =
true;
202 bool weekheader =
true;
206 while (current <= end)
210 if (cs->dayOfWeek(current)==1)
216 if (cs->day(current)==1)
219 col=colstart + (cs->dayOfWeek(current)-1)*2;
222 if (cs->month(current)==1)
231 kdDebug() <<
"inserting year " + TQString::number(current.year()) << endl;
232 sheet->setText(row,colstart+6,cs->yearString(current,
false));
239 kdDebug() <<
"inserting month " + TQString::number(current.month()) << endl;
240 sheet->setText(row,colstart+6,cs->monthName(current,
false));
243 sheet->setText(row,colstart,i18n(
"week"));
244 for (
int i=1; i<8; i++)
246 sheet->setText(row,colstart+(i-1)*2+1,cs->weekDayName(i));
253 sheet->setText(row,colstart,TQString::number(cs->weekNumber(current)));
258 if (cs->day(current)==1)
260 col=colstart + (cs->dayOfWeek(current)-1)*2 + 1;
264 sheet->setText(row,col,TQString::number(cs->day(current)));
267 TQDate next = current.addDays(1);
268 current.setYMD(next.year(),next.month(),next.day());
273 document->emitEndOperation();
275 kdDebug() <<
"inserting calendar completed" << endl;
280#include "kspread_plugininsertcalendar.moc"
The View class displays a KSpread document.