diff --git a/qml/EpisodeItem.qml b/qml/EpisodeItem.qml index 71f8bed..97bb2e1 100644 --- a/qml/EpisodeItem.qml +++ b/qml/EpisodeItem.qml @@ -23,11 +23,13 @@ import Sailfish.Silica 1.0 import 'common/constants.js' as Constants import 'common/util.js' as Util +import 'connectionManagement' ListItem { id: episodeItem property bool isPlaying: ((player.episode === id) && player.isPlaying) property variant mime: mime_type.split('/') + property var downloaded: downloadState === 1 Rectangle { anchors.fill: parent @@ -73,9 +75,27 @@ ListItem { if (episodeItem.isPlaying) { player.pause(); } else { - player.playbackEpisode(id); + if(downloaded === false){ + // curried function below to create a closure + // see e.g. https://stackoverflow.com/questions/28898526 + connectionUtil.executeIfConnectionAllowed( + function(callee, argument1, argument2){ + return function(){ + callee(argument1,argument2)}; + }(doPlayback,player,id) + ); + }else { + doPlayback(player,id); + } } } + + function doPlayback(mediaPlayer,id){ + console.info("playing episode", id); + mediaPlayer.playbackEpisode(id); + } + + } IconMenuItem { diff --git a/qml/Main.qml b/qml/Main.qml index 4eb9602..272638d 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -20,8 +20,10 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import Nemo.Configuration 1.0 import 'common' +import 'connectionManagement' PodcastsPage { id: pgst @@ -72,6 +74,10 @@ PodcastsPage { MprisPlayer {} MediaKeys {} + ConnectionUtils { + id: connectionUtil + } + GPodderPodcastListModel { id: podcastListModel } GPodderPodcastListModelConnections {} @@ -99,4 +105,11 @@ PodcastsPage { visible: !py.ready running: visible } + + ConfigurationValue { + id: configCellularDownloadsEnabled + key: "/apps/ControlPanel/gpodder/cellularDownloadsEnabled" + defaultValue: false + } + } diff --git a/qml/SettingsPage.qml b/qml/SettingsPage.qml index f5407cb..8c01b79 100644 --- a/qml/SettingsPage.qml +++ b/qml/SettingsPage.qml @@ -35,10 +35,12 @@ Page { py.getConfig('limit.episodes', function (value) { limit_episodes.value = value; }); + cellularDownloadsEnabled.checked = configCellularDownloadsEnabled.value; } else if (status === PageStatus.Deactivating) { py.setConfig('plugins.youtube.api_key_v3', youtube_api_key_v3.text); py.setConfig('limit.episodes', parseInt(limit_episodes.value)); youtube_api_key_v3.focus = false; + configCellularDownloadsEnabled.value = cellularDownloadsEnabled.checked } } @@ -92,6 +94,13 @@ Page { maximumValue: 1000 stepSize: 100 } + + TextSwitch { + id: cellularDownloadsEnabled + text: qsTr("Allow Downloads via mobile data") + checked: configCellularDownloadsEnabled.value + } + } } } diff --git a/qml/connectionManagement/ConnectionBlockedDialog.qml b/qml/connectionManagement/ConnectionBlockedDialog.qml new file mode 100644 index 0000000..aa7b2c3 --- /dev/null +++ b/qml/connectionManagement/ConnectionBlockedDialog.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + + Dialog { + Column { + width: parent.width + + DialogHeader { + title: "Connection blocked" + } + Label{ + text: "Make an exception for now?" + } + } + + } diff --git a/qml/connectionManagement/ConnectionUtils.qml b/qml/connectionManagement/ConnectionUtils.qml new file mode 100644 index 0000000..f1f8fa4 --- /dev/null +++ b/qml/connectionManagement/ConnectionUtils.qml @@ -0,0 +1,54 @@ +import QtQuick 2.0 +import Nemo.DBus 2.0 + +QtObject { + + property DBusInterface connmanWifi: DBusInterface { + bus: DBus.SystemBus + service: "net.connman" + path: "/net/connman/technology/wifi" + iface: "net.connman.Technology" + + property bool wifiConnected + + signalsEnabled: true + function propertyChanged(name, value) { + if (name === "Connected") { + wifiConnected = value + } + } + + function getProperties() { + typedCall('GetProperties', undefined, function(result) { + wifiConnected = result['Connected']}) + } + Component.onCompleted: getProperties(); + + onWifiConnectedChanged: { + console.debug("wifistate is now",wifiConnected) + } + } + + function checkConnection(ignoreConnection){ + var cellularAllowed = configCellularDownloadsEnabled.value === true || ignoreConnection === true; + console.debug("Connection check: cellular allowed:",cellularAllowed," wifi connected: ", connmanWifi.wifiConnected) + return cellularAllowed || connmanWifi.wifiConnected; + } + + + /** + * @return signal binding for executing callback anyway + **/ + function downloadBlockedDialog(callback){ + console.info("creating connection blocked dialog, because not on wifi!"); + pageStack.push("ConnectionBlockedDialog.qml").accepted.connect(callback) + } + + function executeIfConnectionAllowed(callback){ + if(checkConnection()) + callback() + else + downloadBlockedDialog(callback) + } + +} diff --git a/translations/harbour-org.gpodder.sailfish-bg.ts b/translations/harbour-org.gpodder.sailfish-bg.ts index d47bac0..2b1e186 100644 --- a/translations/harbour-org.gpodder.sailfish-bg.ts +++ b/translations/harbour-org.gpodder.sailfish-bg.ts @@ -97,44 +97,44 @@ EpisodeItem - + Pause - Паузиране + Паузиране - + Play - Пускане + Пускане - + Download - Изтегляне + - + Enqueue - Към опашката + - + Delete - Изтриване + - + Deleting - Изтрива се + - + Toggle New - Като нов + - + Shownotes - Описание + Описание @@ -512,35 +512,40 @@ SettingsPage - + About Относно - + Settings Настройки - + YouTube YouTube - + API Key (v3) API ключ (v3) - + Limits Ограничения - + Maximum episodes per feed Максимален брой епизоди за RSS емисия + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish-de.ts b/translations/harbour-org.gpodder.sailfish-de.ts index 75df417..e7dbcc3 100644 --- a/translations/harbour-org.gpodder.sailfish-de.ts +++ b/translations/harbour-org.gpodder.sailfish-de.ts @@ -97,42 +97,42 @@ EpisodeItem - + Pause Pause - + Play Abspielen - + Download - + Enqueue - + Delete - + Deleting - + Toggle New - + Shownotes Shownotes @@ -512,35 +512,40 @@ SettingsPage - + About Über - + Settings Einstellungen - + YouTube YouTube - + API Key (v3) API Schlüssel (v3) - + Limits Grenzen - + Maximum episodes per feed Maximale Anzahl Episoden pro Feed + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish-es.ts b/translations/harbour-org.gpodder.sailfish-es.ts index 859d315..a0be8af 100644 --- a/translations/harbour-org.gpodder.sailfish-es.ts +++ b/translations/harbour-org.gpodder.sailfish-es.ts @@ -97,44 +97,44 @@ EpisodeItem - + Pause - Pausar + Pausar - + Play - Reproducir + Reproducir - + Download - Descargar + - + Enqueue - En cola + - + Delete - Borrar + - + Deleting - Borrando + - + Toggle New - Nuevo + - + Shownotes - Notas + Notas @@ -512,35 +512,40 @@ SettingsPage - + About Acerca de - + Settings Ajustes - + YouTube YouTube - + API Key (v3) Clave API (v3) - + Limits Límites - + Maximum episodes per feed Núm. máximo de episodios por canal + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish-it.ts b/translations/harbour-org.gpodder.sailfish-it.ts index e381673..a0c3a75 100644 --- a/translations/harbour-org.gpodder.sailfish-it.ts +++ b/translations/harbour-org.gpodder.sailfish-it.ts @@ -97,42 +97,42 @@ EpisodeItem - + Pause Pausa - + Play Riproduci - + Download - + Enqueue - + Delete - + Deleting - + Toggle New - + Shownotes Note @@ -512,35 +512,40 @@ SettingsPage - + About Info - + Settings Impostazioni - + YouTube YouTube - + API Key (v3) API Key (v3) - + Limits Limiti - + Maximum episodes per feed Massimo episodi per feed + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish-pl.ts b/translations/harbour-org.gpodder.sailfish-pl.ts index b0d0fca..9a0ffdd 100644 --- a/translations/harbour-org.gpodder.sailfish-pl.ts +++ b/translations/harbour-org.gpodder.sailfish-pl.ts @@ -97,42 +97,42 @@ EpisodeItem - + Pause - Pauza + Pauza - + Play - Odtwarzaj + Odtwarzaj - + Download - Pobierz + - + Enqueue - Kolejkuj + - + Delete - Usuń + - + Deleting - Usuwanie + - + Toggle New - + Shownotes Opis odcinka @@ -512,35 +512,40 @@ SettingsPage - + About O gPodder - + Settings Ustawienia - + YouTube YouTube - + API Key (v3) Klucz API (v3) - + Limits Limity - + Maximum episodes per feed Maksymalna liczba odcinków na kanał + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish-ru.ts b/translations/harbour-org.gpodder.sailfish-ru.ts index 07beb1f..44bb05d 100644 --- a/translations/harbour-org.gpodder.sailfish-ru.ts +++ b/translations/harbour-org.gpodder.sailfish-ru.ts @@ -97,44 +97,44 @@ EpisodeItem - + Pause - Пауза + Пауза - + Play - Играть + Играть - + Download - Скачать + - + Enqueue - В очередь + - + Delete - Удалить + - + Deleting - Удаление + - + Toggle New - Отмечать как новый + - + Shownotes - Описание + Описание @@ -512,35 +512,40 @@ SettingsPage - + About О программе - + Settings Настройка - + YouTube YouTube - + API Key (v3) Ключ API (версия 3) - + Limits Ограничения - + Maximum episodes per feed Максимальное число выпусков + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish-sv.ts b/translations/harbour-org.gpodder.sailfish-sv.ts index 88179c8..99e8c2b 100644 --- a/translations/harbour-org.gpodder.sailfish-sv.ts +++ b/translations/harbour-org.gpodder.sailfish-sv.ts @@ -97,44 +97,44 @@ EpisodeItem - + Pause - Paus + Pause - + Play - Spela + Spela - + Download - Ladda ner + - + Enqueue - Köa + - + Delete - Ta bort + - + Deleting - Tar bort + - + Toggle New - Ny av/på + - + Shownotes - Visa notiser + Show notes @@ -512,35 +512,40 @@ SettingsPage - + About Om - + Settings Inställningar - + YouTube YouTube - + API Key (v3) API-nyckel (v3) - + Limits Begränsningar - + Maximum episodes per feed Max antal avsnitt per flöde + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish-zh_CN.ts b/translations/harbour-org.gpodder.sailfish-zh_CN.ts index 8a562de..431044a 100644 --- a/translations/harbour-org.gpodder.sailfish-zh_CN.ts +++ b/translations/harbour-org.gpodder.sailfish-zh_CN.ts @@ -97,44 +97,44 @@ EpisodeItem - + Pause - 暂停 + 暂停 - + Play - 播放 + 播放 - + Download - 下载 + - + Enqueue - 队列 + - + Delete - 删除 + - + Deleting - 删除中 + - + Toggle New - 切到新的 + - + Shownotes - 剧集说明 + 剧集说明 @@ -512,35 +512,40 @@ SettingsPage - + About 关于 - + Settings 设置 - + YouTube YouTube - + API Key (v3) API 密钥(v3) - + Limits 限制 - + Maximum episodes per feed 每个订阅流的最大剧集 + + + Allow Downloads via mobile data + + SleepTimerDialog diff --git a/translations/harbour-org.gpodder.sailfish.ts b/translations/harbour-org.gpodder.sailfish.ts index 0cae0ee..fb2806b 100644 --- a/translations/harbour-org.gpodder.sailfish.ts +++ b/translations/harbour-org.gpodder.sailfish.ts @@ -97,42 +97,42 @@ EpisodeItem - + Pause - + Play - + Download - + Enqueue - + Delete - + Deleting - + Toggle New - + Shownotes @@ -512,35 +512,40 @@ SettingsPage - + About - + Settings - + YouTube - + API Key (v3) - + Limits - + Maximum episodes per feed + + + Allow Downloads via mobile data + + SleepTimerDialog