Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Option: Auto-download episodes when on Wi-Fi (Maemo bug 5181)
  • Loading branch information
thp committed Feb 19, 2011
1 parent edd144d commit c9e725b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
57 changes: 57 additions & 0 deletions src/gpodder/gtkui/frmntl/network.py
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
#
# gPodder - A media aggregator and podcast client
# Copyright (c) 2005-2011 Thomas Perl and the gPodder Team
#
# gPodder is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# gPodder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#


# gpodder.gtkui.frmntl.network - Network connection manager
# Thomas Perl <thp@gpodder.org>; 2011-02-19


import dbus
import conic


class NetworkManager(object):
ICD_NAME = 'com.nokia.icd'
ICD_PATH = '/com/nokia/icd'
ICD_INTF = 'com.nokia.icd'

def __init__(self):
self.system_bus = dbus.Bus.get_system()
self.icd_obj = self.system_bus.get_object(self.ICD_NAME, \
self.ICD_PATH)
self.icd = dbus.Interface(self.icd_obj, self.ICD_INTF)
self.conic = conic.Connection()

def get_current_iap(self):
try:
iap_id, _, _, _, _, _, _ = self.icd.get_statistics()
except Exception, e:
return None
return self.conic.get_iap(iap_id)

def get_bearer_type(self):
iap = self.get_current_iap()
if iap is None:
return None
return iap.get_bearer_type()

def connection_is_wlan(self):
return self.get_bearer_type() in (conic.BEARER_WLAN_INFRA, \
conic.BEARER_WLAN_ADHOC)

2 changes: 1 addition & 1 deletion src/gpodder/gtkui/frmntl/preferences.py
Expand Up @@ -44,7 +44,7 @@ class gPodderPreferences(BuilderWidget):
('quiet', _('Do nothing')),
('never', _('Show episode list')),
('queue', _('Add to download list')),
# ('wifi', _('Download when on Wi-Fi')),
('wifi', _('Download when on Wi-Fi')),
('always', _('Download immediately')),
)

Expand Down
8 changes: 7 additions & 1 deletion src/gpodder/gui.py
Expand Up @@ -145,6 +145,7 @@ def __init__(self, *args, **kwargs):
from gpodder.gtkui.frmntl.portrait import FremantleRotation
from gpodder.gtkui.frmntl.mafw import MafwPlaybackMonitor
from gpodder.gtkui.frmntl.hints import HINT_STRINGS
from gpodder.gtkui.frmntl.network import NetworkManager

from gpodder.gtkui.interface.common import Orientation

Expand Down Expand Up @@ -234,6 +235,9 @@ def show_hint(button):
gpodder.__version__, \
self.config.rotation_mode)

# Initialize the Fremantle network manager
self.network_manager = NetworkManager()

if self.config.rotation_mode == FremantleRotation.ALWAYS:
util.idle_add(self.on_window_orientation_changed, \
Orientation.PORTRAIT)
Expand Down Expand Up @@ -2849,7 +2853,9 @@ def application_in_foreground():
if self.config.auto_download == 'quiet' and not self.config.auto_update_feeds:
# New episodes found, but we should do nothing
self.show_message(_('New episodes are available.'))
elif self.config.auto_download == 'always':
elif self.config.auto_download == 'always' or \
(self.config.auto_download == 'wifi' and \
self.network_manager.connection_is_wlan()):
count = len(episodes)
title = N_('Downloading %(count)d new episode.', 'Downloading %(count)d new episodes.', count) % {'count':count}
self.show_message(title)
Expand Down

0 comments on commit c9e725b

Please sign in to comment.