1. Vladimir Kolev
  2. gSharkDown

Commits

Vladimir Kolev  committed dd774a9

Added functionality to the save and open playlist buttons
Removed debugging info when playling songs

  • Participants
  • Parent commits 7320e93
  • Branches default

Comments (0)

Files changed (3)

File data/main_window.ui

View file
                                     <property name="tooltip_text" translatable="yes">Save playlist to file</property>
                                     <property name="use_action_appearance">False</property>
                                     <property name="image">image9</property>
+                                    <signal name="clicked" handler="save_as_playlist" swapped="no"/>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
                                     <property name="tooltip_text" translatable="yes">Open saved playlist</property>
                                     <property name="use_action_appearance">False</property>
                                     <property name="image">image10</property>
+                                    <signal name="clicked" handler="open_saved_playlist" swapped="no"/>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>

File gsharkdown.py

View file
                 self.playitems[i]['ArtistName'],
                 self.playitems[i]['SongID']
                 ])
+    def save_playlist(self, path):
+        try:
+            output = open(path, 'w')
+            for i in range(0, len(self.playitems)):
+                pickle.dump(self.playitems[i], output)
+            output.close()
+        except:
+            print "Error saving the playlist"
+
+
+    def save_as_playlist(self, widget, data=None):
+        savedlg = gtk.FileChooserDialog("Save playlist to file",
+                                       None,
+                                       gtk.FILE_CHOOSER_ACTION_SAVE,
+                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
+                                       gtk.STOCK_SAVE, gtk.RESPONSE_OK))
+        response = savedlg.run()
+
+        if response == gtk.RESPONSE_OK:
+            filename = savedlg.get_filename()
+            if filename[-4:] != ".pkl":
+                filename += ".pkl"
+            self.save_playlist(filename)
+        savedlg.destroy()
+
+    def open_saved_playlist(self, widget, data=None):
+        opendlg = gtk.FileChooserDialog("Select Playlist to open",
+                                       None,
+                                       gtk.FILE_CHOOSER_ACTION_OPEN,
+                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
+                                       gtk.STOCK_OPEN, gtk.RESPONSE_OK))
+        openfilter = gtk.FileFilter()
+        openfilter.set_name('Playlist files')
+        openfilter.add_pattern("*.pkl")
+
+        opendlg.add_filter(openfilter)
+
+        response = opendlg.run()
+
+        if response == gtk.RESPONSE_OK:
+            self.playlist.clear()
+            self.playitems = []
+            self.playing = None
+            self.load_saved_playlist(opendlg.get_filename())
+        opendlg.destroy()
 
     def window_close(self, widget, data=None):
         """
         dialog.set_title("Quit?")
         response = dialog.run()
         if response == gtk.RESPONSE_YES:
-            try:
-                output = open("%s/.gsharkdown/playlist.pkl" % os.environ.get("HOME"),
-                              'w')
-                for i in range(0, len(self.playitems)):
-                    pickle.dump(self.playitems[i], output)
-                output.close()
-            except:
-                print "Error saving the playlist"
+            self.save_playlist("%s/.gsharkdown/playlist.pkl" % os.environ.get("HOME"))
             gtk.main_quit()
         dialog.destroy()
 

File lib/groove.py

View file
     resp = conn.getresponse().read()
     gzipfile = gzip.GzipFile(fileobj=(StringIO.StringIO(resp)))
     j = json.JSONDecoder().decode(gzipfile.read())
-    print j
     return j