Logo Search packages:      
Sourcecode: viridian version File versions  Download package

def AmpacheTools::AmpacheGUI::AmpacheGUI::button_load_or_save_playlist_clicked (   self,
  widget,
  selection,
  text,
  type 
)
When the user wants to load or save a playlist from Ampache.

Definition at line 2408 of file AmpacheGUI.py.

                                                                                   :
            """When the user wants to load or save a playlist from Ampache."""
            playlist_list_store, iter = selection.get_selected()
            text = text.get_text()
            if iter == None:
                  playlist_id   = -1
                  playlist_name = ''
            else:
                  playlist_id   = playlist_list_store[iter][4]
                  playlist_name = playlist_list_store[iter][0]
            list = []
            if type == 'Load': # Load playlist
                  if iter == None: # nothing selected
                        return True
                  if playlist_id == -1: # text place holders
                        return True
                  if playlist_id == -2: # Local Playlists
                        list = dbfunctions.get_playlist(self.db_session, playlist_name)
                  else:
                        playlist = self.ampache_conn.get_playlist_songs(playlist_id)
                        if not playlist:
                              print "Error with playlist %d" % playlist_id
                              self.create_dialog_alert("error", _("Problem loading playlist.  Playlist ID = %d" % playlist_id), True)
                              return True
                        for song in playlist:
                              list.append(song['song_id'])
                  self.load_playlist(list)
                  self.destroy_playlist()
            elif type == 'Save': # Save playlist
                  if not self.audio_engine.get_playlist(): # playlist is empty
                        self.create_dialog_alert("error", _("Cannot save empty playlist."), True)
                        print _("Cannot save empty playlist.")
                        return False
                  if text == '': # no name for list was specified
                        self.create_dialog_alert("error", _("Invalid Name."), True)
                        return False
                  if dbfunctions.get_playlist(self.db_session, text): # playlist exists
                        answer = self.create_dialog_ok_or_close(_("Overwrite Playlist?"), _("A playlist by the name '%s' already exists, overwrite?" % text))
                        if answer != "ok":
                              return False
                  dbfunctions.set_playlist(self.db_session, text, self.audio_engine.get_playlist())
                  self.destroy_playlist()
            elif type == 'Export': # Export Playlist
                  if iter == None: # nothing selected
                        return True
                  if playlist_id == -1: # placeholders
                        return True
                  if playlist_id != -2: # not local playlists
                        self.create_dialog_alert("error", _("Only exporting of local playlists is supported."), True)
                        return False
                  else: # ready to export
                        list = dbfunctions.get_playlist(self.db_session, playlist_name)
                        if not list:
                              self.create_dialog_alert("error", _("Cannot export empty playlist."), True)
                              return False
                        chooser = gtk.FileChooserDialog(title="Save as...",action=gtk.FILE_CHOOSER_ACTION_SAVE,
                              buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
                        chooser.set_current_folder(os.path.expanduser("~"))
                        response = chooser.run()
                        if response == gtk.RESPONSE_OK:
                              filename = chooser.get_filename()
                              if os.path.isfile(filename):
                                    self.create_dialog_alert("error", _("File already exists."), True)
                                    chooser.destroy()
                                    return False
                                    
                              f = open(filename, 'w')
                              f.write("Playlist '%s' export from Viridian - %s\n\n" % (playlist_name, time.strftime("%A, %B %d, %Y at %I:%M%p")))
                              for song_id in list:
                                    f.write(helperfunctions.convert_html_to_string(self.ampache_conn.get_song_url(song_id).rpartition('.')[0]))
                                    f.write("\n")
                              f.close()
                              print "Exported playlist to %s" % (filename)
                              self.create_dialog_alert("info", _("Playlist %s written to %s." % (playlist_name, filename)), True)
                        
                        chooser.destroy()
                  self.destroy_playlist()
                              
                  

Generated by  Doxygen 1.6.0   Back to index