Skip to content

Commit

Permalink
Break out WifiChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Dec 2, 2019
1 parent ad883cb commit 824a4e3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 51 deletions.
1 change: 1 addition & 0 deletions harbour-seaprint.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
67 changes: 16 additions & 51 deletions qml/pages/FirstPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

bus: DBus.SystemBus

service: 'net.connman'
path: '/'
iface: 'net.connman.Manager'

signalsEnabled: true

function servicesChanged() {
console.log("services changed");
go();
}
WifiChecker {
id: wifi
onConnectedChanged: {
console.log("conn", connected)
if(connected) {
var favourites = db.getFavourites(ssid);
console.log(favourites);
discovery.favourites = favourites;
}
else {
discovery.favourites = []
}

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
Expand All @@ -78,21 +44,20 @@ 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);
})
}
}
MenuItem {
text: qsTr("Refresh")
onClicked: {
discovery.discover();
ssid_finder.go();
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions qml/pages/WifiChecker.qml
Original file line number Diff line number Diff line change
@@ -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;
})
}

}
}

0 comments on commit 824a4e3

Please sign in to comment.