diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,9 +50,29 @@ 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) + +target_compile_definitions(kcm_kdegtkconfig + PRIVATE + -DPROJECT_VERSION="${PROJECT_VERSION}" + -DQT_NO_SIGNALS_SLOTS_KEYWORDS +) + +target_link_libraries(kcm_kdegtkconfig + ${GIO2_LIBRARY} + ${GLIB2_LIBRARY} + ${GTK3_LIBRARY} + ${GOBJECT2_LIBRARY} + Qt5::Svg + KF5::ConfigCore + KF5::I18n + KF5::KIOWidgets + KF5::NewStuff + KF5::Archive + KF5::ConfigWidgets + KF5::IconThemes +) kcoreaddons_desktop_to_json(kcm_kdegtkconfig kde-gtk-config.desktop) diff --git a/src/abstractappearance.h b/src/abstractappearance.h --- a/src/abstractappearance.h +++ b/src/abstractappearance.h @@ -32,21 +32,21 @@ 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; + 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 setTheme(const QString &name); QString getTheme() const; QString getThemeGtk3() const; QStringList installedThemesNames() const; - bool hasProperty(const QString& key) const; + bool hasProperty(const QString &key) const; - static QMap readSettingsTuples(QIODevice* device); + static QMap readSettingsTuples(QIODevice *device); protected: QMap m_settings; diff --git a/src/abstractappearance.cpp b/src/abstractappearance.cpp --- a/src/abstractappearance.cpp +++ b/src/abstractappearance.cpp @@ -19,48 +19,52 @@ * License along with this library. If not, see . */ -#include "abstractappearance.h" -#include #include #include +#include + +#include "abstractappearance.h" -static bool isTrue(const QString& value) +void AbstractAppearance::setTheme(const QString& name) { - return value == "1" || value == "true"; + m_settings["theme"] = name; } -//SETTERS -void AbstractAppearance::setTheme(const QString& name) { m_settings["theme"] = name;} +QString AbstractAppearance::getTheme() const +{ + return m_settings["theme"]; +} -// GETTERS -QString AbstractAppearance::getTheme() const { return m_settings["theme"];} -QString AbstractAppearance::getThemeGtk3() const { return m_settings["themegtk3"]; } +QString AbstractAppearance::getThemeGtk3() const +{ + return m_settings["themegtk3"]; +} -QRegExp valueRx(" *([a-zA-Z\\-_]+) *= *\"?([^\"\\n]+)\"?", Qt::CaseSensitive, QRegExp::RegExp2); QMap AbstractAppearance::readSettingsTuples(QIODevice* device) { + static const QRegExp valueRx(" *([a-zA-Z\\-_]+) *= *\"?([^\"\\n]+)\"?", Qt::CaseSensitive, QRegExp::RegExp2); + QMap ret; QTextStream flow(device); - for(; !flow.atEnd() ;) { + while (!flow.atEnd()) { QString line = flow.readLine(); int idxComment = line.indexOf('#'); - if(idxComment>=0) + if (idxComment >= 0) { line = line.left(idxComment).simplified(); + } - if(valueRx.exactMatch(line)) + if (valueRx.exactMatch(line)) { ret[valueRx.cap(1)] = valueRx.cap(2); - else if(line.startsWith("include \"")) { + } 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)) { + if (f.open(QFile::Text | QFile::ReadOnly)) { ret.unite(readSettingsTuples(&f)); - } else + } else { qWarning() << "couldn't include " << filename; + } } -// else if(!line.isEmpty()) -// qWarning() << "misinterpreted line" << line; } return ret; } @@ -70,8 +74,9 @@ QStringList themes = installedThemes(); QStringList ret; - foreach(const QString& theme, themes) + for(const QString &theme : themes) { ret += QDir(theme).dirName(); + } return ret; } diff --git a/src/appearancegtk2.h b/src/appearancegtk2.h --- a/src/appearancegtk2.h +++ b/src/appearancegtk2.h @@ -27,22 +27,22 @@ class AppearanceGTK2 : public AbstractAppearance { - bool loadSettings(const QString& path) override; - bool saveSettings(const QString& path) const override; + bool loadSettings(const QString &path) override; + bool saveSettings(const QString &path) const override; bool loadSettings() override; bool saveSettings() const override; QStringList installedThemes() const override; - QString themesGtkrcFile(const QString& themeName) const; + QString themesGtkrcFile(const QString &themeName) const; private: void reset(); QString defaultConfigFile() const; - bool loadSettingsPrivate(const QString& path); - bool saveSettingsPrivate(const QString& path) const; - void modifyGtkrcContents(QString& fileContents) const; - void modifyGtkrcProperty(const QString& propertyName, const QString& newValue, QString& fileContents) const; - void removeGtkrcLegacyContents(QString& fileContents) const; + bool loadSettingsPrivate(const QString &path); + bool saveSettingsPrivate(const QString &path) const; + void modifyGtkrcContents(QString &fileContents) const; + void modifyGtkrcProperty(const QString &propertyName, const QString &newValue, QString &fileContents) const; + void removeGtkrcLegacyContents(QString &fileContents) const; }; #endif // APPEARANCEGTK2_H diff --git a/src/appearancegtk2.cpp b/src/appearancegtk2.cpp --- a/src/appearancegtk2.cpp +++ b/src/appearancegtk2.cpp @@ -20,57 +20,59 @@ * 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) +#include "config.h" +#include "appearancegtk2.h" + +bool AppearanceGTK2::loadSettingsPrivate(const QString &path) { QFile configFile(path); - if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text)) + 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; + if (it.key() == QStringLiteral("gtk-theme-name")) { + m_settings[QStringLiteral("theme")] = *it; + } } return true; } -QString AppearanceGTK2::themesGtkrcFile(const QString& themeName) const +QString AppearanceGTK2::themesGtkrcFile(const QString &themeName) const { - QStringList themes=installedThemes(); - themes=themes.filter(QRegExp("/"+themeName+"/?$")); - if(themes.size()==1) { + 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(); + if(it.fileName() == "gtkrc") { return it.filePath(); } } } return QString(); } -bool AppearanceGTK2::saveSettingsPrivate(const QString& gtkrcFile) const +bool AppearanceGTK2::saveSettingsPrivate(const QString >krcFile) const { - QFile gtkrc{gtkrcFile}; + QFile gtkrc(gtkrcFile); if (gtkrc.open(QIODevice::ReadWrite | QIODevice::Text)) { - QString fileContents{gtkrc.readAll()}; + QString fileContents = gtkrc.readAll(); modifyGtkrcContents(fileContents); @@ -84,18 +86,18 @@ return true; } else { - qWarning() << "There was unable to write the .gtkrc-2.0 file"; + qWarning() << "Unable to write the .gtkrc-2.0 file"; return false; } } -void AppearanceGTK2::modifyGtkrcContents(QString& fileContents) const +void AppearanceGTK2::modifyGtkrcContents(QString &fileContents) const { modifyGtkrcProperty("gtk-theme-name", m_settings["theme"], fileContents); removeGtkrcLegacyContents(fileContents); } -void AppearanceGTK2::modifyGtkrcProperty(const QString& propertyName, const QString& newValue, QString& fileContents) const +void AppearanceGTK2::modifyGtkrcProperty(const QString &propertyName, const QString &newValue, QString &fileContents) const { const QRegularExpression regExp{propertyName + "=[^\n]*($|\n)"}; @@ -143,34 +145,35 @@ void AppearanceGTK2::reset() { - m_settings = QMap {}; + m_settings.clear(); } QString AppearanceGTK2::defaultConfigFile() const { - return QDir::homePath()+"/.gtkrc-2.0"; + return QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); } QStringList AppearanceGTK2::installedThemes() const { QFileInfoList availableThemes; - foreach(const QString& themesDir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { + for (const QString& themesDir : QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { QDir root(themesDir); - availableThemes += root.entryInfoList(QDir::NoDotAndDotDot|QDir::AllDirs); + 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); + // 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 + // 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"); + for (const QFileInfo &it : availableThemes) { + 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(); + // If it doesn't exist, we don't want it on the list + if (hasGtkrc) { + paths += it.filePath(); + } } return paths; @@ -180,7 +183,7 @@ { reset(); - bool b = loadSettingsPrivate("/etc/gtk-2.0/gtkrc"); + bool b = loadSettingsPrivate(QStringLiteral("/etc/gtk-2.0/gtkrc")); b |= loadSettingsPrivate(defaultConfigFile()); return b; } @@ -190,13 +193,13 @@ return saveSettings(defaultConfigFile()); } -bool AppearanceGTK2::loadSettings(const QString& gtkrcFile) +bool AppearanceGTK2::loadSettings(const QString >krcFile) { reset(); return loadSettingsPrivate(gtkrcFile); } -bool AppearanceGTK2::saveSettings(const QString& gtkrcFile) const +bool AppearanceGTK2::saveSettings(const QString >krcFile) const { return saveSettingsPrivate(gtkrcFile); } diff --git a/src/appearancegtk3.h b/src/appearancegtk3.h --- a/src/appearancegtk3.h +++ b/src/appearancegtk3.h @@ -24,6 +24,7 @@ #define APPEARANCEGTK3_H #include + #include "abstractappearance.h" class AppearanceGTK3 : public AbstractAppearance @@ -33,16 +34,16 @@ QStringList installedThemes() const override; bool saveSettings() const override; bool loadSettings() override; - bool saveSettings(const QString& file) const override; - bool loadSettings(const QString& path) override; + bool saveSettings(const QString &file) const override; + bool loadSettings(const QString &path) override; bool getApplicationPreferDarkTheme() const; - void setApplicationPreferDarkTheme(const bool& enable); + void setApplicationPreferDarkTheme(bool enable); private: QString defaultConfigFile() const; QString configFileName() const; - bool saveSettings(const KSharedConfig::Ptr& file) const; - bool loadSettings(const KSharedConfig::Ptr& file); + bool saveSettings(const KSharedConfig::Ptr &file) const; + bool loadSettings(const KSharedConfig::Ptr &file); }; #endif // APPEARANCEGTK3_H diff --git a/src/appearancegtk3.cpp b/src/appearancegtk3.cpp --- a/src/appearancegtk3.cpp +++ b/src/appearancegtk3.cpp @@ -20,77 +20,78 @@ * 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 + +#include "appearancegtk3.h" QStringList AppearanceGTK3::installedThemes() const { QFileInfoList availableThemes; - foreach(const QString& themesDir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "themes", QStandardPaths::LocateDirectory)) { + for (const QString& themesDir : QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("themes"), QStandardPaths::LocateDirectory)) { QDir root(themesDir); - availableThemes += root.entryInfoList(QDir::NoDotAndDotDot|QDir::AllDirs); + 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); + // Also show the user-installed themes + QDir user(QDir::homePath() + QStringLiteral("/.themes")); + availableThemes += user.entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs); - //we just want actual themes + // 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()); + QStringList gtk3SubdirPattern(QStringLiteral("gtk-3.*")); + for (const QFileInfo &it : availableThemes) { + QDir themeDir(it.filePath()); if(!themeDir.entryList(gtk3SubdirPattern, QDir::Dirs).isEmpty()) - themes += it->filePath(); + themes += it.filePath(); } return themes; } bool AppearanceGTK3::saveSettings(const KSharedConfig::Ptr& file) const { - KConfigGroup group(file, "Settings"); + KConfigGroup group(file, QStringLiteral("Settings")); - group.writeEntry("gtk-theme-name", m_settings["theme"]); - group.writeEntry("gtk-application-prefer-dark-theme", m_settings["application_prefer_dark_theme"]); + group.writeEntry(QStringLiteral("gtk-theme-name"), m_settings["theme"]); + group.writeEntry(QStringLiteral("gtk-application-prefer-dark-theme"), m_settings[QStringLiteral("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"); + KConfigGroup group(file, QStringLiteral("Settings")); if (!file || !group.isValid()) { - qWarning() << "Cannot open the GTK3 config file" << file; + qWarning() << QStringLiteral("Cannot open the GTK3 config file") << file; return false; } m_settings = QMap { - {"application_prefer_dark_theme", "false"} + {QStringLiteral("application_prefer_dark_theme"), QStringLiteral("false")} }; - m_settings["theme"] = group.readEntry("gtk-theme-name"); - m_settings["application_prefer_dark_theme"] = group.readEntry("gtk-application-prefer-dark-theme"); + m_settings[QStringLiteral("theme")] = group.readEntry(QStringLiteral("gtk-theme-name")); + m_settings[QStringLiteral("application_prefer_dark_theme")] = group.readEntry(QStringLiteral("gtk-application-prefer-dark-theme")); for(auto it = m_settings.begin(); it != m_settings.end(); ) { - if (it.value().isEmpty()) + if (it.value().isEmpty()) { it = m_settings.erase(it); - else + } else { ++it; + } } return true; } @@ -103,20 +104,21 @@ QString AppearanceGTK3::defaultConfigFile() const { QString root = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); - if(root.isEmpty()) - root = QFileInfo(QDir::home(), ".config").absoluteFilePath(); + if(root.isEmpty()) { + root = QFileInfo(QDir::home(), QStringLiteral(".config")).absoluteFilePath(); + } return root + '/' + configFileName(); } bool AppearanceGTK3::getApplicationPreferDarkTheme() const { - return m_settings["application_prefer_dark_theme"] == "1" || m_settings["application_prefer_dark_theme"] == "true"; + return m_settings[QStringLiteral("application_prefer_dark_theme")] == QStringLiteral("1") || m_settings[QStringLiteral("application_prefer_dark_theme")] == QStringLiteral("true"); } -void AppearanceGTK3::setApplicationPreferDarkTheme(const bool& enable) +void AppearanceGTK3::setApplicationPreferDarkTheme(bool enable) { - m_settings["application_prefer_dark_theme"] = enable ? "true" : "false"; + m_settings[QStringLiteral("application_prefer_dark_theme")] = enable ? QStringLiteral("true") : QStringLiteral("false"); } bool AppearanceGTK3::saveSettings(const QString& file) const @@ -143,8 +145,6 @@ // 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()); diff --git a/src/appearencegtk.h b/src/appearencegtk.h --- a/src/appearencegtk.h +++ b/src/appearencegtk.h @@ -25,9 +25,10 @@ #include #include -#include +#include class AbstractAppearance; + /** * This class is responsible of administrating the GTK themes. It loads the * configurations from the .gtkrc-2.0 file. @@ -38,32 +39,14 @@ AppearenceGTK(); ~AppearenceGTK(); - void setTheme(const QString&); + void setTheme(const QString &); void setThemeGtk3(const QString &theme); - void setApplicationPreferDarkTheme(const bool& enable); - void setCursor(const QString&); - void setIcon(const QString&); - void setIconFallback(const QString&); - void setFont(const QString&); + void setApplicationPreferDarkTheme(bool enable); - void setToolbarStyle(const QString&); - void setShowIconsInMenus(const bool& show); - void setShowIconsInButtons(const bool& show); - void setPrimaryButtonWarpsSlider(const bool &enable); - QString getTheme() const; QString getThemeGtk3() const; bool getApplicationPreferDarkTheme() const; - QString getCursor() const; - QString getIcon() const; - QString getFont() const; - QString getIconFallback() const; - QString getToolbarStyle() const; - bool getShowIconsInMenus() const; - bool getShowIconsInButtons() const; - bool getPrimaryButtonWarpsSlider() const; - bool loadFileConfig(); bool saveFileConfig(); diff --git a/src/appearencegtk.cpp b/src/appearencegtk.cpp --- a/src/appearencegtk.cpp +++ b/src/appearencegtk.cpp @@ -20,9 +20,10 @@ * License along with this library. If not, see . */ -#include "appearencegtk.h" #include + #include "abstractappearance.h" +#include "appearencegtk.h" #include "appearancegtk2.h" #include "appearancegtk3.h" @@ -37,34 +38,52 @@ qDeleteAll(m_app); } -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); } +QString AppearenceGTK::getTheme() const +{ + return gtk2Appearance()->getTheme(); +} + +void AppearenceGTK::setTheme(const QString& name) +{ + return gtk2Appearance()->setTheme(name); +} -//////////////////////////////////// -// Methods responsible of file creation +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(bool enable) +{ + return ((AppearanceGTK3*)gtk3Appearance())->setApplicationPreferDarkTheme(enable); +} bool AppearenceGTK::loadFileConfig() { bool correct = false; - foreach(AbstractAppearance* app, m_app) { + for(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) { + for(AbstractAppearance *app : m_app) { bool c = app->saveSettings(); correct = correct && c; } -// qDebug() << "saving..." << correct; return correct; } diff --git a/src/dialog_installer.h b/src/dialog_installer.h --- a/src/dialog_installer.h +++ b/src/dialog_installer.h @@ -21,11 +21,13 @@ #ifndef DIALOGINSTALLER_H #define DIALOGINSTALLER_H + #include class ThreadAnalisysThemeIcon; class ThreadAnalisysTheme; class Thread; + namespace Ui { class dialog_installer; } @@ -40,13 +42,13 @@ DialogInstaller(QWidget *parent=0); ~DialogInstaller(); -signals: +Q_SIGNALS: /** * Whenever a theme is installed, this signal is emitted */ void themeInstalled(); -private slots: +private Q_SLOTS: /** Instala el tema de icono a traves del objeto Installer Para ello lanza un hilo para que no se bloqué la GUI @@ -58,7 +60,7 @@ void refreshGUITheme(); void themeAnalisys(); - ///executed after analyzing theme + // Executed after analyzing theme void checkThemeAnalisys(); private: diff --git a/src/dialog_installer.cpp b/src/dialog_installer.cpp --- a/src/dialog_installer.cpp +++ b/src/dialog_installer.cpp @@ -19,20 +19,23 @@ * License along with this library. If not, see . */ +#include +#include + +#include +#include + #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()) + if(file.isDir() || !file.exists()) { return false; + } QMimeDatabase db; QMimeType type = db.mimeTypeForUrl(QUrl::fromLocalFile(path)); @@ -44,11 +47,11 @@ { ui->setupUi(this); - //TODO: make sure it's a good idea to have the threads always instanciated + // TODO: make sure it's a good idea to have the threads always instanciated threadForTheme = new Thread("theme"); threadAnalisysTheme = new ThreadAnalisysTheme; - //installation ui + // Installation ui connect(ui->theme_file, &KUrlRequester::textChanged, this, &DialogInstaller::themeAnalisys); connect(ui->but_theme_install, &QAbstractButton::clicked, this, &DialogInstaller::installTheme); @@ -58,7 +61,7 @@ connect(threadForTheme, &Thread::started, this, &DialogInstaller::disableGUIThemeInstaller); connect(threadForTheme, &KJob::finished, this, &DialogInstaller::enableGUIThemeInstaller); - //ui refresh + // Ui refresh connect(threadForTheme, &KJob::finished, this, &DialogInstaller::refreshGUITheme); } @@ -78,7 +81,6 @@ { 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; @@ -110,7 +112,6 @@ ui->lb_theme_notice->setText(i18n("This GTK theme cannot be installed")); ui->but_theme_install->setEnabled(false); } - } void DialogInstaller::enableGUIThemeInstaller() diff --git a/src/dialog_uninstaller.h b/src/dialog_uninstaller.h --- a/src/dialog_uninstaller.h +++ b/src/dialog_uninstaller.h @@ -41,10 +41,10 @@ DialogUninstaller(QWidget *parent = 0, AppearenceGTK *app=0); ~DialogUninstaller(); -signals: +Q_SIGNALS: void themeUninstalled(); -public slots: +public Q_SLOTS: void refreshListsForUninstall(); void uninstallTheme(); void threadUninstalledThemeFinished(KJob* job); diff --git a/src/dialog_uninstaller.cpp b/src/dialog_uninstaller.cpp --- a/src/dialog_uninstaller.cpp +++ b/src/dialog_uninstaller.cpp @@ -20,16 +20,18 @@ * License along with this library. If not, see . */ +#include +#include + +#include + #include "dialog_uninstaller.h" #include "abstractappearance.h" #include "ui_dialog_uninstaller.h" #include "thread.h" #include "appearencegtk.h" -#include -#include -#include -DialogUninstaller::DialogUninstaller(QWidget* parent, AppearenceGTK *app) +DialogUninstaller::DialogUninstaller(QWidget *parent, AppearenceGTK *app) : QDialog(parent) , ui(new Ui::dialog_uninstaller) , appareance(app) @@ -51,9 +53,9 @@ ui->lb_notice_uninstall_theme->clear(); QStringList themes = appareance->gtk2Appearance()->installedThemes(); - themes = themes.filter(QDir::homePath()); //we only one the locally installed themes + themes = themes.filter(QDir::homePath()); // We only one the locally installed themes - //Just leave the theme name + // Just leave the theme name for(QStringList::iterator it=themes.begin(); it!=themes.end(); ++it) *it = QDir(*it).dirName(); @@ -69,9 +71,9 @@ QString tema = ui->cb_uninstall_theme->currentText(); QStringList themes = appareance->gtk2Appearance()->installedThemes(); - themes = themes.filter(QRegExp('/'+tema+'$')); + themes = themes.filter(QRegExp('/' + tema + '$')); - Q_ASSERT(themes.size()==1); + Q_ASSERT(themes.size() == 1); ui->cb_uninstall_theme->setEnabled(false); ui->but_uninstall_theme->setEnabled(false); @@ -86,7 +88,7 @@ void DialogUninstaller::threadUninstalledThemeFinished(KJob* job) { - if(job->error()==0) { + if (job->error()==0) { ui->lb_notice_uninstall_theme->setText(i18n("GTK theme successfully uninstalled.")); emit(themeUninstalled()); } else { diff --git a/src/gtkconfigkcmodule.h b/src/gtkconfigkcmodule.h --- a/src/gtkconfigkcmodule.h +++ b/src/gtkconfigkcmodule.h @@ -24,32 +24,33 @@ #ifndef GTKCONFIGKCMODULE_H #define GTKCONFIGKCMODULE_H -#include +#include +#include + #include "appearencegtk.h" #include "dialog_installer.h" #include "dialog_uninstaller.h" -#include class KProcess; namespace Ui { class Modulo; class GUI; } class GTKConfigKCModule : public KCModule { Q_OBJECT public: - explicit GTKConfigKCModule(QWidget* parent = 0 ,const QVariantList& args = QVariantList() ); + explicit GTKConfigKCModule(QWidget *parent = 0 ,const QVariantList &args = QVariantList() ); ~GTKConfigKCModule(); - void refreshThemesUi(bool useConfig=false); + void refreshThemesUi(bool useConfig = false); void save() override; void defaults() override; void load() override; -public slots: +public Q_SLOTS: void refreshLists(); - ///it is called whenever something in the UI has changed + // It is called whenever something in the UI has changed void appChanged(); void savePreviewConfig(); @@ -72,8 +73,8 @@ DialogInstaller *installer; DialogUninstaller *uninstaller; - KProcess* m_p2; - KProcess* m_p3; + KProcess *m_p2; + KProcess *m_p3; QString m_tempGtk2Preview; QString m_tempGtk3Preview; bool m_saveEnabled; diff --git a/src/gtkconfigkcmodule.cpp b/src/gtkconfigkcmodule.cpp --- a/src/gtkconfigkcmodule.cpp +++ b/src/gtkconfigkcmodule.cpp @@ -20,26 +20,28 @@ * 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 -#include +#include #include #include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "ui_gui.h" +#include "abstractappearance.h" +#include "gtkconfigkcmodule.h" + K_PLUGIN_FACTORY_WITH_JSON(GTKConfigKCModuleFactory, "kde-gtk-config.json", registerPlugin();) GTKConfigKCModule::GTKConfigKCModule(QWidget* parent, const QVariantList& args ) @@ -61,8 +63,8 @@ ui->setupUi(this); appareance = new AppearenceGTK; - m_tempGtk2Preview = QStandardPaths::writableLocation(QStandardPaths::TempLocation)+ "/gtkrc-2.0"; - m_tempGtk3Preview = QStandardPaths::writableLocation(QStandardPaths::TempLocation)+ "/.config/gtk-3.0/settings.ini"; + 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); @@ -88,16 +90,16 @@ ui->gtk2Preview->setVisible(!gtk2Preview.isEmpty()); ui->gtk3Preview->setVisible(!gtk3Preview.isEmpty()); - //UI changes + // 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); - //preview updates + // Preview updates connect(ui->gtk2Preview, &QAbstractButton::clicked, this, >KConfigKCModule::runGtk2IfNecessary); connect(ui->gtk3Preview, &QAbstractButton::clicked, this, >KConfigKCModule::runGtk3IfNecessary); - QMenu* m = new QMenu(this); + 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); @@ -150,29 +152,30 @@ void GTKConfigKCModule::appChanged() { - if (m_loading) + if (m_loading) { return; + } savePreviewConfig(); emit changed(true); } void GTKConfigKCModule::savePreviewConfig() { - if(!m_saveEnabled || !(ui->gtk2Preview->isChecked() || ui->gtk3Preview->isChecked())) + 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 + // 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 + // Need to make sure runIfNecessary() to know that it's not running m_p3->waitForFinished(); m_p3->start(); @@ -188,12 +191,13 @@ KProcess* p = m_p2; KProcess* np = m_p3; - if(checked) { + if (checked) { np->kill(); np->waitForFinished(); savePreviewConfig(); - if(p->state() == QProcess::NotRunning) + if(p->state() == QProcess::NotRunning) { p->start(); + } } else { p->kill(); p->waitForFinished(); @@ -205,35 +209,32 @@ KProcess* p = m_p3; KProcess* np = m_p2; - if(checked) { + if (checked) { np->kill(); np->waitForFinished(); savePreviewConfig(); - if(p->state() == QProcess::NotRunning) + 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" - << "********************************************************"; - */ syncUI(); - if(!appareance->saveFileConfig()) + if(!appareance->saveFileConfig()) { KMessageBox::error(this, i18n("Failed to save configuration.")); + } } void setComboItem(QComboBox* combo, const QStringList& texts) { - foreach(const QString& text, texts) { + for (const QString &text : texts) { int pos = combo->findText(text); - if(pos>=0) { + if(pos >= 0) { combo->setCurrentIndex(pos); return; } @@ -244,7 +245,6 @@ { refreshThemesUi(false); -// qDebug() << "loading defaults..."; m_saveEnabled = false; setComboItem(ui->cb_theme, QStringList("oxygen-gtk") << "Clearlooks"); @@ -279,13 +279,16 @@ QVariant data(const QModelIndex & index, int role) const override { - if (role != Qt::DisplayRole || !index.isValid() || index.row()>=m_texts.count()) + 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(); } + 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(); @@ -299,11 +302,12 @@ } int from = -1; - for(const auto &row: oldRows) { - for(; fromcb_theme, useConfig ? appareance->getTheme() : ui->cb_theme->currentText(), appareance->gtk2Appearance()->installedThemesNames()); - //theme gtk3 + // Theme gtk3 refreshComboSameCurrentValue(ui->cb_theme_gtk3, useConfig ? appareance->getThemeGtk3() : ui->cb_theme_gtk3->currentText(), appareance->gtk3Appearance()->installedThemesNames()); - // dark theme for gtk3 + // Dark theme for gtk3 ui->checkBox_theme_gtk3_prefer_dark->setChecked(appareance->getApplicationPreferDarkTheme()); @@ -378,10 +382,11 @@ void GTKConfigKCModule::untogglePreview() { - if(sender()==m_p2) + if(sender() == m_p2) { ui->gtk2Preview->setChecked(false); - else + } else { ui->gtk3Preview->setChecked(false); + } } #include "gtkconfigkcmodule.moc" diff --git a/src/installer.cpp b/src/installer.cpp --- a/src/installer.cpp +++ b/src/installer.cpp @@ -20,19 +20,22 @@ * License along with this library. If not, see . */ -#include "installer.h" #include #include + #include +#include "installer.h" + bool Installer::installTheme(const QString &urlPackage) { - QString dest(QDir::homePath()+"/.themes"); + QString dest(QDir::homePath() + QStringLiteral("/.themes")); QDir::home().mkpath(dest); KTar package(urlPackage); - if(!package.open(QIODevice::ReadOnly)) + if(!package.open(QIODevice::ReadOnly)) { return false; + } package.directory()->copyTo(dest); return true; } diff --git a/src/thread.h b/src/thread.h --- a/src/thread.h +++ b/src/thread.h @@ -42,7 +42,7 @@ ///@returns whether it was successful bool isSuccess() const; -signals: +Q_SIGNALS: void started(); private: @@ -92,7 +92,7 @@ private: QString themeForErase; -public slots: +public Q_SLOTS: void deleted(KJob*); }; diff --git a/src/thread.cpp b/src/thread.cpp --- a/src/thread.cpp +++ b/src/thread.cpp @@ -20,16 +20,18 @@ * License along with this library. If not, see . */ -#include "thread.h" #include #include #include #include #include #include + #include #include +#include "thread.h" + Thread::Thread(const QString& accion) : action(accion) {} @@ -39,10 +41,9 @@ emit started(); bool success = false; - if(urlPackage.isEmpty()) { + if (urlPackage.isEmpty()) { qWarning() << "*** ERROR: There's nothing to do"; } else if(action == "theme") { -// qDebug() << "Installing GTK theme"; success = Installer::installTheme(urlPackage); } setError(success); @@ -56,26 +57,24 @@ bool Thread::isSuccess() const { - return error()==0; + 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 + + // We proceed unpacking the package in a temporal directory QDir temporal(QDir::tempPath()+"/CGC/theme"); - //Make sure it's already created + // Make sure it's already created temporal.mkpath(temporal.path()); package.directory()->copyTo(temporal.path()); @@ -90,33 +89,26 @@ } 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); + // 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; + if(it.fileName() == QStringLiteral("gtkrc")) { success = true; break; } } QUrl tempUrl = QUrl::fromLocalFile(temporal.path()); -// qDebug() << "Deleting temps. Successful:" << success; - if(!KIO::del(tempUrl, KIO::HideProgressInfo)->exec()) + if(!KIO::del(tempUrl, KIO::HideProgressInfo)->exec()) { qWarning() << "There was not cleanning"; -// else -// qDebug() << "Cleanning complete" << temporal.path(); + } - if(!success) + if(!success) { setError(2); + } emitResult(); } @@ -127,53 +119,43 @@ bool ThreadAnalisysTheme::isSuccess() const { - return error()==0; + 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"); + + QDir temporal(QDir::tempPath() + "/CGC/icon"); temporal.mkpath(temporal.path()); package.directory()->copyTo(temporal.path()); - //archive extracted in the temp directory + // 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; + if(it.fileName() == QStringLiteral("index.theme")) { 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(); @@ -186,12 +168,12 @@ bool ThreadAnalisysThemeIcon::isSuccess() { - return error()==0; + return error() == 0; } bool ThreadErase::isSuccess() { - return error()==0; + return error() == 0; } void ThreadErase::setThemeForErase(const QString& theme) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,6 +3,7 @@ add_test(${name} ${name}) ecm_mark_as_test(${name}) target_link_libraries(${name} ${GIO2_LIBRARY} ${GLIB2_LIBRARY} ${GTK3_LIBRARY} ${GOBJECT2_LIBRARY} Qt5::Core Qt5::Gui Qt5::Test KF5::ConfigCore) + target_compile_definitions(${name} PUBLIC -DQT_NO_SIGNALS_SLOTS_KEYWORDS) target_include_directories(${name} PRIVATE ${CMAKE_BINARY_DIR}) endmacro(add_kgc_test) diff --git a/tests/configsavetest.h b/tests/configsavetest.h --- a/tests/configsavetest.h +++ b/tests/configsavetest.h @@ -12,7 +12,7 @@ Q_OBJECT public: ConfigSaveTest(); -private slots: +private Q_SLOTS: void testGtk2(); void testGtk3(); };