This file is indexed.

/usr/lib/totem/plugins/dbus/dbusservice.py is in totem-plugins 3.10.1-1ubuntu4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# -*- coding: utf-8 -*-

## Totem D-Bus plugin
## Copyright (C) 2009 Lucky <lucky1.data@gmail.com>
## Copyright (C) 2009 Philip Withnall <philip@tecnocode.co.uk>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor,
## Boston, MA 02110-1301  USA.
##
## Sunday 13th May 2007: Bastien Nocera: Add exception clause.
## See license_change file for details.

import gettext
from gi.repository import GObject, Peas, Totem # pylint: disable-msg=E0611
import dbus, dbus.service
from dbus.mainloop.glib import DBusGMainLoop

gettext.textdomain ("totem")
_ = gettext.gettext

class DbusService (GObject.Object, Peas.Activatable):
    __gtype_name__ = 'DbusService'

    object = GObject.property (type = GObject.Object)

    def __init__ (self):
        GObject.Object.__init__ (self)

        self.root = None

    def do_activate (self):
        DBusGMainLoop (set_as_default = True)

        name = dbus.service.BusName ('org.mpris.MediaPlayer2.totem',
                                     bus = dbus.SessionBus ())
        self.root = Root (name, self.object)

    def do_deactivate (self):
        # Ensure we don't leak our paths on the bus
        self.root.disconnect ()

class Root (dbus.service.Object): # pylint: disable-msg=R0923,R0904
    def __init__ (self, name, totem):
        dbus.service.Object.__init__ (self, name, '/org/mpris/MediaPlayer2')
        self.totem = totem

        self.null_metadata = {
            'year' : u'', 'tracknumber' : '', 'location' : '',
            'title' : u'', 'album' : u'', 'time' : u'', 'genre' : u'',
            'artist' : u''
        }
        self.current_metadata = self.null_metadata.copy ()
        self.current_position = 0

        totem.connect ('metadata-updated', self.__do_update_metadata)
        totem.connect ('notify::playing', self.__do_notify_playing)
        totem.connect ('notify::seekable', self.__do_notify_seekable)
        totem.connect ('notify::current-mrl', self.__do_notify_current_mrl)
        totem.connect ('notify::current-time', self.__do_notify_current_time)

    def disconnect (self):
        self.totem.disconnect_by_func (self.__do_notify_current_time)
        self.totem.disconnect_by_func (self.__do_notify_current_mrl)
        self.totem.disconnect_by_func (self.__do_notify_seekable)
        self.totem.disconnect_by_func (self.__do_notify_playing)
        self.totem.disconnect_by_func (self.__do_update_metadata)

        self.__do_update_metadata (self.totem, '', '', '', 0)

        self.remove_from_connection (None, None)

    def __calculate_playback_status (self):
        if self.totem.is_playing ():
            return 'Playing'
        elif self.totem.is_paused ():
            return 'Paused'
        else:
            return 'Stopped'

    def __calculate_metadata (self):
        metadata = {
            'mpris:trackid': dbus.String (self.totem.props.current_mrl,
                variant_level = 1),
            'mpris:length': dbus.Int64 (
                self.totem.props.stream_length * 1000L,
                variant_level = 1),
        }

        if self.current_metadata['title'] != '':
            metadata['xesam:title'] = dbus.String (
                self.current_metadata['title'], variant_level = 1)

        if self.current_metadata['artist'] != '':
            metadata['xesam:artist'] = dbus.Array (
                [ self.current_metadata['artist'] ], variant_level = 1)

        if self.current_metadata['album'] != '':
            metadata['xesam:album'] = dbus.String (
                self.current_metadata['album'], variant_level = 1)

        if self.current_metadata['tracknumber'] != '':
            metadata['xesam:trackNumber'] = dbus.Int32 (
                self.current_metadata['tracknumber'], variant_level = 1)

        return metadata

    def __do_update_metadata (self, totem, artist, # pylint: disable-msg=R0913
                              title, album, num):
        self.current_metadata = self.null_metadata.copy ()
        if title:
            self.current_metadata['title'] = unicode (title, 'utf-8')
        if artist:
            self.current_metadata['artist'] = unicode (artist, 'utf-8')
        if album:
            self.current_metadata['album'] = unicode (album, 'utf-8')
        if num:
            self.current_metadata['tracknumber'] = num

        self.PropertiesChanged ('org.mpris.MediaPlayer2.Player',
            { 'Metadata': self.__calculate_metadata () }, [])

    def __do_notify_playing (self, totem, prop):
        self.PropertiesChanged ('org.mpris.MediaPlayer2.Player',
            { 'PlaybackStatus': self.__calculate_playback_status () }, [])

    def __do_notify_current_mrl (self, totem, prop):
        self.PropertiesChanged ('org.mpris.MediaPlayer2.Player', {
            'CanPlay': (self.totem.props.current_mrl != None),
            'CanPause': (self.totem.props.current_mrl != None),
            'CanSeek': (self.totem.props.current_mrl != None and
                        self.totem.props.seekable),
        }, [])

    def __do_notify_seekable (self, totem, prop):
        self.PropertiesChanged ('org.mpris.MediaPlayer2.Player', {
            'CanSeek': (self.totem.props.current_mrl != None and
                        self.totem.props.seekable),
        }, [])

    def __do_notify_current_time (self, totem, prop):
        # Only notify of seeks if we've skipped more than 3 seconds
        if abs (totem.props.current_time - self.current_position) > 3:
            self.Seeked (totem.props.current_time * 1000L)

        self.current_position = totem.props.current_time

    # org.freedesktop.DBus.Properties interface
    @dbus.service.method (dbus_interface = dbus.PROPERTIES_IFACE,
                          in_signature = 'ss', # pylint: disable-msg=C0103
                          out_signature = 'v')
    def Get (self, interface_name, property_name):
        return self.GetAll (interface_name)[property_name]

    @dbus.service.method (dbus_interface = dbus.PROPERTIES_IFACE,
                          in_signature = 's', # pylint: disable-msg=C0103
                          out_signature = 'a{sv}')
    def GetAll (self, interface_name):
        if interface_name == 'org.mpris.MediaPlayer2':
            return {
                'CanQuit': True,
                'CanRaise': True,
                'HasTrackList': False,
                'Identity': self.totem.get_version (),
                'DesktopEntry': 'totem',
                'SupportedUriSchemes': self.totem.get_supported_uri_schemes (),
                'SupportedMimeTypes': self.totem.get_supported_content_types (),
            }
        elif interface_name == 'org.mpris.MediaPlayer2.Player':
            # Loop status (we don't support Track)
            if self.totem.action_remote_get_setting (
                Totem.RemoteSetting.REPEAT):
                loop_status = 'Playlist'
            else:
                loop_status = 'None'

            # Shuffle
            shuffle = self.totem.action_remote_get_setting (
                Totem.RemoteSetting.SHUFFLE)

            return {
                'PlaybackStatus': self.__calculate_playback_status (),
                'LoopStatus': loop_status, # TODO: Notifications
                'Rate': 1.0,
                'MinimumRate': 1.0,
                'MaximumRate': 1.0,
                'Shuffle': shuffle, # TODO: Notifications
                'Metadata': self.__calculate_metadata (),
                'Volume': self.totem.get_volume (), # TODO: Notifications
                'Position': self.totem.props.current_time * 1000L,
                'CanGoNext': True, # TODO
                'CanGoPrevious': True, # TODO
                'CanPlay': (self.totem.props.current_mrl != None),
                'CanPause': (self.totem.props.current_mrl != None),
                'CanSeek': (self.totem.props.current_mrl != None and
                            self.totem.props.seekable),
                'CanControl': True,
            }

        raise dbus.exceptions.DBusException (
            'org.mpris.MediaPlayer2.UnknownInterface',
            _(u'The MediaPlayer2 object does not implement the ‘%s’ interface')
                % interface_name)

    @dbus.service.method (dbus_interface = dbus.PROPERTIES_IFACE,
                          in_signature = 'ssv') # pylint: disable-msg=C0103
    def Set (self, interface_name, property_name, new_value):
        if interface_name == 'org.mpris.MediaPlayer2':
            raise dbus.exceptions.DBusException (
                'org.mpris.MediaPlayer2.ReadOnlyProperty',
                _(u'The property ‘%s’ is not writeable.'))
        elif interface_name == 'org.mpris.MediaPlayer2.Player':
            if property_name == 'LoopStatus':
                self.totem.action_remote_set_setting (
                    Totem.RemoteSetting.REPEAT, (new_value == 'Playlist'))
            elif property_name == 'Rate':
                # Ignore, since we don't support setting the rate
                pass
            elif property_name == 'Shuffle':
                self.totem.action_remote_set_setting (
                    Totem.RemoteSetting.SHUFFLE, new_value)
            elif property_name == 'Volume':
                self.totem.action_volume (new_value)

            raise dbus.exceptions.DBusException (
                'org.mpris.MediaPlayer2.ReadOnlyProperty',
                _(u'Unknown property ‘%s’ requested of a MediaPlayer 2 object')
                    % interface_name)

        raise dbus.exceptions.DBusException (
            'org.mpris.MediaPlayer2.UnknownInterface',
            _(u'The MediaPlayer2 object does not implement the ‘%s’ interface')
                % interface_name)

    @dbus.service.signal (dbus_interface = dbus.PROPERTIES_IFACE,
                          signature = 'sa{sv}as') # pylint: disable-msg=C0103
    def PropertiesChanged (self, interface_name, changed_properties,
                           invalidated_properties):
        pass

    # org.mpris.MediaPlayer2 interface
    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def Raise (self):
        main_window = self.totem.get_main_window ()
        main_window.present ()

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def Quit (self):
        self.totem.action_exit ()

    # org.mpris.MediaPlayer2.Player interface
    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def Next (self):
        if self.totem.is_playing () or self.totem.is_paused ():
            return

        self.totem.action_next ()

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def Previous (self):
        if self.totem.is_playing () or self.totem.is_paused ():
            return

        self.totem.action_previous ()

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def Pause (self):
        self.totem.action_pause ()

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def PlayPause (self):
        self.totem.action_play_pause ()

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def Stop (self):
        self.totem.action_stop ()

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = '', # pylint: disable-msg=C0103
                          out_signature = '')
    def Play (self):
        # If playing or no track loaded: do nothing,
        # else: start playing.
        if self.totem.is_playing () or self.totem.props.current_mrl == None:
            return

        self.totem.action_play ()

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = 'x', # pylint: disable-msg=C0103
                          out_signature = '')
    def Seek (self, offset):
        self.totem.action_seek_relative (offset / 1000L, False)

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = 'ox', # pylint: disable-msg=C0103
                          out_signature = '')
    def SetPosition (self, track_id, position):
        position = position / 1000L

        # Bail if the position is not in the permitted range
        if position < 0 or position > self.totem.props.stream_length:
            return

        self.totem.action_seek_time (position, False)

    @dbus.service.method (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          in_signature = 's', # pylint: disable-msg=C0103
                          out_signature = '')
    def OpenUri (self, uri):
        if self.totem.action_set_mrl (uri):
            self.totem.action_play ()

        raise dbus.exceptions.DBusException (
            'org.mpris.MediaPlayer2.InvalidUri',
            _(u'The URI ‘%s’ is not supported.') % uri)

    @dbus.service.signal (dbus_interface = 'org.mpris.MediaPlayer2.Player',
                          signature = 'x') # pylint: disable-msg=C0103
    def Seeked (self, position):
        pass