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
)
51 self
.connect(self
.mpclient
, QtCore
.SIGNAL('song_changed'), self
.update
)
54 self
.disconnect(self
.mpclient
, QtCore
.SIGNAL('song_changed'), self
.update
)
55 self
.disconnect(self
.mpclient
, QtCore
.SIGNAL('disconnected'), self
.update
)
56 self
.disconnect(self
.mpclient
, QtCore
.SIGNAL('time_changed'), self
.update
)
58 self
.o
.setIcon(QtGui
.QIcon(None))
60 self
.parent()._wheelEvent
= None
62 return "Display the mpclientpc icon in the systray."
65 status
= self
.mpclient
.status()
70 values
['state']={'play':'playing', 'stop':'stopped', 'pause':'paused'}[status
['state']]
72 values
['length'] = sec2min(status
['length'])
73 values
['time'] = sec2min(status
['time'])
75 song
= self
.mpclient
.current_song()
77 self
.o
.setToolTip(expand_tags(self
.format
, (song
,)))
79 self
.o
.setToolTip('%s not playing'%APPNAME
)
81 def onSysTrayClick(self
, reason
):
82 if reason
== QtGui
.QSystemTrayIcon
.Trigger
or\
83 reason
== QtGui
.QSystemTrayIcon
.Context
:
89 elif reason
== QtGui
.QSystemTrayIcon
.MiddleClick
:
90 if self
.mpclient
.is_playing():
93 self
.mpclient
.resume()
95 class SettingsWidgetSystray(Plugin
.SettingsWidget
):
98 def __init__(self
, plugin
):
99 Plugin
.SettingsWidget
.__init
__(self
, plugin
)
101 self
.format
= QtGui
.QLineEdit(self
.settings
.value(self
.plugin
.name
+ '/format').toString())
103 self
.setLayout(QtGui
.QVBoxLayout())
104 self
._add
_widget
(self
.format
, 'Tooltip format')
106 def save_settings(self
):
107 self
.settings
.beginGroup(self
.plugin
.name
)
108 self
.settings
.setValue('format', QVariant(self
.format
.text()))
109 self
.settings
.endGroup()
111 def get_settings_widget(self
):
112 return self
.SettingsWidgetSystray(self
)
114 def set_enabled(self
, val
):