Commit fbb63f59 authored by kempe's avatar kempe
Browse files

Added Update logic and settings object

parent 6d3625aa
......@@ -14,7 +14,8 @@ TARGET = harbour-received
CONFIG += sailfishapp
SOURCES += src/harbour-received.cpp
SOURCES += src/harbour-received.cpp \
src/settings.cpp
OTHER_FILES += qml/harbour-received.qml \
qml/cover/CoverPage.qml \
......@@ -34,8 +35,7 @@ OTHER_FILES += qml/harbour-received.qml \
translations/harbour-received-sv.ts \
qml/pages/BrowseByCategory.qml \
qml/components/SleepTimer.qml \
qml/components/RadioAPI.qml \
qml/pages/Settings.qml
qml/components/RadioAPI.qml
# to disable building translations every time, comment out the
# following CONFIG line
......@@ -47,7 +47,8 @@ CONFIG += sailfishapp_i18n
# modify the localized app name in the the .desktop file.
TRANSLATIONS += translations/harbour-received-sv.ts
HEADERS +=
HEADERS += \
src/settings.h
DISTFILES += \
qml/components/js/Rad.js \
......@@ -64,5 +65,7 @@ DISTFILES += \
qml/pages/StationsPageForm.ui.qml \
qml/pages/StationsPage.qml \
qml/components/StationsListContextMenu.qml \
qml/components/CustomSearchField.qml
qml/components/CustomSearchField.qml \
qml/pages/Settings2.qml \
qml/components/RecivedUpgrader.qml
......@@ -41,10 +41,11 @@ Python {
loading = true;
call('api.radio.getStationById', [''+oldFavorite.radIoId], function(response) {
var stationData = Rad.getStationFromRadioJson(response);
FavoritesUtils.removeFavorite(oldFavorite)
FavoritesUtils.addFavorite(stationData)
FavoritesUtils.removeFavorite(oldFavorite);
FavoritesUtils.addFavorite(stationData);
console.log("Updated", JSON.stringify(oldFavorite));
loading = false
loading = false;
});
}
......
import QtQuick 2.6
import "js/Storage.js" as DB
/**
* Upgrader used to make necessary updates for new versions
*
* This upgrader is async and might need to be reimplemented for future upgrades
* That is version 2 might be applied before version 1 is completed and so on
*/
Item {
property int version: 1
property int latestInstalledVersion: settings.value("latestInstalledVersion", 0)
function updateFavoritesV1() {
console.log("Updating favorites to version1")
var stations = DB.loadStations();
for(var i = 0; i < stations.rows.length; i++) {
var row = stations.rows.item(i);
radioAPI.updateFavorite(row);
}
}
Component.onCompleted: {
switch (latestInstalledVersion) {
// We want fall-through to apply all updates from the lastestInstalledVersion
case 0:
updateFavoritesV1()
settings.setValue("latestInstalledVersion", 1)
case version:
console.log("We are up to date")
}
}
}
......@@ -9,13 +9,18 @@ import "./components/js/Utils.js" as Utils
ApplicationWindow
{
id: window
property bool loading: false
property string stationIcon: ""
allowedOrientations: Orientation.All
bottomMargin: player.visibleSize
initialPage: favorites
cover: Qt.resolvedUrl("cover/CoverPage.qml")
RecivedUpgrader {
}
FavoritesPage {
id: favorites
}
......
......@@ -32,20 +32,22 @@
#include <QtQuick>
#endif
#include <QSettings>
#include <sailfishapp.h>
#include "src/settings.h"
int main(int argc, char *argv[])
{
// SailfishApp::main() will display "qml/template.qml", if you need more
// control over initialization, you can use:
//
// - SailfishApp::application(int, char *[]) to get the QGuiApplication *
// - SailfishApp::createView() to get a new QQuickView * instance
// - SailfishApp::pathTo(QString) to get a QUrl to a resource file
//
// To display the view, call "show()" (will show fullscreen on device).
return SailfishApp::main(argc, argv);
//return SailfishApp::main(argc, argv);
QGuiApplication *app = SailfishApp::application(argc, argv);
QQuickView *view = SailfishApp::createView();
Settings settings;
view->rootContext()->setContextProperty("settings", &settings);
view->setSource(SailfishApp::pathTo("qml/harbour-received.qml"));
view->showFullScreen();
return app->exec();
}
#include "settings.h"
Settings::Settings(QObject *parent) : QObject(parent) {
}
void Settings::setValue(const QString &key, const QVariant &value) {
settings_.setValue(key, value);
}
QVariant Settings::value(const QString &key, const QVariant &defaultValue) const {
return settings_.value(key, defaultValue);
}
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QObject>
#include <QSettings>
class Settings : public QObject {
Q_OBJECT
public:
explicit Settings(QObject *parent = 0);
Q_INVOKABLE void setValue(const QString & key, const QVariant & value);
Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
signals:
public slots:
private:
QSettings settings_;
};
#endif // SETTINGS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment