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

akonadi/contact

  • 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 <kaction.h>
32 #include <kactioncollection.h>
33 #include <klocale.h>
34 #include <kmessagebox.h>
35 
36 #include <QtCore/QPointer>
37 #include <QItemSelectionModel>
38 
39 using namespace Akonadi;
40 
41 class StandardContactActionManager::Private
42 {
43  public:
44  Private( KActionCollection *actionCollection, QWidget *parentWidget, StandardContactActionManager *parent )
45  : mActionCollection( actionCollection ), mParentWidget( parentWidget ),
46  mCollectionSelectionModel( 0 ), mItemSelectionModel( 0 ), mParent( parent )
47  {
48  mGenericManager = new StandardActionManager( actionCollection, parentWidget );
49  mParent->connect( mGenericManager, SIGNAL(actionStateUpdated()),
50  mParent, SIGNAL(actionStateUpdated()) );
51 
52  mGenericManager->setMimeTypeFilter(
53  QStringList() << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType() );
54 
55  mGenericManager->setCapabilityFilter( QStringList() << QLatin1String( "Resource" ) );
56  }
57 
58  ~Private()
59  {
60  delete mGenericManager;
61  }
62 
63  void updateGenericAllActions()
64  {
65  updateGenericAction(StandardActionManager::CreateCollection);
66  updateGenericAction(StandardActionManager::CopyCollections);
67  updateGenericAction(StandardActionManager::DeleteCollections);
68  updateGenericAction(StandardActionManager::SynchronizeCollections);
69  updateGenericAction(StandardActionManager::CollectionProperties);
70  updateGenericAction(StandardActionManager::CopyItems);
71  updateGenericAction(StandardActionManager::Paste);
72  updateGenericAction(StandardActionManager::DeleteItems);
73  updateGenericAction(StandardActionManager::ManageLocalSubscriptions);
74  updateGenericAction(StandardActionManager::AddToFavoriteCollections);
75  updateGenericAction(StandardActionManager::RemoveFromFavoriteCollections);
76  updateGenericAction(StandardActionManager::RenameFavoriteCollection);
77  updateGenericAction(StandardActionManager::CopyCollectionToMenu);
78  updateGenericAction(StandardActionManager::CopyItemToMenu);
79  updateGenericAction(StandardActionManager::MoveItemToMenu);
80  updateGenericAction(StandardActionManager::MoveCollectionToMenu);
81  updateGenericAction(StandardActionManager::CutItems);
82  updateGenericAction(StandardActionManager::CutCollections);
83  updateGenericAction(StandardActionManager::CreateResource);
84  updateGenericAction(StandardActionManager::DeleteResources);
85  updateGenericAction(StandardActionManager::ResourceProperties);
86  updateGenericAction(StandardActionManager::SynchronizeResources);
87  updateGenericAction(StandardActionManager::ToggleWorkOffline);
88  updateGenericAction(StandardActionManager::CopyCollectionToDialog);
89  updateGenericAction(StandardActionManager::MoveCollectionToDialog);
90  updateGenericAction(StandardActionManager::CopyItemToDialog);
91  updateGenericAction(StandardActionManager::MoveItemToDialog);
92  updateGenericAction(StandardActionManager::SynchronizeCollectionsRecursive);
93  updateGenericAction(StandardActionManager::MoveCollectionsToTrash);
94  updateGenericAction(StandardActionManager::MoveItemsToTrash);
95  updateGenericAction(StandardActionManager::RestoreCollectionsFromTrash);
96  updateGenericAction(StandardActionManager::RestoreItemsFromTrash);
97  updateGenericAction(StandardActionManager::MoveToTrashRestoreCollection);
98  updateGenericAction(StandardActionManager::MoveToTrashRestoreCollectionAlternative);
99  updateGenericAction(StandardActionManager::MoveToTrashRestoreItem);
100  updateGenericAction(StandardActionManager::MoveToTrashRestoreItemAlternative);
101  updateGenericAction(StandardActionManager::SynchronizeFavoriteCollections);
102 
103  }
104 
105  void updateGenericAction(StandardActionManager::Type type)
106  {
107  switch(type) {
108  case Akonadi::StandardActionManager::CreateCollection:
109  mGenericManager->action( Akonadi::StandardActionManager::CreateCollection )->setText(
110  i18n( "Add Address Book Folder..." ) );
111 
112  mGenericManager->action( Akonadi::StandardActionManager::CreateCollection )->setWhatsThis(
113  i18n( "Add a new address book folder to the currently selected address book folder." ) );
114  mGenericManager->setContextText(
115  StandardActionManager::CreateCollection, StandardActionManager::DialogTitle,
116  i18nc( "@title:window", "New Address Book Folder" ) );
117 
118  mGenericManager->setContextText(
119  StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageText,
120  ki18n( "Could not create address book folder: %1" ) );
121 
122  mGenericManager->setContextText(
123  StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageTitle,
124  i18n( "Address book folder creation failed" ) );
125 
126  break;
127  case Akonadi::StandardActionManager::CopyCollections:
128  mGenericManager->setActionText( Akonadi::StandardActionManager::CopyCollections,
129  ki18np( "Copy Address Book Folder",
130  "Copy %1 Address Book Folders" ) );
131  mGenericManager->action( Akonadi::StandardActionManager::CopyCollections )->setWhatsThis(
132  i18n( "Copy the selected address book folders to the clipboard." ) );
133  break;
134  case Akonadi::StandardActionManager::DeleteCollections:
135  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteCollections,
136  ki18np( "Delete Address Book Folder",
137  "Delete %1 Address Book Folders" ) );
138  mGenericManager->action( Akonadi::StandardActionManager::DeleteCollections )->setWhatsThis(
139  i18n( "Delete the selected address book folders from the address book." ) );
140 
141  mGenericManager->setContextText(
142  StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxText,
143  ki18np( "Do you really want to delete this address book folder and all its sub-folders?",
144  "Do you really want to delete %1 address book folders and all their sub-folders?" ) );
145  mGenericManager->setContextText(
146  StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxTitle,
147  ki18ncp( "@title:window", "Delete address book folder?", "Delete address book folders?" ) );
148 
149  mGenericManager->setContextText(
150  StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageText,
151  ki18n( "Could not delete address book folder: %1" ) );
152 
153 
154  mGenericManager->setContextText(
155  StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageTitle,
156  i18n( "Address book folder deletion failed" ) );
157  break;
158  case Akonadi::StandardActionManager::SynchronizeCollections:
159  mGenericManager->setActionText( Akonadi::StandardActionManager::SynchronizeCollections,
160  ki18np( "Update Address Book Folder",
161  "Update %1 Address Book Folders" ) );
162  mGenericManager->action( Akonadi::StandardActionManager::SynchronizeCollections )->setWhatsThis(
163  i18n( "Update the content of the selected address book folders." ) );
164  break;
165  case Akonadi::StandardActionManager::CutCollections:
166  mGenericManager->setActionText( Akonadi::StandardActionManager::CutCollections,
167  ki18np( "Cut Address Book Folder",
168  "Cut %1 Address Book Folders" ) );
169  mGenericManager->action( Akonadi::StandardActionManager::CutCollections )->setWhatsThis(
170  i18n( "Cut the selected address book folders from the address book." ) );
171  break;
172  case Akonadi::StandardActionManager::CollectionProperties:
173  mGenericManager->action( Akonadi::StandardActionManager::CollectionProperties )->setText(
174  i18n( "Folder Properties..." ) );
175  mGenericManager->action( Akonadi::StandardActionManager::CollectionProperties )->setWhatsThis(
176  i18n( "Open a dialog to edit the properties of the selected address book folder." ) );
177  mGenericManager->setContextText(
178  StandardActionManager::CollectionProperties, StandardActionManager::DialogTitle,
179  ki18nc( "@title:window", "Properties of Address Book Folder %1" ) );
180  break;
181  case Akonadi::StandardActionManager::CopyItems:
182  mGenericManager->setActionText( Akonadi::StandardActionManager::CopyItems,
183  ki18np( "Copy Contact", "Copy %1 Contacts" ) );
184  mGenericManager->action( Akonadi::StandardActionManager::CopyItems )->setWhatsThis(
185  i18n( "Copy the selected contacts to the clipboard." ) );
186  break;
187  case Akonadi::StandardActionManager::DeleteItems:
188  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteItems,
189  ki18np( "Delete Contact", "Delete %1 Contacts" ) );
190  mGenericManager->action( Akonadi::StandardActionManager::DeleteItems )->setWhatsThis(
191  i18n( "Delete the selected contacts from the address book." ) );
192  mGenericManager->setContextText(
193  StandardActionManager::DeleteItems, StandardActionManager::MessageBoxText,
194  ki18np( "Do you really want to delete the selected contact?",
195  "Do you really want to delete %1 contacts?" ) );
196 
197  mGenericManager->setContextText(
198  StandardActionManager::DeleteItems, StandardActionManager::MessageBoxTitle,
199  ki18ncp( "@title:window", "Delete Contact?", "Delete Contacts?" ) );
200 
201  mGenericManager->setContextText(
202  StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageText,
203  ki18n( "Could not delete contact: %1" ) );
204 
205  mGenericManager->setContextText(
206  StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageTitle,
207  i18n( "Contact deletion failed" ) );
208  break;
209  case Akonadi::StandardActionManager::CutItems:
210  mGenericManager->setActionText( Akonadi::StandardActionManager::CutItems,
211  ki18np( "Cut Contact", "Cut %1 Contacts" ) );
212  mGenericManager->action( Akonadi::StandardActionManager::CutItems )->setWhatsThis(
213  i18n( "Cut the selected contacts from the address book." ) );
214  break;
215  case Akonadi::StandardActionManager::CreateResource:
216  mGenericManager->action( Akonadi::StandardActionManager::CreateResource )->setText(
217  i18n( "Add &Address Book..." ) );
218  mGenericManager->action( Akonadi::StandardActionManager::CreateResource )->setWhatsThis(
219  i18n( "Add a new address book<p>"
220  "You will be presented with a dialog where you can select "
221  "the type of the address book that shall be added.</p>" ) );
222  mGenericManager->setContextText(
223  StandardActionManager::CreateResource, StandardActionManager::DialogTitle,
224  i18nc( "@title:window", "Add Address Book" ) );
225 
226  mGenericManager->setContextText(
227  StandardActionManager::CreateResource, StandardActionManager::ErrorMessageText,
228  ki18n( "Could not create address book: %1" ) );
229 
230  mGenericManager->setContextText(
231  StandardActionManager::CreateResource, StandardActionManager::ErrorMessageTitle,
232  i18n( "Address book creation failed" ) );
233  break;
234  case Akonadi::StandardActionManager::DeleteResources:
235 
236  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteResources,
237  ki18np( "&Delete Address Book",
238  "&Delete %1 Address Books" ) );
239  mGenericManager->action( Akonadi::StandardActionManager::DeleteResources )->setWhatsThis(
240  i18n( "Delete the selected address books<p>"
241  "The currently selected address books will be deleted, "
242  "along with all the contacts and contact groups they contain.</p>" ) );
243  mGenericManager->setContextText(
244  StandardActionManager::DeleteResources, StandardActionManager::MessageBoxText,
245  ki18np( "Do you really want to delete this address book?",
246  "Do you really want to delete %1 address books?" ) );
247 
248  mGenericManager->setContextText(
249  StandardActionManager::DeleteResources, StandardActionManager::MessageBoxTitle,
250  ki18ncp( "@title:window", "Delete Address Book?", "Delete Address Books?" ) );
251 
252  break;
253  case Akonadi::StandardActionManager::ResourceProperties:
254 
255  mGenericManager->action( Akonadi::StandardActionManager::ResourceProperties )->setText(
256  i18n( "Address Book Properties..." ) );
257  mGenericManager->action( Akonadi::StandardActionManager::ResourceProperties )->setWhatsThis(
258  i18n( "Open a dialog to edit properties of the selected address book." ) );
259  break;
260  case Akonadi::StandardActionManager::SynchronizeResources:
261  mGenericManager->setActionText( Akonadi::StandardActionManager::SynchronizeResources,
262  ki18np( "Update Address Book",
263  "Update %1 Address Books" ) );
264 
265  mGenericManager->action( Akonadi::StandardActionManager::SynchronizeResources )->setWhatsThis
266  ( i18n( "Updates the content of all folders of the selected address books." ) );
267 
268  break;
269  case StandardActionManager::Paste:
270  mGenericManager->setContextText(
271  StandardActionManager::Paste, StandardActionManager::ErrorMessageText,
272  ki18n( "Could not paste contact: %1" ) );
273 
274  mGenericManager->setContextText(
275  StandardActionManager::Paste, StandardActionManager::ErrorMessageTitle,
276  i18n( "Paste failed" ) );
277  break;
278  default:
279  break;
280  }
281 
282  }
283 
284  static bool hasWritableCollection( const QModelIndex &index, const QString &mimeType )
285  {
286  const Akonadi::Collection collection =
287  index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
288  if ( collection.isValid() ) {
289  if ( collection.contentMimeTypes().contains( mimeType ) &&
290  ( collection.rights() & Akonadi::Collection::CanCreateItem ) ) {
291  return true;
292  }
293  }
294 
295  const QAbstractItemModel *model = index.model();
296  if ( !model ) {
297  return false;
298  }
299 
300  for ( int row = 0; row < model->rowCount( index ); ++row ) {
301  if ( hasWritableCollection( model->index( row, 0, index ), mimeType ) ) {
302  return true;
303  }
304  }
305 
306  return false;
307  }
308 
309  bool hasWritableCollection( const QString &mimeType ) const
310  {
311  if ( !mCollectionSelectionModel ) {
312  return false;
313  }
314 
315  const QAbstractItemModel *collectionModel = mCollectionSelectionModel->model();
316  for ( int row = 0; row < collectionModel->rowCount(); ++row ) {
317  if ( hasWritableCollection( collectionModel->index( row, 0, QModelIndex() ), mimeType ) ) {
318  return true;
319  }
320  }
321 
322  return false;
323  }
324 
325  void updateActions()
326  {
327  int itemCount = 0;
328  if ( mItemSelectionModel ) {
329  itemCount = mItemSelectionModel->selectedRows().count();
330  if ( itemCount == 1 ) {
331  const QModelIndex index = mItemSelectionModel->selectedRows().first();
332  if ( index.isValid() ) {
333  const QString mimeType = index.data( EntityTreeModel::MimeTypeRole ).toString();
334  if ( mimeType == KABC::Addressee::mimeType() ) {
335  if(mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu )) {
336  mGenericManager->setActionText( Akonadi::StandardActionManager::CopyItems,
337  ki18np( "Copy Contact", "Copy %1 Contacts" ) );
338  mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu )->setText( i18n( "Copy Contact To" ) );
339  }
340  if(mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog)) {
341  mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog )->setText( i18n( "Copy Contact To" ) );
342  }
343  if(mGenericManager->action( Akonadi::StandardActionManager::DeleteItems)) {
344  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteItems,
345  ki18np( "Delete Contact", "Delete %1 Contacts" ) );
346  }
347  if(mGenericManager->action( Akonadi::StandardActionManager::CutItems)) {
348  mGenericManager->setActionText( Akonadi::StandardActionManager::CutItems,
349  ki18np( "Cut Contact", "Cut %1 Contacts" ) );
350  }
351  if(mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu)) {
352  mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu )->setText( i18n( "Move Contact To" ) );
353  }
354  if(mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )) {
355  mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )->setText( i18n( "Move Contact To" ) );
356  }
357  } else if ( mimeType == KABC::ContactGroup::mimeType() ) {
358  if(mGenericManager->action( Akonadi::StandardActionManager::CopyItems )) {
359  mGenericManager->setActionText( Akonadi::StandardActionManager::CopyItems,
360  ki18np( "Copy Group", "Copy %1 Groups" ) );
361  }
362  if(mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu)) {
363  mGenericManager->action( Akonadi::StandardActionManager::CopyItemToMenu )->setText( i18n( "Copy Group To" ) );
364  }
365  if(mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog )) {
366  mGenericManager->action( Akonadi::StandardActionManager::CopyItemToDialog )->setText( i18n( "Copy Group To" ) );
367  }
368  if(mGenericManager->action( Akonadi::StandardActionManager::DeleteItems)) {
369  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteItems,
370  ki18np( "Delete Group", "Delete %1 Groups" ) );
371  }
372  if(mGenericManager->action( Akonadi::StandardActionManager::CutItems)) {
373  mGenericManager->setActionText( Akonadi::StandardActionManager::CutItems,
374  ki18np( "Cut Group", "Cut %1 Groups" ) );
375  }
376  if(mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu )) {
377  mGenericManager->action( Akonadi::StandardActionManager::MoveItemToMenu )->setText( i18n( "Move Group To" ) );
378  }
379  if(mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )) {
380  mGenericManager->action( Akonadi::StandardActionManager::MoveItemToDialog )->setText( i18n( "Move Group To" ) );
381  }
382  if ( mActions.contains( StandardContactActionManager::EditItem ) ) {
383  mActions.value( StandardContactActionManager::EditItem )->setText( i18n( "Edit Group..." ) );
384  }
385  }
386  }
387  }
388  }
389 
390  if ( mActions.contains( StandardContactActionManager::CreateContact ) ) {
391  mActions[ StandardContactActionManager::CreateContact ]->setEnabled( hasWritableCollection( KABC::Addressee::mimeType() ) );
392  }
393  if ( mActions.contains( StandardContactActionManager::CreateContactGroup ) ) {
394  mActions[ StandardContactActionManager::CreateContactGroup ]->setEnabled( hasWritableCollection( KABC::ContactGroup::mimeType() ) );
395  }
396 
397  if ( mActions.contains( StandardContactActionManager::EditItem ) ) {
398  bool canEditItem = true;
399 
400  // only one selected item can be edited
401  canEditItem = canEditItem && ( itemCount == 1 );
402 
403  // check whether parent collection allows changing the item
404  const QModelIndexList rows = mItemSelectionModel->selectedRows();
405  if ( rows.count() == 1 ) {
406  const QModelIndex index = rows.first();
407  const Collection parentCollection = index.data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
408  if ( parentCollection.isValid() ) {
409  canEditItem = canEditItem && ( parentCollection.rights() & Collection::CanChangeItem );
410  }
411  }
412 
413  mActions.value( StandardContactActionManager::EditItem )->setEnabled( canEditItem );
414  }
415 
416  emit mParent->actionStateUpdated();
417  }
418 
419  Collection selectedCollection() const
420  {
421  if ( !mCollectionSelectionModel ) {
422  return Collection();
423  }
424 
425  if ( mCollectionSelectionModel->selectedIndexes().isEmpty() ) {
426  return Collection();
427  }
428 
429  const QModelIndex index = mCollectionSelectionModel->selectedIndexes().first();
430  if ( !index.isValid() ) {
431  return Collection();
432  }
433 
434  return index.data( EntityTreeModel::CollectionRole ).value<Collection>();
435  }
436 
437  void slotCreateContact()
438  {
439  if ( mInterceptedActions.contains( StandardContactActionManager::CreateContact ) ) {
440  return;
441  }
442 
443  Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::CreateMode, mParentWidget );
444  dlg.setDefaultAddressBook( selectedCollection() );
445 
446  dlg.exec();
447  }
448 
449  void slotCreateContactGroup()
450  {
451  if ( mInterceptedActions.contains( StandardContactActionManager::CreateContactGroup ) ) {
452  return;
453  }
454 
455  Akonadi::ContactGroupEditorDialog dlg( Akonadi::ContactGroupEditorDialog::CreateMode, mParentWidget );
456  dlg.setDefaultAddressBook( selectedCollection() );
457 
458  dlg.exec();
459  }
460 
461  void slotEditItem()
462  {
463  if ( mInterceptedActions.contains( StandardContactActionManager::EditItem ) ) {
464  return;
465  }
466 
467  if ( !mItemSelectionModel ) {
468  return;
469  }
470 
471  if ( mItemSelectionModel->selectedIndexes().isEmpty() ) {
472  return;
473  }
474 
475  const QModelIndex index = mItemSelectionModel->selectedIndexes().first();
476  if ( !index.isValid() ) {
477  return;
478  }
479 
480  const Item item = index.data( EntityTreeModel::ItemRole ).value<Item>();
481  if ( !item.isValid() ) {
482  return;
483  }
484 
485  if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::Addressee::mimeType() ) ) {
486  Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::EditMode, mParentWidget );
487  dlg.setContact( item );
488  dlg.exec();
489  } else if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::ContactGroup::mimeType() ) ) {
490  Akonadi::ContactGroupEditorDialog dlg( Akonadi::ContactGroupEditorDialog::EditMode, mParentWidget );
491  dlg.setContactGroup( item );
492  dlg.exec();
493  }
494  }
495 
496  KActionCollection *mActionCollection;
497  QWidget *mParentWidget;
498  StandardActionManager *mGenericManager;
499  QItemSelectionModel *mCollectionSelectionModel;
500  QItemSelectionModel *mItemSelectionModel;
501  QHash<StandardContactActionManager::Type, KAction*> mActions;
502  QSet<StandardContactActionManager::Type> mInterceptedActions;
503  StandardContactActionManager *mParent;
504 };
505 
506 StandardContactActionManager::StandardContactActionManager( KActionCollection *actionCollection, QWidget *parent )
507  : QObject( parent ), d( new Private( actionCollection, parent, this ) )
508 {
509 }
510 
511 StandardContactActionManager::~StandardContactActionManager()
512 {
513  delete d;
514 }
515 
516 void StandardContactActionManager::setCollectionSelectionModel( QItemSelectionModel *selectionModel )
517 {
518  d->mCollectionSelectionModel = selectionModel;
519  d->mGenericManager->setCollectionSelectionModel( selectionModel );
520 
521  connect( selectionModel->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
522  SLOT(updateActions()) );
523  connect( selectionModel->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
524  SLOT(updateActions()) );
525  connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
526  SLOT(updateActions()) );
527 
528  d->updateActions();
529 }
530 
531 void StandardContactActionManager::setItemSelectionModel( QItemSelectionModel* selectionModel )
532 {
533  d->mItemSelectionModel = selectionModel;
534  d->mGenericManager->setItemSelectionModel( selectionModel );
535 
536  connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
537  SLOT(updateActions()) );
538 
539  d->updateActions();
540 }
541 
542 KAction* StandardContactActionManager::createAction( Type type )
543 {
544  if ( d->mActions.contains( type ) ) {
545  return d->mActions.value( type );
546  }
547 
548  KAction *action = 0;
549 
550  switch ( type ) {
551  case CreateContact:
552  action = new KAction( d->mParentWidget );
553  action->setIcon( KIcon( QLatin1String( "contact-new" ) ) );
554  action->setText( i18n( "New &Contact..." ) );
555  action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_N ) );
556  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>" ) );
557  d->mActions.insert( CreateContact, action );
558  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_contact_create" ), action );
559  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCreateContact()) );
560  break;
561  case CreateContactGroup:
562  action = new KAction( d->mParentWidget );
563  action->setIcon( KIcon( QLatin1String( "user-group-new" ) ) );
564  action->setText( i18n( "New &Group..." ) );
565  action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_G ) );
566  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>" ) );
567  d->mActions.insert( CreateContactGroup, action );
568  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_contact_group_create" ), action );
569  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCreateContactGroup()) );
570  break;
571  case EditItem:
572  action = new KAction( d->mParentWidget );
573  action->setIcon( KIcon( QLatin1String( "document-edit" ) ) );
574  action->setText( i18n( "Edit Contact..." ) );
575  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>" ) );
576  action->setEnabled( false );
577  d->mActions.insert( EditItem, action );
578  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_contact_item_edit" ), action );
579  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotEditItem()) );
580  break;
581  default:
582  Q_ASSERT( false ); // should never happen
583  break;
584  }
585 
586  return action;
587 }
588 
589 KAction* StandardContactActionManager::createAction( StandardActionManager::Type type )
590 {
591  KAction *act = d->mGenericManager->action(type);
592  if(!act )
593  act = d->mGenericManager->createAction( type );
594  d->updateGenericAction(type);
595  return act;
596 }
597 
598 void StandardContactActionManager::createAllActions()
599 {
600  createAction( CreateContact );
601  createAction( CreateContactGroup );
602  createAction( EditItem );
603 
604  d->mGenericManager->createAllActions();
605  d->updateGenericAllActions();
606 
607  d->updateActions();
608 }
609 
610 KAction* StandardContactActionManager::action( Type type ) const
611 {
612  if ( d->mActions.contains( type ) ) {
613  return d->mActions.value( type );
614  }
615 
616  return 0;
617 }
618 
619 KAction* StandardContactActionManager::action( StandardActionManager::Type type ) const
620 {
621  return d->mGenericManager->action( type );
622 }
623 
624 void StandardContactActionManager::setActionText( StandardActionManager::Type type, const KLocalizedString &text )
625 {
626  d->mGenericManager->setActionText( type, text );
627 }
628 
629 void StandardContactActionManager::interceptAction( Type type, bool intercept )
630 {
631  if ( intercept ) {
632  d->mInterceptedActions.insert( type );
633  } else {
634  d->mInterceptedActions.remove( type );
635  }
636 }
637 
638 void StandardContactActionManager::interceptAction( StandardActionManager::Type type, bool intercept )
639 {
640  d->mGenericManager->interceptAction( type, intercept );
641 }
642 
643 Akonadi::Collection::List StandardContactActionManager::selectedCollections() const
644 {
645  return d->mGenericManager->selectedCollections();
646 }
647 
648 Akonadi::Item::List StandardContactActionManager::selectedItems() const
649 {
650  return d->mGenericManager->selectedItems();
651 }
652 
653 
654 void StandardContactActionManager::setCollectionPropertiesPageNames( const QStringList &names )
655 {
656  d->mGenericManager->setCollectionPropertiesPageNames( names );
657 }
658 #include "moc_standardcontactactionmanager.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:28:43 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 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