21 #include <AkonadiCore/CollectionFetchJob>
22 #include <AkonadiCore/CollectionDeleteJob>
23 #include <KLocalizedString>
24 #include <KMessageBox>
27 #include "MailCommon/MailUtil"
28 #include "MailCommon/MailKernel"
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, &KJob::result,
this, &RemoveCollectionJob::slotDelayedRemoveFolder);
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 const auto col = 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>",
73 col.name().toHtmlEscaped());
74 buttonLabel = i18nc(
"@action:button Delete search",
"&Delete");
76 title = i18n(
"Delete Folder");
78 if (col.statistics().count() == 0) {
79 if (hasNotSubDirectory) {
80 str = i18n(
"<qt>Are you sure you want to delete the empty folder "
82 col.name().toHtmlEscaped());
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());
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());
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());
106 buttonLabel = i18nc(
"@action:button Delete folder",
"&Delete");
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);
120 Akonadi::CollectionDeleteJob *job =
new Akonadi::CollectionDeleteJob(col);
121 connect(job, &KJob::result,
this, &RemoveCollectionJob::slotDeletionCollectionResult);
127 void RemoveCollectionJob::slotDeletionCollectionResult(
KJob *job)
130 if (!MailCommon::Util::showJobErrorMessage(job)) {
void setMainWidget(KMMainWidget *mainWidget)
void setCurrentFolder(const Akonadi::Collection ¤tFolder)
void clearCurrentFolder()
RemoveCollectionJob(QObject *parent=nullptr)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Akonadi::Collection currentCollection() const