Unverified Commit 15ce4671 authored by Andrey Legayev's avatar Andrey Legayev
Browse files

Fix windows size save/restore

Related bug reports:
https://dev.gnupg.org/T4819
https://bugreports.qt.io/browse/QTBUG-77385

Differential Revision: https://phabricator.kde.org/D28580
parent 6af76e25
......@@ -42,6 +42,7 @@
#include <Libkleo/FileNameRequester>
#include <QWindow>
#include <QVBoxLayout>
#include <QProgressBar>
#include <QLabel>
......@@ -54,6 +55,7 @@
#include <KMessageBox>
#include <KConfigGroup>
#include <KSharedConfig>
#include <KWindowConfig>
using namespace Kleo;
using namespace Kleo::Crypto;
......@@ -243,18 +245,24 @@ void DecryptVerifyFilesDialog::checkAccept() {
void DecryptVerifyFilesDialog::readConfig()
{
winId(); // ensure there's a window created
// set default window size
windowHandle()->resize(640, 480);
// restore size from config file
KConfigGroup cfgGroup(KSharedConfig::openConfig(), "DecryptVerifyFilesDialog");
const QByteArray geom = cfgGroup.readEntry("geometry", QByteArray());
if (!geom.isEmpty()) {
restoreGeometry(geom);
return;
}
resize(QSize(640, 480));
KWindowConfig::restoreWindowSize(windowHandle(), cfgGroup);
// NOTICE: QWindow::setGeometry() does NOT impact the backing QWidget geometry even if the platform
// window was created -> QTBUG-40584. We therefore copy the size here.
// TODO: remove once this was resolved in QWidget QPA
resize(windowHandle()->size());
}
void DecryptVerifyFilesDialog::writeConfig()
{
KConfigGroup cfgGroup(KSharedConfig::openConfig(), "DecryptVerifyFilesDialog");
cfgGroup.writeEntry("geometry", saveGeometry());
KWindowConfig::saveWindowSize(windowHandle(), cfgGroup);
cfgGroup.sync();
}
......@@ -42,6 +42,7 @@
#include <KSharedConfig>
#include <KColorScheme>
#include <KConfigGroup>
#include <KWindowConfig>
#include <KMessageBox>
......@@ -49,6 +50,7 @@
#include <utils/gnupg-helper.h>
#include <Libkleo/FileNameRequester>
#include <QWindow>
#include <QVBoxLayout>
#include <QWizardPage>
#include <QGroupBox>
......@@ -393,6 +395,8 @@ SignEncryptFilesWizard::SignEncryptFilesWizard(QWidget *parent, Qt::WindowFlags
, mSigningUserMutable(true)
, mEncryptionUserMutable(true)
{
readConfig();
bool de_vs = Kleo::gpgComplianceP("de-vs");
#ifdef Q_OS_WIN
// Enforce modern style to avoid vista style ugliness.
......@@ -421,13 +425,6 @@ SignEncryptFilesWizard::SignEncryptFilesWizard(QWidget *parent, Qt::WindowFlags
} else {
mLabel = nullptr;
}
KConfigGroup cfgGroup(KSharedConfig::openConfig(), "SignEncryptFilesWizard");
const QByteArray geom = cfgGroup.readEntry("geometry", QByteArray());
if (!geom.isEmpty()) {
restoreGeometry(geom);
return;
}
}
void SignEncryptFilesWizard::setLabelText(const QString &label) const
......@@ -447,9 +444,7 @@ void SignEncryptFilesWizard::slotCurrentIdChanged(int id)
SignEncryptFilesWizard::~SignEncryptFilesWizard()
{
qCDebug(KLEOPATRA_LOG);
KConfigGroup cfgGroup(KSharedConfig::openConfig(), "SignEncryptFilesWizard");
cfgGroup.writeEntry("geometry", saveGeometry());
cfgGroup.sync();
writeConfig();
}
void SignEncryptFilesWizard::setSigningPreset(bool preset)
......@@ -518,4 +513,29 @@ bool SignEncryptFilesWizard::encryptSymmetric() const
return mSigEncPage->encryptSymmetric();
}
void SignEncryptFilesWizard::readConfig()
{
winId(); // ensure there's a window created
// set default window size
windowHandle()->resize(640, 480);
// restore size from config file
KConfigGroup cfgGroup(KSharedConfig::openConfig(), "SignEncryptFilesWizard");
KWindowConfig::restoreWindowSize(windowHandle(), cfgGroup);
// NOTICE: QWindow::setGeometry() does NOT impact the backing QWidget geometry even if the platform
// window was created -> QTBUG-40584. We therefore copy the size here.
// TODO: remove once this was resolved in QWidget QPA
resize(windowHandle()->size());
}
void SignEncryptFilesWizard::writeConfig()
{
KConfigGroup cfgGroup(KSharedConfig::openConfig(), "SignEncryptFilesWizard");
KWindowConfig::saveWindowSize(windowHandle(), cfgGroup);
cfgGroup.sync();
}
#include "signencryptfileswizard.moc"
......@@ -104,6 +104,10 @@ public:
void setLabelText(const QString &label) const;
protected:
void readConfig();
void writeConfig();
Q_SIGNALS:
void operationPrepared();
......
......@@ -222,6 +222,10 @@ void KleopatraApplication::init()
KleopatraApplication::~KleopatraApplication()
{
// main window doesn't receive "close" signal and cannot
// save settings before app exit
delete d->mainWindow;
// work around kdelibs bug https://bugs.kde.org/show_bug.cgi?id=162514
KSharedConfig::openConfig()->sync();
}
......
......@@ -59,6 +59,7 @@
#include <KXMLGUIFactory>
#include <QApplication>
#include <QSize>
#include <QLineEdit>
#include <KActionMenu>
#include <KActionCollection>
......@@ -398,7 +399,10 @@ MainWindow::Private::Private(MainWindow *qq)
q->setAcceptDrops(true);
// set default window size
q->resize(QSize(1024, 500));
q->setAutoSaveSettings();
updateSearchBarClickMessage();
updateStatusBar();
}
......@@ -407,9 +411,7 @@ MainWindow::Private::~Private() {}
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
: KXmlGuiWindow(parent, flags), d(new Private(this))
{
resize(1024, 500);
}
{}
MainWindow::~MainWindow() {}
......@@ -682,14 +684,7 @@ void MainWindow::readProperties(const KConfigGroup &cg)
{
qCDebug(KLEOPATRA_LOG);
KXmlGuiWindow::readProperties(cg);
savedGeometry = cg.readEntry("savedGeometry", QByteArray());
if (!savedGeometry.isEmpty()) {
restoreGeometry(savedGeometry);
}
if (! cg.readEntry<bool>("hidden", false)) {
show();
}
setHidden(cg.readEntry("hidden", false));
}
void MainWindow::saveProperties(KConfigGroup &cg)
......@@ -697,11 +692,6 @@ void MainWindow::saveProperties(KConfigGroup &cg)
qCDebug(KLEOPATRA_LOG);
KXmlGuiWindow::saveProperties(cg);
cg.writeEntry("hidden", isHidden());
if (isHidden()) {
cg.writeEntry("savedGeometry", savedGeometry);
} else {
cg.writeEntry("savedGeometry", saveGeometry());
}
}
#include "moc_mainwindow.cpp"
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