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 @@
#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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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();
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
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