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