Support for grouping podcasts by content type
This commit is contained in:
parent
497082ceaf
commit
4e09b984f8
|
@ -9,18 +9,18 @@ SelectableItem {
|
|||
|
||||
Image {
|
||||
id: icon
|
||||
source: 'episodeList/' + model.episode.qfiletype + '.png'
|
||||
source: 'episodeList/' + modelData.qfiletype + '.png'
|
||||
width: Config.iconSize
|
||||
height: Config.iconSize
|
||||
opacity: model.episode.qdownloaded?1:.1
|
||||
opacity: modelData.qdownloaded?1:.1
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Config.largeSpacing
|
||||
}
|
||||
|
||||
ShadowText {
|
||||
text: model.episode.qtitle
|
||||
color: model.episode.qnew?"white":"#888"
|
||||
text: modelData.qtitle
|
||||
color: modelData.qnew?"white":"#888"
|
||||
font.pointSize: episodeItem.height * .25
|
||||
font.bold: false
|
||||
anchors.left: icon.right
|
||||
|
|
|
@ -11,10 +11,10 @@ SelectableItem {
|
|||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.rightMargin: 5
|
||||
text: (model.podcast.qdownloaded)?(''+model.podcast.qdownloaded):('')
|
||||
text: (modelData.qdownloaded)?(''+modelData.qdownloaded):('')
|
||||
color: "white"
|
||||
width: Config.iconSize * 1.5 // FIXME
|
||||
font.pixelSize: podcastItem.height * .6
|
||||
width: Config.iconSize * 1.5
|
||||
font.pixelSize: podcastItem.height * .4
|
||||
horizontalAlignment: Text.AlignRight
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ SelectableItem {
|
|||
}
|
||||
|
||||
Image {
|
||||
source: model.podcast.qcoverfile
|
||||
source: modelData.qcoverfile
|
||||
width: parent.width * .85
|
||||
height: parent.height * .85
|
||||
sourceSize.width: width
|
||||
|
@ -55,7 +55,7 @@ SelectableItem {
|
|||
|
||||
ShadowText {
|
||||
id: titleText
|
||||
text: model.podcast.qtitle
|
||||
text: modelData.qtitle
|
||||
color: "white"
|
||||
anchors {
|
||||
left: parent.left
|
||||
|
@ -66,7 +66,7 @@ SelectableItem {
|
|||
|
||||
ShadowText {
|
||||
id: descriptionText
|
||||
text: model.podcast.qupdating?"UPDATING...":modelData.qdescription
|
||||
text: modelData.qupdating?"UPDATING...":modelData.qdescription
|
||||
visible: text != ''
|
||||
color: "#aaa"
|
||||
offsetX: -1
|
||||
|
|
|
@ -18,6 +18,23 @@ Item {
|
|||
id: listView
|
||||
anchors.fill: parent
|
||||
|
||||
section.property: 'section'
|
||||
section.delegate: Item {
|
||||
height: Config.headerHeight
|
||||
ShadowText {
|
||||
font.pixelSize: parent.height * .5
|
||||
text: section
|
||||
color: "#aaa"
|
||||
anchors {
|
||||
//bottomMargin: Config.smallSpacing
|
||||
leftMargin: Config.switcherWidth / 3
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delegate: PodcastItem {
|
||||
onSelected: rectangle.podcastSelected(item)
|
||||
onContextMenu: rectangle.podcastContextMenu(item)
|
||||
|
|
|
@ -190,6 +190,15 @@ class Database(object):
|
|||
log('Error commiting changes: %s', e, sender=self, traceback=True)
|
||||
self.lock.release()
|
||||
|
||||
def get_content_types(self, id):
|
||||
"""Given a podcast ID, returns the content types"""
|
||||
with self.lock:
|
||||
cur = self.cursor()
|
||||
cur.execute('SELECT DISTINCT mime_type AS mime_type FROM %s WHERE podcast_id = ?' % self.TABLE_EPISODE, (id,))
|
||||
for (mime_type,) in cur:
|
||||
yield mime_type
|
||||
cur.close()
|
||||
|
||||
def get_podcast_statistics(self, id):
|
||||
"""Given a podcast ID, returns the statistics for it
|
||||
|
||||
|
|
|
@ -902,6 +902,16 @@ class PodcastChannel(PodcastModelObject):
|
|||
else:
|
||||
return self.db.get_podcast_statistics(self.id)
|
||||
|
||||
def _get_content_type(self):
|
||||
if 'youtube.com' in self.url:
|
||||
return 'video'
|
||||
|
||||
content_types = self.db.get_content_types(self.id)
|
||||
result = ' and '.join(sorted(set(x.split('/')[0].lower() for x in content_types if not x.startswith('application'))))
|
||||
if result == '':
|
||||
return 'other'
|
||||
return result
|
||||
|
||||
def authenticate_url(self, url):
|
||||
return util.url_add_authentication(url, self.auth_username, self.auth_password)
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ class QPodcast(QObject, model.PodcastChannel):
|
|||
def __init__(self, *args, **kwargs):
|
||||
QObject.__init__(self)
|
||||
self._updating = False
|
||||
self._section_cached = None
|
||||
model.PodcastChannel.__init__(self, *args, **kwargs)
|
||||
|
||||
def qupdate(self):
|
||||
|
@ -112,12 +113,12 @@ class QPodcast(QObject, model.PodcastChannel):
|
|||
qupdating = Property(bool, _updating, notify=changed)
|
||||
|
||||
def _title(self):
|
||||
return self.title
|
||||
return convert(self.title)
|
||||
|
||||
qtitle = Property(unicode, _title, notify=changed)
|
||||
|
||||
def _coverfile(self):
|
||||
return self.cover_file
|
||||
return convert(self.cover_file)
|
||||
|
||||
qcoverfile = Property(unicode, _coverfile, notify=changed)
|
||||
|
||||
|
@ -131,6 +132,14 @@ class QPodcast(QObject, model.PodcastChannel):
|
|||
|
||||
qdescription = Property(unicode, _description, notify=changed)
|
||||
|
||||
def _section(self):
|
||||
if self._section_cached is None:
|
||||
self._section_cached = convert(self._get_content_type())
|
||||
return self._section_cached
|
||||
|
||||
qsection = Property(unicode, _section, notify=changed)
|
||||
|
||||
|
||||
|
||||
|
||||
class Model(model.Model):
|
||||
|
|
|
@ -113,14 +113,12 @@ class Controller(QObject):
|
|||
|
||||
|
||||
class gPodderListModel(QAbstractListModel):
|
||||
COLUMNS = ['object',]
|
||||
|
||||
def __init__(self, objects=None):
|
||||
QAbstractListModel.__init__(self)
|
||||
if objects is None:
|
||||
objects = []
|
||||
self._objects = objects
|
||||
self.setRoleNames(dict(enumerate(self.COLUMNS)))
|
||||
self.setRoleNames({0: 'modelData', 1: 'section'})
|
||||
|
||||
def set_objects(self, objects):
|
||||
self._objects = objects
|
||||
|
@ -136,16 +134,13 @@ class gPodderListModel(QAbstractListModel):
|
|||
return len(self._objects)
|
||||
|
||||
def data(self, index, role):
|
||||
if index.isValid() and role == 0:
|
||||
return self.get_object(index)
|
||||
if index.isValid():
|
||||
if role == 0:
|
||||
return self.get_object(index)
|
||||
elif role == 1:
|
||||
return self.get_object(index).qsection
|
||||
return None
|
||||
|
||||
class gPodderPodcastModel(gPodderListModel):
|
||||
COLUMNS = ['podcast',]
|
||||
|
||||
class gPodderEpisodeModel(gPodderListModel):
|
||||
COLUMNS = ['episode',]
|
||||
|
||||
def QML(filename):
|
||||
for folder in gpodder.ui_folders:
|
||||
filename = os.path.join(folder, filename)
|
||||
|
@ -167,8 +162,8 @@ class qtPodder(QApplication):
|
|||
self.qml_view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
|
||||
|
||||
rc = self.qml_view.rootContext()
|
||||
self.podcast_model = gPodderPodcastModel()
|
||||
self.episode_model = gPodderEpisodeModel()
|
||||
self.podcast_model = gPodderListModel()
|
||||
self.episode_model = gPodderListModel()
|
||||
rc.setContextProperty('podcastModel', self.podcast_model)
|
||||
rc.setContextProperty('episodeModel', self.episode_model)
|
||||
rc.setContextProperty('controller', self.controller)
|
||||
|
@ -197,7 +192,8 @@ class qtPodder(QApplication):
|
|||
root.openContextMenu(items)
|
||||
|
||||
def reload_podcasts(self):
|
||||
self.podcast_model.set_objects(model.Model.get_podcasts(self._db))
|
||||
podcasts = sorted(model.Model.get_podcasts(self._db), key=lambda p: p.qsection)
|
||||
self.podcast_model.set_objects(podcasts)
|
||||
|
||||
def select_podcast(self, podcast):
|
||||
self.episode_model.set_objects(podcast.get_all_episodes())
|
||||
|
|
Loading…
Reference in New Issue