Mailcommon

filteractionwithfolder.cpp
1 /*
2  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <[email protected]>
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 
18 using 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(QStringLiteral("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 
85 QString 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() + QLatin1String(" \"") + result.toHtmlEscaped() + QLatin1String("\"");
122 }
123 
125 {
126  if (oldFolder == mFolder) {
127  mFolder = newFolder;
128  return true;
129  } else {
130  return false;
131  }
132 }
QString number(int n, int base)
QString toHtmlEscaped() const const
void applyParamWidgetValue(QWidget *paramWidget) override
The filter action shall set it's parameter from the widget's contents.
qlonglong toLongLong(bool *ok, int base) const const
void setParamWidgetValue(QWidget *paramWidget) const override
The filter action shall set it's widget's contents from it's parameter.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString displayString() const override
Returns a translated string describing this filter for visualization purposes, e.g.
QString name() const
Returns identifier name, ie.
Abstract base class for mail filter actions.
Definition: filteraction.h:38
const T & at(int i) const const
QString label() const
Returns i18n'd label, ie.
void filterActionModified()
Called to notify that the current FilterAction has had some value modification.
FilterActionWithFolder(const QString &name, const QString &label, QObject *parent=nullptr)
Creates a new filter action.
bool folderRemoved(const Akonadi::Collection &aFolder, const Akonadi::Collection &aNewFolder) override
Called from the filter when a folder is removed.
bool argsFromStringInteractive(const QString &argsStr, const QString &filterName) override
Read extra arguments from given string.
QWidget * createParamWidget(QWidget *parent) const override
Creates a widget for setting the filter action parameter.
int count(const T &value) const const
void clearParamWidget(QWidget *paramWidget) const override
The filter action shall clear it's parameter widget's contents.
bool isValid() const
QString argsAsString() const override
Return extra arguments as string.
bool isEmpty() const override
Determines whether this action is valid.
void argsFromString(const QString &argsStr) override
Read extra arguments from given string.
QObject * parent() const const
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.