diff options
-rw-r--r-- | app/bluetooth/Bluetooth.qml | 9 | ||||
-rw-r--r-- | app/main.cpp | 29 | ||||
-rw-r--r-- | app/wifi/Wifi.qml | 308 | ||||
-rw-r--r-- | binding-wifi/wifi-api.c | 28 | ||||
-rw-r--r-- | binding-wifi/wifi-connman.c | 35 | ||||
-rw-r--r-- | binding-wifi/wifi-connman.h | 9 |
6 files changed, 200 insertions, 218 deletions
diff --git a/app/bluetooth/Bluetooth.qml b/app/bluetooth/Bluetooth.qml index 3a4d50f..0ce01a1 100644 --- a/app/bluetooth/Bluetooth.qml +++ b/app/bluetooth/Bluetooth.qml @@ -25,12 +25,7 @@ SettingPage { title: 'Bluetooth' checkable: true - property string protocol: 'http://' - property string ipAddress: '127.0.0.1' - property string portNumber: Qt.application.arguments[1] - property string tokenString: Qt.application.arguments[2] - property string btAPI: '/api/Bluetooth-manager/' - property string btAPIpath: protocol + ipAddress + ':' + portNumber + btAPI + property string btAPIpath: bindingAddress + '/Bluetooth-manager/' property var jsonObjectBT property string currentState: 'idle' property string btState: 'off' //add property to indicate the bt status @@ -337,7 +332,7 @@ SettingPage { //Timer for periodic refresh; this is BAD solution, need to figure out how to subscribe for events Timer { id: periodicRefresh - interval: (currentState == "idle")? 10000:5000 // 5seconds + interval: (currentState == "idle")? 10000:1000 // 1second onTriggered: { btDeviceList.clear() diff --git a/app/main.cpp b/app/main.cpp index fd8201e..a55ebad 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) QCommandLineParser parser; parser.addPositionalArgument("port", app.translate("main", "port for binding")); - parser.addPositionalArgument("secret", app.translate("main", "secret for binding")); +// parser.addPositionalArgument("secret", app.translate("main", "secret for binding")); parser.addHelpOption(); parser.addVersionOption(); parser.process(app); @@ -75,20 +75,21 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; - if (positionalArguments.length() == 2) { - int port = positionalArguments.takeFirst().toInt(); - QString secret = positionalArguments.takeFirst(); - QUrl bindingAddress; - bindingAddress.setScheme(QStringLiteral("ws")); - bindingAddress.setHost(QStringLiteral("localhost")); - bindingAddress.setPort(port); - bindingAddress.setPath(QStringLiteral("/api")); - QUrlQuery query; - query.addQueryItem(QStringLiteral("token"), secret); - bindingAddress.setQuery(query); - QQmlContext *context = engine.rootContext(); - context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress); + int port = 0; + if (!positionalArguments.isEmpty()) { + port = positionalArguments.takeFirst().toInt(); } +// QString secret = positionalArguments.takeFirst(); + QUrl bindingAddress; + bindingAddress.setScheme(QStringLiteral("http")); + bindingAddress.setHost(QStringLiteral("localhost")); + bindingAddress.setPort(port); + bindingAddress.setPath(QStringLiteral("/api")); +// QUrlQuery query; +// query.addQueryItem(QStringLiteral("token"), secret); +// bindingAddress.setQuery(query); + QQmlContext *context = engine.rootContext(); + context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress); QFile version("/proc/version"); if (version.open(QFile::ReadOnly)) { diff --git a/app/wifi/Wifi.qml b/app/wifi/Wifi.qml index f5fdae1..dcde6ed 100644 --- a/app/wifi/Wifi.qml +++ b/app/wifi/Wifi.qml @@ -17,6 +17,7 @@ import QtQuick 2.6 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.0 +import AGL.Demo.Controls 1.0 import '..' SettingPage { @@ -25,21 +26,7 @@ SettingPage { title: 'Wifi' checkable: true - property string protocol: 'http://' - property string ipAddress: '127.0.0.1' - property string portNumber: Qt.application.arguments[1] - property string tokenString: Qt.application.arguments[2] - property string wifiAPI: '/api/wifi-manager/' - property string wifiAPIpath: protocol + ipAddress + ':' + portNumber + wifiAPI - - Text { - id: log - anchors.fill: parent - anchors.margins: 10 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - //text: "log" - } + property string wifiAPIpath: bindingAddress + '/wifi-manager/' onCheckedChanged: { console.log("Wifi set to", checked) @@ -88,214 +75,89 @@ SettingPage { Component { id: wifiDevice - Rectangle { + MouseArea { height: 120 - width: parent.width - color: "transparent" + width: ListView.view.width Image { - anchors.left: parent.left - anchors.leftMargin: 80 //width: 70 //height: 50 id: icon source: { + var svg + if (strength < 30) + svg = "1Bar" + else if (strength < 50) + svg = "2Bars" + else if (strength < 70) + svg = "3Bars" + else + svg = "Full" if (securityType(security) === "unsecured") { - if (strength < 30) - source = "images/HMI_Settings_Wifi_1Bar.svg" - else if (strength >= 30 && strength < 50) - source = "images/HMI_Settings_Wifi_2Bars.svg" - else if (strength >= 50 && strength < 70) - source = "images/HMI_Settings_Wifi_3Bars.svg" - else - source = "images/HMI_Settings_Wifi_Full.svg" + return 'images/HMI_Settings_Wifi_%1.svg'.arg(svg) } else { - if (strength < 30) - source = "images/HMI_Settings_Wifi_Locked_1Bar.svg" - else if (strength >= 30 && strength < 50) - source = "images/HMI_Settings_Wifi_Locked_2Bars.svg" - else if (strength >= 50 && strength < 70) - source = "images/HMI_Settings_Wifi_Locked_3Bars.svg" - else - source = "images/HMI_Settings_Wifi_Locked_Full.svg" + return 'images/HMI_Settings_Wifi_Locked_%1.svg'.arg(svg) } } } Column { anchors.left: icon.right anchors.leftMargin: 5 - Text { + Label { id: networkNameText text: name color: '#66FF99' font.pixelSize: 48 - font.bold: { - if ((serviceState === "ready") - || serviceState === "online") - font.bold = true - else - font.bold = false - } + font.bold: serviceState === "ready" || serviceState === "online" } - Text { - visible: ((serviceState === "ready") - || serviceState === "online") ? true : false + Label { + visible: serviceState === "ready" || serviceState === "online" text: "connected, " + address font.pointSize: 18 color: "white" //font.italic: true } } - Button { - id: connectButton - anchors.top: parent.top - anchors.topMargin: 5 - //anchors.horizontalCenter: networkNameText.horizontalCenter - anchors.rightMargin: 50 - anchors.right: parent.right - width: 250 - - MouseArea { - anchors.fill: parent - - Text { - anchors.fill: parent - id: buttonTextLabel - font.pixelSize: 15 - font.bold: true - color: "black" - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - text: { - if ((serviceState === "ready") - || serviceState === "online") - text = "Forget" - else - text = "Connect" - } - } - - onClicked: { - - //connectButton.border.color = "steelblue" - if ((serviceState === "ready") - || serviceState === "online") { - - //means we are connected - console.log("Disconnecting from", index, " ,", name) - request(wifiAPIpath + 'disconnect?network=' + index, - function (o) { - - //showRequestInfo(o.responseText) - console.log(o.responseText) - }) - } else { - console.log("Conect to", index, " ,", name) - - //passwordDialog.open() - request(wifiAPIpath + 'connect?network=' + index, - function (o) { - - // log the json response - //showRequestInfo(o.responseText) - console.log(o.responseText) - }) - } - } - } - } - - Button { - id: passwordButton - anchors.top: parent.top - anchors.topMargin: 5 - anchors.right: connectButton.right - width: 40 - visible: (securityType(security) === "unsecured") ? false : true - - text: { - "Key" - } - - MouseArea { - anchors.fill: parent - onClicked: { - - //connectButton.border.color = "steelblue" - passwordInputText.visible = true - connectButton.visible = false - passwordValidateButton.visible = true - - //passwordInputText.o - periodicRefresh.stop() - - var passkey = passwordInputText.text.valueOf() - - //var passkey = 'randompassword' - console.log("Disconnecting from", index, " ,", name) - } - } - } - - Button { - id: passwordValidateButton - anchors.top: parent.top - anchors.topMargin: 5 - anchors.right: parent.right - anchors.rightMargin: connectButton.width + 5 - width: 40 - visible: false - - //anchors.rightMargin: connectButton.width + 5 - //buttonText: "Connect" - text: { - "ok" //or some icon? - } - - MouseArea { - anchors.fill: parent - - onClicked: { - //passwordInputText = "" - var passkey = passwordInputText.text.valueOf() - console.log("Validating", passkey) - - console.log("Passkey is", passkey) - request(wifiAPIpath + 'security?passkey=' + passkey, + onClicked: { + //connectButton.border.color = "steelblue" + if ((serviceState === "ready") + || serviceState === "online") { + + //means we are connected + console.log("Disconnecting from", index, " ,", name) + request(wifiAPIpath + 'disconnect?network=' + index, + function (o) { + + //showRequestInfo(o.responseText) + console.log(o.responseText) + }) + } else { + console.log("Conect to", index, " ,", name) + view.currentIndex = model.index + if (securityType(security) === "unsecured") { + request(wifiAPIpath + 'connect?network=' + view.currentIndex, function (o) { + // log the json response //showRequestInfo(o.responseText) console.log(o.responseText) }) - passwordValidateButton.visible = false - passwordInputText.visible = false - connectButton.visible = true - - periodicRefresh.start() + } else { + dialog.visible = true } } } - TextInput { - id: passwordInputText - anchors.top: parent.top - anchors.topMargin: 10 - anchors.right: parent.right - anchors.rightMargin: 0 - readOnly: false - //horizontalAlignment: TextInput.AlignHCenter - //verticalAlignment: TextInput.AlignVCenter - +// ImageButton { +// anchors.verticalCenter: parent.verticalCenter +// anchors.right: parent.right +// offImage: '../images/HMI_Settings_X.svg' +// onClicked: { - font.pointSize: 15 - color: "#ffffff" +// } +// } - width: connectButton.width - visible: false - text: "password" - /*hardcore until virtual keyboard works*/ - } Image { source: '../images/HMI_Settings_DividingLine.svg' @@ -305,27 +167,80 @@ SettingPage { visible: model.index > 0 } - } - - } + ListView { - width: parent.width - anchors.top: parent.top - anchors.topMargin: 70 - anchors.bottom: parent.bottom - anchors.bottomMargin: 150 + id: view + anchors.fill: parent + anchors.margins: 100 model: networkList //WifiList {} delegate: wifiDevice clip: true } + MouseArea { + id: dialog + anchors.fill: parent + visible: false + z: 1 + onVisibleChanged: if (visible) password.forceActiveFocus() + ColumnLayout { + anchors.fill: parent + Item { + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: 1 + Rectangle { + anchors.fill: parent + color: 'black' + opacity: 0.5 + } + RowLayout { + anchors.centerIn: parent + TextField { + id: password + placeholderText: 'Password' + } + Button { + text: 'Connect' + highlighted: true + onClicked: { + var passkey = password.text + console.log("Validating", passkey) + + console.log("Passkey is", passkey) + request(wifiAPIpath + 'security?passkey=' + passkey, + function (o) { + + //showRequestInfo(o.responseText) + console.log(o.responseText) + }) + dialog.visible = false + } + } + Button { + text: 'Cancel' + onClicked: dialog.visible = false + } + } + } + + Keyboard { + id: keyboard + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: 1 + target: activeFocusControl + } + } + } //Timer for periodic refresh; this is BAD solution, need to figure out how to subscribe for events Timer { id: periodicRefresh - interval: 5000 // 5seconds + interval: 1000 // 1second + running: !dialog.visible onTriggered: { networkList.clear() @@ -334,9 +249,8 @@ SettingPage { console.log(o.responseText) // translate response into object - var jsonObject = eval('(' + o.responseText + ')') - var jsonObjectNetworks = eval('(' + JSON.stringify( - jsonObject.response) + ')') + var jsonObject = JSON.parse(o.responseText) + var jsonObjectNetworks = jsonObject.response console.log("WiFi list refreshed") //console.log(jsonObject.response) for (var i = 0; i < jsonObjectNetworks.length; i++) { diff --git a/binding-wifi/wifi-api.c b/binding-wifi/wifi-api.c index 2d9748f..f6d6d52 100644 --- a/binding-wifi/wifi-api.c +++ b/binding-wifi/wifi-api.c @@ -272,6 +272,34 @@ void wifi_scanResult(struct afb_req request) /*AFB_SESSION_CHECK*/ /*input each scan result into my_array*/ json_object_array_add(my_array, jresp); number += 1; + + //set the HMI icon according to strength, only if "ready" or "online" + + int error = 0; + struct wifiStatus *status; + + status = g_try_malloc0(sizeof(struct wifiStatus)); + error = wifi_state(status); /*get current status of power and connection*/ + if (!error) { + + if (status->connected == 1) { + + if ((strcmp(state, "ready") == 0) + || ((strcmp(state, "online") == 0))) { + + if (strength < 30) + setHMIStatus(BAR_1); + else if (strength < 50) + setHMIStatus(BAR_2); + else if (strength < 70) + setHMIStatus(BAR_3); + else + setHMIStatus(BAR_FULL); + } + } else + setHMIStatus(BAR_NO); + } + } while (list != NULL) { printf("Should be freed"); diff --git a/binding-wifi/wifi-connman.c b/binding-wifi/wifi-connman.c index 74d2be7..68e5e3d 100644 --- a/binding-wifi/wifi-connman.c +++ b/binding-wifi/wifi-connman.c @@ -350,5 +350,40 @@ void registerPasskey(gchar *passkey) { printf("Passkey: %s\n", passkey); sendPasskey(passkey); + +} + +GError* setHMIStatus(enum wifiStates state) { + + gchar *iconString = NULL; + GDBusConnection *connection; + GVariant *params = NULL; + GVariant *message = NULL; + GError *error = NULL; + + if (state==BAR_NO) iconString = "qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png"; + else if (state==BAR_1) iconString = "qrc:/images/Status/HMI_Status_Wifi_1Bar-01.png"; + else if (state==BAR_2) iconString = "qrc:/images/Status/HMI_Status_Wifi_2Bars-01.png"; + else if (state==BAR_3) iconString = "qrc:/images/Status/HMI_Status_Wifi_3Bars-01.png"; + else if (state==BAR_FULL) iconString = "qrc:/images/Status/HMI_Status_Wifi_Full-01.png"; + else iconString = "qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png"; + + connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); + + params = g_variant_new("(is)", HOMESCREEN_WIFI_ICON_POSITION, iconString); + + message = g_dbus_connection_call_sync(connection, HOMESCREEN_SERVICE, + HOMESCREEN_ICON_PATH, HOMESCREEN_ICON_INTERFACE, "setStatusIcon", params, + NULL, G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, NULL, &error); + + if (error) { + printf("error: %s\n", error->message); + + return error; + } else { + return NULL; + } + } diff --git a/binding-wifi/wifi-connman.h b/binding-wifi/wifi-connman.h index bd83821..c47cbcd 100644 --- a/binding-wifi/wifi-connman.h +++ b/binding-wifi/wifi-connman.h @@ -52,6 +52,12 @@ extern "C" { #define WIFI_MAX_PSK_PASSPHRASE_LEN 65 #define WIFI_MAX_WEP_KEY_LEN 26 +#define HOMESCREEN_SERVICE "org.agl.homescreen" +#define HOMESCREEN_ICON_INTERFACE "org.agl.statusbar" +#define HOMESCREEN_ICON_PATH "/StatusBar" +#define HOMESCREEN_WIFI_ICON_POSITION 0 + + #define AGENT_PATH "/net/connman/Agent" #define AGENT_SERVICE "org.agent" @@ -96,6 +102,8 @@ struct wifi_profile_info{ struct wifi_net wifiNetwork; }; +enum wifiStates {BAR_NO, BAR_1, BAR_2, BAR_3, BAR_FULL}; + //typedef void(*callback)(void); typedef void(*callback)(int password_rejected_flag); void register_callback(callback ptr); @@ -113,6 +121,7 @@ GError* do_disconnectNetwork(gchar *object); GError* create_agent(GDBusConnection *connection); GError* stop_agent(GDBusConnection *connection); +GError* setHMIStatus(enum wifiStates); void registerPasskey(gchar *object); GError* sendPasskey(gchar *object); |