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
21 from ..plugin
import Plugin
22 from ..common
import sec2min
, APPNAME
, appIcon
, expand_tags
25 class Systray(Plugin
):
27 info
= 'Provides the systray icon.'
35 DEFAULTS
= {'format': '${track} - ${title} by ${artist} on ${album} (${length})'}
38 self
.format
= self
.settings
.value(self
.name
+ '/format')
39 class SystrayWheelEventObject(QtCore
.QObject
):
40 """This class listens for systray-wheel events"""
41 def eventFilter(self
, object, event
):
42 if type(event
)==QtGui
.QWheelEvent
:
43 numDegrees
=event
.delta() / 8
44 numSteps
=5*numDegrees
/15
45 self
.plugin
.mpclient
.set_volume(self
.plugin
.mpclient
.status
['volume'] + numSteps
)
50 self
.o
= QtGui
.QSystemTrayIcon(QtGui
.QIcon(appIcon
), self
.parent())
51 self
.eventObj
=SystrayWheelEventObject()
52 self
.eventObj
.plugin
= self
53 self
.o
.installEventFilter(self
.eventObj
)
54 self
.o
.activated
.connect(self
.onSysTrayClick
)
56 self
.mpclient
.song_changed
.connect(self
.update
)
59 self
.mpclient
.song_changed
.disconnect(self
.update
)
61 self
.o
.setIcon(QtGui
.QIcon(None))
63 self
.parent()._wheelEvent
= None
66 status
= self
.mpclient
.status
71 values
['state']={'play':'playing', 'stop':'stopped', 'pause':'paused'}[status
['state']]
73 values
['length'] = sec2min(status
['time'][0])
74 values
['time'] = sec2min(status
['time'][1])
76 song
= self
.mpclient
.cur_song
78 self
.o
.setToolTip(expand_tags(self
.format
, (song
,)))
80 self
.o
.setToolTip('%s not playing'%APPNAME
)
82 def onSysTrayClick(self
, reason
):
83 if reason
== QtGui
.QSystemTrayIcon
.Trigger
or\
84 reason
== QtGui
.QSystemTrayIcon
.Context
:
90 elif reason
== QtGui
.QSystemTrayIcon
.MiddleClick
:
91 if self
.mpclient
.is_playing():
94 self
.mpclient
.resume()
96 class SettingsWidgetSystray(Plugin
.SettingsWidget
):
99 def __init__(self
, plugin
):
100 Plugin
.SettingsWidget
.__init
__(self
, plugin
)
102 self
.format
= QtGui
.QLineEdit(self
.settings
.value(self
.plugin
.name
+ '/format'))
104 self
.setLayout(QtGui
.QVBoxLayout())
105 self
._add
_widget
(self
.format
, 'Tooltip format')
107 def save_settings(self
):
108 self
.settings
.beginGroup(self
.plugin
.name
)
109 self
.settings
.setValue('format', self
.format
.text())
110 self
.settings
.endGroup()
112 def get_settings_widget(self
):
113 return self
.SettingsWidgetSystray(self
)
115 def set_enabled(self
, val
):