diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake kded/config.h) -add_subdirectory(gtkproxies) add_subdirectory(gtk3proxies) add_subdirectory(kded) add_subdirectory(kconf_update) diff --git a/gtkproxies/CMakeLists.txt b/gtkproxies/CMakeLists.txt deleted file mode 100644 --- a/gtkproxies/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable(reload_gtk_apps reload.c) -target_link_libraries(reload_gtk_apps PkgConfig::GTK+2) -install(TARGETS reload_gtk_apps RUNTIME DESTINATION "${LIBEXEC_INSTALL_DIR}") - -add_executable(gtk_preview preview.c) -target_compile_definitions(gtk_preview PRIVATE "-DDATA_DIR=\"${KDE_INSTALL_FULL_DATADIR}/kcm-gtk-module/\"") -target_link_libraries(gtk_preview PkgConfig::GTK+2) -install(TARGETS gtk_preview RUNTIME DESTINATION "${LIBEXEC_INSTALL_DIR}") - -# preview file used for the gtk3 version too -install(FILES preview.ui - DESTINATION ${DATA_INSTALL_DIR}/kcm-gtk-module/) diff --git a/gtkproxies/preview.c b/gtkproxies/preview.c deleted file mode 100644 --- a/gtkproxies/preview.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2011 Aleix Pol Gonzalez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * #include - */ - -#include -#include -#include -#include -#include - -static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data) -{ - switch(res) - { - default: - gtk_main_quit(); - } -} - -void reloadstyle(GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event_type, - gpointer user_data) -{ - if(event_type!=G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) - return; - - fprintf(stderr, "changing settings... %d\n", event_type); - gtk_rc_reparse_all(); - fprintf(stderr, "settings changed!!\n"); -} - -void printHelp() -{ - printf( - "Small utility for previewing Gtk2 theme.\n" - "\n" - "Using:\n" - "gtk_preview \n" - "\n" - "Arguments:\n" - " -h, --help\tShows this help\n" - " -V, --version\tPrints the program version\n" - " \t Creates a window that can be embedded using XEmbed\n" - ); -} - -int main(int argc, char **argv) -{ - GError *error = NULL; - unsigned long wid=0; - gtk_init( &argc, &argv ); - int i; - for(i=0; i1) - sscanf(argv[1], "%ld", &wid); - } - const char* ui_file = DATA_DIR "/preview.ui"; - - GtkBuilder *builder = gtk_builder_new(); - if( ! gtk_builder_add_from_file( builder, ui_file, &error ) ) { - g_warning( "%s", error->message ); - g_object_unref( error ); - return 1; - } - - GtkWidget *previewUI = GTK_WIDGET( gtk_builder_get_object( builder, "frame1" ) ); - gtk_builder_connect_signals( builder, NULL ); - - /* a plug when embedded, a window when a window */ - GtkWidget* window; - - if(wid==0) { - window = gtk_dialog_new(); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (window)->vbox), previewUI); - g_signal_connect(window, "response", G_CALLBACK(on_dlg_response), NULL); - } else { - window = gtk_plug_new(wid); - gtk_container_add (GTK_CONTAINER (window), previewUI); - } - - GdkColor black = {0, 0, 0, 0}; - gtk_widget_modify_bg(previewUI, GTK_STATE_NORMAL, &black); - - g_signal_connect (window, "destroy", - G_CALLBACK (gtk_widget_destroyed), - &window); - - gtk_widget_show_all ( window ); - g_object_unref( G_OBJECT( builder ) ); - - if(wid) - fprintf(stderr, "--- is embedded: %d\n", gtk_plug_get_embedded(GTK_PLUG(window))); - - gchar** files = gtk_rc_get_default_files(); - GFile* file = g_file_new_for_path(files[0]); - GFileMonitor* monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, NULL, NULL); - g_signal_connect (monitor, "changed", - G_CALLBACK (reloadstyle), NULL); - - gtk_main(); - - return 0; -} diff --git a/gtkproxies/preview.ui b/gtkproxies/preview.ui deleted file mode 100644 --- a/gtkproxies/preview.ui +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - True - False - 0 - - - True - False - - - True - False - 10 - - - True - False - 2 - - - True - False - - - False - True - False - _File - True - - - False - - - gtk-new - False - True - False - True - True - - - - - gtk-open - False - True - False - True - True - - - - - gtk-save - False - True - False - True - True - - - - - gtk-save-as - False - True - False - True - True - - - - - True - False - - - - - gtk-quit - False - True - False - True - True - - - - - - - - - False - True - False - _Edit - True - - - False - - - gtk-cut - False - True - False - True - True - - - - - gtk-copy - False - True - False - True - True - - - - - gtk-paste - False - True - False - True - True - - - - - gtk-delete - False - True - False - True - True - - - - - - - - - False - True - False - _Help - True - - - False - - - gtk-about - False - True - False - True - True - - - - - - - - - False - False - 0 - - - - - True - False - - - True - False - icons - False - - - False - True - False - False - True - gtk-go-back - - - False - True - - - - - False - True - False - False - gtk-go-forward - - - False - True - - - - - False - True - False - False - True - gtk-stop - - - False - True - - - - - False - True - False - False - - - True - True - - True - - - - - True - True - - - - - - - False - False - 1 - - - - - True - True - 5 - - - True - False - - - True - False - 4 - 0 - - - True - False - 4 - 4 - - - True - False - 4 - - - Radio Button - False - True - True - False - False - True - 0 - True - True - - - False - False - 0 - - - - - Check Button - False - True - True - False - False - True - 0 - True - - - False - False - 1 - - - - - True - False - - - True - True - - True - 1 - - - True - True - 0 - - - - - False - True - True - True - False - - - True - False - 0 - 0 - - - True - False - 2 - - - True - False - gtk-find - - - False - False - 0 - - - - - True - False - button - True - - - False - False - 1 - - - - - - - - - False - False - 1 - - - - - False - True - 2 - - - - - - - - - True - False - Demo - True - - - - - True - True - 0 - - - - - True - False - 4 - - - True - False - 0.60000002384200002 - 0.10000000149 - 60 % - True - - - False - False - 0 - - - - - True - True - 1 - - - False - True - 1 - - - - - True - False - - - - 0 - - - - - False - True - 2 - - - - - True - True - 1 - - - - - - - True - False - Page1 - - - False - - - - - True - True - never - in - - - True - True - False - True - 0 - - - - - - column - - - - 0 - - - - - - - column - - - - 0 - - - - - - - - - 1 - - - - - True - False - Page2 - - - 1 - False - - - - - True - True - 2 - - - - - True - False - 2 - - - False - False - 3 - - - - - - - - - - - - - diff --git a/gtkproxies/reload.c b/gtkproxies/reload.c deleted file mode 100644 --- a/gtkproxies/reload.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2011 Aleix Pol Gonzalez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * #include - */ - -#include -#include -#include -#include - -void printHelp() -{ - printf( - "Small utility for sending signal to reload theme in Gtk programs.\n" - "\n" - "Using:\n" - "reload_gtk_apps \n" - "\n" - "Arguments:\n" - " -h, --help\tShows this help\n" - " -V, --version\tPrints the program version\n" - ); -} -GdkEventClient createEvent() -{ - GdkEventClient event; - event.type = GDK_CLIENT_EVENT; - event.send_event = TRUE; - event.window = NULL; - event.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); - event.data_format = 8; - - return event; -} - -int main(int argc, char** argv) -{ - gtk_init(&argc, &argv); - int i; - for(i=0; i. */ +#include #include #include +#include #include "configeditor.h" +QString gtk2Theme(); void upgradeGtk2Theme(); void upgradeGtk3Theme(); @@ -33,7 +36,7 @@ } void upgradeGtk2Theme() { - QString currentGtk2Theme = ConfigEditor::gtk2ConfigValue(QStringLiteral("gtk-theme-name")); + QString currentGtk2Theme = gtk2Theme(); if (currentGtk2Theme.isEmpty() || currentGtk2Theme == QStringLiteral("oxygen-gtk") || currentGtk2Theme == QStringLiteral("BreezyGTK") @@ -55,3 +58,20 @@ ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/ThemeName"), QStringLiteral("Breeze")); } } + +QString gtk2Theme() +{ + QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); + QFile gtkrc(gtkrcPath); + if (gtkrc.open(QIODevice::ReadWrite | QIODevice::Text)) { + const QRegularExpression regExp(QStringLiteral("gtk-theme-name=[^\n]*($|\n)")); + while (!gtkrc.atEnd()) { + QString line = gtkrc.readLine(); + if (line.contains(regExp)) { + return line.split('"')[1]; + } + } + } + + return QString(); +} diff --git a/kded/configeditor.h b/kded/configeditor.h --- a/kded/configeditor.h +++ b/kded/configeditor.h @@ -37,7 +37,6 @@ void setGtk3Colors(const QMap &colorsDefinitions); - QString gtk2ConfigValue(const QString& paramName); QString gtk3ConfigValueSettingsIni(const QString& paramName); void removeLegacyGtk2Strings(); @@ -52,7 +51,6 @@ QString readFileContents(QFile >krc); - void reloadGtk2Apps(); void reloadXSettingsd(); pid_t pidOfXSettingsd(); diff --git a/kded/configeditor.cpp b/kded/configeditor.cpp --- a/kded/configeditor.cpp +++ b/kded/configeditor.cpp @@ -75,14 +75,14 @@ void ConfigEditor::setGtk3ConfigValueXSettingsd(const QString ¶mName, const QVariant ¶mValue) { QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); - + QDir xsettingsdPath = configLocation + QStringLiteral("/xsettingsd"); if (!xsettingsdPath.exists()) { xsettingsdPath.mkpath(QStringLiteral(".")); } - + QString xSettingsdConfigPath = xsettingsdPath.path() + QStringLiteral("/xsettingsd.conf"); - + QFile xSettingsdConfig(xSettingsdConfigPath); QString xSettingsdConfigContents = readFileContents(xSettingsdConfig); replaceValueInXSettingsdContents(xSettingsdConfigContents, paramName, paramValue); @@ -104,7 +104,6 @@ gtkrc.remove(); gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); gtkrc.write(gtkrcContents.toUtf8()); - reloadGtk2Apps(); } void ConfigEditor::setGtk3Colors(const QMap &colorsDefinitions) @@ -114,24 +113,6 @@ addGtkModule(QStringLiteral("colorreload-gtk-module")); } - -QString ConfigEditor::gtk2ConfigValue(const QString& paramName) -{ - QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); - QFile gtkrc(gtkrcPath); - if (gtkrc.open(QIODevice::ReadWrite | QIODevice::Text)) { - const QRegularExpression regExp(paramName + QStringLiteral("=[^\n]*($|\n)")); - while (!gtkrc.atEnd()) { - QString line = gtkrc.readLine(); - if (line.contains(regExp)) { - return line.split('"')[1]; - } - } - } - - return QString(); -} - QString ConfigEditor::gtk3ConfigValueSettingsIni(const QString& paramName) { QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); @@ -169,7 +150,6 @@ gtkrc.remove(); gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); gtkrc.write(gtkrcContents.toUtf8()); - reloadGtk2Apps(); } void ConfigEditor::addGtkModule(const QString& moduleName) @@ -268,11 +248,6 @@ } } -void ConfigEditor::reloadGtk2Apps() -{ - QProcess::startDetached(QStandardPaths::findExecutable(QStringLiteral("reload_gtk_apps"))); -} - pid_t ConfigEditor::pidOfXSettingsd() { QProcess pidof; diff --git a/kded/gtkconfig.h b/kded/gtkconfig.h --- a/kded/gtkconfig.h +++ b/kded/gtkconfig.h @@ -52,14 +52,9 @@ void applyAllSettings() const; public Q_SLOTS: - Q_SCRIPTABLE void setGtk2Theme(const QString &themeName) const; - Q_SCRIPTABLE void setGtk3Theme(const QString &themeName) const; - - Q_SCRIPTABLE QString gtk2Theme() const; - Q_SCRIPTABLE QString gtk3Theme() const; - - Q_SCRIPTABLE void showGtk2ThemePreview(const QString &themeName) const; - Q_SCRIPTABLE void showGtk3ThemePreview(const QString &themeName) const; + Q_SCRIPTABLE void setGtkTheme(const QString &themeName) const; + Q_SCRIPTABLE QString gtkTheme() const; + Q_SCRIPTABLE void showGtkThemePreview(const QString &themeName) const; void onKdeglobalsSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const; void onKWinSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const; diff --git a/kded/gtkconfig.cpp b/kded/gtkconfig.cpp --- a/kded/gtkconfig.cpp +++ b/kded/gtkconfig.cpp @@ -62,34 +62,20 @@ dbus.unregisterObject(QStringLiteral("/GtkConfig")); } -void GtkConfig::setGtk2Theme(const QString &themeName) const +void GtkConfig::setGtkTheme(const QString &themeName) const { ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-theme-name"), themeName); -} - -void GtkConfig::setGtk3Theme(const QString &themeName) const -{ ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("gtk-theme"), themeName); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name"), themeName); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/ThemeName"), themeName); } -QString GtkConfig::gtk2Theme() const -{ - return ConfigEditor::gtk2ConfigValue(QStringLiteral("gtk-theme-name")); -} - -QString GtkConfig::gtk3Theme() const +QString GtkConfig::gtkTheme() const { return ConfigEditor::gtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name")); } -void GtkConfig::showGtk2ThemePreview(const QString& themeName) const -{ - themePreviewer->showGtk2App(themeName); -} - -void GtkConfig::showGtk3ThemePreview(const QString& themeName) const +void GtkConfig::showGtkThemePreview(const QString& themeName) const { themePreviewer->showGtk3App(themeName); } diff --git a/kded/themepreviewer.h b/kded/themepreviewer.h --- a/kded/themepreviewer.h +++ b/kded/themepreviewer.h @@ -28,20 +28,10 @@ public: ThemePreviewer(QObject *parent); - void showGtk2App(const QString &themeName); void showGtk3App(const QString &themeName); -private Q_SLOTS: - void startXsettingsd(); - void stopXsettingsd(); - private: - static const QString previewGtk2ConfigPath; - static const QString currentGtk2ConfigPath; - static const QString gtk2PreviewerExecutablePath; - static const QString gtk3PreviewerExecutablePath; - QProcess gtk2PreviewerProccess; QProcess gtk3PreviewerProccess; }; diff --git a/kded/themepreviewer.cpp b/kded/themepreviewer.cpp --- a/kded/themepreviewer.cpp +++ b/kded/themepreviewer.cpp @@ -18,62 +18,18 @@ * along with this program. If not, see . */ -#include -#include -#include #include #include #include -#include -#include - -#include -#include - -#include #include "themepreviewer.h" -#include "configeditor.h" #include "config.h" -const QString ThemePreviewer::previewGtk2ConfigPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QStringLiteral("/gtkrc-2.0"); -const QString ThemePreviewer::currentGtk2ConfigPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); -const QString ThemePreviewer::gtk2PreviewerExecutablePath = QStandardPaths::findExecutable(QStringLiteral("gtk_preview"), {CMAKE_INSTALL_FULL_LIBEXECDIR}); - const QString ThemePreviewer::gtk3PreviewerExecutablePath = QStandardPaths::findExecutable(QStringLiteral("gtk3_preview"), {CMAKE_INSTALL_FULL_LIBEXECDIR}); ThemePreviewer::ThemePreviewer(QObject *parent) : QObject(parent), -gtk2PreviewerProccess(), gtk3PreviewerProccess() { - QProcessEnvironment gtk2PreviewEnvironment = QProcessEnvironment::systemEnvironment(); - gtk2PreviewEnvironment.insert(QStringLiteral("GTK2_RC_FILES"), previewGtk2ConfigPath); - - gtk2PreviewerProccess.setProcessEnvironment(gtk2PreviewEnvironment); - connect(>k2PreviewerProccess, SIGNAL(finished(int)), this, SLOT(startXsettingsd())); -} - -void ThemePreviewer::showGtk2App(const QString& themeName) -{ - if (gtk2PreviewerProccess.state() == QProcess::ProcessState::NotRunning) { - if (QFile::exists(previewGtk2ConfigPath)) { - QFile::remove(previewGtk2ConfigPath); - } - - QFile::copy(currentGtk2ConfigPath, previewGtk2ConfigPath); - - QFile previewConfig(previewGtk2ConfigPath); - QString previewConfigContents = ConfigEditor::readFileContents(previewConfig); - ConfigEditor::replaceValueInGtkrcContents(previewConfigContents, QStringLiteral("gtk-theme-name"), themeName); - previewConfig.remove(); - previewConfig.open(QIODevice::WriteOnly | QIODevice::Text); - previewConfig.write(previewConfigContents.toUtf8()); - - stopXsettingsd(); - gtk2PreviewerProccess.start(gtk2PreviewerExecutablePath); - } else { - gtk2PreviewerProccess.close(); - } } void ThemePreviewer::showGtk3App(const QString& themeName) @@ -88,19 +44,3 @@ gtk3PreviewerProccess.close(); } } - -void ThemePreviewer::startXsettingsd() -{ - if (gtk2PreviewerProccess.state() == QProcess::ProcessState::NotRunning && - gtk3PreviewerProccess.state() == QProcess::ProcessState::NotRunning) { - QProcess::startDetached(QStandardPaths::findExecutable(QStringLiteral("xsettingsd"))); - } -} - -void ThemePreviewer::stopXsettingsd() -{ - pid_t pidOfXSettingsd = ConfigEditor::pidOfXSettingsd(); - if (pidOfXSettingsd > 0) { - kill(pidOfXSettingsd, SIGTERM); - } -}