Skip to content
Snippets Groups Projects
Commit 25abbe5e authored by akiraohgaki's avatar akiraohgaki Committed by GitHub
Browse files

Merge pull request #43 from ocs-url/develop

Develop
parents 3a3ee907 744a0019
No related branches found
No related tags found
No related merge requests found
Showing
with 743 additions and 106 deletions
*.pro.user
pkg/build/
build_*/
lib/qtlib/
language: cpp
sudo: required
dist: trusty
before_install:
- sudo add-apt-repository -y ppa:beineri/opt-qt57-trusty
- sudo apt-get update -qq
install:
- sudo apt-get -y install build-essential fuse zsync desktop-file-utils
- sudo apt-get -y install qt57base qt57svg qt57declarative qt57quickcontrols
# Replace linuxdeployqt download URL to official download URL when the stable version released
- curl -L -o linuxdeployqt https://dl.dropboxusercontent.com/u/150776/temp/linuxdeployqt-799f704-x86-64.appimage
- sudo install -m 755 -p linuxdeployqt /usr/local/bin/linuxdeployqt
- rm linuxdeployqt
before_script:
- sudo modprobe fuse
- source /opt/qt57/bin/qt57-env.sh
script:
- sh ./pkg/build.sh appimage
after_script:
- appimage_file="$(ls ./pkg/build/*.AppImage)"
- [ -f "${appimage_file}" ] && curl -T "${appimage_file}" "https://transfer.sh/${appimage_file}"
# xdgurl
# ocs-url
An install helper program for desktop stuff.
An install helper program for items served on OpenCollaborationServices (OCS).
Copyright: 2016-2017, Akira Ohgaki
......@@ -10,6 +10,6 @@ Download Linux package from:
https://www.linux-apps.com/p/1136805/
And please check the xdgurl wiki for more information.
And please check the ocs-url wiki for more information.
https://github.com/xdgurl/xdgurl/wiki
https://github.com/ocs-url/ocs-url/wiki
......@@ -6,12 +6,17 @@ QT += \
svg
HEADERS += \
$${PWD}/handlers/xdgurlhandler.h
$${PWD}/src/handlers/confighandler.h \
$${PWD}/src/handlers/ocsurlhandler.h
SOURCES += \
$${PWD}/main.cpp \
$${PWD}/handlers/xdgurlhandler.cpp
$${PWD}/src/main.cpp \
$${PWD}/src/handlers/confighandler.cpp \
$${PWD}/src/handlers/ocsurlhandler.cpp
RESOURCES += \
$${PWD}/configs/configs.qrc \
$${PWD}/images/images.qrc \
$${PWD}/qml/qml.qrc
INCLUDEPATH += $${PWD}/src
{
"id": "ocs-url",
"name": "ocs-url",
"version": "3.0.0",
"organization": "ocs-url",
"domain": "com.ocs-url.ocs-url",
"icon": ":/desktop/ocs-url.svg",
"description": "An install helper program for items served on OpenCollaborationServices (OCS).",
"license": "GPL-3+",
"author": "Akira Ohgaki",
"contact": "akiraohgaki@gmail.com",
"homepage": "https://github.com/ocs-url/ocs-url"
}
<RCC>
<qresource prefix="/configs">
<file>application.json</file>
<file>destinations.json</file>
<file>destinations_alias.json</file>
<file>install_types.json</file>
<file>install_types_alias.json</file>
</qresource>
</RCC>
{
"bin": {
"name": "Softwares",
"destination": "$HOME/.local/bin",
"generic_destination": "$APP_DATA/bin"
},
"downloads": {
"name": "Downloads",
"destination": "$HOME/Downloads",
"generic_destination": "$APP_DATA/downloads"
},
"documents": {
"name": "Documents",
"destination": "$HOME/Documents",
"generic_destination": "$APP_DATA/documents"
},
"pictures": {
"name": "Pictures",
"destination": "$HOME/Pictures",
"generic_destination": "$APP_DATA/pictures"
},
"music": {
"name": "Music",
"destination": "$HOME/Music",
"generic_destination": "$APP_DATA/music"
},
"videos": {
"name": "Videos",
"destination": "$HOME/Videos",
"generic_destination": "$APP_DATA/videos"
},
"wallpapers": {
"name": "Wallpapers",
"destination": "$XDG_DATA_HOME/wallpapers",
"generic_destination": "$APP_DATA/wallpapers"
},
"fonts": {
"name": "Fonts",
"destination": "$HOME/.fonts",
"generic_destination": "$APP_DATA/fonts"
},
"cursors": {
"name": "Cursors",
"destination": "$HOME/.icons",
"generic_destination": "$APP_DATA/cursors"
},
"icons": {
"name": "Icons",
"destination": "$XDG_DATA_HOME/icons",
"generic_destination": "$APP_DATA/icons"
},
"emoticons": {
"name": "Emoticons",
"destination": "$XDG_DATA_HOME/emoticons",
"generic_destination": "$APP_DATA/emoticons"
},
"themes": {
"name": "Desktop Themes",
"destination": "$HOME/.themes",
"generic_destination": "$APP_DATA/themes"
},
"emerald_themes": {
"name": "Emerald Themes",
"destination": "$HOME/.emerald/themes",
"generic_destination": "$APP_DATA/emerald_themes"
},
"enlightenment_themes": {
"name": "Enlightenment Themes",
"destination": "$HOME/.e/e/themes",
"generic_destination": "$APP_DATA/enlightenment_themes"
},
"enlightenment_backgrounds": {
"name": "Enlightenment Backgrounds",
"destination": "$HOME/.e/e/backgrounds",
"generic_destination": "$APP_DATA/enlightenment_backgrounds"
},
"fluxbox_styles": {
"name": "Fluxbox Styles",
"destination": "$HOME/.fluxbox/styles",
"generic_destination": "$APP_DATA/fluxbox_styles"
},
"pekwm_themes": {
"name": "PekWM Themes",
"destination": "$HOME/.pekwm/themes",
"generic_destination": "$APP_DATA/pekwm_themes"
},
"icewm_themes": {
"name": "IceWM Themes",
"destination": "$HOME/.icewm/themes",
"generic_destination": "$APP_DATA/icewm_themes"
},
"plasma_plasmoids": {
"name": "Plasma Plasmoids",
"destination": "$XDG_DATA_HOME/plasma/plasmoids",
"generic_destination": "$APP_DATA/plasma_plasmoids"
},
"plasma_look_and_feel": {
"name": "Plasma Look and Feel",
"destination": "$XDG_DATA_HOME/plasma/look-and-feel",
"generic_destination": "$APP_DATA/plasma_look_and_feel"
},
"plasma_desktopthemes": {
"name": "Plasma Desktop Themes",
"destination": "$XDG_DATA_HOME/plasma/desktoptheme",
"generic_destination": "$APP_DATA/plasma_desktopthemes"
},
"kwin_effects": {
"name": "KWin Effects",
"destination": "$XDG_DATA_HOME/kwin/effects",
"generic_destination": "$APP_DATA/kwin_effects"
},
"kwin_scripts": {
"name": "KWin Scripts",
"destination": "$XDG_DATA_HOME/kwin/scripts",
"generic_destination": "$APP_DATA/kwin_scripts"
},
"kwin_tabbox": {
"name": "KWin Window Switcher",
"destination": "$XDG_DATA_HOME/kwin/tabbox",
"generic_destination": "$APP_DATA/kwin_tabbox"
},
"aurorae_themes": {
"name": "Aurorae Themes",
"destination": "$XDG_DATA_HOME/aurorae/themes",
"generic_destination": "$APP_DATA/aurorae_themes"
},
"dekorator_themes": {
"name": "deKorator Themes",
"destination": "$XDG_DATA_HOME/deKorator/themes",
"generic_destination": "$APP_DATA/dekorator_themes"
},
"qtcurve": {
"name": "QtCurve Themes",
"destination": "$XDG_DATA_HOME/QtCurve",
"generic_destination": "$APP_DATA/qtcurve"
},
"color_schemes": {
"name": "KDE Color Schemes",
"destination": "$XDG_DATA_HOME/color-schemes",
"generic_destination": "$APP_DATA/color_schemes"
},
"gnome_shell_extensions": {
"name": "Gnome Shell Extensions",
"destination": "$XDG_DATA_HOME/gnome-shell/extensions",
"generic_destination": "$APP_DATA/gnome_shell_extensions"
},
"cinnamon_applets": {
"name": "Cinnamon Applets",
"destination": "$XDG_DATA_HOME/cinnamon/applets",
"generic_destination": "$APP_DATA/cinnamon_applets"
},
"cinnamon_desklets": {
"name": "Cinnamon Desklets",
"destination": "$XDG_DATA_HOME/cinnamon/desklets",
"generic_destination": "$APP_DATA/cinnamon_desklets"
},
"cinnamon_extensions": {
"name": "Cinnamon Extensions",
"destination": "$XDG_DATA_HOME/cinnamon/extensions",
"generic_destination": "$APP_DATA/cinnamon_extensions"
},
"nautilus_scripts": {
"name": "Nautilus Scripts",
"destination": "$XDG_DATA_HOME/nautilus/scripts",
"generic_destination": "$APP_DATA/nautilus_scripts"
},
"amarok_scripts": {
"name": "Amarok Scripts",
"destination": "$KDEHOME/share/apps/amarok/scripts",
"generic_destination": "$APP_DATA/amarok_scripts"
},
"yakuake_skins": {
"name": "Yakuake Skins",
"destination": "$KDEHOME/share/apps/yakuake/skins",
"generic_destination": "$APP_DATA/yakuake_skins"
},
"cairo_clock_themes": {
"name": "Cairo-Clock Themes",
"destination": "$HOME/.cairo-clock/themes",
"generic_destination": "$APP_DATA/cairo_clock_themes"
},
"books": {
"name": "Books",
"destination": "$APP_DATA/books",
"generic_destination": "$APP_DATA/books"
},
"comics": {
"name": "Comics",
"destination": "$APP_DATA/comics",
"generic_destination": "$APP_DATA/comics"
}
}
{
"gnome_shell_themes": {
"base": "themes",
"name": "Gnome Shell Themes"
},
"cinnamon_themes": {
"base": "themes",
"name": "Cinnamon Themes"
},
"gtk2_themes": {
"base": "themes",
"name": "GTK2 Themes"
},
"gtk3_themes": {
"base": "themes",
"name": "GTK3 Themes"
},
"metacity_themes": {
"base": "themes",
"name": "Metacity Themes"
},
"xfwm4_themes": {
"base": "themes",
"name": "XFWM4 Themes"
},
"openbox_themes": {
"base": "themes",
"name": "Openbox Themes"
},
"kvantum_themes": {
"base": "themes",
"name": "Kvantum Themes"
},
"compiz_themes": {
"base": "emerald_themes",
"name": "Compiz Themes"
},
"beryl_themes": {
"base": "emerald_themes",
"name": "Beryl Themes"
},
"plasma4_plasmoids": {
"base": "plasma_plasmoids",
"name": "Plasma4 Plasmoids"
},
"plasma5_plasmoids": {
"base": "plasma_plasmoids",
"name": "Plasma5 Plasmoids"
},
"plasma5_look_and_feel": {
"base": "plasma_look_and_feel",
"name": "Plasma5 Look and Feel"
},
"plasma5_desktopthemes": {
"base": "plasma_desktopthemes",
"name": "Plasma5 Desktop Themes"
},
"plasma_color_schemes": {
"base": "color_schemes",
"name": "Plasma Color Schemes"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="128" height="128" viewBox="0, 0, 128, 128">
<g id="icon">
<path d="M64,8 C33.072,8 8,33.072 8,64 C8,94.928 33.072,120 64,120 C94.928,120 120,94.928 120,64 C120,33.072 94.928,8 64,8 z M64,24 C68.418,24 72,27.582 72,32 C72,36.418 68.418,40 64,40 C59.582,40 56,36.418 56,32 C56,27.582 59.582,24 64,24 z M48,48 L72,48 L72,96 L80,96 L80,104 L48,104 L48,96 L56,96 L56,56 L48,56 L48,48 z" fill="#000000" id="dialog-information"/>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="128" height="128" viewBox="0, 0, 128, 128">
<g id="icon">
<path d="M64,16 L8,112 L120,112 L64,16 z M56,48 L72,48 L72,80 L56,80 L56,48 z M64,88 C68.418,88 72,91.582 72,96 C72,100.418 68.418,104 64,104 C59.582,104 56,100.418 56,96 C56,91.582 59.582,88 64,88 z" fill="#000000" id="dialog-warning"/>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="128" height="128" viewBox="0, 0, 128, 128">
<g id="icon">
<path d="M64,8 C33.072,8 8,33.072 8,64 C8,94.928 33.072,120 64,120 C94.928,120 120,94.928 120,64 C120,33.072 94.928,8 64,8 z M80,32 L104,32 L56,104 L32,80 L32,56 L56,80 L80,32 z" fill="#000000" id="emblem-default"/>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="128" height="128" viewBox="0, 0, 128, 128">
<g id="icon">
<path d="M40,8 L40,48 L16,48 L64,96 L112,48 L88,48 L88,8 L40,8 z M8,72 L8,120 L120,120 L120,72 L104,72 L104,104 L24,104 L24,72 L8,72 z" fill="#000000" id="emblem-downloads"/>
</g>
</svg>
<RCC>
<qresource prefix="/images">
<file>icons/dialog-information.svg</file>
<file>icons/dialog-warning.svg</file>
<file>icons/emblem-default.svg</file>
<file>icons/emblem-downloads.svg</file>
</qresource>
</RCC>
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
import "ui" as Ui
import "scripts/Utility.js" as Utility
ApplicationWindow {
id: app
title: configHandler.getAppConfigApplication().name
visible: true
width: 400
minimumWidth: width
maximumWidth: width
height: 200
minimumHeight: height
maximumHeight: height
function init() {
var metadata = ocsUrlHandler.metadata();
var primaryMessages = {
"success_download": qsTr("Download successfull"),
"success_install": qsTr("Installation successfull"),
"error_validation": qsTr("Validation error"),
"error_network": qsTr("Network error"),
"error_save": qsTr("Saving file failed"),
"error_install": qsTr("Installation failed")
};
ocsUrlHandler.started.connect(function() {
confirmDialog.close();
progressDialog.open();
});
ocsUrlHandler.finishedWithSuccess.connect(function(result) {
progressDialog.close();
infoDialog.primaryText = primaryMessages[result.status];
infoDialog.informativeText = metadata.filename;
infoDialog.detailedText = result.message;
infoDialog.open();
});
ocsUrlHandler.finishedWithError.connect(function(result) {
progressDialog.close();
errorDialog.primaryText = primaryMessages[result.status];
errorDialog.informativeText = metadata.filename;
errorDialog.detailedText = result.message;
errorDialog.open();
});
ocsUrlHandler.downloadProgress.connect(function(id, bytesReceived, bytesTotal) {
progressDialog.primaryText = qsTr("Downloading");
progressDialog.informativeText = metadata.filename;
progressDialog.detailedContentLoader.item.progressBar = bytesReceived / bytesTotal;
progressDialog.detailedContentLoader.item.progressText
= Utility.convertByteToHumanReadable(bytesReceived)
+ " / " + Utility.convertByteToHumanReadable(bytesTotal);
});
if (ocsUrlHandler.isValid()) {
if (metadata.command === "download") {
confirmDialog.primaryText = qsTr("Do you want to download?");
}
else if (metadata.command === "install") {
confirmDialog.primaryText = qsTr("Do you want to install?");
}
confirmDialog.informativeText = metadata.filename;
confirmDialog.detailedText
= qsTr("URL") + ": " + metadata.url + "\n"
+ qsTr("File") + ": " + metadata.filename + "\n"
+ qsTr("Type") + ": " + configHandler.getAppConfigInstallTypes()[metadata.type].name;
confirmDialog.open();
}
else {
errorDialog.primaryText = primaryMessages["error_validation"];
errorDialog.detailedText = qsTr("Invalid OCS-URL");
errorDialog.open();
}
}
function fixWindowSize(dialog) {
if (dialog.visible) {
app.height = dialog.implicitHeight + (dialog.anchors.margins * 2);
}
}
Ui.Dialog {
id: confirmDialog
icon: "qrc:/images/icons/dialog-information.svg"
actionButton.text: qsTr("Details")
actionButton.onClicked: toggleDetails()
acceptButton.text: qsTr("OK")
acceptButton.onClicked: ocsUrlHandler.process()
rejectButton.text: qsTr("Cancel")
rejectButton.onClicked: Qt.quit()
onVisibleChanged: app.fixWindowSize(confirmDialog)
onImplicitHeightChanged: app.fixWindowSize(confirmDialog)
}
Ui.Dialog {
id: infoDialog
icon: "qrc:/images/icons/emblem-default.svg"
actionButton.text: qsTr("Details")
actionButton.onClicked: toggleDetails()
acceptButton.text: qsTr("Open")
acceptButton.onClicked: {
ocsUrlHandler.openDestination();
Qt.quit();
}
rejectButton.text: qsTr("Close")
rejectButton.onClicked: Qt.quit()
onVisibleChanged: app.fixWindowSize(infoDialog)
onImplicitHeightChanged: app.fixWindowSize(infoDialog)
}
Ui.Dialog {
id: errorDialog
icon: "qrc:/images/icons/dialog-warning.svg"
actionButton.text: qsTr("Details")
actionButton.onClicked: toggleDetails()
rejectButton.text: qsTr("Close")
rejectButton.onClicked: Qt.quit()
onVisibleChanged: app.fixWindowSize(errorDialog)
onImplicitHeightChanged: app.fixWindowSize(errorDialog)
}
Component {
id: progressComponent
ColumnLayout {
property alias progressBar: progressBar.value
property alias progressText: progressText.text
anchors.fill: parent
spacing: 4
ProgressBar {
id: progressBar
minimumValue: 0
maximumValue: 1
value: 0
Layout.fillWidth: true
}
Label {
id: progressText
text: ""
Layout.alignment: Qt.AlignRight
}
}
}
Ui.Dialog {
id: progressDialog
icon: "qrc:/images/icons/emblem-downloads.svg"
detailsVisible: true
detailedContentLoader.sourceComponent: progressComponent
rejectButton.text: qsTr("Cancel")
rejectButton.onClicked: Qt.quit()
onVisibleChanged: app.fixWindowSize(progressDialog)
onImplicitHeightChanged: app.fixWindowSize(progressDialog)
}
Component.onCompleted: {
app.init();
}
}
<RCC>
<qresource prefix="/qml">
<file>main.qml</file>
<file>ui/Dialog.qml</file>
<file>scripts/Utility.js</file>
</qresource>
</RCC>
File moved
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
ColumnLayout {
id: dialog
visible: false
anchors.fill: parent
anchors.margins: 12
spacing: 12
property alias icon: icon.source
property alias primaryText: primaryText.text
property alias informativeText: informativeText.text
property alias detailsVisible: details.visible
property alias detailedText: detailedText.text
property alias detailedContentLoader: detailedContentLoader
property alias actionButton: actionButton
property alias acceptButton: acceptButton
property alias rejectButton: rejectButton
function open() {
dialog.visible = true;
}
function close() {
dialog.visible = false;
}
function toggleDetails() {
details.visible = details.visible ? false : true;
}
RowLayout {
Layout.fillWidth: true
spacing: 12
Image {
id: icon
source: ""
visible: source.toString() ? true : false
Layout.preferredWidth: 48
Layout.preferredHeight: 48
sourceSize.width: 128
sourceSize.height: 128
}
ColumnLayout {
Layout.fillWidth: true
spacing: 4
Label {
id: primaryText
text: ""
visible: text ? true : false
Layout.fillWidth: true
wrapMode: Text.WrapAnywhere
font.bold: true
font.pixelSize: 14
}
Label {
id: informativeText
text: ""
visible: text ? true : false
Layout.fillWidth: true
wrapMode: Text.WrapAnywhere
}
}
}
ColumnLayout {
id: details
visible: false
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 12
Label {
id: detailedText
text: ""
visible: text ? true : false
Layout.fillWidth: true
wrapMode: Text.WrapAnywhere
}
Loader {
id: detailedContentLoader
visible: (source.toString() || sourceComponent) ? true : false
Layout.fillWidth: true
}
}
RowLayout {
Layout.fillWidth: true
spacing: 4
Button {
id: actionButton
text: ""
visible: text ? true : false
}
Item {
Layout.fillWidth: true
}
Button {
id: acceptButton
text: ""
visible: text ? true : false
}
Button {
id: rejectButton
text: ""
visible: text ? true : false
}
}
}
#include "confighandler.h"
#include <QStringList>
#include "qtlib_dir.h"
ConfigHandler::ConfigHandler(QObject *parent)
: QObject(parent)
{
appConfig_ = qtlib::Config(":/configs");
}
QJsonObject ConfigHandler::getAppConfigApplication()
{
if (appConfigApplication_.isEmpty()) {
appConfigApplication_ = appConfig_.get("application");
}
return appConfigApplication_;
}
QJsonObject ConfigHandler::getAppConfigInstallTypes()
{
if (appConfigInstallTypes_.isEmpty()) {
QJsonObject installTypes = appConfig_.get("install_types");
foreach (const QString &key, installTypes.keys()) {
QJsonObject installtype = installTypes[key].toObject();
installtype["destination"] = convertPathString(installtype["destination"].toString());
installtype["generic_destination"] = convertPathString(installtype["generic_destination"].toString());
installTypes[key] = installtype;
}
QJsonObject installTypesAlias = appConfig_.get("install_types_alias");
foreach (const QString &key, installTypesAlias.keys()) {
QJsonObject installTypeAlias = installTypesAlias[key].toObject();
QString baseKey = installTypeAlias["base"].toString();
if (installTypes.contains(baseKey)) {
QJsonObject installType = installTypes[baseKey].toObject();
installType["base"] = baseKey;
installType["name"] = installTypeAlias["name"].toString();
installTypes[key] = installType;
}
}
appConfigInstallTypes_ = installTypes;
}
return appConfigInstallTypes_;
}
QString ConfigHandler::convertPathString(const QString &path)
{
QString newPath = path;
if (newPath.contains("$HOME")) {
newPath.replace("$HOME", qtlib::Dir::homePath());
}
else if (newPath.contains("$XDG_DATA_HOME")) {
newPath.replace("$XDG_DATA_HOME", qtlib::Dir::genericDataPath());
}
else if (newPath.contains("$KDEHOME")) {
newPath.replace("$KDEHOME", qtlib::Dir::kdehomePath());
}
else if (newPath.contains("$APP_DATA")) {
newPath.replace("$APP_DATA", qtlib::Dir::genericDataPath() + "/" + getAppConfigApplication()["id"].toString());
}
return newPath;
}
#pragma once
#include <QObject>
#include <QJsonObject>
#include "qtlib_config.h"
class ConfigHandler : public QObject
{
Q_OBJECT
public:
explicit ConfigHandler(QObject *parent = 0);
public slots:
QJsonObject getAppConfigApplication();
QJsonObject getAppConfigInstallTypes();
private:
QString convertPathString(const QString &path);
qtlib::Config appConfig_;
QJsonObject appConfigApplication_;
QJsonObject appConfigInstallTypes_;
};
#include "xdgurlhandler.h"
#include "ocsurlhandler.h"
#include <QUrlQuery>
#include <QDesktopServices>
......@@ -8,45 +8,46 @@
#include "qtlib_networkresource.h"
#include "qtlib_package.h"
XdgUrlHandler::XdgUrlHandler(const QString &xdgUrl, const qtlib::Config &config, QObject *parent)
: QObject(parent), xdgUrl_(xdgUrl), config_(config)
#include "handlers/confighandler.h"
OcsUrlHandler::OcsUrlHandler(const QString &ocsUrl, ConfigHandler *configHandler, QObject *parent)
: QObject(parent), ocsUrl_(ocsUrl), configHandler_(configHandler)
{
parse();
loadDestinations();
}
QString XdgUrlHandler::xdgUrl() const
QString OcsUrlHandler::ocsUrl() const
{
return xdgUrl_;
return ocsUrl_;
}
QJsonObject XdgUrlHandler::metadata() const
QJsonObject OcsUrlHandler::metadata() const
{
return metadata_;
}
void XdgUrlHandler::process()
void OcsUrlHandler::process()
{
// xdgs scheme is a reserved name, so the process of xdgs
// is the same process of the xdg scheme currently.
// ocss scheme is a reserved name, so the process of ocss
// is the same process of the ocs scheme currently.
if (!isValid()) {
QJsonObject result;
result["status"] = QString("error_validation");
result["message"] = QString("Invalid XDG-URL " + xdgUrl_);
result["message"] = tr("Invalid OCS-URL");
emit finishedWithError(result);
return;
}
QString url = metadata_["url"].toString();
qtlib::NetworkResource *resource = new qtlib::NetworkResource(url, QUrl(url), true, this);
connect(resource, &qtlib::NetworkResource::downloadProgress, this, &XdgUrlHandler::downloadProgress);
connect(resource, &qtlib::NetworkResource::finished, this, &XdgUrlHandler::networkResourceFinished);
connect(resource, &qtlib::NetworkResource::downloadProgress, this, &OcsUrlHandler::downloadProgress);
connect(resource, &qtlib::NetworkResource::finished, this, &OcsUrlHandler::networkResourceFinished);
resource->get();
emit started();
}
bool XdgUrlHandler::isValid()
bool OcsUrlHandler::isValid()
{
QString scheme = metadata_["scheme"].toString();
QString command = metadata_["command"].toString();
......@@ -54,23 +55,24 @@ bool XdgUrlHandler::isValid()
QString type = metadata_["type"].toString();
QString filename = metadata_["filename"].toString();
if ((scheme == "xdg" || scheme == "xdgs")
// Still support xdg and xdgs schemes for backward compatibility
if ((scheme == "ocs" || scheme == "ocss" || scheme == "xdg" || scheme == "xdgs")
&& (command == "download" || command == "install")
&& QUrl(url).isValid()
&& destinations_.contains(type)
&& configHandler_->getAppConfigInstallTypes().contains(type)
&& !filename.isEmpty()) {
return true;
}
return false;
}
void XdgUrlHandler::openDestination()
void OcsUrlHandler::openDestination()
{
QString type = metadata_["type"].toString();
QDesktopServices::openUrl(QUrl("file://" + destinations_[type].toString()));
QDesktopServices::openUrl(QUrl("file://" + configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString()));
}
void XdgUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource)
void OcsUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource)
{
if (!resource->isFinishedWithNoError()) {
QJsonObject result;
......@@ -89,12 +91,12 @@ void XdgUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource)
}
}
void XdgUrlHandler::parse()
void OcsUrlHandler::parse()
{
QUrl url(xdgUrl_);
QUrl url(ocsUrl_);
QUrlQuery query(url);
metadata_["scheme"] = QString("xdg");
metadata_["scheme"] = QString("ocs");
metadata_["command"] = QString("download");
metadata_["url"] = QString("");
metadata_["type"] = QString("downloads");
......@@ -125,65 +127,31 @@ void XdgUrlHandler::parse()
}
}
void XdgUrlHandler::loadDestinations()
{
QJsonObject configDestinations = config_.get("destinations");
QJsonObject configDestinationsAlias = config_.get("destinations_alias");
foreach (const QString &key, configDestinations.keys()) {
destinations_[key] = convertPathString(configDestinations[key].toString());
}
foreach (const QString &key, configDestinationsAlias.keys()) {
QString value = configDestinationsAlias[key].toString();
if (destinations_.contains(value)) {
destinations_[key] = destinations_.value(value);
}
}
}
QString XdgUrlHandler::convertPathString(const QString &path)
{
QString newPath = path;
if (newPath.contains("$HOME")) {
newPath.replace("$HOME", qtlib::Dir::homePath());
}
else if (newPath.contains("$XDG_DATA_HOME")) {
newPath.replace("$XDG_DATA_HOME", qtlib::Dir::genericDataPath());
}
else if (newPath.contains("$KDEHOME")) {
newPath.replace("$KDEHOME", qtlib::Dir::kdehomePath());
}
return newPath;
}
void XdgUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
void OcsUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
{
QJsonObject result;
QString type = metadata_["type"].toString();
qtlib::Dir destDir(destinations_[type].toString());
qtlib::Dir destDir(configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString());
destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
if (!resource->saveData(destFile.path())) {
result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + destFile.path());
result["message"] = tr("Failed to save data");
emit finishedWithError(result);
resource->deleteLater();
return;
}
result["status"] = QString("success_download");
result["message"] = QString("The file has been stored into " + destDir.path());
result["message"] = tr("The file has been downloaded");
emit finishedWithSuccess(result);
resource->deleteLater();
}
void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
void OcsUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
{
QJsonObject result;
......@@ -191,7 +159,7 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
if (!resource->saveData(tempFile.path())) {
result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + tempFile.path());
result["message"] = tr("Failed to save data");
emit finishedWithError(result);
resource->deleteLater();
return;
......@@ -199,47 +167,47 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
qtlib::Package package(tempFile.path());
QString type = metadata_["type"].toString();
qtlib::Dir destDir(destinations_[type].toString());
qtlib::Dir destDir(configHandler_->getAppConfigInstallTypes()[type].toObject()["destination"].toString());
destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
if (type == "bin"
&& package.installAsProgram(destFile.path())) {
result["message"] = QString("The file has been installed into " + destDir.path());
result["message"] = tr("The file has been installed as program");
}
else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids")
&& package.installAsPlasmapkg("plasmoid")) {
result["message"] = QString("The plasmoid has been installed");
result["message"] = tr("The plasmoid has been installed");
}
else if ((type == "plasma_look_and_feel" || type == "plasma5_look_and_feel")
&& package.installAsPlasmapkg("lookandfeel")) {
result["message"] = QString("The plasma look and feel has been installed");
result["message"] = tr("The plasma look and feel has been installed");
}
else if ((type == "plasma_desktopthemes" || type == "plasma5_desktopthemes")
&& package.installAsPlasmapkg("theme")) {
result["message"] = QString("The plasma desktop theme has been installed");
result["message"] = tr("The plasma desktop theme has been installed");
}
else if (type == "kwin_effects"
&& package.installAsPlasmapkg("kwineffect")) {
result["message"] = QString("The KWin effect has been installed");
result["message"] = tr("The KWin effect has been installed");
}
else if (type == "kwin_scripts"
&& package.installAsPlasmapkg("kwinscript")) {
result["message"] = QString("The KWin script has been installed");
result["message"] = tr("The KWin script has been installed");
}
else if (type == "kwin_tabbox"
&& package.installAsPlasmapkg("windowswitcher")) {
result["message"] = QString("The KWin window switcher has been installed");
result["message"] = tr("The KWin window switcher has been installed");
}
else if (package.installAsArchive(destDir.path())) {
result["message"] = QString("The archive file has been extracted into " + destDir.path());
result["message"] = tr("The archive file has been extracted");
}
else if (package.installAsFile(destFile.path())) {
result["message"] = QString("The file has been installed into " + destDir.path());
result["message"] = tr("The file has been installed");
}
else {
result["status"] = QString("error_install");
result["message"] = QString("Failed to installation");
result["message"] = tr("Failed to installation");
emit finishedWithError(result);
tempFile.remove();
return;
......
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