Permalink
Browse files

Harmattan: Option to hide podcasts in Music app

Add a configuration option and helper class to add
or remove the gPodder downloads directory to the
Tracker miner configuration, so that users can opt
to hide all downloads from the built-in Music app.
  • Loading branch information...
thp committed May 27, 2012
1 parent 78da431 commit adff9bc8cf17f789f88c5c7ee050d66110c59440
Showing with 83 additions and 0 deletions.
  1. +11 −0 share/gpodder/ui/qml/main_default.qml
  2. +3 −0 src/gpodder/qmlui/__init__.py
  3. +69 −0 src/gpodder/qmlui/helper.py
@@ -275,6 +275,7 @@ PageStackWindow {
function loadSettings() {
settingsAutorotate.checked = configProxy.autorotate
settingsIndexing.checked = trackerMinerConfig.get_index_podcasts()
myGpoEnableSwitch.checked = controller.myGpoEnabled
myGpoUsernameField.text = controller.myGpoUsername
@@ -330,6 +331,16 @@ PageStackWindow {
}
}
SettingsHeader { text: _('Media indexing') }
SettingsSwitch {
id: settingsIndexing
text: _('Show podcasts in Music app')
onCheckedChanged: {
trackerMinerConfig.set_index_podcasts(checked)
}
}
SettingsHeader { text: _('gpodder.net') }
SettingsSwitch {
@@ -759,6 +759,7 @@ def __init__(self, args, gpodder_core, dbus_bus_name):
self.controller = Controller(self)
self.media_buttons_handler = helper.MediaButtonsHandler()
self.tracker_miner_config = helper.TrackerMinerConfig()
self.podcast_model = gPodderPodcastListModel()
self.episode_model = gPodderEpisodeListModel(self.config)
self.last_episode = None
@@ -786,6 +787,8 @@ def __init__(self, args, gpodder_core, dbus_bus_name):
root_context.setContextProperty('configProxy', self.config_proxy)
root_context.setContextProperty('mediaButtonsHandler',
self.media_buttons_handler)
root_context.setContextProperty('trackerMinerConfig',
self.tracker_miner_config)
# Load the QML UI (this could take a while...)
self.view.setSource(QUrl.fromLocalFile(QML('main_default.qml')))
@@ -19,10 +19,14 @@
import gpodder
import os
from gpodder import util
from PySide import QtCore
import logging
logger = logging.getLogger(__name__)
class Action(QtCore.QObject):
def __init__(self, caption, action, target=None):
@@ -108,3 +112,68 @@ def handle_button(self, signal, button):
previousPressed = QtCore.Signal()
nextPressed = QtCore.Signal()
class TrackerMinerConfig(QtCore.QObject):
FILENAME = os.path.expanduser('~/.config/tracker/tracker-miner-fs.cfg')
SECTION = 'IgnoredDirectories'
ENTRY = '$HOME/MyDocs/gPodder/'
def __init__(self, filename=None):
QtCore.QObject.__init__(self)
self._filename = filename or TrackerMinerConfig.FILENAME
self._index_podcasts = self.get_index_podcasts()
@QtCore.Slot(result=bool)
def get_index_podcasts(self):
"""
Returns True if the gPodder directory is indexed, False otherwise
"""
if not os.path.exists(self._filename):
logger.warn('File does not exist: %s', self._filename)
return False
for line in open(self._filename, 'r'):
if line.startswith(TrackerMinerConfig.SECTION + '='):
return (TrackerMinerConfig.ENTRY not in line)
@QtCore.Slot(bool, result=bool)
def set_index_podcasts(self, index_podcasts):
"""
If index_podcasts is True, make sure the gPodder directory is indexed
If index_podcasts is False, ignore the gPodder directory in Tracker
"""
if not os.path.exists(self._filename):
logger.warn('File does not exist: %s', self._filename)
return False
if self._index_podcasts == index_podcasts:
# Nothing to do
return True
tmp_filename = self._filename + '.gpodder.tmp'
out = open(tmp_filename, 'w')
for line in open(self._filename, 'r'):
if line.startswith(TrackerMinerConfig.SECTION + '='):
_, rest = line.rstrip('\n').split('=', 1)
directories = filter(None, rest.split(';'))
if index_podcasts:
if TrackerMinerConfig.ENTRY in directories:
directories.remove(TrackerMinerConfig.ENTRY)
else:
if TrackerMinerConfig.ENTRY not in directories:
directories.append(TrackerMinerConfig.ENTRY)
line = '%(section)s=%(value)s;\n' % {
'section': TrackerMinerConfig.SECTION,
'value': ';'.join(directories),
}
logger.info('Writing new config line: %s', line)
out.write(line)
out.close()
os.rename(tmp_filename, self._filename)
self._index_podcasts = index_podcasts
return True

0 comments on commit adff9bc

Please sign in to comment.