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

akonadi/kmime

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

KDE's Doxygen guidelines are available online.

akonadi/kmime

Skip menu "akonadi/kmime"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • 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