Make favourites SSID-aware

This commit is contained in:
Anton Thomasson 2019-12-01 20:21:36 +01:00
parent 210e40920c
commit bf747f2dab
3 changed files with 77 additions and 21 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.9.1, 2019-12-01T15:39:07. --> <!-- Written by QtCreator 4.9.1, 2019-12-01T19:52:19. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -63,7 +63,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">SailfishOS-3.2.0.12-armv7hl (in Sailfish OS Build Engine)</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">SailfishOS-3.2.0.12-armv7hl (in Sailfish OS Build Engine)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">SailfishOS-3.2.0.12-armv7hl</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">SailfishOS-3.2.0.12-armv7hl</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">2</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/attah/repos/sfos_build/build-harbour-seaprint-SailfishOS_3_2_0_12_armv7hl_in_Sailfish_OS_Build_Engine-Debug</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/attah/repos/sfos_build/build-harbour-seaprint-SailfishOS_3_2_0_12_armv7hl_in_Sailfish_OS_Build_Engine-Debug</value>
@ -278,7 +278,13 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.MerRpmBuildStep</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.MerRpmBuildStep</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">RPM Validation</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.MerRpmValidationStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
@ -393,12 +399,14 @@
<value type="int" key="MerRunConfiguration.QmlLiveIpcPort">-1</value> <value type="int" key="MerRunConfiguration.QmlLiveIpcPort">-1</value>
<value type="int" key="MerRunConfiguration.QmlLiveOptions">3</value> <value type="int" key="MerRunConfiguration.QmlLiveOptions">3</value>
<value type="QString" key="MerRunConfiguration.QmlLiveTargetWorkspace"></value> <value type="QString" key="MerRunConfiguration.QmlLiveTargetWorkspace"></value>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">1</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">harbour-seaprint (on Xperia XA2 (ARM))</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.MerRunConfiguration:/home/attah/repos/harbour-seaprint/harbour-seaprint.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value> <value type="int" key="RemoteLinux.EnvironmentAspect.Version">1</value>
<value type="QString" key="RemoteLinux.RunConfig.AlternateRemoteExecutable"></value>
<value type="bool" key="RemoteLinux.RunConfig.UseAlternateRemoteExecutable">false</value>
<value type="QString" key="RunConfiguration.Arguments"></value> <value type="QString" key="RunConfiguration.Arguments"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
@ -634,7 +642,13 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.MerRpmBuildStep</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.MerRpmBuildStep</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">RPM Validation</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.MerRpmValidationStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>

View file

@ -17,26 +17,27 @@ ApplicationWindow
Component.onCompleted: { Component.onCompleted: {
db_conn = LocalStorage.openDatabaseSync("TintDB", "1.0", "Tint storage", 100000) db_conn = LocalStorage.openDatabaseSync("TintDB", "1.0", "Tint storage", 100000)
db_conn.transaction(function (tx) { db_conn.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Favourites (url STRING UNIQUE)'); tx.executeSql('CREATE TABLE IF NOT EXISTS Favourites (ssid STRING, url STRING)');
}); });
} }
function addFavourite(url) { function addFavourite(ssid, url) {
db_conn.transaction(function (tx) { db_conn.transaction(function (tx) {
tx.executeSql('REPLACE INTO Favourites VALUES(?)', [url] ); tx.executeSql('INSERT INTO Favourites VALUES(?, ?)', [ssid, url] );
}); });
} }
function getFavourites() { function getFavourites(ssid) {
var favs = []; var favs = [];
db_conn.transaction(function (tx) { db_conn.transaction(function (tx) {
var res = tx.executeSql('SELECT * FROM Favourites'); var res = tx.executeSql('SELECT * FROM Favourites WHERE ssid=?', [ssid]);
if (res.rows.length !== 0) { if (res.rows.length !== 0) {
console.log(res.rows.item(0).url) console.log(res.rows.item(0).url)
favs.push(res.rows.item(0).url); favs.push(res.rows.item(0).url);
} }
}); });
console.log(ssid, favs);
return favs return favs
} }
} }

View file

@ -11,20 +11,58 @@ 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
} }
DBusAdaptor { DBusInterface {
id: ssid_finder
bus: DBus.SystemBus
service: 'net.connman'
path: '/'
iface: 'net.connman.Manager'
signalsEnabled: true
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();
var favourites = db.getFavourites(); ssid_finder.go();
console.log(favourites);
discovery.favourites = favourites;
} }
// To enable PullDownMenu, place our content in a SilicaFlickable // To enable PullDownMenu, place our content in a SilicaFlickable
@ -38,14 +76,17 @@ Page {
onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("InputDialog.qml"), onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("InputDialog.qml"),
{value: qsTr("Add favourite"), title: qsTr("URL")}); {value: qsTr("Add favourite"), title: qsTr("URL")});
dialog.accepted.connect(function() { dialog.accepted.connect(function() {
db.addFavourite(dialog.value); db.addFavourite(page.currentSSID, dialog.value);
discovery.insert(dialog.value); discovery.favourites = db.getFavourites(page.currentSSID);
}) })
} }
} }
MenuItem { MenuItem {
text: qsTr("Refresh") text: qsTr("Refresh")
onClicked: discovery.discover() onClicked: {
discovery.discover();
ssid_finder.go();
}
} }
} }