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

kmail/src

  • kde-4.x
  • pim
  • kmail
  • src
  • job
removecollectionjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2019 Montel Laurent <[email protected]>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; see the file COPYING. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "removecollectionjob.h"
21 #include <AkonadiCore/CollectionFetchJob>
22 #include <AkonadiCore/CollectionDeleteJob>
23 #include <KLocalizedString>
24 #include <KMessageBox>
25 #include <KGuiItem>
26 #include "kmmainwidget.h"
27 #include "MailCommon/MailUtil"
28 #include "MailCommon/MailKernel"
29 #include "kmkernel.h"
30 
31 RemoveCollectionJob::RemoveCollectionJob(QObject *parent)
32  : QObject(parent)
33 {
34 }
35 
36 RemoveCollectionJob::~RemoveCollectionJob()
37 {
38 }
39 
40 void RemoveCollectionJob::setMainWidget(KMMainWidget *mainWidget)
41 {
42  mMainWidget = mainWidget;
43 }
44 
45 void RemoveCollectionJob::setCurrentFolder(const Akonadi::Collection &currentFolder)
46 {
47  mCurrentCollection = currentFolder;
48 }
49 
50 void RemoveCollectionJob::start()
51 {
52  Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(mCurrentCollection, Akonadi::CollectionFetchJob::FirstLevel, this);
53  job->fetchScope().setContentMimeTypes(QStringList() << KMime::Message::mimeType());
54  job->setProperty("collectionId", mCurrentCollection.id());
55  connect(job, &KJob::result, this, &RemoveCollectionJob::slotDelayedRemoveFolder);
56 }
57 
58 void RemoveCollectionJob::slotDelayedRemoveFolder(KJob *job)
59 {
60  const Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob *>(job);
61  Akonadi::Collection::List listOfCollection = fetchJob->collections();
62  const bool hasNotSubDirectory = listOfCollection.isEmpty();
63 
64  const Akonadi::Collection::Id id = fetchJob->property("collectionId").toLongLong();
65  const auto col = CommonKernel->collectionFromId(id);
66  QString str;
67  QString title;
68  QString buttonLabel;
69  if (col.resource() == QLatin1String("akonadi_search_resource")) {
70  title = i18n("Delete Search");
71  str = i18n("<qt>Are you sure you want to delete the search <b>%1</b>?<br />"
72  "Any messages it shows will still be available in their original folder.</qt>",
73  col.name().toHtmlEscaped());
74  buttonLabel = i18nc("@action:button Delete search", "&Delete");
75  } else {
76  title = i18n("Delete Folder");
77 
78  if (col.statistics().count() == 0) {
79  if (hasNotSubDirectory) {
80  str = i18n("<qt>Are you sure you want to delete the empty folder "
81  "<b>%1</b>?</qt>",
82  col.name().toHtmlEscaped());
83  } else {
84  str = i18n("<qt>Are you sure you want to delete the empty folder "
85  "<resource>%1</resource> and all its subfolders? Those subfolders might "
86  "not be empty and their contents will be discarded as well. "
87  "<p><b>Beware</b> that discarded messages are not saved "
88  "into your Trash folder and are permanently deleted.</p></qt>",
89  col.name().toHtmlEscaped());
90  }
91  } else {
92  if (hasNotSubDirectory) {
93  str = i18n("<qt>Are you sure you want to delete the folder "
94  "<resource>%1</resource>, discarding its contents? "
95  "<p><b>Beware</b> that discarded messages are not saved "
96  "into your Trash folder and are permanently deleted.</p></qt>",
97  col.name().toHtmlEscaped());
98  } else {
99  str = i18n("<qt>Are you sure you want to delete the folder <resource>%1</resource> "
100  "and all its subfolders, discarding their contents? "
101  "<p><b>Beware</b> that discarded messages are not saved "
102  "into your Trash folder and are permanently deleted.</p></qt>",
103  col.name().toHtmlEscaped());
104  }
105  }
106  buttonLabel = i18nc("@action:button Delete folder", "&Delete");
107  }
108 
109  if (KMessageBox::warningContinueCancel(mMainWidget, str, title,
110  KGuiItem(buttonLabel, QStringLiteral("edit-delete")),
111  KStandardGuiItem::cancel(), QString(),
112  KMessageBox::Notify | KMessageBox::Dangerous)
113  == KMessageBox::Continue) {
114  kmkernel->checkFolderFromResources(listOfCollection << col);
115 
116  if (col.id() == mMainWidget->currentCollection().id()) {
117  Q_EMIT clearCurrentFolder();
118  }
119 
120  Akonadi::CollectionDeleteJob *job = new Akonadi::CollectionDeleteJob(col);
121  connect(job, &KJob::result, this, &RemoveCollectionJob::slotDeletionCollectionResult);
122  } else {
123  deleteLater();
124  }
125 }
126 
127 void RemoveCollectionJob::slotDeletionCollectionResult(KJob *job)
128 {
129  if (job) {
130  if (!MailCommon::Util::showJobErrorMessage(job)) {
131  //TODO
132  }
133  }
134  deleteLater();
135 }
kmmainwidget.h
removecollectionjob.h
RemoveCollectionJob::start
void start()
Definition: removecollectionjob.cpp:50
RemoveCollectionJob::setMainWidget
void setMainWidget(KMMainWidget *mainWidget)
Definition: removecollectionjob.cpp:40
RemoveCollectionJob::setCurrentFolder
void setCurrentFolder(const Akonadi::Collection &currentFolder)
Definition: removecollectionjob.cpp:45
QObject
KMMainWidget
Definition: kmmainwidget.h:97
QObject::deleteLater
void deleteLater()
QString
kmkernel
#define kmkernel
Definition: kmkernel.h:21
QStringList
RemoveCollectionJob::~RemoveCollectionJob
~RemoveCollectionJob()
Definition: removecollectionjob.cpp:36
kmkernel.h
RemoveCollectionJob::clearCurrentFolder
void clearCurrentFolder()
RemoveCollectionJob::RemoveCollectionJob
RemoveCollectionJob(QObject *parent=nullptr)
Definition: removecollectionjob.cpp:31
QLatin1String
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KMMainWidget::currentCollection
Akonadi::Collection currentCollection() const
Definition: kmmainwidget.cpp:978
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Sun Dec 15 2019 02:44:44 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail/src

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

pim API Reference

Skip menu "pim API Reference"
  • akonadi-calendar-tools
  •   konsolekalendar
  • akregator
  •   src
  • kalarmcal
  •   src
  •     lib
  • kdepim-runtime
  •   agents
  •   src
  • kleopatra
  •   src
  • kmailtransport
  • knotes
  • kontact
  • kontactinterface
  • kpimtextedit
  • ksmtp
  • ktnef
  • libkgapi
  • libkleo
  •   src
  •     src
  •     src

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