QGtkStyle: Try to get the theme name from GtkSettings

Note that GtkSettings is already used for retrieving the icon
theme name.

Change-Id: I935d903c703f7d832b0350d3cfd3a638f22d1391
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
Dmitry Shachnev 2013-03-09 17:54:21 +04:00 committed by The Qt Project
parent 06d4c0b2e8
commit d7e28c1a8d

View File

@ -676,38 +676,12 @@ bool QGtkStylePrivate::getGConfBool(const QString &key, bool fallback)
QString QGtkStylePrivate::getThemeName()
{
QString themeName;
// We try to parse the gtkrc file first
// primarily to avoid resolving Gtk functions if
// the KDE 3 "Qt" style is currently in use
QString rcPaths = QString::fromLocal8Bit(qgetenv("GTK2_RC_FILES"));
if (!rcPaths.isEmpty()) {
QStringList paths = rcPaths.split(QLS(":"));
foreach (const QString &rcPath, paths) {
if (!rcPath.isEmpty()) {
QFile rcFile(rcPath);
if (rcFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&rcFile);
while(!in.atEnd()) {
QString line = in.readLine();
if (line.contains(QLS("gtk-theme-name"))) {
line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1);
line.remove(QLatin1Char('\"'));
line = line.trimmed();
themeName = line;
break;
}
}
}
}
if (!themeName.isEmpty())
break;
}
}
// Fall back to gconf
if (themeName.isEmpty() && resolveGConf())
themeName = getGConfString(QLS("/desktop/gnome/interface/gtk_theme"));
// Read the theme name from GtkSettings
GtkSettings *settings = QGtkStylePrivate::gtk_settings_get_default();
gchararray value;
g_object_get(settings, "gtk-theme-name", &value, NULL);
themeName = QString::fromUtf8(value);
g_free(value);
return themeName;
}