From 482a8ccb53a7553a0fdca4e0ee8392c216b831c3 Mon Sep 17 00:00:00 2001 From: Oguzhan INAN Date: Thu, 8 Mar 2018 15:31:59 +0300 Subject: [PATCH] updated variable names --- CMakeLists.txt | 2 +- stacer-core/Info/cpu_info.cpp | 4 +- stacer-core/Info/network_info.h | 2 +- stacer-core/Info/process.cpp | 5 - stacer-core/Info/process.h | 6 - stacer-core/Info/system_info.cpp | 2 +- stacer-core/Info/system_info.h | 5 +- stacer-core/Tools/apt_source_tool.cpp | 87 ++++++++------- stacer-core/Tools/apt_source_tool.h | 1 + stacer-core/Utils/format_util.cpp | 1 - stacer-core/Utils/format_util.h | 11 +- stacer-core/stacer-core.pro | 4 + stacer/Managers/app_manager.cpp | 28 ++--- stacer/Managers/app_manager.h | 11 +- stacer/Managers/info_manager.cpp | 33 +++--- stacer/Managers/info_manager.h | 5 +- stacer/Managers/tool_manager.cpp | 41 +++---- stacer/Managers/tool_manager.h | 20 +--- .../AptSourceManager/apt_source_edit.cpp | 5 +- .../Pages/AptSourceManager/apt_source_edit.ui | 7 +- .../apt_source_manager_page.cpp | 30 ++--- .../apt_source_manager_page.h | 5 +- .../apt_source_repository_item.cpp | 10 +- .../apt_source_repository_item.h | 2 - stacer/Pages/Dashboard/circlebar.cpp | 59 +++++----- stacer/Pages/Dashboard/circlebar.h | 10 +- stacer/Pages/Dashboard/circlebar.ui | 6 +- stacer/Pages/Dashboard/dashboard_page.cpp | 104 +++++++++--------- stacer/Pages/Dashboard/dashboard_page.h | 19 ++-- stacer/Pages/Dashboard/dashboard_page.ui | 2 +- stacer/Pages/Dashboard/linebar.h | 1 + .../Pages/GnomeSettings/gnome_settings_page.h | 4 +- stacer/Pages/Processes/processes_page.cpp | 104 ++++++++++-------- stacer/Pages/Processes/processes_page.h | 15 ++- stacer/Pages/Resources/history_chart.cpp | 66 +++++------ stacer/Pages/Resources/history_chart.h | 17 ++- stacer/Pages/Services/service_item.cpp | 10 +- stacer/Pages/Services/services_page.cpp | 12 +- stacer/Pages/Settings/settings_page.cpp | 14 +-- stacer/Pages/Settings/settings_page.h | 2 +- stacer/Pages/StartupApps/startup_app.cpp | 31 +++--- stacer/Pages/StartupApps/startup_app.h | 10 +- stacer/Pages/StartupApps/startup_app_edit.cpp | 23 ++-- stacer/Pages/StartupApps/startup_app_edit.h | 4 +- stacer/Pages/StartupApps/startup_app_edit.ui | 68 ++++++------ .../Pages/StartupApps/startup_apps_page.cpp | 18 +-- stacer/Pages/StartupApps/startup_apps_page.h | 2 +- .../SystemCleaner/system_cleaner_page.cpp | 30 ++--- .../Pages/SystemCleaner/system_cleaner_page.h | 11 +- stacer/Pages/Uninstaller/uninstaller_page.cpp | 14 ++- stacer/Pages/Uninstaller/uninstaller_page.h | 8 +- stacer/app.cpp | 81 +++++++------- stacer/app.h | 12 +- stacer/feedback.cpp | 16 +-- stacer/feedback.h | 6 +- stacer/utilities.h | 4 +- 56 files changed, 548 insertions(+), 562 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cdd6a612..8de9ed1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") # Activating MOC and searching for the Qt5 dependencies set(CMAKE_AUTOMOC ON) -find_package(Qt5 COMPONENTS Core Gui Widgets Charts Svg Concurrent REQUIRED) +find_package(Qt5 COMPONENTS Core Gui Widgets Charts Svg Concurrent REQUIRED) # Setting the minimum C++ standard and passing the Qt-specific define set(CMAKE_CXX_STANDARD 11) diff --git a/stacer-core/Info/cpu_info.cpp b/stacer-core/Info/cpu_info.cpp index bd5f2590..f7679c9b 100644 --- a/stacer-core/Info/cpu_info.cpp +++ b/stacer-core/Info/cpu_info.cpp @@ -16,10 +16,12 @@ quint8 CpuInfo::getCpuCoreCount() const QList CpuInfo::getLoadAvgs() const { - QList avgs; + QList avgs = {0, 0, 0}; + QStringList strListAvgs = FileUtil::readStringFromFile(PROC_LOADAVG).split(QRegExp("\\s+")); if (strListAvgs.count() > 2) { + avgs.clear(); avgs << strListAvgs.takeFirst().toDouble(); avgs << strListAvgs.takeFirst().toDouble(); avgs << strListAvgs.takeFirst().toDouble(); diff --git a/stacer-core/Info/network_info.h b/stacer-core/Info/network_info.h index 0e7945de..a21a1fc6 100644 --- a/stacer-core/Info/network_info.h +++ b/stacer-core/Info/network_info.h @@ -1,9 +1,9 @@ #ifndef NETWORK_INFO_H #define NETWORK_INFO_H +#include #include "Utils/file_util.h" #include "Utils/command_util.h" -#include #include "stacer-core_global.h" diff --git a/stacer-core/Info/process.cpp b/stacer-core/Info/process.cpp index 40a1d7ab..69505285 100644 --- a/stacer-core/Info/process.cpp +++ b/stacer-core/Info/process.cpp @@ -1,10 +1,5 @@ #include "process.h" -Process::Process() -{ - -} - pid_t Process::getPid() const { return pid; diff --git a/stacer-core/Info/process.h b/stacer-core/Info/process.h index 02f54f5c..9f1d69b3 100644 --- a/stacer-core/Info/process.h +++ b/stacer-core/Info/process.h @@ -3,17 +3,11 @@ #include "Utils/file_util.h" -// defines -#define PROC_PID_CMD "/proc/%1/comm" -#define PROC_PID_STATUS "/proc/%1/comm" - #include "stacer-core_global.h" class STACERCORESHARED_EXPORT Process { public: - Process(); - pid_t getPid() const; void setPid(const pid_t &value); diff --git a/stacer-core/Info/system_info.cpp b/stacer-core/Info/system_info.cpp index 40b36d75..41bc9c4d 100644 --- a/stacer-core/Info/system_info.cpp +++ b/stacer-core/Info/system_info.cpp @@ -44,7 +44,7 @@ SystemInfo::SystemInfo() try { if (name.isEmpty()) name = CommandUtil::exec("whoami").trimmed(); - } catch (QString &ex) { + } catch (const QString &ex) { qCritical() << ex; } diff --git a/stacer-core/Info/system_info.h b/stacer-core/Info/system_info.h index b6fa1ba7..a3144f17 100644 --- a/stacer-core/Info/system_info.h +++ b/stacer-core/Info/system_info.h @@ -9,6 +9,7 @@ #define PROC_CPUINFO "/proc/cpuinfo" #include "stacer-core_global.h" + class STACERCORESHARED_EXPORT SystemInfo { public: @@ -21,18 +22,16 @@ class STACERCORESHARED_EXPORT SystemInfo QString getCpuModel() const; QString getCpuSpeed() const; QString getCpuCore() const; + QString getUsername() const; QFileInfoList getCrashReports() const; QFileInfoList getAppLogs() const; QFileInfoList getAppCaches() const; - QString getUsername() const; - private: QString cpuCore; QString cpuModel; QString cpuSpeed; - QString username; }; diff --git a/stacer-core/Tools/apt_source_tool.cpp b/stacer-core/Tools/apt_source_tool.cpp index 8876cddf..bf8e3ef5 100644 --- a/stacer-core/Tools/apt_source_tool.cpp +++ b/stacer-core/Tools/apt_source_tool.cpp @@ -17,6 +17,18 @@ void AptSourceTool::removeAPTSource(const APTSourcePtr aptSource) changeSource(aptSource, ""); } +void AptSourceTool::addRepository(const QString &repository, const bool isSource) +{ + if (! repository.isEmpty()) { + QStringList args = { "-y", repository }; + if (isSource) { + args << "-s"; + } + + CommandUtil::sudoExec("add-apt-repository", args); + } +} + void AptSourceTool::changeSource(const APTSourcePtr aptSource, const QString newSource) { QStringList sourceFileContent = FileUtil::readListFromFile(aptSource->filePath); @@ -32,14 +44,18 @@ void AptSourceTool::changeSource(const APTSourcePtr aptSource, const QString new } if (pos != -1) { - sourceFileContent.replace(pos, newSource); - } + if (newSource.isEmpty()) { + sourceFileContent.removeAt(pos); + } else { + sourceFileContent.replace(pos, newSource); + } - QStringList args = { aptSource->filePath }; + QStringList args = { aptSource->filePath }; - QByteArray data = sourceFileContent.join('\n').append('\n').toUtf8(); + QByteArray data = sourceFileContent.join('\n').append('\n').toUtf8(); - CommandUtil::sudoExec("tee", args, data); + CommandUtil::sudoExec("tee", args, data); + } } void AptSourceTool::changeStatus(const APTSourcePtr aptSource, const bool status) @@ -59,57 +75,46 @@ QList AptSourceTool::getSourceList() { QList aptSourceList; - QDir aptSourceListDir(APT_SOURCES_LIST_D_PATH); - - QFileInfoList infoList = aptSourceListDir.entryInfoList({ "*.list"/*, "*.save"*/ }, - QDir::Files, QDir::Time); + QFileInfoList infoList = QDir(APT_SOURCES_LIST_D_PATH).entryInfoList({"*.list"}, QDir::Files, QDir::Time); infoList.append(QFileInfo(APT_SOURCES_LIST_PATH)); // sources.list + // example "deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main" for (const QFileInfo &info : infoList) { - QStringList fileContent = FileUtil::readListFromFile(info.absoluteFilePath()); + QStringList fileContent = FileUtil::readListFromFile(info.absoluteFilePath()).filter(QRegExp("^\\s{0,}#{0,}\\s{0,}deb")); for (const QString &line : fileContent) { QString _line = line.trimmed(); - if (! _line.isEmpty()) { - - APTSourcePtr aptSource(new APTSource); - aptSource->filePath = info.absoluteFilePath(); + APTSourcePtr aptSource(new APTSource); + aptSource->filePath = info.absoluteFilePath(); - if (_line.startsWith(QChar('#'))) { // is deactive - aptSource->isActive = false; - _line.replace("#", ""); // remove comment - } else { - aptSource->isActive = true; - } + aptSource->isActive = ! _line.startsWith(QChar('#')); - // if has options - if (_line.contains(" [")) { - int pos1 = _line.indexOf('['), pos2 = _line.indexOf(']'); + _line.remove('#'); // remove comment - if (pos1 != -1 && pos2 != -1) { - aptSource->options = _line.mid(pos1, pos2-pos1+1); - _line.replace(aptSource->options, ""); // delete options section - } - } + // if has options + QRegExp regexOption("(\\s[\\[]+.*[\\]]+)"); + regexOption.indexIn(_line); + if (regexOption.matchedLength() > 0) { + aptSource->options = regexOption.cap().trimmed(); + } + // remove options + _line.remove(regexOption); - QStringList sourceColumns = _line.trimmed().split(QRegExp("\\s+")); - bool isBinary = sourceColumns.first() == "deb"; - bool isSource = sourceColumns.first() == "deb-src"; + QStringList sourceColumns = _line.trimmed().split(QRegExp("\\s+")); + bool isBinary = sourceColumns.first() == "deb"; + bool isSource = sourceColumns.first() == "deb-src"; - // example "deb http://packages.microsoft.com/repos/vscode stable main" - if (isBinary || isSource) { - aptSource->isSource = isSource; - aptSource->uri = sourceColumns.at(1); - aptSource->distribution = sourceColumns.at(2); - aptSource->components = sourceColumns.mid(3).join(' '); + if ((isBinary || isSource) && sourceColumns.count() > 2) { + aptSource->isSource = isSource; + aptSource->uri = sourceColumns.at(1); + aptSource->distribution = sourceColumns.at(2); + aptSource->components = sourceColumns.mid(3).join(' '); - aptSource->source = line.trimmed().replace("#", "").trimmed(); -// qDebug() << aptSource->source; + aptSource->source = line.trimmed().remove('#').trimmed(); - aptSourceList.append(aptSource); - } + aptSourceList.append(aptSource); } } } diff --git a/stacer-core/Tools/apt_source_tool.h b/stacer-core/Tools/apt_source_tool.h index 530c53a5..250a9246 100644 --- a/stacer-core/Tools/apt_source_tool.h +++ b/stacer-core/Tools/apt_source_tool.h @@ -34,6 +34,7 @@ class AptSourceTool static void removeAPTSource(const APTSourcePtr aptSource); static void changeStatus(const APTSourcePtr aptSource, const bool status); static void changeSource(const APTSourcePtr aptSource, const QString newSource); + static void addRepository(const QString &repository, const bool isSource); }; #endif // AptSourceTool_H diff --git a/stacer-core/Utils/format_util.cpp b/stacer-core/Utils/format_util.cpp index d16d4491..1ec62296 100644 --- a/stacer-core/Utils/format_util.cpp +++ b/stacer-core/Utils/format_util.cpp @@ -19,6 +19,5 @@ QString FormatUtil::formatBytes(const quint64 &bytes) return formatUnit(bytes, GIBI, "GiB"); else // TiB return formatUnit(bytes, TEBI, "TiB"); - #undef formatUnit } diff --git a/stacer-core/Utils/format_util.h b/stacer-core/Utils/format_util.h index 6e3d4947..53f43c6f 100644 --- a/stacer-core/Utils/format_util.h +++ b/stacer-core/Utils/format_util.h @@ -8,12 +8,11 @@ class STACERCORESHARED_EXPORT FormatUtil public: static QString formatBytes(const quint64 &bytes); -private: - static const quint64 KIBI = 1UL << 10UL; - static const quint64 MEBI = 1UL << 20UL; - static const quint64 GIBI = 1UL << 30UL; - static const quint64 TEBI = 1UL << 40UL; - +public: + static const quint64 KIBI = 1024; + static const quint64 MEBI = 1048576; + static const quint64 GIBI = 1073741824; + static const quint64 TEBI = 1099511627776; }; #endif // FORMAT_UTIL_H diff --git a/stacer-core/stacer-core.pro b/stacer-core/stacer-core.pro index 07d1b4b3..e7592e2a 100644 --- a/stacer-core/stacer-core.pro +++ b/stacer-core/stacer-core.pro @@ -6,6 +6,10 @@ QT -= gui +QT += core network + +CONFIG += c++11 + TARGET = stacer-core TEMPLATE = lib diff --git a/stacer/Managers/app_manager.cpp b/stacer/Managers/app_manager.cpp index 918756ee..4da0ae1c 100644 --- a/stacer/Managers/app_manager.cpp +++ b/stacer/Managers/app_manager.cpp @@ -22,8 +22,8 @@ AppManager::AppManager() loadThemeList(); - if (translator.load(QString("stacer_%1").arg(mSettingManager->getLanguage()), qApp->applicationDirPath() + "/translations")) { - qApp->installTranslator(&translator); + if (mTranslator.load(QString("stacer_%1").arg(mSettingManager->getLanguage()), qApp->applicationDirPath() + "/translations")) { + qApp->installTranslator(&mTranslator); (mSettingManager->getLanguage() == "ar") ? qApp->setLayoutDirection(Qt::RightToLeft) : qApp->setLayoutDirection(Qt::LeftToRight); } else { qCritical() << "Translator could not load."; @@ -37,7 +37,7 @@ QSystemTrayIcon *AppManager::getTrayIcon() QSettings *AppManager::getStyleValues() const { - return styleValues; + return mStyleValues; } void AppManager::loadLanguageList() @@ -49,13 +49,13 @@ void AppManager::loadLanguageList() QJsonObject ob = lanuages.at(i).toObject(); - languageList.insert(ob["value"].toString(), ob["text"].toString()); + mLanguageList.insert(ob["value"].toString(), ob["text"].toString()); } } QMap AppManager::getLanguageList() const { - return languageList; + return mLanguageList; } void AppManager::loadThemeList() @@ -67,33 +67,33 @@ void AppManager::loadThemeList() QJsonObject ob = themes.at(i).toObject(); - themeList.insert(ob["value"].toString(), ob["text"].toString()); + mThemeList.insert(ob["value"].toString(), ob["text"].toString()); } } QMap AppManager::getThemeList() const { - return themeList; + return mThemeList; } void AppManager::updateStylesheet() { QString appThemePath = QString(":/static/themes/%1/style").arg(mSettingManager->getThemeName()); - styleValues = new QSettings(QString("%1/values.ini").arg(appThemePath), QSettings::IniFormat); + mStyleValues = new QSettings(QString("%1/values.ini").arg(appThemePath), QSettings::IniFormat); - stylesheetFileContent = FileUtil::readStringFromFile(QString("%1/style.qss").arg(appThemePath)); + mStylesheetFileContent = FileUtil::readStringFromFile(QString("%1/style.qss").arg(appThemePath)); // set values example: @color01 => #fff - for (const QString &key : styleValues->allKeys()) { - stylesheetFileContent.replace(key, styleValues->value(key).toString()); + for (const QString &key : mStyleValues->allKeys()) { + mStylesheetFileContent.replace(key, mStyleValues->value(key).toString()); } - qApp->setStyleSheet(stylesheetFileContent); + qApp->setStyleSheet(mStylesheetFileContent); - emit SignalMapper::ins()->changedAppTheme(); + emit SignalMapper::ins()->sigChangedAppTheme(); } QString AppManager::getStylesheetFileContent() const { - return stylesheetFileContent; + return mStylesheetFileContent; } diff --git a/stacer/Managers/app_manager.h b/stacer/Managers/app_manager.h index 4162378e..982ab407 100644 --- a/stacer/Managers/app_manager.h +++ b/stacer/Managers/app_manager.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -39,14 +38,14 @@ class AppManager AppManager(); private: - QTranslator translator; + QTranslator mTranslator; QSystemTrayIcon *mTrayIcon; - QSettings *styleValues; + QSettings *mStyleValues; - QMap languageList; - QMap themeList; - QString stylesheetFileContent; + QMap mLanguageList; + QMap mThemeList; + QString mStylesheetFileContent; SettingManager *mSettingManager; }; diff --git a/stacer/Managers/info_manager.cpp b/stacer/Managers/info_manager.cpp index 0abb88a1..1a634cbb 100644 --- a/stacer/Managers/info_manager.cpp +++ b/stacer/Managers/info_manager.cpp @@ -1,13 +1,14 @@ #include "info_manager.h" -InfoManager *InfoManager::_instance = NULL; +InfoManager *InfoManager::instance = nullptr; InfoManager *InfoManager::ins() { - if(_instance == NULL) - _instance = new InfoManager; + if(! instance){ + instance = new InfoManager; + } - return _instance; + return instance; } QString InfoManager::getUserName() const @@ -15,9 +16,9 @@ QString InfoManager::getUserName() const return si.getUsername(); } -/******************** - * CPU INFORMATION - *******************/ +/* + * CPU Provider + */ quint8 InfoManager::getCpuCoreCount() const { return ci.getCpuCoreCount(); @@ -33,9 +34,9 @@ QList InfoManager::getCpuLoadAvgs() const return ci.getLoadAvgs(); } -/******************** - * MEMORY INFORMATION - *******************/ +/* + * Memory Provider + */ void InfoManager::updateMemoryInfo() { mi.updateMemoryInfo(); @@ -61,9 +62,9 @@ quint64 InfoManager::getMemTotal() const return mi.getMemTotal(); } -/******************** - * DISK INFORMATION - *******************/ +/* + * Disk Provider + */ QList InfoManager::getDisks() const { return di.getDisks(); @@ -80,7 +81,7 @@ QList InfoManager::getDiskIO() } /******************** - * NETWORK INFORMATION + * Network Provider *******************/ quint64 InfoManager::getRXbytes() const { @@ -93,7 +94,7 @@ quint64 InfoManager::getTXbytes() const } /******************** - * CLEANER INFORMATION + * System Provider *******************/ QFileInfoList InfoManager::getCrashReports() const { @@ -111,7 +112,7 @@ QFileInfoList InfoManager::getAppCaches() const } /******************** - * PROCESSES INFORMATION + * Process Provider *******************/ void InfoManager::updateProcesses() { diff --git a/stacer/Managers/info_manager.h b/stacer/Managers/info_manager.h index 5d72df04..d7b58d4a 100644 --- a/stacer/Managers/info_manager.h +++ b/stacer/Managers/info_manager.h @@ -10,8 +10,6 @@ #include #include -#include - class InfoManager { public: @@ -41,8 +39,9 @@ class InfoManager void updateProcesses(); QList getProcesses() const; QString getUserName() const; + private: - static InfoManager *_instance; + static InfoManager *instance; private: CpuInfo ci; diff --git a/stacer/Managers/tool_manager.cpp b/stacer/Managers/tool_manager.cpp index 5d8c0fd7..a5c1fb30 100644 --- a/stacer/Managers/tool_manager.cpp +++ b/stacer/Managers/tool_manager.cpp @@ -1,18 +1,19 @@ #include "tool_manager.h" -ToolManager *ToolManager::_instance = NULL; +ToolManager *ToolManager::instance = NULL; ToolManager *ToolManager::ins() { - if(_instance == NULL) - _instance = new ToolManager; + if(! instance) { + instance = new ToolManager; + } - return _instance; + return instance; } -/****************** - * SERVICES - *****************/ +/* + * Services + */ QList ToolManager::getServices() const { return ServiceTool::getServicesWithSystemctl(); @@ -38,9 +39,9 @@ bool ToolManager::serviceIsEnabled(const QString &sname) const return ServiceTool::serviceIsEnabled(sname); } -/****************** - * PACKAGES - *****************/ +/* + * Packages + */ QStringList ToolManager::getPackages() const { switch (PackageTool::currentPackageTool) { @@ -81,8 +82,6 @@ QFileInfoList ToolManager::getPackageCaches() const void ToolManager::uninstallPackages(const QStringList &packages) { - emit uninstallStarted(); - switch (PackageTool::currentPackageTool) { case PackageTool::PackageTools::APT: PackageTool::dpkgRemovePackages(packages); @@ -99,14 +98,11 @@ void ToolManager::uninstallPackages(const QStringList &packages) default: break; } - - emit uninstallFinished(); } -/****************** - * APT SOURCE - *****************/ - +/* + * APT Source + */ bool ToolManager::checkSourceRepository() const { return AptSourceTool::checkSourceRepository(); @@ -122,13 +118,18 @@ void ToolManager::removeAPTSource(const APTSourcePtr source) AptSourceTool::removeAPTSource(source); } -void ToolManager::changeStatus(const APTSourcePtr aptSource, const bool status) +void ToolManager::changeAPTStatus(const APTSourcePtr aptSource, const bool status) { AptSourceTool::changeStatus(aptSource, status); } -void ToolManager::changeSource(const APTSourcePtr aptSource, const QString newSource) +void ToolManager::changeAPTSource(const APTSourcePtr aptSource, const QString newSource) { AptSourceTool::changeSource(aptSource, newSource); } +void ToolManager::addAPTRepository(const QString &repository, const bool isSource) +{ + AptSourceTool::addRepository(repository, isSource); +} + diff --git a/stacer/Managers/tool_manager.h b/stacer/Managers/tool_manager.h index dacea148..af9bd38b 100644 --- a/stacer/Managers/tool_manager.h +++ b/stacer/Managers/tool_manager.h @@ -1,26 +1,19 @@ #ifndef TOOL_MANAGER_H #define TOOL_MANAGER_H -#include -#include - #include #include #include -class ToolManager : public QObject +class ToolManager { - Q_OBJECT - public: static ToolManager *ins(); -public: QList getServices() const; QStringList getPackages() const; QFileInfoList getPackageCaches() const; -public slots: bool changeServiceStatus(const QString &sname, bool status) const; bool changeServiceActive(const QString &sname, bool status) const; bool serviceIsActive(const QString &sname) const; @@ -31,15 +24,12 @@ public slots: bool checkSourceRepository() const; QList getSourceList() const; void removeAPTSource(const APTSourcePtr source); - void changeStatus(const APTSourcePtr aptSource, const bool status); - void changeSource(const APTSourcePtr aptSource, const QString newSource); - -signals: - void uninstallFinished(); - void uninstallStarted(); + void changeAPTStatus(const APTSourcePtr aptSource, const bool status); + void changeAPTSource(const APTSourcePtr aptSource, const QString newSource); + void addAPTRepository(const QString &repository, const bool isSource); private: - static ToolManager *_instance; + static ToolManager *instance; }; #endif // TOOL_MANAGER_H diff --git a/stacer/Pages/AptSourceManager/apt_source_edit.cpp b/stacer/Pages/AptSourceManager/apt_source_edit.cpp index 40809431..29ade1fb 100644 --- a/stacer/Pages/AptSourceManager/apt_source_edit.cpp +++ b/stacer/Pages/AptSourceManager/apt_source_edit.cpp @@ -52,7 +52,8 @@ void APTSourceEdit::clearElements() void APTSourceEdit::on_btnSave_clicked() { - if (! ui->txtUri->text().isEmpty() && ! ui->txtDistribution->text().isEmpty()) + if (! ui->txtUri->text().isEmpty() && + ! ui->txtDistribution->text().isEmpty()) { QString sourceType = ui->radioBinary->isChecked() ? "deb" : "deb-src"; QString updatedAptSource = QString("%1 %2 %3 %4 %5") @@ -62,7 +63,7 @@ void APTSourceEdit::on_btnSave_clicked() .arg(ui->txtDistribution->text()) .arg(ui->txtComponents->text()); - ToolManager::ins()->changeSource(selectedAptSource, updatedAptSource); + ToolManager::ins()->changeAPTSource(selectedAptSource, updatedAptSource); emit saved(); diff --git a/stacer/Pages/AptSourceManager/apt_source_edit.ui b/stacer/Pages/AptSourceManager/apt_source_edit.ui index 5c67f618..1283241a 100644 --- a/stacer/Pages/AptSourceManager/apt_source_edit.ui +++ b/stacer/Pages/AptSourceManager/apt_source_edit.ui @@ -7,7 +7,7 @@ 0 0 452 - 260 + 295 @@ -26,12 +26,9 @@ 15 - + 15 - - 10 - diff --git a/stacer/Pages/AptSourceManager/apt_source_manager_page.cpp b/stacer/Pages/AptSourceManager/apt_source_manager_page.cpp index 3df58f1d..5f11172d 100644 --- a/stacer/Pages/AptSourceManager/apt_source_manager_page.cpp +++ b/stacer/Pages/AptSourceManager/apt_source_manager_page.cpp @@ -22,7 +22,8 @@ APTSourceManagerPage::APTSourceManagerPage(QWidget *parent) : void APTSourceManagerPage::init() { - ui->txtAptSource->setPlaceholderText(tr("example %1").arg("'deb http://archive.ubuntu.com/ubuntu xenial main'")); + ui->txtAptSource->setPlaceholderText(tr("example %1") + .arg("'deb http://archive.ubuntu.com/ubuntu xenial main'")); loadAptSources(); @@ -60,17 +61,11 @@ void APTSourceManagerPage::on_btnAddAPTSourceRepository_clicked(bool checked) if (checked) { ui->btnAddAPTSourceRepository->setText(tr("Save")); changeElementsVisible(checked); - } - else { + } else { QString aptSourceRepository = ui->txtAptSource->text().trimmed(); - if (!aptSourceRepository.isEmpty()) { - QStringList args = { "-y", aptSourceRepository }; - if (ui->checkEnableSource->isChecked()) { - args << "-s"; - } - - CommandUtil::sudoExec("add-apt-repository", args); + if (! aptSourceRepository.isEmpty()) { + ToolManager::ins()->addAPTRepository(aptSourceRepository, ui->checkEnableSource->isChecked()); ui->txtAptSource->clear(); ui->checkEnableSource->setChecked(false); @@ -84,7 +79,7 @@ void APTSourceManagerPage::on_btnCancel_clicked() { ui->btnAddAPTSourceRepository->setChecked(false); changeElementsVisible(false); - ui->btnAddAPTSourceRepository->setText(tr("Add APT Source")); + ui->btnAddAPTSourceRepository->setText(tr("Add APT Repository")); } void APTSourceManagerPage::changeElementsVisible(const bool checked) @@ -94,10 +89,7 @@ void APTSourceManagerPage::changeElementsVisible(const bool checked) ui->btnCancel->setVisible(checked); ui->btnEditAptSource->setVisible(!checked); ui->btnDeleteAptSource->setVisible(!checked); - if (checked) - ui->bottomSectionHorizontalSpacer->changeSize(0, 0, QSizePolicy::Minimum); - else - ui->bottomSectionHorizontalSpacer->changeSize(0, 0, QSizePolicy::Expanding); + ui->bottomSectionHorizontalSpacer->changeSize(0, 0, checked ? QSizePolicy::Minimum : QSizePolicy::Expanding); } void APTSourceManagerPage::on_listWidgetAptSources_itemClicked(QListWidgetItem *item) @@ -141,11 +133,11 @@ void APTSourceManagerPage::on_txtSearchAptSource_textChanged(const QString &val) void APTSourceManagerPage::on_btnEditAptSource_clicked() { if (! selectedAptSource.isNull()) { - if (aptSourceEditDialog.isNull()) { - aptSourceEditDialog = QSharedPointer(new APTSourceEdit(this)); - connect(aptSourceEditDialog.data(), &APTSourceEdit::saved, this, &APTSourceManagerPage::loadAptSources); + if (mAptSourceEditDialog.isNull()) { + mAptSourceEditDialog = QSharedPointer(new APTSourceEdit(this)); + connect(mAptSourceEditDialog.data(), &APTSourceEdit::saved, this, &APTSourceManagerPage::loadAptSources); } APTSourceEdit::selectedAptSource = selectedAptSource; - aptSourceEditDialog->show(); + mAptSourceEditDialog->show(); } } diff --git a/stacer/Pages/AptSourceManager/apt_source_manager_page.h b/stacer/Pages/AptSourceManager/apt_source_manager_page.h index 4142763c..7788ad00 100644 --- a/stacer/Pages/AptSourceManager/apt_source_manager_page.h +++ b/stacer/Pages/AptSourceManager/apt_source_manager_page.h @@ -6,6 +6,7 @@ #include "apt_source_repository_item.h" #include "apt_source_edit.h" +#include "Managers/info_manager.h" namespace Ui { class APTSourceManagerPage; @@ -24,10 +25,10 @@ class APTSourceManagerPage : public QWidget private slots: void loadAptSources(); + void changeElementsVisible(const bool checked); void on_btnAddAPTSourceRepository_clicked(bool checked); void on_listWidgetAptSources_itemClicked(QListWidgetItem *item); void on_listWidgetAptSources_itemDoubleClicked(QListWidgetItem *item); - void changeElementsVisible(const bool checked); void on_txtSearchAptSource_textChanged(const QString &val); void on_btnDeleteAptSource_clicked(); void on_btnEditAptSource_clicked(); @@ -39,7 +40,7 @@ private slots: private: Ui::APTSourceManagerPage *ui; - QSharedPointer aptSourceEditDialog; + QSharedPointer mAptSourceEditDialog; }; #endif diff --git a/stacer/Pages/AptSourceManager/apt_source_repository_item.cpp b/stacer/Pages/AptSourceManager/apt_source_repository_item.cpp index 7908e9b6..1a50e6d6 100644 --- a/stacer/Pages/AptSourceManager/apt_source_repository_item.cpp +++ b/stacer/Pages/AptSourceManager/apt_source_repository_item.cpp @@ -26,14 +26,14 @@ void APTSourceRepositoryItem::init() ui->checkAptSource->setChecked(mAptSource->isActive); // example "deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main" - QString sourceName = mAptSource->source; + QString source = mAptSource->source; - sourceName = sourceName.remove(QRegularExpression("\[.*?\]")); + source.remove(QRegExp("\\s[\\[]+.*[\\]]+")); if (mAptSource->isSource) { - ui->lblAptSourceName->setText(tr("%1 (Source Code)").arg(sourceName)); + ui->lblAptSourceName->setText(tr("%1 (Source Code)").arg(source)); } else { - ui->lblAptSourceName->setText(sourceName); + ui->lblAptSourceName->setText(source); } ui->lblAptSourceName->setToolTip(ui->lblAptSourceName->text()); @@ -46,5 +46,5 @@ APTSourcePtr APTSourceRepositoryItem::aptSource() const void APTSourceRepositoryItem::on_checkAptSource_clicked(bool checked) { - ToolManager::ins()->changeStatus(mAptSource, checked); + ToolManager::ins()->changeAPTStatus(mAptSource, checked); } diff --git a/stacer/Pages/AptSourceManager/apt_source_repository_item.h b/stacer/Pages/AptSourceManager/apt_source_repository_item.h index d035419c..16278828 100644 --- a/stacer/Pages/AptSourceManager/apt_source_repository_item.h +++ b/stacer/Pages/AptSourceManager/apt_source_repository_item.h @@ -2,7 +2,6 @@ #define APTSourceRepositoryItem_H #include -#include #include "Managers/tool_manager.h" namespace Ui { @@ -15,7 +14,6 @@ class APTSourceRepositoryItem : public QWidget public: explicit APTSourceRepositoryItem(APTSourcePtr aptSource, QWidget *parent = 0); - ~APTSourceRepositoryItem(); public: diff --git a/stacer/Pages/Dashboard/circlebar.cpp b/stacer/Pages/Dashboard/circlebar.cpp index 28167612..5e20b3fc 100644 --- a/stacer/Pages/Dashboard/circlebar.cpp +++ b/stacer/Pages/Dashboard/circlebar.cpp @@ -4,16 +4,16 @@ CircleBar::~CircleBar() { delete ui; - delete chart; + delete mChart; } CircleBar::CircleBar(const QString &title, const QStringList &colors, QWidget *parent) : QWidget(parent), ui(new Ui::CircleBar), - colors(colors), - chart(new QChart), - chartView(new QChartView(chart)), - series(new QPieSeries(this)) + mColors(colors), + mChart(new QChart), + mChartView(new QChartView(mChart)), + mSeries(new QPieSeries(this)) { ui->setupUi(this); @@ -27,43 +27,44 @@ void CircleBar::init() QColor transparent("transparent"); // series settings - series->setHoleSize(0.67); - series->setPieSize(165); - series->setPieStartAngle(-115); - series->setPieEndAngle(115); - series->setLabelsVisible(false); - series->append("Used", 0); - series->append("Free", 0); - series->slices().first()->setBorderColor(transparent); - series->slices().last()->setBorderColor(transparent); + mSeries->setHoleSize(0.67); + mSeries->setPieSize(165); + mSeries->setPieStartAngle(-115); + mSeries->setPieEndAngle(115); + mSeries->setLabelsVisible(false); + mSeries->append("Used", 0); + mSeries->append("Free", 0); + mSeries->slices().first()->setBorderColor(transparent); + mSeries->slices().last()->setBorderColor(transparent); QConicalGradient gradient; gradient.setAngle(115); - for (int i = 0; i < colors.count(); ++i) - gradient.setColorAt(i, QColor(colors.at(i))); - series->slices().first()->setBrush(gradient); + for (int i = 0; i < mColors.count(); ++i) { + gradient.setColorAt(i, QColor(mColors.at(i))); + } + mSeries->slices().first()->setBrush(gradient); // chart settings - chart->setBackgroundBrush(QBrush(transparent)); - chart->setContentsMargins(-20, -20, -20, -65); - chart->addSeries(series); - chart->legend()->hide(); + mChart->setBackgroundBrush(QBrush(transparent)); + mChart->setContentsMargins(-20, -20, -20, -65); + mChart->addSeries(mSeries); + mChart->legend()->hide(); // chartview settings - chartView->setRenderHint(QPainter::Antialiasing); + mChartView->setRenderHint(QPainter::Antialiasing); - ui->layoutCircleBar->insertWidget(1, chartView); + ui->layoutCircleBar->insertWidget(1, mChartView); - connect(SignalMapper::ins(), &SignalMapper::changedAppTheme, [=] { + connect(SignalMapper::ins(), &SignalMapper::sigChangedAppTheme, [=] { QSettings *styleValues = AppManager::ins()->getStyleValues(); - chartView->setBackgroundBrush(QColor(styleValues->value("@circleChartBackgroundColor").toString())); - series->slices().last()->setColor(styleValues->value("@pageContent").toString()); // trail color + mChartView->setBackgroundBrush(QColor(styleValues->value("@circleChartBackgroundColor").toString())); + mSeries->slices().last()->setColor(styleValues->value("@pageContent").toString()); // trail color }); } -void CircleBar::setValue(int value, QString valueText) +void CircleBar::setValue(const int &value, const QString &valueText) { - series->slices().first()->setValue(value); - series->slices().last()->setValue(100 - value); + mSeries->slices().first()->setValue(value); + mSeries->slices().last()->setValue(100 - value); ui->lblCircleChartValue->setText(valueText); } diff --git a/stacer/Pages/Dashboard/circlebar.h b/stacer/Pages/Dashboard/circlebar.h index 34fa54ed..807232db 100644 --- a/stacer/Pages/Dashboard/circlebar.h +++ b/stacer/Pages/Dashboard/circlebar.h @@ -19,7 +19,7 @@ class CircleBar : public QWidget ~CircleBar(); public slots: - void setValue(int value, QString valueText); + void setValue(const int &value, const QString &valueText); private slots: void init(); @@ -28,11 +28,11 @@ private slots: Ui::CircleBar *ui; private: - QStringList colors; + QStringList mColors; - QChart *chart; - QChartView *chartView; - QPieSeries *series; + QChart *mChart; + QChartView *mChartView; + QPieSeries *mSeries; }; #endif // CIRCLEBAR_H diff --git a/stacer/Pages/Dashboard/circlebar.ui b/stacer/Pages/Dashboard/circlebar.ui index ee39b323..f2e3a51b 100644 --- a/stacer/Pages/Dashboard/circlebar.ui +++ b/stacer/Pages/Dashboard/circlebar.ui @@ -48,16 +48,16 @@ - 0 + 2 - 0 + 20 10 - 0 + 20 10 diff --git a/stacer/Pages/Dashboard/dashboard_page.cpp b/stacer/Pages/Dashboard/dashboard_page.cpp index 353e070e..a8061994 100644 --- a/stacer/Pages/Dashboard/dashboard_page.cpp +++ b/stacer/Pages/Dashboard/dashboard_page.cpp @@ -11,14 +11,13 @@ DashboardPage::~DashboardPage() DashboardPage::DashboardPage(QWidget *parent) : QWidget(parent), ui(new Ui::DashboardPage), - cpuBar(new CircleBar(tr("CPU"), {"#A8E063", "#56AB2F"}, this)), - memBar(new CircleBar(tr("MEMORY"), {"#FFB75E", "#ED8F03"}, this)), - diskBar(new CircleBar(tr("DISK"), {"#DC2430", "#7B4397"}, this)), - downloadBar(new LineBar(tr("DOWNLOAD"), this)), - uploadBar(new LineBar(tr("UPLOAD"), this)), - timer(new QTimer(this)), + mCpuBar(new CircleBar(tr("CPU"), {"#A8E063", "#56AB2F"}, this)), + mMemBar(new CircleBar(tr("MEMORY"), {"#FFB75E", "#ED8F03"}, this)), + mDiskBar(new CircleBar(tr("DISK"), {"#DC2430", "#7B4397"}, this)), + mDownloadBar(new LineBar(tr("DOWNLOAD"), this)), + mUploadBar(new LineBar(tr("UPLOAD"), this)), + mTimer(new QTimer(this)), im(InfoManager::ins()), - iconTray(QIcon(":/static/logo.png")), mSettingManager(SettingManager::ins()) { ui->setupUi(this); @@ -31,24 +30,24 @@ DashboardPage::DashboardPage(QWidget *parent) : void DashboardPage::init() { // Circle bars - ui->circleBarsLayout->addWidget(cpuBar); - ui->circleBarsLayout->addWidget(memBar); - ui->circleBarsLayout->addWidget(diskBar); + ui->circleBarsLayout->addWidget(mCpuBar); + ui->circleBarsLayout->addWidget(mMemBar); + ui->circleBarsLayout->addWidget(mDiskBar); // line bars - ui->lineBarsLayout->addWidget(downloadBar); - ui->lineBarsLayout->addWidget(uploadBar); + ui->lineBarsLayout->addWidget(mDownloadBar); + ui->lineBarsLayout->addWidget(mUploadBar); // connections - connect(timer, &QTimer::timeout, this, &DashboardPage::updateCpuBar); - connect(timer, &QTimer::timeout, this, &DashboardPage::updateMemoryBar); - connect(timer, &QTimer::timeout, this, &DashboardPage::updateNetworkBar); + connect(mTimer, &QTimer::timeout, this, &DashboardPage::updateCpuBar); + connect(mTimer, &QTimer::timeout, this, &DashboardPage::updateMemoryBar); + connect(mTimer, &QTimer::timeout, this, &DashboardPage::updateNetworkBar); QTimer *timerDisk = new QTimer; connect(timerDisk, &QTimer::timeout, this, &DashboardPage::updateDiskBar); timerDisk->start(5 * 1000); - timer->start(1 * 1000); + mTimer->start(1 * 1000); // initialization updateCpuBar(); @@ -59,11 +58,13 @@ void DashboardPage::init() ui->widgetUpdateBar->hide(); // check update - checkUpdate(); + QtConcurrent::run(this, &DashboardPage::checkUpdate); + connect(this, &DashboardPage::sigShowUpdateBar, ui->widgetUpdateBar, &QWidget::show); QList widgets = { - cpuBar, memBar, diskBar, downloadBar, uploadBar + mCpuBar, mMemBar, mDiskBar, mDownloadBar, mUploadBar }; + Utilities::addDropShadow(widgets, 60); } @@ -72,24 +73,24 @@ void DashboardPage::checkUpdate() QString requestResult; if (CommandUtil::isExecutable("curl")) { - try { + try { requestResult = CommandUtil::exec("curl", { "https://api.github.com/repos/oguzhaninan/Stacer/releases/latest" }); - } catch (QString &ex) { + } catch (const QString &ex) { qCritical() << ex; } if (! requestResult.isEmpty()) { QJsonDocument result = QJsonDocument::fromJson(requestResult.toUtf8()); - QRegExp ex("[0-9].[0-9].[0-9]"); + QRegExp ex("([0-9].[0-9].[0-9])"); ex.indexIn(result.object().value("tag_name").toString()); QString version; - if (! ex.captureCount()) + if (ex.matchedLength() > 0) version = ex.cap(); if (qApp->applicationVersion() != version) { - ui->widgetUpdateBar->show(); + emit sigShowUpdateBar(); } } } @@ -125,20 +126,20 @@ void DashboardPage::updateCpuBar() int cpuUsedPercent = im->getCpuPercents().at(0); // alert message - int maxCpuPercent = mSettingManager->getCpuAlertPercent(); - if (maxCpuPercent > 0) { + int cpuAlerPercent = mSettingManager->getCpuAlertPercent(); + if (cpuAlerPercent > 0) { static bool isShow = true; - if (cpuUsedPercent > maxCpuPercent && isShow) { + if (cpuUsedPercent > cpuAlerPercent && isShow) { AppManager::ins()->getTrayIcon()->showMessage(tr("High CPU Usage"), - tr("The amount of CPU used is over %1%.").arg(maxCpuPercent), - iconTray); + tr("The amount of CPU used is over %1%.").arg(cpuAlerPercent), + QSystemTrayIcon::Warning); isShow = false; - } else if (cpuUsedPercent < maxCpuPercent) { + } else if (cpuUsedPercent < cpuAlerPercent) { isShow = true; } } - cpuBar->setValue(cpuUsedPercent, QString("%1%").arg(cpuUsedPercent)); + mCpuBar->setValue(cpuUsedPercent, QString("%1%").arg(cpuUsedPercent)); } void DashboardPage::updateMemoryBar() @@ -146,27 +147,28 @@ void DashboardPage::updateMemoryBar() im->updateMemoryInfo(); int memUsedPercent = 0; - if (im->getMemTotal()) + if (im->getMemTotal()) { memUsedPercent = ((double)im->getMemUsed() / (double)im->getMemTotal()) * 100.0; + } QString f_memUsed = FormatUtil::formatBytes(im->getMemUsed()); QString f_memTotal = FormatUtil::formatBytes(im->getMemTotal()); // alert message - int maxMemoryPercent = mSettingManager->getMemoryAlertPercent(); - if (maxMemoryPercent > 0) { + int memoryAlertPercent = mSettingManager->getMemoryAlertPercent(); + if (memoryAlertPercent > 0) { static bool isShow = true; - if (memUsedPercent > maxMemoryPercent && isShow) { + if (memUsedPercent > memoryAlertPercent && isShow) { AppManager::ins()->getTrayIcon()->showMessage(tr("High Memory Usage"), - tr("The amount of memory used is over %1%.").arg(maxMemoryPercent), - iconTray); + tr("The amount of memory used is over %1%.").arg(memoryAlertPercent), + QSystemTrayIcon::Warning); isShow = false; - } else if (memUsedPercent < maxMemoryPercent) { + } else if (memUsedPercent < memoryAlertPercent) { isShow = true; } } - memBar->setValue(memUsedPercent, QString("%1 / %2") + mMemBar->setValue(memUsedPercent, QString("%1 / %2") .arg(f_memUsed) .arg(f_memTotal)); } @@ -183,33 +185,33 @@ void DashboardPage::updateDiskBar() disk = d; } - if (disk == nullptr) { + if (! disk) { disk = im->getDisks().at(0); } - QString sizeText = FormatUtil::formatBytes(disk->size); - QString usedText = FormatUtil::formatBytes(disk->used); - int diskPercent = 0; if (disk->size > 0) { diskPercent = ((double) disk->used / (double) disk->size) * 100.0; } // alert message - int maxDiskPercent = mSettingManager->getDiskAlertPercent(); - if (maxDiskPercent > 0) { + int diskAlertPercent = mSettingManager->getDiskAlertPercent(); + if (diskAlertPercent > 0) { static bool isShow = true; - if (diskPercent > maxDiskPercent && isShow) { + if (diskPercent > diskAlertPercent && isShow) { AppManager::ins()->getTrayIcon()->showMessage(tr("High Disk Usage"), - tr("The amount of disk used is over %1%.").arg(diskPercent), - iconTray); + tr("The amount of disk used is over %1%.").arg(diskAlertPercent), + QSystemTrayIcon::Warning); isShow = false; - } else if (diskPercent < maxDiskPercent) { + } else if (diskPercent < diskAlertPercent) { isShow = true; } } - diskBar->setValue(diskPercent, QString("%1 / %2") + QString sizeText = FormatUtil::formatBytes(disk->size); + QString usedText = FormatUtil::formatBytes(disk->used); + + mDiskBar->setValue(diskPercent, QString("%1 / %2") .arg(usedText) .arg(sizeText)); } @@ -234,11 +236,11 @@ void DashboardPage::updateNetworkBar() int downPercent = ((double) d_RXbytes / (double) max_RXbytes) * 100.0; int upPercent = ((double) d_TXbytes / (double) max_TXbytes) * 100.0; - downloadBar->setValue(downPercent, + mDownloadBar->setValue(downPercent, QString("%1/s").arg(downText), tr("Total: %1").arg(FormatUtil::formatBytes(RXbytes))); - uploadBar->setValue(upPercent, + mUploadBar->setValue(upPercent, QString("%1/s").arg(upText), tr("Total: %1").arg(FormatUtil::formatBytes(TXbytes))); diff --git a/stacer/Pages/Dashboard/dashboard_page.h b/stacer/Pages/Dashboard/dashboard_page.h index 5ab922b7..c037308f 100644 --- a/stacer/Pages/Dashboard/dashboard_page.h +++ b/stacer/Pages/Dashboard/dashboard_page.h @@ -9,7 +9,7 @@ #include #include -#include +#include "Managers/info_manager.h" #include "circlebar.h" #include "linebar.h" @@ -39,22 +39,23 @@ private slots: void on_btnDownloadUpdate_clicked(); +signals: + void sigShowUpdateBar(); + private: Ui::DashboardPage *ui; private: - CircleBar* cpuBar; - CircleBar* memBar; - CircleBar* diskBar; + CircleBar* mCpuBar; + CircleBar* mMemBar; + CircleBar* mDiskBar; - LineBar *downloadBar; - LineBar *uploadBar; + LineBar *mDownloadBar; + LineBar *mUploadBar; - QTimer *timer; + QTimer *mTimer; InfoManager *im; - QIcon iconTray; - SettingManager *mSettingManager; }; diff --git a/stacer/Pages/Dashboard/dashboard_page.ui b/stacer/Pages/Dashboard/dashboard_page.ui index da93adfd..0dd6a332 100644 --- a/stacer/Pages/Dashboard/dashboard_page.ui +++ b/stacer/Pages/Dashboard/dashboard_page.ui @@ -30,7 +30,7 @@ 5 - 10 + 5 0 diff --git a/stacer/Pages/Dashboard/linebar.h b/stacer/Pages/Dashboard/linebar.h index 57eec863..a5ec98db 100644 --- a/stacer/Pages/Dashboard/linebar.h +++ b/stacer/Pages/Dashboard/linebar.h @@ -17,6 +17,7 @@ class LineBar : public QWidget public slots: void setValue(const int &value, const QString &text, const QString &totalText); + private: Ui::LineBar *ui; }; diff --git a/stacer/Pages/GnomeSettings/gnome_settings_page.h b/stacer/Pages/GnomeSettings/gnome_settings_page.h index 057264b7..e270462a 100644 --- a/stacer/Pages/GnomeSettings/gnome_settings_page.h +++ b/stacer/Pages/GnomeSettings/gnome_settings_page.h @@ -2,14 +2,12 @@ #define GNOME_SETTINGS_PAGE_H #include -#include "slidingstackedwidget.h" +#include "sliding_stacked_widget.h" #include "unity_settings.h" #include "window_manager_settings.h" #include "appearance_settings.h" -#include "gnome_settings_page.h" - namespace Ui { class GnomeSettingsPage; } diff --git a/stacer/Pages/Processes/processes_page.cpp b/stacer/Pages/Processes/processes_page.cpp index 7c0a7501..9e95f648 100644 --- a/stacer/Pages/Processes/processes_page.cpp +++ b/stacer/Pages/Processes/processes_page.cpp @@ -10,13 +10,10 @@ ProcessesPage::~ProcessesPage() ProcessesPage::ProcessesPage(QWidget *parent) : QWidget(parent), ui(new Ui::ProcessesPage), - model(new QStandardItemModel(this)), - sortModel(new QSortFilterProxyModel(this)), - headers{"PID", tr("Resident Memory"), tr("%Memory"), tr("Virtual Memory"), - tr("User"), "%CPU", tr("Start Time"), tr("State"), tr("Group"), - tr("Nice"), tr("CPU Time"), tr("Session"), tr("Process")}, + mItemModel(new QStandardItemModel(this)), + mSortFilterModel(new QSortFilterProxyModel(this)), im(InfoManager::ins()), - timer(new QTimer(this)) + mTimer(new QTimer(this)) { ui->setupUi(this); @@ -24,21 +21,27 @@ ProcessesPage::ProcessesPage(QWidget *parent) : } void ProcessesPage::init() -{ +{ + mHeaders = QStringList { + "PID", tr("Resident Memory"), tr("%Memory"), tr("Virtual Memory"), + tr("User"), "%CPU", tr("Start Time"), tr("State"), tr("Group"), + tr("Nice"), tr("CPU Time"), tr("Session"), tr("Process") + }; + // slider settings ui->sliderRefresh->setRange(1, 10); ui->sliderRefresh->setPageStep(1); ui->sliderRefresh->setSingleStep(1); // Table settings - sortModel->setSourceModel(model); + mSortFilterModel->setSourceModel(mItemModel); - model->setHorizontalHeaderLabels(headers); + mItemModel->setHorizontalHeaderLabels(mHeaders); - ui->tableProcess->setModel(sortModel); - sortModel->setSortRole(1); - sortModel->setDynamicSortFilter(true); - sortModel->sort(5, Qt::SortOrder::DescendingOrder); + ui->tableProcess->setModel(mSortFilterModel); + mSortFilterModel->setSortRole(1); + mSortFilterModel->setDynamicSortFilter(true); + mSortFilterModel->sort(5, Qt::SortOrder::DescendingOrder); ui->tableProcess->horizontalHeader()->setSectionsMovable(true); ui->tableProcess->horizontalHeader()->setFixedHeight(36); @@ -49,9 +52,9 @@ void ProcessesPage::init() loadProcesses(); - connect(timer, &QTimer::timeout, this, &ProcessesPage::loadProcesses); - timer->setInterval(1000); - timer->start(); + connect(mTimer, &QTimer::timeout, this, &ProcessesPage::loadProcesses); + mTimer->setInterval(1000); + mTimer->start(); ui->tableProcess->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu); @@ -67,22 +70,22 @@ void ProcessesPage::init() void ProcessesPage::loadHeaderMenu() { int i = 0; - for (const QString &header : headers) { + for (const QString &header : mHeaders) { QAction *action = new QAction(header); action->setCheckable(true); action->setChecked(true); action->setData(i++); - headerMenu.addAction(action); + mHeaderMenu.addAction(action); } // exclude headers -#define ex(n) headers.indexOf(n) +#define ex(n) mHeaders.indexOf(n) QList hiddenHeaders = { ex("Start Time"), ex("State"), ex("Group"), ex("Nice"), ex("CPU Time"), ex("Session"), ex("Virtual Memory") }; #undef ex - QList actions = headerMenu.actions(); + QList actions = mHeaderMenu.actions(); for (const int i : hiddenHeaders) { ui->tableProcess->horizontalHeader()->setSectionHidden(i, true); actions.at(i)->setChecked(false); @@ -91,37 +94,41 @@ void ProcessesPage::loadHeaderMenu() void ProcessesPage::loadProcesses() { - QModelIndexList selecteds = ui->tableProcess->selectionModel()->selectedRows(); + QModelIndexList selecteds = ui->tableProcess->selectionModel()->selectedRows(); - model->removeRows(0, model->rowCount()); + mItemModel->removeRows(0, mItemModel->rowCount()); im->updateProcesses(); QList processes = im->getProcesses(); QString username = im->getUserName(); - for (const Process &proc : processes) { - if (ui->checkAllProcesses->isChecked()) { - model->appendRow(createRow(proc)); + + if (ui->checkAllProcesses->isChecked()) { + for (const Process &proc : processes) { + mItemModel->appendRow(createRow(proc)); } - else { - if (username == proc.getUname()) - model->appendRow(createRow(proc)); + } else { + for (const Process &proc : processes) { + if (username == proc.getUname()) { + mItemModel->appendRow(createRow(proc)); + } } } - ui->lblProcessTitle->setText(tr("Processes (%1)").arg(model->rowCount())); + ui->lblProcessTitle->setText(tr("Processes (%1)").arg(mItemModel->rowCount())); // selected item if(! selecteds.isEmpty()) { - seletedRowModel = selecteds.first(); + mSeletedRowModel = selecteds.first(); - for (int i = 0; i < sortModel->rowCount(); ++i) { - if (sortModel->index(i, 0).data(1).toInt() == seletedRowModel.data(1).toInt()) + for (int i = 0; i < mSortFilterModel->rowCount(); ++i) { + if (mSortFilterModel->index(i, 0).data(1).toInt() == mSeletedRowModel.data(1).toInt()) { ui->tableProcess->selectRow(i); + } } } else { - seletedRowModel = QModelIndex(); + mSeletedRowModel = QModelIndex(); } } @@ -194,31 +201,32 @@ void ProcessesPage::on_txtProcessSearch_textChanged(const QString &val) { QRegExp query(val, Qt::CaseInsensitive, QRegExp::Wildcard); - sortModel->setFilterKeyColumn(headers.count() - 1); // process name - sortModel->setFilterRegExp(query); + mSortFilterModel->setFilterKeyColumn(mHeaders.count() - 1); // process name + mSortFilterModel->setFilterRegExp(query); } void ProcessesPage::on_sliderRefresh_valueChanged(const int &i) { ui->lblRefresh->setText(tr("Refresh (%1)").arg(i)); - timer->setInterval(i * 1000); + mTimer->setInterval(i * 1000); } void ProcessesPage::on_btnEndProcess_clicked() { - pid_t pid = seletedRowModel.data(1).toInt(); + pid_t pid = mSeletedRowModel.data(1).toInt(); - QString selectedUname = sortModel->index(seletedRowModel.row(), 4).data(1).toString(); + if (pid) { + QString selectedUname = mSortFilterModel->index(mSeletedRowModel.row(), 4).data(1).toString(); - try { - if (pid) { - if (selectedUname == im->getUserName()) + try { + if (selectedUname == im->getUserName()) { CommandUtil::exec("kill", { QString::number(pid) }); - else + } else { CommandUtil::sudoExec("kill", { QString::number(pid) }); + } + } catch (QString &ex) { + qCritical() << ex; } - } catch (QString &ex) { - qCritical() << ex; } } @@ -226,9 +234,9 @@ void ProcessesPage::on_tableProcess_customContextMenuRequested(const QPoint &pos { QPoint globalPos = ui->tableProcess->mapToGlobal(pos); - QAction *action = headerMenu.exec(globalPos); + QAction *action = mHeaderMenu.exec(globalPos); - if (action) - ui->tableProcess->horizontalHeader()->setSectionHidden(action->data().toInt(), - ! action->isChecked()); + if (action) { + ui->tableProcess->horizontalHeader()->setSectionHidden(action->data().toInt(), ! action->isChecked()); + } } diff --git a/stacer/Pages/Processes/processes_page.h b/stacer/Pages/Processes/processes_page.h index 2495e034..5371f095 100644 --- a/stacer/Pages/Processes/processes_page.h +++ b/stacer/Pages/Processes/processes_page.h @@ -27,24 +27,23 @@ class ProcessesPage : public QWidget private slots: void init(); void loadProcesses(); + void loadHeaderMenu(); QList createRow(const Process &proc); void on_txtProcessSearch_textChanged(const QString &val); void on_sliderRefresh_valueChanged(const int &i); void on_btnEndProcess_clicked(); void on_tableProcess_customContextMenuRequested(const QPoint &pos); - void loadHeaderMenu(); private: Ui::ProcessesPage *ui; -private: - QStandardItemModel *model; - QSortFilterProxyModel *sortModel; - QModelIndex seletedRowModel; - QStringList headers; + QStandardItemModel *mItemModel; + QSortFilterProxyModel *mSortFilterModel; + QModelIndex mSeletedRowModel; + QStringList mHeaders; + QMenu mHeaderMenu; + QTimer *mTimer; InfoManager *im; - QTimer *timer; - QMenu headerMenu; }; #endif // PROCESSESPAGE_H diff --git a/stacer/Pages/Resources/history_chart.cpp b/stacer/Pages/Resources/history_chart.cpp index f6a1b57e..fd27df07 100644 --- a/stacer/Pages/Resources/history_chart.cpp +++ b/stacer/Pages/Resources/history_chart.cpp @@ -9,35 +9,35 @@ HistoryChart::~HistoryChart() HistoryChart::HistoryChart(const QString &title, const int &seriesCount, QCategoryAxis* categoriAxisY, QWidget *parent) : QWidget(parent), ui(new Ui::HistoryChart), - title(title), - seriesCount(seriesCount), - chartView(new QChartView(this)), - chart(chartView->chart()) + mTitle(title), + mSeriesCount(seriesCount), + mChartView(new QChartView(this)), + mChart(mChartView->chart()) { ui->setupUi(this); init(); if (categoriAxisY) { - axisY = categoriAxisY; - axisY->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue); + mAxisY = categoriAxisY; + mAxisY->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue); for (int i = 0; i < seriesCount; ++i) { - chart->setAxisY(axisY, chart->series().at(i)); + mChart->setAxisY(mAxisY, mSeriesList.at(i)); } } } void HistoryChart::init() { - ui->lblHistoryTitle->setText(title); + ui->lblHistoryTitle->setText(mTitle); // add series to chart - for (int i = 0; i < seriesCount; i++) { + for (int i = 0; i < mSeriesCount; i++) { mSeriesList.append(new QSplineSeries); - chart->addSeries(mSeriesList.at(i)); + mChart->addSeries(mSeriesList.at(i)); } - chartView->setRenderHint(QPainter::Antialiasing); + mChartView->setRenderHint(QPainter::Antialiasing); QList colors = { 0x2ecc71, 0xe74c3c, 0x3498db, 0xf1c40f, 0xe67e22, @@ -46,19 +46,19 @@ void HistoryChart::init() 0x5499C7, 0x58D68D, 0xCD6155, 0xF5B041, 0x566573 }; // set colors - for (int i = 0; i < chart->series().count(); ++i) { - dynamic_cast(chart->series().at(i))->setColor(QColor(colors.at(i))); + for (int i = 0; i < mSeriesList.count(); ++i) { + dynamic_cast(mChart->series().at(i))->setColor(QColor(colors.at(i))); } // Chart Settings - chart->createDefaultAxes(); + mChart->createDefaultAxes(); - chart->axisX()->setRange(0, 60); - chart->axisX()->setReverse(true); + mChart->axisX()->setRange(0, 60); + mChart->axisX()->setReverse(true); - chart->setContentsMargins(-11, -11, -11, -11); - chart->setMargins(QMargins(20, 0, 10, 10)); - ui->layoutHistoryChart->addWidget(chartView, 1, 0, 1, 3); + mChart->setContentsMargins(-11, -11, -11, -11); + mChart->setMargins(QMargins(20, 0, 10, 10)); + ui->layoutHistoryChart->addWidget(mChartView, 1, 0, 1, 3); // theme changed connect(SignalMapper::ins(), &SignalMapper::sigChangedAppTheme, [=] { @@ -66,36 +66,36 @@ void HistoryChart::init() QString chartGridColor = AppManager::ins()->getStyleValues()->value("@chartGridColor").toString(); QString historyChartBackground = AppManager::ins()->getStyleValues()->value("@historyChartBackgroundColor").toString(); - chart->axisX()->setLabelsColor(chartLabelColor); - chart->axisX()->setGridLineColor(chartGridColor); + mChart->axisX()->setLabelsColor(chartLabelColor); + mChart->axisX()->setGridLineColor(chartGridColor); - chart->axisY()->setLabelsColor(chartLabelColor); - chart->axisY()->setGridLineColor(chartGridColor); + mChart->axisY()->setLabelsColor(chartLabelColor); + mChart->axisY()->setGridLineColor(chartGridColor); - chart->setBackgroundBrush(QColor(historyChartBackground)); - chart->legend()->setLabelColor(chartLabelColor); + mChart->setBackgroundBrush(QColor(historyChartBackground)); + mChart->legend()->setLabelColor(chartLabelColor); }); } void HistoryChart::setYMax(const int &value) { - chart->axisY()->setRange(0, value); + mChart->axisY()->setRange(0, value); } QCategoryAxis *HistoryChart::getAxisY() { - return axisY; + return mAxisY; } void HistoryChart::setCategoryAxisYLabels() { - if (axisY) { - for (const QString &label : axisY->categoriesLabels()){ - axisY->remove(label); + if (mAxisY) { + for (const QString &label : mAxisY->categoriesLabels()){ + mAxisY->remove(label); } for (int i = 1; i < 5; ++i) { - axisY->append(FormatUtil::formatBytes((axisY->max()/4)*i), (axisY->max()/4)*i); + mAxisY->append(FormatUtil::formatBytes((mAxisY->max()/4)*i), (mAxisY->max()/4)*i); } } } @@ -108,10 +108,10 @@ QVector HistoryChart::getSeriesList() const void HistoryChart::setSeriesList(const QVector &seriesList) { for (int i = 0; i < seriesList.count(); ++i) { - chart->series().replace(0, seriesList.at(i)); + mChart->series().replace(0, seriesList.at(i)); } - chartView->repaint(); + mChartView->repaint(); } void HistoryChart::on_checkHistoryTitle_clicked(bool checked) diff --git a/stacer/Pages/Resources/history_chart.h b/stacer/Pages/Resources/history_chart.h index 046339d2..e54864b0 100644 --- a/stacer/Pages/Resources/history_chart.h +++ b/stacer/Pages/Resources/history_chart.h @@ -23,27 +23,26 @@ class HistoryChart : public QWidget QVector getSeriesList() const; QCategoryAxis *getAxisY(); - -public slots: void setYMax(const int &value); void setSeriesList(const QVector &seriesList); void setCategoryAxisYLabels(); private slots: - void init(); void on_checkHistoryTitle_clicked(bool checked); private: - Ui::HistoryChart *ui; + void init(); private: - QString title; - int seriesCount; - QChartView *chartView; - QChart *chart; + Ui::HistoryChart *ui; + + QString mTitle; + int mSeriesCount; + QChartView *mChartView; + QChart *mChart; QVector mSeriesList; - QCategoryAxis *axisY; + QCategoryAxis *mAxisY; }; #endif // HISTORYCHART_H diff --git a/stacer/Pages/Services/service_item.cpp b/stacer/Pages/Services/service_item.cpp index af70b5d6..11855107 100644 --- a/stacer/Pages/Services/service_item.cpp +++ b/stacer/Pages/Services/service_item.cpp @@ -7,7 +7,11 @@ ServiceItem::~ServiceItem() delete ui; } -ServiceItem::ServiceItem(const QString &name, const QString description, const bool status, const bool active, QWidget *parent) : +ServiceItem::ServiceItem(const QString &name, + const QString description, + const bool status, + const bool active, + QWidget *parent) : QWidget(parent), ui(new Ui::ServiceItem), tm(ToolManager::ins()) @@ -27,7 +31,7 @@ ServiceItem::ServiceItem(const QString &name, const QString description, const b void ServiceItem::on_checkServiceStartup_clicked(bool status) { - auto name = ui->lblServiceName->text(); + QString name = ui->lblServiceName->text(); tm->changeServiceStatus(name, status); @@ -36,7 +40,7 @@ void ServiceItem::on_checkServiceStartup_clicked(bool status) void ServiceItem::on_checkServiceRunning_clicked(bool status) { - auto name = ui->lblServiceName->text(); + QString name = ui->lblServiceName->text(); tm->changeServiceActive(name, status); diff --git a/stacer/Pages/Services/services_page.cpp b/stacer/Pages/Services/services_page.cpp index e7dcb3da..de30116b 100644 --- a/stacer/Pages/Services/services_page.cpp +++ b/stacer/Pages/Services/services_page.cpp @@ -64,14 +64,10 @@ void ServicesPage::loadServices() setServiceCount(); - if(ui->listWidgetServices->count() > 0) { - ui->listWidgetServices->show(); - ui->notFoundWidget->hide(); - } - else { // list widget is empty show not found - ui->notFoundWidget->show(); - ui->listWidgetServices->hide(); - } + bool isListEmpty = ui->listWidgetServices->count() == 0; + + ui->listWidgetServices->setVisible(! isListEmpty); + ui->notFoundWidget->setVisible(isListEmpty); } void ServicesPage::setServiceCount() diff --git a/stacer/Pages/Settings/settings_page.cpp b/stacer/Pages/Settings/settings_page.cpp index ba8dc126..e1d75967 100644 --- a/stacer/Pages/Settings/settings_page.cpp +++ b/stacer/Pages/Settings/settings_page.cpp @@ -57,12 +57,12 @@ void SettingsPage::init() ui->cmbDisks->setCurrentIndex(ui->cmbDisks->findData(dk)); // start on boot - startupAppPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).append("/autostart"); - startupAppPath.append("/stacer.desktop"); + mStartupAppPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).append("/autostart"); + mStartupAppPath.append("/stacer.desktop"); - QFile startupAppFile(startupAppPath); + QFile startupAppFile(mStartupAppPath); if (startupAppFile.exists()) { - QStringList appContent = FileUtil::readListFromFile(startupAppPath); + QStringList appContent = FileUtil::readListFromFile(mStartupAppPath); QString isHidden = Utilities::getDesktopValue(QRegExp("^Hidden=.*"), appContent).toLower(); ui->checkAutostart->setChecked(isHidden == "false"); } else { @@ -125,14 +125,14 @@ void SettingsPage::on_checkAutostart_clicked(bool checked) QString appTemplate = QString("[Desktop Entry]\n" "Name=Stacer\n" "Comment=Linux System Optimizer and Monitoring\n" - "Exec=/usr/share/stacer/stacer --hide \n" + "Exec=stacer --hide \n" "Type=Application\n" "Terminal=false\n" "Hidden=false\n"); - FileUtil::writeFile(startupAppPath, appTemplate); + FileUtil::writeFile(mStartupAppPath, appTemplate); } else { - QFile::remove(startupAppPath); + QFile::remove(mStartupAppPath); } } diff --git a/stacer/Pages/Settings/settings_page.h b/stacer/Pages/Settings/settings_page.h index 3e185430..3fdc3bf4 100644 --- a/stacer/Pages/Settings/settings_page.h +++ b/stacer/Pages/Settings/settings_page.h @@ -39,7 +39,7 @@ private slots: private: AppManager *apm; - QString startupAppPath; + QString mStartupAppPath; SettingManager *mSettingManager; }; diff --git a/stacer/Pages/StartupApps/startup_app.cpp b/stacer/Pages/StartupApps/startup_app.cpp index 303d15c0..4daa1bbc 100644 --- a/stacer/Pages/StartupApps/startup_app.cpp +++ b/stacer/Pages/StartupApps/startup_app.cpp @@ -7,16 +7,16 @@ StartupApp::~StartupApp() delete ui; } -StartupApp::StartupApp(const QString &lblStartupAppName, bool enabled, const QString &filePath, QWidget *parent) : +StartupApp::StartupApp(const QString &startupAppName, bool enabled, const QString &filePath, QWidget *parent) : QWidget(parent), ui(new Ui::StartupApp), - lblStartupAppName(lblStartupAppName), - enabled(enabled), - filePath(filePath) + mStartupAppName(startupAppName), + mEnabled(enabled), + mFilePath(filePath) { ui->setupUi(this); - ui->lblStartupAppName->setText(lblStartupAppName); + ui->lblStartupAppName->setText(startupAppName); ui->checkStartup->setChecked(enabled); Utilities::addDropShadow(this, 50); @@ -24,7 +24,7 @@ StartupApp::StartupApp(const QString &lblStartupAppName, bool enabled, const QSt void StartupApp::on_checkStartup_clicked(bool status) { - QStringList lines = FileUtil::readListFromFile(filePath); + QStringList lines = FileUtil::readListFromFile(mFilePath); // Hidden=[true|false] int pos = lines.indexOf(HIDDEN_REG); @@ -47,47 +47,48 @@ void StartupApp::on_checkStartup_clicked(bool status) lines.append(QString("Hidden=%1").arg(_status)); } - FileUtil::writeFile(filePath, lines.join('\n').append('\n')); + FileUtil::writeFile(mFilePath, lines.join('\n').append('\n')); } void StartupApp::on_btnDeleteStartupApp_clicked() { - if(QFile::remove(filePath)) + if (QFile::remove(mFilePath)) { emit deleteAppS(); + } } void StartupApp::on_btnEditStartupApp_clicked() { - emit editStartupAppS(filePath); + emit editStartupAppS(mFilePath); } QString StartupApp::getAppName() const { - return lblStartupAppName; + return mStartupAppName; } void StartupApp::setAppName(const QString &value) { - lblStartupAppName = value; + mStartupAppName = value; } bool StartupApp::getEnabled() const { - return enabled; + return mEnabled; } void StartupApp::setEnabled(bool value) { - enabled = value; + mEnabled = value; } QString StartupApp::getFilePath() const { - return filePath; + return mFilePath; } void StartupApp::setFilePath(const QString &value) { - filePath = value; + mFilePath = value; } diff --git a/stacer/Pages/StartupApps/startup_app.h b/stacer/Pages/StartupApps/startup_app.h index e59fb15e..c5bbbd62 100644 --- a/stacer/Pages/StartupApps/startup_app.h +++ b/stacer/Pages/StartupApps/startup_app.h @@ -17,7 +17,7 @@ class StartupApp : public QWidget Q_OBJECT public: - explicit StartupApp(const QString &lblStartupAppName, bool enabled, const QString &filePath, QWidget *parent = 0); + explicit StartupApp(const QString &startupAppName, bool enabled, const QString &filePath, QWidget *parent = 0); ~StartupApp(); QString getAppName() const; @@ -42,10 +42,10 @@ private slots: Ui::StartupApp *ui; private: - QString lblStartupAppName; - QString appComment; - bool enabled; - QString filePath; + QString mStartupAppName; + QString mAppComment; + bool mEnabled; + QString mFilePath; }; #endif // STARTUP_APP_H diff --git a/stacer/Pages/StartupApps/startup_app_edit.cpp b/stacer/Pages/StartupApps/startup_app_edit.cpp index 2b410ea8..b6096c36 100644 --- a/stacer/Pages/StartupApps/startup_app_edit.cpp +++ b/stacer/Pages/StartupApps/startup_app_edit.cpp @@ -1,6 +1,7 @@ #include "startup_app_edit.h" #include "ui_startup_app_edit.h" #include "utilities.h" +#include StartupAppEdit::~StartupAppEdit() { @@ -12,7 +13,7 @@ QString StartupAppEdit::selectedFilePath = ""; StartupAppEdit::StartupAppEdit(QWidget *parent) : QDialog(parent), ui(new Ui::StartupAppEdit), - newAppTemplate("[Desktop Entry]\n" + mNewAppTemplate("[Desktop Entry]\n" "Name=%1\n" "Comment=%2\n" "Exec=%3\n" @@ -28,14 +29,11 @@ StartupAppEdit::StartupAppEdit(QWidget *parent) : void StartupAppEdit::init() { setGeometry( - QStyle::alignedRect( - Qt::LeftToRight, - Qt::AlignCenter, - size(), - qApp->desktop()->availableGeometry()) + QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, + size(), qApp->desktop()->availableGeometry()) ); - this->autostartPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/autostart"; + mAutostartPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/autostart"; ui->lblErrorMsg->hide(); @@ -90,17 +88,20 @@ void StartupAppEdit::on_btnSave_clicked() } else { // new file content - QString appContent = newAppTemplate + QString appContent = mNewAppTemplate .arg(ui->txtStartupAppName->text()) .arg(ui->txtStartupAppComment->text()) .arg(ui->txtStartupAppCommand->text()); // file name QString appFileName = ui->txtStartupAppName->text() - .replace(" ", "_") - .replace(QRegExp("\\W+"), ""); + .simplified() + .replace(' ', '-') + .toLower(); - QString path = QString("%1/%2.desktop").arg(autostartPath).arg(appFileName); + qDebug() << appFileName; + + QString path = QString("%1/%2.desktop").arg(mAutostartPath).arg(appFileName); FileUtil::writeFile(path, appContent); } diff --git a/stacer/Pages/StartupApps/startup_app_edit.h b/stacer/Pages/StartupApps/startup_app_edit.h index 58687ae0..1cea45cb 100644 --- a/stacer/Pages/StartupApps/startup_app_edit.h +++ b/stacer/Pages/StartupApps/startup_app_edit.h @@ -43,8 +43,8 @@ private slots: Ui::StartupAppEdit *ui; private: - QString newAppTemplate; - QString autostartPath; + QString mNewAppTemplate; + QString mAutostartPath; }; #endif // STARTUP_APP_EDIT_H diff --git a/stacer/Pages/StartupApps/startup_app_edit.ui b/stacer/Pages/StartupApps/startup_app_edit.ui index 1fbe7e4f..9a6e3c73 100644 --- a/stacer/Pages/StartupApps/startup_app_edit.ui +++ b/stacer/Pages/StartupApps/startup_app_edit.ui @@ -7,13 +7,13 @@ 0 0 380 - 260 + 227 380 - 260 + 0 @@ -33,11 +33,32 @@ 30 - 5 + 15 15 + + + + Fields cannot be left blank. + + + + + + + App Name + + + + + + + App Comment + + + @@ -57,35 +78,7 @@ - - - - Fields cannot be left blank. - - - - - - - App Comment - - - - - - - App Name - - - - - - - Command - - - - + dialog-title @@ -98,7 +91,14 @@ - + + + + Command + + + + Qt::Vertical @@ -106,7 +106,7 @@ 20 - 0 + 40 diff --git a/stacer/Pages/StartupApps/startup_apps_page.cpp b/stacer/Pages/StartupApps/startup_apps_page.cpp index 65347cbc..4beee547 100644 --- a/stacer/Pages/StartupApps/startup_apps_page.cpp +++ b/stacer/Pages/StartupApps/startup_apps_page.cpp @@ -19,12 +19,12 @@ StartupAppsPage::StartupAppsPage(QWidget *parent) : void StartupAppsPage::init() { - this->mAutostartPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).append("/autostart"); - if (! QDir(this->mAutostartPath).exists()) { - QDir().mkdir(this->mAutostartPath); + mAutostartPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).append("/autostart/"); + if (! QDir(mAutostartPath).exists()) { + QDir().mkdir(mAutostartPath); } - mFileSystemWatcher.addPath(this->mAutostartPath); + mFileSystemWatcher.addPath(mAutostartPath); loadApps(); @@ -86,7 +86,7 @@ void StartupAppsPage::setAppCount() int count = ui->listWidgetStartup->count(); ui->lblStartupAppsTitle->setText( - tr("System Startup Applications (%1)") + tr("Startup Applications (%1)") .arg(QString::number(count))); ui->notFoundWidget->setVisible(! count); @@ -96,9 +96,9 @@ void StartupAppsPage::setAppCount() void StartupAppsPage::openStartupAppEdit(const QString filePath) { StartupAppEdit::selectedFilePath = filePath; - if (startupAppEdit.isNull()) { - startupAppEdit = QSharedPointer(new StartupAppEdit(this)); - connect(startupAppEdit.data(), &StartupAppEdit::startupAppAdded, this, &StartupAppsPage::loadApps); + if (mStartupAppEdit.isNull()) { + mStartupAppEdit = QSharedPointer(new StartupAppEdit(this)); + connect(mStartupAppEdit.data(), &StartupAppEdit::startupAppAdded, this, &StartupAppsPage::loadApps); } - startupAppEdit->show(); + mStartupAppEdit->show(); } diff --git a/stacer/Pages/StartupApps/startup_apps_page.h b/stacer/Pages/StartupApps/startup_apps_page.h index 97a2d892..991f3135 100644 --- a/stacer/Pages/StartupApps/startup_apps_page.h +++ b/stacer/Pages/StartupApps/startup_apps_page.h @@ -36,7 +36,7 @@ private slots: Ui::StartupAppsPage *ui; private: - QSharedPointer startupAppEdit; + QSharedPointer mStartupAppEdit; QFileSystemWatcher mFileSystemWatcher; QString mAutostartPath; diff --git a/stacer/Pages/SystemCleaner/system_cleaner_page.cpp b/stacer/Pages/SystemCleaner/system_cleaner_page.cpp index 819a5952..2b43b765 100644 --- a/stacer/Pages/SystemCleaner/system_cleaner_page.cpp +++ b/stacer/Pages/SystemCleaner/system_cleaner_page.cpp @@ -4,10 +4,6 @@ SystemCleanerPage::~SystemCleanerPage() { delete ui; - if (loadingMovie) - loadingMovie->deleteLater(); - if (loadingMovie_2) - loadingMovie_2->deleteLater(); } SystemCleanerPage::SystemCleanerPage(QWidget *parent) : @@ -15,9 +11,9 @@ SystemCleanerPage::SystemCleanerPage(QWidget *parent) : ui(new Ui::SystemCleanerPage), im(InfoManager::ins()), tmr(ToolManager::ins()), - defaultIcon(QIcon::fromTheme("application-x-executable")), - loadingMovie(nullptr), - loadingMovie_2(nullptr) + mDefaultIcon(QIcon::fromTheme("application-x-executable")), + mLoadingMovie(nullptr), + mLoadingMovie_2(nullptr) { ui->setupUi(this); @@ -36,21 +32,17 @@ void SystemCleanerPage::init() ui->treeWidgetScanResult->setHeaderLabels({ tr("File Name"), tr("Size") }); // loaders - connect(SignalMapper::ins(), &SignalMapper::changedAppTheme, [=] { + connect(SignalMapper::ins(), &SignalMapper::sigChangedAppTheme, [=] { QString themeName = SettingManager::ins()->getThemeName(); - if (loadingMovie) - loadingMovie->deleteLater(); - loadingMovie = new QMovie(QString(":/static/themes/%1/img/scanLoading.gif").arg(themeName)); - ui->lblLoadingScanner->setMovie(loadingMovie); - loadingMovie->start(); + mLoadingMovie = new QMovie(QString(":/static/themes/%1/img/scanLoading.gif").arg(themeName)); + ui->lblLoadingScanner->setMovie(mLoadingMovie); + mLoadingMovie->start(); ui->lblLoadingScanner->hide(); - if (loadingMovie_2) - loadingMovie_2->deleteLater(); - loadingMovie_2 = new QMovie(QString(":/static/themes/%1/img/loading.gif").arg(themeName)); - ui->lblLoadingCleaner->setMovie(loadingMovie_2); - loadingMovie_2->start(); + mLoadingMovie_2 = new QMovie(QString(":/static/themes/%1/img/loading.gif").arg(themeName)); + ui->lblLoadingCleaner->setMovie(mLoadingMovie_2); + mLoadingMovie_2->start(); ui->lblLoadingCleaner->hide(); }); } @@ -95,7 +87,7 @@ void SystemCleanerPage::addTreeRoot(const CleanCategories &cat, const QString &t void SystemCleanerPage::addTreeChild(const QString &data, const QString &text, const quint64 &size, QTreeWidgetItem *parent) { QTreeWidgetItem *item = new QTreeWidgetItem(parent); - item->setIcon(0, QIcon::fromTheme(text, defaultIcon)); + item->setIcon(0, QIcon::fromTheme(text, mDefaultIcon)); item->setText(0, text); item->setText(1, FormatUtil::formatBytes(size)); item->setData(2, 0, data); diff --git a/stacer/Pages/SystemCleaner/system_cleaner_page.h b/stacer/Pages/SystemCleaner/system_cleaner_page.h index ca03babd..f13b1dca 100644 --- a/stacer/Pages/SystemCleaner/system_cleaner_page.h +++ b/stacer/Pages/SystemCleaner/system_cleaner_page.h @@ -35,7 +35,6 @@ class SystemCleanerPage : public QWidget ~SystemCleanerPage(); private slots: - void init(); void addTreeRoot(const CleanCategories &cat, const QString &title, const QFileInfoList &infos, bool noChild = false); void addTreeChild(const CleanCategories &cat, const QString &text, const quint64 &size); void addTreeChild(const QString &data, const QString &text, const quint64 &size, QTreeWidgetItem *parent); @@ -50,15 +49,17 @@ private slots: bool cleanValid(); private: - Ui::SystemCleanerPage *ui; + void init(); private: + Ui::SystemCleanerPage *ui; + InfoManager *im; ToolManager *tmr; - QIcon defaultIcon; - QMovie *loadingMovie; - QMovie *loadingMovie_2; + QIcon mDefaultIcon; + QMovie *mLoadingMovie; + QMovie *mLoadingMovie_2; }; #endif // SYSTEMCLEANERPAGE_H diff --git a/stacer/Pages/Uninstaller/uninstaller_page.cpp b/stacer/Pages/Uninstaller/uninstaller_page.cpp index f0e14798..0351834e 100644 --- a/stacer/Pages/Uninstaller/uninstaller_page.cpp +++ b/stacer/Pages/Uninstaller/uninstaller_page.cpp @@ -20,8 +20,8 @@ UninstallerPage::UninstallerPage(QWidget *parent) : void UninstallerPage::init() { - QString path = QString(":/static/themes/%1/img/loading.gif").arg(SettingManager::ins()->getThemeName()); - QMovie *loadingMovie = new QMovie(path, QByteArray(), this); + QString iconLoading = QString(":/static/themes/%1/img/loading.gif").arg(SettingManager::ins()->getThemeName()); + QMovie *loadingMovie = new QMovie(iconLoading, QByteArray(), this); ui->lblLoadingUninstaller->setMovie(loadingMovie); loadingMovie->start(); ui->lblLoadingUninstaller->hide(); @@ -32,8 +32,8 @@ void UninstallerPage::init() QtConcurrent::run(this, &UninstallerPage::loadPackages); - connect(tm, &ToolManager::uninstallStarted, this, &UninstallerPage::uninstallStarted); - connect(tm, &ToolManager::uninstallFinished, this, &UninstallerPage::loadPackages); + connect(SignalMapper::ins(), &SignalMapper::sigUninstallStarted, this, &UninstallerPage::uninstallStarted); + connect(SignalMapper::ins(), &SignalMapper::sigUninstallFinished, this, &UninstallerPage::loadPackages); } void UninstallerPage::loadPackages() @@ -43,7 +43,7 @@ void UninstallerPage::loadPackages() // clear items ui->listWidgetPackages->clear(); - QIcon icon(QString(":/static/themes/%1/img/package.png").arg(SettingManager::ins()->getThemeName())); + QIcon icon(":/static/themes/common/img/package.png"); QStringList packages = tm->getPackages(); for (const QString &package : packages) { QListWidgetItem *item = new QListWidgetItem(QIcon::fromTheme(package, icon), QString(" %1").arg(package)); @@ -92,8 +92,10 @@ void UninstallerPage::on_btnUninstall_clicked() QStringList selectedPackages = getSelectedPackages(); if(! selectedPackages.isEmpty()) { - QtConcurrent::run([selectedPackages]() -> void { + QtConcurrent::run([=] { + emit SignalMapper::ins()->sigUninstallStarted(); ToolManager::ins()->uninstallPackages(selectedPackages); + emit SignalMapper::ins()->sigUninstallFinished(); }); } } diff --git a/stacer/Pages/Uninstaller/uninstaller_page.h b/stacer/Pages/Uninstaller/uninstaller_page.h index 77f69bcc..0fccbc3e 100644 --- a/stacer/Pages/Uninstaller/uninstaller_page.h +++ b/stacer/Pages/Uninstaller/uninstaller_page.h @@ -7,6 +7,7 @@ #include "Managers/tool_manager.h" #include "Managers/app_manager.h" +#include "signal_mapper.h" namespace Ui { class UninstallerPage; @@ -22,10 +23,12 @@ class UninstallerPage : public QWidget public slots: void uninstallStarted(); -private slots: + +private: void init(); - void setAppCount(); +private slots: + void setAppCount(); void on_txtPackageSearch_textChanged(const QString &val); void on_btnUninstall_clicked(); QStringList getSelectedPackages(); @@ -34,7 +37,6 @@ private slots: private: Ui::UninstallerPage *ui; -private: ToolManager *tm; }; diff --git a/stacer/app.cpp b/stacer/app.cpp index c96c88cf..30c01e1b 100644 --- a/stacer/app.cpp +++ b/stacer/app.cpp @@ -10,17 +10,9 @@ App::~App() App::App(QWidget *parent) : QMainWindow(parent), ui(new Ui::App), - slidingStacked(new SlidingStackedWidget(this)), - dashboardPage(new DashboardPage(slidingStacked)), - startupAppsPage(new StartupAppsPage(slidingStacked)), - systemCleanerPage(new SystemCleanerPage(slidingStacked)), - servicesPage(new ServicesPage(slidingStacked)), - processPage(new ProcessesPage(slidingStacked)), - uninstallerPage(new UninstallerPage(slidingStacked)), - resourcesPage(new ResourcesPage(slidingStacked)), - settingsPage(new SettingsPage(slidingStacked)), - trayIcon(AppManager::ins()->getTrayIcon()), - trayMenu(new QMenu(this)) + mSlidingStacked(new SlidingStackedWidget(this)), + mTrayIcon(AppManager::ins()->getTrayIcon()), + mTrayMenu(new QMenu(this)) { ui->setupUi(this); @@ -38,39 +30,51 @@ void App::init() ui->horizontalLayout->setContentsMargins(0,0,0,0); ui->horizontalLayout->setSpacing(0); - ui->pageContentLayout->addWidget(slidingStacked); + dashboardPage = new DashboardPage(mSlidingStacked); + startupAppsPage = new StartupAppsPage(mSlidingStacked); + systemCleanerPage = new SystemCleanerPage(mSlidingStacked); + servicesPage = new ServicesPage(mSlidingStacked); + processPage = new ProcessesPage(mSlidingStacked); + uninstallerPage = new UninstallerPage(mSlidingStacked); + resourcesPage = new ResourcesPage(mSlidingStacked); + settingsPage = new SettingsPage(mSlidingStacked); - listPages = { + ui->pageContentLayout->addWidget(mSlidingStacked); + + mListPages = { dashboardPage, startupAppsPage, systemCleanerPage, servicesPage, processPage, uninstallerPage, resourcesPage, settingsPage }; - listSidebarButtons = { + mListSidebarButtons = { ui->btnDash, ui->btnStartupApps, ui->btnSystemCleaner, ui->btnServices, ui->btnProcesses, ui->btnUninstaller, ui->btnResources, ui->btnSettings }; // APT SOURCE MANAGER if (ToolManager::ins()->checkSourceRepository()) { - aptSourceManagerPage = new APTSourceManagerPage(slidingStacked); - listPages.insert(7, aptSourceManagerPage); - listSidebarButtons.insert(7, ui->btnAptSourceManager); + aptSourceManagerPage = new APTSourceManagerPage(mSlidingStacked); + mListPages.insert(7, aptSourceManagerPage); + mListSidebarButtons.insert(7, ui->btnAptSourceManager); } else { ui->btnAptSourceManager->hide(); } // GNOME SETTINGS - if (GnomeSettingsTool::ins().checkGSettings()) { - gnomeSettingsPage = new GnomeSettingsPage(slidingStacked); - listPages.insert(8, gnomeSettingsPage); - listSidebarButtons.insert(8, ui->btnGnomeSettings); + bool checkDesktopSession = QString(qgetenv("DESKTOP_SESSION")).contains(QRegExp("ubuntu", Qt::CaseInsensitive)); + bool checkDistribution = SystemInfo().getDistribution().contains(QRegExp("ubuntu", Qt::CaseInsensitive));; + + if (checkDesktopSession || checkDistribution) { + gnomeSettingsPage = new GnomeSettingsPage(mSlidingStacked); + mListPages.insert(8, gnomeSettingsPage); + mListSidebarButtons.insert(8, ui->btnGnomeSettings); } else { ui->btnGnomeSettings->hide(); } // add pages - for (QWidget *page: listPages) { - slidingStacked->addWidget(page); + for (QWidget *page: mListPages) { + mSlidingStacked->addWidget(page); } AppManager::ins()->updateStylesheet(); @@ -82,34 +86,33 @@ void App::init() createTrayActions(); - trayIcon->show(); + mTrayIcon->show(); } void App::closeEvent(QCloseEvent *event) { - event->accept(); -// event->ignore(); -// hide(); + event->ignore(); + hide(); } void App::createTrayActions() { - for (QPushButton *button: listSidebarButtons) { + for (QPushButton *button: mListSidebarButtons) { QString toolTip = button->toolTip(); QAction *action = new QAction(toolTip, this); connect(action, &QAction::triggered, [=] { clickSidebarButton(toolTip, true); }); - trayMenu->addAction(action); + mTrayMenu->addAction(action); } - trayMenu->addSeparator(); + mTrayMenu->addSeparator(); QAction *quitAction = new QAction(tr("Quit"), this); connect(quitAction, &QAction::triggered, [=] {qApp->quit();}); - trayMenu->addAction(quitAction); + mTrayMenu->addAction(quitAction); - trayIcon->setContextMenu(trayMenu); + mTrayIcon->setContextMenu(mTrayMenu); } void App::clickSidebarButton(QString pageTitle, bool isShow) @@ -119,16 +122,14 @@ void App::clickSidebarButton(QString pageTitle, bool isShow) pageClick(selectedWidget, !isShow); checkSidebarButtonByTooltip(pageTitle); } else { - pageClick(listPages.first()); - } - if (isShow) { - show(); + pageClick(mListPages.first()); } + setVisible(isShow); } void App::checkSidebarButtonByTooltip(const QString &text) { - for (QPushButton *button: listSidebarButtons) { + for (QPushButton *button: mListSidebarButtons) { if (button->toolTip() == text) { button->setChecked(true); } @@ -137,7 +138,7 @@ void App::checkSidebarButtonByTooltip(const QString &text) QWidget* App::getPageByTitle(const QString &title) { - for (QWidget *page: listPages) { + for (QWidget *page: mListPages) { if (page->windowTitle() == title) { return page; } @@ -150,9 +151,9 @@ void App::pageClick(QWidget *widget, bool slide) if (widget) { ui->pageTitle->setText(widget->windowTitle()); if (slide) { - slidingStacked->slideInIdx(slidingStacked->indexOf(widget)); + mSlidingStacked->slideInIdx(mSlidingStacked->indexOf(widget)); } else { - slidingStacked->setCurrentWidget(widget); + mSlidingStacked->setCurrentWidget(widget); } } } diff --git a/stacer/app.h b/stacer/app.h index 1bb0cf72..f8ac3e9f 100644 --- a/stacer/app.h +++ b/stacer/app.h @@ -3,7 +3,7 @@ #include -#include "slidingstackedwidget.h" +#include "sliding_stacked_widget.h" #include "Managers/app_manager.h" #include "Managers/setting_manager.h" @@ -62,10 +62,10 @@ private slots: Ui::App *ui; // Pages - QList listPages; - QList listSidebarButtons; + QList mListPages; + QList mListSidebarButtons; - SlidingStackedWidget *slidingStacked; + SlidingStackedWidget *mSlidingStacked; DashboardPage *dashboardPage; StartupAppsPage *startupAppsPage; @@ -80,9 +80,9 @@ private slots: QSharedPointer feedback; - QSystemTrayIcon *trayIcon; + QSystemTrayIcon *mTrayIcon; - QMenu *trayMenu; + QMenu *mTrayMenu; }; #endif // APP_H diff --git a/stacer/feedback.cpp b/stacer/feedback.cpp index 60f4caab..f9d3e665 100644 --- a/stacer/feedback.cpp +++ b/stacer/feedback.cpp @@ -15,9 +15,9 @@ Feedback::~Feedback() Feedback::Feedback(QWidget *parent) : QDialog(parent), ui(new Ui::Feedback), - header("Content-Type: application/json"), - feedbackUrl("https://stacer-web-api.herokuapp.com/feedback"), - mailRegex("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b") + mHeader("Content-Type: application/json"), + mFeedbackUrl("https://stacer-web-api.herokuapp.com/feedback"), + mMailRegex("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b") { ui->setupUi(this); @@ -26,10 +26,10 @@ Feedback::Feedback(QWidget *parent) : void Feedback::init() { - mailRegex.setCaseSensitivity(Qt::CaseInsensitive); - mailRegex.setPatternSyntax(QRegExp::RegExp); + mMailRegex.setCaseSensitivity(Qt::CaseInsensitive); + mMailRegex.setPatternSyntax(QRegExp::RegExp); - connect(this, &Feedback::clearInputsS, this, &Feedback::clearInputs); + connect(this, &Feedback::clearInputsS, this, &Feedback::clearInputs); connect(this, &Feedback::setErrorMessageS, this, &Feedback::setErrorMessage); connect(this, &Feedback::disableElementsS, this, &Feedback::disableElements); } @@ -40,7 +40,7 @@ void Feedback::on_btnSend_clicked() QString email = ui->txtEmail->text(); QString message = ui->txtMessage->toPlainText(); - bool isEmailValid = mailRegex.exactMatch(email); + bool isEmailValid = mMailRegex.exactMatch(email); if (! isEmailValid) { emit setErrorMessageS(tr("Email address is not valid !")); @@ -68,7 +68,7 @@ void Feedback::on_btnSend_clicked() QJsonDocument json(postData); - args << "-d" << json.toJson() << "-H" << header << "-X" << "POST" << feedbackUrl; + args << "-d" << json.toJson() << "-H" << mHeader << "-X" << "POST" << mFeedbackUrl; try { QString result = CommandUtil::exec("curl", args); diff --git a/stacer/feedback.h b/stacer/feedback.h index ce79ac73..df48bd9b 100644 --- a/stacer/feedback.h +++ b/stacer/feedback.h @@ -32,10 +32,10 @@ private slots: private: Ui::Feedback *ui; - QString header; - QString feedbackUrl; + QString mHeader; + QString mFeedbackUrl; - QRegExp mailRegex; + QRegExp mMailRegex; }; #endif // FEEDBACK_H diff --git a/stacer/utilities.h b/stacer/utilities.h index da594e59..0a05bf57 100644 --- a/stacer/utilities.h +++ b/stacer/utilities.h @@ -8,13 +8,13 @@ class Utilities { public: static void - addDropShadow(QWidget *widget, int alpha, int blur = 15) + addDropShadow(QWidget *widget, const int alpha, const int blur = 15) { addDropShadow(QList() << widget, alpha, blur); } static void - addDropShadow(QList widgets, int alpha, int blur = 15) + addDropShadow(QList widgets, const int alpha, const int blur = 15) { for (QWidget *widget: widgets) { QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(widget);