1 # -*- coding: utf-8 -*-
3 # This file is part of Panucci.
4 # Copyright (c) 2008-2011 The Panucci 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/>.
19 from __future__
import absolute_import
25 session_bus
= dbus
.SessionBus()
27 class panucciInterface(dbus
.service
.Object
):
28 """ Panucci's d-bus interface """
29 HEADSET_NAME
= 'org.freedesktop.Hal'
30 HEADSET_PATH
= '/org/freedesktop/Hal/devices/platform_retu_headset_logicaldev_input'
31 HEADSET_INTF
= 'org.freedesktop.Hal.Device'
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
42 bus
= dbus
.SystemBus()
43 headset
= bus
.get_object(self
.HEADSET_NAME
, self
.HEADSET_PATH
)
44 self
.headset_device
= dbus
.Interface(headset
, self
.HEADSET_INTF
)
46 self
.__log
.debug('Could not find headset object (on Maemo)')
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')
86 self
.__log
.debug('playNext() called')
87 if self
.player
is not None: self
.player
.play_next()
89 @dbus.service
.method('org.panucci.panucciInterface')
91 self
.__log
.debug('playPrev() called')
92 if self
.player
is not None: self
.player
.play_prev()
94 @dbus.service
.method('org.panucci.panucciInterface')
96 self
.__log
.debug('backShort() called')
97 seek_amount
= self
.gui
.config
.getint("options", "seek_short")
98 if self
.player
is not None: self
.player
.do_seek(from_current
=-seek_amount
*10**9)
100 @dbus.service
.method('org.panucci.panucciInterface')
101 def forwardShort(self
):
102 self
.__log
.debug('forwardShort() called')
103 seek_amount
= self
.gui
.config
.getint("options", "seek_short")
104 if self
.player
is not None: self
.player
.do_seek(from_current
=seek_amount
*10**9)
106 @dbus.service
.method('org.panucci.panucciInterface')
108 self
.__log
.debug('backLong() called')
109 seek_amount
= self
.gui
.config
.getint("options", "seek_long")
110 if self
.player
is not None: self
.player
.do_seek(from_current
=-seek_amount
*10**9)
112 @dbus.service
.method('org.panucci.panucciInterface')
113 def forwardLong(self
):
114 self
.__log
.debug('forwardLong() called')
115 seek_amount
= self
.gui
.config
.getint("options", "seek_long")
116 if self
.player
is not None: self
.player
.do_seek(from_current
=seek_amount
*10**9)
118 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='s')
119 def play_file(self
, filepath
):
120 self
.__log
.debug('play_file() called with: ' + filepath
)
121 if self
.player
is not None:
122 self
.player
.playlist
.load(filepath
)
125 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='su')
126 def playback_from(self
, uri
, seconds
):
127 """Playback an URI from a position (in seconds)
128 This sets the current file to "uri" and tries
129 to start playback from the position given by
130 the "seconds" parameter.
133 self
.__log
.debug('%s playback_from %d' % (uri
, seconds
))
134 if self
.player
is not None:
135 self
.show_main_window()
137 new_file
= (self
.player
.playlist
.current_filepath
!= uri
)
139 # I've diabled this for now as I've no possibility to debug it. /xerxes2
140 #if self.gui is not None:
141 # self.gui.set_progress_indicator(new_file)
144 self
.player
.playlist
.load(uri
)
145 self
.player
.playlist
.last()
146 self
.player
.playlist
.set_seek_to(seconds
)
147 elif not self
.player
._is
_playing
:
150 # self.player.do_seek(from_beginning=(10**9)*seconds)
152 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='s')
153 def queue_file(self
, filepath
):
154 self
.__log
.debug('queue_file() called with: ' + filepath
)
155 if self
.player
is not None: self
.player
.playlist
.append(filepath
)
157 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='su')
158 def insert_file(self
, pos
, filepath
):
159 self
.__log
.debug('insert_file() called')
160 if self
.player
is not None: self
.player
.playlist
.insert(pos
, filepath
)
162 @dbus.service
.method('org.panucci.panucciInterface', in_signature
='sb')
163 def load_directory(self
, directory
, append
):
164 self
.__log
.debug('load_directory() called')
165 if self
.player
is not None: self
.player
.playlist
.load_directory(
168 @dbus.service
.method('org.panucci.panucciInterface')
169 def show_main_window(self
):
170 self
.__log
.debug('show_main_window() called')
171 if self
.gui
is not None: self
.gui
.show_main_window()
173 # Signals for gPodder's media player integration
174 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='us')
175 def PlaybackStarted(self
, position
, file_uri
):
178 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uuus')
179 def PlaybackStopped(self
, start_position
, end_position
, total_time
, \
183 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uussb')
184 def ChapterAdded(self
, start_position
, end_position
, file_uri
, name
, \
188 @dbus.service
.signal(dbus_interface
='org.gpodder.player', signature
='uus')
189 def ChapterRemoved(self
, start_position
, end_position
, file_uri
):
192 interface
= panucciInterface(
193 dbus
.service
.BusName('org.panucci.panucciInterface', session_bus
) )