mirror of
https://github.com/fergalmoran/picard.git
synced 2026-01-05 16:13:59 +00:00
new renaming setting
This commit is contained in:
@@ -280,7 +280,8 @@ class File(QtCore.QObject, Item):
|
||||
new_filename = self._script_to_filename(format, metadata, settings)
|
||||
if not settings['move_files']:
|
||||
new_filename = os.path.basename(new_filename)
|
||||
new_filename = make_short_filename(new_dirname, new_filename, settings['windows_compatibility'])
|
||||
new_filename = make_short_filename(new_dirname, new_filename,
|
||||
settings['windows_compatibility'], settings['move_files_ancestor'])
|
||||
# win32 compatibility fixes
|
||||
if settings['windows_compatibility'] or sys.platform == 'win32':
|
||||
new_filename = new_filename.replace('./', '_/').replace('.\\', '_\\')
|
||||
|
||||
@@ -43,6 +43,7 @@ class RenamingOptionsPage(OptionsPage):
|
||||
TextOption("setting", "file_naming_format", "$if2(%albumartist%,%artist%)/%album%/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2)$if(%compilation%, %artist% -,) %title%"),
|
||||
BoolOption("setting", "move_files", False),
|
||||
TextOption("setting", "move_files_to", ""),
|
||||
TextOption("setting", "move_files_ancestor", ""),
|
||||
BoolOption("setting", "move_additional_files", False),
|
||||
TextOption("setting", "move_additional_files_pattern", "*.jpg *.png"),
|
||||
BoolOption("setting", "delete_empty_dirs", True),
|
||||
@@ -58,6 +59,7 @@ class RenamingOptionsPage(OptionsPage):
|
||||
self.ui.rename_files.clicked.connect(self.update_examples)
|
||||
self.ui.move_files.clicked.connect(self.update_examples)
|
||||
self.ui.move_files_to.editingFinished.connect(self.update_examples)
|
||||
self.ui.move_files_ancestor.editingFinished.connect(self.update_examples)
|
||||
|
||||
self.ui.rename_files.stateChanged.connect(self.ui.ascii_filenames.setEnabled)
|
||||
self.ui.rename_files.stateChanged.connect(self.ui.file_naming_format.setEnabled)
|
||||
@@ -65,6 +67,9 @@ class RenamingOptionsPage(OptionsPage):
|
||||
|
||||
if not sys.platform == "win32":
|
||||
self.ui.rename_files.stateChanged.connect(self.ui.windows_compatibility.setEnabled)
|
||||
self.ui.rename_files.stateChanged.connect(self.toggle_move_files_ancestor_enabled)
|
||||
self.ui.windows_compatibility.stateChanged.connect(self.toggle_move_files_ancestor_enabled)
|
||||
self.ui.move_files.stateChanged.connect(self.toggle_move_files_ancestor_enabled)
|
||||
|
||||
self.ui.move_files.stateChanged.connect(self.ui.delete_empty_dirs.setEnabled)
|
||||
self.ui.move_files.stateChanged.connect(self.ui.move_files_to.setEnabled)
|
||||
@@ -75,6 +80,16 @@ class RenamingOptionsPage(OptionsPage):
|
||||
self.ui.file_naming_format_default.clicked.connect(self.set_file_naming_format_default)
|
||||
self.highlighter = TaggerScriptSyntaxHighlighter(self.ui.file_naming_format.document())
|
||||
self.ui.move_files_to_browse.clicked.connect(self.move_files_to_browse)
|
||||
self.ui.move_files_ancestor_browse.clicked.connect(self.move_files_ancestor_browse)
|
||||
|
||||
def toggle_move_files_ancestor_enabled(self):
|
||||
enabled = self.ui.rename_files.isChecked() and \
|
||||
self.ui.windows_compatibility.isChecked() and \
|
||||
self.ui.windows_compatibility.isEnabled() and \
|
||||
self.ui.move_files.isChecked()
|
||||
parentLayout = self.ui.move_files_ancestorLayout
|
||||
for i in range(parentLayout.count()):
|
||||
parentLayout.itemAt(i).widget().setEnabled(enabled)
|
||||
|
||||
def check_formats(self):
|
||||
self.test()
|
||||
@@ -88,7 +103,8 @@ class RenamingOptionsPage(OptionsPage):
|
||||
'move_files': self.ui.move_files.isChecked(),
|
||||
'use_va_format': False, # TODO remove
|
||||
'file_naming_format': unicode(self.ui.file_naming_format.toPlainText()),
|
||||
'move_files_to': os.path.normpath(unicode(self.ui.move_files_to.text()))
|
||||
'move_files_to': os.path.normpath(unicode(self.ui.move_files_to.text())),
|
||||
'move_files_ancestor': unicode(self.ui.move_files_ancestor.text())
|
||||
}
|
||||
try:
|
||||
if self.config.setting["enable_tagger_script"]:
|
||||
@@ -123,6 +139,8 @@ class RenamingOptionsPage(OptionsPage):
|
||||
self.ui.file_naming_format.setPlainText(self.config.setting["file_naming_format"])
|
||||
self.ui.move_files_to.setText(self.config.setting["move_files_to"])
|
||||
self.ui.move_files_to.setCursorPosition(0)
|
||||
self.ui.move_files_ancestor.setText(self.config.setting["move_files_ancestor"])
|
||||
self.ui.move_files_ancestor.setCursorPosition(0)
|
||||
self.ui.move_additional_files.setChecked(self.config.setting["move_additional_files"])
|
||||
self.ui.move_additional_files_pattern.setText(self.config.setting["move_additional_files_pattern"])
|
||||
self.ui.delete_empty_dirs.setChecked(self.config.setting["delete_empty_dirs"])
|
||||
@@ -130,8 +148,21 @@ class RenamingOptionsPage(OptionsPage):
|
||||
|
||||
def check(self):
|
||||
self.check_format()
|
||||
if self.ui.move_files.isChecked() and not unicode(self.ui.move_files_to.text()).strip():
|
||||
raise OptionsCheckError(_("Error"), _("The location to move files to must not be empty."))
|
||||
if self.ui.move_files.isChecked():
|
||||
move_files_to = unicode(self.ui.move_files_to.text()).strip()
|
||||
if not move_files_to:
|
||||
raise OptionsCheckError(_("Error"), _("The location to move files to must not be empty."))
|
||||
if self.ui.windows_compatibility.isChecked() and self.ui.windows_compatibility.isEnabled():
|
||||
move_files_ancestor = unicode(self.ui.move_files_ancestor.text()).strip()
|
||||
if move_files_ancestor:
|
||||
move_files_to = os.path.abspath(move_files_to)
|
||||
move_files_ancestor = os.path.abspath(move_files_ancestor)
|
||||
if not move_files_to.startswith(move_files_ancestor) or \
|
||||
move_files_to.split(move_files_ancestor)[1][:1] not in (os.path.sep, ""):
|
||||
raise OptionsCheckError(
|
||||
_("Error"),
|
||||
_("Compatibility must be applied against an ancestor of where files are moved to.")
|
||||
)
|
||||
|
||||
def check_format(self):
|
||||
parser = ScriptParser()
|
||||
@@ -151,6 +182,7 @@ class RenamingOptionsPage(OptionsPage):
|
||||
self.tagger.window.enable_renaming_action.setChecked(self.config.setting["rename_files"])
|
||||
self.config.setting["move_files"] = self.ui.move_files.isChecked()
|
||||
self.config.setting["move_files_to"] = os.path.normpath(unicode(self.ui.move_files_to.text()))
|
||||
self.config.setting["move_files_ancestor"] = unicode(self.ui.move_files_ancestor.text())
|
||||
self.config.setting["move_additional_files"] = self.ui.move_additional_files.isChecked()
|
||||
self.config.setting["move_additional_files_pattern"] = unicode(self.ui.move_additional_files_pattern.text())
|
||||
self.config.setting["delete_empty_dirs"] = self.ui.delete_empty_dirs.isChecked()
|
||||
@@ -220,6 +252,12 @@ class RenamingOptionsPage(OptionsPage):
|
||||
path = os.path.normpath(unicode(path))
|
||||
self.ui.move_files_to.setText(path)
|
||||
|
||||
def move_files_ancestor_browse(self):
|
||||
path = QtGui.QFileDialog.getExistingDirectory(self, "", self.ui.move_files_ancestor.text())
|
||||
if path:
|
||||
path = os.path.normpath(unicode(path))
|
||||
self.ui.move_files_ancestor.setText(path)
|
||||
|
||||
def test(self):
|
||||
self.ui.renaming_error.setStyleSheet("");
|
||||
self.ui.renaming_error.setText("")
|
||||
|
||||
@@ -72,6 +72,43 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="move_files_ancestorLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="move_files_ancestor_label">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Apply compatibility against:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="move_files_ancestor">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="move_files_ancestor_browse">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="delete_empty_dirs">
|
||||
<property name="enabled">
|
||||
|
||||
Reference in New Issue
Block a user