• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • folderarchive
folderarchiveagentjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "folderarchiveagentjob.h"
19 #include "folderarchiveaccountinfo.h"
20 #include "folderarchiveagentcheckcollection.h"
21 #include "folderarchivemanager.h"
22 #include "folderarchivecache.h"
23 
24 #include "kmcommands.h"
25 
26 #include <Akonadi/ItemMoveJob>
27 #include <Akonadi/CollectionFetchJob>
28 #include <Akonadi/ItemMoveJob>
29 
30 #include <KLocale>
31 
32 FolderArchiveAgentJob::FolderArchiveAgentJob(FolderArchiveManager *manager, FolderArchiveAccountInfo *info, const QList<Akonadi::Item> &lstItem, QObject *parent)
33  : QObject(parent),
34  mListItem(lstItem),
35  mManager(manager),
36  mInfo(info)
37 {
38 }
39 
40 FolderArchiveAgentJob::~FolderArchiveAgentJob()
41 {
42 }
43 
44 void FolderArchiveAgentJob::start()
45 {
46  if (!mInfo->isValid()) {
47  sendError(i18n("Archive folder not defined. Please verify settings for account", mInfo->instanceName() ));
48  return;
49  }
50  if (mListItem.isEmpty()) {
51  sendError(i18n("No messages selected."));
52  return;
53  }
54 
55  if (mInfo->folderArchiveType() == FolderArchiveAccountInfo::UniqueFolder) {
56  Akonadi::CollectionFetchJob *fetchCollection = new Akonadi::CollectionFetchJob( Akonadi::Collection(mInfo->archiveTopLevel()), Akonadi::CollectionFetchJob::Base );
57  connect( fetchCollection, SIGNAL(result(KJob*)), this, SLOT(slotFetchCollection(KJob*)));
58  } else {
59  Akonadi::Collection::Id id = mManager->folderArchiveCache()->collectionId(mInfo);
60  if (id != -1) {
61  Akonadi::CollectionFetchJob *fetchCollection = new Akonadi::CollectionFetchJob( Akonadi::Collection(id), Akonadi::CollectionFetchJob::Base );
62  connect( fetchCollection, SIGNAL(result(KJob*)), this, SLOT(slotFetchCollection(KJob*)));
63  } else {
64  FolderArchiveAgentCheckCollection *checkCol = new FolderArchiveAgentCheckCollection(mInfo, this);
65  connect(checkCol, SIGNAL(collectionIdFound(Akonadi::Collection)), SLOT(slotCollectionIdFound(Akonadi::Collection)));
66  connect(checkCol, SIGNAL(checkFailed(QString)), this, SLOT(slotCheckFailder(QString)));
67  checkCol->start();
68  }
69  }
70 }
71 
72 void FolderArchiveAgentJob::slotCheckFailder(const QString &message)
73 {
74  sendError(i18n("Cannot fetch collection. %1", message));
75 }
76 
77 void FolderArchiveAgentJob::slotFetchCollection(KJob *job)
78 {
79  if ( job->error() ) {
80  sendError(i18n("Cannot fetch collection. %1", job->errorString() ));
81  return;
82  }
83  Akonadi::CollectionFetchJob *fetchCollectionJob = static_cast<Akonadi::CollectionFetchJob*>(job);
84  Akonadi::Collection::List collections = fetchCollectionJob->collections();
85  if (collections.isEmpty()) {
86  sendError(i18n("List of collections is empty. %1", job->errorString() ));
87  return;
88  }
89  sloMoveMailsToCollection(collections.at(0));
90 }
91 
92 void FolderArchiveAgentJob::slotCollectionIdFound(const Akonadi::Collection &col)
93 {
94  mManager->folderArchiveCache()->addToCache(mInfo->instanceName(), col.id());
95  sloMoveMailsToCollection(col);
96 }
97 
98 void FolderArchiveAgentJob::sloMoveMailsToCollection(const Akonadi::Collection &col)
99 {
100  KMMoveCommand *command = new KMMoveCommand( col, mListItem, -1 );
101  connect( command, SIGNAL(moveDone(KMMoveCommand*)), this, SLOT(slotMoveMessages(KMMoveCommand*)));
102  command->start();
103 }
104 
105 void FolderArchiveAgentJob::sendError(const QString &error)
106 {
107  mManager->moveFailed(error);
108 }
109 
110 void FolderArchiveAgentJob::slotMoveMessages(KMMoveCommand *command)
111 {
112  if ( command->result() == KMCommand::Failed ) {
113  sendError(i18n("Cannot move messages."));
114  return;
115  }
116  mManager->moveDone();
117 }
FolderArchiveAccountInfo::folderArchiveType
FolderArchiveType folderArchiveType() const
Definition: folderarchiveaccountinfo.cpp:53
FolderArchiveManager::moveFailed
void moveFailed(const QString &msg)
Definition: folderarchivemanager.cpp:189
FolderArchiveAgentJob::~FolderArchiveAgentJob
~FolderArchiveAgentJob()
Definition: folderarchiveagentjob.cpp:40
folderarchivemanager.h
KMMoveCommand
Definition: kmcommands.h:523
FolderArchiveAccountInfo::instanceName
QString instanceName() const
Definition: folderarchiveaccountinfo.cpp:68
FolderArchiveCache::addToCache
void addToCache(const QString &resourceName, Akonadi::Collection::Id id)
Definition: folderarchivecache.cpp:84
FolderArchiveAgentJob::start
void start()
Definition: folderarchiveagentjob.cpp:44
folderarchiveaccountinfo.h
KMCommand::result
Result result() const
Returns the result of the command.
Definition: kmcommands.cpp:206
FolderArchiveCache::collectionId
Akonadi::Collection::Id collectionId(FolderArchiveAccountInfo *info)
Definition: folderarchivecache.cpp:48
FolderArchiveAccountInfo::isValid
bool isValid() const
Definition: folderarchiveaccountinfo.cpp:43
folderarchiveagentcheckcollection.h
FolderArchiveManager::folderArchiveCache
FolderArchiveCache * folderArchiveCache() const
Definition: folderarchivemanager.cpp:213
QObject
QList::isEmpty
bool isEmpty() const
KMCommand::start
void start()
Definition: kmcommands.cpp:233
QString
FolderArchiveAccountInfo::archiveTopLevel
Akonadi::Collection::Id archiveTopLevel() const
Definition: folderarchiveaccountinfo.cpp:63
QList< Akonadi::Item >
FolderArchiveAccountInfo
Definition: folderarchiveaccountinfo.h:24
FolderArchiveManager
Definition: folderarchivemanager.h:33
FolderArchiveAgentCheckCollection::start
void start()
Definition: folderarchiveagentcheckcollection.cpp:39
FolderArchiveManager::moveDone
void moveDone()
Definition: folderarchivemanager.cpp:176
folderarchiveagentjob.h
FolderArchiveAccountInfo::UniqueFolder
Definition: folderarchiveaccountinfo.h:32
FolderArchiveAgentJob::FolderArchiveAgentJob
FolderArchiveAgentJob(FolderArchiveManager *manager, FolderArchiveAccountInfo *info, const QList< Akonadi::Item > &lstItem, QObject *parent=0)
Definition: folderarchiveagentjob.cpp:32
KMCommand::Failed
Definition: kmcommands.h:53
kmcommands.h
folderarchivecache.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
FolderArchiveAgentCheckCollection
Definition: folderarchiveagentcheckcollection.h:25
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



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