Allow app to add custom color sheme locations

This commit is contained in:
Igor
2016-05-20 16:55:25 +03:00
parent 5ebc2c0780
commit ad59d1dc5e
6 changed files with 78 additions and 35 deletions
+33 -27
View File
@@ -558,17 +558,13 @@ ColorSchemeManager::~ColorSchemeManager()
void ColorSchemeManager::loadAllColorSchemes()
{
qDebug() << "loadAllColorSchemes";
int success = 0;
int failed = 0;
QList<QString> nativeColorSchemes = listColorSchemes();
QListIterator<QString> nativeIter(nativeColorSchemes);
while ( nativeIter.hasNext() )
{
if ( loadColorScheme( nativeIter.next() ) )
success++;
else
if ( !loadColorScheme( nativeIter.next() ) )
failed++;
}
@@ -576,9 +572,7 @@ void ColorSchemeManager::loadAllColorSchemes()
QListIterator<QString> kde3Iter(kde3ColorSchemes);
while ( kde3Iter.hasNext() )
{
if ( loadKDE3ColorScheme( kde3Iter.next() ) )
success++;
else
if ( !loadKDE3ColorScheme( kde3Iter.next() ) )
failed++;
}
@@ -650,6 +644,11 @@ bool ColorSchemeManager::loadCustomColorScheme(const QString& path)
return false;
}
void ColorSchemeManager::addCustomColorSchemeDir(const QString& custom_dir)
{
add_custom_color_scheme_dir(custom_dir);
}
bool ColorSchemeManager::loadColorScheme(const QString& filePath)
{
if ( !filePath.endsWith(QLatin1String(".colorscheme")) || !QFile::exists(filePath) )
@@ -686,15 +685,18 @@ bool ColorSchemeManager::loadColorScheme(const QString& filePath)
}
QList<QString> ColorSchemeManager::listKDE3ColorSchemes()
{
QString dname(get_color_schemes_dir());
QDir dir(dname);
QStringList filters;
filters << "*.schema";
dir.setNameFilters(filters);
QStringList list = dir.entryList(filters);
QStringList ret;
foreach(QString i, list)
ret << dname + "/" + i;
foreach(const QString &scheme_dir, get_color_schemes_dirs())
{
QString dname(scheme_dir);
QDir dir(dname);
QStringList filters;
filters << "*.schema";
dir.setNameFilters(filters);
QStringList list = dir.entryList(filters);
foreach(QString i, list)
ret << dname + "/" + i;
}
return ret;
//return KGlobal::dirs()->findAllResources("data",
// "konsole/*.schema",
@@ -703,15 +705,18 @@ QList<QString> ColorSchemeManager::listKDE3ColorSchemes()
}
QList<QString> ColorSchemeManager::listColorSchemes()
{
QString dname(get_color_schemes_dir());
QDir dir(dname);
QStringList filters;
filters << "*.colorscheme";
dir.setNameFilters(filters);
QStringList list = dir.entryList(filters);
QStringList ret;
foreach(QString i, list)
ret << dname + "/" + i;
foreach(const QString &scheme_dir, get_color_schemes_dirs())
{
QString dname(scheme_dir);
QDir dir(dname);
QStringList filters;
filters << "*.colorscheme";
dir.setNameFilters(filters);
QStringList list = dir.entryList(filters);
foreach(QString i, list)
ret << dname + "/" + i;
}
return ret;
// return KGlobal::dirs()->findAllResources("data",
// "konsole/*.colorscheme",
@@ -742,12 +747,13 @@ bool ColorSchemeManager::deleteColorScheme(const QString& name)
QString ColorSchemeManager::findColorSchemePath(const QString& name) const
{
// QString path = KStandardDirs::locate("data","konsole/"+name+".colorscheme");
QString path(get_color_schemes_dir() + "/"+ name + ".colorscheme");
const QString dir = get_color_schemes_dirs().first();
QString path(dir + "/"+ name + ".colorscheme");
if ( !path.isEmpty() )
return path;
return path;
//path = KStandardDirs::locate("data","konsole/"+name+".schema");
path = get_color_schemes_dir() + "/"+ name + ".schema";
path = dir + "/"+ name + ".schema";
return path;
}
+8
View File
@@ -327,6 +327,14 @@ public:
* @return Whether the color scheme is loaded successfully.
*/
bool loadCustomColorScheme(const QString& path);
/**
* @brief Allows to add a custom location of color schemes.
*
* @param[in] custom_dir Custom location of color schemes (must end with /).
*/
void addCustomColorSchemeDir(const QString& custom_dir);
private:
// loads a color scheme from a KDE 4+ .colorscheme file
bool loadColorScheme(const QString& path);
+5
View File
@@ -433,6 +433,11 @@ QStringList QTermWidget::availableColorSchemes()
return ret;
}
void QTermWidget::addCustomColorSchemeDir(const QString& custom_dir)
{
ColorSchemeManager::instance()->addCustomColorSchemeDir(custom_dir);
}
void QTermWidget::setSize(const QSize &size)
{
if (!m_impl->m_terminalDisplay)
+1
View File
@@ -120,6 +120,7 @@ public:
*/
void setColorScheme(const QString & name);
static QStringList availableColorSchemes();
void addCustomColorSchemeDir(const QString& custom_dir);
// History size for scrolling
void setHistorySize(int lines); //infinite if lines < 0
+28 -6
View File
@@ -43,36 +43,58 @@ QString get_kb_layout_dir()
#endif // BUNDLE_KEYBOARDLAYOUTS
}
/*! Helper function to get possible location of layout files.
/*! Helper function to add custom location of color schemes.
*/
QStringList custom_color_schemes_dirs;
void add_custom_color_scheme_dir(const QString& custom_dir)
{
custom_color_schemes_dirs << custom_dir;
}
/*! Helper function to get possible locations of color schemes.
By default the COLORSCHEMES_DIR is used (linux/BSD/macports).
But in some cases (apple bundle) there can be more locations).
*/
QString get_color_schemes_dir()
QStringList get_color_schemes_dirs()
{
#ifdef BUNDLE_COLORSCHEMES
return QLatin1String(":/");
#else
// qDebug() << __FILE__ << __FUNCTION__;
QString rval = "";
QStringList rval;
QString k(COLORSCHEMES_DIR);
QDir d(k);
// qDebug() << "default COLORSCHEMES_DIR: " << k;
if (d.exists())
rval = k.append("/");
rval << k.append("/");
// subdir in the app location
d.setPath(QCoreApplication::applicationDirPath() + "/color-schemes/");
//qDebug() << d.path();
if (d.exists())
rval = QCoreApplication::applicationDirPath() + "/color-schemes/";
{
if (!rval.isEmpty())
rval.clear();
rval << (QCoreApplication::applicationDirPath() + "/color-schemes/");
}
#ifdef Q_WS_MAC
d.setPath(QCoreApplication::applicationDirPath() + "/../Resources/color-schemes/");
if (d.exists())
rval = QCoreApplication::applicationDirPath() + "/../Resources/color-schemes/";
{
if (!rval.isEmpty())
rval.clear();
rval << (QCoreApplication::applicationDirPath() + "/../Resources/color-schemes/");
}
#endif
foreach (const QString& custom_dir, custom_color_schemes_dirs)
{
d.setPath(custom_dir);
if (d.exists())
rval << custom_dir;
}
#ifdef QT_DEBUG
if(!rval.isEmpty()) {
qDebug() << "Using color-schemes: " << rval;
+3 -2
View File
@@ -2,9 +2,10 @@
#define TOOLS_H
#include <QString>
#include <QStringList>
QString get_kb_layout_dir();
QString get_color_schemes_dir();
void add_custom_color_scheme_dir(const QString& custom_dir);
QStringList get_color_schemes_dirs();
#endif