Skip to content
Snippets Groups Projects
main.qml 3.05 KiB
Newer Older
akiraohgaki's avatar
akiraohgaki committed
import QtQuick 2.0
akiraohgaki's avatar
akiraohgaki committed
import QtQuick.Window 2.0
akiraohgaki's avatar
akiraohgaki committed
import QtQuick.Dialogs 1.1
akiraohgaki's avatar
akiraohgaki committed

akiraohgaki's avatar
akiraohgaki committed
Window {
akiraohgaki's avatar
akiraohgaki committed
    id: root
    title: Qt.application.name
    width: 400
    height: 200
    minimumWidth: 400
    minimumHeight: 200
    maximumWidth: 800
    maximumHeight: 400
akiraohgaki's avatar
akiraohgaki committed

akiraohgaki's avatar
akiraohgaki committed
    MessageDialog {
        id: confirmDialog
        title: root.title
akiraohgaki's avatar
akiraohgaki committed
        icon: StandardIcon.Question
akiraohgaki's avatar
akiraohgaki committed
        text: ''
akiraohgaki's avatar
akiraohgaki committed
        informativeText: ''
akiraohgaki's avatar
akiraohgaki committed
        detailedText: ''
akiraohgaki's avatar
akiraohgaki committed
        standardButtons: StandardButton.Ok | StandardButton.Cancel
        onAccepted: xdgUrlHandler.process()
        onRejected: Qt.quit()
    }

    MessageDialog {
        id: infoDialog
        title: root.title
akiraohgaki's avatar
akiraohgaki committed
        icon: StandardIcon.Information
akiraohgaki's avatar
akiraohgaki committed
        text: ''
akiraohgaki's avatar
akiraohgaki committed
        informativeText: ''
akiraohgaki's avatar
akiraohgaki committed
        detailedText: ''
        standardButtons: StandardButton.Ok
akiraohgaki's avatar
akiraohgaki committed
        onAccepted: Qt.quit()
    }

    MessageDialog {
        id: errorDialog
        title: root.title
akiraohgaki's avatar
akiraohgaki committed
        icon: StandardIcon.Warning
akiraohgaki's avatar
akiraohgaki committed
        text: ''
akiraohgaki's avatar
akiraohgaki committed
        informativeText: ''
akiraohgaki's avatar
akiraohgaki committed
        detailedText: ''
        standardButtons: StandardButton.Ok
akiraohgaki's avatar
akiraohgaki committed
        onAccepted: Qt.quit()
akiraohgaki's avatar
akiraohgaki committed
    }

akiraohgaki's avatar
akiraohgaki committed
    MessageDialog {
        id: progressDialog
        title: root.title
        contentItem: Rectangle {
            implicitWidth: 400
            implicitHeight: 200
        }
    }

akiraohgaki's avatar
akiraohgaki committed
    Component.onCompleted: {
akiraohgaki's avatar
akiraohgaki committed
        var metadata = JSON.parse(xdgUrlHandler.getMetadata());

akiraohgaki's avatar
akiraohgaki committed
        xdgUrlHandler.finished.connect(function(result) {
            result = JSON.parse(result);
akiraohgaki's avatar
akiraohgaki committed
            var primaryMessages = {
akiraohgaki's avatar
akiraohgaki committed
                'success_download': 'Download successfull',
                'success_install': 'Installation successfull',
                'error_validation': 'Validation error',
                'error_network': 'Network error',
                'error_filetype': 'File type error',
                'error_save': 'Saving file failed',
                'error_install': 'Installation failed'
akiraohgaki's avatar
akiraohgaki committed
            };
akiraohgaki's avatar
akiraohgaki committed
            var primaryMessage = primaryMessages[result.status];

akiraohgaki's avatar
akiraohgaki committed
            if (result.status.split('_').shift() === 'success') {
akiraohgaki's avatar
akiraohgaki committed
                infoDialog.text = primaryMessage;
akiraohgaki's avatar
akiraohgaki committed
                infoDialog.informativeText = metadata.filename;
                infoDialog.detailedText = result.message;
akiraohgaki's avatar
akiraohgaki committed
                infoDialog.open();
            }
akiraohgaki's avatar
akiraohgaki committed
            else {
akiraohgaki's avatar
akiraohgaki committed
                errorDialog.text = primaryMessage;
akiraohgaki's avatar
akiraohgaki committed
                errorDialog.informativeText = metadata.filename;
                errorDialog.detailedText = result.message;
akiraohgaki's avatar
akiraohgaki committed
                errorDialog.open();
            }
        });

        if (xdgUrlHandler.isValid()) {
akiraohgaki's avatar
akiraohgaki committed
            confirmDialog.text = 'Do you want to ' + metadata.command + '?';
            confirmDialog.informativeText = metadata.filename;
            confirmDialog.detailedText = 'URL: ' + metadata.url + '\n\n'
                    + 'File: ' + metadata.filename + '\n\n'
akiraohgaki's avatar
akiraohgaki committed
                    + 'Type: ' + metadata.type;
akiraohgaki's avatar
akiraohgaki committed
            confirmDialog.open();
        }
        else {
akiraohgaki's avatar
akiraohgaki committed
            errorDialog.text = 'Validation error';
            errorDialog.detailedText = 'Invalid XDG-URL ' + xdgUrlHandler.getXdgUrl();
akiraohgaki's avatar
akiraohgaki committed
            errorDialog.open();
        }
    }
akiraohgaki's avatar
akiraohgaki committed
}