21 #include "emptytrashcommand_p.h"
23 #include "imapsettings.h"
27 #include <KMessageBox>
29 #include "akonadi/entitytreemodel.h"
30 #include "akonadi/kmime/specialmailcollections.h"
31 #include "akonadi/itemfetchjob.h"
32 #include "akonadi/itemdeletejob.h"
33 #include "akonadi/agentmanager.h"
34 #include "kmime/kmime_message.h"
36 EmptyTrashCommand::EmptyTrashCommand(
const QAbstractItemModel* model, QObject* parent)
37 : CommandBase( parent ),
39 the_trashCollectionFolder( -1 ),
40 mNumberOfTrashToEmpty( 0 )
45 : CommandBase( parent ),
47 the_trashCollectionFolder( -1 ),
49 mNumberOfTrashToEmpty( 0 )
54 void EmptyTrashCommand::execute()
56 if ( !mFolder.isValid() && !mModel ) {
61 if ( !mFolder.isValid() ) {
62 const QString title = i18n(
"Empty Trash");
63 const QString text = i18n(
"Are you sure you want to empty the trash folders of all accounts?");
64 if (KMessageBox::warningContinueCancel(0, text, title,
65 KStandardGuiItem::cont(), KStandardGuiItem::cancel(),
66 QLatin1String(
"confirm_empty_trash" ) )
67 != KMessageBox::Continue)
73 QList<Akonadi::Collection> trashFolder;
78 if ( type.
identifier().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
81 OrgKdeAkonadiImapSettingsInterface *iface = Util::createImapSettingsInterface( type.
identifier() );
82 if ( iface->isValid() ) {
83 const int trashImap = iface->trashCollection();
84 if ( trashImap != trash.id() ) {
91 mNumberOfTrashToEmpty = trashFolder.count();
92 for (
int i = 0; i < mNumberOfTrashToEmpty; ++i) {
93 expunge( trashFolder.at( i ) );
96 if ( folderIsTrash( mFolder ) ) {
97 mNumberOfTrashToEmpty++;
110 connect( job, SIGNAL(result(KJob*)),
this, SLOT(slotExpungeJob(KJob*)) );
112 kDebug()<<
" Try to expunge an invalid collection :"<<col;
113 emitResult( Failed );
117 void EmptyTrashCommand::slotExpungeJob( KJob *job )
119 if ( job->error() ) {
120 Util::showJobError( job );
121 emitResult( Failed );
126 emitResult( Failed );
130 if ( lstItem.isEmpty() ) {
135 connect( jobDelete, SIGNAL(result(KJob*)),
this, SLOT(slotDeleteJob(KJob*)) );
139 void EmptyTrashCommand::slotDeleteJob( KJob *job )
141 if ( job->error() ) {
142 Util::showJobError( job );
143 emitResult( Failed );
152 if ( instance.
type().
mimeTypes().contains( KMime::Message::mimeType() ) &&
155 relevantInstances << instance;
158 return relevantInstances;
171 if ( the_trashCollectionFolder < 0 )
173 return collectionFromId( the_trashCollectionFolder );
184 if ( type.
identifier().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
185 OrgKdeAkonadiImapSettingsInterface *iface = Util::createImapSettingsInterface( type.
identifier() );
186 if ( iface->isValid() ) {
187 if ( iface->trashCollection() == col.
id() ) {
198 void EmptyTrashCommand::emitResult( Result value )
200 emit result( value );
201 mNumberOfTrashToEmpty--;
202 if ( mNumberOfTrashToEmpty <= 0 ) {