22 #include "standardcalendaractionmanager.h"
24 #include <akonadi/entitytreemodel.h>
27 #include <kactioncollection.h>
28 #include <kcalcore/event.h>
29 #include <kcalcore/journal.h>
30 #include <kcalcore/todo.h>
33 #include <QItemSelectionModel>
35 using namespace Akonadi;
37 class StandardCalendarActionManager::Private
41 : mActionCollection( actionCollection ),
42 mParentWidget( parentWidget ),
43 mCollectionSelectionModel( 0 ),
44 mItemSelectionModel( 0 ),
47 KGlobal::locale()->insertCatalog( QLatin1String(
"libakonadi-calendar" ) );
52 mGenericManager->setMimeTypeFilter( QStringList() << QLatin1String(
"text/calendar" ) );
53 mGenericManager->setCapabilityFilter( QStringList() << QLatin1String(
"Resource" ) );
58 delete mGenericManager;
66 i18n(
"Add Calendar Folder..." ) );
68 i18n(
"Add a new calendar folder to the currently selected calendar folder." ) );
69 mGenericManager->setContextText(
71 i18nc(
"@title:window",
"New Calendar Folder" ) );
73 mGenericManager->setContextText(
75 ki18n(
"Could not create calendar folder: %1" ) );
77 mGenericManager->setContextText(
79 i18n(
"Calendar folder creation failed" ) );
84 ki18np(
"Copy Calendar Folder",
"Copy %1 Calendar Folders" ) );
86 i18n(
"Copy the selected calendar folders to the clipboard." ) );
90 ki18np(
"Delete Calendar Folder",
"Delete %1 Calendar Folders" ) );
92 i18n(
"Delete the selected calendar folders from the calendar." ) );
93 mGenericManager->setContextText(
95 ki18np(
"Do you really want to delete this calendar folder and all its sub-folders?",
96 "Do you really want to delete %1 calendar folders and all their sub-folders?" ) );
98 mGenericManager->setContextText(
100 ki18ncp(
"@title:window",
"Delete calendar folder?",
"Delete calendar folders?" ) );
102 mGenericManager->setContextText(
104 ki18n(
"Could not delete calendar folder: %1" ) );
106 mGenericManager->setContextText(
108 i18n(
"Calendar folder deletion failed" ) );
113 ki18np(
"Update Calendar Folder",
"Update %1 Calendar Folders" ) );
115 i18n(
"Update the content of the selected calendar folders." ) );
120 ki18np(
"Cut Calendar Folder",
"Cut %1 Calendar Folders" ) );
122 i18n(
"Cut the selected calendar folders from the calendar." ) );
126 i18n(
"Folder Properties..." ) );
128 i18n(
"Open a dialog to edit the properties of the selected calendar folder." ) );
129 mGenericManager->setContextText(
131 ki18nc(
"@title:window",
"Properties of Calendar Folder %1" ) );
135 ki18np(
"Copy Event",
"Copy %1 Events" ) );
137 i18n(
"Copy the selected events to the clipboard." ) );
142 ki18np(
"Delete Event",
"Delete %1 Events" ) );
144 i18n(
"Delete the selected events from the calendar." ) );
145 mGenericManager->setContextText(
147 ki18np(
"Do you really want to delete the selected event?",
148 "Do you really want to delete %1 events?" ) );
150 mGenericManager->setContextText(
152 ki18ncp(
"@title:window",
"Delete Event?",
"Delete Events?" ) );
154 mGenericManager->setContextText(
156 ki18n(
"Could not delete event: %1" ) );
158 mGenericManager->setContextText(
160 i18n(
"Event deletion failed" ) );
165 ki18np(
"Cut Event",
"Cut %1 Events" ) );
167 i18n(
"Cut the selected events from the calendar." ) );
171 i18n(
"Add &Calendar..." ) );
173 i18n(
"Add a new calendar<p>"
174 "You will be presented with a dialog where you can select "
175 "the type of the calendar that shall be added.</p>" ) );
176 mGenericManager->setContextText(
178 i18nc(
"@title:window",
"Add Calendar" ) );
180 mGenericManager->setContextText(
182 ki18n(
"Could not create calendar: %1" ) );
184 mGenericManager->setContextText(
186 i18n(
"Calendar creation failed" ) );
192 ki18np(
"&Delete Calendar",
"&Delete %1 Calendars" ) );
194 i18n(
"Delete the selected calendars<p>"
195 "The currently selected calendars will be deleted, "
196 "along with all the events, todos and journals they contain.</p>" ) );
197 mGenericManager->setContextText(
199 ki18np(
"Do you really want to delete this calendar?",
200 "Do you really want to delete %1 calendars?" ) );
202 mGenericManager->setContextText(
204 ki18ncp(
"@title:window",
"Delete Calendar?",
"Delete Calendars?" ) );
209 i18n(
"Calendar Properties..." ) );
211 i18n(
"Open a dialog to edit properties of the selected calendar." ) );
216 ki18np(
"Update Calendar",
"Update %1 Calendars" ) );
218 i18n(
"Updates the content of all folders of the selected calendars." ) );
222 i18n(
"&Copy to Calendar" ) );
224 i18n(
"Copy the selected event to a different calendar." ) );
228 i18n(
"&Move to Calendar" ) );
230 i18n(
"Move the selected event to a different calendar." ) );
233 mGenericManager->setContextText(
235 ki18n(
"Could not paste event: %1" ) );
237 mGenericManager->setContextText(
239 i18n(
"Paste failed" ) );
245 void updateGenericAllActions()
288 static bool hasWritableCollection(
const QModelIndex &index,
const QString &mimeType )
299 const QAbstractItemModel *model = index.model();
304 for (
int row = 0; row < model->rowCount( index ); ++row ) {
305 if ( hasWritableCollection( model->index( row, 0, index ), mimeType ) ) {
313 bool hasWritableCollection(
const QString &mimeType )
const
315 if ( !mCollectionSelectionModel ) {
319 const QAbstractItemModel *collectionModel = mCollectionSelectionModel->model();
320 for (
int row = 0; row < collectionModel->rowCount(); ++row ) {
321 if ( hasWritableCollection( collectionModel->index( row, 0, QModelIndex() ), mimeType ) ) {
331 if ( !mItemSelectionModel ) {
336 const int itemCount = mItemSelectionModel->selectedRows().count();
337 if ( itemCount == 1 ) {
338 const QModelIndex index = mItemSelectionModel->selectedRows().first();
339 if ( index.isValid() ) {
341 if ( mimeType == KCalCore::Event::eventMimeType() ) {
344 ki18np(
"Copy Event",
"Copy %1 Events" ) );
354 ki18np(
"Delete Event",
"Delete %1 Events" ) );
358 ki18np(
"Cut Event",
"Cut %1 Events" ) );
369 }
else if ( mimeType == KCalCore::Todo::todoMimeType() ) {
372 ki18np(
"Copy To-do",
"Copy %1 To-dos" ) );
382 ki18np(
"Delete To-do",
"Delete %1 To-dos" ) );
386 ki18np(
"Cut To-do",
"Cut %1 To-dos" ) );
397 }
else if ( mimeType == KCalCore::Journal::journalMimeType() ) {
400 ki18np(
"Copy Journal",
"Copy %1 Journals" ) );
410 ki18np(
"Delete Journal",
"Delete %1 Journals" ) );
414 ki18np(
"Cut Journal",
"Cut %1 Journals" ) );
441 bool canEditItem =
true;
444 canEditItem = canEditItem && ( itemCount == 1 );
447 const QModelIndexList rows = mItemSelectionModel->selectedRows();
448 if ( rows.count() == 1 ) {
449 const QModelIndex index = rows.first();
451 if ( parentCollection.
isValid() ) {
463 if ( itemCount == 1 ) {
464 const Akonadi::Item item = mGenericManager->selectedItems().first();
473 emit mParent->actionStateUpdated();
476 void slotCreateEvent()
481 void slotCreateTodo()
486 void slotCreateSubTodo()
491 void slotCreateJournal()
496 void slotEditIncidence()
501 KActionCollection *mActionCollection;
502 QWidget *mParentWidget;
504 QItemSelectionModel *mCollectionSelectionModel;
505 QItemSelectionModel *mItemSelectionModel;
506 QHash<StandardCalendarActionManager::Type, KAction*> mActions;
507 QSet<StandardCalendarActionManager::Type> mInterceptedActions;
514 d( new Private( actionCollection, parent, this ) )
525 d->mCollectionSelectionModel = selectionModel;
526 d->mGenericManager->setCollectionSelectionModel( selectionModel );
528 connect( selectionModel->model(), SIGNAL(rowsInserted(QModelIndex,
int,
int)),
529 SLOT(updateActions()) );
530 connect( selectionModel->model(), SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
531 SLOT(updateActions()) );
532 connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
533 SLOT(updateActions()) );
539 d->mItemSelectionModel = selectionModel;
540 d->mGenericManager->setItemSelectionModel( selectionModel );
542 connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
543 SLOT(updateActions()) );
550 if ( d->mActions.contains( type ) ) {
551 return d->mActions.value( type );
557 action =
new KAction( d->mParentWidget );
558 action->setIcon( KIcon( QLatin1String(
"appointment-new" ) ) );
559 action->setText( i18n(
"New E&vent..." ) );
560 action->setWhatsThis( i18n(
"Create a new event" ) );
562 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_event_create" ), action );
563 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateEvent()) );
566 action =
new KAction( d->mParentWidget );
567 action->setIcon( KIcon( QLatin1String(
"task-new" ) ) );
568 action->setText( i18n(
"New &To-do..." ) );
569 action->setWhatsThis( i18n(
"Create a new To-do" ) );
571 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_todo_create" ), action );
572 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateTodo()) );
575 action =
new KAction( d->mParentWidget );
576 action->setIcon( KIcon( QLatin1String(
"new_subtodo" ) ) );
577 action->setText( i18n(
"New Su&b-to-do..." ) );
578 action->setWhatsThis( i18n(
"Create a new Sub-to-do" ) );
580 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_subtodo_create" ), action );
581 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateSubTodo()) );
584 action =
new KAction( d->mParentWidget );
585 action->setIcon( KIcon( QLatin1String(
"journal-new" ) ) );
586 action->setText( i18n(
"New &Journal..." ) );
587 action->setWhatsThis( i18n(
"Create a new Journal" ) );
589 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_journal_create" ), action );
590 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateJournal()) );
593 action =
new KAction( d->mParentWidget );
594 action->setText( i18n(
"&Edit..." ) );
595 action->setWhatsThis( i18n(
"Edit the selected incidence." ) );
597 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_incidence_edit" ), action );
598 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotEditIncidence()) );
610 KAction *act = d->mGenericManager->action(type);
612 act = d->mGenericManager->createAction( type );
613 d->updateGenericAction(type);
625 d->mGenericManager->createAllActions();
626 d->updateGenericAllActions();
632 if ( d->mActions.contains( type ) ) {
633 return d->mActions.value( type );
641 return d->mGenericManager->action( type );
646 d->mGenericManager->setActionText( type, text );
652 d->mInterceptedActions.insert( type );
654 d->mInterceptedActions.remove( type );
660 d->mGenericManager->interceptAction( type, intercept );
665 return d->mGenericManager->selectedCollections();
670 return d->mGenericManager->selectedItems();
675 d->mGenericManager->setContextText( type, context, text );
680 d->mGenericManager->setContextText( type, context, text );
683 void StandardCalendarActionManager::setCollectionPropertiesPageNames(
const QStringList &names )
685 d->mGenericManager->setCollectionPropertiesPageNames( names );
688 #include "standardcalendaractionmanager.moc"