Commit 992a9499 authored by kempe's avatar kempe

Resolve "As a user I want to be able to change api language"

parent c0034b73
......@@ -59,7 +59,8 @@ DISTFILES += \
qml/pages/StationsPage.qml \
qml/harbour-received.qml \
qml/cover/layouts/CoverDesign.qml \
qml/components/audioplayer/StationInfoLabel.qml
qml/components/audioplayer/StationInfoLabel.qml \
qml/components/listmodels/ApiLanguageListModel.qml
OTHER_FILES += \
rpm/harbour-received.changes.in \
......
......@@ -5,28 +5,36 @@ import "./js/Favorites.js" as FavoritesUtils
Python {
id: radioAPI
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('./python'));
setHandler('log', function(msg) {
console.log("Pyton log:", msg)
});
importModule('api', function () {});
importModule('api', function () {
setApiBaseUrl()
});
}
function setApiBaseUrl() {
call('api.radio.setApiBaseUrl', [settings.value("apiUrl")], function(response) {
console.log("apiBaseUrl updated: ", response)
});
}
function playStationById(id) {
loading = true;
call('api.radio.getStationById', [''+id], function(response) {
var stationData = Rad.getStationFromRadioJson(response);
console.log("Playing station:", JSON.stringify(stationData))
player.play(stationData);
loading = false;
});
}
function addRadIoAsFavorite(id) {
loading = true;
call('api.radio.getStationById', [''+id], function(response) {
......@@ -98,11 +106,11 @@ Python {
loading = false
});
}
onError: {
console.log('python error: ' + traceback);
}
onReceived: {
console.log('got message from python: ' + data);
}
......
import QtQuick 2.0
ListModel {
id: model
ListElement { title: qsTr("English"); apiUrl: "http://www.rad.io" }
ListElement { title: qsTr("German"); apiUrl: "http://www.radio.de" }
ListElement { title: qsTr("Austria"); apiUrl: "http://www.radio.at" }
ListElement { title: qsTr("France"); apiUrl: "http://www.radio.fr" }
ListElement { title: qsTr("Portugal"); apiUrl: "http://www.radio.pt" }
ListElement { title: qsTr("Spain"); apiUrl: "http://www.radio.es" }
}
......@@ -4,20 +4,26 @@ import pyotherside
import requests
USER_AGENT = "XBMC not really, Recived on sailfish"
BASE = "http://rad.io/info"
recomendedURL = "{0}/broadcast/editorialreccomendationsembedded".format(BASE)
top100URL = "{0}/menu/broadcastsofcategory".format(BASE)
mostWantedURL = "{0}/account/getmostwantedbroadcastlists".format(BASE)
searchURL = "{0}/index/searchembeddedbroadcast".format(BASE)
categoriesURL = "{0}/menu/valuesofcategory".format(BASE)
stationsByCategoriesURL = "{0}/menu/broadcastsofcategory".format(BASE)
stationByIdURL = "{0}/broadcast/getbroadcastembedded".format(BASE)
recomendedURL = "info/broadcast/editorialreccomendationsembedded"
top100URL = "info/menu/broadcastsofcategory"
mostWantedURL = "info/account/getmostwantedbroadcastlists"
searchURL = "info/index/searchembeddedbroadcast"
categoriesURL = "info/menu/valuesofcategory"
stationsByCategoriesURL = "info/menu/broadcastsofcategory"
stationByIdURL = "info/broadcast/getbroadcastembedded"
class Radio_API:
def __init__(self):
self.apiBaseUrl = "http://www.rad.io"
pass
def setApiBaseUrl(self, apiUrl):
self.apiBaseUrl = apiUrl
pyotherside.send('log', "setting apiBaseUrl: {}".format(apiUrl))
return True
def getTopStations(self):
params = {'category': '_top'}
response = self.doRequest(top100URL, params)
......@@ -68,6 +74,9 @@ class Radio_API:
def doRequest(self, url, params=None):
headers = {'user-agent': USER_AGENT}
url = "{0}/{1}".format(self.apiBaseUrl, url)
pyotherside.send('log', "Request: {0} {1} {2}".format(url, params, headers))
r = requests.get(url, params=params, headers=headers)
return r.json()
......
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components/js/Storage.js" as DB
import "../components/js/Favorites.js" as Favorites
SettingsPageForm {
aboutAction.onClicked: console.log("TODO")
buttonResetDb.onClicked: {
remorse.execute("Droping DB",function() {
Remorse.popupAction(buttonResetDb, "Droping DB", function() {
DB.dropDB();
Favorites.updateFavorites()});
}
onApiLanguageChanged: {
settings.setValue("apiUrl", url)
radioAPI.setApiBaseUrl()
}
Component.onCompleted: {
for (var i = 0; i < apiLanguageModel.count; i++) {
var item = apiLanguageModel.get(i)
if (settings.value("apiUrl") === item.apiUrl) {
apiLanguageComboBox.currentIndex = i;
}
}
}
}
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components/listmodels/"
Page {
id: settingsPage
signal apiLanguageChanged(string title, string url)
property alias aboutAction: aboutAction
property alias buttonResetDb: buttonResetDb
property alias apiLanguageComboBox: apiLanguageComboBox
property alias apiLanguageModel: apiLanguageModel
SilicaFlickable {
id: settingsPageFlickable
......@@ -34,6 +39,27 @@ Page {
title: qsTr("Settings")
}
ComboBox {
id: apiLanguageComboBox
label: qsTr("API Language:")
menu: ContextMenu {
id: apiLanguageComboBoxMenu
Repeater {
model: ApiLanguageListModel { id: apiLanguageModel }
MenuItem {
id: apiLanguage
text: model.title
Connections {
target: apiLanguage
onClicked: apiLanguageChanged(model.title, model.apiUrl)
}
}
}
}
}
SectionHeader {
text: qsTr("Advanced Options")
}
......@@ -50,8 +76,8 @@ Page {
color: Theme.primaryColor
text: qsTr("<h2>Settings info:</h2>")+"<br>"+
qsTr("<p>All settings are saved when you make a change</p>")+"<br>"+
qsTr("<p><b>API Language:</b> Sets the endpoint to be used for API calls e.g. rad.io for English and radio.de for German</p>")+"<br>"+
qsTr("<p><b>Reset DB:</b> Removes everything in the database and gives you a clean start</p>")
}
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="es_ES">
<context>
<name>ApiLanguageListModel</name>
<message>
<source>English</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>German</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Austria</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>France</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Portugal</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Spain</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BrowseByCategoryPageForm.ui</name>
<message>
......@@ -187,6 +214,14 @@
<source>&lt;p&gt;&lt;b&gt;Reset DB:&lt;/b&gt; Removes everything in the database and gives you a clean start&lt;/p&gt;</source>
<translation>&lt;p&gt;&lt;b&gt;Restaurar BD:&lt;/b&gt; Se elimina todo de la base de datos y proporciona un inicio limpio&lt;/p&gt;</translation>
</message>
<message>
<source>API Language:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;&lt;b&gt;API Language:&lt;/b&gt; Sets the endpoint to be used for API calls e.g. rad.io for English and radio.de for German&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StationsListContextMenu</name>
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>ApiLanguageListModel</name>
<message>
<source>English</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>German</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Austria</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>France</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Portugal</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Spain</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BrowseByCategoryPageForm.ui</name>
<message>
......@@ -175,6 +202,10 @@
<source>Reset DB</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>API Language:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;h2&gt;Settings info:&lt;/h2&gt;</source>
<translation type="unfinished"></translation>
......@@ -187,6 +218,10 @@
<source>&lt;p&gt;&lt;b&gt;Reset DB:&lt;/b&gt; Removes everything in the database and gives you a clean start&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;&lt;b&gt;API Language:&lt;/b&gt; Sets the endpoint to be used for API calls e.g. rad.io for English and radio.de for German&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StationsListContextMenu</name>
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>ApiLanguageListModel</name>
<message>
<source>English</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>German</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Austria</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>France</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Portugal</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Spain</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BrowseByCategoryPageForm.ui</name>
<message>
......@@ -175,6 +202,10 @@
<source>Reset DB</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>API Language:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;h2&gt;Settings info:&lt;/h2&gt;</source>
<translation type="unfinished"></translation>
......@@ -187,6 +218,10 @@
<source>&lt;p&gt;&lt;b&gt;Reset DB:&lt;/b&gt; Removes everything in the database and gives you a clean start&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;&lt;b&gt;API Language:&lt;/b&gt; Sets the endpoint to be used for API calls e.g. rad.io for English and radio.de for German&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StationsListContextMenu</name>
......
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