From 7bdccf603b31fb39d627b6b2c80e17fb1af36750 Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Mon, 19 Oct 2020 13:48:36 +0200 Subject: [PATCH 1/2] basic implementation of an option to allow streaming and downloads via wifi only --- qml/ConnectionBlockedDialog.qml | 22 ++++++++ qml/EpisodeItem.qml | 11 +++- qml/Main.qml | 13 +++++ qml/SettingsPage.qml | 9 ++++ qml/utils/ConnectionUtils.qml | 50 +++++++++++++++++++ .../harbour-org.gpodder.sailfish-bg.ts | 33 ++++++------ .../harbour-org.gpodder.sailfish-de.ts | 33 ++++++------ .../harbour-org.gpodder.sailfish-es.ts | 33 ++++++------ .../harbour-org.gpodder.sailfish-it.ts | 33 ++++++------ .../harbour-org.gpodder.sailfish-pl.ts | 33 ++++++------ .../harbour-org.gpodder.sailfish-ru.ts | 33 ++++++------ .../harbour-org.gpodder.sailfish-sv.ts | 33 ++++++------ .../harbour-org.gpodder.sailfish-zh_CN.ts | 33 ++++++------ translations/harbour-org.gpodder.sailfish.ts | 33 ++++++------ 14 files changed, 275 insertions(+), 127 deletions(-) create mode 100644 qml/ConnectionBlockedDialog.qml create mode 100644 qml/utils/ConnectionUtils.qml diff --git a/qml/ConnectionBlockedDialog.qml b/qml/ConnectionBlockedDialog.qml new file mode 100644 index 0000000..7abf2bc --- /dev/null +++ b/qml/ConnectionBlockedDialog.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + + Dialog { + property var callback + + Column { + width: parent.width + + DialogHeader { + title: "Connection blocked" + } + Label{ + text: "Make an exception for now?" + } + } + + onAccepted: { + callback(); + } + + } diff --git a/qml/EpisodeItem.qml b/qml/EpisodeItem.qml index 71f8bed..62d749d 100644 --- a/qml/EpisodeItem.qml +++ b/qml/EpisodeItem.qml @@ -28,6 +28,7 @@ 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 +74,17 @@ ListItem { if (episodeItem.isPlaying) { player.pause(); } else { - player.playbackEpisode(id); + if(downloaded === false){ + connectionUtil.executeIfConnectionAllowed(doPlayback) + }else { + doPlayback(); + } } } + + function doPlayback(){ + player.playbackEpisode(id); + } } IconMenuItem { diff --git a/qml/Main.qml b/qml/Main.qml index 4eb9602..5976e7c 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 'utils' PodcastsPage { id: pgst @@ -72,6 +74,10 @@ PodcastsPage { MprisPlayer {} MediaKeys {} + ConnectionUtil { + 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/utils/ConnectionUtils.qml b/qml/utils/ConnectionUtils.qml new file mode 100644 index 0000000..876eae9 --- /dev/null +++ b/qml/utils/ConnectionUtils.qml @@ -0,0 +1,50 @@ +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; + } + + + function downloadBlockedDialog(callback){ + console.info("suppressing playback, because not on wifi!"); + pageStack.push(Qt.resolvedUrl("../ConnectionBlockedDialog.qml"),{"callback":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..f5b822d 100644 --- a/translations/harbour-org.gpodder.sailfish-bg.ts +++ b/translations/harbour-org.gpodder.sailfish-bg.ts @@ -97,42 +97,42 @@ 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..dec532a 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..486a2ae 100644 --- a/translations/harbour-org.gpodder.sailfish-es.ts +++ b/translations/harbour-org.gpodder.sailfish-es.ts @@ -97,42 +97,42 @@ EpisodeItem - + Pause Pausar - + Play Reproducir - + Download Descargar - + Enqueue En cola - + Delete Borrar - + Deleting Borrando - + Toggle New Nuevo - + Shownotes 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..b1b31e7 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..49599e9 100644 --- a/translations/harbour-org.gpodder.sailfish-pl.ts +++ b/translations/harbour-org.gpodder.sailfish-pl.ts @@ -97,42 +97,42 @@ EpisodeItem - + Pause Pauza - + Play 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..022bdbb 100644 --- a/translations/harbour-org.gpodder.sailfish-ru.ts +++ b/translations/harbour-org.gpodder.sailfish-ru.ts @@ -97,42 +97,42 @@ 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..1b05cdb 100644 --- a/translations/harbour-org.gpodder.sailfish-sv.ts +++ b/translations/harbour-org.gpodder.sailfish-sv.ts @@ -97,42 +97,42 @@ EpisodeItem - + Pause Paus - + Play Spela - + Download Ladda ner - + Enqueue Köa - + Delete Ta bort - + Deleting Tar bort - + Toggle New Ny av/på - + Shownotes Visa notiser @@ -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..e0fcb5d 100644 --- a/translations/harbour-org.gpodder.sailfish-zh_CN.ts +++ b/translations/harbour-org.gpodder.sailfish-zh_CN.ts @@ -97,42 +97,42 @@ 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..2700bd9 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 From e4310b7c59c12bc60697836774af159e61ac243e Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Fri, 23 Oct 2020 17:51:34 +0200 Subject: [PATCH 2/2] creating now a propper closure for the ConnectionBlockedDialog callback --- qml/EpisodeItem.qml | 19 ++++++++++--- qml/Main.qml | 4 +-- .../ConnectionBlockedDialog.qml | 6 ---- .../ConnectionUtils.qml | 10 +++++-- .../harbour-org.gpodder.sailfish-bg.ts | 28 +++++++++---------- .../harbour-org.gpodder.sailfish-de.ts | 12 ++++---- .../harbour-org.gpodder.sailfish-es.ts | 28 +++++++++---------- .../harbour-org.gpodder.sailfish-it.ts | 12 ++++---- .../harbour-org.gpodder.sailfish-pl.ts | 24 ++++++++-------- .../harbour-org.gpodder.sailfish-ru.ts | 28 +++++++++---------- .../harbour-org.gpodder.sailfish-sv.ts | 28 +++++++++---------- .../harbour-org.gpodder.sailfish-zh_CN.ts | 28 +++++++++---------- translations/harbour-org.gpodder.sailfish.ts | 12 ++++---- 13 files changed, 124 insertions(+), 115 deletions(-) rename qml/{ => connectionManagement}/ConnectionBlockedDialog.qml (77%) rename qml/{utils => connectionManagement}/ConnectionUtils.qml (82%) diff --git a/qml/EpisodeItem.qml b/qml/EpisodeItem.qml index 62d749d..97bb2e1 100644 --- a/qml/EpisodeItem.qml +++ b/qml/EpisodeItem.qml @@ -23,6 +23,7 @@ import Sailfish.Silica 1.0 import 'common/constants.js' as Constants import 'common/util.js' as Util +import 'connectionManagement' ListItem { id: episodeItem @@ -75,16 +76,26 @@ ListItem { player.pause(); } else { if(downloaded === false){ - connectionUtil.executeIfConnectionAllowed(doPlayback) + // 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(); + doPlayback(player,id); } } } - function doPlayback(){ - player.playbackEpisode(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 5976e7c..272638d 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -23,7 +23,7 @@ import Sailfish.Silica 1.0 import Nemo.Configuration 1.0 import 'common' -import 'utils' +import 'connectionManagement' PodcastsPage { id: pgst @@ -74,7 +74,7 @@ PodcastsPage { MprisPlayer {} MediaKeys {} - ConnectionUtil { + ConnectionUtils { id: connectionUtil } diff --git a/qml/ConnectionBlockedDialog.qml b/qml/connectionManagement/ConnectionBlockedDialog.qml similarity index 77% rename from qml/ConnectionBlockedDialog.qml rename to qml/connectionManagement/ConnectionBlockedDialog.qml index 7abf2bc..aa7b2c3 100644 --- a/qml/ConnectionBlockedDialog.qml +++ b/qml/connectionManagement/ConnectionBlockedDialog.qml @@ -2,8 +2,6 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 Dialog { - property var callback - Column { width: parent.width @@ -15,8 +13,4 @@ import Sailfish.Silica 1.0 } } - onAccepted: { - callback(); - } - } diff --git a/qml/utils/ConnectionUtils.qml b/qml/connectionManagement/ConnectionUtils.qml similarity index 82% rename from qml/utils/ConnectionUtils.qml rename to qml/connectionManagement/ConnectionUtils.qml index 876eae9..f1f8fa4 100644 --- a/qml/utils/ConnectionUtils.qml +++ b/qml/connectionManagement/ConnectionUtils.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 import Nemo.DBus 2.0 QtObject { + property DBusInterface connmanWifi: DBusInterface { bus: DBus.SystemBus service: "net.connman" @@ -35,9 +36,12 @@ QtObject { } - function downloadBlockedDialog(callback){ - console.info("suppressing playback, because not on wifi!"); - pageStack.push(Qt.resolvedUrl("../ConnectionBlockedDialog.qml"),{"callback":callback}) + /** + * @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){ diff --git a/translations/harbour-org.gpodder.sailfish-bg.ts b/translations/harbour-org.gpodder.sailfish-bg.ts index f5b822d..2b1e186 100644 --- a/translations/harbour-org.gpodder.sailfish-bg.ts +++ b/translations/harbour-org.gpodder.sailfish-bg.ts @@ -99,42 +99,42 @@ Pause - Паузиране + Паузиране Play - Пускане + Пускане - + Download - Изтегляне + - + Enqueue - Към опашката + - + Delete - Изтриване + - + Deleting - Изтрива се + - + Toggle New - Като нов + - + Shownotes - Описание + Описание diff --git a/translations/harbour-org.gpodder.sailfish-de.ts b/translations/harbour-org.gpodder.sailfish-de.ts index dec532a..e7dbcc3 100644 --- a/translations/harbour-org.gpodder.sailfish-de.ts +++ b/translations/harbour-org.gpodder.sailfish-de.ts @@ -107,32 +107,32 @@ Abspielen - + Download - + Enqueue - + Delete - + Deleting - + Toggle New - + Shownotes Shownotes diff --git a/translations/harbour-org.gpodder.sailfish-es.ts b/translations/harbour-org.gpodder.sailfish-es.ts index 486a2ae..a0be8af 100644 --- a/translations/harbour-org.gpodder.sailfish-es.ts +++ b/translations/harbour-org.gpodder.sailfish-es.ts @@ -99,42 +99,42 @@ Pause - Pausar + Pausar Play - Reproducir + Reproducir - + Download - Descargar + - + Enqueue - En cola + - + Delete - Borrar + - + Deleting - Borrando + - + Toggle New - Nuevo + - + Shownotes - Notas + Notas diff --git a/translations/harbour-org.gpodder.sailfish-it.ts b/translations/harbour-org.gpodder.sailfish-it.ts index b1b31e7..a0c3a75 100644 --- a/translations/harbour-org.gpodder.sailfish-it.ts +++ b/translations/harbour-org.gpodder.sailfish-it.ts @@ -107,32 +107,32 @@ Riproduci - + Download - + Enqueue - + Delete - + Deleting - + Toggle New - + Shownotes Note diff --git a/translations/harbour-org.gpodder.sailfish-pl.ts b/translations/harbour-org.gpodder.sailfish-pl.ts index 49599e9..9a0ffdd 100644 --- a/translations/harbour-org.gpodder.sailfish-pl.ts +++ b/translations/harbour-org.gpodder.sailfish-pl.ts @@ -99,40 +99,40 @@ Pause - Pauza + Pauza Play - Odtwarzaj + Odtwarzaj - + Download - Pobierz + - + Enqueue - Kolejkuj + - + Delete - Usuń + - + Deleting - Usuwanie + - + Toggle New - + Shownotes Opis odcinka diff --git a/translations/harbour-org.gpodder.sailfish-ru.ts b/translations/harbour-org.gpodder.sailfish-ru.ts index 022bdbb..44bb05d 100644 --- a/translations/harbour-org.gpodder.sailfish-ru.ts +++ b/translations/harbour-org.gpodder.sailfish-ru.ts @@ -99,42 +99,42 @@ Pause - Пауза + Пауза Play - Играть + Играть - + Download - Скачать + - + Enqueue - В очередь + - + Delete - Удалить + - + Deleting - Удаление + - + Toggle New - Отмечать как новый + - + Shownotes - Описание + Описание diff --git a/translations/harbour-org.gpodder.sailfish-sv.ts b/translations/harbour-org.gpodder.sailfish-sv.ts index 1b05cdb..99e8c2b 100644 --- a/translations/harbour-org.gpodder.sailfish-sv.ts +++ b/translations/harbour-org.gpodder.sailfish-sv.ts @@ -99,42 +99,42 @@ 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 diff --git a/translations/harbour-org.gpodder.sailfish-zh_CN.ts b/translations/harbour-org.gpodder.sailfish-zh_CN.ts index e0fcb5d..431044a 100644 --- a/translations/harbour-org.gpodder.sailfish-zh_CN.ts +++ b/translations/harbour-org.gpodder.sailfish-zh_CN.ts @@ -99,42 +99,42 @@ Pause - 暂停 + 暂停 Play - 播放 + 播放 - + Download - 下载 + - + Enqueue - 队列 + - + Delete - 删除 + - + Deleting - 删除中 + - + Toggle New - 切到新的 + - + Shownotes - 剧集说明 + 剧集说明 diff --git a/translations/harbour-org.gpodder.sailfish.ts b/translations/harbour-org.gpodder.sailfish.ts index 2700bd9..fb2806b 100644 --- a/translations/harbour-org.gpodder.sailfish.ts +++ b/translations/harbour-org.gpodder.sailfish.ts @@ -107,32 +107,32 @@ - + Download - + Enqueue - + Delete - + Deleting - + Toggle New - + Shownotes