diff --git a/src/editor/attachment/attachmentview.h b/src/editor/attachment/attachmentview.h --- a/src/editor/attachment/attachmentview.h +++ b/src/editor/attachment/attachmentview.h @@ -77,6 +77,7 @@ QToolButton *mToolButton = nullptr; QLabel *mInfoAttachment = nullptr; QWidget *mWidget = nullptr; + KConfigGroup grp; }; } // namespace KMail diff --git a/src/editor/attachment/attachmentview.cpp b/src/editor/attachment/attachmentview.cpp --- a/src/editor/attachment/attachmentview.cpp +++ b/src/editor/attachment/attachmentview.cpp @@ -51,6 +51,7 @@ 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 @@ 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/kmcomposerwin.cpp b/src/editor/kmcomposerwin.cpp --- a/src/editor/kmcomposerwin.cpp +++ b/src/editor/kmcomposerwin.cpp @@ -520,12 +520,13 @@ 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 @@ 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 @@ return false; } if (kmkernel->shuttingDown() || qApp->isSavingSession()) { + writeConfig(); return true; } @@ -1770,6 +1770,7 @@ qCWarning(KMAIL_LOG) << "Tried to close while composer was active"; return false; } + writeConfig(); return true; } @@ -3049,8 +3050,6 @@ 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 --- a/src/kmkernel.cpp +++ b/src/kmkernel.cpp @@ -1063,33 +1063,14 @@ 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)