19 #include <Akonadi/CollectionFetchJob>
20 #include <Akonadi/CollectionDeleteJob>
21 #include <KLocalizedString>
22 #include <KMessageBox>
25 #include "mailcommon/util/mailutil.h"
26 #include "mailcommon/kernel/mailkernel.h"
42 mMainWidget = mainWidget;
47 mCurrentCollection = currentFolder;
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*)) );
58 void RemoveCollectionJob::slotDelayedRemoveFolder(
KJob *job )
60 const Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
61 Akonadi::Collection::List listOfCollection = fetchJob->collections();
62 const bool hasNotSubDirectory = listOfCollection.isEmpty();
64 const Akonadi::Collection::Id
id = fetchJob->property(
"collectionId" ).toLongLong();
65 Akonadi::Collection col = MailCommon::Util::updatedCollection(CommonKernel->collectionFromId(
id ));
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>",
74 buttonLabel = i18nc(
"@action:button Delete search",
"&Delete");
76 title = i18n(
"Delete Folder");
79 if ( col.statistics().count() == 0 ) {
80 if ( hasNotSubDirectory ) {
81 str = i18n(
"<qt>Are you sure you want to delete the empty folder "
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>",
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>",
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>",
107 buttonLabel = i18nc(
"@action:button Delete folder",
"&Delete");
110 if ( KMessageBox::warningContinueCancel( mMainWidget, str, title,
112 KStandardGuiItem::cancel(),
QString(),
113 KMessageBox::Notify | KMessageBox::Dangerous )
114 == KMessageBox::Continue )
116 kmkernel->checkFolderFromResources( listOfCollection<<col );
118 if (col.id() == mMainWidget->
currentFolder()->collection().id()) {
122 Akonadi::CollectionDeleteJob *job =
new Akonadi::CollectionDeleteJob( col );
123 connect( job, SIGNAL(result(
KJob*)),
this, SLOT(slotDeletionCollectionResult(
KJob*)) );
129 void RemoveCollectionJob::slotDeletionCollectionResult(
KJob* job)
132 MailCommon::Util::showJobErrorMessage( job );
RemoveCollectionJob(QObject *parent=0)
QSharedPointer< MailCommon::FolderCollection > currentFolder() const
void setMainWidget(KMMainWidget *mainWidget)
void setCurrentFolder(const Akonadi::Collection ¤tFolder)
void clearCurrentFolder()
QString escape(const QString &plain)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)