Commit 3a3ee907 authored by akiraohgaki's avatar akiraohgaki Committed by GitHub
Browse files

Merge pull request #33 from xdgurl/development

Development
parents cc784f74 919716d0
......@@ -8,7 +8,7 @@ before_install:
install:
- sudo apt-get -y install build-essential fuse zsync desktop-file-utils
- sudo apt-get -y install qt57base qt57svg qt57quickcontrols qt57quickcontrols2
- 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
......
......@@ -2,7 +2,7 @@
An install helper program for desktop stuff.
Copyright: 2016, Akira Ohgaki
Copyright: 2016-2017, Akira Ohgaki
License: GPL-3+
......
# Maintainer: Akira Ohgaki <akiraohgaki@gmail.com>
pkgname='xdgurl'
pkgver='2.0.2'
pkgver='2.0.3'
pkgrel='1'
pkgdesc='An install helper program for desktop stuff.'
arch=('i686' 'x86_64')
......
......@@ -71,7 +71,7 @@ build_appimage() {
#sudo apt update
#sudo apt install build-essential fuse zsync desktop-file-utils
#sudo apt install qt57base qt57svg qt57quickcontrols qt57quickcontrols2
#sudo apt 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
......
Summary: An install helper program for desktop stuff
Name: xdgurl
Version: 2.0.2
Version: 2.0.3
Release: 1%{?dist}
License: GPLv3+
Group: Applications/Internet
......@@ -37,6 +37,11 @@ make INSTALL_ROOT="%{buildroot}" install
rm -rf %{buildroot}
%changelog
* Wed Jan 25 2017 Akira Ohgaki <akiraohgaki@gmail.com> - 2.0.3-1
- Change installation destination of type bin
- Update qtlib
- Fix for dialog
* Thu Nov 17 2016 Akira Ohgaki <akiraohgaki@gmail.com> - 2.0.2-1
- Update qtlibs
- Small fix
......
xdgurl (2.0.3-0ubuntu1) xenial; urgency=low
* Change installation destination of type bin
* Update qtlib
* Fix for dialog
-- Akira Ohgaki <akiraohgaki@gmail.com> Wed, 25 Jan 2017 19:58:44 +0000
xdgurl (2.0.2-0ubuntu1) xenial; urgency=low
* Update qtlibs
......
......@@ -4,7 +4,7 @@ Upstream-Contact: Akira Ohgaki <akiraohgaki@gmail.com>
Source: https://github.com/xdgurl/xdgurl
Files: *
Copyright: 2016, Akira Ohgaki
Copyright: 2016-2017, Akira Ohgaki
License: GPL-3+
On Debian systems, the full text of the GNU General Public License version 3
can be found in the `/usr/share/common-licenses/GPL-3' file.
......@@ -6,11 +6,11 @@ QT += \
svg
HEADERS += \
$${PWD}/handlers/xdgurl.h
$${PWD}/handlers/xdgurlhandler.h
SOURCES += \
$${PWD}/main.cpp \
$${PWD}/handlers/xdgurl.cpp
$${PWD}/handlers/xdgurlhandler.cpp
RESOURCES += \
$${PWD}/configs/configs.qrc \
......
{
"id": "xdgurl",
"name": "xdgurl",
"version": "2.0.2",
"version": "2.0.3",
"organization": "xdgurl",
"domain": "com.xdgurl.xdgurl",
"icon": ":/desktop/xdgurl.svg",
......
{
"bin": "$HOME/.bin",
"bin": "$HOME/.local/bin",
"downloads": "$HOME/Downloads",
"documents": "$HOME/Documents",
"pictures": "$HOME/Pictures",
......
#include "xdgurl.h"
#include "xdgurlhandler.h"
#include <QUrlQuery>
#include <QDesktopServices>
#include "qtlibs/file.h"
#include "qtlibs/dir.h"
#include "qtlibs/networkresource.h"
#include "qtlibs/package.h"
#include "qtlib_file.h"
#include "qtlib_dir.h"
#include "qtlib_networkresource.h"
#include "qtlib_package.h"
namespace handlers {
XdgUrl::XdgUrl(const QString &xdgUrl, const qtlibs::Config &config, QObject *parent)
XdgUrlHandler::XdgUrlHandler(const QString &xdgUrl, const qtlib::Config &config, QObject *parent)
: QObject(parent), xdgUrl_(xdgUrl), config_(config)
{
parse();
loadDestinations();
}
QString XdgUrl::xdgUrl() const
QString XdgUrlHandler::xdgUrl() const
{
return xdgUrl_;
}
QJsonObject XdgUrl::metadata() const
QJsonObject XdgUrlHandler::metadata() const
{
return metadata_;
}
void XdgUrl::process()
void XdgUrlHandler::process()
{
/**
* xdgs scheme is a reserved name, so the process of xdgs
* is the same process of the xdg scheme currently.
*/
// xdgs scheme is a reserved name, so the process of xdgs
// is the same process of the xdg scheme currently.
if (!isValid()) {
QJsonObject result;
......@@ -43,14 +39,14 @@ void XdgUrl::process()
}
QString url = metadata_["url"].toString();
qtlibs::NetworkResource *resource = new qtlibs::NetworkResource(url, QUrl(url), true, this);
connect(resource, &qtlibs::NetworkResource::downloadProgress, this, &XdgUrl::downloadProgress);
connect(resource, &qtlibs::NetworkResource::finished, this, &XdgUrl::networkResourceFinished);
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);
resource->get();
emit started();
}
bool XdgUrl::isValid()
bool XdgUrlHandler::isValid()
{
QString scheme = metadata_["scheme"].toString();
QString command = metadata_["command"].toString();
......@@ -68,20 +64,20 @@ bool XdgUrl::isValid()
return false;
}
void XdgUrl::openDestination()
void XdgUrlHandler::openDestination()
{
if (!destination_.isEmpty()) {
QDesktopServices::openUrl(QUrl("file://" + destination_));
}
QString type = metadata_["type"].toString();
QDesktopServices::openUrl(QUrl("file://" + destinations_[type].toString()));
}
void XdgUrl::networkResourceFinished(qtlibs::NetworkResource *resource)
void XdgUrlHandler::networkResourceFinished(qtlib::NetworkResource *resource)
{
if (resource->reply()->error() != QNetworkReply::NoError) {
if (!resource->isFinishedWithNoError()) {
QJsonObject result;
result["status"] = QString("error_network");
result["message"] = resource->reply()->errorString();
emit finishedWithError(result);
resource->deleteLater();
return;
}
......@@ -93,7 +89,7 @@ void XdgUrl::networkResourceFinished(qtlibs::NetworkResource *resource)
}
}
void XdgUrl::parse()
void XdgUrlHandler::parse()
{
QUrl url(xdgUrl_);
QUrlQuery query(url);
......@@ -129,7 +125,7 @@ void XdgUrl::parse()
}
}
void XdgUrl::loadDestinations()
void XdgUrlHandler::loadDestinations()
{
QJsonObject configDestinations = config_.get("destinations");
QJsonObject configDestinationsAlias = config_.get("destinations_alias");
......@@ -146,72 +142,70 @@ void XdgUrl::loadDestinations()
}
}
QString XdgUrl::convertPathString(const QString &path)
QString XdgUrlHandler::convertPathString(const QString &path)
{
QString newPath = path;
if (newPath.contains("$HOME")) {
newPath.replace("$HOME", qtlibs::Dir::homePath());
newPath.replace("$HOME", qtlib::Dir::homePath());
}
else if (newPath.contains("$XDG_DATA_HOME")) {
newPath.replace("$XDG_DATA_HOME", qtlibs::Dir::genericDataPath());
newPath.replace("$XDG_DATA_HOME", qtlib::Dir::genericDataPath());
}
else if (newPath.contains("$KDEHOME")) {
newPath.replace("$KDEHOME", qtlibs::Dir::kdehomePath());
newPath.replace("$KDEHOME", qtlib::Dir::kdehomePath());
}
return newPath;
}
void XdgUrl::saveDownloadedFile(qtlibs::NetworkResource *resource)
void XdgUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
{
QJsonObject result;
QString type = metadata_["type"].toString();
QString destination = destinations_[type].toString();
QString path = destination + "/" + metadata_["filename"].toString();
qtlibs::Dir(destination).make();
qtlib::Dir destDir(destinations_[type].toString());
destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
if (!resource->saveData(path)) {
if (!resource->saveData(destFile.path())) {
result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + path);
result["message"] = QString("Failed to save data as " + destFile.path());
emit finishedWithError(result);
resource->deleteLater();
return;
}
destination_ = destination;
result["status"] = QString("success_download");
result["message"] = QString("The file has been stored into " + destination);
result["message"] = QString("The file has been stored into " + destDir.path());
emit finishedWithSuccess(result);
resource->deleteLater();
}
void XdgUrl::installDownloadedFile(qtlibs::NetworkResource *resource)
void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
{
QJsonObject result;
QString tempPath = qtlibs::Dir::tempPath() + "/" + metadata_["filename"].toString();
qtlib::File tempFile(qtlib::Dir::tempPath() + "/" + metadata_["filename"].toString());
if (!resource->saveData(tempPath)) {
if (!resource->saveData(tempFile.path())) {
result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + tempPath);
result["message"] = QString("Failed to save data as " + tempFile.path());
emit finishedWithError(result);
resource->deleteLater();
return;
}
qtlibs::Package package(tempPath);
qtlibs::File tempFile(tempPath);
qtlib::Package package(tempFile.path());
QString type = metadata_["type"].toString();
QString destination = destinations_[type].toString();
QString path = destination + "/" + metadata_["filename"].toString();
qtlibs::Dir(destination).make();
qtlib::Dir destDir(destinations_[type].toString());
destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
if (type == "bin"
&& package.installAsProgram(path)) {
result["message"] = QString("The file has been installed into " + destination);
&& package.installAsProgram(destFile.path())) {
result["message"] = QString("The file has been installed into " + destDir.path());
}
else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids")
&& package.installAsPlasmapkg("plasmoid")) {
......@@ -237,26 +231,23 @@ void XdgUrl::installDownloadedFile(qtlibs::NetworkResource *resource)
&& package.installAsPlasmapkg("windowswitcher")) {
result["message"] = QString("The KWin window switcher has been installed");
}
else if (package.installAsArchive(destination)) {
result["message"] = QString("The archive file has been extracted into " + destination);
else if (package.installAsArchive(destDir.path())) {
result["message"] = QString("The archive file has been extracted into " + destDir.path());
}
else if (package.installAsFile(path)) {
result["message"] = QString("The file has been installed into " + destination);
else if (package.installAsFile(destFile.path())) {
result["message"] = QString("The file has been installed into " + destDir.path());
}
else {
tempFile.remove();
result["status"] = QString("error_install");
result["message"] = QString("Failed to installation");
emit finishedWithError(result);
tempFile.remove();
return;
}
tempFile.remove();
destination_ = destination;
result["status"] = QString("success_install");
emit finishedWithSuccess(result);
}
} // namespace handlers
tempFile.remove();
resource->deleteLater();
}
......@@ -3,26 +3,24 @@
#include <QObject>
#include <QJsonObject>
#include "qtlibs/config.h"
#include "qtlib_config.h"
namespace qtlibs {
namespace qtlib {
class NetworkResource;
}
namespace handlers {
class XdgUrl : public QObject
class XdgUrlHandler : public QObject
{
Q_OBJECT
public:
explicit XdgUrl(const QString &xdgUrl, const qtlibs::Config &config, QObject *parent = 0);
explicit XdgUrlHandler(const QString &xdgUrl, const qtlib::Config &config, QObject *parent = 0);
signals:
void started();
void finishedWithSuccess(const QJsonObject &result);
void finishedWithError(const QJsonObject &result);
void downloadProgress(const qint64 &bytesReceived, const qint64 &bytesTotal);
void finishedWithSuccess(QJsonObject result);
void finishedWithError(QJsonObject result);
void downloadProgress(QString id, qint64 bytesReceived, qint64 bytesTotal);
public slots:
QString xdgUrl() const;
......@@ -33,20 +31,17 @@ public slots:
void openDestination();
private slots:
void networkResourceFinished(qtlibs::NetworkResource *resource);
void networkResourceFinished(qtlib::NetworkResource *resource);
private:
void parse();
void loadDestinations();
QString convertPathString(const QString &path);
void saveDownloadedFile(qtlibs::NetworkResource *resource);
void installDownloadedFile(qtlibs::NetworkResource *resource);
void saveDownloadedFile(qtlib::NetworkResource *resource);
void installDownloadedFile(qtlib::NetworkResource *resource);
QString xdgUrl_;
qtlibs::Config config_;
qtlib::Config config_;
QJsonObject metadata_;
QJsonObject destinations_;
QString destination_;
};
} // namespace handlers
#include <QtGlobal>
//#include <QtGlobal>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QJsonObject>
#include <QCommandLineParser>
#include <QCoreApplication>
//#include <QCoreApplication>
#include <QGuiApplication>
#include <QIcon>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "qtlibs/config.h"
#include "qtlib_config.h"
#include "handlers/xdgurl.h"
#include "handlers/xdgurlhandler.h"
int main(int argc, char *argv[])
{
// Init
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
//#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
// QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//#endif
QGuiApplication app(argc, argv);
qtlibs::Config config(":/configs");
qtlib::Config config(":/configs");
QJsonObject configApplication = config.get("application");
app.setApplicationName(configApplication["name"].toString());
......@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
// Setup QML
QQmlApplicationEngine qmlAppEngine;
QQmlContext *qmlContext = qmlAppEngine.rootContext();
qmlContext->setContextProperty("xdgUrlHandler", new handlers::XdgUrl(xdgUrl, config, &qmlAppEngine));
qmlContext->setContextProperty("xdgUrlHandler", new XdgUrlHandler(xdgUrl, config, &qmlAppEngine));
qmlAppEngine.load(QUrl("qrc:/qml/main.qml"));
return app.exec();
......
......@@ -3,10 +3,10 @@ import QtQuick.Window 2.0
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import 'scripts/Utility.js' as Utility
import "scripts/Utility.js" as Utility
Window {
id: root
id: app
title: Qt.application.name
width: 400
height: 200
......@@ -17,11 +17,11 @@ Window {
MessageDialog {
id: confirmDialog
title: root.title
title: app.title
icon: StandardIcon.Question
text: ''
informativeText: ''
detailedText: ''
text: ""
informativeText: ""
detailedText: ""
standardButtons: StandardButton.Ok | StandardButton.Cancel
onAccepted: xdgUrlHandler.process()
onRejected: Qt.quit()
......@@ -29,11 +29,11 @@ Window {
MessageDialog {
id: infoDialog
title: root.title
title: app.title
icon: StandardIcon.Information
text: ''
informativeText: ''
detailedText: ''
text: ""
informativeText: ""
detailedText: ""
standardButtons: StandardButton.Open | StandardButton.Close
onAccepted: {
xdgUrlHandler.openDestination();
......@@ -44,18 +44,22 @@ Window {
MessageDialog {
id: errorDialog
title: root.title
title: app.title
icon: StandardIcon.Warning
text: ''
informativeText: ''
detailedText: ''
text: ""
informativeText: ""
detailedText: ""
standardButtons: StandardButton.Close
onRejected: Qt.quit()
}
Dialog {
id: progressDialog
title: root.title
title: app.title
property alias primaryLabel: primaryLabel
property alias informativeLabel: informativeLabel
property alias progressBar: progressBar
property alias progressLabel: progressLabel
contentItem: Item {
implicitWidth: 400
implicitHeight: 150
......@@ -65,12 +69,12 @@ Window {
spacing: 8
Label {
id: primaryLabel
text: ''
text: " "
font.bold: true
}
Label {
id: informativeLabel
text: ''
text: " "
}
ProgressBar {
id: progressBar
......@@ -82,32 +86,28 @@ Window {
}
Label {
id: progressLabel
text: ''
text: " "
anchors.right: parent.right
}
Button {
id: cancelButton
text: 'Cancel'
text: "Cancel"
anchors.right: parent.right
onClicked: Qt.quit()
}
}
}
property alias primaryLabel: primaryLabel
property alias informativeLabel: informativeLabel
property alias progressBar: progressBar
property alias progressLabel: progressLabel
}
Component.onCompleted: {
var metadata = xdgUrlHandler.metadata();
var primaryMessages = {
'success_download': 'Download successfull',
'success_install': 'Installation successfull',
'error_validation': 'Validation error',
'error_network': 'Network error',
'error_save': 'Saving file failed',
'error_install': 'Installation failed'
"success_download": "Download successfull",
"success_install": "Installation successfull",
"error_validation": "Validation error",
"error_network": "Network error",
"error_save": "Saving file failed",
"error_install": "Installation failed"
};
xdgUrlHandler.started.connect(function() {
......@@ -130,25 +130,25 @@ Window {
errorDialog.open();
});
xdgUrlHandler.downloadProgress.connect(function(bytesReceived, bytesTotal) {
progressDialog.primaryLabel.text = 'Downloading... ';
xdgUrlHandler.downloadProgress.connect(function(id, bytesReceived, bytesTotal) {
progressDialog.primaryLabel.text = "Downloading... ";
progressDialog.informativeLabel.text = metadata.filename;
progressDialog.progressBar.value = bytesReceived / bytesTotal;
progressDialog.progressLabel.text = Utility.convertByteToHumanReadable(bytesReceived)
+ ' / ' + Utility.convertByteToHumanReadable(bytesTotal)
+ " / " + Utility.convertByteToHumanReadable(bytesTotal)
});
if (xdgUrlHandler.isValid()) {
confirmDialog.text = 'Do you want to ' + metadata.command + '?';
confirmDialog.text = "Do you want to " + metadata.command + "?";
confirmDialog.informativeText = metadata.filename;
confirmDialog.detailedText = 'URL: ' + metadata.url + '\n\n'
+ 'File: ' + metadata.filename + '\n\n'
+ 'Type: ' + metadata.type;
confirmDialog.detailedText = "URL: " + metadata.url + "\n\n"
+ "File: " + metadata.filename + "\n\n"
+ "Type: " + metadata.type;
confirmDialog.open();