Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config option to allow downloads via wifi only #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion qml/EpisodeItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,6 +74,10 @@ PodcastsPage {
MprisPlayer {}
MediaKeys {}

ConnectionUtils {
id: connectionUtil
}

GPodderPodcastListModel { id: podcastListModel }
GPodderPodcastListModelConnections {}

Expand Down Expand Up @@ -99,4 +105,11 @@ PodcastsPage {
visible: !py.ready
running: visible
}

ConfigurationValue {
id: configCellularDownloadsEnabled
key: "/apps/ControlPanel/gpodder/cellularDownloadsEnabled"
defaultValue: false
}

}
9 changes: 9 additions & 0 deletions qml/SettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -92,6 +94,13 @@ Page {
maximumValue: 1000
stepSize: 100
}

TextSwitch {
id: cellularDownloadsEnabled
text: qsTr("Allow Downloads via mobile data")
checked: configCellularDownloadsEnabled.value
}

}
}
}
16 changes: 16 additions & 0 deletions qml/connectionManagement/ConnectionBlockedDialog.qml
Original file line number Diff line number Diff line change
@@ -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?"
}
}

}
54 changes: 54 additions & 0 deletions qml/connectionManagement/ConnectionUtils.qml
Original file line number Diff line number Diff line change
@@ -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)
}

}
49 changes: 27 additions & 22 deletions translations/harbour-org.gpodder.sailfish-bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,44 +97,44 @@
<context>
<name>EpisodeItem</name>
<message>
<location filename="../qml/EpisodeItem.qml" line="70"/>
<location filename="../qml/EpisodeItem.qml" line="72"/>
<source>Pause</source>
<translation>Паузиране</translation>
<translation type="unfinished">Паузиране</translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="70"/>
<location filename="../qml/EpisodeItem.qml" line="72"/>
<source>Play</source>
<translation>Пускане</translation>
<translation type="unfinished">Пускане</translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="82"/>
<location filename="../qml/EpisodeItem.qml" line="103"/>
<source>Download</source>
<translation>Изтегляне</translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="92"/>
<location filename="../qml/EpisodeItem.qml" line="113"/>
<source>Enqueue</source>
<translation>Към опашката</translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="105"/>
<location filename="../qml/EpisodeItem.qml" line="126"/>
<source>Delete</source>
<translation>Изтриване</translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="111"/>
<location filename="../qml/EpisodeItem.qml" line="132"/>
<source>Deleting</source>
<translation>Изтрива се</translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="119"/>
<location filename="../qml/EpisodeItem.qml" line="140"/>
<source>Toggle New</source>
<translation>Като нов</translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="125"/>
<location filename="../qml/EpisodeItem.qml" line="146"/>
<source>Shownotes</source>
<translation>Описание</translation>
<translation type="unfinished">Описание</translation>
</message>
</context>
<context>
Expand Down Expand Up @@ -512,35 +512,40 @@
<context>
<name>SettingsPage</name>
<message>
<location filename="../qml/SettingsPage.qml" line="53"/>
<location filename="../qml/SettingsPage.qml" line="55"/>
<source>About</source>
<translation>Относно</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="63"/>
<location filename="../qml/SettingsPage.qml" line="65"/>
<source>Settings</source>
<translation>Настройки</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="67"/>
<location filename="../qml/SettingsPage.qml" line="69"/>
<source>YouTube</source>
<translation>YouTube</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="73"/>
<location filename="../qml/SettingsPage.qml" line="75"/>
<source>API Key (v3)</source>
<translation>API ключ (v3)</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="82"/>
<location filename="../qml/SettingsPage.qml" line="84"/>
<source>Limits</source>
<translation>Ограничения</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="88"/>
<location filename="../qml/SettingsPage.qml" line="90"/>
<source>Maximum episodes per feed</source>
<translation>Максимален брой епизоди за RSS емисия</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="100"/>
<source>Allow Downloads via mobile data</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SleepTimerDialog</name>
Expand Down
33 changes: 19 additions & 14 deletions translations/harbour-org.gpodder.sailfish-de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,42 +97,42 @@
<context>
<name>EpisodeItem</name>
<message>
<location filename="../qml/EpisodeItem.qml" line="70"/>
<location filename="../qml/EpisodeItem.qml" line="72"/>
<source>Pause</source>
<translation type="unfinished">Pause</translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="70"/>
<location filename="../qml/EpisodeItem.qml" line="72"/>
<source>Play</source>
<translation type="unfinished">Abspielen</translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="82"/>
<location filename="../qml/EpisodeItem.qml" line="103"/>
<source>Download</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="92"/>
<location filename="../qml/EpisodeItem.qml" line="113"/>
<source>Enqueue</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="105"/>
<location filename="../qml/EpisodeItem.qml" line="126"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="111"/>
<location filename="../qml/EpisodeItem.qml" line="132"/>
<source>Deleting</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="119"/>
<location filename="../qml/EpisodeItem.qml" line="140"/>
<source>Toggle New</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/EpisodeItem.qml" line="125"/>
<location filename="../qml/EpisodeItem.qml" line="146"/>
<source>Shownotes</source>
<translation type="unfinished">Shownotes</translation>
</message>
Expand Down Expand Up @@ -512,35 +512,40 @@
<context>
<name>SettingsPage</name>
<message>
<location filename="../qml/SettingsPage.qml" line="53"/>
<location filename="../qml/SettingsPage.qml" line="55"/>
<source>About</source>
<translation>Über</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="63"/>
<location filename="../qml/SettingsPage.qml" line="65"/>
<source>Settings</source>
<translation>Einstellungen</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="67"/>
<location filename="../qml/SettingsPage.qml" line="69"/>
<source>YouTube</source>
<translation>YouTube</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="73"/>
<location filename="../qml/SettingsPage.qml" line="75"/>
<source>API Key (v3)</source>
<translation>API Schlüssel (v3)</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="82"/>
<location filename="../qml/SettingsPage.qml" line="84"/>
<source>Limits</source>
<translation>Grenzen</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="88"/>
<location filename="../qml/SettingsPage.qml" line="90"/>
<source>Maximum episodes per feed</source>
<translation>Maximale Anzahl Episoden pro Feed</translation>
</message>
<message>
<location filename="../qml/SettingsPage.qml" line="100"/>
<source>Allow Downloads via mobile data</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SleepTimerDialog</name>
Expand Down
Loading