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" ) );
51 mGenericManager->setMimeTypeFilter( QStringList() << QLatin1String(
"text/calendar" ) );
52 mGenericManager->setCapabilityFilter( QStringList() << QLatin1String(
"Resource" ) );
57 delete mGenericManager;
65 i18n(
"Add Calendar Folder..." ) );
67 i18n(
"Add a new calendar folder to the currently selected calendar folder." ) );
68 mGenericManager->setContextText(
70 i18nc(
"@title:window",
"New Calendar Folder" ) );
72 mGenericManager->setContextText(
74 ki18n(
"Could not create calendar folder: %1" ) );
76 mGenericManager->setContextText(
78 i18n(
"Calendar folder creation failed" ) );
83 ki18np(
"Copy Calendar Folder",
"Copy %1 Calendar Folders" ) );
85 i18n(
"Copy the selected calendar folders to the clipboard." ) );
89 ki18np(
"Delete Calendar Folder",
"Delete %1 Calendar Folders" ) );
91 i18n(
"Delete the selected calendar folders from the calendar." ) );
92 mGenericManager->setContextText(
94 ki18np(
"Do you really want to delete this calendar folder and all its sub-folders?",
95 "Do you really want to delete %1 calendar folders and all their sub-folders?" ) );
97 mGenericManager->setContextText(
99 ki18ncp(
"@title:window",
"Delete calendar folder?",
"Delete calendar folders?" ) );
101 mGenericManager->setContextText(
103 ki18n(
"Could not delete calendar folder: %1" ) );
105 mGenericManager->setContextText(
107 i18n(
"Calendar folder deletion failed" ) );
112 ki18np(
"Update Calendar Folder",
"Update %1 Calendar Folders" ) );
114 i18n(
"Update the content of the selected calendar folders." ) );
119 ki18np(
"Cut Calendar Folder",
"Cut %1 Calendar Folders" ) );
121 i18n(
"Cut the selected calendar folders from the calendar." ) );
125 i18n(
"Folder Properties..." ) );
127 i18n(
"Open a dialog to edit the properties of the selected calendar folder." ) );
128 mGenericManager->setContextText(
130 ki18nc(
"@title:window",
"Properties of Calendar Folder %1" ) );
134 ki18np(
"Copy Event",
"Copy %1 Events" ) );
136 i18n(
"Copy the selected events to the clipboard." ) );
141 ki18np(
"Delete Event",
"Delete %1 Events" ) );
143 i18n(
"Delete the selected events from the calendar." ) );
144 mGenericManager->setContextText(
146 ki18np(
"Do you really want to delete the selected event?",
147 "Do you really want to delete %1 events?" ) );
149 mGenericManager->setContextText(
151 ki18ncp(
"@title:window",
"Delete Event?",
"Delete Events?" ) );
153 mGenericManager->setContextText(
155 ki18n(
"Could not delete event: %1" ) );
157 mGenericManager->setContextText(
159 i18n(
"Event deletion failed" ) );
164 ki18np(
"Cut Event",
"Cut %1 Events" ) );
166 i18n(
"Cut the selected events from the calendar." ) );
170 i18n(
"Add &Calendar..." ) );
172 i18n(
"Add a new calendar<p>"
173 "You will be presented with a dialog where you can select "
174 "the type of the calendar that shall be added.</p>" ) );
175 mGenericManager->setContextText(
177 i18nc(
"@title:window",
"Add Calendar" ) );
179 mGenericManager->setContextText(
181 ki18n(
"Could not create calendar: %1" ) );
183 mGenericManager->setContextText(
185 i18n(
"Calendar creation failed" ) );
191 ki18np(
"&Delete Calendar",
"&Delete %1 Calendars" ) );
193 i18n(
"Delete the selected calendars<p>"
194 "The currently selected calendars will be deleted, "
195 "along with all the events, todos and journals they contain.</p>" ) );
196 mGenericManager->setContextText(
198 ki18np(
"Do you really want to delete this calendar?",
199 "Do you really want to delete %1 calendars?" ) );
201 mGenericManager->setContextText(
203 ki18ncp(
"@title:window",
"Delete Calendar?",
"Delete Calendars?" ) );
208 i18n(
"Calendar Properties..." ) );
210 i18n(
"Open a dialog to edit properties of the selected calendar." ) );
215 ki18np(
"Update Calendar",
"Update %1 Calendars" ) );
217 i18n(
"Updates the content of all folders of the selected calendars." ) );
221 i18n(
"&Copy to Calendar" ) );
223 i18n(
"Copy the selected event to a different calendar." ) );
227 i18n(
"&Move to Calendar" ) );
229 i18n(
"Move the selected event to a different calendar." ) );
232 mGenericManager->setContextText(
234 ki18n(
"Could not paste event: %1" ) );
236 mGenericManager->setContextText(
238 i18n(
"Paste failed" ) );
244 void updateGenericAllActions()
287 static bool hasWritableCollection(
const QModelIndex &index,
const QString &mimeType )
298 const QAbstractItemModel *model = index.model();
303 for (
int row = 0; row < model->rowCount( index ); ++row ) {
304 if ( hasWritableCollection( model->index( row, 0, index ), mimeType ) ) {
312 bool hasWritableCollection(
const QString &mimeType )
const
314 if ( !mCollectionSelectionModel ) {
318 const QAbstractItemModel *collectionModel = mCollectionSelectionModel->model();
319 for (
int row = 0; row < collectionModel->rowCount(); ++row ) {
320 if ( hasWritableCollection( collectionModel->index( row, 0, QModelIndex() ), mimeType ) ) {
330 if ( !mItemSelectionModel ) {
335 const int itemCount = mItemSelectionModel->selectedRows().count();
336 if ( itemCount == 1 ) {
337 const QModelIndex index = mItemSelectionModel->selectedRows().first();
338 if ( index.isValid() ) {
340 if ( mimeType == KCalCore::Event::eventMimeType() ) {
343 ki18np(
"Copy Event",
"Copy %1 Events" ) );
353 ki18np(
"Delete Event",
"Delete %1 Events" ) );
357 ki18np(
"Cut Event",
"Cut %1 Events" ) );
368 }
else if ( mimeType == KCalCore::Todo::todoMimeType() ) {
371 ki18np(
"Copy To-do",
"Copy %1 To-dos" ) );
381 ki18np(
"Delete To-do",
"Delete %1 To-dos" ) );
385 ki18np(
"Cut To-do",
"Cut %1 To-dos" ) );
396 }
else if ( mimeType == KCalCore::Journal::journalMimeType() ) {
399 ki18np(
"Copy Journal",
"Copy %1 Journals" ) );
409 ki18np(
"Delete Journal",
"Delete %1 Journals" ) );
413 ki18np(
"Cut Journal",
"Cut %1 Journals" ) );
440 bool canEditItem =
true;
443 canEditItem = canEditItem && ( itemCount == 1 );
446 const QModelIndexList rows = mItemSelectionModel->selectedRows();
447 if ( rows.count() == 1 ) {
448 const QModelIndex index = rows.first();
450 if ( parentCollection.
isValid() ) {
462 if ( itemCount == 1 ) {
463 const Akonadi::Item item = mGenericManager->selectedItems().first();
472 emit mParent->actionStateUpdated();
475 void slotCreateEvent()
480 void slotCreateTodo()
485 void slotCreateSubTodo()
490 void slotCreateJournal()
495 void slotEditIncidence()
500 KActionCollection *mActionCollection;
501 QWidget *mParentWidget;
503 QItemSelectionModel *mCollectionSelectionModel;
504 QItemSelectionModel *mItemSelectionModel;
505 QHash<StandardCalendarActionManager::Type, KAction*> mActions;
506 QSet<StandardCalendarActionManager::Type> mInterceptedActions;
513 d( new Private( actionCollection, parent, this ) )
524 d->mCollectionSelectionModel = selectionModel;
525 d->mGenericManager->setCollectionSelectionModel( selectionModel );
527 connect( selectionModel->model(), SIGNAL(rowsInserted(QModelIndex,
int,
int)),
528 SLOT(updateActions()) );
529 connect( selectionModel->model(), SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
530 SLOT(updateActions()) );
531 connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
532 SLOT(updateActions()) );
538 d->mItemSelectionModel = selectionModel;
539 d->mGenericManager->setItemSelectionModel( selectionModel );
541 connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
542 SLOT(updateActions()) );
549 if ( d->mActions.contains( type ) ) {
550 return d->mActions.value( type );
556 action =
new KAction( d->mParentWidget );
557 action->setIcon( KIcon( QLatin1String(
"appointment-new" ) ) );
558 action->setText( i18n(
"New E&vent..." ) );
559 action->setWhatsThis( i18n(
"Create a new event" ) );
561 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_event_create" ), action );
562 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateEvent()) );
565 action =
new KAction( d->mParentWidget );
566 action->setIcon( KIcon( QLatin1String(
"task-new" ) ) );
567 action->setText( i18n(
"New &To-do..." ) );
568 action->setWhatsThis( i18n(
"Create a new To-do" ) );
570 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_todo_create" ), action );
571 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateTodo()) );
574 action =
new KAction( d->mParentWidget );
575 action->setIcon( KIcon( QLatin1String(
"new_subtodo" ) ) );
576 action->setText( i18n(
"New Su&b-to-do..." ) );
577 action->setWhatsThis( i18n(
"Create a new Sub-to-do" ) );
579 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_subtodo_create" ), action );
580 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateSubTodo()) );
583 action =
new KAction( d->mParentWidget );
584 action->setIcon( KIcon( QLatin1String(
"journal-new" ) ) );
585 action->setText( i18n(
"New &Journal..." ) );
586 action->setWhatsThis( i18n(
"Create a new Journal" ) );
588 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_journal_create" ), action );
589 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateJournal()) );
592 action =
new KAction( d->mParentWidget );
593 action->setText( i18n(
"&Edit..." ) );
594 action->setWhatsThis( i18n(
"Edit the selected incidence." ) );
596 d->mActionCollection->addAction( QString::fromLatin1(
"akonadi_incidence_edit" ), action );
597 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotEditIncidence()) );
609 KAction *act = d->mGenericManager->action(type);
611 act = d->mGenericManager->createAction( type );
612 d->updateGenericAction(type);
624 d->mGenericManager->createAllActions();
625 d->updateGenericAllActions();
631 if ( d->mActions.contains( type ) ) {
632 return d->mActions.value( type );
640 return d->mGenericManager->action( type );
645 d->mGenericManager->setActionText( type, text );
651 d->mInterceptedActions.insert( type );
653 d->mInterceptedActions.remove( type );
659 d->mGenericManager->interceptAction( type, intercept );
664 return d->mGenericManager->selectedCollections();
669 return d->mGenericManager->selectedItems();
674 d->mGenericManager->setContextText( type, context, text );
679 d->mGenericManager->setContextText( type, context, text );
682 void StandardCalendarActionManager::setCollectionPropertiesPageNames(
const QStringList &names )
684 d->mGenericManager->setCollectionPropertiesPageNames( names );
687 #include "moc_standardcalendaractionmanager.cpp"