Commits

Vladimir Kolev committed a1773a9

Removed the MessageDialog when user tries to start another instance of
gSharkDown in favor of a commandline interface with 3 commands:
current, state and info.

Comments (0)

Files changed (1)

         self.window = builder.get_object('mainwindow')
         self.window.connect('delete-event', self.window_close)
         self.windowstate = 1
+        self.current_song = None
         self.play_button = builder.get_object('toolbutton_play')
         self.ff_button = builder.get_object('toolbutton_play_next')
         self.prev_button = builder.get_object('toolbutton_play_previous')
                 self.playing = 0
             treerow = self.playlist.iter_nth_child(None, self.playing)
             self.selector.select_iter(treerow)
+            self.current_song = song
             self.staticon.set_from_file(
                 "%s/data/gsharkdown_16_playing.png" % BASEPATH
             )
 
     def get_stream_url(self):
         """
-        Not used at the momment, but should be implemented
-        with an short url to share with friends. TODO
+        TODO: Not used at the momment, but should be implemented
+        with an short url to share with friends.
         """
         pass
 
 class SingleService(dbus.service.Object):
     """
     Class to ensure that gSharkDown is running as a single service
+    and allow command line arguments to be passed to the application
     """
 
     def __init__(self, app):
         dbus.service.Object.__init__(self, bus_name, '/org/gsharkdown/Single')
 
     @dbus.service.method(dbus_interface='org.gsharkdown.Single')
-    def show_window(self):
-        self.app.window.present()
+    def get_current(self):
+        """
+        Method to get the current playing song used in the
+        commandline interface.
+        """
+        if self.app.current_song == None:
+            return "gSharkDown is not playing"
+        else:
+            song = self.app.current_song['ArtistName']
+            song = song + " - "
+            song = song + self.app.current_song['SongName']
+            return song
+        
+    @dbus.service.method(dbus_interface='org.gsharkdown.Single')
+    def get_state(self):
+        """
+        Method to get the player state used in the commandline interface
+        """
+        if self.app.playing == None:
+            return "Stopped"
+        else:
+            return "Playing"
+        
+    @dbus.service.method(dbus_interface='org.gsharkdown.Single')
+    def get_info(self):
+        """
+        Method to get information about the current playing song
+        artist, song, album, year. Used in the commandline interface
+        """
+        if self.app.current_song == None:
+            return ""
+        else:
+            song = self.app.current_song
+            info = "Artist: " + song['ArtistName'] + "\n"
+            info = info + "Song:" + song['SongName'] + "\n"
+            info = info + "Album:" + song['AlbumName'] + "\n"
+            info = info + "Year:" + song['Year'] + "\n"
+            return info
 
 
 if __name__ == "__main__":
     owner = dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER
     if dbus.SessionBus().request_name("org.gsharkdown.Single") != owner:
-        message = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
-                                   gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE,
-                                   _("gSharkDown is already running!"))
-        message.set_title(_("gSharkDown Running"))
-        message.run()
-        message.destroy()
-        method = dbus.SessionBus().get_object("org.gsharkdown.Single",
-                        "/org/gsharkdown/Single").get_dbus_method("show_window")
-        method()
+        """
+        This is just a simple salution so gsharkdown can have a 
+        commandline interface, so others programs can interract with
+        the application and share some informations.
+        """
+        try:
+            if sys.argv[1] == "current":
+                method = dbus.SessionBus().get_object("org.gsharkdown.Single",
+                            "/org/gsharkdown/Single").get_dbus_method("get_current")
+            elif sys.argv[1] == "state":
+                method = dbus.SessionBus().get_object("org.gsharkdown.Single",
+                            "/org/gsharkdown/Single").get_dbus_method("get_state")
+            elif sys.argv[1] == "info":
+                method = dbus.SessionBus().get_object("org.gsharkdown.Single",
+                            "/org/gsharkdown/Single").get_dbus_method("get_info")
+            print method()
+        except:
+            print "gSharkDown commands:\ncurrent\nstate\ninfo\n"
     else:
         app = SharkDown()
         service = SingleService(app)