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/>.
20 from __future__
import absolute_import
26 session_bus
= dbus
.SessionBus()
28 from panucci
import util
30 class panucciInterface(dbus
.service
.Object
):
31 """ Panucci's d-bus interface """
33 def __init__(self
, bus_name
, path
='/panucciInterface'):
34 self
.__log
= logging
.getLogger('panucci.dbusinterface.panucciInterface')
35 dbus
.service
.Object
.__init
__(self
, object_path
=path
, bus_name
=bus_name
)
39 self
.headset_device
= None
41 if util
.platform
.MAEMO
:
42 headset_button
= dbus
.SystemBus().get_object(
43 'org.freedesktop.Hal', '/org/freedesktop/Hal/devices/'
44 'platform_retu_headset_logicaldev_input' )
45 self
.headset_device
= dbus
.Interface(
46 headset_button
, 'org.freedesktop.Hal.Device')
48 def register_player(self
, player
):
49 self
.__log
.debug('Registered player.')
52 def register_gui(self
, gui
):
53 self
.__log
.debug('Registered GUI.')
56 def start_service_by_name_noblock(
57 self
, service_name
, reply_handler
=None, error_handler
=None ):
58 # it's dbus.SessionBus.start_service_by_name except it doesn't block
60 return session_bus
.call_async(
61 dbus
.BUS_DAEMON_NAME
, dbus
.BUS_DAEMON_PATH
, dbus
.BUS_DAEMON_IFACE
,
62 'StartServiceByName', 'su', ( service_name
, 0 ), None, None )
64 @dbus.service
.method('org.panucci.panucciInterface')
66 self
.__log
.debug('play() called')
67 if self
.player
is not None: self
.player
.play()
69 @dbus.service
.method('org.panucci.panucciInterface')
71 self
.__log
.debug('pause() called')
72 if self
.player
is not None: self
.player
.pause()
74 @dbus.service
.method('org.panucci.panucciInterface')
76 self
.__log
.debug('stop() called')
77 if self
.player
is not None: self
.player
.stop()
79 @dbus.service
.method('org.panucci.panucciInterface')
81 self
.__log
.debug('playPause() called')
82 if self
.player
is not None: self
.player
.play_pause_toggle()
84 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='s')
85 def play_file(self
, filepath
):
86 self
.__log
.debug('play_file() called')
87 if self
.player
is not None:
88 self
.player
.playlist
.load(filepath
)
91 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='s')
92 def queue_file(self
, filepath
):
93 self
.__log
.debug('queue_file() called')
94 if self
.player
is not None: self
.player
.playlist
.append(filepath
)
96 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='su')
97 def insert_file(self
, pos
, filepath
):
98 self
.__log
.debug('insert_file() called')
99 if self
.player
is not None: self
.player
.playlist
.insert(pos
, filepath
)
101 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='sb')
102 def load_directory(self
, directory
, append
):
103 self
.__log
.debug('load_directory() called')
104 if self
.player
is not None: self
.player
.playlist
.load_directory(
107 @dbus.service
.method('org.panucci.panucciInterface')
108 def show_main_window(self
):
109 self
.__log
.debug('show_main_window() called')
110 if self
.gui
is not None: self
.gui
.show_main_window()
112 # Signals for gPodder's media player integration
113 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='us')
114 def PlaybackStarted(self
, position
, file_uri
):
117 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uuus')
118 def PlaybackStopped(self
, start_position
, end_position
, total_time
, \
122 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uussb')
123 def ChapterAdded(self
, start_position
, end_position
, file_uri
, name
, \
127 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uus')
128 def ChapterRemoved(self
, start_position
, end_position
, file_uri
):
131 interface
= panucciInterface(
132 dbus
.service
.BusName('org.panucci.panucciInterface', session_bus
) )