Skip to content
Snippets Groups Projects
Commit 8c312928 authored by akiraohgaki's avatar akiraohgaki
Browse files

Code cleanup

parent 98ec26bb
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "config.h" #include "config.h"
namespace Core { namespace core {
Config::Config(const QString &configsDir, QObject *parent) : Config::Config(const QString &configsDir, QObject *parent) :
QObject(parent), configsDir_(configsDir) QObject(parent), configsDir_(configsDir)
...@@ -14,11 +14,11 @@ QJsonObject Config::get(const QString &name) ...@@ -14,11 +14,11 @@ QJsonObject Config::get(const QString &name)
QString configFile = configsDir_ + "/" + name + ".json"; QString configFile = configsDir_ + "/" + name + ".json";
if (!cacheData_.contains(name)) { if (!cacheData_.contains(name)) {
QString json = Utility::File::readText(configFile); QString json = utility::File::readText(configFile);
if (json.isEmpty()) { if (json.isEmpty()) {
json = "{}"; // Blank JSON data as default json = "{}"; // Blank JSON data as default
} }
cacheData_[name] = Utility::Json::convertStrToObj(json); cacheData_[name] = utility::Json::convertStrToObj(json);
} }
return cacheData_[name].toObject(); return cacheData_[name].toObject();
} }
...@@ -26,14 +26,14 @@ QJsonObject Config::get(const QString &name) ...@@ -26,14 +26,14 @@ QJsonObject Config::get(const QString &name)
bool Config::set(const QString &name, const QJsonObject &jsonObj) bool Config::set(const QString &name, const QJsonObject &jsonObj)
{ {
QString configFile = configsDir_ + "/" + name + ".json"; QString configFile = configsDir_ + "/" + name + ".json";
QString json = Utility::Json::convertObjToStr(jsonObj); QString json = utility::Json::convertObjToStr(jsonObj);
Utility::File::makeDir(configsDir_); utility::File::makeDir(configsDir_);
if (Utility::File::writeText(configFile, json)) { if (utility::File::writeText(configFile, json)) {
cacheData_[name] = jsonObj; cacheData_[name] = jsonObj;
return true; return true;
} }
return false; return false;
} }
} // namespace Core } // namespace core
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <QObject> #include <QObject>
#include <QJsonObject> #include <QJsonObject>
namespace Core { namespace core {
class Config : public QObject class Config : public QObject
{ {
...@@ -21,6 +21,6 @@ public: ...@@ -21,6 +21,6 @@ public:
bool set(const QString &name, const QJsonObject &jsonObj); bool set(const QString &name, const QJsonObject &jsonObj);
}; };
} // namespace Core } // namespace core
#endif // CORE_CONFIG_H #endif // CORE_CONFIG_H
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "network.h" #include "network.h"
namespace Core { namespace core {
Network::Network(const bool &async, QObject *parent) : Network::Network(const bool &async, QObject *parent) :
QObject(parent), async_(async) QObject(parent), async_(async)
...@@ -48,4 +48,4 @@ QNetworkReply *Network::get(const QUrl &uri) ...@@ -48,4 +48,4 @@ QNetworkReply *Network::get(const QUrl &uri)
return reply; return reply;
} }
} // namespace Core } // namespace core
...@@ -7,7 +7,7 @@ class QEventLoop; ...@@ -7,7 +7,7 @@ class QEventLoop;
class QNetworkAccessManager; class QNetworkAccessManager;
class QNetworkReply; class QNetworkReply;
namespace Core { namespace core {
class Network : public QObject class Network : public QObject
{ {
...@@ -30,6 +30,6 @@ signals: ...@@ -30,6 +30,6 @@ signals:
void downloadProgress(const qint64 &received, const qint64 &total); void downloadProgress(const qint64 &received, const qint64 &total);
}; };
} // namespace Core } // namespace core
#endif // CORE_NETWORK_H #endif // CORE_NETWORK_H
...@@ -11,16 +11,16 @@ ...@@ -11,16 +11,16 @@
#include "xdgurl.h" #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) QObject(parent), xdgUrl_(xdgUrl), config_(config), network_(network)
{ {
parse_(); parse_();
loadDestinations_(); loadDestinations_();
connect(network_, &Core::Network::finished, this, &XdgUrl::downloaded_); connect(network_, &core::Network::finished, this, &XdgUrl::downloaded_);
connect(network_, &Core::Network::downloadProgress, this, &XdgUrl::downloadProgress); connect(network_, &core::Network::downloadProgress, this, &XdgUrl::downloadProgress);
} }
void XdgUrl::parse_() void XdgUrl::parse_()
...@@ -81,13 +81,13 @@ QString XdgUrl::convertPathString_(const QString &path) ...@@ -81,13 +81,13 @@ QString XdgUrl::convertPathString_(const QString &path)
QString newPath = path; QString newPath = path;
if (newPath.contains("$HOME")) { if (newPath.contains("$HOME")) {
newPath.replace("$HOME", Utility::File::homePath()); newPath.replace("$HOME", utility::File::homePath());
} }
else if (newPath.contains("$XDG_DATA_HOME")) { 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")) { else if (newPath.contains("$KDEHOME")) {
newPath.replace("$KDEHOME", Utility::File::kdehomePath()); newPath.replace("$KDEHOME", utility::File::kdehomePath());
} }
return newPath; return newPath;
...@@ -110,8 +110,8 @@ void XdgUrl::saveDownloadedFile_(QNetworkReply *reply) ...@@ -110,8 +110,8 @@ void XdgUrl::saveDownloadedFile_(QNetworkReply *reply)
QString destination = destinations_[type].toString(); QString destination = destinations_[type].toString();
QString path = destination + "/" + metadata_["filename"].toString(); QString path = destination + "/" + metadata_["filename"].toString();
Utility::File::makeDir(destination); utility::File::makeDir(destination);
Utility::File::remove(path); // Remove previous downloaded file utility::File::remove(path); // Remove previous downloaded file
if (!temporaryFile.copy(path)) { if (!temporaryFile.copy(path)) {
result["status"] = QString("error_save"); result["status"] = QString("error_save");
...@@ -144,38 +144,38 @@ void XdgUrl::installDownloadedFile_(QNetworkReply *reply) ...@@ -144,38 +144,38 @@ void XdgUrl::installDownloadedFile_(QNetworkReply *reply)
QString destination = destinations_[type].toString(); QString destination = destinations_[type].toString();
QString path = destination + "/" + metadata_["filename"].toString(); QString path = destination + "/" + metadata_["filename"].toString();
Utility::File::makeDir(destination); utility::File::makeDir(destination);
Utility::File::remove(path); // Remove previous downloaded file utility::File::remove(path); // Remove previous downloaded file
if (type == "bin" 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); result["message"] = QString("The program has been installed into " + destination);
} }
else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids") 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"); result["message"] = QString("The plasmoid has been installed");
} }
else if ((type == "plasma_look_and_feel" || type == "plasma5_look_and_feel") 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"); result["message"] = QString("The plasma look and feel has been installed");
} }
else if ((type == "plasma_desktopthemes" || type == "plasma5_desktopthemes") 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"); result["message"] = QString("The plasma desktop theme has been installed");
} }
else if (type == "kwin_effects" 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"); result["message"] = QString("The KWin effect has been installed");
} }
else if (type == "kwin_scripts" 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"); result["message"] = QString("The KWin script has been installed");
} }
else if (type == "kwin_tabbox" 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"); 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); result["message"] = QString("The archive file has been uncompressed into " + destination);
} }
else if (temporaryFile.copy(path)) { else if (temporaryFile.copy(path)) {
...@@ -289,4 +289,4 @@ void XdgUrl::downloaded_(QNetworkReply *reply) ...@@ -289,4 +289,4 @@ void XdgUrl::downloaded_(QNetworkReply *reply)
} }
} }
} // namespace Handlers } // namespace handlers
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
class QNetworkReply; class QNetworkReply;
namespace Core { namespace core {
class Config; class Config;
class Network; class Network;
} }
namespace Handlers { namespace handlers {
class XdgUrl : public QObject class XdgUrl : public QObject
{ {
...@@ -19,15 +19,15 @@ class XdgUrl : public QObject ...@@ -19,15 +19,15 @@ class XdgUrl : public QObject
private: private:
QString xdgUrl_; QString xdgUrl_;
Core::Config *config_; core::Config *config_;
Core::Network *network_; core::Network *network_;
QJsonObject metadata_; QJsonObject metadata_;
QJsonObject destinations_; QJsonObject destinations_;
QString destination_; QString destination_;
public: 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: private:
void parse_(); void parse_();
...@@ -53,6 +53,6 @@ signals: ...@@ -53,6 +53,6 @@ signals:
void downloadProgress(const qint64 &received, const qint64 &total); void downloadProgress(const qint64 &received, const qint64 &total);
}; };
} // namespace Handlers } // namespace handlers
#endif // HANDLERS_XDGURL_H #endif // HANDLERS_XDGURL_H
...@@ -21,8 +21,8 @@ int main(int argc, char *argv[]) ...@@ -21,8 +21,8 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif #endif
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
Core::Config *config = new Core::Config(":/configs"); core::Config *config = new core::Config(":/configs");
Core::Network *network = new Core::Network(true); core::Network *network = new core::Network(true);
QJsonObject configApplication = config->get("application"); QJsonObject configApplication = config->get("application");
...@@ -51,7 +51,7 @@ int main(int argc, char *argv[]) ...@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
// Setup QML // Setup QML
QQmlApplicationEngine qmlAppEngine; QQmlApplicationEngine qmlAppEngine;
QQmlContext *qmlContext = qmlAppEngine.rootContext(); 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")); qmlAppEngine.load(QUrl("qrc:/qml/main.qml"));
return app.exec(); return app.exec();
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "file.h" #include "file.h"
namespace Utility { namespace utility {
/** /**
* XDG Base Directory Specification * XDG Base Directory Specification
...@@ -203,4 +203,4 @@ bool File::remove(const QString &path) ...@@ -203,4 +203,4 @@ bool File::remove(const QString &path)
return false; return false;
} }
} // namespace Utility } // namespace utility
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
class QFileInfo; class QFileInfo;
typedef QList<QFileInfo> QFileInfoList; typedef QList<QFileInfo> QFileInfoList;
namespace Utility { namespace utility {
class File : public QObject class File : public QObject
{ {
...@@ -33,6 +33,6 @@ public: ...@@ -33,6 +33,6 @@ public:
static bool remove(const QString &path); static bool remove(const QString &path);
}; };
} // namespace Utility } // namespace utility
#endif // UTILITY_FILE_H #endif // UTILITY_FILE_H
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "json.h" #include "json.h"
namespace Utility { namespace utility {
Json::Json(QObject *parent) : QObject(parent) Json::Json(QObject *parent) : QObject(parent)
{} {}
...@@ -36,4 +36,4 @@ bool Json::isValid(const QString &json) ...@@ -36,4 +36,4 @@ bool Json::isValid(const QString &json)
return false; return false;
} }
} // namespace Utility } // namespace utility
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <QObject> #include <QObject>
namespace Utility { namespace utility {
class Json : public QObject class Json : public QObject
{ {
...@@ -17,6 +17,6 @@ public: ...@@ -17,6 +17,6 @@ public:
static bool isValid(const QString &json); static bool isValid(const QString &json);
}; };
} // namespace Utility } // namespace utility
#endif // UTILITY_JSON_H #endif // UTILITY_JSON_H
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "package.h" #include "package.h"
namespace Utility { namespace utility {
Package::Package(QObject *parent) : QObject(parent) Package::Package(QObject *parent) : QObject(parent)
{} {}
...@@ -106,4 +106,4 @@ bool Package::process_(const QString &program, const QStringList &arguments) ...@@ -106,4 +106,4 @@ bool Package::process_(const QString &program, const QStringList &arguments)
return false; return false;
} }
} // namespace Utility } // namespace utility
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <QObject> #include <QObject>
namespace Utility { namespace utility {
class Package : public QObject class Package : public QObject
{ {
...@@ -22,6 +22,6 @@ private: ...@@ -22,6 +22,6 @@ private:
static bool process_(const QString &program, const QStringList &arguments); static bool process_(const QString &program, const QStringList &arguments);
}; };
} // namespace Utility } // namespace utility
#endif // UTILITY_PACKAGE_H #endif // UTILITY_PACKAGE_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment