Load chat styles also from DATA_DIR/stylesheets

Chat styles were only loaded from user config dir
(or application dir on windows portable)

If a style exists in both folders, it's taken from config dir, so users
can customize chat styles by copying them to ~/.retroshare/stylesheets/
This commit is contained in:
AsamK 2015-08-27 21:43:18 +02:00
parent 66ba687acd
commit 699213af80

View file

@ -144,37 +144,32 @@ void ChatStyle::styleChanged(int styleType)
} }
} }
static QString getBaseDir() static QStringList getBaseDirList()
{ {
// application path // Search chat styles in config dir and data dir (is application dir for portable)
QString baseDir = QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()); QStringList baseDirs;
baseDirs.append(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()));
baseDirs.append(QString::fromUtf8(RsAccounts::DataDirectory().c_str()));
#ifdef WIN32 return baseDirs;
if (RsInit::isPortable ()) {
// application dir for portable version
baseDir = QApplication::applicationDirPath();
}
#endif
return baseDir;
} }
bool ChatStyle::setStylePath(const QString &stylePath, const QString &styleVariant) bool ChatStyle::setStylePath(const QString &stylePath, const QString &styleVariant)
{ {
m_styleType = TYPE_UNKNOWN; m_styleType = TYPE_UNKNOWN;
m_styleDir.setPath(getBaseDir()); foreach (QString dir, getBaseDirList()) {
if (m_styleDir.cd(stylePath) == false) { m_styleDir.setPath(dir);
m_styleDir = QDir(""); if (m_styleDir.cd(stylePath)) {
m_styleVariant = styleVariant;
return true;
}
}
m_styleDir.setPath("");
m_styleVariant.clear(); m_styleVariant.clear();
return false; return false;
} }
m_styleVariant = styleVariant;
return true;
}
bool ChatStyle::setStyleFromSettings(enumStyleType styleType) bool ChatStyle::setStyleFromSettings(enumStyleType styleType)
{ {
QString stylePath; QString stylePath;
@ -471,9 +466,6 @@ static bool getStyleInfo(QString stylePath, QString stylePathRelative, ChatStyle
{ {
styles.clear(); styles.clear();
// base dir
QDir baseDir(getBaseDir());
ChatStyleInfo standardInfo; ChatStyleInfo standardInfo;
QString stylePath; QString stylePath;
@ -516,10 +508,11 @@ static bool getStyleInfo(QString stylePath, QString stylePathRelative, ChatStyle
return false; return false;
} }
foreach (QDir baseDir, getBaseDirList()) {
QDir dir(baseDir); QDir dir(baseDir);
if (dir.cd("stylesheets") == false) { if (dir.cd("stylesheets") == false) {
// no user styles available // no user styles available here
return true; continue;
} }
// get all style directories // get all style directories
@ -537,6 +530,7 @@ static bool getStyleInfo(QString stylePath, QString stylePathRelative, ChatStyle
styles.append(info); styles.append(info);
} }
} }
}
return true; return true;
} }