Mailcommon

filteractionmissingtagdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
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 <KWindowConfig>
15#include <QDialogButtonBox>
16#include <QLabel>
17#include <QListWidget>
18#include <QPointer>
19#include <QPushButton>
20#include <QVBoxLayout>
21#include <QWindow>
22
23using namespace MailCommon;
24namespace
25{
26static const char myFilterActionMissingTagDialogGroupName[] = "FilterActionMissingTagDialog";
27}
28
29FilterActionMissingTagDialog::FilterActionMissingTagDialog(const QMap<QUrl, QString> &tagList,
30 const QString &filtername,
31 const QString &argsStr,
32 QWidget *parent)
33 : QDialog(parent)
34 , mTagList(new QListWidget(this))
35{
36 setModal(true);
37 setWindowTitle(i18nc("@title:window", "Select Tag"));
38 auto mainLayout = new QVBoxLayout(this);
39
40 auto label = new QLabel(i18nc("@label:textbox", "Tag was \"%1\".", argsStr));
41 label->setObjectName(QLatin1StringView("tagnamelabel"));
42 mainLayout->addWidget(label);
43
44 label = new QLabel(this);
45 label->setObjectName(QLatin1StringView("filtername"));
46 label->setText(
47 i18n("Filter tag is missing. "
48 "Please select a tag to use with filter \"%1\"",
49 filtername));
50 label->setWordWrap(true);
51 mainLayout->addWidget(label);
52 mTagList->setObjectName(QLatin1StringView("taglist"));
53
55 const QMap<QUrl, QString>::const_iterator mapEnd = tagList.constEnd();
56 for (; map != mapEnd; ++map) {
57 auto item = new QListWidgetItem(map.value());
58 item->setData(UrlData, map.key().toString());
59 mTagList->addItem(item);
60 }
61
62 connect(mTagList, &QListWidget::itemDoubleClicked, this, &FilterActionMissingTagDialog::accept);
63 mainLayout->addWidget(mTagList);
64
66 buttonBox->setObjectName(QLatin1StringView("buttonbox"));
67 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
69 auto user1Button = new QPushButton(this);
70 user1Button->setObjectName(QLatin1StringView("addtag"));
71 user1Button->setText(i18n("Add Tag…"));
72 buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
73
74 connect(user1Button, &QPushButton::clicked, this, &FilterActionMissingTagDialog::slotAddTag);
75 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingTagDialog::accept);
76 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingTagDialog::reject);
77 mainLayout->addWidget(buttonBox);
78 okButton->setDefault(true);
79 readConfig();
80}
81
82FilterActionMissingTagDialog::~FilterActionMissingTagDialog()
83{
84 writeConfig();
85}
86
87void FilterActionMissingTagDialog::readConfig()
88{
89 create(); // ensure a window is created
90 windowHandle()->resize(QSize(500, 300));
91 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingTagDialogGroupName));
93 resize(windowHandle()->size()); // workaround for QTBUG-40584
94}
95
96void FilterActionMissingTagDialog::writeConfig()
97{
98 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingTagDialogGroupName));
100 group.sync();
101}
102
103QString FilterActionMissingTagDialog::selectedTag() const
104{
105 if (mTagList->currentItem()) {
106 return mTagList->currentItem()->data(UrlData).toString();
107 }
108 return {};
109}
110
111void FilterActionMissingTagDialog::slotAddTag()
112{
113 QPointer<MailCommon::AddTagDialog> dlg = new MailCommon::AddTagDialog(QList<KActionCollection *>(), this);
114 if (dlg->exec()) {
115 auto item = new QListWidgetItem(dlg->label());
116 item->setData(UrlData, dlg->tag().url().url());
117 mTagList->addItem(item);
118 }
119 delete dlg;
120}
121
122#include "moc_filteractionmissingtagdialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
The filter dialog.
void clicked(bool checked)
void setShortcut(const QKeySequence &key)
void addItem(QListWidgetItem *item)
QListWidgetItem * currentItem() const const
void itemDoubleClicked(QListWidgetItem *item)
virtual QVariant data(int role) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
void setDefault(bool)
Key_Return
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const
void create(WId window, bool initializeWindow, bool destroyOldWindow)
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:02:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.