20 #include "movetotrashcommand_p.h" 22 #include "movecommand_p.h" 23 #include "imapsettings.h" 25 #include <akonadi/itemfetchjob.h> 26 #include <akonadi/itemfetchscope.h> 27 #include <akonadi/kmime/specialmailcollections.h> 28 #include <akonadi/entitytreemodel.h> 30 MoveToTrashCommand::MoveToTrashCommand(
const QAbstractItemModel *model,
const Akonadi::Collection::List &folders, QObject *parent)
33 the_trashCollectionFolder = -1;
36 mFolderListJobCount = mFolders.size();
39 MoveToTrashCommand::MoveToTrashCommand(
const QAbstractItemModel *model,
const QList< Akonadi::Item > &msgList, QObject *parent)
42 the_trashCollectionFolder = -1;
45 mFolderListJobCount = 0;
48 void MoveToTrashCommand::slotFetchDone(KJob *job)
50 mFolderListJobCount--;
54 Util::showJobError(job);
59 Akonadi::ItemFetchJob *fjob =
static_cast<Akonadi::ItemFetchJob *
>(job);
61 mMessages = fjob->items();
64 if (mFolderListJobCount > 0) {
65 Akonadi::ItemFetchJob *job =
new Akonadi::ItemFetchJob(mFolders[mFolderListJobCount - 1], parent());
66 job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
67 connect(job, SIGNAL(result(KJob*)),
this, SLOT(slotFetchDone(KJob*)));
71 void MoveToTrashCommand::execute()
73 if (!mFolders.isEmpty()) {
74 Akonadi::ItemFetchJob *job =
new Akonadi::ItemFetchJob(mFolders[mFolderListJobCount - 1], parent());
75 job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
76 connect(job, SIGNAL(result(KJob*)),
this, SLOT(slotFetchDone(KJob*)));
77 }
else if (!mMessages.isEmpty()) {
78 mFolders << mMessages.first().parentCollection();
85 void MoveToTrashCommand::moveMessages()
87 Akonadi::Collection folder = mFolders[mFolderListJobCount];
88 if (folder.isValid()) {
89 MoveCommand *moveCommand =
new MoveCommand(findTrashFolder(folder), mMessages,
this);
90 connect(moveCommand, SIGNAL(result(Result)),
this, SLOT(slotMoveDone(Result)));
91 moveCommand->execute();
97 void MoveToTrashCommand::slotMoveDone(
const Result &result)
99 if (result == Failed) {
102 if (mFolderListJobCount == 0 && result == OK) {
107 Akonadi::Collection MoveToTrashCommand::collectionFromId(
const Akonadi::Collection::Id &
id)
const 109 const QModelIndex idx = Akonadi::EntityTreeModel::modelIndexForCollection(
110 mModel, Akonadi::Collection(
id)
112 return idx.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
115 Akonadi::Collection MoveToTrashCommand::trashCollectionFromResource(
const Akonadi::Collection &col)
118 Akonadi::Collection trashCol;
120 if (col.resource().contains(IMAP_RESOURCE_IDENTIFIER)) {
123 OrgKdeAkonadiImapSettingsInterface *iface = Util::createImapSettingsInterface(col.resource());
124 if (iface->isValid()) {
126 trashCol = Akonadi::Collection(iface->trashCollection());
136 Akonadi::Collection MoveToTrashCommand::trashCollectionFolder()
138 if (the_trashCollectionFolder < 0) {
141 return collectionFromId(the_trashCollectionFolder);
144 Akonadi::Collection MoveToTrashCommand::findTrashFolder(
const Akonadi::Collection &folder)
146 Akonadi::Collection col = trashCollectionFromResource(folder);
147 if (!col.isValid()) {
148 col = trashCollectionFolder();
153 return Akonadi::Collection();
156 #include "moc_movetotrashcommand_p.cpp"
static SpecialMailCollections * self()
Returns the global SpecialMailCollections instance.
Akonadi::Collection defaultCollection(Type type) const
Returns the special mail collection of given type in the default resource, or an invalid collection i...