30 #include "korganizer/korganizerinterface.h"
32 #include <Akonadi/Contact/ContactSearchJob>
34 #include <KCal/Calendar>
35 #include <KCal/CalHelper>
36 #include <KCal/IncidenceFormatter>
38 #include <KHolidays/Holidays>
40 #include <KontactInterface/Core>
43 #include <KConfigGroup>
44 #include <KIconLoader>
47 #include <KSystemTimeZones>
52 #include <QVBoxLayout>
79 bool operator<(
const SDEntry &entry )
const
81 return daysTo < entry.daysTo;
86 : KontactInterface::Summary( parent ), mPlugin( plugin ), mCalendar( 0 )
88 mLayout =
new QVBoxLayout(
this );
89 mLayout->setSpacing( 3 );
90 mLayout->setMargin( 3 );
92 QWidget *header = createHeader(
this,
"view-pim-summary", i18n(
"Planner" ) );
93 mLayout->addWidget( header );
100 connect( mCalendar, SIGNAL(calendarChanged()), SLOT(updateView()) );
101 connect( mPlugin->core(), SIGNAL(dayChanged(QDate)), SLOT(updateView()) );
109 KConfig config(
"plannerrc" );
112 KConfigGroup group = config.group(
"General" );
113 mShowRecurrence = group.readEntry(
"ShowRecurrence",
true );
114 mShowReminder = group.readEntry(
"ShowReminder",
true );
115 mUnderline = group.readEntry(
"underlineLink",
true );
116 mTodo = group.readEntry(
"ShowTodo",
true );
117 mSd = group.readEntry(
"ShowSd",
true );
120 group = config.group(
"Calendar" );
121 mCustomDays = group.readEntry(
"DaysToShow", 1 );
124 group = config.group(
"Hide" );
125 mHideCompleted = group.readEntry(
"Completed",
true );
126 mHideOpenEnded = group.readEntry(
"OpenEnded",
false );
127 mHideInProgress = group.readEntry(
"InProgress",
false );
128 mHideOverdue = group.readEntry(
"Overdue",
false );
129 mHideNotStarted = group.readEntry(
"NotStarted",
false );
132 group = config.group(
"SpecialDates" );
134 mBirthdayConList = group.readEntry(
"BirthdayConList",
true );
136 mAnniversariesConList = group.readEntry(
"AnniversariesConList",
true );
137 mHolidaysCal = group.readEntry(
"HolidaysCal",
true );
138 mSpecialOccasionsCal = group.readEntry(
"SpecialOccasionsCal",
true );
141 group = config.group(
"Groupware" );
142 mShowMyEventsOnly = group.readEntry(
"ShowMyEventsOnly",
false );
143 mShowMyTodosOnly = group.readEntry(
"ShowMyTodosOnly",
false );
148 void Planner::updateView()
150 while ( !mLabels.isEmpty() ) {
151 delete mLabels.takeFirst();
154 KIconLoader loader(
"kdepim" );
160 QDate currentDate = QDate::currentDate();
162 for ( dt = currentDate;
163 dt <= currentDate.addDays( mCustomDays - 1 );
164 dt = dt.addDays( 1 ) ) {
174 if ( !mEvents.empty() || ( !mTodos.empty() && mTodo ) || ( !mDates.empty() && mSd ) ) {
177 bool makeBold =
false;
181 QDate sD = QDate( dt.year(), dt.month(), dt.day() );
182 if ( ( sD.month() == currentDate.month() ) && ( sD.day() == currentDate.day() ) ) {
183 datestr = i18nc(
"today",
"Today" );
185 }
else if ( ( sD.month() == currentDate.addDays( 1 ).month() ) &&
186 ( sD.day() == currentDate.addDays( 1 ).day() ) ) {
187 datestr = i18nc(
"tomorrow",
"Tomorrow" );
189 datestr = KGlobal::locale()->formatDate( sD );
192 label =
new QLabel( datestr,
this );
193 label->setAlignment( Qt::AlignLeft | Qt::AlignTop );
195 QFont font = label->font();
196 font.setBold(
true );
197 font.setItalic(
true );
198 label->setFont( font );
200 QFont font = label->font();
201 font.setItalic(
true );
202 label->setFont( font );
205 mLayout->addWidget( label );
206 mLabels.append( label );
209 QVBoxLayout *gridLayout =
new QVBoxLayout();
210 mPlannerGrid =
new QGridLayout();
211 gridLayout->addItem( mPlannerGrid );
213 mLayout->addLayout( gridLayout );
215 if ( !mDates.empty() && mSd ) {
216 counter = showSd( counter, dt );
218 if ( !mTodos.empty() && mTodo ) {
219 counter = showTodos( counter, dt );
221 if ( !mEvents.empty() ) {
222 counter = showEvents( counter, dt );
229 i18np(
"No appointments pending within the next day",
230 "No appointments pending within the next %1 days", mCustomDays ),
this );
231 noEvents->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
232 mLayout->addWidget( noEvents, 0, 0 );
233 mLabels.append( noEvents );
236 Q_FOREACH ( label, mLabels ) {
241 void Planner::initTodoList(
const QDate &
date )
243 mTodos.setAutoDelete(
true );
245 mTodos.setAutoDelete(
false );
246 QDate currentDate = QDate::currentDate();
248 Q_FOREACH ( Todo *todo, mCalendar->todos() ) {
250 if ( mShowMyTodosOnly && !CalHelper::isMyCalendarIncidence( mCalendar, todo ) ) {
255 if ( !mHideOverdue && overdue( todo ) && date != currentDate ) {
258 if ( mHideOverdue && overdue( todo ) ) {
262 if ( !mHideInProgress && inProgress( todo ) && date != currentDate ) {
265 if ( mHideInProgress && inProgress( todo ) ) {
269 if ( !mHideCompleted && completed( todo ) && date != currentDate ) {
272 if ( mHideCompleted && completed( todo ) ) {
276 if ( !mHideOpenEnded && openEnded( todo ) && date != currentDate ) {
279 if ( mHideOpenEnded && openEnded( todo ) ) {
283 if ( !mHideNotStarted && notStarted( todo ) && date != currentDate ) {
286 if ( mHideNotStarted && notStarted( todo ) ) {
289 if ( !overdue( todo ) && !inProgress( todo ) && !completed( todo ) && !openEnded( todo ) &&
290 !notStarted( todo ) && todo->hasDueDate() && todo->dtDue().date() !=
date ) {
293 mTodos.append( todo );
296 if ( !mTodos.isEmpty() ) {
297 mTodos = Calendar::sortTodos( &mTodos,
299 SortDirectionAscending );
300 mTodos = Calendar::sortTodos( &mTodos,
302 SortDirectionAscending );
303 mTodos = Calendar::sortTodos( &mTodos,
305 SortDirectionAscending );
309 int Planner::showTodos(
int counter,
const QDate &date )
311 KIconLoader loader(
"kdepim" );
313 if ( !mTodos.empty() ) {
317 Q_FOREACH ( Todo *todo, mTodos ) {
318 QString stateText = initStateText ( todo, date );
320 mPlannerGrid->setColumnMinimumWidth( 0, 40 );
322 QPixmap todoPm = loader.loadIcon(
"view-pim-tasks", KIconLoader::Small );
324 label->setPixmap( todoPm );
325 label->setMaximumWidth( label->minimumSizeHint().width() );
326 mPlannerGrid->addWidget( label, counter, 1 );
327 mLabels.append( label );
329 mPlannerGrid->setColumnMinimumWidth( 2, 15 );
331 QString percent = QString::number( todo->percentComplete() ) +
'%';
332 KUrlLabel *urlLabel =
new KUrlLabel(
this );
333 urlLabel->setText( percent );
334 urlLabel->setUrl( todo->uid() );
335 if ( stateText == i18nc(
"to-do is overdue",
"overdue" ) ) {
336 urlLabel->setText(
"<font color = red >" + percent +
"</font>" );
338 urlLabel->setAlignment( Qt::AlignHCenter | Qt::AlignTop );
340 urlLabel->setUnderline(
false );
342 urlLabel->setWordWrap(
true );
343 urlLabel->setMaximumWidth( urlLabel->minimumSizeHint().width() );
344 mPlannerGrid->addWidget( urlLabel, counter, 3 );
345 mLabels.append( urlLabel );
347 connect( urlLabel, SIGNAL(rightClickedUrl(QString)),
348 this, SLOT(changePercentage(QString)) );
350 QString
string = todo->summary();
351 if ( todo->relatedTo() ) {
352 string = todo->relatedTo()->summary() +
':' + todo->summary();
355 mPlannerGrid->setColumnMinimumWidth( 4, 15 );
357 KUrlLabel *urlLabel2 =
new KUrlLabel(
this );
358 urlLabel2->setText(
string );
359 urlLabel2->setUrl( todo->uid() );
360 urlLabel2->installEventFilter(
this );
361 urlLabel2->setAlignment( Qt::AlignLeft | Qt::AlignTop );
362 urlLabel2->setWordWrap(
true );
363 if ( stateText == i18nc(
"to-do is overdue",
"overdue" ) ) {
364 urlLabel2->setText(
"<font color = red >" +
string +
"</font>" );
367 urlLabel2->setUnderline(
false );
369 mPlannerGrid->addWidget( urlLabel2, counter, 5 );
370 mLabels.append( urlLabel2 );
372 connect( urlLabel2, SIGNAL(leftClickedUrl(QString)),
373 this, SLOT(viewTodo(QString)) );
374 connect( urlLabel2, SIGNAL(rightClickedUrl(QString)),
375 this, SLOT(todoPopupMenu(QString)) );
377 QString tipText( IncidenceFormatter::toolTipStr(
378 mCalendar, todo, date,
true, KSystemTimeZones::local() ) );
379 if ( !tipText.isEmpty() ) {
380 urlLabel2->setToolTip( tipText );
383 mPlannerGrid->setColumnMinimumWidth( 6, 15 );
385 label =
new QLabel( stateText,
this );
386 if ( stateText == i18nc(
"to-do is overdue",
"overdue" ) ) {
387 label->setText(
"<font color = red >" + stateText +
" </font>" );
389 label->setAlignment( Qt::AlignLeft | Qt::AlignTop );
390 label->setMaximumWidth( label->minimumSizeHint().width() );
391 mPlannerGrid->addWidget( label, counter, 7 );
392 mLabels.append( label );
394 mPlannerGrid->setColumnMinimumWidth( 8, 15 );
396 if ( mShowReminder ) {
398 if ( todo->hasEnabledAlarms() ) {
399 alarm = loader.loadIcon(
"task-reminder", KIconLoader::Small );
401 label =
new QLabel(
this );
402 label->setPixmap( alarm );
403 label->setMaximumWidth( label->minimumSizeHint().width() );
404 mPlannerGrid->addWidget( label, counter, 9 );
405 mLabels.append( label );
408 mPlannerGrid->setColumnMinimumWidth( 10, 15 );
410 if ( mShowRecurrence ) {
412 if ( todo->hasEnabledAlarms() ) {
413 recur = loader.loadIcon(
"task-recurring", KIconLoader::Small );
415 label =
new QLabel(
this );
416 label->setPixmap( recur );
417 label->setMaximumWidth( label->minimumSizeHint().width() );
418 mPlannerGrid->addWidget( label, counter, 11 );
419 mLabels.append( label );
427 void Planner::initEventList(
const QDate &date )
429 mEvents.setAutoDelete(
true );
431 mEvents.setAutoDelete(
false );
433 Q_FOREACH ( Event *ev, mCalendar->events( date, mCalendar->timeSpec() ) ) {
435 if ( mShowMyEventsOnly && !CalHelper::isMyCalendarIncidence( mCalendar, ev ) ) {
438 mEvents.append( ev );
442 mEvents = Calendar::sortEvents( &mEvents,
444 SortDirectionAscending );
446 mEvents = Calendar::sortEvents( &mEvents,
448 SortDirectionAscending );
451 int Planner::showEvents(
int counter,
const QDate &date )
453 KIconLoader loader(
"kdepim" );
455 if ( !mEvents.empty() ) {
457 QDate currentDate = QDate::currentDate();
464 Q_FOREACH ( Event *ev, mEvents ) {
468 if ( ev->isMultiDay() ) {
469 QDate d = ev->dtStart().date();
470 if ( d < currentDate ) {
473 while ( d < ev->dtEnd().
date() ) {
484 if ( ev->isMultiDay() && ev->allDay() && dayof != 1 ) {
488 mPlannerGrid->setColumnMinimumWidth( 0, 40 );
491 QPixmap re = loader.loadIcon(
"view-calendar-day", KIconLoader::Small );
492 label =
new QLabel(
this );
493 label->setPixmap( re );
494 label->setMaximumWidth( label->minimumSizeHint().width() );
495 label->setAlignment( Qt::AlignTop );
496 mPlannerGrid->addWidget( label, counter, 1 );
497 mLabels.append( label );
499 mPlannerGrid->setColumnMinimumWidth( 2, 15 );
503 KDateTime::Spec spec = KSystemTimeZones::local();
504 if ( ev->isMultiDay() && ev->allDay() && dayof == 1 && span > 1 ) {
505 KDateTime ksD( sD.addDays( span - 1 ), spec );
506 datestr = IncidenceFormatter::dateToString( ev->dtStart(),
false, spec ) +
508 IncidenceFormatter::dateToString( ksD,
false, spec );
509 label =
new QLabel( datestr,
this );
510 label->setAlignment( Qt::AlignLeft | Qt::AlignTop );
511 mPlannerGrid->addWidget( label, counter, 3 );
512 mLabels.append( label );
516 if ( !ev->allDay() ) {
517 QTime sST = ev->dtStart().toTimeSpec( spec ).time();
518 QTime sET = ev->dtEnd().toTimeSpec( spec ).time();
519 if ( ev->isMultiDay() ) {
520 if ( ev->dtStart().date() <
date ) {
523 if ( ev->dtEnd().date() >
date ) {
524 sET = QTime( 23, 59 );
528 datestr = i18nc(
"Time from - to",
"%1 - %2",
529 KGlobal::locale()->formatTime( sST ),
530 KGlobal::locale()->formatTime( sET ) );
531 label =
new QLabel( datestr,
this );
532 label->setAlignment( Qt::AlignLeft | Qt::AlignTop );
533 label->setMaximumWidth( label->minimumSizeHint().width() );
534 mPlannerGrid->addWidget( label, counter, 3 );
535 mLabels.append( label );
538 mPlannerGrid->setColumnMinimumWidth( 4, 15 );
541 QString newtext = ev->summary();
542 if ( ev->isMultiDay() && !ev->allDay() ) {
543 newtext.append( QString(
" (%1/%2)" ).arg( dayof ).arg( span ) );
545 KUrlLabel *urlLabel =
new KUrlLabel(
this );
546 urlLabel->setText( newtext );
547 urlLabel->setUrl( ev->uid() );
548 urlLabel->installEventFilter(
this );
549 urlLabel->setAlignment( Qt::AlignLeft | Qt::AlignTop );
550 urlLabel->setWordWrap(
true );
552 urlLabel->setUnderline(
false );
554 mPlannerGrid->addWidget( urlLabel, counter, 5 );
555 mLabels.append( urlLabel );
557 mPlannerGrid->setColumnMinimumWidth( 6, 15 );
558 mPlannerGrid->setColumnMinimumWidth( 7, 15 );
559 mPlannerGrid->setColumnMinimumWidth( 8, 15 );
562 if ( mShowReminder ) {
564 if ( ev->hasEnabledAlarms () ) {
565 alarm = loader.loadIcon(
"task-reminder", KIconLoader::Small );
567 label =
new QLabel(
this );
568 label->setPixmap( alarm );
569 label->setMaximumWidth( label->minimumSizeHint().width() );
570 label->setAlignment( Qt::AlignTop );
571 mPlannerGrid->addWidget( label, counter, 9 );
572 mLabels.append( label );
574 mPlannerGrid->setColumnMinimumWidth( 9, 15 );
577 mPlannerGrid->setColumnMinimumWidth( 10, 15 );
580 if ( mShowRecurrence ) {
582 if ( ev->recurs() ) {
583 recur = loader.loadIcon(
"appointment-recurring", KIconLoader::Small );
585 label =
new QLabel(
this );
586 label->setPixmap( recur );
587 label->setMaximumWidth( label->minimumSizeHint().width() );
588 label->setAlignment( Qt::AlignTop );
589 mPlannerGrid->addWidget( label, counter, 11 );
590 mLabels.append( label );
593 connect( urlLabel, SIGNAL(leftClickedUrl(QString)),
594 this, SLOT(viewEvent(QString)) );
595 connect( urlLabel, SIGNAL(rightClickedUrl(QString)),
596 this, SLOT(eventPopupMenu(QString)) );
598 QString tipText( IncidenceFormatter::toolTipStr(
599 mCalendar, ev, date,
true, KSystemTimeZones::local() ) );
600 if ( !tipText.isEmpty() ) {
601 urlLabel->setToolTip( tipText );
610 bool Planner::initHolidays()
612 KConfig _hconfig(
"korganizerrc" );
613 KConfigGroup hconfig( &_hconfig,
"Time & Date" );
614 QString location = hconfig.readEntry(
"Holidays" );
615 if ( !location.isEmpty() ) {
616 mHolidays =
new KHolidays::HolidayRegion( location );
622 void Planner::initSdList(
const QDate &date )
626 Akonadi::ContactSearchJob *job =
new Akonadi::ContactSearchJob(
this );
629 Q_FOREACH (
const Addressee &addressee, job->contacts() ) {
630 const QDate birthday = addressee.birthday().date();
631 if ( birthday.isValid() && mBirthdayConList &&
632 birthday.day() == date.day() && birthday.month() == date.month() ) {
636 entry.date = birthday;
637 entry.addressee = addressee;
638 entry.yearsOld = QDate::currentDate().year() - birthday.year();
639 mDates.append( entry );
642 QString anniversaryAsString = addressee.custom(
"KADDRESSBOOK",
"X-Anniversary" );
643 if ( !anniversaryAsString.isEmpty() ) {
644 QDate anniversary = QDate::fromString( anniversaryAsString, Qt::ISODate );
645 if ( anniversary.isValid() && mAnniversariesConList &&
646 anniversary.day() == date.day() && anniversary.month() == date.month() ) {
650 entry.date = anniversary;
651 entry.addressee = addressee;
652 entry.yearsOld = QDate::currentDate().year() - anniversary.year();
653 mDates.append( entry );
658 if ( mHolidaysCal ) {
659 if ( initHolidays() ) {
660 Q_FOREACH (
const KHolidays::Holiday &holiday, mHolidays->holidays( date ) ) {
661 if ( !mSpecialOccasionsCal && holiday.dayType() != KHolidays::Holiday::NonWorkday ) {
666 entry.category = ( holiday.dayType() == KHolidays::Holiday::NonWorkday )?
669 entry.summary = holiday.text();
670 mDates.append( entry );
676 int Planner::showSd(
int counter,
const QDate &date )
678 KIconLoader loader(
"kdepim" );
682 QPixmap birthdayIcon =
683 loader.loadIcon(
"view-calendar-birthday", KIconLoader::Small );
684 QPixmap anniversaryIcon =
685 loader.loadIcon(
"view-calendar-wedding-anniversary", KIconLoader::Small );
686 QPixmap holidayIcon =
687 loader.loadIcon(
"view-calendar-holiday", KIconLoader::Small );
688 QPixmap specialOccasionsIcon =
689 loader.loadIcon(
"favorites", KIconLoader::Small );
692 Q_FOREACH (
const SDEntry &entry, mDates ) {
693 mPlannerGrid->setColumnMinimumWidth( 0, 40 );
697 switch ( entry.category ) {
699 label->setPixmap( birthdayIcon );
702 label->setPixmap( anniversaryIcon );
705 label->setPixmap( holidayIcon );
708 label->setPixmap( specialOccasionsIcon );
711 label->setMaximumWidth( label->minimumSizeHint().width() );
712 label->setAlignment( Qt::AlignTop );
713 mPlannerGrid->addWidget( label, counter, 1 );
714 mLabels.append( label );
716 mPlannerGrid->setColumnMinimumWidth( 2, 15 );
719 switch ( entry.category ) {
721 catName = i18n(
"Birthday" );
724 catName = i18n(
"Anniversary" );
727 catName = i18n(
"Holiday" );
730 catName = i18n(
"Special Occasion" );
733 label =
new QLabel(
this );
734 label->setText( catName );
735 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
736 mPlannerGrid->addWidget( label, counter, 3 );
737 mLabels.append( label );
739 mPlannerGrid->setColumnMinimumWidth( 4, 15 );
742 KUrlLabel *urlLabel =
new KUrlLabel(
this );
743 urlLabel->installEventFilter(
this );
744 urlLabel->setUrl( entry.addressee.uid() );
745 urlLabel->setText( entry.addressee.realName() );
746 urlLabel->setTextFormat( Qt::RichText );
747 urlLabel->setWordWrap(
true );
749 urlLabel->setUnderline(
false );
751 mPlannerGrid->addWidget( urlLabel, counter, 5 );
752 mLabels.append( urlLabel );
754 label =
new QLabel(
this );
755 label->setText( entry.summary );
756 label->setTextFormat( Qt::RichText );
757 mPlannerGrid->addWidget( label, counter, 5 );
758 mLabels.append( label );
759 if ( !entry.desc.isEmpty() ) {
760 label->setToolTip( entry.desc );
764 mPlannerGrid->setColumnMinimumWidth( 6, 15 );
767 label =
new QLabel(
this );
768 if ( entry.yearsOld <= 0 ) {
769 label->setText(
"" );
771 label->setText( i18np(
"one year",
"%1 years", entry.yearsOld ) );
773 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
774 mPlannerGrid->addWidget( label, counter, 7 );
775 mLabels.append( label );
783 void Planner::viewEvent(
const QString &uid )
785 mPlugin->core()->selectPlugin(
"kontact_korganizerplugin" );
786 OrgKdeKorganizerKorganizerInterface korganizer(
787 "org.kde.korganizer",
"/Korganizer", QDBusConnection::sessionBus() );
788 korganizer.editIncidence( uid );
791 void Planner::removeEvent(
const QString &uid )
793 mPlugin->core()->selectPlugin(
"kontact_korganizerplugin" );
794 OrgKdeKorganizerKorganizerInterface korganizer(
795 "org.kde.korganizer",
"/Korganizer", QDBusConnection::sessionBus() );
796 korganizer.deleteIncidence( uid,
false );
799 void Planner::eventPopupMenu(
const QString &uid )
802 QAction *editIt = popup.addAction( i18n(
"&Edit Appointment..." ) );
803 QAction *delIt = popup.addAction( i18n(
"&Delete Appointment" ) );
804 delIt->setIcon( KIconLoader::global()->loadIcon(
"edit-delete", KIconLoader::Small ) );
806 const QAction *selectedAction = popup.exec( QCursor::pos() );
807 if ( selectedAction == editIt ) {
809 }
else if ( selectedAction == delIt ) {
816 if ( obj->inherits(
"KUrlLabel" ) ) {
817 KUrlLabel *label =
static_cast<KUrlLabel*
>( obj );
818 if ( e->type() == QEvent::Enter ) {
819 emit message( i18n(
"Edit Appointment: \"%1\"", label->text() ) );
821 if ( e->type() == QEvent::Leave ) {
822 emit message( QString::null );
826 return KontactInterface::Summary::eventFilter( obj, e );
829 QString Planner::initStateText(
const Todo *todo,
const QDate &date )
831 QDate currentDate = QDate::currentDate();
834 if ( todo->hasDueDate() && !todo->isCompleted() &&
835 todo->dtDue().date() < currentDate ) {
836 stateText = i18nc(
"to-do is overdue",
"overdue" );
840 if ( todo->hasStartDate() && todo->hasDueDate() &&
841 todo->dtStart().date() < date &&
842 date < todo->dtDue().date() ) {
843 stateText = i18nc(
"work on to-do is in progress",
"in progress" );
847 if ( todo->hasStartDate() && todo->dtStart().date() ==
date ) {
848 stateText = i18nc(
"to-do starts today",
"starts today" );
852 if ( todo->hasDueDate() && todo->dtDue().date() == date && todo->dtDue().date() == currentDate ) {
853 stateText = i18nc(
"to-do due today",
"due today" );
855 if ( todo->isCompleted() ) {
856 stateText = i18nc(
"to-do is completed",
"completed" );
861 void Planner::todoPopupMenu(
const QString &uid )
864 QAction *editIt = popup.addAction( i18n(
"&Edit To-do..." ) );
865 QAction *delIt = popup.addAction( i18n(
"&Delete To-do" ) );
866 delIt->setIcon( KIconLoader::global()->loadIcon(
"edit-delete", KIconLoader::Small ) );
868 Todo *todo = mCalendar->todo( uid );
869 if ( !todo->isCompleted() ) {
870 doneIt = popup.addAction( i18n(
"&Mark To-do Completed" ) );
871 doneIt->setIcon( KIconLoader::global()->loadIcon(
"task-complete", KIconLoader::Small ) );
875 const QAction *selectedAction = popup.exec( QCursor::pos() );
876 if ( selectedAction == editIt ) {
878 }
else if ( selectedAction == delIt ) {
880 }
else if ( doneIt && selectedAction == doneIt ) {
885 void Planner::viewTodo(
const QString &uid )
887 mPlugin->core()->selectPlugin(
"kontact_todoplugin" );
888 OrgKdeKorganizerKorganizerInterface korganizer(
889 "org.kde.korganizer",
"/Korganizer", QDBusConnection::sessionBus() );
890 korganizer.editIncidence( uid );
893 void Planner::removeTodo(
const QString &uid )
895 mPlugin->core()->selectPlugin(
"kontact_todoplugin" );
896 OrgKdeKorganizerKorganizerInterface korganizer(
897 "org.kde.korganizer",
"/Korganizer", QDBusConnection::sessionBus() );
898 korganizer.deleteIncidence( uid,
false );
901 void Planner::completeTodo(
const QString &uid )
903 Todo *todo = mCalendar->todo( uid );
904 if ( !todo->isReadOnly() ) {
905 todo->setCompleted( KDateTime::currentLocalDateTime() );
911 void Planner::changePercentage(
const QString &uid )
914 QAction *per00 = popup.addAction( i18n(
"%1%", 0 ) );
915 QAction *per10 = popup.addAction( i18n(
"%1%", 10 ) );
916 QAction *per20 = popup.addAction( i18n(
"%1%", 20 ) );
917 QAction *per30 = popup.addAction( i18n(
"%1%", 30 ) );
918 QAction *per40 = popup.addAction( i18n(
"%1%", 40 ) );
919 QAction *per50 = popup.addAction( i18n(
"%1%", 50 ) );
920 QAction *per60 = popup.addAction( i18n(
"%1%", 60 ) );
921 QAction *per70 = popup.addAction( i18n(
"%1%", 70 ) );
922 QAction *per80 = popup.addAction( i18n(
"%1%", 80 ) );
923 QAction *per90 = popup.addAction( i18n(
"%1%", 90 ) );
924 QAction *per100= popup.addAction( i18n(
"%1%", 100 ) );
926 Todo *todo = mCalendar->todo( uid );
927 if ( !todo->isReadOnly() && mCalendar->beginChange( todo ) ) {
928 const QAction *selectedAction = popup.exec( QCursor::pos() );
929 if ( selectedAction == per00 ) {
930 todo->setPercentComplete( 0 );
931 }
else if ( selectedAction == per10 ) {
932 todo->setPercentComplete( 10 );
933 }
else if ( selectedAction == per20 ) {
934 todo->setPercentComplete( 20 );
935 }
else if ( selectedAction == per30 ) {
936 todo->setPercentComplete( 30 );
937 }
else if ( selectedAction == per40 ) {
938 todo->setPercentComplete( 40 );
939 }
else if ( selectedAction == per50 ) {
940 todo->setPercentComplete( 50 );
941 }
else if ( selectedAction == per60 ) {
942 todo->setPercentComplete( 60 );
943 }
else if ( selectedAction == per70 ) {
944 todo->setPercentComplete( 70 );
945 }
else if ( selectedAction == per80 ) {
946 todo->setPercentComplete( 80 );
947 }
else if ( selectedAction == per90 ) {
948 todo->setPercentComplete( 90 );
949 }
else if ( selectedAction == per100 ) {
950 todo->setCompleted(
true );
952 mCalendar->endChange( todo );
959 if ( obj->inherits(
"KUrlLabel" ) ) {
960 KUrlLabel *label =
static_cast<KUrlLabel*
>( obj );
961 if ( e->type() == QEvent::Enter ) {
962 emit message( i18n(
"Edit To-do: \"%1\"", label->text() ) );
964 if ( e->type() == QEvent::Leave ) {
965 emit message( QString() );
969 return KontactInterface::Summary::eventFilter( obj, e );
974 return QStringList(
"kcmplanner.desktop" );
977 bool Planner::overdue( Todo *todo )
979 if ( todo->hasDueDate() && !todo->isCompleted() &&
980 todo->dtDue().date() < QDate::currentDate() ) {
986 bool Planner::completed( Todo *todo )
988 return todo->isCompleted();
991 bool Planner::openEnded( Todo *todo )
993 if ( !todo->hasDueDate() && !todo->isCompleted() ) {
999 bool Planner::inProgress( Todo *todo )
1001 if ( overdue( todo ) ) {
1005 if ( todo->percentComplete() > 0 ) {
1009 QDate currDate = QDate::currentDate();
1010 if ( todo->hasStartDate() && todo->hasDueDate() &&
1011 todo->dtStart().date() < currDate &&
1012 currDate < todo->dtDue().date() ) {
1019 bool Planner::notStarted( Todo *todo )
1021 if ( todo->percentComplete() > 0 ) {
1025 if ( !todo->hasStartDate() ) {
1029 if ( todo->dtStart().date() >= QDate::currentDate() ) {
1035 #include "planner.moc"
QStringList configModules() const
Planner(KontactInterface::Plugin *plugin, QWidget *parent)
virtual bool todoEventFilter(QObject *obj, QEvent *e)
static StdCalendar * self()
virtual bool eventFilter(QObject *obj, QEvent *e)