Mailcommon

selectthunderbirdfilterfilesdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2012-2022 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 <QDialogButtonBox>
14 #include <QPushButton>
15 #include <QVBoxLayout>
16 
17 using namespace MailCommon;
18 
19 SelectThunderbirdFilterFilesDialog::SelectThunderbirdFilterFilesDialog(const QString &defaultSettingPath, QWidget *parent)
20  : QDialog(parent)
21  , mSelectFilterFilesWidget(new MailCommon::SelectThunderbirdFilterFilesWidget(defaultSettingPath, this))
22 {
23  setWindowTitle(i18nc("@title:window", "Select thunderbird filter files"));
24  setModal(true);
25  auto mainLayout = new QVBoxLayout(this);
26 
27  mainLayout->addWidget(mSelectFilterFilesWidget);
28 
30  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
31  okButton->setDefault(true);
32  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
33  connect(buttonBox, &QDialogButtonBox::accepted, this, &SelectThunderbirdFilterFilesDialog::accept);
34  connect(buttonBox, &QDialogButtonBox::rejected, this, &SelectThunderbirdFilterFilesDialog::reject);
35  connect(mSelectFilterFilesWidget, &MailCommon::SelectThunderbirdFilterFilesWidget::enableOkButton, okButton, &QPushButton::setEnabled);
36  okButton->setEnabled(false);
37  mainLayout->addWidget(buttonBox);
38  readConfig();
39 }
40 
41 SelectThunderbirdFilterFilesDialog::~SelectThunderbirdFilterFilesDialog()
42 {
43  writeConfig();
44 }
45 
46 QStringList SelectThunderbirdFilterFilesDialog::selectedFiles() const
47 {
48  return mSelectFilterFilesWidget->selectedFiles();
49 }
50 
51 void SelectThunderbirdFilterFilesDialog::setStartDir(const QUrl &url)
52 {
53  mSelectFilterFilesWidget->setStartDir(url);
54 }
55 
56 void SelectThunderbirdFilterFilesDialog::readConfig()
57 {
58  KConfigGroup group(KSharedConfig::openStateConfig(), "SelectThunderbirdFilterFilesDialog");
59 
60  const QSize size = group.readEntry("Size", QSize(500, 300));
61  if (size.isValid()) {
62  resize(size);
63  }
64 }
65 
66 void SelectThunderbirdFilterFilesDialog::writeConfig()
67 {
68  KConfigGroup group(KSharedConfig::openStateConfig(), "SelectThunderbirdFilterFilesDialog");
69  group.writeEntry("Size", size());
70 }
bool isValid() const const
void setShortcut(const QKeySequence &key)
void readConfig()
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Key_Return
void setEnabled(bool)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.