def __save(self, *data): """Save the cover and spawn the program to edit it if selected""" filename = self.name_combo.get_active_text() # Allow support for filename patterns pattern = Pattern(filename) filename = fsencode(pattern.format(self.song)) file_path = os.path.join(self.dirname, filename) msg = (_('The file <b>%s</b> already exists.\n\nOverwrite?') % util.escape(filename)) if (os.path.exists(file_path) and not qltk.ConfirmAction(None, _('File exists'), msg).run()): return try: f = open(file_path, 'wb') f.write(self.current_data) f.close() except IOError: qltk.ErrorMessage(None, _('Saving failed'), _('Unable to save "%s".') % file_path).run() else: if self.open_check.get_active(): try: util.spawn([self.cmd.get_text(), file_path]) except: pass app.window.emit("artwork-changed", [self.song]) self.main_win.destroy()
def __save_files(self, parent, model, library): win = WritingWindow(parent, len(model)) was_changed = set() for song, track in [(r[0], r[2]) for r in model]: if song.get("tracknumber") == track: win.step() continue if not song.valid() and not qltk.ConfirmAction( win, _("Tag may not be accurate"), _("<b>%s</b> changed while the program was running. " "Saving without refreshing your library may " "overwrite other changes to the song.\n\n" "Save this song anyway?") % util.escape(fsdecode(song("~basename")))).run(): break song["tracknumber"] = track try: song.write() except: util.print_exc() qltk.ErrorMessage( win, _("Unable to save song"), _("Saving <b>%s</b> failed. The file may be " "read-only, corrupted, or you do not have " "permission to edit it.") % util.escape(fsdecode(song('~basename')))).run() library.reload(song, changed=was_changed) break was_changed.add(song) if win.step(): break library.changed(was_changed) win.destroy()
def __save(self, *data): """Save the cover and spawn the program to edit it if selected""" save_format = self.name_combo.get_active_text() # Allow use of patterns in creating cover filenames pattern = ArbitraryExtensionFileFromPattern( save_format.decode("utf-8")) filename = pattern.format(self.song) print_d("Using '%s' as filename based on %s" % (filename, save_format)) file_path = os.path.join(self.dirname, filename) msg = (_('The file <b>%s</b> already exists.\n\nOverwrite?') % util.escape(filename)) if (os.path.exists(file_path) and not qltk.ConfirmAction(None, _('File exists'), msg).run()): return try: f = open(file_path, 'wb') f.write(self.current_data) f.close() except IOError: qltk.ErrorMessage(None, _('Saving failed'), _('Unable to save "%s".') % file_path).run() else: if self.open_check.get_active(): try: util.spawn([self.cmd.get_text(), file_path]) except: pass app.window.emit("artwork-changed", [self.song]) self.main_win.destroy()
def __save(self, addreplace, library): pattern_text = self.combo.get_child().get_text().decode('utf-8') pattern = TagsFromPattern(pattern_text) model = self.view.get_model() add = bool(addreplace.get_active()) win = WritingWindow(self, len(model)) win.show() was_changed = set() for row in (model or []): song = row[0] changed = False if not song.valid() and not qltk.ConfirmAction( self, _("Tag may not be accurate"), _("<b>%s</b> changed while the program was running. " "Saving without refreshing your library may " "overwrite other changes to the song.\n\n" "Save this song anyway?") % ( util.escape(fsdecode(song("~basename")))) ).run(): break for i, h in enumerate(pattern.headers): if row[i + 2]: text = row[i + 2].decode("utf-8") if not add or h not in song or not song.multiple_values: song[h] = text changed = True else: for val in text.split("\n"): if val not in song.list(h): song.add(h, val) changed = True if changed: try: song.write() except: qltk.ErrorMessage( self, _("Unable to edit song"), _("Saving <b>%s</b> failed. The file " "may be read-only, corrupted, or you " "do not have permission to edit it.") % ( util.escape(fsdecode(song('~basename')))) ).run() library.reload(song, changed=was_changed) break was_changed.add(song) if win.step(): break win.destroy() library.changed(was_changed) self.save.set_sensitive(False)
def __configure_scan_dirs(self, library): """Get user to configure scan dirs, if none is set up""" if not get_scan_dirs() and not len(library) and \ quodlibet.is_first_session("quodlibet"): print_d("Couldn't find any scan dirs") if qltk.ConfirmAction(self, _("Set up library directories?"), _("You don't have any music library set up. " "Would you like to do that now?")).run(): prefs = PreferencesWindow(self) prefs.set_page("library") prefs.show()
def __load_db(self): if self.__itdb: return self.__itdb self.__itdb = gpod.itdb_parse(self.mountpoint, None) if not self.__itdb and self.is_connected() and qltk.ConfirmAction( None, _("Uninitialized iPod"), _("Do you want to create an empty database on this iPod?") ).run(): self.__itdb = self.__create_db() return self.__itdb
def on_sub_clicked(self, *data): if (self.cover == None): qltk.ErrorMessage(None, _('Error'), _("No image selected")).run() return esc = escape_data txt = _('Remove {!s}').format(esc(self.cover.desc)) txt += _('\nType: {!s}').format(TYPE[self.cover.type]) txt += _('\nResolution: {!s} x {!s}').format(self.cover.width, self.cover.height) print(txt) if not qltk.ConfirmAction(self.main_win, _('Remove Image'), txt).run(): return True for row in self.main_win.liststore: cover = row[1] if cover == self.cover: self.main_win.liststore.remove(row.iter) break self.save_button.set_sensitive(True)
def on_delete(self, widget, event): file_changed = False i = 0 if len(self.liststore) <> len(self.coverlist): file_changed = True for row in self.liststore: cover = row[1] if (self.coverlist[i].data != cover.data) \ or (self.coverlist[i].desc != cover.desc) \ or (self.coverlist[i].type != cover.type) : file_changed = True i += 1 if file_changed == True and qltk.ConfirmAction( None, _('Images changed'), _('The images in file <b>%s</b> were changed.' '\n\nOverwrite?') % util.escape(self.song.get("~filename", ""))).run(): self.on_save() return
def __save_files(self, save, revert, model, library): updated = {} deleted = {} added = {} renamed = {} for row in model: if row[EDITED] and not (row[DELETED] or row[RENAMED]): if row[ORIGVALUE] is not None: updated.setdefault(row[TAG], []) updated[row[TAG]].append( (decode(row[VALUE]), decode(row[ORIGVALUE]))) else: added.setdefault(row[TAG], []) added[row[TAG]].append(decode(row[VALUE])) if row[EDITED] and row[DELETED]: if row[ORIGVALUE] is not None: deleted.setdefault(row[TAG], []) deleted[row[TAG]].append(decode(row[ORIGVALUE])) if row[EDITED] and row[RENAMED] and not row[DELETED]: renamed.setdefault(row[TAG], []) renamed[row[TAG]].append( (decode(row[ORIGTAG]), decode(row[VALUE]), decode(row[ORIGVALUE]))) was_changed = set() songs = self.__songinfo.songs win = WritingWindow(self, len(songs)) win.show() for song in songs: if not song.valid() and not qltk.ConfirmAction( self, _("Tag may not be accurate"), _("<b>%s</b> changed while the program was running. " "Saving without refreshing your library may " "overwrite other changes to the song.\n\n" "Save this song anyway?") % util.escape(util.fsdecode(song("~basename")))).run(): break changed = False for key, values in updated.iteritems(): for (new_value, old_value) in values: new_value = util.unescape(new_value) if song.can_change(key): if old_value is None: song.add(key, new_value) else: song.change(key, old_value, new_value) changed = True for key, values in added.iteritems(): for value in values: value = util.unescape(value) if song.can_change(key): song.add(key, value) changed = True for key, values in deleted.iteritems(): for value in values: value = util.unescape(value) if song.can_change(key) and key in song: song.remove(key, value) changed = True save_rename = [] for new_tag, values in renamed.iteritems(): for old_tag, new_value, old_value in values: old_tag = util.unescape(old_tag) old_value = util.unescape(old_value) new_value = util.unescape(new_value) if (song.can_change(new_tag) and song.can_change(old_tag) and old_tag in song): if not is_special(new_value): song.remove(old_tag, old_value) save_rename.append((new_tag, new_value)) elif is_missing(new_value): value = strip_missing(old_value) song.remove(old_tag, old_value) save_rename.append((new_tag, new_value)) else: save_rename.append((new_tag, song[old_tag])) song.remove(old_tag, None) changed = True for tag, value in save_rename: song.add(tag, value) if changed: try: song.write() except: util.print_exc() qltk.ErrorMessage( self, _("Unable to save song"), _("Saving <b>%s</b> failed. The file " "may be read-only, corrupted, or you " "do not have permission to edit it.") % (util.escape(fsdecode(song('~basename'))))).run() library.reload(song, changed=was_changed) break was_changed.add(song) if win.step(): break win.destroy() library.changed(was_changed) for b in [save, revert]: b.set_sensitive(False)
def __save_playlist(self, songs, name=None): dialog = Gtk.FileChooserDialog( self.PLUGIN_NAME, None, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK)) dialog.set_default_response(Gtk.ResponseType.OK) if name: dialog.set_current_name(name) ffilter = Gtk.FileFilter() ffilter.set_name("m3u") ffilter.add_mime_type("audio/x-mpegurl") ffilter.add_pattern("*.m3u") dialog.add_filter(ffilter) ffilter = Gtk.FileFilter() ffilter.set_name("pls") ffilter.add_mime_type("audio/x-scpls") ffilter.add_pattern("*.pls") dialog.add_filter(ffilter) dialog.set_current_folder(lastfolder) diag_cont = dialog.get_child() hbox_path = Gtk.HBox() combo_path = Gtk.ComboBoxText() hbox_path.pack_end(combo_path, False, False, 6) diag_cont.pack_start(hbox_path, False, False, 0) diag_cont.show_all() for option_text in [_("Use relative paths"), _("Use absolute paths")]: combo_path.append_text(option_text) combo_path.set_active(0) response = dialog.run() if response == Gtk.ResponseType.OK: file_path = dialog.get_filename() dir_path = os.path.dirname(file_path) file_format = dialog.get_filter().get_name() extension = "." + file_format if not file_path.endswith(extension): file_path += extension if os.path.exists(file_path) and not qltk.ConfirmAction( None, _('File exists'), _('The file <b>%s</b> already exists.\n\nOverwrite?') % util.escape(file_path)).run(): dialog.destroy() return relative = combo_path.get_active() == 0 files = self.__get_files(songs, dir_path, relative) if file_format == "m3u": self.__m3u_export(file_path, files) elif file_format == "pls": self.__pls_export(file_path, files) self.lastfolder = dir_path dialog.destroy()