Commits

Vladimir Kolev committed e4c05be

Fixed the problem with last.fm it was a typo... damn it
Added button Love Song for Last.fm

Comments (0)

Files changed (3)

data/main_window.ui

               </packing>
             </child>
             <child>
+              <object class="GtkToolButton" id="toolbutton3">
+                <property name="sensitive">False</property>
+                <property name="tooltip_text" translatable="yes">Love song on Last.fm</property>
+                <property name="label" translatable="yes">Love Song</property>
+                <property name="use_underline">True</property>
+                <property name="icon_widget">image5</property>
+                <signal name="clicked" handler="on_love_song"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkToolItem" id="aligment">
                 <property name="visible">True</property>
                 <child>
     <property name="visible">True</property>
     <property name="stock">gtk-add</property>
   </object>
+  <object class="GtkImage" id="image5">
+    <property name="visible">True</property>
+    <property name="pixbuf">love_song.svg</property>
+  </object>
 </interface>
     CONFIG = ConfigObj("%s/.gsharkdown/gsharkdown.ini" % os.environ.get("HOME"))
     try:
         if HAVE_PYLAST:
-            test = CONFIG['scribbling']
+            test = CONFIG['scrobbling']
         else:
             raise KeyError()
     except KeyError:
         self.songinfo = builder.get_object('songinfo')
         self.songinfo.set_text("")
         self.prefsmenu = builder.get_object('mainmenu')
+        self.lovebutton = builder.get_object('toolbutton3')
         repeat_button = builder.get_object('togglebutton_repeat')
         repeat_button.set_active(int(CONFIG['repeat_playlist']))
         shuffle_button = builder.get_object('togglebutton_shuffle')
         # Scrobbling initialisation
         self.lastfm = ""
         if int(CONFIG['scrobbling']) == 1 and HAVE_PYLAST:
-            self.lastfm = pylast.LastFMNetwork(api_key = LAST_KEY,
+            try:
+                self.lastfm = pylast.LastFMNetwork(api_key = LAST_KEY,
                                           api_secret = LAST_SECRET,
                                           username = CONFIG['lastuser'],
                                           password_hash = CONFIG['lastpass'])
+                self.lovebutton.set_sensitive(True)
+            except pylast.WSError:
+                error = lib.guihelpers.ErrorMessage(self.window,
+                            _("Check your password and username for Last.fm"))
+                error.show_all()
+                pass
 
         builder.connect_signals(self)
         self.tlisten = KeyListenerThread(self)
             CONFIG['scrobbling'] = 1
             CONFIG['lastuser'] = self.lastuser.get_text()
             CONFIG['lastpass'] = pylast.md5(self.lastpass.get_text())
+        else:
+            CONFIG['scrobbling'] = 0
+            self.lovebutton.set_sensitive(False)
+        CONFIG.write()
+        try:
             self.lastfm = pylast.LastFMNetwork(api_key = LAST_KEY,
                                           api_secret = LAST_SECRET,
                                           username = CONFIG['lastuser'],
                                           password_hash = CONFIG['lastpass'])
-
-        else:
+            self.lovebutton.set_sensitive(True)
+        except pylast.WSError:
+            lib.guihelpers.ErrorMessage(self.window,
+                    _("Please check your username and password for Last.fm"))
+            CONFIG['lastuser'] = ""
+            CONFIG['lastpass'] = ""
             CONFIG['scrobbling'] = 0
-        CONFIG.write()
+            CONFIG.write()
         self.prefs.destroy()
 
     def close_preferences(self, widget, data = None):
         """
         pass
 
+    def on_love_song(self, button):
+        if self.current_song == None:
+            info = lib.guihelpers.InfoDialog(self.window,
+                    _("There is no song to be loved.\n A song should be playing"))
+            info.show_all()
+        else:
+            track = self.lastfm.get_track(self.current_song['ArtistName'],
+                                          self.current_song['SongName'])
+            track.love()
+
     def get_sliced_string(self, str, max):
         sliced = str[0:max - 3]
         if len(sliced) < len(str):

lib/guihelpers.py

         """
         self.destroy()
 
+class InfoDialog(gtk.MessageDialog):
+    """
+    Informations dialog helper. Displays Information messages
+    with given text.
+    """
+
+    def __init__(self, parent, message):
+        """
+        InfoDialog accepts the following parameters
+        @param parent : The parent window of the Infor dialog
+        @param message : The message to be shown
+        """
+        gtk.MessageDialog.__init__(self, parent,
+                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+                            gtk.MESSAGE_INFO, gtk.BUTTONS_OK, message)
+        self.set_default_response(gtk.RESPONSE_OK)
+        self.connect('response', self.handle_clicked)
+
+    def handle_clicked(self, *args):
+        """
+        Handler of the default dialog response
+        """
+        self.destroy()
 
 class UpdateDialog(gtk.MessageDialog):
     """