First working QML context menu action: update
This commit is contained in:
parent
682017a633
commit
0731e0fb2f
6 changed files with 74 additions and 10 deletions
|
@ -6,7 +6,7 @@ import 'config.js' as Config
|
|||
Item {
|
||||
id: contextMenu
|
||||
|
||||
property variant items: ['context menu']
|
||||
property variant items: []
|
||||
|
||||
signal close
|
||||
signal response(int index)
|
||||
|
@ -49,7 +49,7 @@ Item {
|
|||
}
|
||||
color: "white"
|
||||
font.pixelSize: parent.height * .3
|
||||
text: modelData
|
||||
text: modelData.caption
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
|
|
|
@ -31,14 +31,14 @@ Item {
|
|||
|
||||
Video {
|
||||
id: videoPlayer
|
||||
opacity: (episode.qfiletype == 'video')?(1):(0)
|
||||
opacity: (episode != undefined && episode.qfiletype == 'video')?(1):(0)
|
||||
anchors.fill: parent
|
||||
source: episode.qsourceurl
|
||||
source: (episode != undefined)?episode.qsourceurl:''
|
||||
}
|
||||
|
||||
Audio {
|
||||
id: audioPlayer
|
||||
source: episode.qsourceurl
|
||||
source: (episode != undefined)?episode.qsourceurl:''
|
||||
}
|
||||
|
||||
ShadowText {
|
||||
|
@ -47,9 +47,8 @@ Item {
|
|||
visible: !videoPlayer.playing
|
||||
|
||||
anchors.centerIn: parent
|
||||
elide: Text.ElideEnd
|
||||
color: "white"
|
||||
text: episode.qtitle
|
||||
text: (episode != undefined)?episode.qtitle:''
|
||||
|
||||
font.pixelSize: 20
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ Item {
|
|||
|
||||
ShadowText {
|
||||
id: descriptionText
|
||||
text: model.podcast.qdescription
|
||||
text: model.podcast.qupdating?"UPDATING...":model.podcast.qdescription
|
||||
visible: text != ''
|
||||
color: "#aaa"
|
||||
offsetX: -1
|
||||
|
|
|
@ -53,3 +53,21 @@ def AutoQObject(*class_def, **kwargs):
|
|||
|
||||
return Object
|
||||
|
||||
|
||||
class Action(QtCore.QObject):
|
||||
def __init__(self, caption, action, target):
|
||||
QtCore.QObject.__init__(self)
|
||||
if isinstance(caption, str):
|
||||
caption = caption.decode('utf-8')
|
||||
self._caption = caption
|
||||
|
||||
self.action = action
|
||||
self.target = target
|
||||
|
||||
changed = QtCore.Signal()
|
||||
|
||||
def _get_caption(self):
|
||||
return self._caption
|
||||
|
||||
caption = QtCore.Property(unicode, _get_caption, notify=changed)
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ from gpodder import model
|
|||
from gpodder import util
|
||||
from gpodder import youtube
|
||||
|
||||
import threading
|
||||
|
||||
class QEpisode(QObject, model.PodcastEpisode):
|
||||
def __init__(self, *args, **kwargs):
|
||||
QObject.__init__(self)
|
||||
|
@ -73,10 +75,30 @@ class QPodcast(QObject, model.PodcastChannel):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
QObject.__init__(self)
|
||||
self._updating = False
|
||||
model.PodcastChannel.__init__(self, *args, **kwargs)
|
||||
|
||||
def qupdate(self):
|
||||
def t(self):
|
||||
self._updating = True
|
||||
self.changed.emit()
|
||||
try:
|
||||
self.update()
|
||||
except Exception, e:
|
||||
# XXX: Handle exception (error message)!
|
||||
pass
|
||||
self._updating = False
|
||||
self.changed.emit()
|
||||
|
||||
threading.Thread(target=t, args=[self]).start()
|
||||
|
||||
changed = Signal()
|
||||
|
||||
def _updating(self):
|
||||
return self._updating
|
||||
|
||||
qupdating = Property(bool, _updating, notify=changed)
|
||||
|
||||
def _title(self):
|
||||
return self.title
|
||||
|
||||
|
@ -93,7 +115,10 @@ class QPodcast(QObject, model.PodcastChannel):
|
|||
qdownloaded = Property(int, _downloaded, notify=changed)
|
||||
|
||||
def _description(self):
|
||||
return util.get_first_line(self.description).decode('utf-8')
|
||||
result = util.get_first_line(self.description)
|
||||
if not isinstance(result, unicode):
|
||||
result = result.decode('utf-8', 'ignore')
|
||||
return result
|
||||
|
||||
qdescription = Property(unicode, _description, notify=changed)
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ class Controller(QObject):
|
|||
QObject.__init__(self)
|
||||
self.root = root
|
||||
self.uidata = uidata
|
||||
self.context_menu_actions = []
|
||||
|
||||
@Slot(QObject)
|
||||
def podcastSelected(self, podcast):
|
||||
|
@ -40,15 +41,32 @@ class Controller(QObject):
|
|||
@Slot(QObject)
|
||||
def podcastContextMenu(self, podcast):
|
||||
print 'context menu:', podcast.qtitle
|
||||
self.root.open_context_menu(['Unsubscribe', 'Add Option', 'Be cool', 'Sing a song', 'Recommend to a friend'])
|
||||
self.context_menu_actions = [
|
||||
helper.Action('Update all', 'update_all', podcast),
|
||||
helper.Action('Update', 'update', podcast),
|
||||
helper.Action('Unsubscribe', 'unsubscribe', podcast),
|
||||
helper.Action('Be cool', 'be_cool', podcast),
|
||||
helper.Action('Sing a song', 'sing_a_song', podcast),
|
||||
]
|
||||
self.root.open_context_menu(self.context_menu_actions)
|
||||
|
||||
@Slot(int)
|
||||
def contextMenuResponse(self, index):
|
||||
print 'context menu response:', index
|
||||
assert index < len(self.context_menu_actions)
|
||||
action = self.context_menu_actions[index]
|
||||
if action.action == 'update':
|
||||
action.target.qupdate()
|
||||
elif action.action == 'update_all':
|
||||
for podcast in self.root.podcast_model.get_objects():
|
||||
podcast.qupdate()
|
||||
if action.action == 'unsubscribe':
|
||||
print 'would unsubscribe from', action.target.title
|
||||
|
||||
@Slot()
|
||||
def contextMenuClosed(self):
|
||||
print 'context menu closed'
|
||||
self.context_menu_actions = []
|
||||
|
||||
@Slot(QObject)
|
||||
def episodeSelected(self, episode):
|
||||
|
@ -86,6 +104,9 @@ class gPodderListModel(QAbstractListModel):
|
|||
self._objects = objects
|
||||
self.reset()
|
||||
|
||||
def get_objects(self):
|
||||
return self._objects
|
||||
|
||||
def get_object(self, index):
|
||||
return self._objects[index.row()]
|
||||
|
||||
|
@ -164,6 +185,7 @@ class qtPodder(QApplication):
|
|||
self.qml_view.rootObject().setCurrentEpisode(episode)
|
||||
|
||||
def main():
|
||||
gpodder.load_plugins()
|
||||
cfg = config.Config(gpodder.config_file)
|
||||
db = dbsqlite.Database(gpodder.database_file)
|
||||
gui = qtPodder(sys.argv, cfg, db)
|
||||
|
|
Loading…
Reference in a new issue