Mailcommon

filteractionmissingaccountdialog.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 "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 <QDialogButtonBox>
16 #include <QLabel>
17 #include <QPushButton>
18 #include <QVBoxLayout>
19 
20 using namespace MailCommon;
21 
22 FilterActionMissingAccountDialog::FilterActionMissingAccountDialog(const QStringList &lstAccount, const QString &filtername, QWidget *parent)
23  : QDialog(parent)
24  , mAccountList(new MailCommon::KMFilterAccountList(this))
25 {
26  setModal(true);
27  setWindowTitle(i18nc("@title:window", "Select Account"));
28  auto mainLayout = new QVBoxLayout(this);
29 
30  auto label = new QLabel(this);
31  label->setObjectName(QStringLiteral("label"));
32  label->setText(
33  i18n("Filter account is missing. "
34  "Please select account to use with filter \"%1\"",
35  filtername));
36  label->setWordWrap(true);
37  mainLayout->addWidget(label);
38  mAccountList->setObjectName(QStringLiteral("accountlist"));
39  mAccountList->applyOnAccount(lstAccount);
40  mainLayout->addWidget(mAccountList);
41 
43  buttonBox->setObjectName(QStringLiteral("buttonbox"));
44  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
45  okButton->setDefault(true);
46  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
47  connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingAccountDialog::accept);
48  connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingAccountDialog::reject);
49  mainLayout->addWidget(buttonBox);
50  readConfig();
51 }
52 
53 FilterActionMissingAccountDialog::~FilterActionMissingAccountDialog()
54 {
55  writeConfig();
56 }
57 
58 void FilterActionMissingAccountDialog::readConfig()
59 {
60  KConfigGroup group(KSharedConfig::openStateConfig(), "FilterActionMissingAccountDialog");
61 
62  const QSize size = group.readEntry("Size", QSize(500, 300));
63  if (size.isValid()) {
64  resize(size);
65  }
66 }
67 
68 void FilterActionMissingAccountDialog::writeConfig()
69 {
70  KConfigGroup group(KSharedConfig::openStateConfig(), "FilterActionMissingAccountDialog");
71  group.writeEntry("Size", size());
72 }
73 
74 QStringList FilterActionMissingAccountDialog::selectedAccount() const
75 {
76  return mAccountList->selectedAccount();
77 }
78 
79 bool FilterActionMissingAccountDialog::allAccountExist(const QStringList &lst)
80 {
81  const Akonadi::AgentInstance::List lstAgent = MailCommon::Util::agentInstances();
82 
83  const int numberOfAccount(lst.count());
84  const int numberOfAgent(lstAgent.count());
85 
86  for (int i = 0; i < numberOfAccount; ++i) {
87  bool found = false;
88  const QString accountName(lst.at(i));
89  for (int j = 0; j < numberOfAgent; ++j) {
90  if (lstAgent.at(j).identifier() == accountName) {
91  found = true;
92  break;
93  }
94  }
95  if (!found) {
96  return false;
97  }
98  }
99  return true;
100 }
bool isValid() const const
void setShortcut(const QKeySequence &key)
int count(const T &value) const const
void readConfig()
QString i18n(const char *text, const TYPE &arg...)
const T & at(int i) const const
const T & at(int i) const const
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Key_Return
QString label(StandardShortcut id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
int count(const T &value) 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:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.