Changeset View
Changeset View
Standalone View
Standalone View
kded/configeditor.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 <QDebug> | 21 | #include <QColor> | ||
22 | #include <QDir> | 22 | #include <QDir> | ||
23 | #include <QRegularExpression> | 23 | #include <QRegularExpression> | ||
24 | #include <QStandardPaths> | 24 | #include <QStandardPaths> | ||
25 | #include <QProcess> | 25 | #include <QProcess> | ||
26 | #include <QMap> | ||||
27 | #include <QList> | ||||
28 | #include <QTextStream> | ||||
26 | 29 | | |||
27 | #include <KSharedConfig> | 30 | #include <KSharedConfig> | ||
28 | #include <KConfigGroup> | 31 | #include <KConfigGroup> | ||
32 | #include <KColorScheme> | ||||
33 | #include <KColorUtils> | ||||
29 | 34 | | |||
30 | #include <string> | 35 | #include <string> | ||
31 | #include <csignal> | 36 | #include <csignal> | ||
32 | #include <cstdio> | 37 | #include <cstdio> | ||
33 | 38 | | |||
34 | #include <gio/gio.h> | 39 | #include <gio/gio.h> | ||
35 | 40 | | |||
36 | #include "configeditor.h" | 41 | #include "configeditor.h" | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 89 | { | |||
90 | QString gtkrcContents = readFileContents(gtkrc); | 95 | QString gtkrcContents = readFileContents(gtkrc); | ||
91 | replaceValueInGtkrcContents(gtkrcContents, paramName, paramValue); | 96 | replaceValueInGtkrcContents(gtkrcContents, paramName, paramValue); | ||
92 | gtkrc.remove(); | 97 | gtkrc.remove(); | ||
93 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | 98 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | ||
94 | gtkrc.write(gtkrcContents.toUtf8()); | 99 | gtkrc.write(gtkrcContents.toUtf8()); | ||
95 | reloadGtk2Apps(); | 100 | reloadGtk2Apps(); | ||
96 | } | 101 | } | ||
97 | 102 | | |||
103 | void ConfigEditor::setGtk3Colors(const QMap<QString, QColor> &colorsDefinitions) | ||||
104 | { | ||||
105 | addImportStatementToGtkCssUserFile(); | ||||
106 | modifyColorsCssFile(colorsDefinitions); | ||||
107 | // FIXME Find a way to update colors on the fly | ||||
gikari: Also, I would like to move D24275 to kde-gtk-config repo too with autoloading the module to all… | |||||
108 | } | ||||
109 | | ||||
110 | | ||||
98 | QString ConfigEditor::gtk2ConfigValue(const QString& paramName) | 111 | QString ConfigEditor::gtk2ConfigValue(const QString& paramName) | ||
99 | { | 112 | { | ||
100 | QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); | 113 | QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); | ||
101 | QFile gtkrc(gtkrcPath); | 114 | QFile gtkrc(gtkrcPath); | ||
102 | if (gtkrc.open(QIODevice::ReadWrite | QIODevice::Text)) { | 115 | if (gtkrc.open(QIODevice::ReadWrite | QIODevice::Text)) { | ||
103 | const QRegularExpression regExp(paramName + QStringLiteral("=[^\n]*($|\n)")); | 116 | const QRegularExpression regExp(paramName + QStringLiteral("=[^\n]*($|\n)")); | ||
104 | while (!gtkrc.atEnd()) { | 117 | while (!gtkrc.atEnd()) { | ||
105 | QString line = gtkrc.readLine(); | 118 | QString line = gtkrc.readLine(); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 141 | { | |||
147 | gtkrcContents.remove(userFontStyleRegexp); | 160 | gtkrcContents.remove(userFontStyleRegexp); | ||
148 | 161 | | |||
149 | gtkrc.remove(); | 162 | gtkrc.remove(); | ||
150 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | 163 | gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); | ||
151 | gtkrc.write(gtkrcContents.toUtf8()); | 164 | gtkrc.write(gtkrcContents.toUtf8()); | ||
152 | reloadGtk2Apps(); | 165 | reloadGtk2Apps(); | ||
153 | } | 166 | } | ||
154 | 167 | | |||
168 | void ConfigEditor::addImportStatementToGtkCssUserFile() | ||||
169 | { | ||||
170 | QString gtkCssPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/gtk.css"); | ||||
171 | QFile gtkCss(gtkCssPath); | ||||
172 | | ||||
173 | if (gtkCss.open(QIODevice::ReadWrite)) { | ||||
174 | QByteArray gtkCssContents = gtkCss.readAll(); | ||||
175 | | ||||
176 | static const QByteArray importStatement = QByteArrayLiteral("@import 'colors.css';"); | ||||
177 | if (!gtkCssContents.contains(importStatement)) { | ||||
178 | QTextStream gtkCssStream(>kCss); | ||||
179 | gtkCssStream << importStatement; | ||||
180 | } | ||||
181 | } | ||||
182 | } | ||||
183 | | ||||
184 | void ConfigEditor::modifyColorsCssFile(const QMap<QString, QColor> &colorsDefinitions) | ||||
185 | { | ||||
186 | QString colorsCssPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/gtk-3.0/colors.css"); | ||||
187 | QFile colorsCss(colorsCssPath); | ||||
188 | | ||||
189 | if (colorsCss.open(QIODevice::WriteOnly | QIODevice::Truncate)) { | ||||
190 | QTextStream colorsCssStream(&colorsCss); | ||||
191 | | ||||
192 | for (auto it = colorsDefinitions.cbegin(); it != colorsDefinitions.cend(); it++) { | ||||
193 | colorsCssStream << QStringLiteral("@define-color %1 %2;\n").arg(it.key(), it.value().name()); | ||||
194 | } | ||||
195 | } | ||||
196 | } | ||||
197 | | ||||
155 | QString ConfigEditor::readFileContents(QFile &file) | 198 | QString ConfigEditor::readFileContents(QFile &file) | ||
156 | { | 199 | { | ||
157 | if (file.open(QIODevice::ReadWrite | QIODevice::Text)) { | 200 | if (file.open(QIODevice::ReadWrite | QIODevice::Text)) { | ||
158 | return file.readAll(); | 201 | return file.readAll(); | ||
159 | } else { | 202 | } else { | ||
160 | return QString(); | 203 | return QString(); | ||
161 | } | 204 | } | ||
162 | } | 205 | } | ||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |
Also, I would like to move D24275 to kde-gtk-config repo too with autoloading the module to all GTK applications.