From 8b4c6f90b4a72cf69bdb3eeec810b9f134f2e893 Mon Sep 17 00:00:00 2001 From: Anthony Fieroni Date: Fri, 17 Nov 2017 07:34:34 +0200 Subject: [PATCH] [komposerwin] Save configuration on window close Diffrential Revision: https://phabricator.kde.org/D7569 Signed-off-by: Anthony Fieroni --- src/editor/attachment/attachmentview.cpp | 3 +-- src/editor/attachment/attachmentview.h | 1 + src/editor/kmcomposerwin.cpp | 11 +++++------ src/kmkernel.cpp | 19 ------------------- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/editor/attachment/attachmentview.cpp b/src/editor/attachment/attachmentview.cpp index d4a3b2116..25ace70ad 100644 --- a/src/editor/attachment/attachmentview.cpp +++ b/src/editor/attachment/attachmentview.cpp @@ -51,6 +51,7 @@ using namespace KMail; AttachmentView::AttachmentView(MessageComposer::AttachmentModel *model, QWidget *parent) : QTreeView(parent) + , grp(KMKernel::self()->config()->group("AttachmentView")) { mWidget = new QWidget(); QHBoxLayout *lay = new QHBoxLayout(mWidget); @@ -100,13 +101,11 @@ AttachmentView::~AttachmentView() void AttachmentView::restoreHeaderState() { - KConfigGroup grp(KMKernel::self()->config(), "AttachmentView"); header()->restoreState(grp.readEntry("State", QByteArray())); } void AttachmentView::saveHeaderState() { - KConfigGroup grp(KMKernel::self()->config(), "AttachmentView"); grp.writeEntry("State", header()->saveState()); grp.sync(); } diff --git a/src/editor/attachment/attachmentview.h b/src/editor/attachment/attachmentview.h index 1f3d4da5c..3595dba17 100644 --- a/src/editor/attachment/attachmentview.h +++ b/src/editor/attachment/attachmentview.h @@ -77,6 +77,7 @@ private: QToolButton *mToolButton = nullptr; QLabel *mInfoAttachment = nullptr; QWidget *mWidget = nullptr; + KConfigGroup grp; }; } // namespace KMail diff --git a/src/editor/kmcomposerwin.cpp b/src/editor/kmcomposerwin.cpp index 4f894a569..b51ec91b3 100644 --- a/src/editor/kmcomposerwin.cpp +++ b/src/editor/kmcomposerwin.cpp @@ -520,12 +520,13 @@ KMComposerWin::KMComposerWin(const KMime::Message::Ptr &aMsg, bool lastSignState mDummyComposer = new MessageComposer::Composer(this); mDummyComposer->globalPart()->setParentWidgetForGui(this); + + KConfigGroup grp(KMKernel::self()->config()->group("Composer")); + setAutoSaveSettings(grp, true); } KMComposerWin::~KMComposerWin() { - writeConfig(); - // When we have a collection set, store the message back to that collection. // Note that when we save the message or sent it, mFolder is set back to 0. // So this for example kicks in when opening a draft and then closing the window. @@ -665,8 +666,6 @@ void KMComposerWin::writeConfig(void) KMailSettings::self()->setComposerSize(size()); KMailSettings::self()->setShowSnippetManager(mSnippetAction->isChecked()); - KConfigGroup grp(KMKernel::self()->config()->group("Composer")); - saveMainWindowSettings(grp); if (mSnippetAction->isChecked()) { KMailSettings::setSnippetSplitterPosition(mSnippetSplitter->sizes()); } @@ -1731,6 +1730,7 @@ bool KMComposerWin::queryClose() return false; } if (kmkernel->shuttingDown() || qApp->isSavingSession()) { + writeConfig(); return true; } @@ -1770,6 +1770,7 @@ bool KMComposerWin::queryClose() qCWarning(KMAIL_LOG) << "Tried to close while composer was active"; return false; } + writeConfig(); return true; } @@ -3049,8 +3050,6 @@ void KMComposerWin::slotSpellcheckConfig() void KMComposerWin::slotEditToolbars() { - KConfigGroup grp(KMKernel::self()->config()->group("Composer")); - saveMainWindowSettings(grp); QPointer dlg = new KEditToolBar(guiFactory(), this); connect(dlg.data(), &KEditToolBar::newToolBarConfig, this, &KMComposerWin::slotUpdateToolbars); diff --git a/src/kmkernel.cpp b/src/kmkernel.cpp index 3775437df..1bd607be2 100644 --- a/src/kmkernel.cpp +++ b/src/kmkernel.cpp @@ -1063,33 +1063,14 @@ void KMKernel::setFirstInstance(bool value) void KMKernel::closeAllKMailWindows() { - QList windowsToDelete; - foreach (KMainWindow *window, KMainWindow::memberList()) { if (::qobject_cast(window) || ::qobject_cast(window)) { // close and delete the window window->setAttribute(Qt::WA_DeleteOnClose); window->close(); - windowsToDelete.append(window); } } - - // We delete all main windows here. Above we called close(), but that calls - // deleteLater() internally, therefore does not delete it immediately. - // This would lead to problems when closing Kontact when a composer window - // is open, because the destruction order is: - // - // 1. destructor of the Kontact mainwinow - // 2. delete all parts - // 3. the KMail part destructor calls KMKernel::cleanup(), which calls - // this function - // 4. delete all other mainwindows - // - // Deleting the composer windows here will make sure that step 4 will not delete - // any composer window, which would fail because the kernel is already deleted. - qDeleteAll(windowsToDelete); - windowsToDelete.clear(); } void KMKernel::cleanup(void)