Commits

Vladimir Kolev committed 36911d0

Single Service is now working after the refactoring to the methods

  • Participants
  • Parent commits 551b1b7

Comments (0)

Files changed (2)

File gsharkdown.py

     print "You don't have python-appindicator installed!"
     print "StautsIcon will be used instead"
     HAVE_INDICATOR = False
-    
+
 # Common imports
 import dbus
 import dbus.service
     else:
         app = SharkDown()
         env().set_app(app)
-        service = SingleService(app)
+        service = SingleService(app, env)
         gtk.main()

File lib/SingleService.py

 import dbus
 import dbus.service
 import dbus.glib
+import glib
 
 class SingleService(dbus.service.Object):
     """
     and allow command line arguments to be passed to the application
     """
 
-    def __init__(self, app):
+    def __init__(self, app, env):
         self.app = app
+        self.env = env()
         bus_name = dbus.service.BusName('org.gsharkdown.Single',
                                        bus = dbus.SessionBus())
         dbus.service.Object.__init__(self, bus_name, '/org/gsharkdown/Single')
         Method to get the current playing song used in the
         commandline interface.
         """
-        if self.app.current_song == None:
+        if self.app.playlist.playing_song == None:
             return "gSharkDown is not playing"
         else:
-            song = self.app.current_song['ArtistName']
+            song = self.app.playlist.playing_song.get_artist()
             song = song + " - "
-            song = song + self.app.current_song['SongName']
+            song = song + self.app.playlist.playing_song.get_title()
             return song
 
     @dbus.service.method(dbus_interface = 'org.gsharkdown.Single')
         """
         Method to get the player state used in the commandline interface
         """
-        if self.app.playing == None:
+        if self.app.playlist.playing_song == None:
             return "Stopped"
         else:
             return "Playing"
         Method to get information about the current playing song
         artist, song, album, year. Used in the commandline interface
         """
-        if self.app.current_song == None:
+        if self.app.playlist.playing_song == None:
             return ""
         else:
-            song = self.app.current_song
-            info = "Artist: " + glib.markup_escape_text(song['ArtistName']) + "\n"
-            info += "Song:" + glib.markup_escpate_text(song['SongName']) + "\n"
-            info += "Album:" + glib.markup_escpate_text(song['AlbumName']) + "\n"
-            info += "Year:" + song['Year'] + "\n"
+            song = self.app.playlist.playing_song
+            info = "Artist: " + glib.markup_escape_text(song.get_artist()) + "\n"
+            info += "Song:" + glib.markup_escape_text(song.get_title()) + "\n"
+            info += "Album:" + glib.markup_escape_text(song.get_album()) + "\n"
+            info += "Year:" + song.get_year() + "\n"
             return info
 
     @dbus.service.method(dbus_interface = 'org.gsharkdown.Single')
         """
         Method to return the current version of gSharkDown.
         """
-        f = open("%s/VERSION" % env().BASEPATH, 'r')
+        f = open("%s/VERSION" % self.env.BASEPATH, 'r')
         version = f.read()
         f.close()
         return version
         Method to read the HELP file and display the help message
         when using the commandline interface.
         """
-        return open("%s/HELP" % env().BASEPATH, 'r').read()
+        return open("%s/HELP" % self.env().BASEPATH, 'r').read()