Mailcommon

filteractionmissingaccountdialog.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 "filteractionmissingaccountdialog.h"
8#include "filter/kmfilteraccountlist.h"
9#include "util/mailutil.h"
10
11#include <KLocalizedString>
12#include <KSharedConfig>
13
14#include <KConfigGroup>
15#include <KWindowConfig>
16#include <QDialogButtonBox>
17#include <QLabel>
18#include <QPushButton>
19#include <QVBoxLayout>
20#include <QWindow>
21
22using namespace MailCommon;
23namespace
24{
25static const char myFilterActionMissingAccountDialogConfigGroupName[] = "FilterActionMissingAccountDialog";
26}
27
28FilterActionMissingAccountDialog::FilterActionMissingAccountDialog(const QStringList &lstAccount, const QString &filtername, QWidget *parent)
29 : QDialog(parent)
30 , mAccountList(new MailCommon::KMFilterAccountList(this))
31{
32 setModal(true);
33 setWindowTitle(i18nc("@title:window", "Select Account"));
34 auto mainLayout = new QVBoxLayout(this);
35
36 auto label = new QLabel(this);
37 label->setObjectName(QLatin1StringView("label"));
38 label->setText(
39 i18n("Filter account is missing. "
40 "Please select account to use with filter \"%1\"",
41 filtername));
42 label->setWordWrap(true);
43 mainLayout->addWidget(label);
44 mAccountList->setObjectName(QLatin1StringView("accountlist"));
45 mAccountList->applyOnAccount(lstAccount);
46 mainLayout->addWidget(mAccountList);
47
49 buttonBox->setObjectName(QLatin1StringView("buttonbox"));
50 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
51 okButton->setDefault(true);
53 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingAccountDialog::accept);
54 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingAccountDialog::reject);
55 mainLayout->addWidget(buttonBox);
56 readConfig();
57}
58
59FilterActionMissingAccountDialog::~FilterActionMissingAccountDialog()
60{
61 writeConfig();
62}
63
64void FilterActionMissingAccountDialog::readConfig()
65{
66 create(); // ensure a window is created
67 windowHandle()->resize(QSize(500, 300));
68 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingAccountDialogConfigGroupName));
70 resize(windowHandle()->size()); // workaround for QTBUG-40584
71}
72
73void FilterActionMissingAccountDialog::writeConfig()
74{
75 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingAccountDialogConfigGroupName));
77 group.sync();
78}
79
80QStringList FilterActionMissingAccountDialog::selectedAccount() const
81{
82 return mAccountList->selectedAccount();
83}
84
85bool FilterActionMissingAccountDialog::allAccountExist(const QStringList &lst)
86{
87 const Akonadi::AgentInstance::List lstAgent = MailCommon::Util::agentInstances();
88
89 const int numberOfAccount(lst.count());
90 const int numberOfAgent(lstAgent.count());
91
92 for (int i = 0; i < numberOfAccount; ++i) {
93 bool found = false;
94 const QString accountName(lst.at(i));
95 for (int j = 0; j < numberOfAgent; ++j) {
96 if (lstAgent.at(j).identifier() == accountName) {
97 found = true;
98 break;
99 }
100 }
101 if (!found) {
102 return false;
103 }
104 }
105 return true;
106}
107
108#include "moc_filteractionmissingaccountdialog.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 setShortcut(const QKeySequence &key)
const_reference at(qsizetype i) const const
qsizetype count() const const
void setDefault(bool)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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 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.