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>
40class StandardCalendarActionManager::Private
44 : mActionCollection(actionCollection),
45 mParentWidget(parentWidget),
46 mCollectionSelectionModel(0),
47 mItemSelectionModel(0),
50 KGlobal::locale()->insertCatalog(QLatin1String(
"libakonadi-calendar"));
52 mParent->connect(mGenericManager, SIGNAL(actionStateUpdated()),
53 mParent, SIGNAL(actionStateUpdated()));
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(
72 StandardActionManager::CreateCollection, StandardActionManager::DialogTitle,
73 i18nc(
"@title:window",
"New Calendar Folder"));
75 mGenericManager->setContextText(
76 StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageText,
77 ki18n(
"Could not create calendar folder: %1"));
79 mGenericManager->setContextText(
80 StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageTitle,
81 i18n(
"Calendar folder creation failed"));
83 QLatin1String(
"inode/directory") <<
84 QLatin1String(
"application/x-vnd.akonadi.calendar.todo") <<
85 QLatin1String(
"application/x-vnd.akonadi.calendar.event") <<
86 QLatin1String(
"application/x-vnd.akonadi.calendar.journal") );
91 ki18np(
"Copy Calendar Folder",
"Copy %1 Calendar Folders"));
93 i18n(
"Copy the selected calendar folders to the clipboard."));
97 ki18np(
"Delete Calendar Folder",
"Delete %1 Calendar Folders"));
99 i18n(
"Delete the selected calendar folders from the calendar."));
100 mGenericManager->setContextText(
101 StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxText,
102 ki18np(
"Do you really want to delete this calendar folder and all its sub-folders?",
103 "Do you really want to delete %1 calendar folders and all their sub-folders?"));
105 mGenericManager->setContextText(
106 StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxTitle,
107 ki18ncp(
"@title:window",
"Delete calendar folder?",
"Delete calendar folders?"));
109 mGenericManager->setContextText(
110 StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageText,
111 ki18n(
"Could not delete calendar folder: %1"));
113 mGenericManager->setContextText(
114 StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageTitle,
115 i18n(
"Calendar folder deletion failed"));
120 ki18np(
"Update Calendar Folder",
"Update %1 Calendar Folders"));
122 i18n(
"Update the content of the selected calendar folders."));
127 ki18np(
"Cut Calendar Folder",
"Cut %1 Calendar Folders"));
129 i18n(
"Cut the selected calendar folders from the calendar."));
133 i18n(
"Folder Properties..."));
135 i18n(
"Open a dialog to edit the properties of the selected calendar folder."));
136 mGenericManager->setContextText(
137 StandardActionManager::CollectionProperties, StandardActionManager::DialogTitle,
138 ki18nc(
"@title:window",
"Properties of Calendar Folder %1"));
142 ki18np(
"Copy Event",
"Copy %1 Events"));
144 i18n(
"Copy the selected events to the clipboard."));
149 ki18np(
"Delete Event",
"Delete %1 Events"));
151 i18n(
"Delete the selected events from the calendar."));
152 mGenericManager->setContextText(
153 StandardActionManager::DeleteItems, StandardActionManager::MessageBoxText,
154 ki18np(
"Do you really want to delete the selected event?",
155 "Do you really want to delete %1 events?"));
157 mGenericManager->setContextText(
158 StandardActionManager::DeleteItems, StandardActionManager::MessageBoxTitle,
159 ki18ncp(
"@title:window",
"Delete Event?",
"Delete Events?"));
161 mGenericManager->setContextText(
162 StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageText,
163 ki18n(
"Could not delete event: %1"));
165 mGenericManager->setContextText(
166 StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageTitle,
167 i18n(
"Event deletion failed"));
172 ki18np(
"Cut Event",
"Cut %1 Events"));
174 i18n(
"Cut the selected events from the calendar."));
178 i18n(
"Add &Calendar..."));
180 i18n(
"Add a new calendar<p>"
181 "You will be presented with a dialog where you can select "
182 "the type of the calendar that shall be added.</p>"));
183 mGenericManager->setContextText(
184 StandardActionManager::CreateResource, StandardActionManager::DialogTitle,
185 i18nc(
"@title:window",
"Add Calendar"));
187 mGenericManager->setContextText(
188 StandardActionManager::CreateResource, StandardActionManager::ErrorMessageText,
189 ki18n(
"Could not create calendar: %1"));
191 mGenericManager->setContextText(
192 StandardActionManager::CreateResource, StandardActionManager::ErrorMessageTitle,
193 i18n(
"Calendar creation failed"));
199 ki18np(
"&Delete Calendar",
"&Delete %1 Calendars"));
201 i18n(
"Delete the selected calendars<p>"
202 "The currently selected calendars will be deleted, "
203 "along with all the events, todos and journals they contain.</p>"));
204 mGenericManager->setContextText(
205 StandardActionManager::DeleteResources, StandardActionManager::MessageBoxText,
206 ki18np(
"Do you really want to delete this calendar?",
207 "Do you really want to delete %1 calendars?"));
209 mGenericManager->setContextText(
210 StandardActionManager::DeleteResources, StandardActionManager::MessageBoxTitle,
211 ki18ncp(
"@title:window",
"Delete Calendar?",
"Delete Calendars?"));
216 i18n(
"Calendar Properties..."));
218 i18n(
"Open a dialog to edit properties of the selected calendar."));
223 ki18np(
"Update Calendar",
"Update %1 Calendars"));
225 i18n(
"Updates the content of all folders of the selected calendars."));
229 i18n(
"&Copy to Calendar"));
231 i18n(
"Copy the selected event to a different calendar."));
235 i18n(
"&Move to Calendar"));
237 i18n(
"Move the selected event to a different calendar."));
239 case StandardActionManager::Paste:
240 mGenericManager->setContextText(
241 StandardActionManager::Paste, StandardActionManager::ErrorMessageText,
242 ki18n(
"Could not paste event: %1"));
244 mGenericManager->setContextText(
245 StandardActionManager::Paste, StandardActionManager::ErrorMessageTitle,
246 i18n(
"Paste failed"));
252 void updateGenericAllActions()
254 updateGenericAction(StandardActionManager::CreateCollection);
255 updateGenericAction(StandardActionManager::CopyCollections);
256 updateGenericAction(StandardActionManager::DeleteCollections);
257 updateGenericAction(StandardActionManager::SynchronizeCollections);
258 updateGenericAction(StandardActionManager::CollectionProperties);
259 updateGenericAction(StandardActionManager::CopyItems);
260 updateGenericAction(StandardActionManager::Paste);
261 updateGenericAction(StandardActionManager::DeleteItems);
262 updateGenericAction(StandardActionManager::ManageLocalSubscriptions);
263 updateGenericAction(StandardActionManager::AddToFavoriteCollections);
264 updateGenericAction(StandardActionManager::RemoveFromFavoriteCollections);
265 updateGenericAction(StandardActionManager::RenameFavoriteCollection);
266 updateGenericAction(StandardActionManager::CopyCollectionToMenu);
267 updateGenericAction(StandardActionManager::CopyItemToMenu);
268 updateGenericAction(StandardActionManager::MoveItemToMenu);
269 updateGenericAction(StandardActionManager::MoveCollectionToMenu);
270 updateGenericAction(StandardActionManager::CutItems);
271 updateGenericAction(StandardActionManager::CutCollections);
272 updateGenericAction(StandardActionManager::CreateResource);
273 updateGenericAction(StandardActionManager::DeleteResources);
274 updateGenericAction(StandardActionManager::ResourceProperties);
275 updateGenericAction(StandardActionManager::SynchronizeResources);
276 updateGenericAction(StandardActionManager::ToggleWorkOffline);
277 updateGenericAction(StandardActionManager::CopyCollectionToDialog);
278 updateGenericAction(StandardActionManager::MoveCollectionToDialog);
279 updateGenericAction(StandardActionManager::CopyItemToDialog);
280 updateGenericAction(StandardActionManager::MoveItemToDialog);
281 updateGenericAction(StandardActionManager::SynchronizeCollectionsRecursive);
282 updateGenericAction(StandardActionManager::MoveCollectionsToTrash);
283 updateGenericAction(StandardActionManager::MoveItemsToTrash);
284 updateGenericAction(StandardActionManager::RestoreCollectionsFromTrash);
285 updateGenericAction(StandardActionManager::RestoreItemsFromTrash);
286 updateGenericAction(StandardActionManager::MoveToTrashRestoreCollection);
287 updateGenericAction(StandardActionManager::MoveToTrashRestoreCollectionAlternative);
288 updateGenericAction(StandardActionManager::MoveToTrashRestoreItem);
289 updateGenericAction(StandardActionManager::MoveToTrashRestoreItemAlternative);
290 updateGenericAction(StandardActionManager::SynchronizeFavoriteCollections);
294 static bool hasWritableCollection(
const QModelIndex &index,
const QString &mimeType)
298 if (collection.isValid()) {
299 if (collection.contentMimeTypes().contains(mimeType) &&
305 const QAbstractItemModel *model = index.model();
310 for (
int row = 0; row < model->rowCount(index); ++row) {
311 if (hasWritableCollection(model->index(row, 0, index), mimeType)) {
319 bool hasWritableCollection(
const QString &mimeType)
const
321 if (!mCollectionSelectionModel) {
325 const QAbstractItemModel *collectionModel = mCollectionSelectionModel->model();
326 for (
int row = 0; row < collectionModel->rowCount(); ++row) {
327 if (hasWritableCollection(collectionModel->index(row, 0, QModelIndex()), mimeType)) {
337 if (!mItemSelectionModel) {
342 const int itemCount = mItemSelectionModel->selectedRows().count();
343 if (itemCount == 1) {
344 const QModelIndex index = mItemSelectionModel->selectedRows().first();
345 if (index.isValid()) {
346 const QString mimeType = index.data(EntityTreeModel::MimeTypeRole).toString();
347 if (mimeType == KCalCore::Event::eventMimeType()) {
350 ki18np(
"Copy Event",
"Copy %1 Events"));
360 ki18np(
"Delete Event",
"Delete %1 Events"));
364 ki18np(
"Cut Event",
"Cut %1 Events"));
372 if (mActions.contains(StandardCalendarActionManager::EditIncidence)) {
373 mActions.value(StandardCalendarActionManager::EditIncidence)->setText(i18n(
"Edit Event..."));
375 }
else if (mimeType == KCalCore::Todo::todoMimeType()) {
378 ki18np(
"Copy To-do",
"Copy %1 To-dos"));
388 ki18np(
"Delete To-do",
"Delete %1 To-dos"));
392 ki18np(
"Cut To-do",
"Cut %1 To-dos"));
400 if (mActions.contains(StandardCalendarActionManager::EditIncidence)) {
401 mActions.value(StandardCalendarActionManager::EditIncidence)->setText(i18n(
"Edit To-do..."));
403 }
else if (mimeType == KCalCore::Journal::journalMimeType()) {
406 ki18np(
"Copy Journal",
"Copy %1 Journals"));
416 ki18np(
"Delete Journal",
"Delete %1 Journals"));
420 ki18np(
"Cut Journal",
"Cut %1 Journals"));
428 if (mActions.contains(StandardCalendarActionManager::EditIncidence)) {
429 mActions.value(StandardCalendarActionManager::EditIncidence)->setText(i18n(
"Edit Journal..."));
436 if (mActions.contains(StandardCalendarActionManager::CreateEvent)) {
437 mActions[ StandardCalendarActionManager::CreateEvent ]->
setEnabled(hasWritableCollection(KCalCore::Event::eventMimeType()));
439 if (mActions.contains(StandardCalendarActionManager::CreateTodo)) {
440 mActions[ StandardCalendarActionManager::CreateTodo ]->setEnabled(hasWritableCollection(KCalCore::Todo::todoMimeType()));
442 if (mActions.contains(StandardCalendarActionManager::CreateJournal)) {
443 mActions[ StandardCalendarActionManager::CreateJournal ]->setEnabled(hasWritableCollection(KCalCore::Journal::journalMimeType()));
446 if (mActions.contains(StandardCalendarActionManager::EditIncidence)) {
447 bool canEditItem =
true;
450 canEditItem = canEditItem && (itemCount == 1);
453 const QModelIndexList rows = mItemSelectionModel->selectedRows();
454 if (rows.count() == 1) {
455 const QModelIndex index = rows.first();
456 const Collection parentCollection = index.data(EntityTreeModel::ParentCollectionRole).value<
Collection>();
457 if (parentCollection.
isValid()) {
458 canEditItem = canEditItem && (parentCollection.
rights() & Collection::CanChangeItem);
462 mActions.value(StandardCalendarActionManager::EditIncidence)->
setEnabled(canEditItem);
465 if (mActions.contains(StandardCalendarActionManager::CreateSubTodo)) {
466 mActions[ StandardCalendarActionManager::CreateSubTodo ]->setEnabled(
false);
469 if (itemCount == 1) {
470 const Akonadi::Item item = mGenericManager->selectedItems().first();
472 if (item.isValid() && item.hasPayload<KCalCore::Todo::Ptr>()) {
473 if (mActions.contains(StandardCalendarActionManager::CreateSubTodo)) {
474 mActions[ StandardCalendarActionManager::CreateSubTodo ]->setEnabled(hasWritableCollection(KCalCore::Todo::todoMimeType()));
479 emit mParent->actionStateUpdated();
482 void slotCreateEvent()
487 void slotCreateTodo()
492 void slotCreateSubTodo()
497 void slotCreateJournal()
502 void slotEditIncidence()
507 KActionCollection *mActionCollection;
508 QWidget *mParentWidget;
510 QItemSelectionModel *mCollectionSelectionModel;
511 QItemSelectionModel *mItemSelectionModel;
512 QHash<StandardCalendarActionManager::Type, KAction*> mActions;
513 QSet<StandardCalendarActionManager::Type> mInterceptedActions;
519 d(new Private(actionCollection, parent, this))
530 d->mCollectionSelectionModel = selectionModel;
531 d->mGenericManager->setCollectionSelectionModel(selectionModel);
533 connect(selectionModel->model(), SIGNAL(rowsInserted(QModelIndex,
int,
int)),
534 SLOT(updateActions()));
535 connect(selectionModel->model(), SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
536 SLOT(updateActions()));
537 connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
538 SLOT(updateActions()));
544 d->mItemSelectionModel = selectionModel;
545 d->mGenericManager->setItemSelectionModel(selectionModel);
547 connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
548 SLOT(updateActions()));
555 if (d->mActions.contains(type)) {
556 return d->mActions.value(type);
562 action =
new KAction(d->mParentWidget);
563 action->setIcon(KIcon(QLatin1String(
"appointment-new")));
564 action->setText(i18n(
"New E&vent..."));
565 action->setWhatsThis(i18n(
"Create a new event"));
567 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_event_create"),
action);
568 connect(
action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateEvent()));
571 action =
new KAction(d->mParentWidget);
572 action->setIcon(KIcon(QLatin1String(
"task-new")));
573 action->setText(i18n(
"New &To-do..."));
574 action->setWhatsThis(i18n(
"Create a new To-do"));
576 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_todo_create"),
action);
577 connect(
action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateTodo()));
580 action =
new KAction(d->mParentWidget);
581 action->setIcon(KIcon(QLatin1String(
"new_subtodo")));
582 action->setText(i18n(
"New Su&b-to-do..."));
583 action->setWhatsThis(i18n(
"Create a new Sub-to-do"));
585 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_subtodo_create"),
action);
586 connect(
action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateSubTodo()));
589 action =
new KAction(d->mParentWidget);
590 action->setIcon(KIcon(QLatin1String(
"journal-new")));
591 action->setText(i18n(
"New &Journal..."));
592 action->setWhatsThis(i18n(
"Create a new Journal"));
594 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_journal_create"),
action);
595 connect(
action, SIGNAL(triggered(
bool)),
this, SLOT(slotCreateJournal()));
598 action =
new KAction(d->mParentWidget);
599 action->setText(i18n(
"&Edit..."));
600 action->setWhatsThis(i18n(
"Edit the selected incidence."));
602 d->mActionCollection->addAction(QString::fromLatin1(
"akonadi_incidence_edit"),
action);
603 connect(
action, SIGNAL(triggered(
bool)),
this, SLOT(slotEditIncidence()));
615 KAction *act = d->mGenericManager->action(type);
617 act = d->mGenericManager->createAction(type);
618 d->updateGenericAction(type);
630 d->mGenericManager->createAllActions();
631 d->updateGenericAllActions();
637 if (d->mActions.contains(type)) {
638 return d->mActions.value(type);
646 return d->mGenericManager->action(type);
651 d->mGenericManager->setActionText(type, text);
657 d->mInterceptedActions.insert(type);
659 d->mInterceptedActions.remove(type);
665 d->mGenericManager->interceptAction(type, intercept);
670 return d->mGenericManager->selectedCollections();
675 return d->mGenericManager->selectedItems();
680 d->mGenericManager->setContextText(type, context, text);
685 d->mGenericManager->setContextText(type, context, text);
688void StandardCalendarActionManager::setCollectionPropertiesPageNames(
const QStringList &names)
690 d->mGenericManager->setCollectionPropertiesPageNames(names);
693#include "moc_standardcalendaractionmanager.cpp"
Represents a collection of PIM items.
Rights rights() const
Returns the rights the user has on the collection.
QList< Collection > List
Describes a list of collections.
void setEnabled(bool enabled)
Sets the collection's enabled state.
@ CanCreateItem
Can create new items in this collection.
@ CollectionRole
The collection.
bool isValid() const
Returns whether the entity is valid.
Manages generic actions for collection and item views.
Type
Describes the supported actions.
@ CreateResource
Creates a new resource.
@ CreateCollection
Creates an collection.
@ SynchronizeResources
Synchronizes the selected resources.
@ DeleteItems
Deletes the selected items.
@ SynchronizeCollections
Synchronizes collections.
@ CopyItemToMenu
Menu allowing to quickly copy an item into a collection.
@ ResourceProperties
Provides the resource properties.
@ CutItems
Cuts the selected items.
@ DeleteCollections
Deletes the selected collections.
@ CutCollections
Cuts the selected collections.
@ MoveItemToMenu
Menu allowing to move item into a collection.
@ CopyCollections
Copies the selected collections.
@ CollectionProperties
Provides collection properties.
@ DeleteResources
Deletes the selected resources.
@ CopyItems
Copies the selected items.
@ MoveItemToDialog
Move an item into a collection, select the target in a dialog.
@ CopyItemToDialog
Copy an item into a collection, select the target in a dialog.
TextContext
Describes the text context that can be customized.
Manages calendar specific actions for collection and item views.
void createAllActions()
Convenience method to create all standard actions.
void interceptAction(Type type, bool intercept=true)
Sets whether the default implementation for the given action type shall be executed when the action i...
KAction * action(Type type) const
Returns the action of the given type, 0 if it has not been created (yet).
void setContextText(StandardActionManager::Type type, StandardActionManager::TextContext context, const QString &text)
Sets the text of the action type for the given context.
~StandardCalendarActionManager()
Destroys the standard calendar action manager.
StandardCalendarActionManager(KActionCollection *actionCollection, QWidget *parent=0)
Creates a new standard calendar action manager.
KAction * createAction(Type type)
Creates the action of the given type and adds it to the action collection specified in the constructo...
Akonadi::Collection::List selectedCollections() const
Returns the list of collections that are currently selected.
void setActionText(StandardActionManager::Type type, const KLocalizedString &text)
Sets the label of the action type to text, which is used during updating the action state and substit...
Akonadi::Item::List selectedItems() const
Returns the list of items that are currently selected.
void setCollectionSelectionModel(QItemSelectionModel *selectionModel)
Sets the collection selection model based on which the collection related actions should operate.
Type
Describes the supported actions.
@ CreateTodo
Creates a new todo.
@ CreateEvent
Creates a new event.
@ CreateJournal
Creates a new journal.
@ EditIncidence
Edit currently selected event/todo/journal.
@ CreateSubTodo
Creates a new sub-todo.
void setItemSelectionModel(QItemSelectionModel *selectionModel)
Sets the item selection model based on which the item related actions should operate.
FreeBusyManager::Singleton.