def on_add_button_clicked(self, widget): """ Adds a path to the list """ dialog = Gtk.FileChooserDialog( _("Add a Directory"), self.parent, Gtk.FileChooserAction.SELECT_FOLDER, ( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_ADD, Gtk.ResponseType.OK, ), ) dialog.set_current_folder(xdg.get_last_dir()) dialog.set_local_only(False) # enable gio response = dialog.run() # XXX: For some reason, on Ubuntu 12.10 (GTK 2.24.13), hiding the # dialog before retrieving the results causes an incorrect URI # to be retrieved. uri = dialog.get_uri() dialog.hide() if response == Gtk.ResponseType.OK: location = Gio.File.new_for_uri(uri) removals = [] for row in self.model: library_location = Gio.File.new_for_uri(row[0]) # monitored = row[1] # scan_on_startup = row[2] if location.has_prefix(library_location): self.message.show_warning( _('Directory not added.'), _( 'The directory is already in your collection ' 'or is a subdirectory of another directory in ' 'your collection.' ), ) break elif library_location.has_prefix(location): removals += [row.iter] else: self.model.append([location.get_uri(), False, False]) for iter in removals: self.model.remove(iter) dialog.destroy()
def on_add_button_clicked(self, widget): """ Adds a path to the list """ dialog = Gtk.FileChooserDialog( _("Add a Directory"), self.parent, Gtk.FileChooserAction.SELECT_FOLDER, ( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_ADD, Gtk.ResponseType.OK, ), ) dialog.set_current_folder(xdg.get_last_dir()) dialog.set_local_only(False) # enable gio response = dialog.run() # XXX: For some reason, on Ubuntu 12.10 (GTK 2.24.13), hiding the # dialog before retrieving the results causes an incorrect URI # to be retrieved. uri = dialog.get_uri() dialog.hide() if response == Gtk.ResponseType.OK: location = Gio.File.new_for_uri(uri) removals = [] for row in self.model: library_location = Gio.File.new_for_uri(row[0]) # monitored = row[1] # scan_on_startup = row[2] if location.equal(library_location) or location.has_prefix( library_location): self.message.show_warning( _('Directory not added.'), _('The directory is already in your collection ' 'or is a subdirectory of another directory in ' 'your collection.'), ) break elif library_location.has_prefix(location): removals += [row.iter] else: self.model.append([location.get_uri(), False, False]) for iter in removals: self.model.remove(iter) dialog.destroy()
def save_selected(self, widget=None, event=None): """ Save the selected tracks to disk. """ items = self.get_selected_items() dialog = Gtk.FileChooserDialog( _("Select a Location for Saving"), main.mainwindow().window, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_OPEN, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) dialog.set_current_folder(xdg.get_last_dir()) dialog.set_select_multiple(False) result = dialog.run() dialog.hide() if result == Gtk.ResponseType.OK: folder = dialog.get_current_folder() self.save_items(items, folder)
def save_selected(self, widget=None, event=None): """ Save the selected tracks to disk. """ items = self.get_selected_items() dialog = Gtk.FileChooserDialog( _("Select a Location for Saving"), main.mainwindow().window, Gtk.FileChooserAction.SELECT_FOLDER, ( Gtk.STOCK_OPEN, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, ), ) dialog.set_current_folder(xdg.get_last_dir()) dialog.set_select_multiple(False) result = dialog.run() dialog.hide() if result == Gtk.ResponseType.OK: folder = dialog.get_current_folder() self.save_items(items, folder)