• 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
  • job
removecollectionjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014-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 "removecollectionjob.h"
19 #include <Akonadi/CollectionFetchJob>
20 #include <Akonadi/CollectionDeleteJob>
21 #include <KLocalizedString>
22 #include <KMessageBox>
23 #include <KGuiItem>
24 #include "kmmainwidget.h"
25 #include "mailcommon/util/mailutil.h"
26 #include "mailcommon/kernel/mailkernel.h"
27 #include "kmkernel.h"
28 
29 RemoveCollectionJob::RemoveCollectionJob(QObject *parent)
30  : QObject(parent)
31 {
32 
33 }
34 
35 RemoveCollectionJob::~RemoveCollectionJob()
36 {
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, SIGNAL(result(KJob*)), SLOT(slotDelayedRemoveFolder(KJob*)) );
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  Akonadi::Collection col = MailCommon::Util::updatedCollection(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  Qt::escape( col.name() ) );
74  buttonLabel = i18nc("@action:button Delete search", "&Delete");
75  } else {
76  title = i18n("Delete Folder");
77 
78 
79  if ( col.statistics().count() == 0 ) {
80  if ( hasNotSubDirectory ) {
81  str = i18n("<qt>Are you sure you want to delete the empty folder "
82  "<b>%1</b>?</qt>",
83  Qt::escape( col.name() ) );
84  } else {
85  str = i18n("<qt>Are you sure you want to delete the empty folder "
86  "<resource>%1</resource> and all its subfolders? Those subfolders might "
87  "not be empty and their contents will be discarded as well. "
88  "<p><b>Beware</b> that discarded messages are not saved "
89  "into your Trash folder and are permanently deleted.</p></qt>",
90  Qt::escape( col.name() ) );
91  }
92  } else {
93  if ( hasNotSubDirectory ) {
94  str = i18n("<qt>Are you sure you want to delete the folder "
95  "<resource>%1</resource>, discarding its contents? "
96  "<p><b>Beware</b> that discarded messages are not saved "
97  "into your Trash folder and are permanently deleted.</p></qt>",
98  Qt::escape( col.name() ) );
99  }else {
100  str = i18n("<qt>Are you sure you want to delete the folder <resource>%1</resource> "
101  "and all its subfolders, discarding their contents? "
102  "<p><b>Beware</b> that discarded messages are not saved "
103  "into your Trash folder and are permanently deleted.</p></qt>",
104  Qt::escape( col.name() ) );
105  }
106  }
107  buttonLabel = i18nc("@action:button Delete folder", "&Delete");
108  }
109 
110  if ( KMessageBox::warningContinueCancel( mMainWidget, str, title,
111  KGuiItem( buttonLabel, QLatin1String("edit-delete" )),
112  KStandardGuiItem::cancel(), QString(),
113  KMessageBox::Notify | KMessageBox::Dangerous )
114  == KMessageBox::Continue )
115  {
116  kmkernel->checkFolderFromResources( listOfCollection<<col );
117 
118  if (col.id() == mMainWidget->currentFolder()->collection().id()) {
119  Q_EMIT clearCurrentFolder();
120  }
121 
122  Akonadi::CollectionDeleteJob *job = new Akonadi::CollectionDeleteJob( col );
123  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotDeletionCollectionResult(KJob*)) );
124  } else {
125  deleteLater();
126  }
127 }
128 
129 void RemoveCollectionJob::slotDeletionCollectionResult(KJob* job)
130 {
131  if ( job ) {
132  MailCommon::Util::showJobErrorMessage( job );
133  }
134  deleteLater();
135 }
136 
137 
kmmainwidget.h
RemoveCollectionJob::RemoveCollectionJob
RemoveCollectionJob(QObject *parent=0)
Definition: removecollectionjob.cpp:29
removecollectionjob.h
RemoveCollectionJob::start
void start()
Definition: removecollectionjob.cpp:50
KMMainWidget::currentFolder
QSharedPointer< MailCommon::FolderCollection > currentFolder() const
Definition: kmmainwidget.cpp:4161
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:91
QObject::deleteLater
void deleteLater()
QString
kmkernel
#define kmkernel
Definition: kmkernel.h:24
QStringList
RemoveCollectionJob::~RemoveCollectionJob
~RemoveCollectionJob()
Definition: removecollectionjob.cpp:35
kmkernel.h
RemoveCollectionJob::clearCurrentFolder
void clearCurrentFolder()
QLatin1String
Qt::escape
QString escape(const QString &plain)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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