Better wording
[kdepim.git] / archivemailagent / archivemailmanager.cpp
blobce084100bbb6d6f2f3b1bc813b22ec0bfd0044f5
1 /*
2 Copyright (c) 2012 Montel Laurent <montel@kde.org>
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.
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.
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
18 #include "archivemailmanager.h"
19 #include "archivemailinfo.h"
20 #include "archivejob.h"
21 #include "archivemailkernel.h"
22 #include "archivemailagentutil.h"
24 #include <mailcommon/mailkernel.h>
26 #include <Akonadi/Collection>
28 #include <KConfigGroup>
29 #include <KSharedConfig>
30 #include <KGlobal>
32 #include <QDate>
34 static QString archivePattern = QLatin1String("ArchiveMailCollection %1");
36 ArchiveMailManager::ArchiveMailManager(QObject *parent)
37 : QObject( parent )
39 mArchiveMailKernel = new ArchiveMailKernel( this );
40 CommonKernel->registerKernelIf( mArchiveMailKernel ); //register KernelIf early, it is used by the Filter classes
41 CommonKernel->registerSettingsIf( mArchiveMailKernel ); //SettingsIf is used in FolderTreeWidget
44 ArchiveMailManager::~ArchiveMailManager()
46 qDeleteAll(mListArchiveInfo);
49 void ArchiveMailManager::load()
51 qDeleteAll(mListArchiveInfo);
52 mListArchiveInfo.clear();
54 KSharedConfig::Ptr config = KGlobal::config();
55 const QStringList collectionList = config->groupList().filter( QRegExp( "ArchiveMailCollection \\d+" ) );
56 const int numberOfCollection = collectionList.count();
57 for(int i = 0 ; i < numberOfCollection; ++i) {
58 KConfigGroup group = config->group(collectionList.at(i));
59 ArchiveMailInfo *info = new ArchiveMailInfo(group);
61 const QDate diffDate = ArchiveMailAgentUtil::diffDate(info);
62 if(QDate::currentDate() >= diffDate) {
63 Q_FOREACH(ArchiveMailInfo*oldInfo,mListArchiveInfo) {
64 if(oldInfo->saveCollectionId() == info->saveCollectionId()) {
65 //already in jobscheduler
66 delete info;
67 info = 0;
68 break;
71 if(info) {
72 //Store task started
73 mListArchiveInfo.append(info);
74 ScheduledArchiveTask *task = new ScheduledArchiveTask( this, info,Akonadi::Collection(info->saveCollectionId()), /*immediate*/false );
75 mArchiveMailKernel->jobScheduler()->registerTask( task );
77 } else {
78 delete info;
83 void ArchiveMailManager::removeCollection(const Akonadi::Collection& collection)
85 KSharedConfig::Ptr config = KGlobal::config();
86 const QString groupname = archivePattern.arg(collection.id());
87 if(config->hasGroup(groupname)) {
88 KConfigGroup group = config->group(groupname);
89 group.deleteGroup();
90 config->sync();
91 Q_FOREACH(ArchiveMailInfo *info, mListArchiveInfo) {
92 if(info->saveCollectionId() == collection.id()) {
93 mListArchiveInfo.removeAll(info);
99 void ArchiveMailManager::backupDone(ArchiveMailInfo *info)
101 info->setLastDateSaved(QDate::currentDate());
102 KSharedConfig::Ptr config = KGlobal::config();
103 const QString groupname = archivePattern.arg(info->saveCollectionId());
104 //Don't store it if we removed this task
105 if(config->hasGroup(groupname)) {
106 KConfigGroup group = config->group(groupname);
107 info->writeConfig(group);
109 mListArchiveInfo.removeAll(info);
112 void ArchiveMailManager::pause()
114 mArchiveMailKernel->jobScheduler()->pause();
117 void ArchiveMailManager::resume()
119 mArchiveMailKernel->jobScheduler()->resume();
123 #include "archivemailmanager.moc"