3 # This file is part of Panucci.
4 # Copyright (c) 2008-2010 The Panucci Audiobook and Podcast Player Project
6 # Panucci 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 3 of the License, or
9 # (at your option) any later version.
11 # Panucci 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.
16 # You should have received a copy of the GNU General Public License
17 # along with Panucci. If not, see <http://www.gnu.org/licenses/>.
24 session_bus
= dbus
.SessionBus()
28 class panucciInterface(dbus
.service
.Object
):
29 """ Panucci's d-bus interface """
31 def __init__(self
, bus_name
, path
='/panucciInterface'):
32 self
.__log
= logging
.getLogger('panucci.dbusinterface.panucciInterface')
33 dbus
.service
.Object
.__init
__(self
, object_path
=path
, bus_name
=bus_name
)
37 self
.headset_device
= None
39 if util
.platform
.MAEMO
:
40 headset_button
= dbus
.SystemBus().get_object(
41 'org.freedesktop.Hal', '/org/freedesktop/Hal/devices/'
42 'platform_retu_headset_logicaldev_input' )
43 self
.headset_device
= dbus
.Interface(
44 headset_button
, 'org.freedesktop.Hal.Device')
46 def register_player(self
, player
):
47 self
.__log
.debug('Registered player.')
50 def register_gui(self
, gui
):
51 self
.__log
.debug('Registered GUI.')
54 def start_service_by_name_noblock(
55 self
, service_name
, reply_handler
=None, error_handler
=None ):
56 # it's dbus.SessionBus.start_service_by_name except it doesn't block
58 return session_bus
.call_async(
59 dbus
.BUS_DAEMON_NAME
, dbus
.BUS_DAEMON_PATH
, dbus
.BUS_DAEMON_IFACE
,
60 'StartServiceByName', 'su', ( service_name
, 0 ), None, None )
62 @dbus.service
.method('org.panucci.panucciInterface')
64 self
.__log
.debug('play() called')
65 if self
.player
is not None: self
.player
.play()
67 @dbus.service
.method('org.panucci.panucciInterface')
69 self
.__log
.debug('pause() called')
70 if self
.player
is not None: self
.player
.pause()
72 @dbus.service
.method('org.panucci.panucciInterface')
74 self
.__log
.debug('stop() called')
75 if self
.player
is not None: self
.player
.stop()
77 @dbus.service
.method('org.panucci.panucciInterface')
79 self
.__log
.debug('playPause() called')
80 if self
.player
is not None: self
.player
.play_pause_toggle()
82 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='s')
83 def play_file(self
, filepath
):
84 self
.__log
.debug('play_file() called')
85 if self
.player
is not None:
86 self
.player
.playlist
.load(filepath
)
89 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='s')
90 def queue_file(self
, filepath
):
91 self
.__log
.debug('queue_file() called')
92 if self
.player
is not None: self
.player
.playlist
.append(filepath
)
94 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='su')
95 def insert_file(self
, pos
, filepath
):
96 self
.__log
.debug('insert_file() called')
97 if self
.player
is not None: self
.player
.playlist
.insert(pos
, filepath
)
99 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='sb')
100 def load_directory(self
, directory
, append
):
101 self
.__log
.debug('load_directory() called')
102 if self
.player
is not None: self
.player
.playlist
.load_directory(
105 @dbus.service
.method('org.panucci.panucciInterface')
106 def show_main_window(self
):
107 self
.__log
.debug('show_main_window() called')
108 if self
.gui
is not None: self
.gui
.show_main_window()
110 # Signals for gPodder's media player integration
111 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='us')
112 def PlaybackStarted(self
, position
, file_uri
):
115 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uuus')
116 def PlaybackStopped(self
, start_position
, end_position
, total_time
, \
120 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uussb')
121 def ChapterAdded(self
, start_position
, end_position
, file_uri
, name
, \
125 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uus')
126 def ChapterRemoved(self
, start_position
, end_position
, file_uri
):
129 interface
= panucciInterface(
130 dbus
.service
.BusName('org.panucci.panucciInterface', session_bus
) )