Commit 1c7ca419 authored by Ahmad Samir's avatar Ahmad Samir Committed by Tomaz Canabrava
Browse files

Let KColorSchemeManager handle loading/saving the widget color scheme

KColorSchemeManager (from KConfigWidgets) was changed in 5.89 to handle
loading/saving the selected color scheme automatically if
KColorSchemeManager::setAutosaveChanges(true) is used (it auto saves by
default, but calling setAutosaveChanges(true) makes it easier to understand
the code).

However this is conditional on KConfigWidgets >= 5.93 because that's where
the KColorSchemeManager::createSchemeSelectionMenu() overload used here was
changed to load the previously saved color scheme.

Since KColorSchemeManager uses "ColorScheme" as the config entry name,
migrate the old config entry when KF >= 5.93.
parent 60b0c9d5
Pipeline #179913 passed with stage
in 2 minutes and 52 seconds
......@@ -22,20 +22,23 @@ AppColorSchemeChooser::AppColorSchemeChooser(QObject *parent)
{
auto *manager = new KColorSchemeManager(parent);
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 93, 0)
const QString scheme(currentSchemeName());
qCDebug(KonsoleDebug) << "Color scheme : " << scheme;
auto *selectionMenu = manager->createSchemeSelectionMenu(scheme, this);
connect(selectionMenu->menu(), &QMenu::triggered, this, &AppColorSchemeChooser::slotSchemeChanged);
manager->activateScheme(manager->indexForScheme(scheme));
#else
manager->setAutosaveChanges(true);
KActionMenu *selectionMenu = manager->createSchemeSelectionMenu(this);
#endif
setMenu(selectionMenu->menu());
menu()->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-color")));
menu()->setTitle(i18n("&Window Color Scheme"));
}
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 93, 0)
QString AppColorSchemeChooser::currentSchemeName() const
{
if (!menu()) {
......@@ -58,3 +61,4 @@ void AppColorSchemeChooser::slotSchemeChanged(QAction *triggeredAction)
cg.writeEntry("WindowColorScheme", KLocalizedString::removeAcceleratorMarker(triggeredAction->text()));
cg.sync();
}
#endif
......@@ -12,6 +12,7 @@
#include <QObject>
#include <KColorSchemeManager>
#include <kconfigwidgets_version.h>
// Konsole
#include "konsoleprivate_export.h"
......@@ -23,15 +24,19 @@ class KActionCollection;
*
* Furthermore, it will save the selection in the user configuration.
*/
// TODO: Once the minimum KF version is changed to >= 5.93, remove this whole
// class and move the couple of lines of code from the constructor to MainWindow
class KONSOLEPRIVATE_EXPORT AppColorSchemeChooser : public QAction
{
public:
explicit AppColorSchemeChooser(QObject *parent);
// Not needed with KF >= 5.93
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 93, 0)
QString currentSchemeName() const;
private Q_SLOTS:
void slotSchemeChanged(QAction *triggeredAction);
#endif
};
#endif
......@@ -32,6 +32,7 @@
#include <Kdelibs4ConfigMigrator>
#include <Kdelibs4Migration>
#endif
#include <kconfigwidgets_version.h>
#include <kdbusservice.h>
using Konsole::Application;
......@@ -98,6 +99,16 @@ static void migrateRenamedConfigKeys()
}
}
// With 5.93 KColorSchemeManager from KConfigWidgets, handles the loading
// and saving of the widget color scheme, and uses "ColorScheme" as the
// entry name, so clean-up here
#if KCONFIGWIDGETS_VERSION >= QT_VERSION_CHECK(5, 93, 0)
KConfigGroup cg(konsoleConfig, "UiSettings");
const QString schemeName = cg.readEntry("WindowColorScheme");
cg.deleteEntry("WindowColorScheme");
cg.writeEntry("ColorScheme", schemeName);
#endif
konsoleConfig->sync();
}
......
Supports Markdown
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