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 "filteractionmissingtemplatedialog.h" 0008 0009 #include <KSharedConfig> 0010 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 #include <QComboBox> 0014 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 myFilterActionMissingTemplateDialogGroupName[] = "FilterActionMissingTemplateDialog"; 0026 } 0027 FilterActionMissingTemplateDialog::FilterActionMissingTemplateDialog(const QStringList &templateList, const QString &filtername, QWidget *parent) 0028 : QDialog(parent) 0029 , mComboBoxTemplate(new QComboBox(this)) 0030 { 0031 setModal(true); 0032 setWindowTitle(i18nc("@title:window", "Select Template")); 0033 auto mainLayout = new QVBoxLayout(this); 0034 0035 auto label = new QLabel(this); 0036 label->setObjectName(QLatin1StringView("label")); 0037 label->setText( 0038 i18n("Filter template is missing. " 0039 "Please select a template to use with filter \"%1\"", 0040 filtername)); 0041 label->setWordWrap(true); 0042 mainLayout->addWidget(label); 0043 mComboBoxTemplate->setObjectName(QLatin1StringView("comboboxtemplate")); 0044 mComboBoxTemplate->addItems(templateList); 0045 mainLayout->addWidget(mComboBoxTemplate); 0046 0047 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0048 buttonBox->setObjectName(QLatin1StringView("buttonbox")); 0049 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0050 okButton->setDefault(true); 0051 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0052 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingTemplateDialog::accept); 0053 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingTemplateDialog::reject); 0054 mainLayout->addWidget(buttonBox); 0055 readConfig(); 0056 } 0057 0058 FilterActionMissingTemplateDialog::~FilterActionMissingTemplateDialog() 0059 { 0060 writeConfig(); 0061 } 0062 0063 void FilterActionMissingTemplateDialog::readConfig() 0064 { 0065 create(); // ensure a window is created 0066 windowHandle()->resize(QSize(500, 300)); 0067 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingTemplateDialogGroupName)); 0068 KWindowConfig::restoreWindowSize(windowHandle(), group); 0069 resize(windowHandle()->size()); // workaround for QTBUG-40584 0070 } 0071 0072 void FilterActionMissingTemplateDialog::writeConfig() 0073 { 0074 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingTemplateDialogGroupName)); 0075 KWindowConfig::saveWindowSize(windowHandle(), group); 0076 group.sync(); 0077 } 0078 0079 QString FilterActionMissingTemplateDialog::selectedTemplate() const 0080 { 0081 if (mComboBoxTemplate->currentIndex() == 0) { 0082 return {}; 0083 } else { 0084 return mComboBoxTemplate->currentText(); 0085 } 0086 } 0087 0088 #include "moc_filteractionmissingtemplatedialog.cpp"