8#include "folderrequester.h"
9#include "folderselectiondialog.h"
10#include "kernel/mailkernel.h"
11#include "util/mailutil.h"
12#include <Akonadi/CollectionFetchJob>
13#include <KLineEditEventHandler>
15#include <KLocalizedString>
26class MailCommon::FolderRequesterPrivate
31 QString mSelectFolderTitleDialog;
32 bool mMustBeReadWrite =
false;
33 bool mShowOutbox =
false;
34 bool mNotCreateNewFolder =
false;
35 Akonadi::AccountActivitiesAbstract *mAccountActivities =
nullptr;
38FolderRequester::FolderRequester(
QWidget *parent)
43 hlay->setContentsMargins({});
46 d->mEdit->setPlaceholderText(
i18nc(
"@info:placeholder",
"Select Folder"));
48 d->mEdit->setReadOnly(
true);
49 hlay->addWidget(d->mEdit);
53 hlay->addWidget(button);
61void FolderRequester::slotOpenDialog()
64 options |= FolderSelectionDialog::HideVirtualFolder;
65 options |= FolderSelectionDialog::NotUseGlobalSettings;
66 if (d->mNotCreateNewFolder) {
67 options |= FolderSelectionDialog::NotAllowToCreateNewFolder;
69 if (!d->mShowOutbox) {
70 options |= FolderSelectionDialog::HideOutboxFolder;
74 dlg->setWindowTitle(d->mSelectFolderTitleDialog.isEmpty() ?
i18nc(
"@title:window",
"Select Folder") : d->mSelectFolderTitleDialog);
76 dlg->setSelectedCollection(d->mCollection);
77 dlg->setAccountActivities(d->mAccountActivities);
79 if (dlg->exec() && dlg) {
80 setCollection(dlg->selectedCollection(),
false);
86FolderRequester::~FolderRequester() =
default;
90 return d->mCollection;
95 if (KernelIf->collectionModel()) {
96 d->mEdit->setText(Util::fullCollectionPath(col));
102void setAccountActivities(Akonadi::AccountActivitiesAbstract *accountActivities);
105void FolderRequester::setCollection(
const Akonadi::Collection &collection,
bool fetchCollection)
107 d->mCollection = collection;
108 if (d->mCollection.isValid()) {
109 if (fetchCollection) {
112 connect(job, &Akonadi::CollectionFetchJob::result,
this, &FolderRequester::slotCollectionsReceived);
114 setCollectionFullPath(d->mCollection);
116 }
else if (!d->mMustBeReadWrite) {
117 d->mEdit->setText(
i18n(
"Local Folders"));
120 Q_EMIT folderChanged(d->mCollection);
123void FolderRequester::slotCollectionsReceived(
KJob *job)
127 d->mEdit->setText(
i18n(
"Please select a folder"));
138 if (collection.
id() == d->mCollection.id()) {
139 d->mCollection = collection;
140 setCollectionFullPath(collection);
145 d->mEdit->setText(
i18n(
"Please select a folder"));
150bool FolderRequester::hasCollection()
const
152 return d->mCollection.isValid();
156void FolderRequester::keyPressEvent(
QKeyEvent *e)
165void FolderRequester::setMustBeReadWrite(
bool readwrite)
167 d->mMustBeReadWrite = readwrite;
170void FolderRequester::setShowOutbox(
bool show)
172 d->mShowOutbox =
show;
175void FolderRequester::setNotAllowToCreateNewFolder(
bool notCreateNewFolder)
177 d->mNotCreateNewFolder = notCreateNewFolder;
180void FolderRequester::setSelectFolderTitleDialog(
const QString &title)
182 d->mSelectFolderTitleDialog = title;
185void FolderRequester::setAccountActivities(Akonadi::AccountActivitiesAbstract *accountActivities)
187 d->mAccountActivities = accountActivities;
190#include "moc_folderrequester.cpp"
Collection::List collections() const
A dialog that lets the user select a folder.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
QIcon fromTheme(const QString &name)
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)