Commit 8b1e5c4d authored by Eugene Popov's avatar Eugene Popov 🇺🇦
Browse files

Save/restore file dialog window size

This MR makes the file dialog to save/restore its window size, making it more user friendly.

BUG: 443251
parent b7d7de73
......@@ -21,10 +21,13 @@
#include <QStandardPaths>
#include <QUrl>
#include <QVBoxLayout>
#include <QWindow>
#include <KFileFilterCombo>
#include <KFileWidget>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KWindowConfig>
#include <mobilefiledialog.h>
......@@ -130,6 +133,7 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, FileChooserPortal::Opt
FileDialog::FileDialog(QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, m_fileWidget(new KFileWidget(QUrl(), this))
, m_configGroup(KSharedConfig::openConfig()->group("FileDialogSize"))
{
setLayout(new QVBoxLayout);
layout()->addWidget(m_fileWidget);
......@@ -143,10 +147,19 @@ FileDialog::FileDialog(QDialog *parent, Qt::WindowFlags flags)
connect(m_fileWidget, &KFileWidget::accepted, this, &QDialog::accept);
connect(m_fileWidget->cancelButton(), &QAbstractButton::clicked, this, &QDialog::reject);
layout()->addWidget(m_buttons);
// restore window size
if (m_configGroup.exists()) {
winId(); // ensure there's a window created
KWindowConfig::restoreWindowSize(windowHandle(), m_configGroup);
resize(windowHandle()->size());
}
}
FileDialog::~FileDialog()
{
// save window size
KWindowConfig::saveWindowSize(windowHandle(), m_configGroup);
}
FileChooserPortal::FileChooserPortal(QObject *parent)
......
......@@ -15,6 +15,8 @@
#include <QDBusObjectPath>
#include <QDialog>
#include <KConfigGroup>
class KFileWidget;
class QDialogButtonBox;
class MobileFileDialog;
......@@ -33,6 +35,7 @@ private:
protected:
KFileWidget *m_fileWidget;
KConfigGroup m_configGroup;
};
class FileChooserPortal : public QDBusAbstractAdaptor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment