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: https://phabricator.kde.org/D9568
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);
private:
Q_DISABLE_COPY(ColorSchemeManager)
......
......@@ -533,6 +533,7 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr profile)
_ui->editColorSchemeButton->setEnabled(false);
_ui->removeColorSchemeButton->setEnabled(false);
_ui->resetColorSchemeButton->setEnabled(false);
// setup color list
updateColorSchemeList(true);
......@@ -556,6 +557,9 @@ void EditProfileDialog::setupAppearancePage(const Profile::Ptr profile)
connect(_ui->newColorSchemeButton, &QPushButton::clicked, this,
&Konsole::EditProfileDialog::newColorScheme);
connect(_ui->resetColorSchemeButton, &QPushButton::clicked, this,
&Konsole::EditProfileDialog::resetColorScheme);
// setup font preview
const bool antialias = profile->antiAliasFonts();
......@@ -840,6 +844,12 @@ void EditProfileDialog::removeColorScheme()
}
}
void EditProfileDialog::resetColorScheme()
{
removeColorScheme();
updateColorSchemeList(true);
}
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);
_ui->resetColorSchemeButton->setEnabled(isResettable);
bool isDeletable = ColorSchemeManager::instance()->isColorSchemeDeletable(name);
// if a colorScheme can be restored then it can't be deleted
_ui->removeColorSchemeButton->setEnabled(isDeletable && !isResettable);
} else {
_ui->removeColorSchemeButton->setEnabled(false);
_ui->resetColorSchemeButton->setEnabled(false);
}
}
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 @@
</property>
</widget>
</item>
<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>
<property name="text">
<string>Defaults</string>
</property>
</widget>
</item>
<item row="4" column="1" rowspan="1">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
......
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