File indexing completed on 2024-11-10 04:50:02
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 "filteractionmissingidentitydialog.h" 0008 #include "kernel/mailkernel.h" 0009 0010 #include <KConfigGroup> 0011 #include <KLocalizedString> 0012 #include <KSharedConfig> 0013 0014 #include <KWindowConfig> 0015 #include <QDialogButtonBox> 0016 #include <QLabel> 0017 #include <QPushButton> 0018 #include <QVBoxLayout> 0019 #include <QWindow> 0020 0021 #include <KIdentityManagementWidgets/IdentityCombo> 0022 0023 using namespace MailCommon; 0024 namespace 0025 { 0026 static const char myFilterActionMissingIdentityDialogConfigGroupName[] = "FilterActionMissingIdentityDialog"; 0027 } 0028 FilterActionMissingIdentityDialog::FilterActionMissingIdentityDialog(const QString &filtername, QWidget *parent) 0029 : QDialog(parent) 0030 { 0031 setModal(true); 0032 setWindowTitle(i18nc("@title:window", "Select Identity")); 0033 auto mainLayout = new QVBoxLayout(this); 0034 0035 auto label = new QLabel(this); 0036 label->setObjectName(QLatin1StringView("label")); 0037 label->setText( 0038 i18n("Filter identity is missing. " 0039 "Please select an identity to use with filter \"%1\"", 0040 filtername)); 0041 label->setWordWrap(true); 0042 mainLayout->addWidget(label); 0043 mComboBoxIdentity = new KIdentityManagementWidgets::IdentityCombo(KernelIf->identityManager(), this); 0044 mComboBoxIdentity->setObjectName(QLatin1StringView("comboboxidentity")); 0045 mainLayout->addWidget(mComboBoxIdentity); 0046 0047 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0048 buttonBox->setObjectName(QLatin1StringView("buttonbox")); 0049 0050 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0051 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0052 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingIdentityDialog::accept); 0053 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingIdentityDialog::reject); 0054 mainLayout->addWidget(buttonBox); 0055 okButton->setDefault(true); 0056 0057 readConfig(); 0058 } 0059 0060 FilterActionMissingIdentityDialog::~FilterActionMissingIdentityDialog() 0061 { 0062 writeConfig(); 0063 } 0064 0065 void FilterActionMissingIdentityDialog::readConfig() 0066 { 0067 create(); // ensure a window is created 0068 windowHandle()->resize(QSize(500, 300)); 0069 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingIdentityDialogConfigGroupName)); 0070 KWindowConfig::restoreWindowSize(windowHandle(), group); 0071 resize(windowHandle()->size()); // workaround for QTBUG-40584 0072 } 0073 0074 void FilterActionMissingIdentityDialog::writeConfig() 0075 { 0076 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingIdentityDialogConfigGroupName)); 0077 KWindowConfig::saveWindowSize(windowHandle(), group); 0078 group.sync(); 0079 } 0080 0081 int FilterActionMissingIdentityDialog::selectedIdentity() const 0082 { 0083 return mComboBoxIdentity->currentIdentity(); 0084 } 0085 0086 #include "moc_filteractionmissingidentitydialog.cpp"