Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • akiraohgaki/ocs-url
  • ab3875o/ocs-url
  • dembego3/ocs-url
  • arakun/ocs-url
  • longviauroy/ocs-url
  • rolfen/ocs-url
  • hemm/ocs-url
  • simonsvw0000/ocs-url
  • dfn2/ocs-url
  • rws77/ocs-url
  • bitwalk/ocs-url
  • visdom/ocs-url
  • ricatfarker/ocs-url
  • mussah/ocs-url
  • tigefa/ocs-url
  • cobalt2727/ocs-url
  • ammark226/ocs-url
  • violethaze74/ocs-url
  • armedssault/ocs-url
  • billflick/ocs-url
  • kimblejeremy/ocs-url
  • yuvrajsm/ocs-url
  • wawmart/ocs-url
  • jhefry/ocs-url
  • robcdntruckin/ocs-url
  • bigmake2266/ocs-url
  • kamil-chbeir/ocs-url
  • jocker73/ocs-url
  • laboties/ocs-url
  • smekke61279-522014/ocs-url
  • coolduck/ocs-url
  • zulfikar-lahiya/ocs-url
  • faz-83/ocs-url
  • dado105/ocs-url
34 results
Show changes
Commits on Source (250)
Showing
with 788 additions and 36 deletions
*.pro.user
pkg/build/
build_*/
lib/qtil/
stages:
- build
ubuntu_deb:
stage: build
image: ubuntu:14.04
only:
- master
- /^release\-.+/
script:
- ./scripts/package ubuntu_deb
artifacts:
paths:
- build_*/ocs-url*.deb
expire_in: 2 days
fedora_rpm:
stage: build
image: fedora:20
only:
- master
- /^release\-.+/
script:
- ./scripts/package fedora_rpm
artifacts:
paths:
- build_*/RPMS/x86_64/ocs-url*.rpm
expire_in: 2 days
opensuse_rpm:
stage: build
image: opensuse/leap:42.3
only:
- master
- /^release\-.+/
script:
- ./scripts/package opensuse_rpm
artifacts:
paths:
- build_*/RPMS/x86_64/ocs-url*.rpm
expire_in: 2 days
archlinux_pkg:
stage: build
image: archlinux/base:latest
only:
- master
- /^release\-.+/
script:
- ./scripts/package archlinux_pkg
artifacts:
paths:
- build_*/ocs-url*.pkg.tar.xz
expire_in: 2 days
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 qt57quickcontrols qt57quickcontrols2
# 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.
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
Copyright: 2016-2017, Akira Ohgaki
An install helper program for items served via OpenCollaborationServices (ocs://).
Copyright: 2016-2019, Opendesktop.org
License: GPL-3+
Download Linux package from:
https://www.linux-apps.com/p/1136805/
And please check the xdgurl wiki for more information.
https://www.opendesktop.org/p/1136805/
https://github.com/xdgurl/xdgurl/wiki
And please see docs/* for more information.
CONFIG += c++11
QT += \
core \
gui \
widgets \
qml \
quick \
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.1.0",
"organization": "Opendesktop.org",
"domain": "org.opendesktop.ocs-url",
"icon": ":/desktop/ocs-url.svg",
"description": "An install helper program for items served via OpenCollaborationServices (ocs://).",
"license": "GPL-3+",
"author": "Opendesktop.org",
"contact": "contact@opendesktop.org",
"homepage": "https://git.opendesktop.org/akiraohgaki/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": "Software",
"destination": "$HOME/.local/bin",
"generic_destination": "$APP_DATA/bin"
},
"downloads": {
"name": "Downloads",
"destination": "$XDG_DOWNLOAD_DIR",
"generic_destination": "$APP_DATA/downloads"
},
"documents": {
"name": "Documents",
"destination": "$XDG_DOCUMENTS_DIR",
"generic_destination": "$APP_DATA/documents"
},
"pictures": {
"name": "Pictures",
"destination": "$XDG_PICTURES_DIR",
"generic_destination": "$APP_DATA/pictures"
},
"music": {
"name": "Music",
"destination": "$XDG_MUSIC_DIR",
"generic_destination": "$APP_DATA/music"
},
"videos": {
"name": "Videos",
"destination": "$XDG_VIDEOS_DIR",
"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 successful"),
"success_install": qsTr("Installation successful"),
"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);
app.minimumHeight = app.height;
app.maximumHeight = app.height;
}
}
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>
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 <QStandardPaths>
#include "qtil_dir.h"
ConfigHandler::ConfigHandler(QObject *parent)
: QObject(parent)
{
appConfig_ = Qtil::Config(":/configs");
importAppConfigApplication();
importAppConfigInstallTypes();
}
QJsonObject ConfigHandler::getAppConfigApplication() const
{
return appConfigApplication_;
}
QJsonObject ConfigHandler::getAppConfigInstallTypes() const
{
return appConfigInstallTypes_;
}
void ConfigHandler::importAppConfigApplication()
{
appConfigApplication_ = appConfig_.get("application");
}
void ConfigHandler::importAppConfigInstallTypes()
{
auto installTypes = appConfig_.get("install_types");
for (const auto &key : installTypes.keys()) {
auto installtype = installTypes[key].toObject();
installtype["destination"] = convertPathString(installtype["destination"].toString());
installtype["generic_destination"] = convertPathString(installtype["generic_destination"].toString());
installTypes[key] = installtype;
}
auto installTypesAlias = appConfig_.get("install_types_alias");
for (const auto &key : installTypesAlias.keys()) {
auto installTypeAlias = installTypesAlias[key].toObject();
auto baseKey = installTypeAlias["base"].toString();
if (installTypes.contains(baseKey)) {
auto installType = installTypes[baseKey].toObject();
installType["base"] = baseKey;
installType["name"] = installTypeAlias["name"].toString();
installTypes[key] = installType;
}
}
appConfigInstallTypes_ = installTypes;
}
QString ConfigHandler::convertPathString(const QString &path) const
{
auto newPath = path;
if (newPath.contains("$HOME")) {
newPath.replace("$HOME", Qtil::Dir::homePath());
}
else if (newPath.contains("$XDG_DOCUMENTS_DIR")) {
newPath.replace("$XDG_DOCUMENTS_DIR", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
}
else if (newPath.contains("$XDG_DOWNLOAD_DIR")) {
newPath.replace("$XDG_DOWNLOAD_DIR", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
}
else if (newPath.contains("$XDG_PICTURES_DIR")) {
newPath.replace("$XDG_PICTURES_DIR", QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
}
else if (newPath.contains("$XDG_MUSIC_DIR")) {
newPath.replace("$XDG_MUSIC_DIR", QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
}
else if (newPath.contains("$XDG_VIDEOS_DIR")) {
newPath.replace("$XDG_VIDEOS_DIR", QStandardPaths::writableLocation(QStandardPaths::MoviesLocation));
}
else if (newPath.contains("$XDG_DATA_HOME")) {
newPath.replace("$XDG_DATA_HOME", Qtil::Dir::genericDataPath());
}
else if (newPath.contains("$KDEHOME")) {
newPath.replace("$KDEHOME", Qtil::Dir::kdehomePath());
}
else if (newPath.contains("$APP_DATA")) {
newPath.replace("$APP_DATA", Qtil::Dir::genericDataPath() + "/" + getAppConfigApplication()["id"].toString());
}
return newPath;
}
#pragma once
#include <QObject>
#include <QJsonObject>
#include "qtil_config.h"
class ConfigHandler : public QObject
{
Q_OBJECT
public:
explicit ConfigHandler(QObject *parent = nullptr);
public slots:
QJsonObject getAppConfigApplication() const;
QJsonObject getAppConfigInstallTypes() const;
private:
void importAppConfigApplication();
void importAppConfigInstallTypes();
QString convertPathString(const QString &path) const;
Qtil::Config appConfig_;
QJsonObject appConfigApplication_;
QJsonObject appConfigInstallTypes_;
};