File indexing completed on 2024-11-10 04:50:01
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "filteractionmissingaccountdialog.h" 0008 #include "filter/kmfilteraccountlist.h" 0009 #include "util/mailutil.h" 0010 0011 #include <KLocalizedString> 0012 #include <KSharedConfig> 0013 0014 #include <KConfigGroup> 0015 #include <KWindowConfig> 0016 #include <QDialogButtonBox> 0017 #include <QLabel> 0018 #include <QPushButton> 0019 #include <QVBoxLayout> 0020 #include <QWindow> 0021 0022 using namespace MailCommon; 0023 namespace 0024 { 0025 static const char myFilterActionMissingAccountDialogConfigGroupName[] = "FilterActionMissingAccountDialog"; 0026 } 0027 0028 FilterActionMissingAccountDialog::FilterActionMissingAccountDialog(const QStringList &lstAccount, const QString &filtername, QWidget *parent) 0029 : QDialog(parent) 0030 , mAccountList(new MailCommon::KMFilterAccountList(this)) 0031 { 0032 setModal(true); 0033 setWindowTitle(i18nc("@title:window", "Select Account")); 0034 auto mainLayout = new QVBoxLayout(this); 0035 0036 auto label = new QLabel(this); 0037 label->setObjectName(QLatin1StringView("label")); 0038 label->setText( 0039 i18n("Filter account is missing. " 0040 "Please select account to use with filter \"%1\"", 0041 filtername)); 0042 label->setWordWrap(true); 0043 mainLayout->addWidget(label); 0044 mAccountList->setObjectName(QLatin1StringView("accountlist")); 0045 mAccountList->applyOnAccount(lstAccount); 0046 mainLayout->addWidget(mAccountList); 0047 0048 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0049 buttonBox->setObjectName(QLatin1StringView("buttonbox")); 0050 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0051 okButton->setDefault(true); 0052 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0053 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingAccountDialog::accept); 0054 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingAccountDialog::reject); 0055 mainLayout->addWidget(buttonBox); 0056 readConfig(); 0057 } 0058 0059 FilterActionMissingAccountDialog::~FilterActionMissingAccountDialog() 0060 { 0061 writeConfig(); 0062 } 0063 0064 void FilterActionMissingAccountDialog::readConfig() 0065 { 0066 create(); // ensure a window is created 0067 windowHandle()->resize(QSize(500, 300)); 0068 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingAccountDialogConfigGroupName)); 0069 KWindowConfig::restoreWindowSize(windowHandle(), group); 0070 resize(windowHandle()->size()); // workaround for QTBUG-40584 0071 } 0072 0073 void FilterActionMissingAccountDialog::writeConfig() 0074 { 0075 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingAccountDialogConfigGroupName)); 0076 KWindowConfig::saveWindowSize(windowHandle(), group); 0077 group.sync(); 0078 } 0079 0080 QStringList FilterActionMissingAccountDialog::selectedAccount() const 0081 { 0082 return mAccountList->selectedAccount(); 0083 } 0084 0085 bool FilterActionMissingAccountDialog::allAccountExist(const QStringList &lst) 0086 { 0087 const Akonadi::AgentInstance::List lstAgent = MailCommon::Util::agentInstances(); 0088 0089 const int numberOfAccount(lst.count()); 0090 const int numberOfAgent(lstAgent.count()); 0091 0092 for (int i = 0; i < numberOfAccount; ++i) { 0093 bool found = false; 0094 const QString accountName(lst.at(i)); 0095 for (int j = 0; j < numberOfAgent; ++j) { 0096 if (lstAgent.at(j).identifier() == accountName) { 0097 found = true; 0098 break; 0099 } 0100 } 0101 if (!found) { 0102 return false; 0103 } 0104 } 0105 return true; 0106 } 0107 0108 #include "moc_filteractionmissingaccountdialog.cpp"