• 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
folderarchiveagentcheckcollection.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 "folderarchiveagentcheckcollection.h"
19 #include "folderarchiveaccountinfo.h"
20 
21 #include <KLocale>
22 
23 #include <Akonadi/CollectionFetchJob>
24 #include <Akonadi/CollectionCreateJob>
25 #include <QDate>
26 
27 
28 FolderArchiveAgentCheckCollection::FolderArchiveAgentCheckCollection(FolderArchiveAccountInfo *info, QObject *parent)
29  : QObject(parent),
30  mCurrentDate(QDate::currentDate()),
31  mInfo(info)
32 {
33 }
34 
35 FolderArchiveAgentCheckCollection::~FolderArchiveAgentCheckCollection()
36 {
37 }
38 
39 void FolderArchiveAgentCheckCollection::start()
40 {
41  Akonadi::Collection col(mInfo->archiveTopLevel());
42 #if 0
43  if (mInfo->keepExistingStructure()) {
44  Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(col, Akonadi::CollectionFetchJob::Recursive);
45  connect(job, SIGNAL(result(KJob*)), this, SLOT(slotInitialCollectionFetchingDone(KJob*)) );
46  } else {
47 #endif
48  Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(col, Akonadi::CollectionFetchJob::FirstLevel);
49  connect(job, SIGNAL(result(KJob*)), this, SLOT(slotInitialCollectionFetchingFirstLevelDone(KJob*)) );
50 #if 0
51  }
52 #endif
53 }
54 
55 #if 0
56 void FolderArchiveAgentCheckCollection::slotInitialCollectionFetchingDone(KJob *job)
57 {
58 #if 0
59  if ( job->error() ) {
60  qWarning() << job->errorString();
61  Q_EMIT checkFailed(QString());
62  return;
63  }
64 
65  //TODO
66  Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
67 
68  foreach ( const Akonadi::Collection &collection, fetchJob->collections() ) {
69 
70  }
71 #endif
72 }
73 #endif
74 
75 void FolderArchiveAgentCheckCollection::slotInitialCollectionFetchingFirstLevelDone(KJob *job)
76 {
77  if ( job->error() ) {
78  qWarning() << job->errorString();
79  Q_EMIT checkFailed(i18n("Cannot fetch collection. %1", job->errorString()));
80  return;
81  }
82 
83  QString folderName;
84  switch(mInfo->folderArchiveType()) {
85  case FolderArchiveAccountInfo::UniqueFolder:
86  //Nothing
87  break;
88  case FolderArchiveAccountInfo::FolderByMonths:
89  //TODO translate ?
90  folderName = QString::fromLatin1("%1-%2").arg(mCurrentDate.month()).arg(mCurrentDate.year());
91  break;
92  case FolderArchiveAccountInfo::FolderByYears:
93  folderName = QString::fromLatin1("%1").arg(mCurrentDate.year());
94  break;
95  }
96 
97  if (folderName.isEmpty()) {
98  Q_EMIT checkFailed(i18n("Folder name not defined."));
99  return;
100  }
101 
102  Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
103 
104  foreach ( const Akonadi::Collection &collection, fetchJob->collections() ) {
105  if (collection.name() == folderName) {
106  Q_EMIT collectionIdFound(collection);
107  return;
108  }
109  }
110  createNewFolder(folderName);
111 }
112 
113 void FolderArchiveAgentCheckCollection::createNewFolder(const QString &name)
114 {
115  Akonadi::Collection parentCollection(mInfo->archiveTopLevel());
116  Akonadi::Collection collection;
117  collection.setParentCollection( parentCollection );
118  collection.setName( name );
119  collection.setContentMimeTypes( QStringList() << QLatin1String( "message/rfc822" ) );
120 
121  Akonadi::CollectionCreateJob *job = new Akonadi::CollectionCreateJob( collection );
122  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotCreateNewFolder(KJob*)) );
123 }
124 
125 void FolderArchiveAgentCheckCollection::slotCreateNewFolder(KJob *job)
126 {
127  if ( job->error() ) {
128  qWarning() << job->errorString();
129  Q_EMIT checkFailed(i18n("Unable to create folder. %1", job->errorString()));
130  return;
131  }
132  Akonadi::CollectionCreateJob *createJob = qobject_cast<Akonadi::CollectionCreateJob*>( job );
133  Q_EMIT collectionIdFound(createJob->collection());
134 }
135 
FolderArchiveAccountInfo::folderArchiveType
FolderArchiveType folderArchiveType() const
Definition: folderarchiveaccountinfo.cpp:53
FolderArchiveAccountInfo::FolderByMonths
Definition: folderarchiveaccountinfo.h:33
FolderArchiveAgentCheckCollection::checkFailed
void checkFailed(const QString &message)
FolderArchiveAccountInfo::FolderByYears
Definition: folderarchiveaccountinfo.h:34
QDate::month
int month() const
folderarchiveaccountinfo.h
folderarchiveagentcheckcollection.h
QObject
FolderArchiveAgentCheckCollection::FolderArchiveAgentCheckCollection
FolderArchiveAgentCheckCollection(FolderArchiveAccountInfo *info, QObject *parent=0)
Definition: folderarchiveagentcheckcollection.cpp:28
QString::isEmpty
bool isEmpty() const
QDate
FolderArchiveAgentCheckCollection::collectionIdFound
void collectionIdFound(const Akonadi::Collection &col)
QDate::year
int year() const
QString
FolderArchiveAccountInfo::archiveTopLevel
Akonadi::Collection::Id archiveTopLevel() const
Definition: folderarchiveaccountinfo.cpp:63
FolderArchiveAccountInfo
Definition: folderarchiveaccountinfo.h:24
QStringList
FolderArchiveAgentCheckCollection::start
void start()
Definition: folderarchiveagentcheckcollection.cpp:39
QLatin1String
FolderArchiveAccountInfo::UniqueFolder
Definition: folderarchiveaccountinfo.h:32
FolderArchiveAccountInfo::keepExistingStructure
bool keepExistingStructure() const
Definition: folderarchiveaccountinfo.cpp:93
QString::fromLatin1
QString fromLatin1(const char *str, int size)
FolderArchiveAgentCheckCollection::~FolderArchiveAgentCheckCollection
~FolderArchiveAgentCheckCollection()
Definition: folderarchiveagentcheckcollection.cpp:35
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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