[-]
[+]
|
Changed |
_service:tar_git:harbour-piratefm-0.0.3.tar.bz2/qml/pages/Tuner.qml
^
|
@@ -89,7 +89,7 @@
icon.source: "image://theme/icon-m-favorite"
onClicked:
{
- stations.add({"frequency": radio.frequency, "stationId": radio.radioData.stationName})
+ stations.add({"frequency": radio.frequency, "station": radio.radioData.stationName})
}
}
}
@@ -117,14 +117,16 @@
model: stations
delegate: ListItem
{
- height: Theme.itemSizeSmall
+ contentHeight: Theme.itemSizeSmall
width: parent.width
+ menu: contextmenu
+
Label
{
anchors.left: parent.left
anchors.leftMargin: Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
- text: stationId
+ text: station
}
Label
{
@@ -135,6 +137,32 @@
font.bold: true
}
onClicked: radio.frequency = frequency
+
+ Component
+ {
+ id: contextmenu
+ ContextMenu
+ {
+ MenuItem
+ {
+ text: "Delete"
+ onClicked: remove()
+ }
+ }
+ }
+
+ function remove()
+ {
+ remorseAction("Deleting", function()
+ {
+ var db = opendb()
+ db.transaction(function(x)
+ {
+ x.executeSql("DELETE FROM favourites WHERE id=?",[ stations.get(index).id ])
+ })
+ stations.reload()
+ })
+ }
}
}
}
|
@@ -1,6 +1,7 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import QtMultimedia 5.0
+import QtQuick.LocalStorage 2.0
ApplicationWindow
{
@@ -11,7 +12,7 @@
{
id: radio
band: Radio.FM
- }
+ }
ListModel
{
@@ -21,9 +22,44 @@
for (var i=0; i<count; i++)
if (data.frequency === get(i).frequency)
return;
- append(data)
+
+ var db = opendb()
+ db.transaction(function(x)
+ {
+ x.executeSql("INSERT INTO favourites (station, frequency) VALUES(?, ?)",[ data.station, data.frequency ])
+ })
+ stations.reload()
+ }
+
+ function reload()
+ {
+ var db = opendb()
+ clear()
+ db.transaction(function(x)
+ {
+ var res = x.executeSql("SELECT * FROM favourites")
+ for(var i = 0; i < res.rows.length; i++)
+ {
+ append(res.rows.item(i))
+ }
+ })
}
+
+ Component.onCompleted: reload()
}
+
+ function opendb()
+ {
+ return LocalStorage.openDatabaseSync('harbour-piratefm', '', 'Stations', 2000, function(db)
+ {
+ db.transaction(function(x)
+ {
+ x.executeSql("CREATE TABLE IF NOT EXISTS favourites (id INTEGER PRIMARY KEY AUTOINCREMENT, station TEXT, frequency INTEGER)")
+ })
+ })
+
+ }
+
}
|