2 # Copyright (C) 2008 jerous <jerous@gmail.com>
3 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
5 # Nephilim is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Nephilim is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
19 from PyQt4
import QtGui
, QtCore
20 from PyQt4
.QtCore
import QVariant
22 from ..plugin
import Plugin
23 from ..misc
import sec2min
, APPNAME
, appIcon
, expand_tags
25 class Systray(Plugin
):
29 DEFAULTS
= {'format': '$track - $title by $artist on $album ($length)'}
32 self
.format
= self
.settings().value(self
.name() + '/format').toString()
33 class SystrayWheelEventObject(QtCore
.QObject
):
34 """This class listens for systray-wheel events"""
35 def eventFilter(self
, object, event
):
36 if type(event
)==QtGui
.QWheelEvent
:
37 numDegrees
=event
.delta() / 8
38 numSteps
=5*numDegrees
/15
39 self
.plugin
.mpclient().set_volume(self
.plugin
.mpclient().volume() + numSteps
)
44 self
.o
= QtGui
.QSystemTrayIcon(QtGui
.QIcon(appIcon
), self
.parent())
45 self
.eventObj
=SystrayWheelEventObject()
46 self
.eventObj
.plugin
= self
47 self
.o
.installEventFilter(self
.eventObj
)
48 self
.parent().connect(self
.o
, QtCore
.SIGNAL('activated (QSystemTrayIcon::ActivationReason)')
49 , self
.onSysTrayClick
)
53 self
.disconnect(self
.mpclient(), QtCore
.SIGNAL('song_changed'), self
.update
)
54 self
.disconnect(self
.mpclient(), QtCore
.SIGNAL('disconnected'), self
.update
)
55 self
.disconnect(self
.mpclient(), QtCore
.SIGNAL('time_changed'), self
.update
)
57 self
.o
.setIcon(QtGui
.QIcon(None))
59 self
.parent()._wheelEvent
= None
61 return "Display the mpclientpc icon in the systray."
64 status
= self
.mpclient().status()
69 values
['state']={'play':'playing', 'stop':'stopped', 'pause':'paused'}[status
['state']]
71 values
['length'] = sec2min(status
['length'])
72 values
['time'] = sec2min(status
['time'])
74 song
= self
.mpclient().current_song()
76 self
.o
.setToolTip(expand_tags(self
.format
, (song
,)))
78 self
.o
.setToolTip('%s not playing'%APPNAME
)
80 def onSysTrayClick(self
, reason
):
81 if reason
== QtGui
.QSystemTrayIcon
.Trigger
or\
82 reason
== QtGui
.QSystemTrayIcon
.Context
:
88 elif reason
== QtGui
.QSystemTrayIcon
.MiddleClick
:
89 if self
.mpclient().is_playing():
90 self
.mpclient().pause()
92 self
.mpclient().resume()
94 class SettingsWidgetSystray(Plugin
.SettingsWidget
):
97 def __init__(self
, plugin
):
98 Plugin
.SettingsWidget
.__init
__(self
, plugin
)
100 self
.format
= QtGui
.QLineEdit(self
.settings().value(self
.plugin
.name() + '/format').toString())
102 self
.setLayout(QtGui
.QVBoxLayout())
103 self
._add
_widget
(self
.format
, 'Tooltip format')
105 def save_settings(self
):
106 self
.settings().beginGroup(self
.plugin
.name())
107 self
.settings().setValue('format', QVariant(self
.format
.text()))
108 self
.settings().endGroup()
110 def get_settings_widget(self
):
111 return self
.SettingsWidgetSystray(self
)