From cda9c08339dd61c0099c6a563603a3a6430c1972 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Fri, 4 May 2007 02:04:48 +0000 Subject: [PATCH] Make deletion of color schemes persistant. svn path=/branches/work/konsole-split-view/; revision=660885 --- konsole/ColorScheme.cpp | 31 +++++++++++++++++++++++++------ konsole/ColorScheme.h | 2 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/konsole/ColorScheme.cpp b/konsole/ColorScheme.cpp index a0a2842c..b4cfaa8c 100644 --- a/konsole/ColorScheme.cpp +++ b/konsole/ColorScheme.cpp @@ -334,7 +334,8 @@ bool ColorSchemeManager::loadKDE3ColorScheme(const QString& filePath) qDebug() << "loading KDE 3 format color scheme from " << filePath; QFile file(filePath); - file.open(QIODevice::ReadOnly); + if (!filePath.endsWith(".schema") || !file.open(QIODevice::ReadOnly)) + return false; KDE3ColorSchemeReader reader(&file); ColorScheme* scheme = reader.read(); @@ -374,6 +375,9 @@ void ColorSchemeManager::addColorScheme(ColorScheme* scheme) } bool ColorSchemeManager::loadColorScheme(const QString& filePath) { + if ( !filePath.endsWith(".colorscheme") || !QFile::exists(filePath) ) + return false; + QFileInfo info(filePath); qDebug() << "loading KDE 4 native color scheme from " << filePath; @@ -427,7 +431,23 @@ void ColorSchemeManager::deleteColorScheme(const QString& name) _colorSchemes.remove(name); - qWarning() << "Color scheme removed - make this change persistant."; + // lookup the path and delete + QString path = findColorSchemePath(name); + if ( QFile::remove(path) ) + qDebug() << "Removed color scheme -" << path; + else + qDebug() << "Failed to remove color scheme -" << path; +} +QString ColorSchemeManager::findColorSchemePath(const QString& name) const +{ + QString path = KStandardDirs::locate("data","konsole/"+name+".colorscheme"); + + if ( !path.isEmpty() ) + return path; + + path = KStandardDirs::locate("data","konsole/"+name+".schema"); + + return path; } const ColorScheme* ColorSchemeManager::findColorScheme(const QString& name) { @@ -441,15 +461,14 @@ const ColorScheme* ColorSchemeManager::findColorScheme(const QString& name) else { // look for this color scheme - QString path = KStandardDirs::locate("data","konsole/"+name+".colorscheme"); + QString path = findColorSchemePath(name); if ( !path.isEmpty() && loadColorScheme(path) ) { return findColorScheme(name); } - else // look for a KDE 3 format color scheme by this name + else { - QString kde3path = KStandardDirs::locate("data","konsole/"+name+".schema"); - if (!kde3path.isEmpty() && loadKDE3ColorScheme(kde3path)) + if (!path.isEmpty() && loadKDE3ColorScheme(path)) return findColorScheme(name); } diff --git a/konsole/ColorScheme.h b/konsole/ColorScheme.h index f996fcd1..b5761801 100644 --- a/konsole/ColorScheme.h +++ b/konsole/ColorScheme.h @@ -242,6 +242,8 @@ private: QList listKDE3ColorSchemes(); // loads all of the color schemes void loadAllColorSchemes(); + // finds the path of a color scheme + QString findColorSchemePath(const QString& name) const; QHash _colorSchemes; QSet _modifiedSchemes; -- GitLab