From ac0e8bc718bad34764bdb96243de9555e71100d5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 13 Mar 2009 22:09:09 +0100 Subject: PlayControl: proper handling of repeat/random. --- nephilim/mpclient.py | 10 ++++++++++ nephilim/plugins/PlayControl.py | 40 ++++------------------------------------ 2 files changed, 14 insertions(+), 36 deletions(-) (limited to 'nephilim') diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py index 664b942..c367204 100644 --- a/nephilim/mpclient.py +++ b/nephilim/mpclient.py @@ -226,6 +226,9 @@ class MPClient(QtCore.QObject): ret = self._retrieve(self._client.status) if not ret: return None + + ret['repeat'] = int(ret['repeat']) + ret['random'] = int(ret['random']) if 'time' in ret: cur, len = ret['time'].split(':') ret['length'] = int(len) @@ -238,6 +241,7 @@ class MPClient(QtCore.QObject): ret['updatings_db'] = 0 if not 'songid' in ret: ret['songid'] = -1 + return ret def timerEvent(self, event): @@ -265,6 +269,12 @@ class MPClient(QtCore.QObject): if self._status['volume'] != old_status['volume']: self.emit(QtCore.SIGNAL('volume_changed'), int(self._status['volume'])) + if self._status['repeat'] != old_status['repeat']: + self.emit(QtCore.SIGNAL('repeat_changed'), bool(self._status['repeat'])) + + if self._status['random'] != old_status['random']: + self.emit(QtCore.SIGNAL('random_changed'), bool(self._status['random'])) + if self._status['playlist'] != old_status['playlist']: self._update_playlist() self.emit(QtCore.SIGNAL('playlist_changed')) diff --git a/nephilim/plugins/PlayControl.py b/nephilim/plugins/PlayControl.py index ca02fe2..eaf56ca 100644 --- a/nephilim/plugins/PlayControl.py +++ b/nephilim/plugins/PlayControl.py @@ -17,11 +17,6 @@ class wgPlayControl(QtGui.QToolBar): random = None p = None - " queued songs: int*" - queuedSongs=[] - # what mode where we in before the queue started? - beforeQueuedMode=None - class VolumeSlider(QtGui.QSlider): def __init__(self, parent): @@ -56,14 +51,16 @@ class wgPlayControl(QtGui.QToolBar): self.btnPrevious=Button("prev", self.onBtnPreviousClick, 'gfx/media-skip-backward.svg', True) self.btnNext=Button("next", self.onBtnNextClick, 'gfx/media-skip-forward.svg', True) - self.random = QtGui.QPushButton(QtGui.QIcon('gfx/random.png'), '', self) + self.random = QtGui.QPushButton(QtGui.QIcon('gfx/media-playlist-shuffle.png'), '', self) self.random.setToolTip('Random') self.random.setCheckable(True) self.connect(self.random, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().random) + self.connect(self.p.mpclient(), QtCore.SIGNAL('random_changed'), self.random.setChecked) self.repeat = QtGui.QPushButton(QtGui.QIcon('gfx/repeat.png'), '', self) self.repeat.setToolTip('Repeat') self.repeat.setCheckable(True) + self.connect(self.p.mpclient(), QtCore.SIGNAL('repeat_changed'), self.repeat.setChecked) self.connect(self.repeat, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().repeat) self.addWidget(self.btnPlayPause) @@ -78,15 +75,9 @@ class wgPlayControl(QtGui.QToolBar): self.connect(self, QtCore.SIGNAL('orientationChanged(Qt::Orientation)'), self.slrVolume.setOrientation) - # queue gets loaded in _load of pluginPlayControl - self.queuedSongs=[] - self.connect(self.p.mpclient(), QtCore.SIGNAL('state_changed'), self.onStateChange) self.connect(self.p.mpclient(), QtCore.SIGNAL('volume_changed'), self.onVolumeChange) - def addSongsToQueue(self, songs): - self.queuedSongs.extend(songs) - def onStateChange(self, new_state): status = self.p.mpclient().status() @@ -127,37 +118,14 @@ class wgPlayControl(QtGui.QToolBar): else: mode=('0', 'min', 'med', 'max')[int(3*v/100)] - # save and load the queue - def saveQueue(self): - # save the ids as a list of space-separated numbers - logging.info("saving queue") - self.p.settings().setValue(self.p.name() + '/queue', QVariant(str(self.queuedSongs)[1:-1].replace(',', ''))) - def loadQueue(self): - # just read all the numbers! - logging.info("loading queue") - self.queuedSongs=[] - i=0 - ids=self.p.settings().value(self.p.name() + '/queue').toString().split(' ') - for id in ids: - try: - self.queuedSongs.append(int(id)) - except: - pass - class PlayControl(Plugin): - o=None - DEFAULTS = {'queue' : ''} + o = None def _load(self): self.o = wgPlayControl(self, None) - self.o.loadQueue() self.parent().addToolBar(QtCore.Qt.TopToolBarArea, self.o) def _unload(self): - self.o.saveQueue() self.parent().removeToolBar(self.o) self.o = None def getInfo(self): return "Have total control over the playing!" - - def addSongsToQueue(self, songs): - return self.o.addSongsToQueue(songs) -- cgit v1.2.3