Changeset View
Changeset View
Standalone View
Standalone View
src/appearancegtk3.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 37 | { | |||
---|---|---|---|---|---|
58 | 58 | | |||
59 | return themes; | 59 | return themes; | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | bool AppearanceGTK3::saveSettings(const KSharedConfig::Ptr& file) const | 62 | bool AppearanceGTK3::saveSettings(const KSharedConfig::Ptr& file) const | ||
63 | { | 63 | { | ||
64 | KConfigGroup group(file, "Settings"); | 64 | KConfigGroup group(file, "Settings"); | ||
65 | 65 | | |||
66 | group.writeEntry("gtk-font-name", m_settings["font"]); | | |||
67 | group.writeEntry("gtk-theme-name", m_settings["theme"]); | 66 | group.writeEntry("gtk-theme-name", m_settings["theme"]); | ||
68 | group.writeEntry("gtk-icon-theme-name", m_settings["icon"]); | | |||
69 | group.writeEntry("gtk-fallback-icon-theme", m_settings["icon_fallback"]); | | |||
70 | group.writeEntry("gtk-cursor-theme-name", m_settings["cursor"]); | | |||
71 | group.writeEntry("gtk-toolbar-style", m_settings["toolbar_style"]); | | |||
72 | group.writeEntry("gtk-menu-images", m_settings["show_icons_menus"]); | | |||
73 | group.writeEntry("gtk-button-images", m_settings["show_icons_buttons"]); | | |||
74 | group.writeEntry("gtk-primary-button-warps-slider", m_settings["primary_button_warps_slider"]); | 67 | group.writeEntry("gtk-primary-button-warps-slider", m_settings["primary_button_warps_slider"]); | ||
75 | group.writeEntry("gtk-application-prefer-dark-theme", m_settings["application_prefer_dark_theme"]); | 68 | group.writeEntry("gtk-application-prefer-dark-theme", m_settings["application_prefer_dark_theme"]); | ||
76 | 69 | | |||
77 | const bool sync = group.sync(); | 70 | const bool sync = group.sync(); | ||
78 | Q_ASSERT(sync); | 71 | Q_ASSERT(sync); | ||
79 | return true; | 72 | return true; | ||
80 | } | 73 | } | ||
81 | 74 | | |||
82 | bool AppearanceGTK3::loadSettings(const KSharedConfig::Ptr& file) | 75 | bool AppearanceGTK3::loadSettings(const KSharedConfig::Ptr& file) | ||
83 | { | 76 | { | ||
84 | KConfigGroup group(file, "Settings"); | 77 | KConfigGroup group(file, "Settings"); | ||
85 | 78 | | |||
86 | if (!file || !group.isValid()) { | 79 | if (!file || !group.isValid()) { | ||
87 | qWarning() << "Cannot open the GTK3 config file" << file; | 80 | qWarning() << "Cannot open the GTK3 config file" << file; | ||
88 | return false; | 81 | return false; | ||
89 | } | 82 | } | ||
90 | 83 | | |||
91 | m_settings = QMap<QString, QString> { | 84 | m_settings = QMap<QString, QString> { | ||
92 | {"toolbar_style", "GTK_TOOLBAR_ICONS"}, | | |||
93 | {"show_icons_buttons", "0"}, | | |||
94 | {"show_icons_menus", "0"}, | | |||
95 | {"primary_button_warps_slider", "false"}, | 85 | {"primary_button_warps_slider", "false"}, | ||
96 | {"application_prefer_dark_theme", "false"} | 86 | {"application_prefer_dark_theme", "false"} | ||
97 | }; | 87 | }; | ||
98 | 88 | | |||
99 | m_settings["theme"] = group.readEntry("gtk-theme-name"); | 89 | m_settings["theme"] = group.readEntry("gtk-theme-name"); | ||
100 | m_settings["icon"] = group.readEntry("gtk-icon-theme-name"); | | |||
101 | m_settings["icon_fallback"] = group.readEntry("gtk-fallback-icon-theme"); | | |||
102 | m_settings["cursor"] = group.readEntry("gtk-cursor-theme-name"); | | |||
103 | m_settings["font"] = group.readEntry("gtk-font-name"); | | |||
104 | m_settings["toolbar_style"] = group.readEntry("gtk-toolbar-style"); | | |||
105 | m_settings["show_icons_buttons"] = group.readEntry("gtk-button-images"); | | |||
106 | m_settings["show_icons_menus"] = group.readEntry("gtk-menu-images"); | | |||
107 | m_settings["primary_button_warps_slider"] = group.readEntry("gtk-primary-button-warps-slider"); | 90 | m_settings["primary_button_warps_slider"] = group.readEntry("gtk-primary-button-warps-slider"); | ||
108 | m_settings["application_prefer_dark_theme"] = group.readEntry("gtk-application-prefer-dark-theme"); | 91 | m_settings["application_prefer_dark_theme"] = group.readEntry("gtk-application-prefer-dark-theme"); | ||
109 | for(auto it = m_settings.begin(); it != m_settings.end(); ) { | 92 | for(auto it = m_settings.begin(); it != m_settings.end(); ) { | ||
110 | if (it.value().isEmpty()) | 93 | if (it.value().isEmpty()) | ||
111 | it = m_settings.erase(it); | 94 | it = m_settings.erase(it); | ||
112 | else | 95 | else | ||
113 | ++it; | 96 | ++it; | ||
114 | } | 97 | } | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 144 | { | |||
162 | // FIXME kdebz#387417 | 145 | // FIXME kdebz#387417 | ||
163 | // We should maybe use GSettings everywhere in future, but at this moment we | 146 | // We should maybe use GSettings everywhere in future, but at this moment we | ||
164 | // need this to have this configuration available in sandboxed applications which | 147 | // need this to have this configuration available in sandboxed applications which | ||
165 | // is only possible through dconf | 148 | // is only possible through dconf | ||
166 | gtk_init(nullptr, nullptr); | 149 | gtk_init(nullptr, nullptr); | ||
167 | 150 | | |||
168 | g_autoptr(GSettings) gsettings = g_settings_new("org.gnome.desktop.interface"); | 151 | g_autoptr(GSettings) gsettings = g_settings_new("org.gnome.desktop.interface"); | ||
169 | g_settings_set_string(gsettings, "gtk-theme", m_settings["theme"].toUtf8().constData()); | 152 | g_settings_set_string(gsettings, "gtk-theme", m_settings["theme"].toUtf8().constData()); | ||
170 | g_settings_set_string(gsettings, "icon-theme", m_settings["icon"].toUtf8().constData()); | | |||
171 | g_settings_set_string(gsettings, "cursor-theme", m_settings["cursor"].toUtf8().constData()); | | |||
172 | g_settings_set_string(gsettings, "font-name", m_settings["font"].toUtf8().constData()); | | |||
173 | | ||||
174 | QString toolbarStyle; | | |||
175 | if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_ICONS")) { | | |||
176 | toolbarStyle = QStringLiteral("icons"); | | |||
177 | } else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_TEXT")) { | | |||
178 | toolbarStyle = QStringLiteral("text"); | | |||
179 | } else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_BOTH")) { | | |||
180 | toolbarStyle = QStringLiteral("both"); | | |||
181 | } else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_BOTH_HORIZ")) { | | |||
182 | toolbarStyle = QStringLiteral("both-horiz"); | | |||
183 | } | | |||
184 | | ||||
185 | g_settings_set_string(gsettings, "toolbar-style", toolbarStyle.toUtf8().constData()); | | |||
186 | 153 | | |||
187 | g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", getApplicationPreferDarkTheme(), nullptr); | 154 | g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", getApplicationPreferDarkTheme(), nullptr); | ||
188 | 155 | | |||
189 | auto cfg = KSharedConfig::openConfig(configFileName(), KConfig::NoGlobals); | 156 | auto cfg = KSharedConfig::openConfig(configFileName(), KConfig::NoGlobals); | ||
190 | return saveSettings(cfg); | 157 | return saveSettings(cfg); | ||
191 | } | 158 | } |