Mailcommon

filteractionmissingtagdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "filteractionmissingtagdialog.h"
8 #include <KLocalizedString>
9 #include <KSharedConfig>
10 
11 #include "tag/addtagdialog.h"
12 
13 #include <KConfigGroup>
14 #include <QDialogButtonBox>
15 #include <QLabel>
16 #include <QListWidget>
17 #include <QPointer>
18 #include <QPushButton>
19 #include <QVBoxLayout>
20 
21 using namespace MailCommon;
22 
23 FilterActionMissingTagDialog::FilterActionMissingTagDialog(const QMap<QUrl, QString> &tagList,
24  const QString &filtername,
25  const QString &argsStr,
26  QWidget *parent)
27  : QDialog(parent)
28  , mTagList(new QListWidget(this))
29 {
30  setModal(true);
31  setWindowTitle(i18nc("@title:window", "Select Tag"));
32  auto mainLayout = new QVBoxLayout(this);
33 
34  auto label = new QLabel(i18n("Tag was \"%1\".", argsStr));
35  label->setObjectName(QStringLiteral("tagnamelabel"));
36  mainLayout->addWidget(label);
37 
38  label = new QLabel(this);
39  label->setObjectName(QStringLiteral("filtername"));
40  label->setText(
41  i18n("Filter tag is missing. "
42  "Please select a tag to use with filter \"%1\"",
43  filtername));
44  label->setWordWrap(true);
45  mainLayout->addWidget(label);
46  mTagList->setObjectName(QStringLiteral("taglist"));
47 
49  const QMap<QUrl, QString>::const_iterator mapEnd = tagList.constEnd();
50  for (; map != mapEnd; ++map) {
51  auto item = new QListWidgetItem(map.value());
52  item->setData(UrlData, map.key().toString());
53  mTagList->addItem(item);
54  }
55 
56  connect(mTagList, &QListWidget::itemDoubleClicked, this, &FilterActionMissingTagDialog::accept);
57  mainLayout->addWidget(mTagList);
58 
60  buttonBox->setObjectName(QStringLiteral("buttonbox"));
61  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
63  auto user1Button = new QPushButton(this);
64  user1Button->setObjectName(QStringLiteral("addtag"));
65  user1Button->setText(i18n("Add Tag..."));
66  buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
67 
68  connect(user1Button, &QPushButton::clicked, this, &FilterActionMissingTagDialog::slotAddTag);
69  connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingTagDialog::accept);
70  connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingTagDialog::reject);
71  mainLayout->addWidget(buttonBox);
72  okButton->setDefault(true);
73  readConfig();
74 }
75 
76 FilterActionMissingTagDialog::~FilterActionMissingTagDialog()
77 {
78  writeConfig();
79 }
80 
81 void FilterActionMissingTagDialog::readConfig()
82 {
83  KConfigGroup group(KSharedConfig::openStateConfig(), "FilterActionMissingTagDialog");
84 
85  const QSize size = group.readEntry("Size", QSize(500, 300));
86  if (size.isValid()) {
87  resize(size);
88  }
89 }
90 
91 void FilterActionMissingTagDialog::writeConfig()
92 {
93  KConfigGroup group(KSharedConfig::openStateConfig(), "FilterActionMissingTagDialog");
94  group.writeEntry("Size", size());
95 }
96 
97 QString FilterActionMissingTagDialog::selectedTag() const
98 {
99  if (mTagList->currentItem()) {
100  return mTagList->currentItem()->data(UrlData).toString();
101  }
102  return {};
103 }
104 
105 void FilterActionMissingTagDialog::slotAddTag()
106 {
107  QPointer<MailCommon::AddTagDialog> dlg = new MailCommon::AddTagDialog(QList<KActionCollection *>(), this);
108  if (dlg->exec()) {
109  auto item = new QListWidgetItem(dlg->label());
110  item->setData(UrlData, dlg->tag().url().url());
111  mTagList->addItem(item);
112  }
113  delete dlg;
114 }
QMap::const_iterator constBegin() const const
bool isValid() const const
void setShortcut(const QKeySequence &key)
void clicked(bool checked)
void readConfig()
QString i18n(const char *text, const TYPE &arg...)
QMap::const_iterator constEnd() const const
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Key_Return
QString label(StandardShortcut id)
void itemDoubleClicked(QListWidgetItem *item)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
QChar * data()
QFuture< void > map(Sequence &sequence, MapFunctor function)
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:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.