PICARD-2576: Move file naming compatibility options to separate page

This reduces the minimum height of the file naming dialog and opens the path for more compatibility options
This commit is contained in:
Philipp Wolfer
2022-12-04 11:28:19 +01:00
parent 07f9d2688f
commit b3c0d787bb
7 changed files with 254 additions and 105 deletions

View File

@@ -75,6 +75,7 @@ from picard.ui.options import ( # noqa: F401 # pylint: disable=unused-import
ratings,
releases,
renaming,
renaming_compat,
scripting,
tags,
tags_compatibility_aac,

View File

@@ -44,9 +44,7 @@ from picard.config import (
TextOption,
get_config,
)
from picard.const.sys import IS_WIN
from picard.script import ScriptParser
from picard.util import system_supports_long_paths
from picard.ui.options import (
OptionsCheckError,
@@ -79,9 +77,6 @@ class RenamingOptionsPage(OptionsPage):
HELP_URL = '/config/options_filerenaming.html'
options = [
BoolOption("setting", "windows_compatibility", True),
BoolOption("setting", "windows_long_paths", system_supports_long_paths() if IS_WIN else False),
BoolOption("setting", "ascii_filenames", False),
BoolOption("setting", "rename_files", False),
BoolOption("setting", "move_files", False),
TextOption("setting", "move_files_to", _default_music_dir),
@@ -96,9 +91,6 @@ class RenamingOptionsPage(OptionsPage):
self.ui = Ui_RenamingOptionsPage()
self.ui.setupUi(self)
self.ui.ascii_filenames.clicked.connect(self.update_examples_from_local)
self.ui.windows_compatibility.clicked.connect(self.update_examples_from_local)
self.ui.windows_long_paths.clicked.connect(self.update_examples_from_local)
self.ui.rename_files.clicked.connect(self.update_examples_from_local)
self.ui.move_files.clicked.connect(self.update_examples_from_local)
self.ui.move_files_to.editingFinished.connect(self.update_examples_from_local)
@@ -200,20 +192,6 @@ class RenamingOptionsPage(OptionsPage):
active = self.ui.move_files.isChecked() or self.ui.rename_files.isChecked()
self.ui.open_script_editor.setEnabled(active)
def toggle_windows_long_paths(self, state):
if state and not system_supports_long_paths():
dialog = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Icon.Information,
_('Windows long path support'),
_(
'Enabling long paths on Windows might cause files being saved with path names '
'exceeding the 259 character limit traditionally imposed by the Windows API. '
'Some software might not be able to properly access those files.'
),
QtWidgets.QMessageBox.StandardButton.Ok,
self)
dialog.exec_()
def save_from_editor(self):
self.script_text = self.script_editor_dialog.get_script()
self.update_selector_from_editor()
@@ -228,11 +206,12 @@ class RenamingOptionsPage(OptionsPage):
def update_examples_from_local(self):
override = {
'ascii_filenames': self.ui.ascii_filenames.isChecked(),
'move_files': self.ui.move_files.isChecked(),
'move_files_to': os.path.normpath(self.ui.move_files_to.text()),
'rename_files': self.ui.rename_files.isChecked(),
'windows_compatibility': self.ui.windows_compatibility.isChecked(),
# 'ascii_filenames': self.ui.ascii_filenames.isChecked(),
# 'windows_compatibility': self.ui.windows_compatibility.isChecked(),
# 'windows_long_paths': self.ui.windows_long_paths.isChecked(),
}
self.examples.update_examples(override=override)
self.update_displayed_examples()
@@ -250,19 +229,8 @@ class RenamingOptionsPage(OptionsPage):
def load(self):
config = get_config()
try:
self.ui.windows_long_paths.toggled.disconnect(self.toggle_windows_long_paths)
except TypeError:
pass
if IS_WIN:
self.ui.windows_compatibility.setChecked(True)
self.ui.windows_compatibility.setEnabled(False)
else:
self.ui.windows_compatibility.setChecked(config.setting["windows_compatibility"])
self.ui.windows_long_paths.setChecked(config.setting["windows_long_paths"])
self.ui.rename_files.setChecked(config.setting["rename_files"])
self.ui.move_files.setChecked(config.setting["move_files"])
self.ui.ascii_filenames.setChecked(config.setting["ascii_filenames"])
self.ui.move_files_to.setText(config.setting["move_files_to"])
self.ui.move_files_to.setCursorPosition(0)
self.ui.move_additional_files.setChecked(config.setting["move_additional_files"])
@@ -275,7 +243,6 @@ class RenamingOptionsPage(OptionsPage):
else:
self.update_selector_from_settings()
self.update_examples_from_local()
self.ui.windows_long_paths.toggled.connect(self.toggle_windows_long_paths)
def check(self):
self.check_format()
@@ -294,9 +261,6 @@ class RenamingOptionsPage(OptionsPage):
def save(self):
config = get_config()
config.setting["windows_compatibility"] = self.ui.windows_compatibility.isChecked()
config.setting["windows_long_paths"] = self.ui.windows_long_paths.isChecked()
config.setting["ascii_filenames"] = self.ui.ascii_filenames.isChecked()
config.setting["rename_files"] = self.ui.rename_files.isChecked()
config.setting["move_files"] = self.ui.move_files.isChecked()
config.setting["move_files_to"] = os.path.normpath(self.ui.move_files_to.text())

View File

@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2006-2008, 2011 Lukáš Lalinský
# Copyright (C) 2008-2009 Nikolai Prokoschenko
# Copyright (C) 2009-2010, 2014-2015, 2018-2022 Philipp Wolfer
# Copyright (C) 2011-2013 Michael Wiencek
# Copyright (C) 2011-2013 Wieland Hoffmann
# Copyright (C) 2013 Calvin Walton
# Copyright (C) 2013 Ionuț Ciocîrlan
# Copyright (C) 2013-2014 Sophist-UK
# Copyright (C) 2013-2015, 2018-2021 Laurent Monin
# Copyright (C) 2015 Alex Berman
# Copyright (C) 2015 Ohm Patel
# Copyright (C) 2016 Suhas
# Copyright (C) 2016-2017 Sambhav Kothari
# Copyright (C) 2021 Bob Swift
# Copyright (C) 2021 Gabriel Ferreira
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from PyQt5 import QtWidgets
from picard.config import (
BoolOption,
get_config,
)
from picard.const.sys import IS_WIN
from picard.util import system_supports_long_paths
from picard.ui.options import (
OptionsPage,
register_options_page,
)
from picard.ui.ui_options_renaming_compat import Ui_RenamingCompatOptionsPage
class RenamingCompatOptionsPage(OptionsPage):
NAME = "filerenaming_compat"
TITLE = N_("Compatibility")
PARENT = "filerenaming"
ACTIVE = True
HELP_URL = '/config/options_filerenaming_compat.html'
options = [
BoolOption("setting", "windows_compatibility", True),
BoolOption("setting", "windows_long_paths", system_supports_long_paths() if IS_WIN else False),
BoolOption("setting", "ascii_filenames", False),
]
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_RenamingCompatOptionsPage()
self.ui.setupUi(self)
def load(self):
config = get_config()
try:
self.ui.windows_long_paths.toggled.disconnect(self.toggle_windows_long_paths)
except TypeError:
pass
if IS_WIN:
self.ui.windows_compatibility.setChecked(True)
self.ui.windows_compatibility.setEnabled(False)
else:
self.ui.windows_compatibility.setChecked(config.setting["windows_compatibility"])
self.ui.windows_long_paths.setChecked(config.setting["windows_long_paths"])
self.ui.ascii_filenames.setChecked(config.setting["ascii_filenames"])
self.ui.windows_long_paths.toggled.connect(self.toggle_windows_long_paths)
def save(self):
config = get_config()
config.setting["windows_compatibility"] = self.ui.windows_compatibility.isChecked()
config.setting["windows_long_paths"] = self.ui.windows_long_paths.isChecked()
config.setting["ascii_filenames"] = self.ui.ascii_filenames.isChecked()
def toggle_windows_long_paths(self, state):
if state and not system_supports_long_paths():
dialog = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Icon.Information,
_('Windows long path support'),
_(
'Enabling long paths on Windows might cause files being saved with path names '
'exceeding the 259 character limit traditionally imposed by the Windows API. '
'Some software might not be able to properly access those files.'
),
QtWidgets.QMessageBox.StandardButton.Ok,
self)
dialog.exec_()
register_options_page(RenamingCompatOptionsPage)

View File

@@ -11,7 +11,7 @@ class Ui_RenamingOptionsPage(object):
def setupUi(self, RenamingOptionsPage):
RenamingOptionsPage.setObjectName("RenamingOptionsPage")
RenamingOptionsPage.setEnabled(True)
RenamingOptionsPage.resize(453, 679)
RenamingOptionsPage.resize(453, 468)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
@@ -52,16 +52,6 @@ class Ui_RenamingOptionsPage(object):
self.rename_files = QtWidgets.QCheckBox(RenamingOptionsPage)
self.rename_files.setObjectName("rename_files")
self.verticalLayout_5.addWidget(self.rename_files)
self.ascii_filenames = QtWidgets.QCheckBox(RenamingOptionsPage)
self.ascii_filenames.setObjectName("ascii_filenames")
self.verticalLayout_5.addWidget(self.ascii_filenames)
self.windows_compatibility = QtWidgets.QCheckBox(RenamingOptionsPage)
self.windows_compatibility.setObjectName("windows_compatibility")
self.verticalLayout_5.addWidget(self.windows_compatibility)
self.windows_long_paths = QtWidgets.QCheckBox(RenamingOptionsPage)
self.windows_long_paths.setEnabled(False)
self.windows_long_paths.setObjectName("windows_long_paths")
self.verticalLayout_5.addWidget(self.windows_long_paths)
self.label_2 = QtWidgets.QLabel(RenamingOptionsPage)
self.label_2.setObjectName("label_2")
self.verticalLayout_5.addWidget(self.label_2)
@@ -86,6 +76,7 @@ class Ui_RenamingOptionsPage(object):
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth())
self.groupBox.setSizePolicy(sizePolicy)
self.groupBox.setMinimumSize(QtCore.QSize(0, 120))
self.groupBox.setObjectName("groupBox")
self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.groupBox)
self.verticalLayout_6.setContentsMargins(3, 3, 3, 3)
@@ -141,7 +132,6 @@ class Ui_RenamingOptionsPage(object):
self.verticalLayout_5.addLayout(self.horizontalLayout)
self.retranslateUi(RenamingOptionsPage)
self.windows_compatibility.toggled['bool'].connect(self.windows_long_paths.setEnabled) # type: ignore
QtCore.QMetaObject.connectSlotsByName(RenamingOptionsPage)
RenamingOptionsPage.setTabOrder(self.move_files, self.move_files_to)
RenamingOptionsPage.setTabOrder(self.move_files_to, self.move_files_to_browse)
@@ -149,10 +139,7 @@ class Ui_RenamingOptionsPage(object):
RenamingOptionsPage.setTabOrder(self.move_additional_files, self.move_additional_files_pattern)
RenamingOptionsPage.setTabOrder(self.move_additional_files_pattern, self.delete_empty_dirs)
RenamingOptionsPage.setTabOrder(self.delete_empty_dirs, self.rename_files)
RenamingOptionsPage.setTabOrder(self.rename_files, self.ascii_filenames)
RenamingOptionsPage.setTabOrder(self.ascii_filenames, self.windows_compatibility)
RenamingOptionsPage.setTabOrder(self.windows_compatibility, self.windows_long_paths)
RenamingOptionsPage.setTabOrder(self.windows_long_paths, self.naming_script_selector)
RenamingOptionsPage.setTabOrder(self.rename_files, self.naming_script_selector)
RenamingOptionsPage.setTabOrder(self.naming_script_selector, self.open_script_editor)
RenamingOptionsPage.setTabOrder(self.open_script_editor, self.example_filename_before)
RenamingOptionsPage.setTabOrder(self.example_filename_before, self.example_filename_sample_files_button)
@@ -166,9 +153,6 @@ class Ui_RenamingOptionsPage(object):
self.move_additional_files.setText(_("Move additional files (case insensitive):"))
self.delete_empty_dirs.setText(_("Delete empty directories"))
self.rename_files.setText(_("Rename files when saving"))
self.ascii_filenames.setText(_("Replace non-ASCII characters"))
self.windows_compatibility.setText(_("Windows compatibility"))
self.windows_long_paths.setText(_("Allow paths longer than 259 characters"))
self.label_2.setText(_("Selected file naming script:"))
self.open_script_editor.setText(_("Edit file naming script..."))
self.groupBox.setTitle(_("Files will be named like this:"))

View File

@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# Automatically generated - don't edit.
# Use `python setup.py build_ui` to update it.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_RenamingCompatOptionsPage(object):
def setupUi(self, RenamingCompatOptionsPage):
RenamingCompatOptionsPage.setObjectName("RenamingCompatOptionsPage")
RenamingCompatOptionsPage.setEnabled(True)
RenamingCompatOptionsPage.resize(453, 374)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(RenamingCompatOptionsPage.sizePolicy().hasHeightForWidth())
RenamingCompatOptionsPage.setSizePolicy(sizePolicy)
self.verticalLayout_5 = QtWidgets.QVBoxLayout(RenamingCompatOptionsPage)
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.ascii_filenames = QtWidgets.QCheckBox(RenamingCompatOptionsPage)
self.ascii_filenames.setObjectName("ascii_filenames")
self.verticalLayout_5.addWidget(self.ascii_filenames)
self.windows_compatibility = QtWidgets.QCheckBox(RenamingCompatOptionsPage)
self.windows_compatibility.setObjectName("windows_compatibility")
self.verticalLayout_5.addWidget(self.windows_compatibility)
self.windows_long_paths = QtWidgets.QCheckBox(RenamingCompatOptionsPage)
self.windows_long_paths.setEnabled(False)
self.windows_long_paths.setObjectName("windows_long_paths")
self.verticalLayout_5.addWidget(self.windows_long_paths)
self.example_selection_note = QtWidgets.QLabel(RenamingCompatOptionsPage)
self.example_selection_note.setText("")
self.example_selection_note.setWordWrap(True)
self.example_selection_note.setObjectName("example_selection_note")
self.verticalLayout_5.addWidget(self.example_selection_note)
self.retranslateUi(RenamingCompatOptionsPage)
self.windows_compatibility.toggled['bool'].connect(self.windows_long_paths.setEnabled) # type: ignore
QtCore.QMetaObject.connectSlotsByName(RenamingCompatOptionsPage)
RenamingCompatOptionsPage.setTabOrder(self.ascii_filenames, self.windows_compatibility)
RenamingCompatOptionsPage.setTabOrder(self.windows_compatibility, self.windows_long_paths)
def retranslateUi(self, RenamingCompatOptionsPage):
_translate = QtCore.QCoreApplication.translate
self.ascii_filenames.setText(_("Replace non-ASCII characters"))
self.windows_compatibility.setText(_("Windows compatibility"))
self.windows_long_paths.setText(_("Allow paths longer than 259 characters"))

View File

@@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>453</width>
<height>679</height>
<height>468</height>
</rect>
</property>
<property name="sizePolicy">
@@ -19,7 +19,7 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0,0,0,0,0,0,0,0,0,0">
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0,0,0,0,0,0,0">
<item>
<widget class="QGroupBox" name="move_files">
<property name="title">
@@ -86,30 +86,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ascii_filenames">
<property name="text">
<string>Replace non-ASCII characters</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="windows_compatibility">
<property name="text">
<string>Windows compatibility</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="windows_long_paths">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Allow paths longer than 259 characters</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
@@ -149,6 +125,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>120</height>
</size>
</property>
<property name="title">
<string>Files will be named like this:</string>
</property>
@@ -304,9 +286,6 @@
<tabstop>move_additional_files_pattern</tabstop>
<tabstop>delete_empty_dirs</tabstop>
<tabstop>rename_files</tabstop>
<tabstop>ascii_filenames</tabstop>
<tabstop>windows_compatibility</tabstop>
<tabstop>windows_long_paths</tabstop>
<tabstop>naming_script_selector</tabstop>
<tabstop>open_script_editor</tabstop>
<tabstop>example_filename_before</tabstop>
@@ -314,22 +293,5 @@
<tabstop>example_filename_after</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>windows_compatibility</sender>
<signal>toggled(bool)</signal>
<receiver>windows_long_paths</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>226</x>
<y>267</y>
</hint>
<hint type="destinationlabel">
<x>226</x>
<y>296</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

View File

@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RenamingCompatOptionsPage</class>
<widget class="QWidget" name="RenamingCompatOptionsPage">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>453</width>
<height>374</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0,0,0,0">
<item>
<widget class="QCheckBox" name="ascii_filenames">
<property name="text">
<string>Replace non-ASCII characters</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="windows_compatibility">
<property name="text">
<string>Windows compatibility</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="windows_long_paths">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Allow paths longer than 259 characters</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="example_selection_note">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>ascii_filenames</tabstop>
<tabstop>windows_compatibility</tabstop>
<tabstop>windows_long_paths</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>windows_compatibility</sender>
<signal>toggled(bool)</signal>
<receiver>windows_long_paths</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>226</x>
<y>267</y>
</hint>
<hint type="destinationlabel">
<x>226</x>
<y>296</y>
</hint>
</hints>
</connection>
</connections>
</ui>