diff --git a/CMakeLists.txt b/CMakeLists.txt index 044d91b..aaa77d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,76 +1,73 @@ project(kde-gtk-config) set(PROJECT_VERSION "5.17.80") cmake_minimum_required(VERSION 2.8.12) find_package(ECM 0.0.9 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${ECM_MODULE_PATH}) find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Widgets Svg Test) find_package(KF5 REQUIRED COMPONENTS I18n KIO ConfigWidgets NewStuff Archive KCMUtils IconThemes DBusAddons) find_package(X11 REQUIRED) find_package(GTK3 REQUIRED) find_package(GSettingSchemas REQUIRED) include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/ui ${GTK3_INCLUDE_DIRS} ) include(ECMSetupVersion) include(ECMInstallIcons) include(ECMMarkAsTest) include(GenerateExportHeader) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDEClangFormat) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) # Set KI18n translation domain add_definitions(-DTRANSLATION_DOMAIN=\"kde-gtk-config\") set(kcm_SRCS - src/iconthemesmodel.cpp - src/cursorthemesmodel.cpp src/appearancegtk3.cpp src/appearancegtk2.cpp src/appearencegtk.cpp src/abstractappearance.cpp src/thread.cpp src/installer.cpp src/gtkconfigkcmodule.cpp src/dialog_installer.cpp src/dialog_uninstaller.cpp - src/fontshelpers.cpp ) ki18n_wrap_ui(kcm_SRCS src/ui/gui.ui src/ui/dialog_installer.ui src/ui/dialog_uninstaller.ui ) add_library(kcm_kdegtkconfig MODULE ${kcm_SRCS}) target_compile_definitions(kcm_kdegtkconfig PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") target_link_libraries(kcm_kdegtkconfig ${X11_Xcursor_LIB} ${GIO2_LIBRARY} ${GLIB2_LIBRARY} ${GTK3_LIBRARY} ${GOBJECT2_LIBRARY} Qt5::Svg KF5::ConfigCore KF5::I18n KF5::KIOWidgets KF5::NewStuff KF5::Archive KF5::NewStuff KF5::ConfigWidgets KF5::IconThemes) kcoreaddons_desktop_to_json(kcm_kdegtkconfig kde-gtk-config.desktop) install(TARGETS kcm_kdegtkconfig DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES cgctheme.knsrc cgcgtk3.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR}) install(FILES kde-gtk-config.desktop DESTINATION ${SERVICES_INSTALL_DIR}) add_subdirectory(gtkproxies) add_subdirectory(gtk3proxies) add_subdirectory(icons) add_subdirectory(tests) add_subdirectory(kded) # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/abstractappearance.cpp b/src/abstractappearance.cpp index e1b663d..56c6c76 100644 --- a/src/abstractappearance.cpp +++ b/src/abstractappearance.cpp @@ -1,98 +1,84 @@ /* KDE GTK Configuration Module * * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "abstractappearance.h" #include #include #include static bool isTrue(const QString& value) { return value == "1" || value == "true"; } //SETTERS void AbstractAppearance::setTheme(const QString& name) { m_settings["theme"] = name;} -void AbstractAppearance::setCursor(const QString& cur) { m_settings["cursor"] = cur;} -void AbstractAppearance::setIcon(const QString& ic) { m_settings["icon"] = ic;} -void AbstractAppearance::setIconFallback(const QString& fall) { m_settings["icon_fallback"] = fall; } -void AbstractAppearance::setFont(const QString& fo) { m_settings["font"] = fo;} -void AbstractAppearance::setShowIconsInButtons(bool show) { m_settings["show_icons_buttons"] = show ? "1" : "0"; } -void AbstractAppearance::setShowIconsInMenus(bool show) { m_settings["show_icons_menus"] = show ? "1" : "0"; } void AbstractAppearance::setPrimaryButtonWarpsSlider(bool enabled) { m_settings["primary_button_warps_slider"] = enabled ? "1" : "0"; } -void AbstractAppearance::setToolbarStyle(const QString& toolbar_style) { m_settings["toolbar_style"] = toolbar_style; } // GETTERS QString AbstractAppearance::getTheme() const { return m_settings["theme"];} -QString AbstractAppearance::getCursor() const { return m_settings["cursor"];} -QString AbstractAppearance::getIcon() const { return m_settings["icon"];} -QString AbstractAppearance::getIconFallback() const { return m_settings["icon_fallback"]; } -QString AbstractAppearance::getFont() const { return m_settings["font"]; } QString AbstractAppearance::getThemeGtk3() const { return m_settings["themegtk3"]; } -QString AbstractAppearance::getToolbarStyle() const { return m_settings["toolbar_style"]; } -bool AbstractAppearance::getShowIconsInButtons() const { return isTrue(m_settings["show_icons_buttons"]); } -bool AbstractAppearance::getShowIconsInMenus() const { return isTrue(m_settings["show_icons_menus"]); } bool AbstractAppearance::getPrimaryButtonWarpsSlider() const { return isTrue(m_settings["primary_button_warps_slider"]); } QRegExp valueRx(" *([a-zA-Z\\-_]+) *= *\"?([^\"\\n]+)\"?", Qt::CaseSensitive, QRegExp::RegExp2); QMap AbstractAppearance::readSettingsTuples(QIODevice* device) { QMap ret; QTextStream flow(device); for(; !flow.atEnd() ;) { QString line = flow.readLine(); int idxComment = line.indexOf('#'); if(idxComment>=0) line = line.left(idxComment).simplified(); if(valueRx.exactMatch(line)) ret[valueRx.cap(1)] = valueRx.cap(2); else if(line.startsWith("include \"")) { QString filename = line.mid(9); filename.chop(1); // qDebug() << "including: " << filename; QFile f(filename); if(f.open(QFile::Text|QFile::ReadOnly)) { ret.unite(readSettingsTuples(&f)); } else qWarning() << "couldn't include " << filename; } // else if(!line.isEmpty()) // qWarning() << "misinterpreted line" << line; } return ret; } QStringList AbstractAppearance::installedThemesNames() const { QStringList themes = installedThemes(); QStringList ret; foreach(const QString& theme, themes) ret += QDir(theme).dirName(); return ret; } bool AbstractAppearance::hasProperty(const QString& key) const { return !m_settings.value(key).isEmpty(); } diff --git a/src/abstractappearance.h b/src/abstractappearance.h index 208342e..3f5cb74 100644 --- a/src/abstractappearance.h +++ b/src/abstractappearance.h @@ -1,71 +1,57 @@ /* KDE GTK Configuration Module * * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef ABSTACTAPPEARANCE_H #define ABSTACTAPPEARANCE_H #include #include #include class AbstractAppearance { public: virtual ~AbstractAppearance() {} virtual bool loadSettings() = 0; virtual bool saveSettings() const = 0; virtual bool loadSettings(const QString& path) = 0; virtual bool saveSettings(const QString& path) const = 0; /** @returns the installed themes' paths*/ virtual QStringList installedThemes() const = 0; void setTheme(const QString& name); - void setCursor(const QString& name); - void setIcon(const QString& name); - void setIconFallback(const QString& name); - void setFont(const QString& font); - void setShowIconsInMenus(bool show); - void setShowIconsInButtons(bool show); void setPrimaryButtonWarpsSlider(bool enabled); - void setToolbarStyle(const QString& style); QString getTheme() const; - QString getCursor() const; - QString getIcon() const; - QString getIconFallback() const; - QString getFont() const; QString getThemeGtk3() const; - QString getToolbarStyle() const; - bool getShowIconsInButtons() const; - bool getShowIconsInMenus() const; bool getPrimaryButtonWarpsSlider() const; QStringList installedThemesNames() const; bool hasProperty(const QString& key) const; static QMap readSettingsTuples(QIODevice* device); protected: QMap m_settings; }; #endif diff --git a/src/appearancegtk2.cpp b/src/appearancegtk2.cpp index 961d336..ebdaef1 100644 --- a/src/appearancegtk2.cpp +++ b/src/appearancegtk2.cpp @@ -1,233 +1,210 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "appearancegtk2.h" #include #include #include #include #include #include #include #include #include bool AppearanceGTK2::loadSettingsPrivate(const QString& path) { QFile configFile(path); if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text)) return false; const QMap foundSettings = readSettingsTuples(&configFile); for(auto it = foundSettings.constBegin(), itEnd = foundSettings.constEnd(); it!=itEnd; ++it) { if (it.key() == "gtk-theme-name") m_settings["theme"] = *it; - else if (it.key() == "gtk-icon-theme-name") - m_settings["icon"] = *it; - else if (it.key() == "gtk-fallback-icon-theme") - m_settings["icon_fallback"] = *it; - else if (it.key() == "gtk-cursor-theme-name") - m_settings["cursor"] = *it; - else if (it.key() == "gtk-font-name") - m_settings["font"] = *it; - else if (it.key() == "gtk-toolbar-style") - m_settings["toolbar_style"] = *it; - else if (it.key() == "gtk-button-images") - m_settings["show_icons_buttons"] = *it; - else if(it.key() == "gtk-menu-images") - m_settings["show_icons_menus"] = *it; else if (it.key() == "gtk-primary-button-warps-slider") m_settings["primary_button_warps_slider"] = *it; - else - qWarning() << "unknown field" << it.key(); } return true; } QString AppearanceGTK2::themesGtkrcFile(const QString& themeName) const { QStringList themes=installedThemes(); themes=themes.filter(QRegExp("/"+themeName+"/?$")); if(themes.size()==1) { QDirIterator it(themes.first(), QDirIterator::Subdirectories); while(it.hasNext()) { it.next(); if(it.fileName()=="gtkrc") { // qDebug() << "\tgtkrc file found at : " << it.filePath(); return it.filePath(); } } } return QString(); } bool AppearanceGTK2::saveSettingsPrivate(const QString& gtkrcFile) const { QFile gtkrc{gtkrcFile}; if (gtkrc.open(QIODevice::ReadWrite | QIODevice::Text)) { QString fileContents{gtkrc.readAll()}; modifyGtkrcContents(fileContents); gtkrc.remove(); gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); gtkrc.write(fileContents.toUtf8()); if (QFileInfo(gtkrc).filePath() == defaultConfigFile()) { QProcess::startDetached(QStandardPaths::findExecutable("reload_gtk_apps", {CMAKE_INSTALL_FULL_LIBEXECDIR})); } return true; } else { qWarning() << "There was unable to write the .gtkrc-2.0 file"; return false; } } void AppearanceGTK2::modifyGtkrcContents(QString& fileContents) const { - modifyGtkrcProperty("gtk-font-name", m_settings["font"], fileContents); modifyGtkrcProperty("gtk-theme-name", m_settings["theme"], fileContents); - modifyGtkrcProperty("gtk-icon-theme-name", m_settings["icon"], fileContents); - modifyGtkrcProperty("gtk-fallback-icon-theme", m_settings["icon_fallback"], fileContents); - modifyGtkrcProperty("gtk-cursor-theme-name", m_settings["cursor"], fileContents); - modifyGtkrcProperty("gtk-toolbar-style", m_settings["toolbar_style"], fileContents); - modifyGtkrcProperty("gtk-menu-images", m_settings["show_icons_menus"], fileContents); - modifyGtkrcProperty("gtk-button-images", m_settings["show_icons_buttons"], fileContents); modifyGtkrcProperty("gtk-primary-button-warps-slider", m_settings["primary_button_warps_slider"], fileContents); removeGtkrcLegacyContents(fileContents); } void AppearanceGTK2::modifyGtkrcProperty(const QString& propertyName, const QString& newValue, QString& fileContents) const { const QRegularExpression regExp{propertyName + "=[^\n]*($|\n)"}; static const QStringList nonStringProperties{ "gtk-toolbar-style", "gtk-menu-images", "gtk-button-images", "gtk-primary-button-warps-slider", }; QString newConfigString; if (nonStringProperties.contains(propertyName)) { newConfigString = propertyName + "=" + newValue + "\n"; } else { newConfigString = propertyName + "=\"" + newValue + "\"\n"; } if (fileContents.contains(regExp)) { fileContents.replace(regExp, newConfigString); } else { fileContents = newConfigString + "\n" + fileContents; } } void AppearanceGTK2::removeGtkrcLegacyContents(QString &fileContents) const { // Remove "include" lines // Example: // include "/usr/share/themes/Adwaita-dark/gtk-2.0/gtkrc" static const QRegularExpression includeRegExp(QStringLiteral("include .*\n")); fileContents.remove(includeRegExp); // Remove redundant font config lines // Example: // style "user-font" // { // font_name="Noto Sans Regular" // } // widget_class "*" style "user-font" static const QRegularExpression userFontStyleRegexp(QStringLiteral("style(.|\n)*{(.|\n)*}\nwidget_class.*\"user-font\"")); fileContents.remove(userFontStyleRegexp); } void AppearanceGTK2::reset() { m_settings = QMap { {"toolbar_style", "GTK_TOOLBAR_ICONS"}, {"show_icons_buttons", "0"}, {"show_icons_menus", "0"}, {"primary_button_warps_slider", "false"} }; } QString AppearanceGTK2::defaultConfigFile() const { return QDir::homePath()+"/.gtkrc-2.0"; } QStringList AppearanceGTK2::installedThemes() const { QFileInfoList availableThemes; foreach(const QString& themesDir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { QDir root(themesDir); availableThemes += root.entryInfoList(QDir::NoDotAndDotDot|QDir::AllDirs); } //Check if there are themes installed by the user QDir user(QDir::homePath()+"/.themes"); availableThemes += user.entryInfoList(QDir::NoDotAndDotDot|QDir::AllDirs); //we just want actual themes QStringList paths; for(QFileInfoList::const_iterator it=availableThemes.constBegin(); it!=availableThemes.constEnd(); ++it) { bool hasGtkrc = QDir(it->filePath()).exists("gtk-2.0"); //If it doesn't exist, we don't want it on the list if(hasGtkrc) paths += it->filePath(); } return paths; } bool AppearanceGTK2::loadSettings() { reset(); bool b = loadSettingsPrivate("/etc/gtk-2.0/gtkrc"); b |= loadSettingsPrivate(defaultConfigFile()); return b; } bool AppearanceGTK2::saveSettings() const { return saveSettings(defaultConfigFile()); } bool AppearanceGTK2::loadSettings(const QString& gtkrcFile) { reset(); return loadSettingsPrivate(gtkrcFile); } bool AppearanceGTK2::saveSettings(const QString& gtkrcFile) const { return saveSettingsPrivate(gtkrcFile); } diff --git a/src/appearancegtk3.cpp b/src/appearancegtk3.cpp index 113f5bc..78868ce 100644 --- a/src/appearancegtk3.cpp +++ b/src/appearancegtk3.cpp @@ -1,191 +1,158 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "appearancegtk3.h" #include #include #include #include #include #include #undef signals #include #include #define signals Q_SIGNALS QStringList AppearanceGTK3::installedThemes() const { QFileInfoList availableThemes; foreach(const QString& themesDir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { QDir root(themesDir); availableThemes += root.entryInfoList(QDir::NoDotAndDotDot|QDir::AllDirs); } //Also show the user-installed themes QDir user(QDir::homePath()+"/.themes"); availableThemes += user.entryInfoList(QDir::NoDotAndDotDot|QDir::AllDirs); //we just want actual themes QStringList themes; // Check that the theme contains a gtk-3.* subdirectory QStringList gtk3SubdirPattern{QStringLiteral("gtk-3.*")}; for(QFileInfoList::const_iterator it=availableThemes.constBegin(); it!=availableThemes.constEnd(); ++it) { QDir themeDir(it->filePath()); if(!themeDir.entryList(gtk3SubdirPattern, QDir::Dirs).isEmpty()) themes += it->filePath(); } return themes; } bool AppearanceGTK3::saveSettings(const KSharedConfig::Ptr& file) const { KConfigGroup group(file, "Settings"); - group.writeEntry("gtk-font-name", m_settings["font"]); group.writeEntry("gtk-theme-name", m_settings["theme"]); - group.writeEntry("gtk-icon-theme-name", m_settings["icon"]); - group.writeEntry("gtk-fallback-icon-theme", m_settings["icon_fallback"]); - group.writeEntry("gtk-cursor-theme-name", m_settings["cursor"]); - group.writeEntry("gtk-toolbar-style", m_settings["toolbar_style"]); - group.writeEntry("gtk-menu-images", m_settings["show_icons_menus"]); - group.writeEntry("gtk-button-images", m_settings["show_icons_buttons"]); group.writeEntry("gtk-primary-button-warps-slider", m_settings["primary_button_warps_slider"]); group.writeEntry("gtk-application-prefer-dark-theme", m_settings["application_prefer_dark_theme"]); const bool sync = group.sync(); Q_ASSERT(sync); return true; } bool AppearanceGTK3::loadSettings(const KSharedConfig::Ptr& file) { KConfigGroup group(file, "Settings"); if (!file || !group.isValid()) { qWarning() << "Cannot open the GTK3 config file" << file; return false; } m_settings = QMap { - {"toolbar_style", "GTK_TOOLBAR_ICONS"}, - {"show_icons_buttons", "0"}, - {"show_icons_menus", "0"}, {"primary_button_warps_slider", "false"}, {"application_prefer_dark_theme", "false"} }; m_settings["theme"] = group.readEntry("gtk-theme-name"); - m_settings["icon"] = group.readEntry("gtk-icon-theme-name"); - m_settings["icon_fallback"] = group.readEntry("gtk-fallback-icon-theme"); - m_settings["cursor"] = group.readEntry("gtk-cursor-theme-name"); - m_settings["font"] = group.readEntry("gtk-font-name"); - m_settings["toolbar_style"] = group.readEntry("gtk-toolbar-style"); - m_settings["show_icons_buttons"] = group.readEntry("gtk-button-images"); - m_settings["show_icons_menus"] = group.readEntry("gtk-menu-images"); m_settings["primary_button_warps_slider"] = group.readEntry("gtk-primary-button-warps-slider"); m_settings["application_prefer_dark_theme"] = group.readEntry("gtk-application-prefer-dark-theme"); for(auto it = m_settings.begin(); it != m_settings.end(); ) { if (it.value().isEmpty()) it = m_settings.erase(it); else ++it; } return true; } QString AppearanceGTK3::configFileName() const { return QStringLiteral("gtk-3.0/settings.ini"); } QString AppearanceGTK3::defaultConfigFile() const { QString root = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); if(root.isEmpty()) root = QFileInfo(QDir::home(), ".config").absoluteFilePath(); return root + '/' + configFileName(); } bool AppearanceGTK3::getApplicationPreferDarkTheme() const { return m_settings["application_prefer_dark_theme"] == "1" || m_settings["application_prefer_dark_theme"] == "true"; } void AppearanceGTK3::setApplicationPreferDarkTheme(const bool& enable) { m_settings["application_prefer_dark_theme"] = enable ? "true" : "false"; } bool AppearanceGTK3::saveSettings(const QString& file) const { auto cfg = KSharedConfig::openConfig(file, KConfig::NoGlobals); return saveSettings(cfg); } bool AppearanceGTK3::loadSettings(const QString& path) { auto cfg = KSharedConfig::openConfig(path, KConfig::NoGlobals); return loadSettings(cfg); } bool AppearanceGTK3::loadSettings() { auto cfg = KSharedConfig::openConfig(configFileName(), KConfig::NoGlobals); return loadSettings(cfg); } bool AppearanceGTK3::saveSettings() const { // FIXME kdebz#387417 // We should maybe use GSettings everywhere in future, but at this moment we // need this to have this configuration available in sandboxed applications which // is only possible through dconf gtk_init(nullptr, nullptr); g_autoptr(GSettings) gsettings = g_settings_new("org.gnome.desktop.interface"); g_settings_set_string(gsettings, "gtk-theme", m_settings["theme"].toUtf8().constData()); - g_settings_set_string(gsettings, "icon-theme", m_settings["icon"].toUtf8().constData()); - g_settings_set_string(gsettings, "cursor-theme", m_settings["cursor"].toUtf8().constData()); - g_settings_set_string(gsettings, "font-name", m_settings["font"].toUtf8().constData()); - - QString toolbarStyle; - if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_ICONS")) { - toolbarStyle = QStringLiteral("icons"); - } else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_TEXT")) { - toolbarStyle = QStringLiteral("text"); - } else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_BOTH")) { - toolbarStyle = QStringLiteral("both"); - } else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_BOTH_HORIZ")) { - toolbarStyle = QStringLiteral("both-horiz"); - } - - g_settings_set_string(gsettings, "toolbar-style", toolbarStyle.toUtf8().constData()); g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", getApplicationPreferDarkTheme(), nullptr); auto cfg = KSharedConfig::openConfig(configFileName(), KConfig::NoGlobals); return saveSettings(cfg); } diff --git a/src/appearencegtk.cpp b/src/appearencegtk.cpp index 95a6604..b2ce09c 100644 --- a/src/appearencegtk.cpp +++ b/src/appearencegtk.cpp @@ -1,83 +1,76 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "appearencegtk.h" #include #include "abstractappearance.h" #include "appearancegtk2.h" #include "appearancegtk3.h" AppearenceGTK::AppearenceGTK() { m_app << new AppearanceGTK2; m_app << new AppearanceGTK3; } AppearenceGTK::~AppearenceGTK() { qDeleteAll(m_app); } #define PROPERTY_IMPLEMENTATION(type, name, propname)\ void AppearenceGTK::set##name(const type& a) { foreach(AbstractAppearance* app, m_app) app->set##name(a); }\ type AppearenceGTK::get##name() const { foreach(AbstractAppearance* app, m_app) { if(app->hasProperty(propname)) return app->get##name(); } /*Q_ASSERT(false);*/ return type (); } -PROPERTY_IMPLEMENTATION(QString, Cursor, "cursor") -PROPERTY_IMPLEMENTATION(QString, Icon, "icon") -PROPERTY_IMPLEMENTATION(QString, IconFallback, "icon_fallback") -PROPERTY_IMPLEMENTATION(QString, Font, "font") -PROPERTY_IMPLEMENTATION(QString, ToolbarStyle, "toolbar_style") -PROPERTY_IMPLEMENTATION(bool, ShowIconsInButtons, "show_icons_buttons") -PROPERTY_IMPLEMENTATION(bool, ShowIconsInMenus, "show_icons_menus") PROPERTY_IMPLEMENTATION(bool, PrimaryButtonWarpsSlider, "primary_button_warps_slider") QString AppearenceGTK::getTheme() const { return gtk2Appearance()->getTheme(); } void AppearenceGTK::setTheme(const QString& name) { return gtk2Appearance()->setTheme(name); } QString AppearenceGTK::getThemeGtk3() const { return gtk3Appearance()->getTheme(); } void AppearenceGTK::setThemeGtk3(const QString& name) { return gtk3Appearance()->setTheme(name); } bool AppearenceGTK::getApplicationPreferDarkTheme() const { return ((AppearanceGTK3*)gtk3Appearance())->getApplicationPreferDarkTheme(); } void AppearenceGTK::setApplicationPreferDarkTheme(const bool& enable) { return ((AppearanceGTK3*)gtk3Appearance())->setApplicationPreferDarkTheme(enable); } //////////////////////////////////// // Methods responsible of file creation bool AppearenceGTK::loadFileConfig() { bool correct = false; foreach(AbstractAppearance* app, m_app) { bool c = app->loadSettings(); correct = correct || c; } // qDebug() << "loading..." << correct; return correct; } bool AppearenceGTK::saveFileConfig() { bool correct = true; foreach(AbstractAppearance* app, m_app) { bool c = app->saveSettings(); correct = correct && c; } // qDebug() << "saving..." << correct; return correct; } diff --git a/src/cursorthemesmodel.cpp b/src/cursorthemesmodel.cpp deleted file mode 100644 index 926a666..0000000 --- a/src/cursorthemesmodel.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* KDE GTK Configuration Module - * - * Copyright 2016 Jason A. Donenfeld - * Copyright 2016 Andrey Bondrov - * Copyright 2011 Aleix Pol Gonzalez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 6 of version 3 of the license. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#include "cursorthemesmodel.h" -#include -#include -#include -#include -#include -#include - -#include - -CursorThemesModel::CursorThemesModel(QObject* parent) - : IconThemesModel(parent) -{ - reload(); -} - -QList CursorThemesModel::installedThemesPaths() -{ - QList availableIcons; - QStringList dirs(QString(XcursorLibraryPath()).split(':', QString::SkipEmptyParts)); - - std::transform(dirs.begin(), dirs.end(), dirs.begin(), KShell::tildeExpand); - dirs.removeDuplicates(); - - foreach(const QString& dir, dirs) { - QDir userIconsDir(dir); - QDirIterator it(userIconsDir.path(), QDir::NoDotAndDotDot|QDir::AllDirs|QDir::NoSymLinks); - while(it.hasNext()) { - QString currentPath = it.next(); - QDir dir(currentPath); - - if(dir.exists() && dir.exists("cursors")) - availableIcons << dir; - } - } - return availableIcons; -} - -void CursorThemesModel::fillItem(const QDir& dir, QStandardItem* item) -{ - KIconTheme theme(dir.dirName()); - if(!theme.name().isEmpty()) - item->setText(theme.name()); - else - item->setText(dir.dirName()); - item->setToolTip(theme.description()); - item->setData(theme.inherits(), CursorThemesModel::InheritsRole); -} - - - -void CursorThemesModel::reload() -{ - clear(); - - QList paths = installedThemesPaths(); - Q_FOREACH(const QDir& dir, paths) { - QStandardItem* themeit = new QStandardItem(dir.dirName()); - themeit->setData(dir.path(), PathRole); - themeit->setData(dir.dirName(), DirNameRole); - fillItem(dir, themeit); - appendRow(themeit); - } -} diff --git a/src/cursorthemesmodel.h b/src/cursorthemesmodel.h deleted file mode 100644 index f802070..0000000 --- a/src/cursorthemesmodel.h +++ /dev/null @@ -1,41 +0,0 @@ -/* KDE GTK Configuration Module - * - * Copyright 2016 Andrey Bondrov - * Copyright 2011 Aleix Pol Gonzalez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 6 of version 3 of the license. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#ifndef CURSORTHEMESMODEL_H -#define CURSORTHEMESMODEL_H - -#include "iconthemesmodel.h" - -class QDir; -class CursorThemesModel : public IconThemesModel -{ - public: - explicit CursorThemesModel(QObject* parent = 0); - - void reload() override; - - private: - static void fillItem(const QDir& dir, QStandardItem* item); - QList installedThemesPaths(); -}; - -#endif // CURSORTHEMESMODEL_H diff --git a/src/dialog_installer.cpp b/src/dialog_installer.cpp index 671372e..f24ce8f 100644 --- a/src/dialog_installer.cpp +++ b/src/dialog_installer.cpp @@ -1,219 +1,140 @@ /* * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "dialog_installer.h" #include "ui_dialog_installer.h" #include #include "installer.h" #include "thread.h" #include #include #include static bool fileIsTar(const QString& path) { QFileInfo file(path); if(file.isDir() || !file.exists()) return false; QMimeDatabase db; QMimeType type = db.mimeTypeForUrl(QUrl::fromLocalFile(path)); return type.isValid() && (type.inherits("application/x-tar") || type.inherits("application/x-bzip-compressed-tar") || type.inherits("application/x-compressed-tar")); } DialogInstaller::DialogInstaller(QWidget *parent) : QDialog(parent), ui(new Ui::dialog_installer) { ui->setupUi(this); //TODO: make sure it's a good idea to have the threads always instanciated threadForTheme = new Thread("theme"); - threadForIcon = new Thread("icon"); threadAnalisysTheme = new ThreadAnalisysTheme; - threadAnalisysThemeIcon = new ThreadAnalisysThemeIcon; //installation ui connect(ui->theme_file, &KUrlRequester::textChanged, this, &DialogInstaller::themeAnalisys); - connect(ui->icon_file, &KUrlRequester::textChanged, this, &DialogInstaller::themeIconAnalisys); - connect(ui->but_icon_install, &QAbstractButton::clicked, this, &DialogInstaller::installThemeIcon); connect(ui->but_theme_install, &QAbstractButton::clicked, this, &DialogInstaller::installTheme); connect(threadAnalisysTheme, &KJob::finished, this, &DialogInstaller::checkThemeAnalisys); - connect(threadAnalisysThemeIcon, &KJob::finished, this, &DialogInstaller::checkThemeIconAnalisys); connect(threadForTheme, &Thread::started, this, &DialogInstaller::disableGUIThemeInstaller); - connect(threadForIcon, &Thread::started, this, &DialogInstaller::disableGUIThemeIconInstaller); connect(threadForTheme, &KJob::finished, this, &DialogInstaller::enableGUIThemeInstaller); - connect(threadForIcon, &KJob::finished, this, &DialogInstaller::enableGUIThemeIconInstaller); //ui refresh connect(threadForTheme, &KJob::finished, this, &DialogInstaller::refreshGUITheme); - connect(threadForIcon, &KJob::finished, this, &DialogInstaller::refreshGUIIconTheme); - } DialogInstaller::~DialogInstaller() { disconnect(threadAnalisysTheme, nullptr, this, nullptr); - disconnect(threadAnalisysThemeIcon, nullptr, this, nullptr); disconnect(threadForTheme, nullptr, this, nullptr); - disconnect(threadForIcon, nullptr, this, nullptr); disconnect(threadForTheme, nullptr, this, nullptr); - disconnect(threadForIcon, nullptr, this, nullptr); delete threadAnalisysTheme; - delete threadAnalisysThemeIcon; - delete threadForIcon; delete threadForTheme; delete ui; } void DialogInstaller::installTheme() { QString file = ui->theme_file->text(); // qDebug()<< "File to install" << file; if(!fileIsTar(file)) { KMessageBox::error(this, i18n("Could not install the %1 theme.", file), i18n("Cannot install theme")); return; } threadForTheme->setUrlPackage(file); threadForTheme->start(); } -void DialogInstaller::installThemeIcon() -{ - QString file = ui->icon_file->text(); - -// qDebug()<< "File to install" << file; - if(!fileIsTar(file)) { - KMessageBox::error(this, i18n("Could not install the %1 theme.", file), i18n("Cannot install theme")); - return; - } - - threadForIcon->setUrlPackage(file); - threadForIcon->start(); -} - void DialogInstaller::themeAnalisys() { ui->lb_theme_notice->setText(i18n("Parsing theme...")); ui->theme_file->setEnabled(false); - ui->but_icon_install->setEnabled(false); QString archivo = ui->theme_file->text(); threadAnalisysTheme->setPackageTheme(archivo); threadAnalisysTheme->start(); } void DialogInstaller::checkThemeAnalisys() { ui->theme_file->setEnabled(true); if(threadAnalisysTheme->isSuccess()) { ui->lb_theme_notice->setText(i18n("This GTK theme can be installed")); ui->but_theme_install->setEnabled(true); } else { ui->lb_theme_notice->setText(i18n("This GTK theme cannot be installed")); ui->but_theme_install->setEnabled(false); } } -void DialogInstaller::themeIconAnalisys() -{ - ui->lb_icon_notice->setText(i18n("Parsing theme...")); - - ui->icon_file->setEnabled(false); - ui->but_icon_install->setEnabled(false); - - QString archivo = ui->icon_file->text(); - threadAnalisysThemeIcon->setPackageTheme(archivo); - threadAnalisysThemeIcon->start(); -} - -void DialogInstaller::checkThemeIconAnalisys() -{ - ui->icon_file->setEnabled(true); - - if(threadAnalisysThemeIcon->isSuccess()) { - ui->lb_icon_notice->setText(i18n("This icons theme can be installed")); - ui->but_icon_install->setEnabled(true); - } else { - ui->lb_icon_notice->setText(i18n("This icons theme cannot be installed")); - ui->but_icon_install->setEnabled(false); - } -} - void DialogInstaller::enableGUIThemeInstaller() { ui->but_theme_install->setEnabled(true); ui->theme_file->setEnabled(true); } -void DialogInstaller::enableGUIThemeIconInstaller() -{ - ui->but_icon_install->setEnabled(true); - ui->icon_file->setEnabled(true); - ui->buttonBox->button(QDialogButtonBox::Close)->setEnabled(true); -} - void DialogInstaller::disableGUIThemeInstaller() { ui->lb_theme_notice->setText(i18n("Installing GTK theme...")); ui->but_theme_install->setEnabled(false); ui->theme_file->setEnabled(false); } -void DialogInstaller::disableGUIThemeIconInstaller() -{ - ui->lb_icon_notice->setText(i18n("Installing icons...")); - ui->but_icon_install->setEnabled(false); - ui->icon_file->setEnabled(false); - ui->buttonBox->button(QDialogButtonBox::Close)->setEnabled(false); -} -void DialogInstaller::refreshGUIIconTheme() -{ - if(threadForIcon->isSuccess()) { - ui->lb_icon_notice->setText(i18n("Icons Successfully Installed")); - ui->icon_file->clear(); - emit themeInstalled(); - } else { - ui->lb_icon_notice->setText(i18n("The icons theme cannot be installed")); - ui->icon_file->clear(); - } -} // Esto se ejecuta cuando un tema es tratado a instalar void DialogInstaller::refreshGUITheme() { if(threadForTheme->isSuccess()) { ui->lb_theme_notice->setText(i18n("GTK Theme Successfully Installed")); emit themeInstalled(); } else { ui->lb_theme_notice->setText(i18n("The GTK theme cannot be installed")); } ui->theme_file->clear(); } diff --git a/src/dialog_installer.h b/src/dialog_installer.h index 1629775..a217e9d 100644 --- a/src/dialog_installer.h +++ b/src/dialog_installer.h @@ -1,87 +1,73 @@ /* * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef DIALOGINSTALLER_H #define DIALOGINSTALLER_H #include class ThreadAnalisysThemeIcon; class ThreadAnalisysTheme; class Thread; namespace Ui { class dialog_installer; } /** * GUI to install icons and gtk themes */ class DialogInstaller : public QDialog { Q_OBJECT public: DialogInstaller(QWidget *parent=0); ~DialogInstaller(); signals: /** * Whenever a theme is installed, this signal is emitted */ void themeInstalled(); private slots: - /** - Instala el tema de icono a traves del objeto Installer - Para ello lanza un hilo para que no se bloqué la GUI - */ - void installThemeIcon(); /** Instala el tema de icono a traves del objeto Installer Para ello lanza un hilo para que no se bloqué la GUI */ void installTheme(); void enableGUIThemeInstaller(); void disableGUIThemeInstaller(); void refreshGUITheme(); void themeAnalisys(); ///executed after analyzing theme void checkThemeAnalisys(); - - void enableGUIThemeIconInstaller(); - void disableGUIThemeIconInstaller(); - void refreshGUIIconTheme(); - void themeIconAnalisys(); - void checkThemeIconAnalisys(); - private: Ui::dialog_installer *ui; //PROPIEDADES PARA EL AREA DE INSTALADOR Thread *threadForTheme; //Hilo que instala el tema gtk - Thread *threadForIcon; //Hilo que instala el tema de iconos ThreadAnalisysTheme *threadAnalisysTheme; //hilo para analizar los temas a instalar - ThreadAnalisysThemeIcon *threadAnalisysThemeIcon; //hilo para analizar los temas a instalar }; #endif //dialog_installer.h diff --git a/src/dialog_uninstaller.cpp b/src/dialog_uninstaller.cpp index f6c5f5a..8809b4a 100644 --- a/src/dialog_uninstaller.cpp +++ b/src/dialog_uninstaller.cpp @@ -1,140 +1,100 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "dialog_uninstaller.h" #include "abstractappearance.h" -#include "iconthemesmodel.h" #include "ui_dialog_uninstaller.h" #include "thread.h" #include "appearencegtk.h" #include #include #include DialogUninstaller::DialogUninstaller(QWidget* parent, AppearenceGTK *app) : QDialog(parent) , ui(new Ui::dialog_uninstaller) , appareance(app) { ui->setupUi(this); refreshListsForUninstall(); connect(ui->but_uninstall_theme, &QAbstractButton::clicked, this, &DialogUninstaller::uninstallTheme); - connect(ui->but_uninstall_icon, &QAbstractButton::clicked, this, &DialogUninstaller::uninstallIcon); } DialogUninstaller::~DialogUninstaller() { delete ui; } void DialogUninstaller::refreshListsForUninstall() { - ui->lb_notice_uninstall_icon->clear(); ui->lb_notice_uninstall_theme->clear(); QStringList themes = appareance->gtk2Appearance()->installedThemes(); themes = themes.filter(QDir::homePath()); //we only one the locally installed themes //Just leave the theme name for(QStringList::iterator it=themes.begin(); it!=themes.end(); ++it) *it = QDir(*it).dirName(); ui->cb_uninstall_theme->clear(); ui->cb_uninstall_theme->addItems(themes); - - ui->cb_uninstall_icon->setModel(new IconThemesModel(true)); } void DialogUninstaller::uninstallTheme() { if(ui->cb_uninstall_theme->currentIndex() < 0) return; QString tema = ui->cb_uninstall_theme->currentText(); QStringList themes = appareance->gtk2Appearance()->installedThemes(); themes = themes.filter(QRegExp('/'+tema+'$')); Q_ASSERT(themes.size()==1); ui->cb_uninstall_theme->setEnabled(false); ui->but_uninstall_theme->setEnabled(false); ui->lb_notice_uninstall_theme->setText(i18n("Uninstalling GTK theme...")); ThreadErase* threadEraseTheme = new ThreadErase; threadEraseTheme->setThemeForErase(themes.first()); connect(threadEraseTheme, &KJob::finished, this, &DialogUninstaller::threadUninstalledThemeFinished); threadEraseTheme->start(); } -void DialogUninstaller::uninstallIcon() -{ - int themeIndex = ui->cb_uninstall_icon->currentIndex(); - if(themeIndex<0) - return; - - QAbstractItemModel* model = ui->cb_uninstall_icon->model(); - QString theme = model->data(model->index(themeIndex, 0), IconThemesModel::PathRole).toString(); - - ui->cb_uninstall_icon->setEnabled(false); - ui->but_uninstall_icon->setEnabled(false); - - ui->lb_notice_uninstall_icon->setText(i18n("Uninstalling icons...")); - - ThreadErase* threadEraseIcon = new ThreadErase; - threadEraseIcon->setThemeForErase(theme); - connect(threadEraseIcon, &KJob::finished, this, &DialogUninstaller::threadUninstalledThemeIconFinished); - threadEraseIcon->start(); -} - void DialogUninstaller::threadUninstalledThemeFinished(KJob* job) { if(job->error()==0) { ui->lb_notice_uninstall_theme->setText(i18n("GTK theme successfully uninstalled.")); emit(themeUninstalled()); } else { ui->lb_notice_uninstall_theme->setText(i18n("Could not uninstall the GTK theme.")); } ui->cb_uninstall_theme->setEnabled(true); ui->but_uninstall_theme->setEnabled(true); refreshListsForUninstall(); } - -void DialogUninstaller::threadUninstalledThemeIconFinished(KJob* job) -{ - if(job->error()==0) { - ui->lb_notice_uninstall_icon->setText(i18n("Icons successfully uninstalled.")); - emit(themeUninstalled()); - } else { - ui->lb_notice_uninstall_icon->setText(i18n("Could not uninstall the icon theme.")); - } - - ui->cb_uninstall_icon->setEnabled(true); - ui->but_uninstall_icon->setEnabled(true); - - refreshListsForUninstall(); -} diff --git a/src/dialog_uninstaller.h b/src/dialog_uninstaller.h index cf67dac..5c48a6a 100644 --- a/src/dialog_uninstaller.h +++ b/src/dialog_uninstaller.h @@ -1,59 +1,57 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef DIALOGUNINSTALLER_H #define DIALOGUNINSTALLER_H #include class KJob; class AppearenceGTK; namespace Ui{ class dialog_uninstaller; } /** * GUI to uninstall GTK themes and icon themes */ class DialogUninstaller: public QDialog { Q_OBJECT public: DialogUninstaller(QWidget *parent = 0, AppearenceGTK *app=0); ~DialogUninstaller(); signals: void themeUninstalled(); public slots: void refreshListsForUninstall(); void uninstallTheme(); - void uninstallIcon(); void threadUninstalledThemeFinished(KJob* job); - void threadUninstalledThemeIconFinished(KJob* job); private: Ui::dialog_uninstaller *ui; AppearenceGTK *appareance; }; #endif //dialog_installer.h diff --git a/src/fontshelpers.cpp b/src/fontshelpers.cpp deleted file mode 100644 index 5244f05..0000000 --- a/src/fontshelpers.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* KDE GTK Configuration Module - * - * Copyright 2011 Aleix Pol Gonzalez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 6 of version 3 of the license. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#include "fontshelpers.h" -#include -#include -#include -#include - -QString fontToString(const QFont& f) -{ - return f.family() + ' ' + f.styleName() + ' ' + QString::number(f.pointSize()); -} - -QFont stringToFont(const QString& font) -{ - QFontDatabase fdb; - QString fontFamily; - int familyIdx=-1; - QStringList allFamilies = fdb.families(); - for(int idx=font.indexOf(' '); idx=0; idx=font.indexOf(' ', idx+1)) { - QString testFont = font.left(idx); - if(allFamilies.contains(testFont)) { - fontFamily = testFont; - familyIdx = idx; - } - } - - QFont f; - f.setFamily(fontFamily); - QRegularExpression fontRx(QStringLiteral(" (.*) +([0-9]+)$")); - QRegularExpressionMatch match = fontRx.match(font, familyIdx); - if (match.isValid()) { - QString fontStyle = match.captured(1).trimmed(); - int fontSize = match.captured(2).toInt(); - f.setStyleName(fontStyle); - f.setPointSize(fontSize); - } else { - qWarning() << "Couldn't figure out style and size" << font; - } - return f; -} diff --git a/src/fontshelpers.h b/src/fontshelpers.h deleted file mode 100644 index 73e73c5..0000000 --- a/src/fontshelpers.h +++ /dev/null @@ -1,30 +0,0 @@ -/* KDE GTK Configuration Module - * - * Copyright 2011 Aleix Pol Gonzalez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 6 of version 3 of the license. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#ifndef FONTSHELPERS_H -#define FONTSHELPERS_H - -#include - -QString fontToString(const QFont& f); -QFont stringToFont(const QString& font); - -#endif diff --git a/src/gtkconfigkcmodule.cpp b/src/gtkconfigkcmodule.cpp index 5b9ec1b..28c036e 100644 --- a/src/gtkconfigkcmodule.cpp +++ b/src/gtkconfigkcmodule.cpp @@ -1,547 +1,397 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "gtkconfigkcmodule.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "ui_gui.h" #include "abstractappearance.h" -#include "iconthemesmodel.h" -#include "fontshelpers.h" #include #include #include #include K_PLUGIN_FACTORY_WITH_JSON(GTKConfigKCModuleFactory, "kde-gtk-config.json", registerPlugin();) -QMap gtkToolbarInit() -{ - QMap gtkToolbar; - gtkToolbar["GTK_TOOLBAR_ICONS"] = 0; - gtkToolbar["GTK_TOOLBAR_TEXT"] = 1; - gtkToolbar["GTK_TOOLBAR_BOTH_HORIZ"] = 2; - gtkToolbar["GTK_TOOLBAR_BOTH"] = 3; - return gtkToolbar; -} - -static QMap gtkToolbar = gtkToolbarInit(); - GTKConfigKCModule::GTKConfigKCModule(QWidget* parent, const QVariantList& args ) : KCModule(parent) , ui(new Ui::GUI) , installer(0) , uninstaller(0) , m_saveEnabled(true) { Q_UNUSED(args); KAboutData *acercade = new KAboutData("cgc", i18n("GTK Application Style"), PROJECT_VERSION, QString(), KAboutLicense::LGPL_V3, i18n("Copyright 2011 José Antonio Sánchez Reynaga")); acercade->addAuthor(i18n("José Antonio Sánchez Reynaga (antonioJASR)"),i18n("Main Developer"), "joanzare@gmail.com"); acercade->addAuthor(i18n("Aleix Pol i Gonzalez"), i18n("Feature development. Previews, code refactoring."), "aleixpol@blue-systems.com"); acercade->addCredit(i18n("Manuel Tortosa (manutortosa)"), i18n("Ideas, tester, internationalization")); acercade->addCredit(i18n("Adrián Chaves Fernández (Gallaecio)"), i18n("Internationalization")); setAboutData(acercade); setButtons(KCModule::Default | KCModule::Apply); ui->setupUi(this); appareance = new AppearenceGTK; - m_cursorsModel = new CursorThemesModel(this); - QSortFilterProxyModel *cursorsProxyModel = new QSortFilterProxyModel(this); - cursorsProxyModel->setSourceModel(m_cursorsModel); - cursorsProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); - cursorsProxyModel->setSortRole(Qt::DisplayRole); - cursorsProxyModel->sort(0); - ui->cb_cursor->setModel(cursorsProxyModel); - - m_iconsModel = new IconThemesModel(false, this); - QSortFilterProxyModel *iconsProxyModel = new QSortFilterProxyModel(this); - iconsProxyModel->setSourceModel(m_iconsModel); - iconsProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); - iconsProxyModel->setSortRole(Qt::DisplayRole); - iconsProxyModel->sort(0); - ui->cb_icon->setModel(iconsProxyModel); - ui->cb_icon_fallback->setModel(iconsProxyModel); - m_tempGtk2Preview = QStandardPaths::writableLocation(QStandardPaths::TempLocation)+ "/gtkrc-2.0"; m_tempGtk3Preview = QStandardPaths::writableLocation(QStandardPaths::TempLocation)+ "/.config/gtk-3.0/settings.ini"; const QIcon previewIcon = QIcon::fromTheme("document-preview"); ui->gtk2Preview->setIcon(previewIcon); ui->gtk3Preview->setIcon(previewIcon); QString gtk2Preview = QStandardPaths::findExecutable("gtk_preview", {CMAKE_INSTALL_FULL_LIBEXECDIR}); QString gtk3Preview = QStandardPaths::findExecutable("gtk3_preview", {CMAKE_INSTALL_FULL_LIBEXECDIR}); m_p2 = new KProcess(this); m_p2->setEnv("GTK2_RC_FILES", m_tempGtk2Preview, true); if(!gtk2Preview.isEmpty()) { *m_p2 << gtk2Preview; connect(m_p2, SIGNAL(finished(int)), this, SLOT(untogglePreview())); } m_p3 = new KProcess(this); m_p3->setEnv("XDG_CONFIG_HOME", QStandardPaths::writableLocation(QStandardPaths::TempLocation)+"/.config"); if(!gtk3Preview.isEmpty()) { *m_p3 << gtk3Preview; connect(m_p3, SIGNAL(finished(int)), this, SLOT(untogglePreview())); } ui->gtk2Preview->setVisible(!gtk2Preview.isEmpty()); ui->gtk3Preview->setVisible(!gtk3Preview.isEmpty()); //UI changes connect(ui->cb_theme, SIGNAL(currentIndexChanged(int)), this, SLOT(appChanged())); connect(ui->cb_theme_gtk3, SIGNAL(currentIndexChanged(int)), this, SLOT(appChanged())); connect(ui->checkBox_theme_gtk3_prefer_dark, &QAbstractButton::clicked, this, >KConfigKCModule::appChanged); - connect(ui->cb_cursor, SIGNAL(currentIndexChanged(int)), this, SLOT(appChanged())); - connect(ui->cb_icon, SIGNAL(currentIndexChanged(int)), this, SLOT(appChanged())); - connect(ui->cb_icon_fallback ,SIGNAL(currentIndexChanged(int)), this, SLOT(appChanged())); - connect(ui->font, &KFontRequester::fontSelected, this, >KConfigKCModule::appChanged); - connect(ui->cb_toolbar_icons, SIGNAL(currentIndexChanged(int)), this, SLOT(appChanged())); - connect(ui->checkBox_icon_gtk_menus, &QAbstractButton::clicked, this, >KConfigKCModule::appChanged); - connect(ui->checkBox_icon_gtk_buttons, &QAbstractButton::clicked, this, >KConfigKCModule::appChanged); connect(ui->buttonGroup_primary_button_warps_slider, SIGNAL(buttonToggled(QAbstractButton*, bool)), this, SLOT(appChanged())); //preview updates - connect(ui->cb_icon_fallback, SIGNAL(activated(QString)), this, SLOT(makePreviewIconTheme())); - connect(ui->cb_icon, SIGNAL(activated(QString)), this, SLOT(makePreviewIconTheme())); connect(ui->gtk2Preview, &QAbstractButton::clicked, this, >KConfigKCModule::runGtk2IfNecessary); connect(ui->gtk3Preview, &QAbstractButton::clicked, this, >KConfigKCModule::runGtk3IfNecessary); QMenu* m = new QMenu(this); m->addAction(QIcon::fromTheme("get-hot-new-stuff"), i18n("Download GTK2 themes..."), this, >KConfigKCModule::showThemeGHNS); m->addAction(QIcon::fromTheme("get-hot-new-stuff"), i18n("Download GTK3 themes..."), this, >KConfigKCModule::installThemeGTK3GHNS); m->addAction(QIcon::fromTheme("archive-insert"), i18n("Install a local theme..."), this, >KConfigKCModule::showDialogForInstall); m->addAction(QIcon::fromTheme("archive-remove"), i18n("Uninstall a local theme..."), this, >KConfigKCModule::showDialogForUninstall); ui->newThemes->setMenu(m); ui->newThemes->setIcon(QIcon::fromTheme("get-hot-new-stuff")); } GTKConfigKCModule::~GTKConfigKCModule() { m_p2->kill(); m_p3->kill(); QFile::remove(m_tempGtk2Preview); QFile::remove(m_tempGtk3Preview); delete appareance; m_p2->waitForFinished(); m_p3->waitForFinished(); delete ui; } void GTKConfigKCModule::syncUI() { appareance->setThemeGtk3(ui->cb_theme_gtk3->currentText()); appareance->setTheme(ui->cb_theme->currentText()); appareance->setApplicationPreferDarkTheme(ui->checkBox_theme_gtk3_prefer_dark->isChecked()); - appareance->setCursor(ui->cb_cursor->itemData(ui->cb_cursor->currentIndex(), CursorThemesModel::DirNameRole).toString()); - appareance->setIcon(ui->cb_icon->itemData(ui->cb_icon->currentIndex(), IconThemesModel::DirNameRole).toString()); - appareance->setIconFallback(ui->cb_icon_fallback->itemData(ui->cb_icon_fallback->currentIndex(), IconThemesModel::DirNameRole).toString()); - appareance->setFont(fontToString(ui->font->font())); - - appareance->setToolbarStyle(gtkToolbar.key(ui->cb_toolbar_icons->currentIndex())); - appareance->setShowIconsInButtons(ui->checkBox_icon_gtk_buttons->isChecked()); - appareance->setShowIconsInMenus(ui->checkBox_icon_gtk_menus->isChecked()); + appareance->setPrimaryButtonWarpsSlider(ui->buttonGroup_primary_button_warps_slider->checkedButton() == ui->radioButton_warp); } void GTKConfigKCModule::showThemeGHNS() { KNS3::DownloadDialog d("cgctheme.knsrc", this); if(d.exec()) { refreshLists(); } } void GTKConfigKCModule::installThemeGTK3GHNS() { KNS3::DownloadDialog d("cgcgtk3.knsrc", this); if(d.exec()) { refreshLists(); } } void GTKConfigKCModule::refreshLists() { refreshThemesUi(true); - const auto newFont = stringToFont(appareance->getFont()); - if (newFont != ui->font->font()) - ui->font->setFont(newFont); - - ui->cb_toolbar_icons->setCurrentIndex(gtkToolbar[appareance->getToolbarStyle()]); - - ui->checkBox_icon_gtk_buttons->setChecked(appareance->getShowIconsInButtons()); - ui->checkBox_icon_gtk_menus->setChecked(appareance->getShowIconsInMenus()); const bool warps = appareance->getPrimaryButtonWarpsSlider(); ui->radioButton_warp->setChecked(warps); ui->radioButton_dont_warp->setChecked(!warps); - - makePreviewIconTheme(); -} - -void tryIcon(QLabel* label, const QString& fallback, const QString& theme, const QString& iconName) -{ - label->setToolTip(iconName); - - auto findIconAt = [label, theme, iconName](const QDir &where) -> bool { - const QString path = IconThemesModel::findIconRecursivelyByName(iconName, where); - - if(!path.isEmpty()) { - QPixmap p; - QSize s(label->width(), label->height()); - if (path.endsWith(".svg") || path.endsWith(".svgz")) { - QImage image(s, QImage::Format_ARGB32_Premultiplied); - image.fill(Qt::transparent); - QPainter painter(&image); - QSvgRenderer r(path); - r.render(&painter); - painter.end(); - - p = QPixmap::fromImage(image); - } else { - p = {path}; - Q_ASSERT(!p.isNull()); - p = p.scaled(s); - } - label->setPixmap(p); - return true; - } - return false; - }; - if (!theme.isEmpty() && findIconAt(QDir(theme))) - return; - if (findIconAt(fallback)) - return; - - QIcon notFoundIcon = QIcon::fromTheme("application-x-zerosize"); - QPixmap noIcon(notFoundIcon.pixmap(48,48)); - label->setPixmap(noIcon); - - qWarning() << "could not find icon" << iconName; -} - -void GTKConfigKCModule::makePreviewIconTheme() -{ - int icon_fallback = ui->cb_icon_fallback->currentIndex(); - QString path_fallback = ui->cb_icon->itemData(icon_fallback, IconThemesModel::PathRole).toString(); - - int icon = ui->cb_icon->currentIndex(); - QString path_icon = ui->cb_icon->itemData(icon, IconThemesModel::PathRole).toString(); - - tryIcon(ui->lb_prev_1, path_fallback, path_icon, "user-home"); - tryIcon(ui->lb_prev_2, path_fallback, path_icon, "folder"); - tryIcon(ui->lb_prev_3, path_fallback, path_icon, "user-trash"); - tryIcon(ui->lb_prev_4, path_fallback, path_icon, "document-print"); - tryIcon(ui->lb_prev_5, path_fallback, path_icon, "user-desktop"); - tryIcon(ui->lb_prev_6, path_fallback, path_icon, "network-server"); - tryIcon(ui->lb_prev_7, path_fallback, path_icon, "system-help"); - tryIcon(ui->lb_prev_8, path_fallback, path_icon, "start-here"); - tryIcon(ui->lb_prev_9, path_fallback, path_icon, "go-up"); } void GTKConfigKCModule::appChanged() { if (m_loading) return; savePreviewConfig(); emit changed(true); } void GTKConfigKCModule::savePreviewConfig() { if(!m_saveEnabled || !(ui->gtk2Preview->isChecked() || ui->gtk3Preview->isChecked())) return; // qDebug() << "saving UI..."; syncUI(); if(ui->gtk3Preview->isChecked()) { //we don't want to recursively loop between savePreviewConfig and runIfNecessary m_saveEnabled = false; m_p3->kill(); appareance->gtk3Appearance()->saveSettings(m_tempGtk3Preview); //need to make sure runIfNecessary() to know that it's not running m_p3->waitForFinished(); m_p3->start(); ui->gtk3Preview->setChecked(true); m_saveEnabled = true; } else if(ui->gtk2Preview->isChecked()) { appareance->gtk2Appearance()->saveSettings(m_tempGtk2Preview); } } void GTKConfigKCModule::runGtk2IfNecessary(bool checked) { KProcess* p = m_p2; KProcess* np = m_p3; if(checked) { np->kill(); np->waitForFinished(); savePreviewConfig(); if(p->state() == QProcess::NotRunning) p->start(); } else { p->kill(); p->waitForFinished(); } } void GTKConfigKCModule::runGtk3IfNecessary(bool checked) { KProcess* p = m_p3; KProcess* np = m_p2; if(checked) { np->kill(); np->waitForFinished(); savePreviewConfig(); if(p->state() == QProcess::NotRunning) p->start(); } else { p->kill(); p->waitForFinished(); } } void GTKConfigKCModule::save() { /* qDebug() << "******************************************* INSTALLATION :\n" << "theme : " << appareance->getTheme() << "\n" << "themeGTK3 : " << appareance->getThemeGtk3() << "\n" - << "icons : " << appareance->getIcon() << "\n" - << "fallback icons : " << appareance->getIconFallback() << "\n" - << "cursors : " << appareance->getCursor() << "\n" - << "font family : " << appareance->getFont() << "\n" - << "toolbar style : " << appareance->getToolbarStyle() << "\n" - << "icons in buttons : " << appareance->getShowIconsInButtons() << "\n" - << "icons in menus : " << appareance->getShowIconsInMenus() << "\n" << "********************************************************"; */ syncUI(); if(!appareance->saveFileConfig()) KMessageBox::error(this, i18n("Failed to save configuration.")); } void setComboItem(QComboBox* combo, const QStringList& texts) { foreach(const QString& text, texts) { int pos = combo->findText(text); if(pos>=0) { combo->setCurrentIndex(pos); return; } } } void GTKConfigKCModule::defaults() { refreshThemesUi(false); // qDebug() << "loading defaults..."; m_saveEnabled = false; - ui->font->setFont(font()); - bool showIcons = !QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus); - ui->checkBox_icon_gtk_buttons->setChecked(showIcons); - ui->checkBox_icon_gtk_menus->setChecked(showIcons); // this makes it consistent with Qt apps and restores the old Gtk behavior ui->radioButton_dont_warp->setChecked(true); setComboItem(ui->cb_theme, QStringList("oxygen-gtk") << "Clearlooks"); setComboItem(ui->cb_theme_gtk3, QStringList("oxygen-gtk") << "Adwaita"); - QStringList icons; - icons << KIconLoader::global()->theme()->name() << "GNOME"; - setComboItem(ui->cb_icon, icons); - - int idx = ui->cb_icon->currentIndex(); - if(idx>=0) { - setComboItem(ui->cb_icon_fallback, icons.mid(icons.indexOf(ui->cb_icon->currentText())+1)); - } m_saveEnabled = true; - makePreviewIconTheme(); appChanged(); } void GTKConfigKCModule::load() { m_saveEnabled = false; bool someCorrect = appareance->loadFileConfig(); m_loading = true; if(someCorrect) { refreshLists(); } else { defaults(); } m_loading = false; m_saveEnabled = true; } class MyStringListModel : public QAbstractListModel { public: MyStringListModel(const QStringList &texts, QObject* parent) : QAbstractListModel(parent), m_texts(texts) { } QVariant data(const QModelIndex & index, int role) const override { if (role != Qt::DisplayRole || !index.isValid() || index.row()>=m_texts.count()) return {}; return m_texts[index.row()]; } int rowCount(const QModelIndex & parent) const override { return parent.isValid() ? 0 : m_texts.count(); } void setStrings(const QSet &list) { const auto current = m_texts.toSet(); const auto oldRows = QSet(current).subtract(list); const auto newRows = QSet(list).subtract(current); if (!newRows.isEmpty()) { beginInsertRows({}, m_texts.count(), m_texts.count() + newRows.count()); m_texts += newRows.toList(); endInsertRows(); } int from = -1; for(const auto &row: oldRows) { for(; from(combo->model()); if (!model) { combo->setModel(new MyStringListModel(texts, combo)); } else { model->setStrings(texts.toSet()); } const int idx = combo->findText(temp); combo->setCurrentIndex(qMax(0, idx)); } void GTKConfigKCModule::refreshThemesUi(bool useConfig) { //theme gtk2 bool wasenabled = m_saveEnabled; m_saveEnabled = false; refreshComboSameCurrentValue(ui->cb_theme, useConfig ? appareance->getTheme() : ui->cb_theme->currentText(), appareance->gtk2Appearance()->installedThemesNames()); //theme gtk3 refreshComboSameCurrentValue(ui->cb_theme_gtk3, useConfig ? appareance->getThemeGtk3() : ui->cb_theme_gtk3->currentText(), appareance->gtk3Appearance()->installedThemesNames()); // dark theme for gtk3 ui->checkBox_theme_gtk3_prefer_dark->setChecked(appareance->getApplicationPreferDarkTheme()); - //cursors - QString currentCursor = useConfig ? appareance->getCursor() : ui->cb_cursor->currentText(); - int currentCursorIdx = ui->cb_cursor->findData(currentCursor, CursorThemesModel::DirNameRole); - ui->cb_cursor->setCurrentIndex(qMax(currentCursorIdx, 0)); - - //icons - QString currentIcon = useConfig ? appareance->getIcon() : ui->cb_icon->currentText(), - currentFallback = useConfig ? appareance->getIconFallback() : ui->cb_icon_fallback->currentText(); - int currentIconIdx = ui->cb_icon->findData(currentIcon, IconThemesModel::DirNameRole); - int currentFallbackIdx = ui->cb_icon_fallback->findData(currentFallback, IconThemesModel::DirNameRole); - ui->cb_icon->setCurrentIndex(qMax(currentIconIdx, 0)); - ui->cb_icon_fallback->setCurrentIndex(qMax(currentFallbackIdx, 0)); m_saveEnabled = wasenabled; - if(currentCursorIdx<0 || currentIconIdx<0 || currentFallbackIdx<0) - emit changed(true); + emit changed(true); } void GTKConfigKCModule::showDialogForInstall() { if(!installer) { installer = new DialogInstaller(this); connect(installer, &DialogInstaller::themeInstalled, this, >KConfigKCModule::refreshLists); } installer->exec(); refreshThemesUi(); } void GTKConfigKCModule::showDialogForUninstall() { if(!uninstaller) { uninstaller = new DialogUninstaller(this, appareance); connect(uninstaller, &DialogUninstaller::themeUninstalled, this, >KConfigKCModule::refreshLists); } uninstaller->refreshListsForUninstall(); uninstaller->exec(); refreshThemesUi(); } void GTKConfigKCModule::untogglePreview() { if(sender()==m_p2) ui->gtk2Preview->setChecked(false); else ui->gtk3Preview->setChecked(false); } #include "gtkconfigkcmodule.moc" diff --git a/src/gtkconfigkcmodule.h b/src/gtkconfigkcmodule.h index 4e03216..a3d5cfa 100644 --- a/src/gtkconfigkcmodule.h +++ b/src/gtkconfigkcmodule.h @@ -1,90 +1,82 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef GTKCONFIGKCMODULE_H #define GTKCONFIGKCMODULE_H #include #include "appearencegtk.h" #include "dialog_installer.h" #include "dialog_uninstaller.h" #include -#include "iconthemesmodel.h" -#include "cursorthemesmodel.h" class KProcess; namespace Ui { class Modulo; class GUI; } class GTKConfigKCModule : public KCModule { Q_OBJECT public: explicit GTKConfigKCModule(QWidget* parent = 0 ,const QVariantList& args = QVariantList() ); ~GTKConfigKCModule(); void refreshThemesUi(bool useConfig=false); void save() override; void defaults() override; void load() override; public slots: void refreshLists(); - void makePreviewIconTheme(); ///it is called whenever something in the UI has changed void appChanged(); void savePreviewConfig(); void showThemeGHNS(); void installThemeGTK3GHNS(); void showDialogForInstall(); void showDialogForUninstall(); void runGtk2IfNecessary(bool); void runGtk3IfNecessary(bool); void untogglePreview(); -signals: - void selectedIconTheme(); - private: void syncUI(); bool m_loading = false; Ui::GUI *ui; AppearenceGTK *appareance; DialogInstaller *installer; DialogUninstaller *uninstaller; KProcess* m_p2; KProcess* m_p3; QString m_tempGtk2Preview; QString m_tempGtk3Preview; bool m_saveEnabled; - CursorThemesModel* m_cursorsModel; - IconThemesModel* m_iconsModel; }; #endif // MODULO_H diff --git a/src/iconthemesmodel.cpp b/src/iconthemesmodel.cpp deleted file mode 100644 index 17fa6bc..0000000 --- a/src/iconthemesmodel.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* KDE GTK Configuration Module - * - * Copyright 2011 José Antonio Sanchez Reynaga - * Copyright 2011 Aleix Pol Gonzalez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 6 of version 3 of the license. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#include "iconthemesmodel.h" -#include -#include -#include -#include -#include -#include - -IconThemesModel::IconThemesModel(bool onlyHome, QObject* parent) - : QStandardItemModel(parent) - , m_onlyHome(onlyHome) -{ - reload(); -} - -QList IconThemesModel::installedThemesPaths() -{ - QList availableIcons; - - QSet dirs; - dirs += QDir::home().filePath(".icons"); - if(!m_onlyHome) { - dirs += QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "icons", QStandardPaths::LocateDirectory).toSet(); - } - - foreach(const QString& dir, dirs) { - QDir userIconsDir(dir); - QDirIterator it(userIconsDir.path(), QDir::NoDotAndDotDot|QDir::AllDirs|QDir::NoSymLinks); - while(it.hasNext()) { - QString currentPath = it.next(); - QDir dir(currentPath); - - if(dir.exists() && dir.exists("index.theme")) { - availableIcons << dir; - } - } - } - - return availableIcons; -} - -bool greatSizeIs48(const QString& a, const QString& b) -{ - bool a48=a.contains("48"), b48=b.contains("48"); - if((a48 && b48) || (!a48 && !b48)) - return a done; - QList paths = installedThemesPaths(); - Q_FOREACH(const QDir& dir, paths) { - KIconTheme theme(dir.dirName()); - if (!theme.isValid()) { //most likely a cursor theme -// qWarning() << "invalid theme" << dir.dirName(); - continue; - } - - if (done.contains(dir.dirName())) - continue; - - done << dir.dirName(); - - QStandardItem* item = new QStandardItem(dir.dirName()); - item->setData(dir.path(), PathRole); - item->setData(dir.dirName(), DirNameRole); - - item->setText(theme.name()); - item->setToolTip(theme.description()); - item->setData(theme.inherits(), IconThemesModel::InheritsRole); - QString iconName = theme.example(); - if (iconName.isEmpty()) - iconName = QStringLiteral("folder"); - - QString path = theme.iconPathByName(iconName, 16, KIconLoader::MatchBest); - item->setIcon(QIcon(path)); - - appendRow(item); - } -} diff --git a/src/iconthemesmodel.h b/src/iconthemesmodel.h deleted file mode 100644 index 1e03332..0000000 --- a/src/iconthemesmodel.h +++ /dev/null @@ -1,45 +0,0 @@ -/* KDE GTK Configuration Module - * - * Copyright 2011 José Antonio Sanchez Reynaga - * Copyright 2011 Aleix Pol Gonzalez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 6 of version 3 of the license. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#ifndef ICONTHEMESMODEL_H -#define ICONTHEMESMODEL_H - -#include - -class QDir; -class IconThemesModel : public QStandardItemModel -{ - public: - enum ThemesRoles { PathRole=Qt::UserRole+1, InheritsRole, DirNameRole }; - - explicit IconThemesModel(bool onlyHome=false, QObject* parent = 0); - - virtual void reload(); - static QString findIconRecursivelyByName(const QString& name, const QDir& directory); - - private: - static QString findFilesRecursively(const QStringList& wildcard, const QDir& directory); - QList installedThemesPaths(); - bool m_onlyHome; -}; - -#endif // ICONTHEMESMODEL_H diff --git a/src/installer.cpp b/src/installer.cpp index 8b45150..d6fd1dd 100644 --- a/src/installer.cpp +++ b/src/installer.cpp @@ -1,50 +1,38 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "installer.h" #include #include #include bool Installer::installTheme(const QString &urlPackage) { QString dest(QDir::homePath()+"/.themes"); QDir::home().mkpath(dest); KTar package(urlPackage); if(!package.open(QIODevice::ReadOnly)) return false; package.directory()->copyTo(dest); return true; } - -bool Installer::installIconTheme(const QString &urlPackage) -{ - QString dest(QDir::homePath()+"/.icons"); - QDir::home().mkpath(dest); - - KTar package(urlPackage); - if(!package.open(QIODevice::ReadOnly)) - return false; - package.directory()->copyTo(dest); - return true; -} diff --git a/src/installer.h b/src/installer.h index 3eeed35..1a9ac2a 100644 --- a/src/installer.h +++ b/src/installer.h @@ -1,45 +1,38 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef INSTALLER_H #define INSTALLER_H #include class Installer { public: /** This function will unpack the @p urlPackage GTK theme packages wherever it has to be installed */ static bool installTheme(const QString& urlPackage); - - /** - This function will unpack the @p urlPackage icons theme packages wherever - it has to be installed - */ - static bool installIconTheme(const QString& urlPackage); - }; #endif // INSTALLER_H diff --git a/src/thread.cpp b/src/thread.cpp index 98e54bb..569a58e 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -1,217 +1,214 @@ /* KDE GTK Configuration Module * * Copyright 2011 José Antonio Sanchez Reynaga * Copyright 2011 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "thread.h" #include #include #include #include #include #include #include #include Thread::Thread(const QString& accion) : action(accion) {} void Thread::start() { emit started(); bool success = false; if(urlPackage.isEmpty()) { qWarning() << "*** ERROR: There's nothing to do"; - } else if(action == "icon") { -// qDebug() << "Installing icons theme"; - success = Installer::installIconTheme(urlPackage); } else if(action == "theme") { // qDebug() << "Installing GTK theme"; success = Installer::installTheme(urlPackage); } setError(success); emitResult(); } void Thread::setUrlPackage(const QString& package) { urlPackage = package; } bool Thread::isSuccess() const { return error()==0; } void ThreadAnalisysTheme::start() { bool success = false; // qDebug()<< "File to install" << packageTheme; KTar package(packageTheme); if(!package.open(QIODevice::ReadOnly)) { // qDebug() << "ERROR extracting the package theme" << packageTheme; setError(1); emitResult(); return; } // qDebug() << "** EXTRACTING ICONS TO A TEMPORAL FOLDER"; //We proceed unpacking the package in a temporal directory QDir temporal(QDir::tempPath()+"/CGC/theme"); //Make sure it's already created temporal.mkpath(temporal.path()); package.directory()->copyTo(temporal.path()); // Package extracted in the temp dir. Now we want to know the name const auto entries = temporal.entryList(QDir::AllDirs|QDir::NoDotAndDotDot); if (entries.isEmpty()) { qDebug() << "no files in" << temporal.path(); setError(3); emitResult(); return; } QString folder=entries.first(); // qDebug() << "FOUND THEME FOLDER = " << folder; // qDebug() << "\n******* THEME " << temporal.path()+'/'+folder; //We know the path of the folder to analyze QDirIterator it(temporal.path()+'/'+folder); while(it.hasNext()) { QString file = it.next(); // qDebug() << "trying file" << file; if(it.fileName()=="gtkrc") { // qDebug() << "FILE : " << file; success = true; break; } } QUrl tempUrl = QUrl::fromLocalFile(temporal.path()); // qDebug() << "Deleting temps. Successful:" << success; if(!KIO::del(tempUrl, KIO::HideProgressInfo)->exec()) qWarning() << "There was not cleanning"; // else // qDebug() << "Cleanning complete" << temporal.path(); if(!success) setError(2); emitResult(); } void ThreadAnalisysTheme::setPackageTheme(const QString& theme) { packageTheme = theme; } bool ThreadAnalisysTheme::isSuccess() const { return error()==0; } void ThreadAnalisysThemeIcon::start() { bool success = false; // qDebug()<< "*************** GTK THEME INSTALLATION"; // qDebug()<< "File to install" << packageTheme; KTar package(packageTheme); if(!package.open(QIODevice::ReadOnly)) { qWarning() << "ERROR extracting the package theme" << packageTheme; return; } // qDebug() << "** EXTRACTING ICONS TO A TEMPORAL FOLDER"; QDir temporal(QDir::tempPath()+"/CGC/icon"); temporal.mkpath(temporal.path()); package.directory()->copyTo(temporal.path()); //archive extracted in the temp directory QString folder= temporal.entryList(QDir::AllDirs|QDir::NoDotAndDotDot).first(); // qDebug() << "FOUND THEME FOLDER = " << folder; // qDebug() << "\n******* THEME " << temporal.path()+'/'+folder; QDirIterator it(temporal.path()+'/'+folder); while(it.hasNext()) { QString file = it.next(); if(it.fileName()=="index.theme") { //archivo index.theme // qDebug() << "FILE : " << file; success = true; break; } } QUrl tempUrl = QUrl::fromLocalFile(temporal.path()); // qDebug() << "Deleting temps. Successful:" << success; if(KIO::del(tempUrl, KIO::HideProgressInfo)->exec()) { qWarning() << "Cleaning was not successful"; } // else // qDebug() << "Cleanning complete." << temporal.path(); if(!success) setError(2); emitResult(); } void ThreadAnalisysThemeIcon::setPackageTheme(const QString& theme) { packageTheme = theme; } bool ThreadAnalisysThemeIcon::isSuccess() { return error()==0; } bool ThreadErase::isSuccess() { return error()==0; } void ThreadErase::setThemeForErase(const QString& theme) { Q_ASSERT(!theme.isEmpty()); themeForErase = theme; } void ThreadErase::start() { KIO::DeleteJob* job = KIO::del(QUrl::fromLocalFile(themeForErase), KIO::HideProgressInfo); connect(job, &KJob::finished, this, &ThreadErase::deleted); } void ThreadErase::deleted(KJob* job) { setError(job->error()); setErrorText(job->errorText()); emitResult(); } diff --git a/src/ui/dialog_installer.ui b/src/ui/dialog_installer.ui index 7e104db..f12d64d 100644 --- a/src/ui/dialog_installer.ui +++ b/src/ui/dialog_installer.ui @@ -1,336 +1,190 @@ dialog_installer 0 0 518 332 0 0 Installer - - - - 450 - 0 - - - - - 16777215 - 600 - - - - QTabWidget::North - - - QTabWidget::Rounded - - - 0 - - - Qt::ElideMiddle - - - false - - - - Add GTK Theme - - - - - - - - - - 0 - 0 - - - - <b>Step 2</b> - - - - - - - - 0 - 0 - - - - Select the theme file you want to install: - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - - - - 0 - 0 - - - - Click the next button in order to install the theme in your system. - - - - - - - - 0 - 0 - - - - <b>Step 1</b> - - - - - - - false - - - Install GTK Theme - - - false - - - - - - - *.tar.gz *.tar|Compressed file - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - Add New Icon Theme - - - - - - - 0 - 0 - - - - - - - - 0 - 0 - - - - Select the theme file you want to install: - - - - - - - - 0 - 0 - - - - <b>Step 1</b> - - - - - - - - 0 - 0 - - - - <b>Step 2</b> - - - - - - - - - - - - - - - 0 - 0 - - - - Click the next button in order to install the theme in your system. - - - - - - - false - - - Install Icon Theme - - - - - - - *.tar.gz *.tar|Compressed file - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + + + + + + 0 + 0 + + + + <b>Step 2</b> + + + + + + + + 0 + 0 + + + + Select the theme file you want to install: + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + + 0 + 0 + + + + Click the next button in order to install the theme in your system. + + + + + + + + 0 + 0 + + + + <b>Step 1</b> + + + + + + + false + + + Install GTK Theme + + + false + + + + + + + *.tar.gz *.tar|Compressed file + + + + - + QDialogButtonBox::Close + + + + Qt::Vertical + + + + 20 + 40 + + + + KUrlRequester QWidget
kurlrequester.h
buttonBox accepted() dialog_installer accept() 387 312 362 300 buttonBox rejected() dialog_installer reject() 484 318 518 296
diff --git a/src/ui/dialog_uninstaller.ui b/src/ui/dialog_uninstaller.ui index b6acfd0..a2c195e 100644 --- a/src/ui/dialog_uninstaller.ui +++ b/src/ui/dialog_uninstaller.ui @@ -1,198 +1,145 @@ dialog_uninstaller 0 0 608 335 Remove Themes 460 0 16777 16777215 Select a GTK theme to uninstall 150 0 Uninstall Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 75 true Remove GTK Theme - - - - - - - Uninstall - - - - - - - Select an icon theme to uninstall - - - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 75 - true - - - - Remove Icon Theme - - - - - - - - 150 - 0 - - - - - - - Qt::Vertical 20 40 QDialogButtonBox::Close buttonBox accepted() dialog_uninstaller accept() 539 320 528 290 buttonBox rejected() dialog_uninstaller reject() 431 325 426 281 diff --git a/src/ui/gui.ui b/src/ui/gui.ui index b823a57..05e6023 100644 --- a/src/ui/gui.ui +++ b/src/ui/gui.ui @@ -1,496 +1,198 @@ GUI 0 0 900 600 - + - - + + + Qt::Horizontal + + - 300 - 0 + 40 + 20 - - GTK Themes - - - - Qt::AlignHCenter|Qt::AlignTop - - - - - GTK2 theme: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - QComboBox::AdjustToContents - - - - - - - Preview Theme - - - true - - - - - - - - - GTK3 theme: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - QComboBox::AdjustToContents - - - - - - - Preview Theme - - - true - - - - - - - - - Prefer dark theme - - - - - - - Font: - - - - - - - - 0 - 0 - - - - - - + - - - - 400 - 0 - - - - Behavior - - - - Qt::AlignHCenter|Qt::AlignTop - - - - - Toolbar label: - - - - - - - 2 - - - - None + + + + + GTK2 theme: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + QComboBox::AdjustToContents - - - - Text only + + + + + + Preview Theme - - - - Beside icons + + true - - - - Below icons + + + + + + + + GTK3 theme: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + QComboBox::AdjustToContents - - - - - - - Show icons: - - - - - - - On scrollbar left-click: - - - - - - - On buttons - - - true - - - - - - - In menus - - - true - - - - - - - Scro&ll one page up/down - - - true - - - buttonGroup_primary_button_warps_slider - - - - - - - &Jump to mouse cursor position - - - buttonGroup_primary_button_warps_slider - - - - - + + + + + + Preview Theme + + + true + + + + + + + + + Prefer dark theme + + + + + + + On scrollbar left-click: + + + + + + + Scro&ll one page up/down + + + true + + + buttonGroup_primary_button_warps_slider + + + + + + + &Jump to mouse cursor position + + + buttonGroup_primary_button_warps_slider + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + - - - - - 16777215 - 400 - - - - Icon Themes - - - - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - - Icon theme: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - - Fallback theme: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - - Cursor theme: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - - 48 - 48 - - - - - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - Qt::Vertical 0 0 Qt::Horizontal 0 0 <html><head/><body><p>Here you can install new GTK themes. Even more are available at <a href="http://gnome-look.org"><span style=" text-decoration: underline;">gnome-look.org</span></a></p></body></html> Get New GNOME/GTK Application Styles... - + + .. - - - KFontRequester - QWidget -
kfontrequester.h
-
-
diff --git a/tests/configsavetest.cpp b/tests/configsavetest.cpp index 1fe8f4f..a1582df 100644 --- a/tests/configsavetest.cpp +++ b/tests/configsavetest.cpp @@ -1,87 +1,73 @@ /* * */ #include "configsavetest.h" #include #include #include QTEST_GUILESS_MAIN(ConfigSaveTest); ConfigSaveTest::ConfigSaveTest() { QStandardPaths::setTestModeEnabled(true); } static void fillValues(QScopedPointer& a) { - a->setFont("a"); - a->setIcon("a"); a->setTheme("a"); - a->setToolbarStyle("a"); - a->setIconFallback("a"); - a->setCursor("a"); - a->setShowIconsInButtons(true); - a->setShowIconsInMenus(true); a->setPrimaryButtonWarpsSlider(true); auto a3 = dynamic_cast(a.data()); if (a3) { a3->setApplicationPreferDarkTheme(false); } } void compareAppearances(QScopedPointer& reloaded, QScopedPointer& instance) { - QCOMPARE(reloaded->getFont(), instance->getFont()); - QCOMPARE(reloaded->getIcon(), instance->getIcon()); QCOMPARE(reloaded->getTheme(), instance->getTheme()); - QCOMPARE(reloaded->getCursor(), instance->getCursor()); - QCOMPARE(reloaded->getToolbarStyle(), instance->getToolbarStyle()); - QCOMPARE(reloaded->getIconFallback(), instance->getIconFallback()); - QCOMPARE(reloaded->getShowIconsInButtons(), instance->getShowIconsInButtons()); - QCOMPARE(reloaded->getShowIconsInMenus(), instance->getShowIconsInMenus()); QCOMPARE(reloaded->getPrimaryButtonWarpsSlider(), instance->getPrimaryButtonWarpsSlider()); } QByteArray readFile(const QString& path) { QFile f(path); if(!f.open(QFile::ReadOnly | QFile::Text)) return QByteArray(); return f.readAll(); } void ConfigSaveTest::testGtk2() { const QString pathA = QDir::current().absoluteFilePath("test-gtk2") , pathB = QDir::current().absoluteFilePath("testB-gtk2"); QScopedPointer instance(new AppearanceGTK2); fillValues(instance); QVERIFY(instance->saveSettings(pathA)); QScopedPointer reloaded(new AppearanceGTK2); QVERIFY(reloaded->loadSettings(pathA)); compareAppearances(reloaded, instance); QVERIFY(reloaded->saveSettings(pathB)); QCOMPARE(readFile(pathA), readFile(pathB)); } void ConfigSaveTest::testGtk3() { QScopedPointer instance(new AppearanceGTK3); fillValues(instance); const QString pathA = QDir::current().absoluteFilePath("test-gtk3") , pathB = QDir::current().absoluteFilePath("testB-gtk3"); QVERIFY(instance->saveSettings(pathA)); QScopedPointer reloaded(new AppearanceGTK3); QVERIFY(QFile::exists(pathA)); QVERIFY(reloaded->loadSettings(pathA)); compareAppearances(reloaded, instance); QVERIFY(reloaded->saveSettings(pathB)); QCOMPARE(readFile(pathA), readFile(pathB)); }