Changeset View
Changeset View
Standalone View
Standalone View
kconf_update/main.cpp
Show All 25 Lines | |||||
26 | #include <QLoggingCategory> | 26 | #include <QLoggingCategory> | ||
27 | #include <QSettings> | 27 | #include <QSettings> | ||
28 | #include <QDir> | 28 | #include <QDir> | ||
29 | 29 | | |||
30 | Q_DECLARE_LOGGING_CATEGORY(GTKBREEZE) | 30 | Q_DECLARE_LOGGING_CATEGORY(GTKBREEZE) | ||
31 | Q_LOGGING_CATEGORY(GTKBREEZE, "gtkbreeze") | 31 | Q_LOGGING_CATEGORY(GTKBREEZE, "gtkbreeze") | ||
32 | 32 | | |||
33 | /* | 33 | /* | ||
34 | * returns whether a GTK 3 theme with the given name is installed | ||||
35 | * themeName: Name of gtk 3 theme | ||||
36 | */ | ||||
37 | static bool isGTK3ThemeInstalled(QString themeName) | ||||
apol: Seems like it would return a bool.
I would change it to `gtk3ThemeInstalledPath()`. I know it… | |||||
38 | { | ||||
39 | // Check that the theme contains a gtk-3.* subdirectory | ||||
40 | QStringList gtk3SubdirPattern{QStringLiteral("gtk-3.*")}; | ||||
41 | foreach (const QString& themesDir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { | ||||
42 | QDir themeDir(themesDir + QDir::separator() + themeName); | ||||
43 | if (!themeDir.entryList(gtk3SubdirPattern, QDir::Dirs).isEmpty()) { | ||||
44 | return true; | ||||
apol: + QLatin1Char('/') + | |||||
45 | } | ||||
46 | } | ||||
47 | return false; | ||||
apol: `return {};` | |||||
48 | } | ||||
49 | | ||||
50 | /* | ||||
34 | * returns a path to the installed gtk if it can be found | 51 | * returns a path to the installed gtk if it can be found | ||
35 | * themeName: gtk theme | 52 | * themeName: gtk theme | ||
36 | * settingsFile: a file installed with the theme to set default options | 53 | * settingsFile: a file installed with the theme to set default options | ||
37 | */ | 54 | */ | ||
38 | QString isGtkThemeInstalled(QString themeName, QString settingsFile) | 55 | static QString gtk2ThemePath(QString themeName, QString settingsFile) | ||
39 | { | 56 | { | ||
40 | foreach (const QString& themesDir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { | 57 | foreach (const QString& themesDir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { | ||
41 | if (QFile::exists(themesDir + QDir::separator() + themeName + QDir::separator() + settingsFile)) { | 58 | if (QFile::exists(themesDir + QDir::separator() + themeName + QDir::separator() + settingsFile)) { | ||
42 | return themesDir + "/" + themeName; | 59 | return themesDir + QDir::separator() + themeName; | ||
43 | } | 60 | } | ||
44 | } | 61 | } | ||
45 | return 0; | 62 | return {}; | ||
46 | } | 63 | } | ||
47 | 64 | | |||
48 | /* | 65 | /* | ||
49 | * Check if gtk theme is already set to oxygen or Orion, if it is then we want to upgrade to the breeze theme | 66 | * Check if gtk theme is already set to oxygen or Orion, if it is then we want to upgrade to the breeze theme | ||
50 | * gtkSettingsFile: filename to use | 67 | * gtkSettingsFile: filename to use | ||
51 | * settingsKey: ini group to read from | 68 | * settingsKey: ini group to read from | ||
52 | * returns: full path to settings file | 69 | * returns: full path to settings file | ||
53 | */ | 70 | */ | ||
Show All 29 Lines | |||||
83 | * Set gtk2 theme if no theme is set or if oxygen is set and gtk theme is installed | 100 | * Set gtk2 theme if no theme is set or if oxygen is set and gtk theme is installed | ||
84 | */ | 101 | */ | ||
85 | int setGtk2() | 102 | int setGtk2() | ||
86 | { | 103 | { | ||
87 | const QString gtk2Theme = QStringLiteral("Breeze"); | 104 | const QString gtk2Theme = QStringLiteral("Breeze"); | ||
88 | const QString gtkrc2path = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first() + QDir::separator() + QStringLiteral(".gtkrc-2.0"); | 105 | const QString gtkrc2path = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first() + QDir::separator() + QStringLiteral(".gtkrc-2.0"); | ||
89 | const QString gtk2ThemeSettings = QStringLiteral("gtk-2.0/gtkrc"); // system installed file to check for | 106 | const QString gtk2ThemeSettings = QStringLiteral("gtk-2.0/gtkrc"); // system installed file to check for | ||
90 | 107 | | |||
91 | const QString gtkThemeDirectory = isGtkThemeInstalled(gtk2Theme, gtk2ThemeSettings); | 108 | const QString gtkThemeDirectory = gtk2ThemePath(gtk2Theme, gtk2ThemeSettings); | ||
92 | 109 | | |||
93 | if (gtkThemeDirectory == 0) { | 110 | if (gtkThemeDirectory.isEmpty()) { | ||
94 | qCDebug(GTKBREEZE) << "Breeze GTK 3 not found, quitting"; | 111 | qCDebug(GTKBREEZE) << "Breeze GTK 2 not found, quitting"; | ||
95 | return 0; | 112 | return 0; | ||
96 | } | 113 | } | ||
97 | qCDebug(GTKBREEZE) << "found gtktheme: " << gtkThemeDirectory; | 114 | qCDebug(GTKBREEZE) << "found gtktheme: " << gtkThemeDirectory; | ||
98 | 115 | | |||
99 | bool needsUpdate = isGtkThemeSetToOldTheme(gtkrc2path, QString()); | 116 | bool needsUpdate = isGtkThemeSetToOldTheme(gtkrc2path, QString()); | ||
100 | if (needsUpdate == false) { | 117 | if (needsUpdate == false) { | ||
101 | qCDebug(GTKBREEZE) << "gtkrc2 already exists and is not using oxygen or orion, quitting"; | 118 | qCDebug(GTKBREEZE) << "gtkrc2 already exists and is not using oxygen or orion, quitting"; | ||
102 | return 0; | 119 | return 0; | ||
Show All 25 Lines | |||||
128 | } | 145 | } | ||
129 | 146 | | |||
130 | /* | 147 | /* | ||
131 | * Set gtk3 theme if no theme is set or if oxygen is set and gtk theme is installed | 148 | * Set gtk3 theme if no theme is set or if oxygen is set and gtk theme is installed | ||
132 | */ | 149 | */ | ||
133 | int setGtk3() | 150 | int setGtk3() | ||
134 | { | 151 | { | ||
135 | const QString gtk3Theme = QStringLiteral("Breeze"); | 152 | const QString gtk3Theme = QStringLiteral("Breeze"); | ||
136 | const QString gtk3ThemeSettings = QStringLiteral("gtk-3.0/gtk.css"); // check for installed /usr/share/themes/Breeze/gtk-3.0/gtk.css | | |||
137 | 153 | | |||
138 | const QString gtkThemeDirectory = isGtkThemeInstalled(gtk3Theme, gtk3ThemeSettings); | 154 | if (!isGTK3ThemeInstalled(gtk3Theme)) { | ||
139 | if (gtkThemeDirectory == 0) { | | |||
140 | qCDebug(GTKBREEZE) << "not found, quitting"; | 155 | qCDebug(GTKBREEZE) << "not found, quitting"; | ||
141 | return 0; | 156 | return 0; | ||
142 | } | 157 | } | ||
143 | qCDebug(GTKBREEZE) << "found gtk3theme:" << gtkThemeDirectory; | 158 | qCDebug(GTKBREEZE) << "found gtk3theme"; | ||
144 | QString configPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); | 159 | QString configPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); | ||
145 | QString gtkrc3path = configPath + "/gtk-3.0/settings.ini"; | 160 | QString gtkrc3path = configPath + "/gtk-3.0/settings.ini"; | ||
apol: Does this need fixing too? | |||||
No, that's the location of the config file, which is always ~/.config/gtk-3.0/settings.ini. Maybe it can be overwritten, but that would cause other problems. fvogt: No, that's the location of the config file, which is always `~/.config/gtk-3.0/settings.ini`. | |||||
146 | bool needsUpdate = isGtkThemeSetToOldTheme(gtkrc3path, "Settings"); | 161 | bool needsUpdate = isGtkThemeSetToOldTheme(gtkrc3path, "Settings"); | ||
147 | if ( !needsUpdate ) { | 162 | if ( !needsUpdate ) { | ||
148 | qCDebug(GTKBREEZE) << "gtkrc3 already exists and is not using oxygen/orion, quitting"; | 163 | qCDebug(GTKBREEZE) << "gtkrc3 already exists and is not using oxygen/orion, quitting"; | ||
149 | return 0; | 164 | return 0; | ||
150 | } | 165 | } | ||
151 | QDir dir = QFileInfo(gtkrc3path).dir(); | 166 | QDir dir = QFileInfo(gtkrc3path).dir(); | ||
152 | dir.mkpath(dir.path()); | 167 | dir.mkpath(dir.path()); | ||
153 | 168 | | |||
Show All 31 Lines |
Seems like it would return a bool.
I would change it to gtk3ThemeInstalledPath(). I know it wasn't your idea and there's already a isGtkThemeInstalled for gtk2, but it looks hard to figure out still. Feel free to change the other one if you like.