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

akonadi

  • akonadi
  • kmime
standardmailactionmanager.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2009 - 2010 Tobias Koenig <tokoe@kde.org>
5  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
6  Copyright (c) 2010 Andras Mantia <andras@kdab.com>
7 
8  This library is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Library General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or (at your
11  option) any later version.
12 
13  This library is distributed in the hope that it will be useful, but WITHOUT
14  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16  License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to the
20  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 */
23 
24 #include "standardmailactionmanager.h"
25 
26 #include "emptytrashcommand_p.h"
27 #include "markascommand_p.h"
28 #include "movetotrashcommand_p.h"
29 #include "removeduplicatescommand_p.h"
30 #include "specialmailcollections.h"
31 
32 #include "akonadi/agentfilterproxymodel.h"
33 #include "akonadi/agentinstance.h"
34 #include "akonadi/agentinstancecreatejob.h"
35 #include "akonadi/agentmanager.h"
36 #include "akonadi/agenttypedialog.h"
37 #include "akonadi/collectionstatistics.h"
38 #include "akonadi/entitytreemodel.h"
39 #include "akonadi/kmime/messagestatus.h"
40 #include "akonadi/mimetypechecker.h"
41 #include "akonadi/subscriptiondialog_p.h"
42 
43 #include <kaction.h>
44 #include <kactioncollection.h>
45 #include <klocale.h>
46 #include <kmessagebox.h>
47 #include <kmime/kmime_message.h>
48 
49 #include <QtCore/QPointer>
50 #include <QtGui/QItemSelectionModel>
51 
52 using namespace Akonadi;
53 
54 class StandardMailActionManager::Private
55 {
56  public:
57  Private( KActionCollection *actionCollection, QWidget *parentWidget, StandardMailActionManager *parent )
58  : mActionCollection( actionCollection ),
59  mParentWidget( parentWidget ),
60  mCollectionSelectionModel( 0 ),
61  mItemSelectionModel( 0 ),
62  mParent( parent )
63  {
64  mGenericManager = new StandardActionManager( actionCollection, parentWidget );
65 
66  mParent->connect( mGenericManager, SIGNAL(actionStateUpdated()),
67  mParent, SIGNAL(actionStateUpdated()) );
68 
69 
70  mGenericManager->setMimeTypeFilter( QStringList() << KMime::Message::mimeType() );
71  mGenericManager->setCapabilityFilter( QStringList() << QLatin1String( "Resource" ) );
72  }
73 
74  ~Private()
75  {
76  delete mGenericManager;
77  }
78 
79  void updateGenericAllActions()
80  {
81  updateGenericAction(StandardActionManager::CreateCollection);
82  updateGenericAction(StandardActionManager::CopyCollections);
83  updateGenericAction(StandardActionManager::DeleteCollections);
84  updateGenericAction(StandardActionManager::SynchronizeCollections);
85  updateGenericAction(StandardActionManager::CollectionProperties);
86  updateGenericAction(StandardActionManager::CopyItems);
87  updateGenericAction(StandardActionManager::Paste);
88  updateGenericAction(StandardActionManager::DeleteItems);
89  updateGenericAction(StandardActionManager::ManageLocalSubscriptions);
90  updateGenericAction(StandardActionManager::AddToFavoriteCollections);
91  updateGenericAction(StandardActionManager::RemoveFromFavoriteCollections);
92  updateGenericAction(StandardActionManager::RenameFavoriteCollection);
93  updateGenericAction(StandardActionManager::CopyCollectionToMenu);
94  updateGenericAction(StandardActionManager::CopyItemToMenu);
95  updateGenericAction(StandardActionManager::MoveItemToMenu);
96  updateGenericAction(StandardActionManager::MoveCollectionToMenu);
97  updateGenericAction(StandardActionManager::CutItems);
98  updateGenericAction(StandardActionManager::CutCollections);
99  updateGenericAction(StandardActionManager::CreateResource);
100  updateGenericAction(StandardActionManager::DeleteResources);
101  updateGenericAction(StandardActionManager::ResourceProperties);
102  updateGenericAction(StandardActionManager::SynchronizeResources);
103  updateGenericAction(StandardActionManager::ToggleWorkOffline);
104  updateGenericAction(StandardActionManager::CopyCollectionToDialog);
105  updateGenericAction(StandardActionManager::MoveCollectionToDialog);
106  updateGenericAction(StandardActionManager::CopyItemToDialog);
107  updateGenericAction(StandardActionManager::MoveItemToDialog);
108  updateGenericAction(StandardActionManager::SynchronizeCollectionsRecursive);
109  updateGenericAction(StandardActionManager::MoveCollectionsToTrash);
110  updateGenericAction(StandardActionManager::MoveItemsToTrash);
111  updateGenericAction(StandardActionManager::RestoreCollectionsFromTrash);
112  updateGenericAction(StandardActionManager::RestoreItemsFromTrash);
113  updateGenericAction(StandardActionManager::MoveToTrashRestoreCollection);
114  updateGenericAction(StandardActionManager::MoveToTrashRestoreCollectionAlternative);
115  updateGenericAction(StandardActionManager::MoveToTrashRestoreItem);
116  updateGenericAction(StandardActionManager::MoveToTrashRestoreItemAlternative);
117  updateGenericAction(StandardActionManager::SynchronizeFavoriteCollections);
118  }
119  void updateGenericAction(StandardActionManager::Type type)
120  {
121  switch(type) {
122  case Akonadi::StandardActionManager::CreateCollection:
123  mGenericManager->action( Akonadi::StandardActionManager::CreateCollection )->setText(
124  i18n( "Add Folder..." ) );
125  mGenericManager->action( Akonadi::StandardActionManager::CreateCollection )->setWhatsThis(
126  i18n( "Add a new folder to the currently selected account." ) );
127  mGenericManager->setContextText(
128  StandardActionManager::CreateCollection, StandardActionManager::DialogTitle,
129  i18nc( "@title:window", "New Folder" ) );
130 
131  mGenericManager->setContextText(
132  StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageText,
133  ki18n( "Could not create folder: %1" ) );
134 
135  mGenericManager->setContextText(
136  StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageTitle,
137  i18n( "Folder creation failed" ) );
138 
139  break;
140  case Akonadi::StandardActionManager::CopyCollections:
141  mGenericManager->setActionText( Akonadi::StandardActionManager::CopyCollections,
142  ki18np( "Copy Folder", "Copy %1 Folders" ) );
143  mGenericManager->action( Akonadi::StandardActionManager::CopyCollections )->setWhatsThis(
144  i18n( "Copy the selected folders to the clipboard." ) );
145  mGenericManager->setContextText(
146  StandardActionManager::CollectionProperties, StandardActionManager::DialogTitle,
147  ki18nc( "@title:window", "Properties of Folder %1" ) );
148 
149  break;
150  case Akonadi::StandardActionManager::DeleteCollections:
151  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteCollections,
152  ki18np( "Delete Folder", "Delete %1 Folders" ) );
153  mGenericManager->action( Akonadi::StandardActionManager::DeleteCollections )->setWhatsThis(
154  i18n( "Delete the selected folders from the account." ) );
155  mGenericManager->setContextText(
156  StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxText,
157  ki18np( "Do you really want to delete this folder and all its sub-folders?",
158  "Do you really want to delete %1 folders and all their sub-folders?" ) );
159 
160  mGenericManager->setContextText(
161  StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxTitle,
162  ki18ncp( "@title:window", "Delete folder?", "Delete folders?" ) );
163 
164  mGenericManager->setContextText(
165  StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageText,
166  ki18n( "Could not delete folder: %1" ) );
167 
168  mGenericManager->setContextText(
169  StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageTitle,
170  i18n( "Folder deletion failed" ) );
171 
172  break;
173  case Akonadi::StandardActionManager::SynchronizeCollections:
174  mGenericManager->setActionText( Akonadi::StandardActionManager::SynchronizeCollections,
175  ki18np( "Update Folder", "Update Folders" ) );
176 
177  mGenericManager->action( Akonadi::StandardActionManager::SynchronizeCollections )->setWhatsThis(
178  i18n( "Update the content of the selected folders." ) );
179  break;
180  case Akonadi::StandardActionManager::CutCollections:
181  mGenericManager->setActionText( Akonadi::StandardActionManager::CutCollections,
182  ki18np( "Cut Folder", "Cut %1 Folders" ) );
183  mGenericManager->action( Akonadi::StandardActionManager::CutCollections )->setWhatsThis(
184  i18n( "Cut the selected folders from the account." ) );
185  break;
186  case Akonadi::StandardActionManager::CollectionProperties:
187  mGenericManager->action( Akonadi::StandardActionManager::CollectionProperties )->setText(
188  i18n( "Folder Properties..." ) );
189  mGenericManager->action( Akonadi::StandardActionManager::CollectionProperties)->setWhatsThis(
190  i18n( "Open a dialog to edit the properties of the selected folder." ) );
191  break;
192  case Akonadi::StandardActionManager::CopyItems:
193  mGenericManager->setActionText( Akonadi::StandardActionManager::CopyItems,
194  ki18np( "Copy Email", "Copy %1 Emails" ) );
195  mGenericManager->action( Akonadi::StandardActionManager::CopyItems )->setWhatsThis(
196  i18n( "Copy the selected emails to the clipboard." ) );
197  break;
198  case Akonadi::StandardActionManager::DeleteItems:
199  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteItems,
200  ki18np( "Delete Email", "Delete %1 Emails" ) );
201  mGenericManager->action( Akonadi::StandardActionManager::DeleteItems )->setWhatsThis(
202  i18n( "Delete the selected emails from the folder." ) );
203  mGenericManager->setContextText(
204  StandardActionManager::DeleteItems, StandardActionManager::MessageBoxText,
205  ki18np( "Do you really want to delete the selected email?",
206  "Do you really want to delete %1 emails?" ) );
207 
208  mGenericManager->setContextText(
209  StandardActionManager::DeleteItems, StandardActionManager::MessageBoxTitle,
210  ki18ncp( "@title:window", "Delete Email?", "Delete Emails?" ) );
211 
212  mGenericManager->setContextText(
213  StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageText,
214  ki18n( "Could not delete email: %1" ) );
215 
216  mGenericManager->setContextText(
217  StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageTitle,
218  i18n( "Email deletion failed" ) );
219  break;
220  case Akonadi::StandardActionManager::CutItems:
221  mGenericManager->setActionText( Akonadi::StandardActionManager::CutItems,
222  ki18np( "Cut Email", "Cut %1 Emails" ) );
223  mGenericManager->action( Akonadi::StandardActionManager::CutItems )->setWhatsThis(
224  i18n( "Cut the selected emails from the folder." ) );
225  break;
226  case Akonadi::StandardActionManager::CreateResource:
227  mGenericManager->action( Akonadi::StandardActionManager::CreateResource )->setText(
228  i18n( "Add &Account..." ) );
229  mGenericManager->action( Akonadi::StandardActionManager::CreateResource )->setWhatsThis(
230  i18n( "Add a new account<p>"
231  "You will be presented with a dialog where you can select "
232  "the type of the account that shall be added.</p>" ) );
233  mGenericManager->setContextText(
234  StandardActionManager::CreateResource, StandardActionManager::DialogTitle,
235  i18nc( "@title:window", "Add Account" ) );
236 
237  mGenericManager->setContextText(
238  StandardActionManager::CreateResource, StandardActionManager::ErrorMessageText,
239  ki18n( "Could not create account: %1" ) );
240 
241  mGenericManager->setContextText(
242  StandardActionManager::CreateResource, StandardActionManager::ErrorMessageTitle,
243  i18n( "Account creation failed" ) );
244  break;
245  case Akonadi::StandardActionManager::DeleteResources:
246  mGenericManager->setActionText( Akonadi::StandardActionManager::DeleteResources,
247  ki18np( "&Delete Account", "&Delete %1 Accounts" ) );
248  mGenericManager->action( Akonadi::StandardActionManager::DeleteResources )->setWhatsThis(
249  i18n( "Delete the selected accounts<p>"
250  "The currently selected accounts will be deleted, "
251  "along with all the emails they contain.</p>" ) );
252  mGenericManager->setContextText(
253  StandardActionManager::DeleteResources, StandardActionManager::MessageBoxText,
254  ki18np( "Do you really want to delete this account?",
255  "Do you really want to delete %1 accounts?" ) );
256 
257  mGenericManager->setContextText(
258  StandardActionManager::DeleteResources, StandardActionManager::MessageBoxTitle,
259  ki18ncp( "@title:window", "Delete Account?", "Delete Accounts?" ) );
260  break;
261  case Akonadi::StandardActionManager::ResourceProperties:
262  mGenericManager->action( Akonadi::StandardActionManager::ResourceProperties )->setText(
263  i18n( "Account Properties..." ) );
264  mGenericManager->action( Akonadi::StandardActionManager::ResourceProperties )->setWhatsThis(
265  i18n( "Open a dialog to edit properties of the selected account." ) );
266  break;
267  case Akonadi::StandardActionManager::SynchronizeResources:
268  mGenericManager->setActionText( Akonadi::StandardActionManager::SynchronizeResources,
269  ki18np( "Update Account", "Update %1 Accounts" ) );
270  mGenericManager->action( Akonadi::StandardActionManager::SynchronizeResources )->setWhatsThis(
271  i18n( "Updates the content of all folders of the selected accounts." ) );
272 
273  break;
274  case Akonadi::StandardActionManager::SynchronizeCollectionsRecursive:
275 
276  mGenericManager->setActionText( Akonadi::StandardActionManager::SynchronizeCollectionsRecursive,
277  ki18np( "Update folder and its subfolders", "Update folders and their subfolders" ) );
278 
279  mGenericManager->action( Akonadi::StandardActionManager::SynchronizeCollectionsRecursive )->setWhatsThis(
280  i18n( "Update the content of the selected folders and their subfolders." ) );
281  break;
282  case Akonadi::StandardActionManager::Paste:
283  mGenericManager->setContextText(
284  StandardActionManager::Paste, StandardActionManager::ErrorMessageText,
285  ki18n( "Could not paste email: %1" ) );
286 
287  mGenericManager->setContextText(
288  StandardActionManager::Paste, StandardActionManager::ErrorMessageTitle,
289  i18n( "Paste failed" ) );
290  break;
291  default:
292  break;
293  }
294 
295  }
296 
297  void updateActions()
298  {
299  const Akonadi::Item::List selectedItems = mGenericManager->selectedItems();
300  const Akonadi::Collection::List selectedCollections = mGenericManager->selectedCollections();
301 
302  bool itemIsSelected = !selectedItems.isEmpty();
303  bool collectionIsSelected = !selectedCollections.isEmpty();
304 
305  if ( itemIsSelected ) {
306  bool allMarkedAsImportant = true;
307  bool allMarkedAsRead = true;
308  bool allMarkedAsUnread = true;
309  bool allMarkedAsActionItem = true;
310 
311  foreach ( const Akonadi::Item &item, selectedItems ) {
312  Akonadi::MessageStatus status;
313  status.setStatusFromFlags( item.flags() );
314  if ( !status.isImportant() )
315  allMarkedAsImportant = false;
316  if ( !status.isRead() )
317  allMarkedAsRead= false;
318  else
319  allMarkedAsUnread = false;
320  if ( !status.isToAct() )
321  allMarkedAsActionItem = false;
322  }
323 
324  QAction *action = mActions.value( Akonadi::StandardMailActionManager::MarkMailAsRead );
325  if ( action ) {
326  updateMarkAction( action, allMarkedAsRead );
327  if ( allMarkedAsRead )
328  action->setEnabled(false);
329  else
330  action->setEnabled( true );
331  }
332 
333  action = mActions.value( Akonadi::StandardMailActionManager::MarkMailAsUnread );
334  if ( action ) {
335  updateMarkAction( action, allMarkedAsUnread );
336  if ( allMarkedAsUnread )
337  action->setEnabled(false);
338  else
339  action->setEnabled( true );
340  }
341 
342  action = mActions.value( Akonadi::StandardMailActionManager::MarkMailAsImportant );
343  if ( action ) {
344  updateMarkAction( action, allMarkedAsImportant );
345  if ( allMarkedAsImportant )
346  action->setText( i18n( "Remove Important Mark" ) );
347  else
348  action->setText( i18n( "&Mark Mail as Important" ) );
349  action->setEnabled( true );
350  }
351 
352  action = mActions.value( Akonadi::StandardMailActionManager::MarkMailAsActionItem );
353  if ( action ) {
354  updateMarkAction( action, allMarkedAsActionItem );
355  if ( allMarkedAsActionItem )
356  action->setText( i18n( "Remove Action Item Mark" ) );
357  else
358  action->setText( i18n( "&Mark Mail as Action Item" ) );
359  action->setEnabled( true );
360  }
361  } else {
362  QAction *action = mActions.value( Akonadi::StandardMailActionManager::MarkMailAsRead );
363  if ( action )
364  action->setEnabled( false );
365 
366  action = mActions.value( Akonadi::StandardMailActionManager::MarkMailAsImportant );
367  if ( action )
368  action->setEnabled( false );
369 
370  action = mActions.value( Akonadi::StandardMailActionManager::MarkMailAsActionItem );
371  if ( action )
372  action->setEnabled( false );
373  }
374 
375  bool enableMarkAllAsRead = false;
376  bool enableMarkAllAsUnread = false;
377  bool canDeleteItem = true;
378  bool isSystemFolder = false;
379  if ( collectionIsSelected ) {
380  foreach( const Collection &collection, selectedCollections )
381  {
382  if ( collection.isValid() ) {
383  const Akonadi::CollectionStatistics stats = collection.statistics();
384  if ( !enableMarkAllAsRead )
385  enableMarkAllAsRead = (stats.unreadCount() > 0);
386  if ( !enableMarkAllAsUnread )
387  enableMarkAllAsUnread = (stats.count() != stats.unreadCount());
388  if ( canDeleteItem )
389  canDeleteItem = collection.rights() & Akonadi::Collection::CanDeleteItem;
390  if ( !isSystemFolder ) {
391  isSystemFolder = (collection == SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Inbox ) ||
392  collection == SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Outbox ) ||
393  collection == SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::SentMail ) ||
394  collection == SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Trash ) ||
395  collection == SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Drafts ) ||
396  collection == SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Templates ));
397  }
398  //We will not change after that.
399  if ( enableMarkAllAsRead && enableMarkAllAsUnread && !canDeleteItem && isSystemFolder )
400  break;
401  }
402  }
403  }
404  if ( isSystemFolder ) {
405  if ( mGenericManager->action( StandardActionManager::DeleteCollections ) ) {
406  mGenericManager->action( StandardActionManager::DeleteCollections )->setEnabled( false );
407  }
408  }
409 
410  if ( mActions.contains( Akonadi::StandardMailActionManager::MoveToTrash ) )
411  mActions.value( Akonadi::StandardMailActionManager::MoveToTrash )->setEnabled( itemIsSelected && canDeleteItem );
412  if ( mActions.contains( Akonadi::StandardMailActionManager::RemoveDuplicates ) )
413  mActions.value( Akonadi::StandardMailActionManager::RemoveDuplicates )->setEnabled( canDeleteItem );
414 
415  QAction *action = mActions.value( Akonadi::StandardMailActionManager::MarkAllMailAsRead );
416  if ( action ) {
417  action->setEnabled( enableMarkAllAsRead );
418  }
419 
420  action = mActions.value( Akonadi::StandardMailActionManager::MarkAllMailAsUnread );
421  if ( action ) {
422  action->setEnabled( enableMarkAllAsUnread );
423  }
424 
425  emit mParent->actionStateUpdated();
426  }
427 
428  void updateMarkAction( QAction* action, bool allMarked )
429  {
430  QByteArray data = action->data().toByteArray();
431  if ( allMarked ) {
432  if ( !data.startsWith( '!' ) )
433  data.prepend( '!' );
434  } else {
435  if ( data.startsWith( '!' ) )
436  data = data.mid( 1 );
437  }
438  action->setData( data );
439  }
440 
441  void slotMarkAs()
442  {
443  const QAction *action = qobject_cast<QAction*>( mParent->sender() );
444  Q_ASSERT( action );
445 
446  const Akonadi::Item::List items = mGenericManager->selectedItems();
447  if ( items.isEmpty() )
448  return;
449 
450  QByteArray typeStr = action->data().toByteArray();
451  kDebug() << "Mark mail as: " << typeStr;
452 
453  bool invert = false;
454  if ( typeStr.startsWith( '!' ) ) {
455  invert = true;
456  typeStr = typeStr.mid( 1 );
457  }
458 
459  Akonadi::MessageStatus targetStatus;
460  targetStatus.setStatusFromStr( QLatin1String( typeStr ) );
461 
462  StandardMailActionManager::Type type = MarkMailAsRead;
463  if ( typeStr == "U" ) {
464  type = MarkMailAsUnread;
465  targetStatus.setRead( true );
466  invert = true;
467  } else if ( typeStr == "K" )
468  type = MarkMailAsActionItem;
469  else if ( typeStr == "G" )
470  type = MarkMailAsImportant;
471 
472  if ( mInterceptedActions.contains( type ) )
473  return;
474 
475  MarkAsCommand *command = new MarkAsCommand( targetStatus, items, invert, mParent );
476  command->execute();
477  }
478 
479  void slotMarkAllAs()
480  {
481  const QAction *action = qobject_cast<QAction*>( mParent->sender() );
482  Q_ASSERT( action );
483 
484  QByteArray typeStr = action->data().toByteArray();
485  kDebug() << "Mark all as: " << typeStr;
486 
487  const Akonadi::Collection::List collections = mGenericManager->selectedCollections();
488  if ( collections.isEmpty() )
489  return;
490 
491  Akonadi::MessageStatus targetStatus;
492  targetStatus.setStatusFromStr( QLatin1String( typeStr ) );
493 
494  bool invert = false;
495  if ( typeStr.startsWith( '!' ) ) {
496  invert = true;
497  typeStr = typeStr.mid( 1 );
498  }
499 
500  StandardMailActionManager::Type type = MarkAllMailAsRead;
501  if ( typeStr == "U" ) {
502  type = MarkAllMailAsUnread;
503  targetStatus.setRead( true );
504  invert = true;
505  } else if ( typeStr == "K" )
506  type = MarkAllMailAsActionItem;
507  else if ( typeStr == "G" )
508  type = MarkAllMailAsImportant;
509 
510  if ( mInterceptedActions.contains( type ) )
511  return;
512 
513  MarkAsCommand *command = new MarkAsCommand( targetStatus, collections, invert, mParent );
514  command->execute();
515  }
516 
517  void slotMoveToTrash()
518  {
519  if ( mInterceptedActions.contains( StandardMailActionManager::MoveToTrash ) )
520  return;
521 
522  if ( mCollectionSelectionModel->selection().indexes().isEmpty() )
523  return;
524 
525  const Item::List items = mGenericManager->selectedItems();
526  if ( items.isEmpty() )
527  return;
528 
529  MoveToTrashCommand *command = new MoveToTrashCommand( mCollectionSelectionModel->model(), items, mParent );
530  command->execute();
531  }
532 
533  void slotMoveAllToTrash()
534  {
535  if ( mInterceptedActions.contains( StandardMailActionManager::MoveAllToTrash ) )
536  return;
537 
538  if ( mCollectionSelectionModel->selection().indexes().isEmpty() )
539  return;
540 
541  const Collection::List collections = mGenericManager->selectedCollections();
542  if ( collections.isEmpty() )
543  return;
544 
545  MoveToTrashCommand *command = new MoveToTrashCommand( mCollectionSelectionModel->model(), collections, mParent );
546  command->execute();
547  }
548 
549  void slotRemoveDuplicates()
550  {
551  if ( mInterceptedActions.contains( StandardMailActionManager::RemoveDuplicates ) )
552  return;
553 
554  const Collection::List collections = mGenericManager->selectedCollections();
555  if ( collections.isEmpty() )
556  return;
557 
558  RemoveDuplicatesCommand *command = new RemoveDuplicatesCommand( mCollectionSelectionModel->model(), collections, mParent );
559  command->execute();
560  }
561 
562  void slotEmptyAllTrash()
563  {
564  if ( mInterceptedActions.contains( StandardMailActionManager::EmptyAllTrash ) )
565  return;
566 
567  EmptyTrashCommand *command = new EmptyTrashCommand( const_cast<QAbstractItemModel*>( mCollectionSelectionModel->model() ), mParent );
568  command->execute();
569  }
570 
571  void slotEmptyTrash()
572  {
573  if ( mInterceptedActions.contains( StandardMailActionManager::EmptyTrash ) )
574  return;
575 
576  if ( mCollectionSelectionModel->selection().indexes().isEmpty() )
577  return;
578 
579  const Collection::List collections = mGenericManager->selectedCollections();
580  if ( collections.count() != 1 )
581  return;
582 
583  EmptyTrashCommand *command = new EmptyTrashCommand( collections.first(), mParent );
584  command->execute();
585  }
586 
587  KActionCollection *mActionCollection;
588  QWidget *mParentWidget;
589  StandardActionManager *mGenericManager;
590  QItemSelectionModel *mCollectionSelectionModel;
591  QItemSelectionModel *mItemSelectionModel;
592  QHash<StandardMailActionManager::Type, KAction*> mActions;
593  QSet<StandardMailActionManager::Type> mInterceptedActions;
594  StandardMailActionManager *mParent;
595 };
596 
597 
598 StandardMailActionManager::StandardMailActionManager( KActionCollection *actionCollection, QWidget *parent )
599  : QObject( parent ), d( new Private( actionCollection, parent, this ) )
600 {
601 }
602 
603 StandardMailActionManager::~StandardMailActionManager()
604 {
605  delete d;
606 }
607 
608 void StandardMailActionManager::setCollectionSelectionModel( QItemSelectionModel *selectionModel )
609 {
610  d->mCollectionSelectionModel = selectionModel;
611  d->mGenericManager->setCollectionSelectionModel( selectionModel );
612 
613  connect( selectionModel->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
614  SLOT(updateActions()) );
615  connect( selectionModel->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
616  SLOT(updateActions()) );
617  connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
618  SLOT(updateActions()) );
619 
620  d->updateActions();
621 }
622 
623 void StandardMailActionManager::setItemSelectionModel( QItemSelectionModel* selectionModel )
624 {
625  d->mItemSelectionModel = selectionModel;
626  d->mGenericManager->setItemSelectionModel( selectionModel );
627 
628  connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
629  SLOT(updateActions()) );
630 
631  //to catch item modifications, listen to the model's dataChanged signal as well
632  connect( selectionModel->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
633  SLOT(updateActions()) );
634 
635  d->updateActions();
636 }
637 
638 KAction* StandardMailActionManager::createAction( Type type )
639 {
640  if ( d->mActions.contains( type ) )
641  return d->mActions.value( type );
642 
643  KAction *action = 0;
644 
645  switch ( type ) {
646  case MarkMailAsRead:
647  action = new KAction( d->mParentWidget );
648  action->setIcon( KIcon( QLatin1String( "mail-mark-read" ) ) );
649  action->setText( i18n( "&Mark Mail as Read" ) );
650  action->setIconText( i18n( "Mark as Read" ) );
651  action->setWhatsThis( i18n( "Mark selected messages as read" ) );
652  d->mActions.insert( MarkMailAsRead, action );
653  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_as_read" ), action );
654  action->setData( QByteArray( "R" ) );
655  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAs()) );
656  break;
657  case MarkMailAsUnread:
658  action = new KAction( d->mParentWidget );
659  action->setText( i18n( "&Mark Mail as Unread" ) );
660  action->setIconText( i18n( "Mark as Unread" ) );
661  action->setIcon( KIcon( QLatin1String( "mail-mark-unread" ) ) );
662  d->mActions.insert( MarkMailAsUnread, action );
663  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_as_unread" ), action );
664  action->setShortcut( Qt::CTRL+Qt::Key_U );
665  action->setData( QByteArray( "U" ) );
666  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAs()) );
667  break;
668  case MarkMailAsImportant:
669  action = new KAction( d->mParentWidget );
670  action->setIcon( KIcon( QLatin1String( "mail-mark-important" ) ) );
671  action->setText( i18n( "&Mark Mail as Important" ) );
672  action->setIconText( i18n( "Mark as Important" ) );
673  d->mActions.insert( MarkMailAsImportant, action );
674  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_as_important" ), action );
675  action->setData( QByteArray( "G" ) );
676  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAs()) );
677  break;
678  case MarkMailAsActionItem:
679  action = new KAction( d->mParentWidget );
680  action->setText( i18n( "&Mark Mail as Action Item" ) );
681  action->setIconText( i18n( "Mark as Action Item" ) );
682  action->setIcon( KIcon( QLatin1String( "mail-mark-task" ) ) );
683  d->mActions.insert( MarkMailAsActionItem, action );
684  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_as_action_item" ), action );
685  action->setData( QByteArray( "K" ) );
686  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAs()) );
687  break;
688  case MarkAllMailAsRead:
689  action = new KAction( d->mParentWidget );
690  action->setIcon( KIcon( QLatin1String( "mail-mark-read" ) ) );
691  action->setText( i18n( "Mark &All Mails as Read" ) );
692  action->setIconText( i18n( "Mark All as Read" ) );
693  d->mActions.insert( MarkAllMailAsRead, action );
694  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_all_as_read" ), action );
695  action->setData( QByteArray( "R" ) );
696  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAllAs()) );
697  break;
698  case MarkAllMailAsUnread:
699  action = new KAction( d->mParentWidget );
700  action->setText( i18n( "Mark &All Mails as Unread" ) );
701  action->setIconText( i18n( "Mark All as Unread" ) );
702  action->setIcon( KIcon( QLatin1String( "mail-mark-unread" ) ) );
703  d->mActions.insert( MarkAllMailAsUnread, action );
704  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_all_as_unread" ), action );
705  action->setData( QByteArray( "U" ) );
706  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAllAs()) );
707  break;
708  case MarkAllMailAsImportant:
709  action = new KAction( d->mParentWidget );
710  action->setText( i18n( "Mark &All Mails as Important" ) );
711  action->setIconText( i18n( "Mark All as Important" ) );
712  action->setIcon( KIcon( QLatin1String( "mail-mark-important" ) ) );
713  d->mActions.insert( MarkAllMailAsImportant, action );
714  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_all_as_important" ), action );
715  action->setData( QByteArray( "G" ) );
716  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAllAs()) );
717  break;
718  case MarkAllMailAsActionItem:
719  action = new KAction( d->mParentWidget );
720  action->setText( i18n( "Mark &All Mails as Action Item" ) );
721  action->setIconText( i18n( "Mark All as Action Item" ) );
722  action->setIcon( KIcon( QLatin1String( "mail-mark-task" ) ) );
723  d->mActions.insert( MarkAllMailAsActionItem, action );
724  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_mark_all_as_action_item" ), action );
725  action->setData( QByteArray("K") );
726  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMarkAllAs()) );
727  break;
728  case MoveToTrash:
729  action = new KAction( d->mParentWidget );
730  action->setIcon( KIcon( QLatin1String( "user-trash" ) ) );
731  action->setText( i18n( "Move to &Trash" ) );
732  action->setShortcut( QKeySequence( Qt::Key_Delete ) );
733  action->setWhatsThis( i18n( "Move message to trashcan" ) );
734  d->mActions.insert( MoveToTrash, action );
735  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_move_to_trash" ), action );
736  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMoveToTrash()) );
737  break;
738  case MoveAllToTrash:
739  action = new KAction( d->mParentWidget );
740  action->setIcon( KIcon( QLatin1String( "user-trash" ) ) );
741  action->setText( i18n( "Move All to &Trash" ) );
742  d->mActions.insert( MoveAllToTrash, action );
743  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_move_all_to_trash" ), action );
744  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotMoveAllToTrash()) );
745  break;
746  case RemoveDuplicates:
747  action = new KAction( d->mParentWidget );
748  action->setText( i18n( "Remove &Duplicate Mails" ) );
749  action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_Asterisk ) );
750  d->mActions.insert( RemoveDuplicates, action );
751  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_remove_duplicates" ), action );
752  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotRemoveDuplicates()) );
753  break;
754  case EmptyAllTrash:
755  action = new KAction( d->mParentWidget );
756  action->setText( i18n( "Empty All &Trash Folders" ) );
757  d->mActions.insert( EmptyAllTrash, action );
758  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_empty_all_trash" ), action );
759  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotEmptyAllTrash()) );
760  break;
761  case EmptyTrash:
762  action = new KAction( d->mParentWidget );
763  action->setText( i18n( "E&mpty Trash" ) );
764  d->mActions.insert( EmptyTrash, action );
765  d->mActionCollection->addAction( QString::fromLatin1( "akonadi_empty_trash" ), action );
766  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotEmptyTrash()) );
767  break;
768  default:
769  Q_ASSERT( false ); // should never happen
770  break;
771  }
772 
773  return action;
774 }
775 
776 KAction* StandardMailActionManager::createAction( StandardActionManager::Type type )
777 {
778  KAction *act = d->mGenericManager->action(type);
779  if(!act )
780  act = d->mGenericManager->createAction( type );
781  d->updateGenericAction(type);
782  return act;
783 }
784 
785 void StandardMailActionManager::createAllActions()
786 {
787  createAction( MarkMailAsRead );
788  createAction( MarkMailAsUnread );
789  createAction( MarkMailAsImportant );
790  createAction( MarkMailAsActionItem );
791  createAction( MarkAllMailAsRead );
792  createAction( MarkAllMailAsUnread );
793  createAction( MarkAllMailAsImportant );
794  createAction( MarkAllMailAsActionItem );
795  createAction( MoveToTrash );
796  createAction( MoveAllToTrash );
797  createAction( RemoveDuplicates );
798  createAction( EmptyAllTrash );
799  createAction( EmptyTrash );
800 
801  d->mGenericManager->createAllActions();
802  d->updateGenericAllActions();
803 
804  d->updateActions();
805 }
806 
807 KAction* StandardMailActionManager::action( Type type ) const
808 {
809  if ( d->mActions.contains( type ) )
810  return d->mActions.value( type );
811 
812  return 0;
813 }
814 
815 KAction* StandardMailActionManager::action( StandardActionManager::Type type ) const
816 {
817  return d->mGenericManager->action( type );
818 }
819 
820 void StandardMailActionManager::setActionText( StandardActionManager::Type type, const KLocalizedString &text )
821 {
822  d->mGenericManager->setActionText( type, text );
823 }
824 
825 void StandardMailActionManager::interceptAction( Type type, bool intercept )
826 {
827  if ( intercept )
828  d->mInterceptedActions.insert( type );
829  else
830  d->mInterceptedActions.remove( type );
831 }
832 
833 void StandardMailActionManager::interceptAction( StandardActionManager::Type type, bool intercept )
834 {
835  d->mGenericManager->interceptAction( type, intercept );
836 }
837 
838 Akonadi::Collection::List StandardMailActionManager::selectedCollections() const
839 {
840  return d->mGenericManager->selectedCollections();
841 }
842 
843 Akonadi::Item::List StandardMailActionManager::selectedItems() const
844 {
845  return d->mGenericManager->selectedItems();
846 }
847 
848 void StandardMailActionManager::setFavoriteCollectionsModel( FavoriteCollectionsModel *favoritesModel )
849 {
850  d->mGenericManager->setFavoriteCollectionsModel( favoritesModel );
851 }
852 
853 void StandardMailActionManager::setFavoriteSelectionModel( QItemSelectionModel *selectionModel )
854 {
855  d->mGenericManager->setFavoriteSelectionModel( selectionModel );
856 }
857 
858 void StandardMailActionManager::setCollectionPropertiesPageNames( const QStringList &names )
859 {
860  d->mGenericManager->setCollectionPropertiesPageNames( names );
861 }
862 
863 Akonadi::StandardActionManager* StandardMailActionManager::standardActionManager() const
864 {
865  return d->mGenericManager;
866 }
867 
868 
869 #include "standardmailactionmanager.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 4 2012 14:36:06 by doxygen 1.8.1.2 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.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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