Changeset View
Changeset View
Standalone View
Standalone View
kded/configeditor.cpp
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 96 | { | |||
---|---|---|---|---|---|
102 | QString gtkrcContents = readFileContents(gtkrc); | 102 | QString gtkrcContents = readFileContents(gtkrc); | ||
103 | replaceValueInGtkrcContents(gtkrcContents, paramName, paramValue); | 103 | replaceValueInGtkrcContents(gtkrcContents, paramName, paramValue); | ||
104 | gtkrc.remove(); | 104 | gtkrc.remove(); | ||
105 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | 105 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | ||
106 | gtkrc.write(gtkrcContents.toUtf8()); | 106 | gtkrc.write(gtkrcContents.toUtf8()); | ||
107 | reloadGtk2Apps(); | 107 | reloadGtk2Apps(); | ||
108 | } | 108 | } | ||
109 | 109 | | |||
110 | void ConfigEditor::setClientSideDecorations(const QMap<QString, QPixmap> &windowDecorationsButtonsImages) | ||||
111 | { | ||||
112 | saveWindowDecorationsToAssets(windowDecorationsButtonsImages); | ||||
113 | addImportStatementsToGtkCssUserFile(); | ||||
114 | modifyWindowDecorationsCssFile(); | ||||
115 | } | ||||
116 | | ||||
110 | void ConfigEditor::setGtk3Colors(const QMap<QString, QColor> &colorsDefinitions) | 117 | void ConfigEditor::setGtk3Colors(const QMap<QString, QColor> &colorsDefinitions) | ||
111 | { | 118 | { | ||
112 | addImportStatementToGtkCssUserFile(); | 119 | addImportStatementsToGtkCssUserFile(); | ||
113 | modifyColorsCssFile(colorsDefinitions); | 120 | modifyColorsCssFile(colorsDefinitions); | ||
114 | addGtkModule(QStringLiteral("colorreload-gtk-module")); | 121 | addGtkModule(QStringLiteral("colorreload-gtk-module")); | ||
115 | } | 122 | } | ||
116 | 123 | | |||
117 | 124 | | |||
118 | QString ConfigEditor::gtk2ConfigValue(const QString& paramName) | 125 | QString ConfigEditor::gtk2ConfigValue(const QString& paramName) | ||
119 | { | 126 | { | ||
120 | QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); | 127 | QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 155 | { | |||
167 | gtkrcContents.remove(userFontStyleRegexp); | 174 | gtkrcContents.remove(userFontStyleRegexp); | ||
168 | 175 | | |||
169 | gtkrc.remove(); | 176 | gtkrc.remove(); | ||
170 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | 177 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | ||
171 | gtkrc.write(gtkrcContents.toUtf8()); | 178 | gtkrc.write(gtkrcContents.toUtf8()); | ||
172 | reloadGtk2Apps(); | 179 | reloadGtk2Apps(); | ||
173 | } | 180 | } | ||
174 | 181 | | |||
182 | void ConfigEditor::saveWindowDecorationsToAssets(const QMap<QString, QPixmap>& windowDecorationsButtonsImages) | ||||
183 | { | ||||
184 | QDir assetsFolder {QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/assets")}; | ||||
185 | | ||||
186 | if (!assetsFolder.exists()) { | ||||
187 | assetsFolder.mkpath(QStringLiteral(".")); | ||||
188 | } | ||||
189 | | ||||
190 | for (auto it = windowDecorationsButtonsImages.cbegin(); it != windowDecorationsButtonsImages.cend(); it++) { | ||||
191 | QString filePath = QStringLiteral("%1/%2.png").arg(assetsFolder.path(), it.key()); | ||||
192 | | ||||
193 | QFile file {filePath}; | ||||
194 | file.open(QIODevice::ReadWrite | QIODevice::Truncate); | ||||
195 | it.value().save(&file, "PNG"); | ||||
196 | } | ||||
197 | } | ||||
198 | | ||||
199 | void ConfigEditor::modifyWindowDecorationsCssFile() | ||||
200 | { | ||||
201 | QString windowDecorationsCssPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/windowDecorations.css"); | ||||
202 | QFile windowDecorationsCss(windowDecorationsCssPath); | ||||
203 | | ||||
204 | if (windowDecorationsCss.open(QIODevice::WriteOnly | QIODevice::Truncate)) { | ||||
205 | QTextStream colorsCssStream(&windowDecorationsCss); | ||||
206 | | ||||
207 | // TODO: Write appropriate css | ||||
208 | | ||||
209 | } | ||||
210 | } | ||||
211 | | ||||
175 | void ConfigEditor::addGtkModule(const QString& moduleName) | 212 | void ConfigEditor::addGtkModule(const QString& moduleName) | ||
176 | { | 213 | { | ||
177 | const QString currentModulesString = gtk3ConfigValueSettingsIni(QStringLiteral("gtk-modules")); | 214 | const QString currentModulesString = gtk3ConfigValueSettingsIni(QStringLiteral("gtk-modules")); | ||
178 | 215 | | |||
179 | if (currentModulesString.contains(moduleName)) { | 216 | if (currentModulesString.contains(moduleName)) { | ||
180 | return; | 217 | return; | ||
181 | } | 218 | } | ||
182 | 219 | | |||
183 | if (currentModulesString.isEmpty()) { // No modules | 220 | if (currentModulesString.isEmpty()) { // No modules | ||
184 | setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-modules"), moduleName); | 221 | setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-modules"), moduleName); | ||
185 | } else { | 222 | } else { | ||
186 | setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-modules"), QStringLiteral("%1:%2").arg(currentModulesString, moduleName)); | 223 | setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-modules"), QStringLiteral("%1:%2").arg(currentModulesString, moduleName)); | ||
187 | } | 224 | } | ||
188 | } | 225 | } | ||
189 | 226 | | |||
190 | void ConfigEditor::addImportStatementToGtkCssUserFile() | 227 | void ConfigEditor::addImportStatementsToGtkCssUserFile() | ||
191 | { | 228 | { | ||
192 | QString gtkCssPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/gtk.css"); | 229 | QString gtkCssPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/gtk.css"); | ||
193 | QFile gtkCss(gtkCssPath); | 230 | QFile gtkCss(gtkCssPath); | ||
194 | 231 | | |||
195 | if (gtkCss.open(QIODevice::ReadWrite)) { | 232 | if (gtkCss.open(QIODevice::ReadWrite)) { | ||
196 | QByteArray gtkCssContents = gtkCss.readAll(); | 233 | QByteArray gtkCssContents = gtkCss.readAll(); | ||
197 | 234 | | |||
198 | static const QByteArray importStatement = QByteArrayLiteral("@import 'colors.css';"); | 235 | static const QVector<QByteArray> importStatements { | ||
199 | if (!gtkCssContents.contains(importStatement)) { | 236 | QByteArrayLiteral("\n@import 'colors.css';"), | ||
237 | QByteArrayLiteral("\n@import 'windowDecorations.css';"), | ||||
238 | }; | ||||
239 | | ||||
240 | for (const auto &statement : importStatements) { | ||||
241 | if (!gtkCssContents.contains(statement.trimmed())) { | ||||
200 | QTextStream gtkCssStream(>kCss); | 242 | QTextStream gtkCssStream(>kCss); | ||
201 | gtkCssStream << importStatement; | 243 | gtkCssStream << statement; | ||
244 | } | ||||
202 | } | 245 | } | ||
203 | } | 246 | } | ||
204 | } | 247 | } | ||
205 | 248 | | |||
206 | void ConfigEditor::modifyColorsCssFile(const QMap<QString, QColor> &colorsDefinitions) | 249 | void ConfigEditor::modifyColorsCssFile(const QMap<QString, QColor> &colorsDefinitions) | ||
207 | { | 250 | { | ||
208 | QString colorsCssPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/colors.css"); | 251 | QString colorsCssPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/colors.css"); | ||
209 | QFile colorsCss(colorsCssPath); | 252 | QFile colorsCss(colorsCssPath); | ||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |