Mailcommon

filteractionwithfolder.cpp
1/*
2 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 */
7
8#include "filteractionwithfolder.h"
9
10#include "filter/dialog/filteractionmissingfolderdialog.h"
11#include "filter/filterimporterpathcache.h"
12#include "folder/folderrequester.h"
13#include "kernel/mailkernel.h"
14#include "util/mailutil.h"
15
16#include <QPointer>
17
18using namespace MailCommon;
19
21 : FilterAction(name, label, parent)
22{
23}
24
26{
27 return !mFolder.isValid();
28}
29
31{
32 auto requester = new FolderRequester(parent);
33 requester->setShowOutbox(false);
34 setParamWidgetValue(requester);
35 requester->setObjectName(QLatin1StringView("folderrequester"));
36
37 connect(requester, &FolderRequester::folderChanged, this, &FilterActionWithFolder::filterActionModified);
38
39 return requester;
40}
41
43{
44 mFolder = static_cast<FolderRequester *>(paramWidget)->collection();
45}
46
48{
49 static_cast<FolderRequester *>(paramWidget)->setCollection(mFolder);
50}
51
53{
54 static_cast<FolderRequester *>(paramWidget)->setCollection(CommonKernel->draftsCollectionFolder());
55}
56
58{
59 bool needUpdate = false;
60 argsFromString(argsStr);
61 if (!mFolder.isValid()) {
62 bool exactPath = false;
63 const Akonadi::Collection::List lst = FilterActionMissingFolderDialog::potentialCorrectFolders(argsStr, exactPath);
64 if (lst.count() == 1 && exactPath) {
65 mFolder = lst.at(0);
66 } else {
67 const Akonadi::Collection newCol = MailCommon::FilterImporterPathCache::self()->convertedFilterPath(argsStr);
68 if (!newCol.isValid()) {
69 QPointer<FilterActionMissingFolderDialog> dlg = new FilterActionMissingFolderDialog(lst, name, argsStr);
70 if (dlg->exec()) {
71 mFolder = dlg->selectedCollection();
72 needUpdate = true;
73 MailCommon::FilterImporterPathCache::self()->insert(argsStr, mFolder);
74 }
75 delete dlg;
76 } else {
77 mFolder = newCol;
78 needUpdate = true;
79 }
80 }
81 }
82 return needUpdate;
83}
84
85QString FilterActionWithFolder::argsAsStringReal() const
86{
87 if (KernelIf->collectionModel()) {
88 return MailCommon::Util::fullCollectionPath(mFolder);
89 }
91}
92
94{
95 bool ok = false;
96 const Akonadi::Collection::Id id = argsStr.toLongLong(&ok);
97 if (ok) {
98 mFolder = Akonadi::Collection(id);
99 } else {
100 mFolder = Akonadi::Collection();
101 }
102}
103
105{
106 QString result;
107 if (mFolder.isValid()) {
108 result = QString::number(mFolder.id());
109 }
110
111 return result;
112}
113
115{
116 QString result;
117 if (mFolder.isValid()) {
118 result = MailCommon::Util::fullCollectionPath(CommonKernel->collectionFromId(mFolder.id()));
119 }
120
121 return label() + QLatin1StringView(" \"") + result.toHtmlEscaped() + QLatin1StringView("\"");
122}
123
125{
126 if (oldFolder == mFolder) {
127 mFolder = newFolder;
128 return true;
129 } else {
130 return false;
131 }
132}
133
134#include "moc_filteractionwithfolder.cpp"
bool isValid() const
void argsFromString(const QString &argsStr) override
Read extra arguments from given string.
void applyParamWidgetValue(QWidget *paramWidget) override
The filter action shall set it's parameter from the widget's contents.
void clearParamWidget(QWidget *paramWidget) const override
The filter action shall clear it's parameter widget's contents.
bool folderRemoved(const Akonadi::Collection &aFolder, const Akonadi::Collection &aNewFolder) override
Called from the filter when a folder is removed.
QString displayString() const override
Returns a translated string describing this filter for visualization purposes, e.g.
void setParamWidgetValue(QWidget *paramWidget) const override
The filter action shall set it's widget's contents from it's parameter.
bool isEmpty() const override
Determines whether this action is valid.
FilterActionWithFolder(const QString &name, const QString &label, QObject *parent=nullptr)
Creates a new filter action.
QWidget * createParamWidget(QWidget *parent) const override
Creates a widget for setting the filter action parameter.
QString argsAsString() const override
Return extra arguments as string.
bool argsFromStringInteractive(const QString &argsStr, const QString &filterName) override
Read extra arguments from given string.
Abstract base class for mail filter actions.
QString name() const
Returns identifier name, ie.
void filterActionModified()
Called to notify that the current FilterAction has had some value modification.
QString label() const
Returns i18n'd label, ie.
The filter dialog.
const_reference at(qsizetype i) const const
qsizetype count() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString number(double n, char format, int precision)
QString toHtmlEscaped() const const
qlonglong toLongLong(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.