~ubuntu-branches/ubuntu/precise/remuco-server/precise

« back to all changes in this revision

Viewing changes to adapter/amarok/remuco-amarok

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-03-30 00:59:36 UTC
  • Revision ID: james.westby@ubuntu.com-20090330005936-hkxki384hm0d33gj
Tags: upstream-0.8.2.1
ImportĀ upstreamĀ versionĀ 0.8.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
# =============================================================================
 
4
#
 
5
#    Remuco - A remote control system for media players.
 
6
#    Copyright (C) 2006-2009 Oben Sonne <obensonne@googlemail.com>
 
7
#
 
8
#    This file is part of Remuco.
 
9
#
 
10
#    Remuco is free software: you can redistribute it and/or modify
 
11
#    it under the terms of the GNU General Public License as published by
 
12
#    the Free Software Foundation, either version 3 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    Remuco is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU General Public License for more details.
 
19
#
 
20
#    You should have received a copy of the GNU General Public License
 
21
#    along with Remuco.  If not, see <http://www.gnu.org/licenses/>.
 
22
#
 
23
# =============================================================================
 
24
 
 
25
"""Remuco player adapter for Amarok, implemented as an executable script."""
 
26
 
 
27
import dbus
 
28
from dbus.exceptions import DBusException
 
29
import gobject
 
30
 
 
31
import remuco
 
32
from remuco import log
 
33
 
 
34
# =============================================================================
 
35
# player adapter
 
36
# =============================================================================
 
37
 
 
38
class AmarokAdapter(remuco.MPRISAdapter):
 
39
    
 
40
    def __init__(self):
 
41
        
 
42
        remuco.MPRISAdapter.__init__(self, "amarok", "Amarok",
 
43
                                     mime_types=("audio",), rating=True)
 
44
        
 
45
        self.__am = None
 
46
        
 
47
    def start(self):
 
48
        
 
49
        remuco.MPRISAdapter.start(self)
 
50
        
 
51
        try:
 
52
            bus = dbus.SessionBus()
 
53
            proxy = bus.get_object("org.kde.amarok", "/amarok/MainWindow")
 
54
            self.__am = dbus.Interface(proxy, "org.kde.KMainWindow")
 
55
        except DBusException, e:
 
56
            raise StandardError("dbus error: %s" % e)
 
57
 
 
58
    def stop(self):
 
59
        
 
60
        remuco.MPRISAdapter.stop(self)
 
61
        
 
62
        self.__am = None
 
63
        
 
64
    def poll(self):
 
65
 
 
66
        remuco.MPRISAdapter.poll(self)
 
67
        
 
68
        # amarok does not signal change in shuffle state
 
69
        self._poll_status()
 
70
        
 
71
    # =========================================================================
 
72
    # control interface 
 
73
    # =========================================================================
 
74
    
 
75
    def ctrl_rate(self, rating):
 
76
        
 
77
        rating = min(rating, 5)
 
78
        rating = max(rating, 1)
 
79
        action = "rate%s" % rating
 
80
        
 
81
        try:
 
82
            self.__am.activateAction(action)
 
83
        except DBusException, e:
 
84
            log.warning("dbus error: %s" % e)
 
85
            
 
86
    def ctrl_toggle_shuffle(self):
 
87
        
 
88
        remuco.MPRISAdapter.ctrl_toggle_shuffle(self)
 
89
        
 
90
        # amarok does not signal change in shuffle state
 
91
        gobject.idle_add(self._poll_status)
 
92
            
 
93
# =============================================================================
 
94
# main
 
95
# =============================================================================
 
96
 
 
97
if __name__ == '__main__':
 
98
 
 
99
    pa = AmarokAdapter()
 
100
    mg = remuco.Manager(pa, player_dbus_name="org.mpris.amarok")
 
101
    
 
102
    mg.run()
 
103