Commits

Vladimir Kolev committed 4e2a123

Added the reuqestet option - when double click on search result - the song is
added to the playlist and starts playing

New VERSION file that will be used to check for new versions of gSharkDown

Comments (0)

Files changed (5)

             <child>
               <object class="GtkHButtonBox" id="hbuttonbox1">
                 <property name="visible">True</property>
+                <property name="spacing">90</property>
                 <property name="layout_style">end</property>
                 <child>
+                  <object class="GtkButton" id="updatbut">
+                    <property name="label" translatable="yes">Check for update</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="image">image3</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkButton" id="flattrbut">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">0</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
               </object>
     <property name="visible">True</property>
     <property name="pixbuf">flattr-badge-large.png</property>
   </object>
+  <object class="GtkImage" id="image3">
+    <property name="visible">True</property>
+    <property name="icon_name">system-software-update</property>
+  </object>
 </interface>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="rules_hint">True</property>
-                                <signal name="row_activated" handler="play_selected"/>
                               </object>
                             </child>
                           </object>
         self.result = gtk.ListStore(str, str, str, str)
         self.result_view = builder.get_object('treeview1')
         self.result_view.set_model(self.result)
+        self.result_view.connect("row-activated", self.add_and_play_result)
         self._create_search_columns()
 
         # Play List definition
         self.playlist = gtk.ListStore(str, str, str)
         self.play_view = builder.get_object('treeview2')
         self.play_view.set_model(self.playlist)
-        self.play_view.connect('row-activated', self.double_click_start)
+        #self.play_view.connect('row-activated', self.double_click_start)
         self._create_play_columns()
         self.selector = self.play_view.get_selection()
 
         prebut.connect("activate", self.play_previous)
         ffbut = gtk.ImageMenuItem(gtk.STOCK_MEDIA_NEXT)
         ffbut.connect("activate", self.play_next)
+
+        updimg = gtk.Image()
+        updimg.set_from_icon_name('system-software-update',
+                                 gtk.ICON_SIZE_MENU)
+        updbut = gtk.ImageMenuItem("Check for update")
+        updbut.set_image(updimg)
+        updbut.connect("activate", self.check_for_update)
         quiter = gtk.ImageMenuItem(gtk.STOCK_QUIT)
         quiter.connect("activate", self.quit_app)
 
         menu.append(ffbut)
         menu.append(gtk.SeparatorMenuItem())
         menu.append(about)
+        menu.append(updbut)
         menu.append(prefs)
         menu.append(gtk.SeparatorMenuItem())
         menu.append(quiter)
         menu.popup(None, None, gtk.status_icon_position_menu,
                   button, time, icon)
 
+    def check_for_update(self, widget, data=None):
+        local = open('%s/VERSION' % BASEPATH, 'r')
+        localversion = local.read().replace("\n", "")
+        print localversion
+
     def icon_clicked(self, widget, data=None):
         """
         Executed on left clicking the statusicon
 
     def double_click_start(self, path, column, data=None):
         self.player.set_state(gst.STATE_NULL)
-        self.playing = column[0]
         self.play_button.set_stock_id(gtk.STOCK_MEDIA_STOP)
         song = self.playitems[column[0]]
         self.set_songinfos(song)
         t = t_play(self, song, int(CONFIG['repeat_playlist']))
         t.start()
 
+    def add_and_play_result(self, path, column, data=None):
+        song = self.results[column[0]]
+        self.playitems.append(song)
+        self.playlist.append([song['SongName'],
+                            song['ArtistName'],
+                            song['SongID']])
+        if self.playing == None:
+            self.playing = len(self.playitems) - 2
+        self.play_next(self.ff_button)
+
+
     def play_next(self, widget, data=None):
         """
         Plays the next item from the playlist
         builder.add_from_file('%s/data/about_dialog.ui' % BASEPATH)
         flattr = builder.get_object('flattrbut')
         flattr.connect("clicked", self.flattr_this)
+        updbtn = builder.get_object('updatbut')
+        updbtn.connect("clicked", self.check_for_update)
         about = builder.get_object('aboutdialog1')
         about.run()
         about.destroy()
         """
         builder = gtk.Builder()
         builder.add_from_file('%s/data/preferenes_dialog.ui' % BASEPATH)
-        prefs = builder.get_object('window1')
+        self.prefs = builder.get_object('window1')
         self.dest = builder.get_object('entry1')
         if CONFIG['down_path'] == "":
             self.dest.set_text(os.environ.get('HOME')+"/Music")
         self.bubble = builder.get_object("checkbutton2")
         self.bubble.set_active(int(CONFIG['show_notification']))
         builder.connect_signals(self)
-        prefs.show_all()
+        self.prefs.show_all()
 
     def select_destination(self, widget, data=None):
         """
         else:
             CONFIG['show_notification'] = 0
         CONFIG.write()
-        win = widget.get_window()
-        win.destroy()
+        self.prefs.destroy()
 
     def close_preferences(self, widget, data=None):
         """
         Closes the Preferences dialog discarding any changes
         """
-        win = widget.get_window()
-        win.destroy()
+        self.prefs.destroy()
 
     def search_grooveshark(self, widget, data=None):
         """
                   "Cookie": "PHPSESSID=" + h["session"]})
     resp = conn.getresponse().read()
     gzipfile = gzip.GzipFile(fileobj=(StringIO.StringIO(resp)))
-    return json.JSONDecoder().decode(gzipfile.read())["result"]["result"]
+    j = json.JSONDecoder().decode(gzipfile.read())
+    try:
+        return j['result']['result']['Songs']
+    except:
+        return j['result']['result']
 
 
 def getStreamKeyFromSongIDEx(id):