From b220c8fe243a452f46b47a9afa36c68bf6cec080 Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Thu, 1 Feb 2018 01:09:08 +0900 Subject: [PATCH] qtlib to qtil --- .gitignore | 2 +- app/src/handlers/confighandler.cpp | 14 +++--- app/src/handlers/confighandler.h | 6 +-- app/src/handlers/desktopthemehandler.cpp | 4 +- app/src/handlers/itemhandler.cpp | 56 ++++++++++++------------ app/src/handlers/itemhandler.h | 8 ++-- app/src/handlers/ocsapihandler.cpp | 10 ++--- app/src/handlers/systemhandler.cpp | 10 ++--- app/src/handlers/updatehandler.cpp | 16 +++---- app/src/handlers/updatehandler.h | 6 +-- app/src/websockets/websocketserver.cpp | 8 ++-- lib/lib.pri | 2 +- scripts/prepare.sh | 4 +- 13 files changed, 73 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index b8451a6..3f396f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.pro.user build_*/ -lib/qtlib/ +lib/qtil/ lib/AppImageUpdate/ lib/AppImageUpdate-prebuilt/ diff --git a/app/src/handlers/confighandler.cpp b/app/src/handlers/confighandler.cpp index 6ccbf7d..6807e93 100644 --- a/app/src/handlers/confighandler.cpp +++ b/app/src/handlers/confighandler.cpp @@ -3,15 +3,15 @@ #include <QStringList> #include <QStandardPaths> -#include "qtlib_dir.h" +#include "qtil_dir.h" ConfigHandler::ConfigHandler(QObject *parent) : QObject(parent) { - appConfig_ = qtlib::Config(":/configs"); + appConfig_ = qtil::Config(":/configs"); importAppConfigApplication(); importAppConfigInstallTypes(); - usrConfig_ = qtlib::Config(qtlib::Dir::genericConfigPath() + "/" + getAppConfigApplication()["id"].toString()); + usrConfig_ = qtil::Config(qtil::Dir::genericConfigPath() + "/" + getAppConfigApplication()["id"].toString()); } QJsonObject ConfigHandler::getAppConfigApplication() const @@ -229,7 +229,7 @@ QString ConfigHandler::convertPathString(const QString &path) const { auto newPath = path; if (newPath.contains("$HOME")) { - newPath.replace("$HOME", qtlib::Dir::homePath()); + newPath.replace("$HOME", qtil::Dir::homePath()); } else if (newPath.contains("$XDG_DOCUMENTS_DIR")) { newPath.replace("$XDG_DOCUMENTS_DIR", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); @@ -247,13 +247,13 @@ QString ConfigHandler::convertPathString(const QString &path) const newPath.replace("$XDG_VIDEOS_DIR", QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); } else if (newPath.contains("$XDG_DATA_HOME")) { - newPath.replace("$XDG_DATA_HOME", qtlib::Dir::genericDataPath()); + newPath.replace("$XDG_DATA_HOME", qtil::Dir::genericDataPath()); } else if (newPath.contains("$KDEHOME")) { - newPath.replace("$KDEHOME", qtlib::Dir::kdehomePath()); + newPath.replace("$KDEHOME", qtil::Dir::kdehomePath()); } else if (newPath.contains("$APP_DATA")) { - newPath.replace("$APP_DATA", qtlib::Dir::genericDataPath() + "/" + getAppConfigApplication()["id"].toString()); + newPath.replace("$APP_DATA", qtil::Dir::genericDataPath() + "/" + getAppConfigApplication()["id"].toString()); } return newPath; } diff --git a/app/src/handlers/confighandler.h b/app/src/handlers/confighandler.h index a1531ff..c7d3891 100644 --- a/app/src/handlers/confighandler.h +++ b/app/src/handlers/confighandler.h @@ -3,7 +3,7 @@ #include <QObject> #include <QJsonObject> -#include "qtlib_config.h" +#include "qtil_config.h" class ConfigHandler : public QObject { @@ -42,8 +42,8 @@ private: void importAppConfigInstallTypes(); QString convertPathString(const QString &path) const; - qtlib::Config appConfig_; - qtlib::Config usrConfig_; + qtil::Config appConfig_; + qtil::Config usrConfig_; QJsonObject appConfigApplication_; QJsonObject appConfigInstallTypes_; }; diff --git a/app/src/handlers/desktopthemehandler.cpp b/app/src/handlers/desktopthemehandler.cpp index 01eaa22..0cf27bb 100644 --- a/app/src/handlers/desktopthemehandler.cpp +++ b/app/src/handlers/desktopthemehandler.cpp @@ -2,7 +2,7 @@ #include <QStringList> -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX #include <QFileInfo> #include "desktopthemes/kdetheme.h" @@ -98,7 +98,7 @@ bool DesktopThemeHandler::isApplicableType(const QString &installType) const bool DesktopThemeHandler::applyTheme(const QString &path, const QString &installType) const { -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX if (QFileInfo::exists(path) && isApplicableType(installType)) { auto desktop = desktopEnvironment(); diff --git a/app/src/handlers/itemhandler.cpp b/app/src/handlers/itemhandler.cpp index 9e71a96..d6a3098 100644 --- a/app/src/handlers/itemhandler.cpp +++ b/app/src/handlers/itemhandler.cpp @@ -6,14 +6,14 @@ #include <QFileInfo> #include <QDateTime> -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX #include <QProcess> #endif -#include "qtlib_dir.h" -#include "qtlib_file.h" -#include "qtlib_networkresource.h" -#include "qtlib_package.h" +#include "qtil_dir.h" +#include "qtil_file.h" +#include "qtil_networkresource.h" +#include "qtil_package.h" #include "handlers/confighandler.h" @@ -67,9 +67,9 @@ void ItemHandler::getItem(const QString &command, const QString &url, const QStr itemMetadataSet[itemKey] = metadata; setMetadataSet(itemMetadataSet); - auto *resource = new qtlib::NetworkResource(itemKey, QUrl(url), true, this); - connect(resource, &qtlib::NetworkResource::downloadProgress, this, &ItemHandler::downloadProgress); - connect(resource, &qtlib::NetworkResource::finished, this, &ItemHandler::networkResourceFinished); + auto *resource = new qtil::NetworkResource(itemKey, QUrl(url), true, this); + connect(resource, &qtil::NetworkResource::downloadProgress, this, &ItemHandler::downloadProgress); + connect(resource, &qtil::NetworkResource::finished, this, &ItemHandler::networkResourceFinished); resource->get(); result["status"] = QString("success_downloadstart"); @@ -146,8 +146,8 @@ void ItemHandler::uninstall(const QString &itemKey) auto installedItem = configHandler_->getUsrConfigInstalledItems()[itemKey].toObject(); auto installType = installedItem["install_type"].toString(); - qtlib::Dir destDir; -#ifdef QTLIB_UNIX + qtil::Dir destDir; +#ifdef QTIL_OS_UNIX destDir.setPath(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString()); for (const auto &filename : installedItem["files"].toArray()) { @@ -155,7 +155,7 @@ void ItemHandler::uninstall(const QString &itemKey) // plasmapkg: Installation process has should be saved plasmapkg into destination directory - qtlib::Package package(fileInfo.filePath()); + qtil::Package package(fileInfo.filePath()); // Uninstall if (installType == "bin") { @@ -186,10 +186,10 @@ void ItemHandler::uninstall(const QString &itemKey) // Remove file if (fileInfo.isDir()) { - qtlib::Dir(fileInfo.filePath()).remove(); + qtil::Dir(fileInfo.filePath()).remove(); } else { - qtlib::File(fileInfo.filePath()).remove(); + qtil::File(fileInfo.filePath()).remove(); } } #else @@ -198,10 +198,10 @@ void ItemHandler::uninstall(const QString &itemKey) for (const auto &filename : installedItem["files"].toArray()) { QFileInfo fileInfo(destDir.path() + "/" + filename.toString()); if (fileInfo.isDir()) { - qtlib::Dir(fileInfo.filePath()).remove(); + qtil::Dir(fileInfo.filePath()).remove(); } else { - qtlib::File(fileInfo.filePath()).remove(); + qtil::File(fileInfo.filePath()).remove(); } } #endif @@ -214,7 +214,7 @@ void ItemHandler::uninstall(const QString &itemKey) emit uninstallFinished(result); } -void ItemHandler::networkResourceFinished(qtlib::NetworkResource *resource) +void ItemHandler::networkResourceFinished(qtil::NetworkResource *resource) { auto itemKey = resource->id(); @@ -252,7 +252,7 @@ void ItemHandler::setMetadataSet(const QJsonObject &metadataSet) emit metadataSetChanged(); } -void ItemHandler::saveDownloadedFile(qtlib::NetworkResource *resource) +void ItemHandler::saveDownloadedFile(qtil::NetworkResource *resource) { auto itemKey = resource->id(); @@ -271,9 +271,9 @@ void ItemHandler::saveDownloadedFile(qtlib::NetworkResource *resource) auto filename = metadata["filename"].toString(); auto installType = metadata["install_type"].toString(); - qtlib::Dir destDir(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString()); + qtil::Dir destDir(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString()); destDir.make(); - qtlib::File destFile(destDir.path() + "/" + filename); + qtil::File destFile(destDir.path() + "/" + filename); if (destFile.exists()) { auto filenamePrefix = QString::number(QDateTime::currentMSecsSinceEpoch()) + "_"; @@ -295,7 +295,7 @@ void ItemHandler::saveDownloadedFile(qtlib::NetworkResource *resource) resource->deleteLater(); } -void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource) +void ItemHandler::installDownloadedFile(qtil::NetworkResource *resource) { // Installation pre-process auto itemKey = resource->id(); @@ -316,13 +316,13 @@ void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource) auto installType = metadata["install_type"].toString(); QString tempDirPrefix = "temp_" + filename; - qtlib::Dir tempDir(qtlib::Dir::genericCachePath() + "/" + qtil::Dir tempDir(qtil::Dir::genericCachePath() + "/" + configHandler_->getAppConfigApplication()["id"].toString() + "/" + tempDirPrefix); tempDir.make(); - qtlib::Dir tempDestDir(tempDir.path() + "/dest"); + qtil::Dir tempDestDir(tempDir.path() + "/dest"); tempDestDir.make(); - qtlib::Package package(tempDir.path() + "/" + filename); + qtil::Package package(tempDir.path() + "/" + filename); if (!resource->saveData(package.path())) { result["status"] = QString("error_save"); @@ -342,8 +342,8 @@ void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource) result["message"] = tr("Installing"); emit installStarted(result); - qtlib::Dir destDir; -#ifdef QTLIB_UNIX + qtil::Dir destDir; +#ifdef QTIL_OS_UNIX destDir.setPath(configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString()); // plasmapkg: Need to save package to remove installed files later @@ -399,7 +399,7 @@ void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource) #else destDir.setPath(configHandler_->getAppConfigInstallTypes()[installType].toObject()["generic_destination"].toString()); - if (qtlib::File(package.path()).copy(tempDestDir.path() + "/" + filename)) { + if (qtil::File(package.path()).copy(tempDestDir.path() + "/" + filename)) { result["message"] = tr("The file has been installed"); } else { @@ -424,10 +424,10 @@ void ItemHandler::installDownloadedFile(qtlib::NetworkResource *resource) } if (fileInfo.isDir()) { - qtlib::Dir(fileInfo.filePath()).move(destDir.path() + "/" + destFilename); + qtil::Dir(fileInfo.filePath()).move(destDir.path() + "/" + destFilename); } else { - qtlib::File(fileInfo.filePath()).move(destDir.path() + "/" + destFilename); + qtil::File(fileInfo.filePath()).move(destDir.path() + "/" + destFilename); } installedFiles.append(QJsonValue(destFilename)); diff --git a/app/src/handlers/itemhandler.h b/app/src/handlers/itemhandler.h index 83ebe3a..79f5906 100644 --- a/app/src/handlers/itemhandler.h +++ b/app/src/handlers/itemhandler.h @@ -3,7 +3,7 @@ #include <QObject> #include <QJsonObject> -namespace qtlib { +namespace qtil { class NetworkResource; } @@ -37,13 +37,13 @@ public slots: void uninstall(const QString &itemKey); private slots: - void networkResourceFinished(qtlib::NetworkResource *resource); + void networkResourceFinished(qtil::NetworkResource *resource); private: void setMetadataSet(const QJsonObject &metadataSet); - void saveDownloadedFile(qtlib::NetworkResource *resource); - void installDownloadedFile(qtlib::NetworkResource *resource); + void saveDownloadedFile(qtil::NetworkResource *resource); + void installDownloadedFile(qtil::NetworkResource *resource); ConfigHandler *configHandler_; QJsonObject metadataSet_; diff --git a/app/src/handlers/ocsapihandler.cpp b/app/src/handlers/ocsapihandler.cpp index eccfdd7..fcf7356 100644 --- a/app/src/handlers/ocsapihandler.cpp +++ b/app/src/handlers/ocsapihandler.cpp @@ -3,7 +3,7 @@ #include <QStringList> #include <QJsonValue> -#include "qtlib_ocsapi.h" +#include "qtil_ocsapi.h" #include "handlers/confighandler.h" @@ -13,7 +13,7 @@ OcsApiHandler::OcsApiHandler(ConfigHandler *configHandler, QObject *parent) bool OcsApiHandler::addProviders(const QString &providerFileUrl) const { - auto providers = qtlib::OcsApi::getProviderFile(QUrl(providerFileUrl)); + auto providers = qtil::OcsApi::getProviderFile(QUrl(providerFileUrl)); if (!providers.isEmpty()) { for (const auto &providerValue : providers) { auto provider = providerValue.toObject(); @@ -60,7 +60,7 @@ bool OcsApiHandler::updateCategories(const QString &providerKey, bool force) con } auto baseUrl = providers[providerKey].toObject()["location"].toString(); - auto response = qtlib::OcsApi(baseUrl, QUrl(baseUrl)).getContentCategories(); + auto response = qtil::OcsApi(baseUrl, QUrl(baseUrl)).getContentCategories(); if (!response.contains("data")) { return false; @@ -185,7 +185,7 @@ QJsonObject OcsApiHandler::getContents(const QString &providerKeys, const QStrin query.addQueryItem("sortmode", sortmode); query.addQueryItem("pagesize", QString::number(pagesize)); query.addQueryItem("page", QString::number(page)); - responseSet[providerKey] = qtlib::OcsApi(baseUrl, QUrl(baseUrl)).getContentDataSet(query); + responseSet[providerKey] = qtil::OcsApi(baseUrl, QUrl(baseUrl)).getContentDataSet(query); } } @@ -198,7 +198,7 @@ QJsonObject OcsApiHandler::getContent(const QString &providerKey, const QString auto providers = configHandler_->getUsrConfigProviders(); if (providers.contains(providerKey)) { auto baseUrl = providers[providerKey].toObject()["location"].toString(); - response = qtlib::OcsApi(baseUrl, QUrl(baseUrl)).getContentData(contentId); + response = qtil::OcsApi(baseUrl, QUrl(baseUrl)).getContentData(contentId); } return response; } diff --git a/app/src/handlers/systemhandler.cpp b/app/src/handlers/systemhandler.cpp index 32cc911..e732fa3 100644 --- a/app/src/handlers/systemhandler.cpp +++ b/app/src/handlers/systemhandler.cpp @@ -3,13 +3,13 @@ #include <QUrl> #include <QDesktopServices> -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX #include <QFileInfo> #include <QProcess> #endif #ifdef Q_OS_ANDROID -#include "qtlib_package.h" +#include "qtil_package.h" #endif SystemHandler::SystemHandler(QObject *parent) @@ -18,7 +18,7 @@ SystemHandler::SystemHandler(QObject *parent) bool SystemHandler::isUnix() const { -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX return true; #endif return false; @@ -42,7 +42,7 @@ bool SystemHandler::openUrl(const QString &url) const path.replace("file://localhost", "", Qt::CaseInsensitive); path.replace("file://", "", Qt::CaseInsensitive); -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX if ((path.endsWith(".appimage", Qt::CaseInsensitive) || path.endsWith(".exe", Qt::CaseInsensitive)) && QFileInfo(path).isExecutable()) { return QProcess::startDetached(path); @@ -51,7 +51,7 @@ bool SystemHandler::openUrl(const QString &url) const #ifdef Q_OS_ANDROID if (path.endsWith(".apk", Qt::CaseInsensitive)) { - return qtlib::Package(path).installAsApk(); + return qtil::Package(path).installAsApk(); } #endif diff --git a/app/src/handlers/updatehandler.cpp b/app/src/handlers/updatehandler.cpp index 0f73b05..717495a 100644 --- a/app/src/handlers/updatehandler.cpp +++ b/app/src/handlers/updatehandler.cpp @@ -5,11 +5,11 @@ #include <QJsonArray> #include <QDateTime> -#include "qtlib_file.h" +#include "qtil_file.h" #include "handlers/confighandler.h" -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX #include "updaters/appimageupdater.h" #endif @@ -38,7 +38,7 @@ void UpdateHandler::checkAll() auto installType = installedItem["install_type"].toString(); QString filePath = ""; -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX filePath = configHandler_->getAppConfigInstallTypes()[installType].toObject()["destination"].toString() + "/" + filename; #else filePath = configHandler_->getAppConfigInstallTypes()[installType].toObject()["generic_destination"].toString() + "/" + filename; @@ -47,7 +47,7 @@ void UpdateHandler::checkAll() QString updateMethod = ""; if (installType == "bin") { -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX if (filePath.endsWith(".appimage", Qt::CaseInsensitive)) { if (AppImageUpdater(itemKey, filePath).checkForChanges()) { updateMethod = "appimageupdate"; @@ -86,7 +86,7 @@ void UpdateHandler::update(const QString &itemKey) auto updateMethod = updateAvailableItems[itemKey].toObject()["update_method"].toString(); -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX if (updateMethod == "appimageupdate") { updateAppImage(itemKey); } @@ -96,7 +96,7 @@ void UpdateHandler::update(const QString &itemKey) #endif } -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater) { auto itemKey = updater->id(); @@ -124,7 +124,7 @@ void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater) configHandler_->setUsrConfigInstalledItemsItem(installedItemKey, installedItem); if (newFilename != filename) { - qtlib::File(updater->path()).remove(); + qtil::File(updater->path()).remove(); } configHandler_->removeUsrConfigUpdateAvailableItemsItem(itemKey); @@ -134,7 +134,7 @@ void UpdateHandler::appImageUpdaterFinished(AppImageUpdater *updater) } #endif -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX void UpdateHandler::updateAppImage(const QString &itemKey) { auto updateAvailableItem = configHandler_->getUsrConfigUpdateAvailableItems()[itemKey].toObject(); diff --git a/app/src/handlers/updatehandler.h b/app/src/handlers/updatehandler.h index 813608f..4d14b6f 100644 --- a/app/src/handlers/updatehandler.h +++ b/app/src/handlers/updatehandler.h @@ -5,7 +5,7 @@ class ConfigHandler; -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX class AppImageUpdater; #endif @@ -28,12 +28,12 @@ public slots: void update(const QString &itemKey); private slots: -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX void appImageUpdaterFinished(AppImageUpdater *updater); #endif private: -#ifdef QTLIB_UNIX +#ifdef QTIL_OS_UNIX void updateAppImage(const QString &itemKey); #endif diff --git a/app/src/websockets/websocketserver.cpp b/app/src/websockets/websocketserver.cpp index 5f1afa9..0c52dab 100644 --- a/app/src/websockets/websocketserver.cpp +++ b/app/src/websockets/websocketserver.cpp @@ -4,7 +4,7 @@ #include <QWebSocketServer> #include <QWebSocket> -#include "qtlib_json.h" +#include "qtil_json.h" #include "handlers/confighandler.h" #include "handlers/systemhandler.h" @@ -108,7 +108,7 @@ void WebSocketServer::wsTextMessageReceived(const QString &message) { auto *wsClient = qobject_cast<QWebSocket *>(sender()); if (wsClient) { - qtlib::Json json(message.toUtf8()); + qtil::Json json(message.toUtf8()); if (json.isObject()) { auto object = json.toObject(); receiveMessage(object["id"].toString(), object["func"].toString(), object["data"].toArray()); @@ -120,7 +120,7 @@ void WebSocketServer::wsBinaryMessageReceived(const QByteArray &message) { auto *wsClient = qobject_cast<QWebSocket *>(sender()); if (wsClient) { - qtlib::Json json(message); + qtil::Json json(message); if (json.isObject()) { auto object = json.toObject(); receiveMessage(object["id"].toString(), object["func"].toString(), object["data"].toArray()); @@ -411,7 +411,7 @@ void WebSocketServer::sendMessage(const QString &id, const QString &func, const object["func"] = func; object["data"] = data; - auto binaryMessage = qtlib::Json(object).toJson(); + auto binaryMessage = qtil::Json(object).toJson(); auto textMessage = QString::fromUtf8(binaryMessage); for (auto *wsClient : wsClients_) { diff --git a/lib/lib.pri b/lib/lib.pri index 9f21473..5451021 100644 --- a/lib/lib.pri +++ b/lib/lib.pri @@ -1,4 +1,4 @@ -include($${PWD}/qtlib/qtlib.pri) +include($${PWD}/qtil/qtil.pri) unix:!ios:!android { INCLUDEPATH += $${PWD}/AppImageUpdate/include diff --git a/scripts/prepare.sh b/scripts/prepare.sh index 3b494b9..433a622 100644 --- a/scripts/prepare.sh +++ b/scripts/prepare.sh @@ -2,8 +2,8 @@ PROJDIR="$(cd "$(dirname "${0}")/../" && pwd)" -if [ ! -d "${PROJDIR}/lib/qtlib" ]; then - git clone https://github.com/akiraohgaki/qtlib.git -b release-0.2.1 --single-branch --depth=1 "${PROJDIR}/lib/qtlib" +if [ ! -d "${PROJDIR}/lib/qtil" ]; then + git clone https://github.com/akiraohgaki/qtil.git -b release-0.3.0 --single-branch --depth=1 "${PROJDIR}/lib/qtil" fi if [ ! -d "${PROJDIR}/lib/AppImageUpdate" ]; then -- GitLab