Skip to content

Commit

Permalink
lxqt-config-appearance: Set default GTK theme if rc file doesn't exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
selairi committed Sep 2, 2018
1 parent 1350a80 commit 10945b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lxqt-config-appearance/configothertoolkits.cpp
Expand Up @@ -34,6 +34,7 @@
#include <QFont>
#include <QDateTime>
#include <QMessageBox>
#include <QProcess>

#include <sys/types.h>
#include <signal.h>
Expand Down Expand Up @@ -250,7 +251,7 @@ QString ConfigOtherToolKits::getGTKThemeFromRCFile(QString version)
QFile file(gtkrcPath);
if(file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
return getDefaultGTKTheme();
while (!file.atEnd()) {
QByteArray line = file.readLine().trimmed();
if(line.startsWith("gtk-theme-name")) {
Expand All @@ -268,7 +269,7 @@ QString ConfigOtherToolKits::getGTKThemeFromRCFile(QString version)
QFile file(gtkrcPath);
if(file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
return getDefaultGTKTheme();
bool settingsFound = false;
while (!file.atEnd()) {
QByteArray line = file.readLine().trimmed();
Expand All @@ -287,7 +288,26 @@ QString ConfigOtherToolKits::getGTKThemeFromRCFile(QString version)
file.close();
}
}
return QString();
return getDefaultGTKTheme();
}

QString ConfigOtherToolKits::getDefaultGTKTheme()
{
// Get the GTK default theme. Command line:
// $ gsettings get org.gnome.desktop.interface gtk-theme
QProcess gsettings;
QStringList args;
args << "get" << "org.gnome.desktop.interface" << "gtk-theme";
gsettings.start("gsettings", args);
if(! gsettings.waitForFinished())
return QString();
QByteArray defaultTheme = gsettings.readAll();
gsettings.close();
if(defaultTheme.size() <= 1)
return QString();
// The theme has got quotation marks. Remove it:
defaultTheme.replace("'","");
return QString(defaultTheme);
}

void ConfigOtherToolKits::updateConfigFromSettings()
Expand Down
1 change: 1 addition & 0 deletions lxqt-config-appearance/configothertoolkits.h
Expand Up @@ -42,6 +42,7 @@ class ConfigOtherToolKits : public QObject
QString getGTKThemeFromRCFile(QString version);
QString getGTKConfigPath(QString version);
bool backupGTKSettings(QString version);
QString getDefaultGTKTheme();

public slots:
void setConfig();
Expand Down

0 comments on commit 10945b9

Please sign in to comment.