[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepimlibs/akonadi/kmime
From:       Andras Mantia <amantia () kde ! org>
Date:       2010-09-28 13:31:10
Message-ID: 20100928133110.71DD6AC88E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1180659 by amantia:

Provide an EmptyTrash action.

 M  +44 -0     emptytrashcommand.cpp  
 M  +3 -0      emptytrashcommand_p.h  
 M  +0 -1      movetotrashcommand.cpp  
 M  +25 -0     standardmailactionmanager.cpp  
 M  +2 -0      standardmailactionmanager.h  


--- trunk/KDE/kdepimlibs/akonadi/kmime/emptytrashcommand.cpp #1180658:1180659
@@ -39,8 +39,22 @@
   mModel = model;
 }
 
+EmptyTrashCommand::EmptyTrashCommand(Akonadi::Collection folder, QObject* parent) : \
CommandBase( parent ) +{
+  mFolder = folder;
+  mModel = 0;
+}
+
+
 void EmptyTrashCommand::execute()
 {
+  if ( !mFolder.isValid() && !mModel ) {
+    emitResult( Failed );
+    return;
+  }
+
+  if ( !mFolder.isValid() ) { //expunge all
+    
   QString title = i18n("Empty Trash");
   QString text = i18n("Are you sure you want to empty the trash folders of all \
accounts?");  if (KMessageBox::warningContinueCancel(0, text, title,
@@ -68,8 +82,16 @@
       delete iface;
     }
   }
+  } else {
+    if ( folderIsTrash( mFolder ) ) {
+      expunge( mFolder );
+    } else {
+      emitResult( OK ); 
 }
 
+  }
+}
+
 void EmptyTrashCommand::expunge( const Akonadi::Collection & col )
 {
   if ( col.isValid() ) {
@@ -138,3 +160,25 @@
     the_trashCollectionFolder = \
Akonadi::SpecialMailCollections::self()->defaultCollection( \
Akonadi::SpecialMailCollections::Trash ).id();  return collectionFromId( \
the_trashCollectionFolder );  }
+
+bool EmptyTrashCommand::folderIsTrash( const Akonadi::Collection & col )
+{
+  if ( col == Akonadi::SpecialMailCollections::self()->defaultCollection( \
Akonadi::SpecialMailCollections::Trash ) ) +    return true;
+  const Akonadi::AgentInstance::List lst = agentInstances();
+  foreach ( const Akonadi::AgentInstance& type, lst ) {
+    if ( type.status() == Akonadi::AgentInstance::Broken )
+      continue;
+    if ( type.identifier().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
+      OrgKdeAkonadiImapSettingsInterface *iface = Util::createImapSettingsInterface( \
type.identifier() ); +      if ( iface->isValid() ) {
+        if ( iface->trashCollection() == col.id() ) {
+          delete iface;
+          return true;
+        }
+      }
+      delete iface;
+    }
+  }
+  return false;
+}
--- trunk/KDE/kdepimlibs/akonadi/kmime/emptytrashcommand_p.h #1180658:1180659
@@ -35,6 +35,7 @@
 
 public:
     EmptyTrashCommand(QAbstractItemModel* model, QObject* parent);
+    EmptyTrashCommand(Akonadi::Collection folder, QObject* parent);
     /*reimp*/ void execute();
      
 private slots:
@@ -45,9 +46,11 @@
   Akonadi::AgentInstance::List agentInstances();
   Akonadi::Collection trashCollectionFolder();
   Akonadi::Collection collectionFromId(const Akonadi::Collection::Id& id) const;
+  bool folderIsTrash( const Akonadi::Collection & col );
 
   QAbstractItemModel* mModel;
   Akonadi::Collection::Id the_trashCollectionFolder;
+  Akonadi::Collection mFolder;
 };
 
 #endif // EMPTYTRASHCOMMAND_P_H
--- trunk/KDE/kdepimlibs/akonadi/kmime/movetotrashcommand.cpp #1180658:1180659
@@ -101,7 +101,6 @@
   if (result == Failed )
     emitResult( Failed );
   if ( mFolderListJobCount == 0 && result == OK) {
-    qDebug() << "MOVETOTRASH ALL AS DONE";
     emitResult( OK );
   }
 }
--- trunk/KDE/kdepimlibs/akonadi/kmime/standardmailactionmanager.cpp #1180658:1180659
@@ -454,6 +454,23 @@
       command->execute();
     }
 
+    void slotEmptyTrash()
+    {
+      if ( mInterceptedActions.contains( StandardMailActionManager::EmptyTrash ) )
+        return;
+
+      if ( mCollectionSelectionModel->selection().indexes().isEmpty() )
+        return;
+
+      Collection::List collections = selectedCollections();
+
+      if ( collections.count() != 1 )
+        return;
+
+      EmptyTrashCommand *command = new EmptyTrashCommand( collections.first(), \
mParent ); +      command->execute();
+    }
+
     void slotMailLocalSubscription()
     {
 #ifndef Q_OS_WINCE
@@ -628,6 +645,13 @@
       d->mActionCollection->addAction( QString::fromLatin1( \
                "akonadi_empty_all_trash" ), action );
       connect( action, SIGNAL( triggered( bool ) ), this, SLOT( slotEmptyAllTrash() \
) );  break;
+    case EmptyTrash:
+      action = new KAction( d->mParentWidget );
+      action->setText( i18n( "E&mpty Trash" ) );
+      d->mActions.insert( EmptyTrash, action );
+      d->mActionCollection->addAction( QString::fromLatin1( "akonadi_empty_trash" ), \
action ); +      connect( action, SIGNAL( triggered( bool ) ), this, SLOT( \
slotEmptyTrash() ) ); +      break;
     default:
       Q_ASSERT( false ); // should never happen
       break;
@@ -655,6 +679,7 @@
   createAction( MoveAllToTrash );
   createAction( RemoveDuplicates );
   createAction( EmptyAllTrash );
+  createAction( EmptyTrash );
 
   d->mGenericManager->createAllActions();
 
--- trunk/KDE/kdepimlibs/akonadi/kmime/standardmailactionmanager.h #1180658:1180659
@@ -65,6 +65,7 @@
       MoveAllToTrash,                                   ///< Move all messages of \
                the current folder to trash.
       RemoveDuplicates,                                 ///< Removes all duplicated \
                messages.
       EmptyAllTrash,                                    ///< Empties trash folders \
on all accounts +      EmptyTrash,                                       ///< Empties \
                the trash folder, if a trash folder was selected
       LastType                                          ///< Marks last action.
     };
 
@@ -205,6 +206,7 @@
     Q_PRIVATE_SLOT( d, void slotMoveAllToTrash() )
     Q_PRIVATE_SLOT( d, void slotRemoveDuplicates() )
     Q_PRIVATE_SLOT( d, void slotEmptyAllTrash() )
+    Q_PRIVATE_SLOT( d, void slotEmptyTrash() )
     Q_PRIVATE_SLOT( d, void slotMailLocalSubscription() )
     //@endcond
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic