Break out WifiChecker

This commit is contained in:
Anton Thomasson 2019-12-02 20:56:38 +01:00
parent ad883cbdab
commit 824a4e3cff
3 changed files with 59 additions and 51 deletions

View file

@ -24,6 +24,7 @@ SOURCES += src/harbour-seaprint.cpp \
DISTFILES += qml/harbour-seaprint.qml \ DISTFILES += qml/harbour-seaprint.qml \
qml/cover/CoverPage.qml \ qml/cover/CoverPage.qml \
qml/pages/*.qml \ qml/pages/*.qml \
qml/pages/WifiChecker.qml \
qml/pages/utils.js \ qml/pages/utils.js \
qml/pages/printer.svg \ qml/pages/printer.svg \
rpm/harbour-seaprint.changes.in \ rpm/harbour-seaprint.changes.in \

View file

@ -11,63 +11,29 @@ Page {
allowedOrientations: Orientation.All allowedOrientations: Orientation.All
property string selectedFile: "/home/nemo/Downloads/1.pdf" 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 { IppDiscovery {
id: discovery id: discovery
} }
DBusInterface { WifiChecker {
id: ssid_finder 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: { Component.onCompleted: {
discovery.discover(); discovery.discover();
ssid_finder.go();
} }
// To enable PullDownMenu, place our content in a SilicaFlickable // To enable PullDownMenu, place our content in a SilicaFlickable
@ -78,13 +44,13 @@ Page {
PullDownMenu { PullDownMenu {
MenuItem { MenuItem {
text: qsTr("Add by URL") text: qsTr("Add by URL")
enabled: currentSSID != "" enabled: wifi.connected
onClicked: { onClicked: {
var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"), var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"),
{ssid: currentSSID, title: qsTr("URL")}); {ssid: wifi.ssid, title: qsTr("URL")});
dialog.accepted.connect(function() { dialog.accepted.connect(function() {
db.addFavourite(page.currentSSID, dialog.value); db.addFavourite(wifi.ssid, dialog.value);
discovery.favourites = db.getFavourites(page.currentSSID); discovery.favourites = db.getFavourites(wifi.ssid);
}) })
} }
} }
@ -92,7 +58,6 @@ Page {
text: qsTr("Refresh") text: qsTr("Refresh")
onClicked: { onClicked: {
discovery.discover(); discovery.discover();
ssid_finder.go();
} }
} }
} }

View file

@ -1,5 +1,47 @@
import QtQuick 2.0 import QtQuick 2.0
import Nemo.DBus 2.0
Item { 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;
})
}
}
} }