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>
32 #include <klocalizedstring.h>
36 #include <QItemSelectionModel>
38 using namespace Akonadi;
40 class StandardCalendarActionManager::Private
44 : mActionCollection(actionCollection),
45 mParentWidget(parentWidget),
46 mCollectionSelectionModel(0),
47 mItemSelectionModel(0),
50 KGlobal::locale()->insertCatalog(QLatin1String(
"libakonadi-calendar"));
54 mGenericManager->setMimeTypeFilter(QStringList() << QLatin1String(
"text/calendar"));
55 mGenericManager->setCapabilityFilter(QStringList() << QLatin1String(
"Resource"));
60 delete mGenericManager;
68 i18n(
"Add Calendar Folder..."));
70 i18n(
"Add a new calendar folder to the currently selected calendar folder."));
71 mGenericManager->setContextText(
73 i18nc(
"@title:window",
"New Calendar Folder"));
75 mGenericManager->setContextText(
77 ki18n(
"Could not create calendar folder: %1"));
79 mGenericManager->setContextText(
81 i18n(
"Calendar folder creation failed"));
86 ki18np(
"Copy Calendar Folder",
"Copy %1 Calendar Folders"));
88 i18n(
"Copy the selected calendar folders to the clipboard."));
92 ki18np(
"Delete Calendar Folder",
"Delete %1 Calendar Folders"));
94 i18n(
"Delete the selected calendar folders from the calendar."));
95 mGenericManager->setContextText(
97 ki18np(
"Do you really want to delete this calendar folder and all its sub-folders?",
98 "Do you really want to delete %1 calendar folders and all their sub-folders?"));
100 mGenericManager->setContextText(
102 ki18ncp(
"@title:window",
"Delete calendar folder?",
"Delete calendar folders?"));
104 mGenericManager->setContextText(
106 ki18n(
"Could not delete calendar folder: %1"));
108 mGenericManager->setContextText(
110 i18n(
"Calendar folder deletion failed"));
115 ki18np(
"Update Calendar Folder",
"Update %1 Calendar Folders"));
117 i18n(
"Update the content of the selected calendar folders."));
122 ki18np(
"Cut Calendar Folder",
"Cut %1 Calendar Folders"));
124 i18n(
"Cut the selected calendar folders from the calendar."));
128 i18n(
"Folder Properties..."));
130 i18n(
"Open a dialog to edit the properties of the selected calendar folder."));
131 mGenericManager->setContextText(
133 ki18nc(
"@title:window",
"Properties of Calendar Folder %1"));
137 ki18np(
"Copy Event",
"Copy %1 Events"));
139 i18n(
"Copy the selected events to the clipboard."));
144 ki18np(
"Delete Event",
"Delete %1 Events"));
146 i18n(
"Delete the selected events from the calendar."));
147 mGenericManager->setContextText(
149 ki18np(
"Do you really want to delete the selected event?",
150 "Do you really want to delete %1 events?"));
152 mGenericManager->setContextText(
154 ki18ncp(
"@title:window",
"Delete Event?",
"Delete Events?"));
156 mGenericManager->setContextText(
158 ki18n(
"Could not delete event: %1"));
160 mGenericManager->setContextText(
162 i18n(
"Event deletion failed"));
167 ki18np(
"Cut Event",
"Cut %1 Events"));
169 i18n(
"Cut the selected events from the calendar."));
173 i18n(
"Add &Calendar..."));
175 i18n(
"Add a new calendar<p>"
176 "You will be presented with a dialog where you can select "
177 "the type of the calendar that shall be added.</p>"));
178 mGenericManager->setContextText(
180 i18nc(
"@title:window",
"Add Calendar"));
182 mGenericManager->setContextText(
184 ki18n(
"Could not create calendar: %1"));
186 mGenericManager->setContextText(
188 i18n(
"Calendar creation failed"));
194 ki18np(
"&Delete Calendar",
"&Delete %1 Calendars"));
196 i18n(
"Delete the selected calendars<p>"
197 "The currently selected calendars will be deleted, "
198 "along with all the events, todos and journals they contain.</p>"));
199 mGenericManager->setContextText(
201 ki18np(
"Do you really want to delete this calendar?",
202 "Do you really want to delete %1 calendars?"));
204 mGenericManager->setContextText(
206 ki18ncp(
"@title:window",
"Delete Calendar?",
"Delete Calendars?"));
211 i18n(
"Calendar Properties..."));
213 i18n(
"Open a dialog to edit properties of the selected calendar."));
218 ki18np(
"Update Calendar",
"Update %1 Calendars"));
220 i18n(
"Updates the content of all folders of the selected calendars."));
224 i18n(
"&Copy to Calendar"));
226 i18n(
"Copy the selected event to a different calendar."));
230 i18n(
"&Move to Calendar"));
232 i18n(
"Move the selected event to a different calendar."));
235 mGenericManager->setContextText(
237 ki18n(
"Could not paste event: %1"));
239 mGenericManager->setContextText(
241 i18n(
"Paste failed"));
247 void updateGenericAllActions()
290 static bool hasWritableCollection(
const QModelIndex &index,
const QString &mimeType)
301 const QAbstractItemModel *model = index.model();
306 for (
int row = 0; row < model->rowCount(index); ++row) {
307 if (hasWritableCollection(model->index(row, 0, index), mimeType)) {
315 bool hasWritableCollection(
const QString &mimeType)
const
317 if (!mCollectionSelectionModel) {
321 const QAbstractItemModel *collectionModel = mCollectionSelectionModel->model();
322 for (
int row = 0; row < collectionModel->rowCount(); ++row) {
323 if (hasWritableCollection(collectionModel->index(row, 0, QModelIndex()), mimeType)) {
333 if (!mItemSelectionModel) {
338 const int itemCount = mItemSelectionModel->selectedRows().count();
339 if (itemCount == 1) {
340 const QModelIndex index = mItemSelectionModel->selectedRows().first();
341 if (index.isValid()) {
343 if (mimeType == KCalCore::Event::eventMimeType()) {
346 ki18np(
"Copy Event",
"Copy %1 Events"));
356 ki18np(
"Delete Event",
"Delete %1 Events"));
360 ki18np(
"Cut Event",
"Cut %1 Events"));
371 }
else if (mimeType == KCalCore::Todo::todoMimeType()) {
374 ki18np(
"Copy To-do",
"Copy %1 To-dos"));
384 ki18np(
"Delete To-do",
"Delete %1 To-dos"));
388 ki18np(
"Cut To-do",
"Cut %1 To-dos"));
399 }
else if (mimeType == KCalCore::Journal::journalMimeType()) {
402 ki18np(
"Copy Journal",
"Copy %1 Journals"));
412 ki18np(
"Delete Journal",
"Delete %1 Journals"));
416 ki18np(
"Cut Journal",
"Cut %1 Journals"));
443 bool canEditItem =
true;
446 canEditItem = canEditItem && (itemCount == 1);
449 const QModelIndexList rows = mItemSelectionModel->selectedRows();
450 if (rows.count() == 1) {
451 const QModelIndex index = rows.first();
453 if (parentCollection.
isValid()) {
465 if (itemCount == 1) {
466 const Akonadi::Item item = mGenericManager->selectedItems().first();
475 emit mParent->actionStateUpdated();
478 void slotCreateEvent()
483 void slotCreateTodo()
488 void slotCreateSubTodo()
493 void slotCreateJournal()
498 void slotEditIncidence()
503 KActionCollection *mActionCollection;
504 QWidget *mParentWidget;
506 QItemSelectionModel *mCollectionSelectionModel;
507 QItemSelectionModel *mItemSelectionModel;
508 QHash<StandardCalendarActionManager::Type, KAction*> mActions;
509 QSet<StandardCalendarActionManager::Type> mInterceptedActions;
516 d(new Private(actionCollection, parent, this))
527 d->mCollectionSelectionModel = selectionModel;
528 d->mGenericManager->setCollectionSelectionModel(selectionModel);
530 connect(selectionModel->model(), SIGNAL(rowsInserted(QModelIndex,
int,
int)),
531 SLOT(updateActions()));
532 connect(selectionModel->model(), SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
533 SLOT(updateActions()));
534 connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
535 SLOT(updateActions()));
541 d->mItemSelectionModel = selectionModel;
542 d->mGenericManager->setItemSelectionModel(selectionModel);
544 connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
545 SLOT(updateActions()));
552 if (d->mActions.contains(type)) {
553 return d->mActions.value(type);
559 action =
new KAction(d->mParentWidget);
560 action->setIcon(KIcon(QLatin1String(
"appointment-new")));
561 action->setText(i18n(
"New E&vent..."));
562 action->setWhatsThis(i18n(
"Create a new event"));
564 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_event_create"), action);
565 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateEvent()));
568 action =
new KAction(d->mParentWidget);
569 action->setIcon(KIcon(QLatin1String(
"task-new")));
570 action->setText(i18n(
"New &To-do..."));
571 action->setWhatsThis(i18n(
"Create a new To-do"));
573 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_todo_create"), action);
574 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateTodo()));
577 action =
new KAction(d->mParentWidget);
578 action->setIcon(KIcon(QLatin1String(
"new_subtodo")));
579 action->setText(i18n(
"New Su&b-to-do..."));
580 action->setWhatsThis(i18n(
"Create a new Sub-to-do"));
582 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_subtodo_create"), action);
583 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateSubTodo()));
586 action =
new KAction(d->mParentWidget);
587 action->setIcon(KIcon(QLatin1String(
"journal-new")));
588 action->setText(i18n(
"New &Journal..."));
589 action->setWhatsThis(i18n(
"Create a new Journal"));
591 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_journal_create"), action);
592 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateJournal()));
595 action =
new KAction(d->mParentWidget);
596 action->setText(i18n(
"&Edit..."));
597 action->setWhatsThis(i18n(
"Edit the selected incidence."));
599 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_incidence_edit"), action);
600 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(slotEditIncidence()));
612 KAction *act = d->mGenericManager->action(type);
614 act = d->mGenericManager->createAction(type);
615 d->updateGenericAction(type);
627 d->mGenericManager->createAllActions();
628 d->updateGenericAllActions();
634 if (d->mActions.contains(type)) {
635 return d->mActions.value(type);
643 return d->mGenericManager->action(type);
648 d->mGenericManager->setActionText(type, text);
654 d->mInterceptedActions.insert(type);
656 d->mInterceptedActions.remove(type);
662 d->mGenericManager->interceptAction(type, intercept);
667 return d->mGenericManager->selectedCollections();
672 return d->mGenericManager->selectedItems();
677 d->mGenericManager->setContextText(type, context, text);
682 d->mGenericManager->setContextText(type, context, text);
685 void StandardCalendarActionManager::setCollectionPropertiesPageNames(
const QStringList &names)
687 d->mGenericManager->setCollectionPropertiesPageNames(names);
690 #include "moc_standardcalendaractionmanager.cpp"