Changeset View
Changeset View
Standalone View
Standalone View
kconf_update/gtktheme.cpp
Show All 12 Lines | |||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include <QDir> | ||||
21 | #include <QString> | 22 | #include <QString> | ||
22 | #include <QVariant> | 23 | #include <QVariant> | ||
24 | #include <QRegularExpression> | ||||
23 | 25 | | |||
24 | #include "configeditor.h" | 26 | #include "configeditor.h" | ||
25 | 27 | | |||
28 | QString gtk2Theme(); | ||||
26 | void upgradeGtk2Theme(); | 29 | void upgradeGtk2Theme(); | ||
27 | void upgradeGtk3Theme(); | 30 | void upgradeGtk3Theme(); | ||
28 | 31 | | |||
29 | int main() { | 32 | int main() { | ||
30 | upgradeGtk2Theme(); | 33 | upgradeGtk2Theme(); | ||
31 | upgradeGtk3Theme(); | 34 | upgradeGtk3Theme(); | ||
32 | return 0; | 35 | return 0; | ||
33 | } | 36 | } | ||
34 | 37 | | |||
35 | void upgradeGtk2Theme() { | 38 | void upgradeGtk2Theme() { | ||
36 | QString currentGtk2Theme = ConfigEditor::gtk2ConfigValue(QStringLiteral("gtk-theme-name")); | 39 | QString currentGtk2Theme = gtk2Theme(); | ||
37 | if (currentGtk2Theme.isEmpty() | 40 | if (currentGtk2Theme.isEmpty() | ||
38 | || currentGtk2Theme == QStringLiteral("oxygen-gtk") | 41 | || currentGtk2Theme == QStringLiteral("oxygen-gtk") | ||
39 | || currentGtk2Theme == QStringLiteral("BreezyGTK") | 42 | || currentGtk2Theme == QStringLiteral("BreezyGTK") | ||
40 | || currentGtk2Theme == QStringLiteral("Orion") | 43 | || currentGtk2Theme == QStringLiteral("Orion") | ||
41 | ) { | 44 | ) { | ||
42 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-theme-name"), QStringLiteral("Breeze")); | 45 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-theme-name"), QStringLiteral("Breeze")); | ||
43 | } | 46 | } | ||
44 | } | 47 | } | ||
45 | 48 | | |||
46 | void upgradeGtk3Theme() { | 49 | void upgradeGtk3Theme() { | ||
47 | QString currentGtk3Theme = ConfigEditor::gtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name")); | 50 | QString currentGtk3Theme = ConfigEditor::gtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name")); | ||
48 | if (currentGtk3Theme.isEmpty() | 51 | if (currentGtk3Theme.isEmpty() | ||
49 | || currentGtk3Theme == QStringLiteral("oxygen-gtk") | 52 | || currentGtk3Theme == QStringLiteral("oxygen-gtk") | ||
50 | || currentGtk3Theme == QStringLiteral("BreezyGTK") | 53 | || currentGtk3Theme == QStringLiteral("BreezyGTK") | ||
51 | || currentGtk3Theme == QStringLiteral("Orion") | 54 | || currentGtk3Theme == QStringLiteral("Orion") | ||
52 | ) { | 55 | ) { | ||
53 | ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("gtk-theme"), QStringLiteral("Breeze")); | 56 | ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("gtk-theme"), QStringLiteral("Breeze")); | ||
54 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name"), QStringLiteral("Breeze")); | 57 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name"), QStringLiteral("Breeze")); | ||
55 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/ThemeName"), QStringLiteral("Breeze")); | 58 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/ThemeName"), QStringLiteral("Breeze")); | ||
56 | } | 59 | } | ||
57 | } | 60 | } | ||
61 | | ||||
62 | QString gtk2Theme() | ||||
63 | { | ||||
64 | QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); | ||||
65 | QFile gtkrc(gtkrcPath); | ||||
66 | if (gtkrc.open(QIODevice::ReadWrite | QIODevice::Text)) { | ||||
67 | const QRegularExpression regExp(QStringLiteral("gtk-theme-name=[^\n]*($|\n)")); | ||||
68 | while (!gtkrc.atEnd()) { | ||||
69 | QString line = gtkrc.readLine(); | ||||
70 | if (line.contains(regExp)) { | ||||
71 | return line.split('"')[1]; | ||||
72 | } | ||||
73 | } | ||||
74 | } | ||||
75 | | ||||
76 | return QString(); | ||||
77 | } |