File indexing completed on 2024-11-10 04:50:02
0001 /* 0002 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "selectthunderbirdfilterfilesdialog.h" 0008 #include "selectthunderbirdfilterfileswidget.h" 0009 #include <KLocalizedString> 0010 #include <KSharedConfig> 0011 0012 #include <KConfigGroup> 0013 #include <KWindowConfig> 0014 #include <QDialogButtonBox> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 #include <QWindow> 0018 0019 using namespace MailCommon; 0020 namespace 0021 { 0022 static const char mySelectThunderbirdFilterFilesDialogGroupName[] = "SelectThunderbirdFilterFilesDialog"; 0023 } 0024 SelectThunderbirdFilterFilesDialog::SelectThunderbirdFilterFilesDialog(const QString &defaultSettingPath, QWidget *parent) 0025 : QDialog(parent) 0026 , mSelectFilterFilesWidget(new MailCommon::SelectThunderbirdFilterFilesWidget(defaultSettingPath, this)) 0027 { 0028 setWindowTitle(i18nc("@title:window", "Select thunderbird filter files")); 0029 setModal(true); 0030 auto mainLayout = new QVBoxLayout(this); 0031 0032 mainLayout->addWidget(mSelectFilterFilesWidget); 0033 0034 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0035 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0036 okButton->setDefault(true); 0037 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0038 connect(buttonBox, &QDialogButtonBox::accepted, this, &SelectThunderbirdFilterFilesDialog::accept); 0039 connect(buttonBox, &QDialogButtonBox::rejected, this, &SelectThunderbirdFilterFilesDialog::reject); 0040 connect(mSelectFilterFilesWidget, &MailCommon::SelectThunderbirdFilterFilesWidget::enableOkButton, okButton, &QPushButton::setEnabled); 0041 okButton->setEnabled(false); 0042 mainLayout->addWidget(buttonBox); 0043 readConfig(); 0044 } 0045 0046 SelectThunderbirdFilterFilesDialog::~SelectThunderbirdFilterFilesDialog() 0047 { 0048 writeConfig(); 0049 } 0050 0051 QStringList SelectThunderbirdFilterFilesDialog::selectedFiles() const 0052 { 0053 return mSelectFilterFilesWidget->selectedFiles(); 0054 } 0055 0056 void SelectThunderbirdFilterFilesDialog::setStartDir(const QUrl &url) 0057 { 0058 mSelectFilterFilesWidget->setStartDir(url); 0059 } 0060 0061 void SelectThunderbirdFilterFilesDialog::readConfig() 0062 { 0063 create(); // ensure a window is created 0064 windowHandle()->resize(QSize(500, 300)); 0065 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySelectThunderbirdFilterFilesDialogGroupName)); 0066 KWindowConfig::restoreWindowSize(windowHandle(), group); 0067 resize(windowHandle()->size()); // workaround for QTBUG-40584 0068 } 0069 0070 void SelectThunderbirdFilterFilesDialog::writeConfig() 0071 { 0072 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySelectThunderbirdFilterFilesDialogGroupName)); 0073 KWindowConfig::saveWindowSize(windowHandle(), group); 0074 group.sync(); 0075 } 0076 0077 #include "moc_selectthunderbirdfilterfilesdialog.cpp"