From 8c31292890c7ab53ae12d17dd992b9e0119ac297 Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Sat, 22 Oct 2016 03:41:01 +0900 Subject: [PATCH] Code cleanup --- src/core/config.cpp | 14 +++++++------- src/core/config.h | 4 ++-- src/core/network.cpp | 4 ++-- src/core/network.h | 4 ++-- src/handlers/xdgurl.cpp | 40 ++++++++++++++++++++-------------------- src/handlers/xdgurl.h | 12 ++++++------ src/main.cpp | 6 +++--- src/utility/file.cpp | 4 ++-- src/utility/file.h | 4 ++-- src/utility/json.cpp | 4 ++-- src/utility/json.h | 4 ++-- src/utility/package.cpp | 4 ++-- src/utility/package.h | 4 ++-- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/core/config.cpp b/src/core/config.cpp index 9276958..2e1635d 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -3,7 +3,7 @@ #include "config.h" -namespace Core { +namespace core { Config::Config(const QString &configsDir, QObject *parent) : QObject(parent), configsDir_(configsDir) @@ -14,11 +14,11 @@ QJsonObject Config::get(const QString &name) QString configFile = configsDir_ + "/" + name + ".json"; if (!cacheData_.contains(name)) { - QString json = Utility::File::readText(configFile); + QString json = utility::File::readText(configFile); if (json.isEmpty()) { json = "{}"; // Blank JSON data as default } - cacheData_[name] = Utility::Json::convertStrToObj(json); + cacheData_[name] = utility::Json::convertStrToObj(json); } return cacheData_[name].toObject(); } @@ -26,14 +26,14 @@ QJsonObject Config::get(const QString &name) bool Config::set(const QString &name, const QJsonObject &jsonObj) { QString configFile = configsDir_ + "/" + name + ".json"; - QString json = Utility::Json::convertObjToStr(jsonObj); + QString json = utility::Json::convertObjToStr(jsonObj); - Utility::File::makeDir(configsDir_); - if (Utility::File::writeText(configFile, json)) { + utility::File::makeDir(configsDir_); + if (utility::File::writeText(configFile, json)) { cacheData_[name] = jsonObj; return true; } return false; } -} // namespace Core +} // namespace core diff --git a/src/core/config.h b/src/core/config.h index 16b4dea..cc1832d 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -4,7 +4,7 @@ #include <QObject> #include <QJsonObject> -namespace Core { +namespace core { class Config : public QObject { @@ -21,6 +21,6 @@ public: bool set(const QString &name, const QJsonObject &jsonObj); }; -} // namespace Core +} // namespace core #endif // CORE_CONFIG_H diff --git a/src/core/network.cpp b/src/core/network.cpp index 12d7b85..7b14b54 100644 --- a/src/core/network.cpp +++ b/src/core/network.cpp @@ -5,7 +5,7 @@ #include "network.h" -namespace Core { +namespace core { Network::Network(const bool &async, QObject *parent) : QObject(parent), async_(async) @@ -48,4 +48,4 @@ QNetworkReply *Network::get(const QUrl &uri) return reply; } -} // namespace Core +} // namespace core diff --git a/src/core/network.h b/src/core/network.h index fc96e62..c2c5c83 100644 --- a/src/core/network.h +++ b/src/core/network.h @@ -7,7 +7,7 @@ class QEventLoop; class QNetworkAccessManager; class QNetworkReply; -namespace Core { +namespace core { class Network : public QObject { @@ -30,6 +30,6 @@ signals: void downloadProgress(const qint64 &received, const qint64 &total); }; -} // namespace Core +} // namespace core #endif // CORE_NETWORK_H diff --git a/src/handlers/xdgurl.cpp b/src/handlers/xdgurl.cpp index f36c5f8..fb0c195 100644 --- a/src/handlers/xdgurl.cpp +++ b/src/handlers/xdgurl.cpp @@ -11,16 +11,16 @@ #include "xdgurl.h" -namespace Handlers { +namespace handlers { -XdgUrl::XdgUrl(const QString &xdgUrl, Core::Config *config, Core::Network *network, QObject *parent) : +XdgUrl::XdgUrl(const QString &xdgUrl, core::Config *config, core::Network *network, QObject *parent) : QObject(parent), xdgUrl_(xdgUrl), config_(config), network_(network) { parse_(); loadDestinations_(); - connect(network_, &Core::Network::finished, this, &XdgUrl::downloaded_); - connect(network_, &Core::Network::downloadProgress, this, &XdgUrl::downloadProgress); + connect(network_, &core::Network::finished, this, &XdgUrl::downloaded_); + connect(network_, &core::Network::downloadProgress, this, &XdgUrl::downloadProgress); } void XdgUrl::parse_() @@ -81,13 +81,13 @@ QString XdgUrl::convertPathString_(const QString &path) QString newPath = path; if (newPath.contains("$HOME")) { - newPath.replace("$HOME", Utility::File::homePath()); + newPath.replace("$HOME", utility::File::homePath()); } else if (newPath.contains("$XDG_DATA_HOME")) { - newPath.replace("$XDG_DATA_HOME", Utility::File::xdgDataHomePath()); + newPath.replace("$XDG_DATA_HOME", utility::File::xdgDataHomePath()); } else if (newPath.contains("$KDEHOME")) { - newPath.replace("$KDEHOME", Utility::File::kdehomePath()); + newPath.replace("$KDEHOME", utility::File::kdehomePath()); } return newPath; @@ -110,8 +110,8 @@ void XdgUrl::saveDownloadedFile_(QNetworkReply *reply) QString destination = destinations_[type].toString(); QString path = destination + "/" + metadata_["filename"].toString(); - Utility::File::makeDir(destination); - Utility::File::remove(path); // Remove previous downloaded file + utility::File::makeDir(destination); + utility::File::remove(path); // Remove previous downloaded file if (!temporaryFile.copy(path)) { result["status"] = QString("error_save"); @@ -144,38 +144,38 @@ void XdgUrl::installDownloadedFile_(QNetworkReply *reply) QString destination = destinations_[type].toString(); QString path = destination + "/" + metadata_["filename"].toString(); - Utility::File::makeDir(destination); - Utility::File::remove(path); // Remove previous downloaded file + utility::File::makeDir(destination); + utility::File::remove(path); // Remove previous downloaded file if (type == "bin" - && Utility::Package::installProgram(temporaryFile.fileName(), path)) { + && utility::Package::installProgram(temporaryFile.fileName(), path)) { result["message"] = QString("The program has been installed into " + destination); } else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids") - && Utility::Package::installPlasmapkg(temporaryFile.fileName(), "plasmoid")) { + && utility::Package::installPlasmapkg(temporaryFile.fileName(), "plasmoid")) { result["message"] = QString("The plasmoid has been installed"); } else if ((type == "plasma_look_and_feel" || type == "plasma5_look_and_feel") - && Utility::Package::installPlasmapkg(temporaryFile.fileName(), "lookandfeel")) { + && utility::Package::installPlasmapkg(temporaryFile.fileName(), "lookandfeel")) { result["message"] = QString("The plasma look and feel has been installed"); } else if ((type == "plasma_desktopthemes" || type == "plasma5_desktopthemes") - && Utility::Package::installPlasmapkg(temporaryFile.fileName(), "theme")) { + && utility::Package::installPlasmapkg(temporaryFile.fileName(), "theme")) { result["message"] = QString("The plasma desktop theme has been installed"); } else if (type == "kwin_effects" - && Utility::Package::installPlasmapkg(temporaryFile.fileName(), "kwineffect")) { + && utility::Package::installPlasmapkg(temporaryFile.fileName(), "kwineffect")) { result["message"] = QString("The KWin effect has been installed"); } else if (type == "kwin_scripts" - && Utility::Package::installPlasmapkg(temporaryFile.fileName(), "kwinscript")) { + && utility::Package::installPlasmapkg(temporaryFile.fileName(), "kwinscript")) { result["message"] = QString("The KWin script has been installed"); } else if (type == "kwin_tabbox" - && Utility::Package::installPlasmapkg(temporaryFile.fileName(), "windowswitcher")) { + && utility::Package::installPlasmapkg(temporaryFile.fileName(), "windowswitcher")) { result["message"] = QString("The KWin window switcher has been installed"); } - else if (Utility::Package::uncompressArchive(temporaryFile.fileName(), destination)) { + else if (utility::Package::uncompressArchive(temporaryFile.fileName(), destination)) { result["message"] = QString("The archive file has been uncompressed into " + destination); } else if (temporaryFile.copy(path)) { @@ -289,4 +289,4 @@ void XdgUrl::downloaded_(QNetworkReply *reply) } } -} // namespace Handlers +} // namespace handlers diff --git a/src/handlers/xdgurl.h b/src/handlers/xdgurl.h index 7fe233c..e426ff7 100644 --- a/src/handlers/xdgurl.h +++ b/src/handlers/xdgurl.h @@ -6,12 +6,12 @@ class QNetworkReply; -namespace Core { +namespace core { class Config; class Network; } -namespace Handlers { +namespace handlers { class XdgUrl : public QObject { @@ -19,15 +19,15 @@ class XdgUrl : public QObject private: QString xdgUrl_; - Core::Config *config_; - Core::Network *network_; + core::Config *config_; + core::Network *network_; QJsonObject metadata_; QJsonObject destinations_; QString destination_; public: - explicit XdgUrl(const QString &xdgUrl, Core::Config *config, Core::Network *network, QObject *parent = 0); + explicit XdgUrl(const QString &xdgUrl, core::Config *config, core::Network *network, QObject *parent = 0); private: void parse_(); @@ -53,6 +53,6 @@ signals: void downloadProgress(const qint64 &received, const qint64 &total); }; -} // namespace Handlers +} // namespace handlers #endif // HANDLERS_XDGURL_H diff --git a/src/main.cpp b/src/main.cpp index 7999ecb..6380ee4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,8 +21,8 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); - Core::Config *config = new Core::Config(":/configs"); - Core::Network *network = new Core::Network(true); + core::Config *config = new core::Config(":/configs"); + core::Network *network = new core::Network(true); QJsonObject configApplication = config->get("application"); @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) // Setup QML QQmlApplicationEngine qmlAppEngine; QQmlContext *qmlContext = qmlAppEngine.rootContext(); - qmlContext->setContextProperty("xdgUrlHandler", new Handlers::XdgUrl(xdgUrl, config, network)); + qmlContext->setContextProperty("xdgUrlHandler", new handlers::XdgUrl(xdgUrl, config, network)); qmlAppEngine.load(QUrl("qrc:/qml/main.qml")); return app.exec(); diff --git a/src/utility/file.cpp b/src/utility/file.cpp index 6f6ed15..5252781 100644 --- a/src/utility/file.cpp +++ b/src/utility/file.cpp @@ -6,7 +6,7 @@ #include "file.h" -namespace Utility { +namespace utility { /** * XDG Base Directory Specification @@ -203,4 +203,4 @@ bool File::remove(const QString &path) return false; } -} // namespace Utility +} // namespace utility diff --git a/src/utility/file.h b/src/utility/file.h index 8700250..bee2341 100644 --- a/src/utility/file.h +++ b/src/utility/file.h @@ -6,7 +6,7 @@ class QFileInfo; typedef QList<QFileInfo> QFileInfoList; -namespace Utility { +namespace utility { class File : public QObject { @@ -33,6 +33,6 @@ public: static bool remove(const QString &path); }; -} // namespace Utility +} // namespace utility #endif // UTILITY_FILE_H diff --git a/src/utility/json.cpp b/src/utility/json.cpp index d70ba2d..9546942 100644 --- a/src/utility/json.cpp +++ b/src/utility/json.cpp @@ -4,7 +4,7 @@ #include "json.h" -namespace Utility { +namespace utility { Json::Json(QObject *parent) : QObject(parent) {} @@ -36,4 +36,4 @@ bool Json::isValid(const QString &json) return false; } -} // namespace Utility +} // namespace utility diff --git a/src/utility/json.h b/src/utility/json.h index 3b7a0d2..0d07c96 100644 --- a/src/utility/json.h +++ b/src/utility/json.h @@ -3,7 +3,7 @@ #include <QObject> -namespace Utility { +namespace utility { class Json : public QObject { @@ -17,6 +17,6 @@ public: static bool isValid(const QString &json); }; -} // namespace Utility +} // namespace utility #endif // UTILITY_JSON_H diff --git a/src/utility/package.cpp b/src/utility/package.cpp index 710b919..033adc0 100644 --- a/src/utility/package.cpp +++ b/src/utility/package.cpp @@ -4,7 +4,7 @@ #include "package.h" -namespace Utility { +namespace utility { Package::Package(QObject *parent) : QObject(parent) {} @@ -106,4 +106,4 @@ bool Package::process_(const QString &program, const QStringList &arguments) return false; } -} // namespace Utility +} // namespace utility diff --git a/src/utility/package.h b/src/utility/package.h index 3827117..d43757c 100644 --- a/src/utility/package.h +++ b/src/utility/package.h @@ -3,7 +3,7 @@ #include <QObject> -namespace Utility { +namespace utility { class Package : public QObject { @@ -22,6 +22,6 @@ private: static bool process_(const QString &program, const QStringList &arguments); }; -} // namespace Utility +} // namespace utility #endif // UTILITY_PACKAGE_H -- GitLab