0

I am trying to write a simple qml application being a n2n frontend of the client and following the tutorial. This application is first intended for the desktop, but if it can also be used as a phone application for Ubuntu Touch, even better.

You can see the code hereunder, but since I am not really a developer, I have basic questions:

  1. How can I execute a shell command in qml (the n2n programme is run in the terminal with the "edge" command + few parameters).
  2. How can I pass variable in this shell command to be executed?
  3. How to store the parameters in a configfile for the next time?

Thanks in advance for your help!

The code:

import QtQuick 2.0
import Ubuntu.Components 0.1
import "components"
import Ubuntu.Components.ListItems 0.1
import Ubuntu.Components.Popups 0.1

/*!
\brief MainView with a Label and Button elements.
*/

MainView {
id: root
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"

// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "com.ubuntu.developer.No Launchpad user ID configured..n2nedge"

/*
 This property enables the application to change orientation
 when the device is rotated. The default is false.
*/
//automaticOrientation: true

width: units.gu(30)
height: units.gu(50)

property real margins: units.gu(2)
property real buttonWidth: units.gu(9)

Page {
    title: i18n.tr("n2n edge")

    Column {
        id: pageLayout

        anchors {
            fill:parent
            margins: root.margins
        }
        spacing: units.gu(1)

        Row {
            spacing: units.gu(1)

            TextField {
                id: networkPwd
                placeholderText: "Password"
                echoMode: TextInput.normal
            }
        }
        Row {
            TextField {
                id: nodeIP
                placeholderText: "Node IP"
                echoMode: TextInput.normal
            }
        }
        Row {
            TextField {
                id: nodePort
                placeholderText: "Node port"
                echoMode: TextInput.normal
            }
        }
        Row {
            TextField {
                id: networkName
                placeholderText: "Network name"
                echoMode: TextInput.normal
            }
        }
        Row {
            TextField {
                id: clientIP
                placeholderText: "client IP"
                echoMode: TextInput.normal
            }
        }
        Row {
            Button {
                id: validatePwdButton
                text: i18n.tr("Validate")
                width: units.gu(12)
                onClicked: {
                    cmdForm.update();
                }
            }
        }
        Row {

            TextField {
                id: cmdForm
                placeholderText: "sudo edge -a ClientIP -c NetworkName -k pwdForm -l NodeIP:NodePort"
                echoMode: TextInput.normal
            }
        }
    }
}
}
vmalep
  • 639
  • 1
  • 6
  • 17
  • and for the second part of you question: http://askubuntu.com/questions/275953/saving-user-settings-file-in-qml-js – andrewsomething Oct 07 '13 at 19:13
  • Thanks very much for those feedback. Indeed the first link answer in good part my first question, even though I find disappointing to realize of complicate it is to execute a simple shell command in an interpreted language... – vmalep Oct 08 '13 at 20:20
  • As for the 2nd, I would prefer to write in a config file and not in a database. So the user could easily modify the config without passing by the programme and even more important, we could upload config file easily (for example to change the password for each connection). Remains also the question on how to pass argument to the commande shell. With the first response, it looks also far more complicated than expected... Actually, I think I will first try to develop this small frontend in python and if working fine, consider later to rewrite it in qml... Thanks and best regards, Pierre – vmalep Oct 08 '13 at 20:28
  • The lack of the ability to call system commands or write local files is a big drawback to working in pure QML/JS. If you aren't targeting the touch (which at least for now only supports QML/JS/C++) and want to write the interface in QML, you might want to look into pyqt5 which lets you use a python backend with a qml frontend. – andrewsomething Oct 08 '13 at 21:13

0 Answers0