• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • contact
standardcontactactionmanager.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2009 - 2010 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "standardcontactactionmanager.h"
23
24#include "contacteditordialog.h"
25#include "contactgroupeditordialog.h"
26
27#include <akonadi/entitytreemodel.h>
28#include <akonadi/mimetypechecker.h>
29#include <kabc/addressee.h>
30#include <kabc/contactgroup.h>
31#include <kicon.h>
32#include <kaction.h>
33#include <kactioncollection.h>
34#include <klocalizedstring.h>
35#include <kmessagebox.h>
36
37#include <QtCore/QPointer>
38#include <QItemSelectionModel>
39
40using namespace Akonadi;
41
42class StandardContactActionManager::Private
43{
44 public:
45 Private( KActionCollection *actionCollection, QWidget *parentWidget, StandardContactActionManager *parent )
46 : mActionCollection( actionCollection ), mParentWidget( parentWidget ),
47 mCollectionSelectionModel( 0 ), mItemSelectionModel( 0 ), mParent( parent )
48 {
49 mGenericManager = new StandardActionManager( actionCollection, parentWidget );
50 mParent->connect( mGenericManager, SIGNAL(actionStateUpdated()),
51 mParent, SIGNAL(actionStateUpdated()) );
52
53 mGenericManager->setMimeTypeFilter(
54 QStringList() << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType() );
55
56 mGenericManager->setCapabilityFilter( QStringList() << QLatin1String( "Resource" ) );
57 }
58
59 ~Private()
60 {
61 delete mGenericManager;
62 }
63
64 void updateGenericAllActions()
65 {
66 updateGenericAction(StandardActionManager::CreateCollection);
67 updateGenericAction(StandardActionManager::CopyCollections);
68 updateGenericAction(StandardActionManager::DeleteCollections);
69 updateGenericAction(StandardActionManager::SynchronizeCollections);
70 updateGenericAction(StandardActionManager::CollectionProperties);
71 updateGenericAction(StandardActionManager::CopyItems);
72 updateGenericAction(StandardActionManager::Paste);
73 updateGenericAction(StandardActionManager::DeleteItems);
74 updateGenericAction(StandardActionManager::ManageLocalSubscriptions);
75 updateGenericAction(StandardActionManager::AddToFavoriteCollections);
76 updateGenericAction(StandardActionManager::RemoveFromFavoriteCollections);
77 updateGenericAction(StandardActionManager::RenameFavoriteCollection);
78 updateGenericAction(StandardActionManager::CopyCollectionToMenu);
79 updateGenericAction(StandardActionManager::CopyItemToMenu);
80 updateGenericAction(StandardActionManager::MoveItemToMenu);
81 updateGenericAction(StandardActionManager::MoveCollectionToMenu);
82 updateGenericAction(StandardActionManager::CutItems);
83 updateGenericAction(StandardActionManager::CutCollections);
84 updateGenericAction(StandardActionManager::CreateResource);
85 updateGenericAction(StandardActionManager::DeleteResources);
86 updateGenericAction(StandardActionManager::ResourceProperties);
87 updateGenericAction(StandardActionManager::SynchronizeResources);
88 updateGenericAction(StandardActionManager::ToggleWorkOffline);
89 updateGenericAction(StandardActionManager::CopyCollectionToDialog);
90 updateGenericAction(StandardActionManager::MoveCollectionToDialog);
91 updateGenericAction(StandardActionManager::CopyItemToDialog);
92 updateGenericAction(StandardActionManager::MoveItemToDialog);
93 updateGenericAction(StandardActionManager::SynchronizeCollectionsRecursive);
94 updateGenericAction(StandardActionManager::MoveCollectionsToTrash);
95 updateGenericAction(StandardActionManager::MoveItemsToTrash);
96 updateGenericAction(StandardActionManager::RestoreCollectionsFromTrash);
97 updateGenericAction(StandardActionManager::RestoreItemsFromTrash);
98 updateGenericAction(StandardActionManager::MoveToTrashRestoreCollection);
99 updateGenericAction(StandardActionManager::MoveToTrashRestoreCollectionAlternative);
100 updateGenericAction(StandardActionManager::MoveToTrashRestoreItem);
101 updateGenericAction(StandardActionManager::MoveToTrashRestoreItemAlternative);
102 updateGenericAction(StandardActionManager::SynchronizeFavoriteCollections);
103
104 }
105
106 void updateGenericAction(StandardActionManager::Type type)
107 {
108 switch(type) {
109 case Akonadi::StandardActionManager::CreateCollection:
110 mGenericManager->action( Akonadi::StandardActionManager::CreateCollection )->setText(
111 i18n( "Add Address Book Folder..." ) );
112
113 mGenericManager->action( Akonadi::StandardActionManager::CreateCollection )->setWhatsThis(
114 i18n( "Add a new address book folder to the currently selected address book folder." ) );
115 mGenericManager->setContextText(
116 StandardActionManager::CreateCollection, StandardActionManager::DialogTitle,
117 i18nc( "@title:window", "New Address Book Folder" ) );
118
119 mGenericManager->setContextText(
120 StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageText,
121 ki18n( "Could not create address book folder: %1" ) );
122
123 mGenericManager->setContextText(
124 StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageTitle,
125 i18n( "Address book folder creation failed" ) );
126 mGenericManager->action(Akonadi::StandardActionManager::CreateCollection)->setProperty("ContentMimeTypes", QStringList() <<
127 QLatin1String("application/x-vnd.kde.contactgroup") <<
128 QLatin1String("text/directory") <<
129 QLatin1String("application/x-vnd.kde.contactgroup"));
130
131
132 break;
133 case Akonadi::StandardActionManager::CopyCollections:
134 mGenericManager->setActionText( Akonadi::StandardActionManager::CopyCollections,
135 ki18np( "Copy Address Book Folder",
136 "Copy %1 Address Book Folders" ) );
137 mGenericManager->action( Akonadi::StandardActionManager::CopyCollections )->setWhatsThis(
138 i18n( "Copy the selected address book folders to the clipboard." ) );
139 break;
140 case Akonadi::StandardActionManager::DeleteCollections:
141 mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteCollections,
142 ki18np( "Delete Address Book Folder",
143 "Delete %1 Address Book Folders" ) );
144 mGenericManager->action( Akonadi::StandardActionManager::DeleteCollections )->setWhatsThis(
145 i18n( "Delete the selected address book folders from the address book." ) );
146
147 mGenericManager->setContextText(
148 StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxText,
149 ki18np( "Do you really want to delete this address book folder and all its sub-folders?",
150 "Do you really want to delete %1 address book folders and all their sub-folders?" ) );
151 mGenericManager->setContextText(
152 StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxTitle,
153 ki18ncp( "@title:window", "Delete address book folder?", "Delete address book folders?" ) );
154
155 mGenericManager->setContextText(
156 StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageText,
157 ki18n( "Could not delete address book folder: %1" ) );
158
159 mGenericManager->setContextText(
160 StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageTitle,
161 i18n( "Address book folder deletion failed" ) );
162 break;
163 case Akonadi::StandardActionManager::SynchronizeCollections:
164 mGenericManager->setActionText( Akonadi::StandardActionManager::SynchronizeCollections,
165 ki18np( "Update Address Book Folder",
166 "Update %1 Address Book Folders" ) );
167 mGenericManager->action( Akonadi::StandardActionManager::SynchronizeCollections )->setWhatsThis(
168 i18n( "Update the content of the selected address book folders." ) );
169 break;
170 case Akonadi::StandardActionManager::CutCollections:
171 mGenericManager->setActionText( Akonadi::StandardActionManager::CutCollections,
172 ki18np( "Cut Address Book Folder",
173 "Cut %1 Address Book Folders" ) );
174 mGenericManager->action( Akonadi::StandardActionManager::CutCollections )->setWhatsThis(
175 i18n( "Cut the selected address book folders from the address book." ) );
176 break;
177 case Akonadi::StandardActionManager::CollectionProperties:
178 mGenericManager->action( Akonadi::StandardActionManager::CollectionProperties )->setText(
179 i18n( "Folder Properties..." ) );
180 mGenericManager->action( Akonadi::StandardActionManager::CollectionProperties )->setWhatsThis(
181 i18n( "Open a dialog to edit the properties of the selected address book folder." ) );
182 mGenericManager->setContextText(
183 StandardActionManager::CollectionProperties, StandardActionManager::DialogTitle,
184 ki18nc( "@title:window", "Properties of Address Book Folder %1" ) );
185 break;
186 case Akonadi::StandardActionManager::CopyItems:
187 mGenericManager->setActionText( Akonadi::StandardActionManager::CopyItems,
188 ki18np( "Copy Contact", "Copy %1 Contacts" ) );
189 mGenericManager->action( Akonadi::StandardActionManager::CopyItems )->setWhatsThis(
190 i18n( "Copy the selected contacts to the clipboard." ) );
191 break;
192 case Akonadi::StandardActionManager::DeleteItems:
193 mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteItems,
194 ki18np( "Delete Contact", "Delete %1 Contacts" ) );
195 mGenericManager->action( Akonadi::StandardActionManager::DeleteItems )->setWhatsThis(
196 i18n( "Delete the selected contacts from the address book." ) );
197 mGenericManager->setContextText(
198 StandardActionManager::DeleteItems, StandardActionManager::MessageBoxText,
199 ki18np( "Do you really want to delete the selected contact?",
200 "Do you really want to delete %1 contacts?" ) );
201
202 mGenericManager->setContextText(
203 StandardActionManager::DeleteItems, StandardActionManager::MessageBoxTitle,
204 ki18ncp( "@title:window", "Delete Contact?", "Delete Contacts?" ) );
205
206 mGenericManager->setContextText(
207 StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageText,
208 ki18n( "Could not delete contact: %1" ) );
209
210 mGenericManager->setContextText(
211 StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageTitle,
212 i18n( "Contact deletion failed" ) );
213 break;
214 case Akonadi::StandardActionManager::CutItems:
215 mGenericManager->setActionText( Akonadi::StandardActionManager::CutItems,
216 ki18np( "Cut Contact", "Cut %1 Contacts" ) );
217 mGenericManager->action( Akonadi::StandardActionManager::CutItems )->setWhatsThis(
218 i18n( "Cut the selected contacts from the address book." ) );
219 break;
220 case Akonadi::StandardActionManager::CreateResource:
221 mGenericManager->action( Akonadi::StandardActionManager::CreateResource )->setText(
222 i18n( "Add &Address Book..." ) );
223 mGenericManager->action( Akonadi::StandardActionManager::CreateResource )->setWhatsThis(
224 i18n( "Add a new address book<p>"
225 "You will be presented with a dialog where you can select "
226 "the type of the address book that shall be added.</p>" ) );
227 mGenericManager->setContextText(
228 StandardActionManager::CreateResource, StandardActionManager::DialogTitle,
229 i18nc( "@title:window", "Add Address Book" ) );
230
231 mGenericManager->setContextText(
232 StandardActionManager::CreateResource, StandardActionManager::ErrorMessageText,
233 ki18n( "Could not create address book: %1" ) );
234
235 mGenericManager->setContextText(
236 StandardActionManager::CreateResource, StandardActionManager::ErrorMessageTitle,
237 i18n( "Address book creation failed" ) );
238 break;
239 case Akonadi::StandardActionManager::DeleteResources:
240
241 mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteResources,
242 ki18np( "&Delete Address Book",
243 "&Delete %1 Address Books" ) );
244 mGenericManager->action( Akonadi::StandardActionManager::DeleteResources )->setWhatsThis(
245 i18n( "Delete the selected address books<p>"
246 "The currently selected address books will be deleted, "
247 "along with all the contacts and contact groups they contain.</p>" ) );
248 mGenericManager->setContextText(
249 StandardActionManager::DeleteResources, StandardActionManager::MessageBoxText,
250 ki18np( "Do you really want to delete this address book?",
251 "Do you really want to delete %1 address books?" ) );
252
253 mGenericManager->setContextText(
254 StandardActionManager::DeleteResources, StandardActionManager::MessageBoxTitle,
255 ki18ncp( "@title:window", "Delete Address Book?", "Delete Address Books?" ) );
256
257 break;
258 case Akonadi::StandardActionManager::ResourceProperties:
259
260 mGenericManager->action( Akonadi::StandardActionManager::ResourceProperties )->setText(
261 i18n( "Address Book Properties..." ) );
262 mGenericManager->action( Akonadi::StandardActionManager::ResourceProperties )->setWhatsThis(
263 i18n( "Open a dialog to edit properties of the selected address book." ) );
264 break;
265 case Akonadi::StandardActionManager::SynchronizeResources:
266 mGenericManager->setActionText( Akonadi::StandardActionManager::SynchronizeResources,
267 ki18np( "Update Address Book",
268 "Update %1 Address Books" ) );
269
270 mGenericManager->action( Akonadi::StandardActionManager::SynchronizeResources )->setWhatsThis
271 ( i18n( "Updates the content of all folders of the selected address books." ) );
272
273 break;
274 case StandardActionManager::Paste:
275 mGenericManager->setContextText(
276 StandardActionManager::Paste, StandardActionManager::ErrorMessageText,
277 ki18n( "Could not paste contact: %1" ) );
278
279 mGenericManager->setContextText(
280 StandardActionManager::Paste, StandardActionManager::ErrorMessageTitle,
281 i18n( "Paste failed" ) );
282 break;
283 default:
284 break;
285 }
286
287 }
288
289 static bool hasWritableCollection( const QModelIndex &index, const QString &mimeType )
290 {
291 const Akonadi::Collection collection =
292 index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
293 if ( collection.isValid() ) {
294 if ( collection.contentMimeTypes().contains( mimeType ) &&
295 ( collection.rights() & Akonadi::Collection::CanCreateItem ) ) {
296 return true;
297 }
298 }
299
300 const QAbstractItemModel *model = index.model();
301 if ( !model ) {
302 return false;
303 }
304
305 for ( int row = 0; row < model->rowCount( index ); ++row ) {
306 if ( hasWritableCollection( model->index( row, 0, index ), mimeType ) ) {
307 return true;
308 }
309 }
310
311 return false;
312 }
313
314 bool hasWritableCollection( const QString &mimeType ) const
315 {
316 if ( !mCollectionSelectionModel ) {
317 return false;
318 }
319
320 const QAbstractItemModel *collectionModel = mCollectionSelectionModel->model();
321 for ( int row = 0; row < collectionModel->rowCount(); ++row ) {
322 if ( hasWritableCollection( collectionModel->index( row, 0, QModelIndex() ), mimeType ) ) {
323 return true;
324 }
325 }
326
327 return false;
328 }
329
330 void updateActions()
331 {
332 int itemCount = 0;
333 if ( mItemSelectionModel ) {
334 itemCount = mItemSelectionModel->selectedRows().count();
335 if ( itemCount == 1 ) {
336 const QModelIndex index = mItemSelectionModel->selectedRows().first();
337 if ( index.isValid() ) {
338 const QString mimeType = index.data( EntityTreeModel::MimeTypeRole ).toString();
339 if ( mimeType == KABC::Addressee::mimeType() ) {
340 if (mGenericManager->action( Akonadi::StandardActionManager::CopyItems )) {
341 mGenericManager->setActionText( Akonadi::StandardActionManager::CopyItems,
342 ki18np( "Copy Contact", "Copy %1 Contacts" ) );
343 }
344 if (mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu )) {
345 mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu )->setText( i18n( "Copy Contact To" ) );
346 }
347 if (mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog)) {
348 mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog )->setText( i18n( "Copy Contact To" ) );
349 }
350 if (mGenericManager->action( Akonadi::StandardActionManager::DeleteItems)) {
351 mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteItems,
352 ki18np( "Delete Contact", "Delete %1 Contacts" ) );
353 }
354 if (mGenericManager->action( Akonadi::StandardActionManager::CutItems)) {
355 mGenericManager->setActionText( Akonadi::StandardActionManager::CutItems,
356 ki18np( "Cut Contact", "Cut %1 Contacts" ) );
357 }
358 if (mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu)) {
359 mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu )->setText( i18n( "Move Contact To" ) );
360 }
361 if (mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )) {
362 mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )->setText( i18n( "Move Contact To" ) );
363 }
364 if ( mActions.contains( StandardContactActionManager::EditItem ) ) {
365 mActions.value( StandardContactActionManager::EditItem )->setText( i18n( "Edit Contact..." ) );
366 }
367 } else if ( mimeType == KABC::ContactGroup::mimeType() ) {
368 if (mGenericManager->action( Akonadi::StandardActionManager::CopyItems )) {
369 mGenericManager->setActionText( Akonadi::StandardActionManager::CopyItems,
370 ki18np( "Copy Group", "Copy %1 Groups" ) );
371 }
372 if (mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu)) {
373 mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu )->setText( i18n( "Copy Group To" ) );
374 }
375 if (mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog )) {
376 mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog )->setText( i18n( "Copy Group To" ) );
377 }
378 if (mGenericManager->action( Akonadi::StandardActionManager::DeleteItems)) {
379 mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteItems,
380 ki18np( "Delete Group", "Delete %1 Groups" ) );
381 }
382 if (mGenericManager->action( Akonadi::StandardActionManager::CutItems)) {
383 mGenericManager->setActionText( Akonadi::StandardActionManager::CutItems,
384 ki18np( "Cut Group", "Cut %1 Groups" ) );
385 }
386 if (mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu )) {
387 mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu )->setText( i18n( "Move Group To" ) );
388 }
389 if (mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )) {
390 mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )->setText( i18n( "Move Group To" ) );
391 }
392 if ( mActions.contains( StandardContactActionManager::EditItem ) ) {
393 mActions.value( StandardContactActionManager::EditItem )->setText( i18n( "Edit Group..." ) );
394 }
395 }
396 }
397 }
398 }
399
400 if ( mActions.contains( StandardContactActionManager::CreateContact ) ) {
401 mActions[ StandardContactActionManager::CreateContact ]->setEnabled( hasWritableCollection( KABC::Addressee::mimeType() ) );
402 }
403 if ( mActions.contains( StandardContactActionManager::CreateContactGroup ) ) {
404 mActions[ StandardContactActionManager::CreateContactGroup ]->setEnabled( hasWritableCollection( KABC::ContactGroup::mimeType() ) );
405 }
406
407 if ( mActions.contains( StandardContactActionManager::EditItem ) ) {
408 bool canEditItem = true;
409
410 // only one selected item can be edited
411 canEditItem = canEditItem && ( itemCount == 1 );
412
413 // check whether parent collection allows changing the item
414 const QModelIndexList rows = mItemSelectionModel->selectedRows();
415 if ( rows.count() == 1 ) {
416 const QModelIndex index = rows.first();
417 const Collection parentCollection = index.data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
418 if ( parentCollection.isValid() ) {
419 canEditItem = canEditItem && ( parentCollection.rights() & Collection::CanChangeItem );
420 }
421 }
422
423 mActions.value( StandardContactActionManager::EditItem )->setEnabled( canEditItem );
424 }
425
426 emit mParent->actionStateUpdated();
427 }
428
429 Collection selectedCollection() const
430 {
431 if ( !mCollectionSelectionModel ) {
432 return Collection();
433 }
434
435 if ( mCollectionSelectionModel->selectedIndexes().isEmpty() ) {
436 return Collection();
437 }
438
439 const QModelIndex index = mCollectionSelectionModel->selectedIndexes().first();
440 if ( !index.isValid() ) {
441 return Collection();
442 }
443
444 return index.data( EntityTreeModel::CollectionRole ).value<Collection>();
445 }
446
447 void slotCreateContact()
448 {
449 if ( mInterceptedActions.contains( StandardContactActionManager::CreateContact ) ) {
450 return;
451 }
452
453 QPointer<Akonadi::ContactEditorDialog> dlg =
454 new Akonadi::ContactEditorDialog(
455 Akonadi::ContactEditorDialog::CreateMode, mParentWidget );
456 dlg->setDefaultAddressBook( selectedCollection() );
457 dlg->exec();
458 delete dlg;
459 }
460
461 void slotCreateContactGroup()
462 {
463 if ( mInterceptedActions.contains( StandardContactActionManager::CreateContactGroup ) ) {
464 return;
465 }
466
467 QPointer<Akonadi::ContactGroupEditorDialog> dlg =
468 new Akonadi::ContactGroupEditorDialog(
469 Akonadi::ContactGroupEditorDialog::CreateMode, mParentWidget );
470 dlg->setDefaultAddressBook( selectedCollection() );
471 dlg->exec();
472 delete dlg;
473 }
474
475 void slotEditItem()
476 {
477 if ( mInterceptedActions.contains( StandardContactActionManager::EditItem ) ) {
478 return;
479 }
480
481 if ( !mItemSelectionModel ) {
482 return;
483 }
484
485 if ( mItemSelectionModel->selectedIndexes().isEmpty() ) {
486 return;
487 }
488
489 const QModelIndex index = mItemSelectionModel->selectedIndexes().first();
490 if ( !index.isValid() ) {
491 return;
492 }
493
494 const Item item = index.data( EntityTreeModel::ItemRole ).value<Item>();
495 if ( !item.isValid() ) {
496 return;
497 }
498
499 if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::Addressee::mimeType() ) ) {
500 QPointer<Akonadi::ContactEditorDialog> dlg =
501 new Akonadi::ContactEditorDialog(
502 Akonadi::ContactEditorDialog::EditMode, mParentWidget );
503 connect( dlg, SIGNAL(error(QString)),
504 mParent, SLOT(slotContactEditorError(QString)) );
505 dlg->setContact( item );
506 dlg->exec();
507 delete dlg;
508 } else if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::ContactGroup::mimeType() ) ) {
509 QPointer<Akonadi::ContactGroupEditorDialog> dlg =
510 new Akonadi::ContactGroupEditorDialog(
511 Akonadi::ContactGroupEditorDialog::EditMode, mParentWidget );
512 dlg->setContactGroup( item );
513 dlg->exec();
514 delete dlg;
515 }
516 }
517
518 void slotContactEditorError(const QString& error)
519 {
520 KMessageBox::error(mParentWidget, i18n("Contact cannot be stored: %1", error), i18n("Failed to store contact"));
521 }
522
523 KActionCollection *mActionCollection;
524 QWidget *mParentWidget;
525 StandardActionManager *mGenericManager;
526 QItemSelectionModel *mCollectionSelectionModel;
527 QItemSelectionModel *mItemSelectionModel;
528 QHash<StandardContactActionManager::Type, KAction*> mActions;
529 QSet<StandardContactActionManager::Type> mInterceptedActions;
530 StandardContactActionManager *mParent;
531};
532
533StandardContactActionManager::StandardContactActionManager( KActionCollection *actionCollection, QWidget *parent )
534 : QObject( parent ), d( new Private( actionCollection, parent, this ) )
535{
536}
537
538StandardContactActionManager::~StandardContactActionManager()
539{
540 delete d;
541}
542
543void StandardContactActionManager::setCollectionSelectionModel( QItemSelectionModel *selectionModel )
544{
545 d->mCollectionSelectionModel = selectionModel;
546 d->mGenericManager->setCollectionSelectionModel( selectionModel );
547
548 connect( selectionModel->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
549 SLOT(updateActions()) );
550 connect( selectionModel->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
551 SLOT(updateActions()) );
552 connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
553 SLOT(updateActions()) );
554
555 d->updateActions();
556}
557
558void StandardContactActionManager::setItemSelectionModel( QItemSelectionModel* selectionModel )
559{
560 d->mItemSelectionModel = selectionModel;
561 d->mGenericManager->setItemSelectionModel( selectionModel );
562
563 connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
564 SLOT(updateActions()) );
565
566 d->updateActions();
567}
568
569KAction* StandardContactActionManager::createAction( Type type )
570{
571 if ( d->mActions.contains( type ) ) {
572 return d->mActions.value( type );
573 }
574
575 KAction *action = 0;
576
577 switch ( type ) {
578 case CreateContact:
579 action = new KAction( d->mParentWidget );
580 action->setIcon( KIcon( QLatin1String( "contact-new" ) ) );
581 action->setText( i18n( "New &Contact..." ) );
582 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_N ) );
583 action->setWhatsThis( i18n( "Create a new contact<p>You will be presented with a dialog where you can add data about a person, including addresses and phone numbers.</p>" ) );
584 d->mActions.insert( CreateContact, action );
585 d->mActionCollection->addAction( QString::fromLatin1( "akonadi_contact_create" ), action );
586 connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCreateContact()) );
587 break;
588 case CreateContactGroup:
589 action = new KAction( d->mParentWidget );
590 action->setIcon( KIcon( QLatin1String( "user-group-new" ) ) );
591 action->setText( i18n( "New &Group..." ) );
592 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_G ) );
593 action->setWhatsThis( i18n( "Create a new group<p>You will be presented with a dialog where you can add a new group of contacts.</p>" ) );
594 d->mActions.insert( CreateContactGroup, action );
595 d->mActionCollection->addAction( QString::fromLatin1( "akonadi_contact_group_create" ), action );
596 connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCreateContactGroup()) );
597 break;
598 case EditItem:
599 action = new KAction( d->mParentWidget );
600 action->setIcon( KIcon( QLatin1String( "document-edit" ) ) );
601 action->setText( i18n( "Edit Contact..." ) );
602 action->setWhatsThis( i18n( "Edit the selected contact<p>You will be presented with a dialog where you can edit the data stored about a person, including addresses and phone numbers.</p>" ) );
603 action->setEnabled( false );
604 d->mActions.insert( EditItem, action );
605 d->mActionCollection->addAction( QString::fromLatin1( "akonadi_contact_item_edit" ), action );
606 connect( action, SIGNAL(triggered(bool)), this, SLOT(slotEditItem()) );
607 break;
608 default:
609 Q_ASSERT( false ); // should never happen
610 break;
611 }
612
613 return action;
614}
615
616KAction* StandardContactActionManager::createAction( StandardActionManager::Type type )
617{
618 KAction *act = d->mGenericManager->action(type);
619 if (!act )
620 act = d->mGenericManager->createAction( type );
621 d->updateGenericAction(type);
622 return act;
623}
624
625void StandardContactActionManager::createAllActions()
626{
627 createAction( CreateContact );
628 createAction( CreateContactGroup );
629 createAction( EditItem );
630
631 d->mGenericManager->createAllActions();
632 d->updateGenericAllActions();
633
634 d->updateActions();
635}
636
637KAction* StandardContactActionManager::action( Type type ) const
638{
639 if ( d->mActions.contains( type ) ) {
640 return d->mActions.value( type );
641 }
642
643 return 0;
644}
645
646KAction* StandardContactActionManager::action( StandardActionManager::Type type ) const
647{
648 return d->mGenericManager->action( type );
649}
650
651void StandardContactActionManager::setActionText( StandardActionManager::Type type, const KLocalizedString &text )
652{
653 d->mGenericManager->setActionText( type, text );
654}
655
656void StandardContactActionManager::interceptAction( Type type, bool intercept )
657{
658 if ( intercept ) {
659 d->mInterceptedActions.insert( type );
660 } else {
661 d->mInterceptedActions.remove( type );
662 }
663}
664
665void StandardContactActionManager::interceptAction( StandardActionManager::Type type, bool intercept )
666{
667 d->mGenericManager->interceptAction( type, intercept );
668}
669
670Akonadi::Collection::List StandardContactActionManager::selectedCollections() const
671{
672 return d->mGenericManager->selectedCollections();
673}
674
675Akonadi::Item::List StandardContactActionManager::selectedItems() const
676{
677 return d->mGenericManager->selectedItems();
678}
679
680void StandardContactActionManager::setCollectionPropertiesPageNames( const QStringList &names )
681{
682 d->mGenericManager->setCollectionPropertiesPageNames( names );
683}
684#include "moc_standardcontactactionmanager.cpp"
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:76
Akonadi::Collection::rights
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:99
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::Collection::setEnabled
void setEnabled(bool enabled)
Sets the collection's enabled state.
Definition: collection.cpp:273
Akonadi::Collection::CanCreateItem
@ CanCreateItem
Can create new items in this collection.
Definition: collection.h:89
Akonadi::Collection::CanChangeItem
@ CanChangeItem
Can change items in this collection.
Definition: collection.h:88
Akonadi::ContactEditorDialog
A dialog for creating or editing a contact in Akonadi.
Definition: contacteditordialog.h:78
Akonadi::ContactEditorDialog::EditMode
@ EditMode
Edits an existing contact.
Definition: contacteditordialog.h:87
Akonadi::ContactEditorDialog::CreateMode
@ CreateMode
Creates a new contact.
Definition: contacteditordialog.h:86
Akonadi::ContactGroupEditorDialog
A dialog for creating or editing a contact group in Akonadi.
Definition: contactgroupeditordialog.h:76
Akonadi::ContactGroupEditorDialog::CreateMode
@ CreateMode
Creates a new contact group.
Definition: contactgroupeditordialog.h:84
Akonadi::ContactGroupEditorDialog::EditMode
@ EditMode
Edits an existing contact group.
Definition: contactgroupeditordialog.h:85
Akonadi::EntityTreeModel::ParentCollectionRole
@ ParentCollectionRole
The parent collection of the entity.
Definition: entitytreemodel.h:341
Akonadi::EntityTreeModel::ItemRole
@ ItemRole
The Item.
Definition: entitytreemodel.h:332
Akonadi::EntityTreeModel::CollectionRole
@ CollectionRole
The collection.
Definition: entitytreemodel.h:336
Akonadi::EntityTreeModel::MimeTypeRole
@ MimeTypeRole
The mimetype of the entity.
Definition: entitytreemodel.h:333
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::MimeTypeChecker::isWantedItem
bool isWantedItem(const Item &item) const
Checks whether a given item has one of the wanted MIME types.
Definition: mimetypechecker.cpp:72
Akonadi::StandardActionManager
Manages generic actions for collection and item views.
Definition: standardactionmanager.h:127
Akonadi::StandardActionManager::Type
Type
Describes the supported actions.
Definition: standardactionmanager.h:133
Akonadi::StandardActionManager::CreateResource
@ CreateResource
Creates a new resource.
Definition: standardactionmanager.h:152
Akonadi::StandardActionManager::CreateCollection
@ CreateCollection
Creates an collection.
Definition: standardactionmanager.h:134
Akonadi::StandardActionManager::MoveToTrashRestoreItem
@ MoveToTrashRestoreItem
Move Item to Trash or Restore it from Trash, needs EntityDeletedAttribute.
Definition: standardactionmanager.h:168
Akonadi::StandardActionManager::SynchronizeResources
@ SynchronizeResources
Synchronizes the selected resources.
Definition: standardactionmanager.h:155
Akonadi::StandardActionManager::RemoveFromFavoriteCollections
@ RemoveFromFavoriteCollections
Remove the collection from the favorite collections model.
Definition: standardactionmanager.h:144
Akonadi::StandardActionManager::DeleteItems
@ DeleteItems
Deletes the selected items.
Definition: standardactionmanager.h:141
Akonadi::StandardActionManager::CopyCollectionToDialog
@ CopyCollectionToDialog
Copy a collection into another collection, select the target in a dialog.
Definition: standardactionmanager.h:157
Akonadi::StandardActionManager::SynchronizeCollections
@ SynchronizeCollections
Synchronizes collections.
Definition: standardactionmanager.h:137
Akonadi::StandardActionManager::MoveCollectionToDialog
@ MoveCollectionToDialog
Move a collection into another collection, select the target in a dialog.
Definition: standardactionmanager.h:158
Akonadi::StandardActionManager::CopyItemToMenu
@ CopyItemToMenu
Menu allowing to quickly copy an item into a collection.
Definition: standardactionmanager.h:147
Akonadi::StandardActionManager::RenameFavoriteCollection
@ RenameFavoriteCollection
Rename the collection of the favorite collections model.
Definition: standardactionmanager.h:145
Akonadi::StandardActionManager::SynchronizeFavoriteCollections
@ SynchronizeFavoriteCollections
Synchronize favorite collections.
Definition: standardactionmanager.h:170
Akonadi::StandardActionManager::ResourceProperties
@ ResourceProperties
Provides the resource properties.
Definition: standardactionmanager.h:154
Akonadi::StandardActionManager::CutItems
@ CutItems
Cuts the selected items.
Definition: standardactionmanager.h:150
Akonadi::StandardActionManager::DeleteCollections
@ DeleteCollections
Deletes the selected collections.
Definition: standardactionmanager.h:136
Akonadi::StandardActionManager::MoveToTrashRestoreCollection
@ MoveToTrashRestoreCollection
Move Collection to Trash or Restore it from Trash, needs EntityDeletedAttribute.
Definition: standardactionmanager.h:166
Akonadi::StandardActionManager::ToggleWorkOffline
@ ToggleWorkOffline
Toggles the work offline state of all resources.
Definition: standardactionmanager.h:156
Akonadi::StandardActionManager::ManageLocalSubscriptions
@ ManageLocalSubscriptions
Manages local subscriptions.
Definition: standardactionmanager.h:142
Akonadi::StandardActionManager::CutCollections
@ CutCollections
Cuts the selected collections.
Definition: standardactionmanager.h:151
Akonadi::StandardActionManager::CopyCollectionToMenu
@ CopyCollectionToMenu
Menu allowing to quickly copy a collection into another collection.
Definition: standardactionmanager.h:146
Akonadi::StandardActionManager::MoveItemToMenu
@ MoveItemToMenu
Menu allowing to move item into a collection.
Definition: standardactionmanager.h:148
Akonadi::StandardActionManager::AddToFavoriteCollections
@ AddToFavoriteCollections
Add the collection to the favorite collections model.
Definition: standardactionmanager.h:143
Akonadi::StandardActionManager::SynchronizeCollectionsRecursive
@ SynchronizeCollectionsRecursive
Synchronizes collections in a recursive way.
Definition: standardactionmanager.h:161
Akonadi::StandardActionManager::MoveItemsToTrash
@ MoveItemsToTrash
Moves the selected items to trash and marks them as deleted, needs EntityDeletedAttribute.
Definition: standardactionmanager.h:163
Akonadi::StandardActionManager::CopyCollections
@ CopyCollections
Copies the selected collections.
Definition: standardactionmanager.h:135
Akonadi::StandardActionManager::Paste
@ Paste
Paste collections or items.
Definition: standardactionmanager.h:140
Akonadi::StandardActionManager::CollectionProperties
@ CollectionProperties
Provides collection properties.
Definition: standardactionmanager.h:138
Akonadi::StandardActionManager::MoveToTrashRestoreCollectionAlternative
@ MoveToTrashRestoreCollectionAlternative
Helper type for MoveToTrashRestoreCollection, do not create directly. Use this to override texts of t...
Definition: standardactionmanager.h:167
Akonadi::StandardActionManager::DeleteResources
@ DeleteResources
Deletes the selected resources.
Definition: standardactionmanager.h:153
Akonadi::StandardActionManager::RestoreItemsFromTrash
@ RestoreItemsFromTrash
Restores the selected items from trash, needs EntityDeletedAttribute.
Definition: standardactionmanager.h:165
Akonadi::StandardActionManager::MoveToTrashRestoreItemAlternative
@ MoveToTrashRestoreItemAlternative
Helper type for MoveToTrashRestoreItem, do not create directly. Use this to override texts of the res...
Definition: standardactionmanager.h:169
Akonadi::StandardActionManager::RestoreCollectionsFromTrash
@ RestoreCollectionsFromTrash
Restores the selected collection from trash, needs EntityDeletedAttribute.
Definition: standardactionmanager.h:164
Akonadi::StandardActionManager::CopyItems
@ CopyItems
Copies the selected items.
Definition: standardactionmanager.h:139
Akonadi::StandardActionManager::MoveCollectionToMenu
@ MoveCollectionToMenu
Menu allowing to move a collection into another collection.
Definition: standardactionmanager.h:149
Akonadi::StandardActionManager::MoveItemToDialog
@ MoveItemToDialog
Move an item into a collection, select the target in a dialog.
Definition: standardactionmanager.h:160
Akonadi::StandardActionManager::CopyItemToDialog
@ CopyItemToDialog
Copy an item into a collection, select the target in a dialog.
Definition: standardactionmanager.h:159
Akonadi::StandardActionManager::MoveCollectionsToTrash
@ MoveCollectionsToTrash
Moves the selected collection to trash and marks it as deleted, needs EntityDeletedAttribute.
Definition: standardactionmanager.h:162
Akonadi::StandardActionManager::MessageBoxText
@ MessageBoxText
The text of a message box.
Definition: standardactionmanager.h:181
Akonadi::StandardActionManager::ErrorMessageText
@ ErrorMessageText
The text of an error message.
Definition: standardactionmanager.h:184
Akonadi::StandardActionManager::MessageBoxTitle
@ MessageBoxTitle
The window title of a message box.
Definition: standardactionmanager.h:180
Akonadi::StandardActionManager::DialogTitle
@ DialogTitle
The window title of a dialog.
Definition: standardactionmanager.h:178
Akonadi::StandardActionManager::ErrorMessageTitle
@ ErrorMessageTitle
The window title of an error message.
Definition: standardactionmanager.h:183
Akonadi::StandardContactActionManager
Manages contact specific actions for collection and item views.
Definition: standardcontactactionmanager.h:47
Akonadi::StandardContactActionManager::StandardContactActionManager
StandardContactActionManager(KActionCollection *actionCollection, QWidget *parent=0)
Creates a new standard contact action manager.
Definition: standardcontactactionmanager.cpp:533
Akonadi::StandardContactActionManager::~StandardContactActionManager
~StandardContactActionManager()
Destroys the standard contact action manager.
Definition: standardcontactactionmanager.cpp:538
Akonadi::StandardContactActionManager::Type
Type
Describes the supported actions.
Definition: standardcontactactionmanager.h:54
Akonadi::StandardContactActionManager::CreateContactGroup
@ CreateContactGroup
Creates a new contact group.
Definition: standardcontactactionmanager.h:56
Akonadi::StandardContactActionManager::CreateContact
@ CreateContact
Creates a new contact.
Definition: standardcontactactionmanager.h:55
Akonadi::StandardContactActionManager::EditItem
@ EditItem
Edits the selected contact resp. contact group.
Definition: standardcontactactionmanager.h:57
Akonadi::StandardContactActionManager::setCollectionPropertiesPageNames
void setCollectionPropertiesPageNames(const QStringList &names)
Definition: standardcontactactionmanager.cpp:680
Akonadi::StandardContactActionManager::action
KAction * action(Type type) const
Returns the action of the given type, 0 if it has not been created (yet).
Definition: standardcontactactionmanager.cpp:637
Akonadi::StandardContactActionManager::createAction
KAction * createAction(Type type)
Creates the action of the given type and adds it to the action collection specified in the constructo...
Definition: standardcontactactionmanager.cpp:569
Akonadi::StandardContactActionManager::setActionText
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...
Definition: standardcontactactionmanager.cpp:651
Akonadi::StandardContactActionManager::setCollectionSelectionModel
void setCollectionSelectionModel(QItemSelectionModel *selectionModel)
Sets the collection selection model based on which the collection related actions should operate.
Definition: standardcontactactionmanager.cpp:543
Akonadi::StandardContactActionManager::selectedItems
Akonadi::Item::List selectedItems() const
Returns the list of items that are currently selected.
Definition: standardcontactactionmanager.cpp:675
Akonadi::StandardContactActionManager::selectedCollections
Akonadi::Collection::List selectedCollections() const
Returns the list of collections that are currently selected.
Definition: standardcontactactionmanager.cpp:670
Akonadi::StandardContactActionManager::actionStateUpdated
void actionStateUpdated()
This signal is emitted whenever the action state has been updated.
Akonadi::StandardContactActionManager::createAllActions
void createAllActions()
Convenience method to create all standard actions.
Definition: standardcontactactionmanager.cpp:625
Akonadi::StandardContactActionManager::setItemSelectionModel
void setItemSelectionModel(QItemSelectionModel *selectionModel)
Sets the item selection model based on which the item related actions should operate.
Definition: standardcontactactionmanager.cpp:558
Akonadi::StandardContactActionManager::interceptAction
void interceptAction(Type type, bool intercept=true)
Sets whether the default implementation for the given action type shall be executed when the action i...
Definition: standardcontactactionmanager.cpp:656
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal