Commit 0d95c7f4 authored by Kurt Hindenburg's avatar Kurt Hindenburg

Add a way to reset changes to system-wide color schemes

If an user has alter the system-side color schemes, Konsole saves
thoses changes in the user's local folder.  This patch allows that
local user file to be deleted, thus resetting the color scheme to the
default system-wide file.

Patch by ahmadsamir

BUG: 369481
FIXED-IN: 18.04
Differential Revision:
parent f9e8eaa1
......@@ -213,3 +213,25 @@ QString ColorSchemeManager::findColorSchemePath(const QString &name) const
return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + name + QStringLiteral(".schema"));
bool ColorSchemeManager::isColorSchemeDeletable(const QString &name)
const QString path = findColorSchemePath(name);
QFileInfo fileInfo(path);
QFileInfo dirInfo = fileInfo.path();
return dirInfo.isWritable();
bool ColorSchemeManager::canResetColorScheme(const QString &name)
const QStringList paths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + name + QStringLiteral(".colorscheme"));
// if the colorscheme exists in both a writable location under the
// user's home dir and a system-wide location, then it's possible
// to delete the colorscheme under the user's home dir so that the
// colorscheme from the system-wide location can be used instead,
// i.e. resetting the colorscheme
return (paths.count() > 1);
......@@ -88,6 +88,18 @@ public:
/** Returns the global color scheme manager instance. */
static ColorSchemeManager *instance();
* Returns @c true if a colorscheme with @p name exists both under
* the user's home dir location, and a system-wide location
bool canResetColorScheme(const QString &name);
* Returns @c true if a colorscheme with @p name exists under the
* user's home dir location, and hence can be deleted
bool isColorSchemeDeletable(const QString &name);
......@@ -533,6 +533,7 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr profile)
// setup color list
......@@ -556,6 +557,9 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr profile)
connect(_ui->newColorSchemeButton, &QPushButton::clicked, this,
connect(_ui->resetColorSchemeButton, &QPushButton::clicked, this,
// setup font preview
const bool antialias = profile->antiAliasFonts();
......@@ -840,6 +844,12 @@ void EditProfileDialog::removeColorScheme()
void EditProfileDialog::resetColorScheme()
void EditProfileDialog::showColorSchemeEditor(bool isNewScheme)
// Finding selected ColorScheme
......@@ -923,7 +933,23 @@ void EditProfileDialog::colorSchemeSelected()
void EditProfileDialog::updateColorSchemeButtons()
enableIfNonEmptySelection(_ui->editColorSchemeButton, _ui->colorSchemeList->selectionModel());
enableIfNonEmptySelection(_ui->removeColorSchemeButton, _ui->colorSchemeList->selectionModel());
QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
if (!selected.isEmpty()) {
const QString &name = selected.first().data(Qt::UserRole + 1).value<const ColorScheme *>()->name();
bool isResettable = ColorSchemeManager::instance()->canResetColorScheme(name);
bool isDeletable = ColorSchemeManager::instance()->isColorSchemeDeletable(name);
// if a colorScheme can be restored then it can't be deleted
_ui->removeColorSchemeButton->setEnabled(isDeletable && !isResettable);
} else {
void EditProfileDialog::updateKeyBindingsButtons()
......@@ -132,6 +132,14 @@ private Q_SLOTS:
void editColorScheme();
void saveColorScheme(const ColorScheme &scheme, bool isNewScheme);
void removeColorScheme();
* Deletes the selected colorscheme from the user's home dir location
* so that the original one from the system-wide location can be used
* instead
void resetColorScheme();
void colorSchemeSelected();
void previewColorScheme(const QModelIndex &index);
void fontSelected(const QFont &);
......@@ -481,7 +481,17 @@
<item row="3" column="1" rowspan="2">
<item row="3" column="1">
<widget class="QPushButton" name="resetColorSchemeButton">
<property name="toolTip">
<string>Reset the selected color scheme settings to the default values</string>
<property name="text">
<item row="4" column="1" rowspan="1">
<property name="orientation">
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