20 #include "markascommand_p.h"
22 #include <akonadi/itemfetchjob.h>
23 #include <akonadi/itemfetchscope.h>
24 #include <akonadi/itemmodifyjob.h>
31 mTargetStatus = targetStatus;
32 mFolderListJobCount = 0;
36 MarkAsCommand::MarkAsCommand(
const Akonadi::MessageStatus &targetStatus,
const Akonadi::Collection::List &folders,
bool invert,
QObject *parent)
41 mTargetStatus = targetStatus;
42 mFolderListJobCount = mFolders.size();
46 void MarkAsCommand::slotFetchDone(KJob *job)
48 mFolderListJobCount--;
52 Util::showJobError(job);
57 Akonadi::ItemFetchJob *fjob =
static_cast<Akonadi::ItemFetchJob *
>(job);
59 foreach (
const Akonadi::Item &item, fjob->items()) {
63 if (status & mTargetStatus) {
64 mMessages.append(item);
66 }
else if (!(status & mTargetStatus)) {
67 mMessages.append(item);
70 if (mMessages.empty()) {
71 if (mFolderListJobCount == 0) {
78 if (mFolderListJobCount > 0) {
79 Akonadi::ItemFetchJob *job =
new Akonadi::ItemFetchJob(mFolders[mFolderListJobCount - 1], parent());
80 job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
81 connect(job, SIGNAL(result(KJob*)),
this, SLOT(slotFetchDone(KJob*)));
85 void MarkAsCommand::execute()
87 if (!mFolders.isEmpty()) {
89 Akonadi::ItemFetchJob *job =
new Akonadi::ItemFetchJob(mFolders[mFolderListJobCount - 1], parent());
90 job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
91 connect(job, SIGNAL(result(KJob*)),
this, SLOT(slotFetchDone(KJob*)));
92 }
else if (!mMessages.isEmpty()) {
93 mFolders << mMessages.first().parentCollection();
100 void MarkAsCommand::markMessages()
105 Q_ASSERT(flags.
size() == 1);
106 Akonadi::Item::Flag flag;
108 flag = *(flags.
begin());
111 Akonadi::Item::List itemsToModify;
112 foreach (
const Akonadi::Item &it, mMessages) {
113 Akonadi::Item item(it);
118 if (item.hasFlag(flag)) {
119 item.clearFlag(flag);
120 itemsToModify.push_back(item);
123 if (!item.hasFlag(flag)) {
125 itemsToModify.push_back(item);
131 if (itemsToModify.isEmpty()) {
132 slotModifyItemDone(0);
134 Akonadi::ItemModifyJob *modifyJob =
new Akonadi::ItemModifyJob(itemsToModify,
this);
135 modifyJob->setIgnorePayload(
true);
136 modifyJob->disableRevisionCheck();
137 connect(modifyJob, SIGNAL(result(KJob*)),
this, SLOT(slotModifyItemDone(KJob*)));
141 void MarkAsCommand::slotModifyItemDone(KJob *job)
145 if (job && job->error()) {
146 kDebug() <<
" Error trying to set item status:" << job->errorText();
149 if (mMarkJobCount == 0 && mFolderListJobCount == 0) {
154 #include "moc_markascommand_p.cpp"
void setStatusFromFlags(const QSet< QByteArray > &flags)
Set the status as a whole e.g.
Akonadi KMime Message Status.