1. Vladimir Kolev
  2. gSharkDown

Commits

Damián Nohales  committed 219fd24

Use GtkFileChooserButton to select download directory.

  • Participants
  • Parent commits 3501686
  • Branches default

Comments (0)

Files changed (2)

File data/preferenes_dialog.ui

View file
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="2.18"/>
+  <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
+  <object class="GtkFileChooserDialog" id="filechooserdialog1">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
   <object class="GtkWindow" id="window1">
+    <property name="can_focus">False</property>
     <property name="title" translatable="yes">Preferences</property>
     <property name="type_hint">dialog</property>
     <child>
       <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="spacing">2</property>
         <child>
           <object class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <child>
               <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">Download Directory:</property>
               </object>
               <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="padding">5</property>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="entry1">
+              <object class="GtkFileChooserButton" id="filechooserbutton1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="invisible_char">&#x2022;</property>
-                <property name="primary_icon_sensitive">True</property>
-                <property name="secondary_icon_sensitive">True</property>
+                <property name="can_focus">False</property>
+                <property name="action">select-folder</property>
+                <property name="preview_widget_active">False</property>
+                <property name="title" translatable="yes">Select the download directory</property>
               </object>
               <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="padding">5</property>
                 <property name="position">1</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButton" id="button1">
-                <property name="label">gtk-open</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="select_destination"/>
-              </object>
-              <packing>
-                <property name="padding">9</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="padding">14</property>
             <property name="position">0</property>
           </packing>
         <child>
           <object class="GtkHBox" id="hbox2">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <child>
               <object class="GtkCheckButton" id="checkbutton1">
                 <property name="label" translatable="yes">Quit application on close without confirmation</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
                 <property name="draw_indicator">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
+                <property name="fill">True</property>
                 <property name="padding">15</property>
                 <property name="position">0</property>
               </packing>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="padding">6</property>
             <property name="position">1</property>
           </packing>
         <child>
           <object class="GtkHBox" id="hbox3">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <child>
               <object class="GtkCheckButton" id="checkbutton2">
                 <property name="label" translatable="yes">Show notifications on track change</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
                 <property name="draw_indicator">True</property>
               </object>
               <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
                 <property name="padding">15</property>
                 <property name="position">0</property>
               </packing>
         <child>
           <object class="GtkFrame" id="frame1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="label_xalign">0</property>
             <property name="shadow_type">none</property>
             <child>
               <object class="GtkAlignment" id="alignment1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="left_padding">12</property>
                 <child>
                   <object class="GtkVBox" id="vbox2">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <child>
                       <object class="GtkHBox" id="hbox4">
                         <property name="visible">True</property>
+                        <property name="can_focus">False</property>
                         <child>
                           <object class="GtkLabel" id="label3">
                             <property name="visible">True</property>
+                            <property name="can_focus">False</property>
                             <property name="label" translatable="yes">Username:</property>
                           </object>
                           <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
                             <property name="position">0</property>
                           </packing>
                         </child>
                           <object class="GtkEntry" id="entry2">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
-                            <property name="invisible_char">&#x2022;</property>
+                            <property name="invisible_char"></property>
                             <property name="primary_icon_name">face-monkey</property>
+                            <property name="primary_icon_activatable">False</property>
+                            <property name="secondary_icon_activatable">False</property>
+                            <property name="primary_icon_sensitive">True</property>
+                            <property name="secondary_icon_sensitive">True</property>
                           </object>
                           <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
                             <property name="position">1</property>
                           </packing>
                         </child>
                       </object>
                       <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
                     <child>
                       <object class="GtkHBox" id="hbox5">
                         <property name="visible">True</property>
+                        <property name="can_focus">False</property>
                         <child>
                           <object class="GtkLabel" id="label4">
                             <property name="visible">True</property>
+                            <property name="can_focus">False</property>
                             <property name="label" translatable="yes">Password:  </property>
                           </object>
                           <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
                             <property name="position">0</property>
                           </packing>
                         </child>
                             <property name="can_focus">True</property>
                             <property name="invisible_char_set">True</property>
                             <property name="primary_icon_name">dialog-password</property>
+                            <property name="primary_icon_activatable">False</property>
+                            <property name="secondary_icon_activatable">False</property>
+                            <property name="primary_icon_sensitive">True</property>
+                            <property name="secondary_icon_sensitive">True</property>
                           </object>
                           <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
                             <property name="position">1</property>
                           </packing>
                         </child>
                       </object>
                       <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
                         <property name="position">1</property>
                       </packing>
                     </child>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
+                        <property name="use_action_appearance">False</property>
                         <property name="draw_indicator">True</property>
-                        <signal name="toggled" handler="on_scrobble_toggle"/>
+                        <signal name="toggled" handler="on_scrobble_toggle" swapped="no"/>
                       </object>
                       <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
                         <property name="position">2</property>
                       </packing>
                     </child>
             <child type="label">
               <object class="GtkLabel" id="label2">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">&lt;b&gt;Last.fm Scrobbling&lt;/b&gt;</property>
                 <property name="use_markup">True</property>
               </object>
             </child>
           </object>
           <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
             <property name="position">3</property>
           </packing>
         </child>
         <child>
           <object class="GtkHSeparator" id="hseparator1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="position">4</property>
           </packing>
         </child>
         <child>
           <object class="GtkHButtonBox" id="hbuttonbox1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="spacing">12</property>
             <property name="layout_style">end</property>
             <child>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
-                <signal name="clicked" handler="close_preferences"/>
+                <signal name="clicked" handler="close_preferences" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
-                <signal name="clicked" handler="save_preferences"/>
+                <signal name="clicked" handler="save_preferences" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">False</property>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="padding">5</property>
             <property name="position">5</property>
           </packing>

File gsharkdown.py

View file
 
         if int(CONFIG['show_notification']) == 1 and HAVE_NOTIFY:
             pynotify.init("gSharkDown")
+            
+        # Set default directory if is empty
+        if CONFIG['down_path'] == "":
+            CONFIG['down_path'] = os.path.join(glib.get_user_special_dir(glib.USER_DIRECTORY_MUSIC), "Grooveshark")
         
         # Scrobbling initialisation
         self.lastfm = ""
         builder.set_translation_domain(APP)
         builder.add_from_file('%s/data/preferenes_dialog.ui' % BASEPATH)
         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")
-        else:
-            self.dest.set_text(CONFIG['down_path'])
+        self.dest = builder.get_object('filechooserbutton1')
+        self.dest.set_filename(CONFIG['down_path'])
         self.quit_without_confirmation = builder.get_object("checkbutton1")
         self.quit_without_confirmation.set_active(int(CONFIG['quit_without_confirmation']))
         self.bubble = builder.get_object("checkbutton2")
         builder.connect_signals(self)
         self.prefs.show_all()
 
-    def select_destination(self, widget, data=None):
-        """
-        Handler for the Select button from the Preferences dialog
-        """
-        chooser = gtk.FileChooserDialog(_("Select destination directory"),
-                                       None,
-                                        gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
-                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
-                                       gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
-        response = chooser.run()
-        if response == gtk.RESPONSE_ACCEPT:
-            self.dest.set_text(chooser.get_filename())
-        else:
-            chooser.destroy()
-        chooser.destroy()
-
     def on_scrobble_toggle(self, widget, data=None):
         self.lastuser.set_sensitive(widget.get_active())
         self.lastpass.set_sensitive(widget.get_active())
         Saves the information from the Preferences dialog in the
         configuration file
         """
-        CONFIG['down_path'] = self.dest.get_text()
+        CONFIG['down_path'] = self.dest.get_filename()
         if self.quit_without_confirmation.get_active():
             CONFIG['quit_without_confirmation'] = '1'
         else:
 
             filename = "%s - %s.mp3" % (song["ArtistName"].strip("<>:\"/\|?*"),
                                     song["SongName"].strip("<>:\"/\|?*"))
-           
-            if CONFIG['down_path'] == "":
-                CONFIG['down_path'] = os.path.join(glib.get_user_special_dir(glib.USER_DIRECTORY_MUSIC), "Grooveshark")
             
             try:
                 tDownload = t_download(self, song, os.path.join(CONFIG['down_path'], filename))