~ubuntu-branches/ubuntu/utopic/radiotray/utopic

« back to all changes in this revision

Viewing changes to data/plugins/MateMediaKeysPlugin.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-05-09 21:24:43 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20130509212443-x1rgywggtb3bsorf
Tags: 0.7.3-1ubuntu1
* Merge from Debian unstable. (LP: #1156142, #972259, #972205)
  Remaining changes:
  - patch config to use appindicator by default
  - depend on python-appindicator

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##########################################################################
 
2
# Copyright 2009 Carlos Ribeiro
 
3
#
 
4
# This file is part of Radio Tray
 
5
#
 
6
# Radio Tray is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation, either version 1 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# Radio Tray is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with Radio Tray.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
##########################################################################
 
20
 
 
21
from Plugin import Plugin
 
22
import dbus
 
23
 
 
24
class MateMediaKeysPlugin(Plugin):
 
25
 
 
26
    def __init__(self):
 
27
        super(MateMediaKeysPlugin, self).__init__()
 
28
 
 
29
 
 
30
    def initialize(self, name, eventManagerWrapper, eventSubscriber, provider, cfgProvider, mediator, tooltip):
 
31
    
 
32
        self.name = name
 
33
        self.eventManagerWrapper = eventManagerWrapper
 
34
        self.eventSubscriber = eventSubscriber
 
35
        self.provider = provider
 
36
        self.cfgProvider = cfgProvider
 
37
        self.mediator = mediator
 
38
        self.tooltip = tooltip
 
39
 
 
40
 
 
41
    def getName(self):
 
42
        return self.name
 
43
 
 
44
 
 
45
    def activate(self):
 
46
        try:
 
47
            self.bus = dbus.SessionBus()
 
48
            self.bus_object = self.bus.get_object('org.mate.SettingsDaemon', '/org/mate/SettingsDaemon/MediaKeys')
 
49
            self.bus_object.GrabMediaPlayerKeys("RadioTray", 0, dbus_interface='org.mate.SettingsDaemon.MediaKeys')
 
50
            self.bus_object.connect_to_signal('MediaPlayerKeyPressed', self.handle_mediakey)
 
51
        except:
 
52
            print "Could not bind to mate for Media Keys"
 
53
            
 
54
            
 
55
    def handle_mediakey(self, *mmkeys):
 
56
        for key in mmkeys:
 
57
            if key == "Play":
 
58
                if (self.mediator.isPlaying()):
 
59
                    self.mediator.stop()
 
60
                else:
 
61
                    self.mediator.playLast()
 
62
            elif key == "Stop":
 
63
                if (self.mediator.isPlaying()):
 
64
                    self.mediator.stop()