Mailcommon

selectthunderbirdfilterfilesdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2012-2023 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "selectthunderbirdfilterfilesdialog.h"
8 #include "selectthunderbirdfilterfileswidget.h"
9 #include <KLocalizedString>
10 #include <KSharedConfig>
11 
12 #include <KConfigGroup>
13 #include <KWindowConfig>
14 #include <QDialogButtonBox>
15 #include <QPushButton>
16 #include <QVBoxLayout>
17 #include <QWindow>
18 
19 using namespace MailCommon;
20 namespace
21 {
22 static const char mySelectThunderbirdFilterFilesDialogGroupName[] = "SelectThunderbirdFilterFilesDialog";
23 }
24 SelectThunderbirdFilterFilesDialog::SelectThunderbirdFilterFilesDialog(const QString &defaultSettingPath, QWidget *parent)
25  : QDialog(parent)
26  , mSelectFilterFilesWidget(new MailCommon::SelectThunderbirdFilterFilesWidget(defaultSettingPath, this))
27 {
28  setWindowTitle(i18nc("@title:window", "Select thunderbird filter files"));
29  setModal(true);
30  auto mainLayout = new QVBoxLayout(this);
31 
32  mainLayout->addWidget(mSelectFilterFilesWidget);
33 
35  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
36  okButton->setDefault(true);
37  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
38  connect(buttonBox, &QDialogButtonBox::accepted, this, &SelectThunderbirdFilterFilesDialog::accept);
39  connect(buttonBox, &QDialogButtonBox::rejected, this, &SelectThunderbirdFilterFilesDialog::reject);
40  connect(mSelectFilterFilesWidget, &MailCommon::SelectThunderbirdFilterFilesWidget::enableOkButton, okButton, &QPushButton::setEnabled);
41  okButton->setEnabled(false);
42  mainLayout->addWidget(buttonBox);
43  readConfig();
44 }
45 
46 SelectThunderbirdFilterFilesDialog::~SelectThunderbirdFilterFilesDialog()
47 {
48  writeConfig();
49 }
50 
51 QStringList SelectThunderbirdFilterFilesDialog::selectedFiles() const
52 {
53  return mSelectFilterFilesWidget->selectedFiles();
54 }
55 
56 void SelectThunderbirdFilterFilesDialog::setStartDir(const QUrl &url)
57 {
58  mSelectFilterFilesWidget->setStartDir(url);
59 }
60 
61 void SelectThunderbirdFilterFilesDialog::readConfig()
62 {
63  create(); // ensure a window is created
64  windowHandle()->resize(QSize(500, 300));
65  KConfigGroup group(KSharedConfig::openStateConfig(), mySelectThunderbirdFilterFilesDialogGroupName);
66  KWindowConfig::restoreWindowSize(windowHandle(), group);
67  resize(windowHandle()->size()); // workaround for QTBUG-40584
68 }
69 
70 void SelectThunderbirdFilterFilesDialog::writeConfig()
71 {
72  KConfigGroup group(KSharedConfig::openStateConfig(), mySelectThunderbirdFilterFilesDialogGroupName);
73  KWindowConfig::saveWindowSize(windowHandle(), group);
74  group.sync();
75 }
76 
77 #include "moc_selectthunderbirdfilterfilesdialog.cpp"
void setShortcut(const QKeySequence &key)
void readConfig()
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QAction * create(StandardGameAction id, const QObject *recvr, const char *slot, QObject *parent)
Key_Return
void setEnabled(bool)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
The filter dialog.
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:55:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.