From 824a4e3cff8ed574f0db416ea27de6470f393a38 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Mon, 2 Dec 2019 20:56:38 +0100 Subject: [PATCH] Break out WifiChecker --- harbour-seaprint.pro | 1 + qml/pages/FirstPage.qml | 67 ++++++++++----------------------------- qml/pages/WifiChecker.qml | 42 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 51 deletions(-) diff --git a/harbour-seaprint.pro b/harbour-seaprint.pro index 2cf915d..a52d211 100644 --- a/harbour-seaprint.pro +++ b/harbour-seaprint.pro @@ -24,6 +24,7 @@ SOURCES += src/harbour-seaprint.cpp \ DISTFILES += qml/harbour-seaprint.qml \ qml/cover/CoverPage.qml \ qml/pages/*.qml \ + qml/pages/WifiChecker.qml \ qml/pages/utils.js \ qml/pages/printer.svg \ rpm/harbour-seaprint.changes.in \ diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index a8f5fd3..9a66ab5 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -11,63 +11,29 @@ Page { allowedOrientations: Orientation.All property string selectedFile: "/home/nemo/Downloads/1.pdf" - property string currentSSID: "" - - onCurrentSSIDChanged: { - console.log(currentSSID); - if(currentSSID != "") { - var favourites = db.getFavourites(currentSSID); - console.log(favourites); - discovery.favourites = favourites; - } - else { - discovery.favourites = [] - } - } IppDiscovery { id: discovery } - DBusInterface { - id: ssid_finder + WifiChecker { + id: wifi + onConnectedChanged: { + console.log("conn", connected) + if(connected) { + var favourites = db.getFavourites(ssid); + console.log(favourites); + discovery.favourites = favourites; + } + else { + discovery.favourites = [] + } - bus: DBus.SystemBus - - service: 'net.connman' - path: '/' - iface: 'net.connman.Manager' - - signalsEnabled: true - - function servicesChanged() { - console.log("services changed"); - go(); } - - function go() { - call("GetServices", undefined, - function(result) { - for (var i = 0; i < result.length; i++) { - var entry = result[i][1]; - if(entry.Type == "wifi" && (entry.State == "online" || entry.State == "ready")) { - page.currentSSID = entry.Name; - return; - } - } - page.currentSSID = ""; - }, - function(error, message) { - console.log('call failed', error, 'message:', message); - page.currentSSID = entry.Name; - }) - } - } Component.onCompleted: { discovery.discover(); - ssid_finder.go(); } // To enable PullDownMenu, place our content in a SilicaFlickable @@ -78,13 +44,13 @@ Page { PullDownMenu { MenuItem { text: qsTr("Add by URL") - enabled: currentSSID != "" + enabled: wifi.connected onClicked: { var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"), - {ssid: currentSSID, title: qsTr("URL")}); + {ssid: wifi.ssid, title: qsTr("URL")}); dialog.accepted.connect(function() { - db.addFavourite(page.currentSSID, dialog.value); - discovery.favourites = db.getFavourites(page.currentSSID); + db.addFavourite(wifi.ssid, dialog.value); + discovery.favourites = db.getFavourites(wifi.ssid); }) } } @@ -92,7 +58,6 @@ Page { text: qsTr("Refresh") onClicked: { discovery.discover(); - ssid_finder.go(); } } } diff --git a/qml/pages/WifiChecker.qml b/qml/pages/WifiChecker.qml index 9c36e13..959ec25 100644 --- a/qml/pages/WifiChecker.qml +++ b/qml/pages/WifiChecker.qml @@ -1,5 +1,47 @@ import QtQuick 2.0 +import Nemo.DBus 2.0 + Item { + property bool connected: false + property string ssid + DBusInterface { + bus: DBus.SystemBus + + service: 'net.connman' + path: '/' + iface: 'net.connman.Manager' + + signalsEnabled: true + + Component.onCompleted: go() + + function servicesChanged() { + console.log("services changed"); + go(); + } + + function go() { + console.log("go!") + call("GetServices", undefined, + function(result) { + for (var i = 0; i < result.length; i++) { + var entry = result[i][1]; + if(entry.Type == "wifi" && (entry.State == "online" || entry.State == "ready")) { + ssid = entry.Name; + connected = true; + return; + } + } + ssid = undefined; + connected = false; + }, + function(error, message) { + console.log('call failed', error, 'message:', message); + page.currentSSID = entry.Name; + }) + } + + } }