Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into plugin_update_ava…
Browse files Browse the repository at this point in the history
…ilable_notification_z
  • Loading branch information
zas committed Aug 1, 2023
2 parents d8491a9 + 46f16e6 commit c6b5f15
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
3 changes: 3 additions & 0 deletions picard/const/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
)


DEFAULT_PROGRAM_UPDATE_LEVEL = 0


DEFAULT_FILE_NAMING_FORMAT = "$if2(%albumartist%,%artist%)/\n" \
"$if(%albumartist%,%album%/,)\n" \
"$if($gt(%totaldiscs%,1),$if($gt(%totaldiscs%,9),$num(%discnumber%,2),%discnumber%)-,)" \
Expand Down
2 changes: 1 addition & 1 deletion picard/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _loading_finished(self, callback, result=None, error=None):

if alternative_file:
# Do not retry reloading exactly the same file format
if type(alternative_file) != type(self): # pylint: disable=unidiomatic-typecheck
if type(alternative_file) != type(self): # pylint: disable=unidiomatic-typecheck # noqa: E721
log.debug('Loading %r failed, retrying as %r', self, alternative_file)
self.remove()
alternative_file.load(callback)
Expand Down
3 changes: 1 addition & 2 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ def _add_other_versions():

# Using type here is intentional. isinstance will return true for the
# NatAlbum instance, which can't be part of a collection.
# pylint: disable=C0123
selected_albums = [a for a in self.window.selected_objects if type(a) == Album]
selected_albums = [a for a in self.window.selected_objects if type(a) == Album] # pylint: disable=C0123 # noqa: E721
if selected_albums:
if not bottom_separator:
menu.addSeparator()
Expand Down
4 changes: 3 additions & 1 deletion picard/ui/options/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from PyQt5 import QtWidgets

from picard import log
from picard.config import get_config
from picard.plugin import ExtensionPoint

Expand Down Expand Up @@ -81,7 +82,8 @@ def restore_defaults(self):
config = get_config()
old_options = {}
for option in options:
if option.section == 'setting':
if option.section == 'setting' and config.setting[option.name] != option.default:
log.debug("Option %s %s: %r -> %r" % (self.NAME, option.name, config.setting[option.name], option.default))
old_options[option.name] = config.setting[option.name]
config.setting[option.name] = option.default
self.load()
Expand Down
16 changes: 12 additions & 4 deletions picard/ui/options/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class OptionsDialog(PicardDialog, SingletonDialog):
ListOption("persist", "options_pages_tree_state", []),
]

suspend_signals = False

def add_pages(self, parent, default_page, parent_item):
pages = [(p.SORT_ORDER, p.NAME, p) for p in self.pages if p.PARENT == parent]
items = []
Expand Down Expand Up @@ -243,7 +245,8 @@ def _get_profile_title_from_id(self, profile_id):
return _('Unknown profile')

def update_from_profile_changes(self):
self.highlight_enabled_profile_options(load_settings=True)
if not self.suspend_signals:
self.highlight_enabled_profile_options(load_settings=True)

def get_working_profile_data(self):
profile_page = self.get_page('profiles')
Expand Down Expand Up @@ -411,13 +414,18 @@ def restoreWindowState(self):
item.setExpanded(is_expanded)

def restore_all_defaults(self):
self.suspend_signals = True
for page in self.pages:
page.restore_defaults()
self.highlight_enabled_profile_options()
try:
page.restore_defaults()
except Exception as e:
log.error('Failed restoring all defaults for page %r: %s', page, e)
self.highlight_enabled_profile_options(load_settings=False)
self.suspend_signals = False

def restore_page_defaults(self):
self.ui.pages_stack.currentWidget().restore_defaults()
self.highlight_enabled_profile_options()
self.highlight_enabled_profile_options(load_settings=False)

def confirm_reset(self):
msg = _("You are about to reset your options for this page.")
Expand Down
39 changes: 23 additions & 16 deletions picard/ui/options/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
get_config,
)
from picard.const import (
DEFAULT_PROGRAM_UPDATE_LEVEL,
MUSICBRAINZ_SERVERS,
PROGRAM_UPDATE_LEVELS,
)
Expand Down Expand Up @@ -72,7 +73,7 @@ class GeneralOptionsPage(OptionsPage):
TextOption("persist", "oauth_username", ""),
BoolOption("setting", "check_for_updates", True),
IntOption("setting", "update_check_days", 7),
IntOption("setting", "update_level", 0),
IntOption("setting", "update_level", DEFAULT_PROGRAM_UPDATE_LEVEL),
IntOption("persist", "last_update_check", 0),
BoolOption("setting", "check_for_plugin_updates", True),
]
Expand Down Expand Up @@ -101,17 +102,24 @@ def load(self):
self.ui.cluster_new_files.setChecked(config.setting["cluster_new_files"])
self.ui.ignore_file_mbids.setChecked(config.setting["ignore_file_mbids"])
self.ui.check_for_plugin_updates.setChecked(config.setting["check_for_plugin_updates"])
if self.tagger.autoupdate_enabled:
self.ui.check_for_updates.setChecked(config.setting["check_for_updates"])
self.ui.update_level.clear()
for level, description in PROGRAM_UPDATE_LEVELS.items():
# TODO: Remove temporary workaround once https://github.com/python-babel/babel/issues/415 has been resolved.
babel_415_workaround = description['title']
self.ui.update_level.addItem(_(babel_415_workaround), level)
self.ui.update_level.setCurrentIndex(self.ui.update_level.findData(config.setting["update_level"]))
self.ui.update_check_days.setValue(config.setting["update_check_days"])
else:
self.ui.program_update_check_frame.hide()
self.ui.check_for_updates.setChecked(config.setting["check_for_updates"])
self.set_update_level(config.setting["update_level"])
self.ui.update_check_days.setValue(config.setting["update_check_days"])
if not self.tagger.autoupdate_enabled:
self.ui.update_check_groupbox.hide()

def set_update_level(self, value):
if value not in PROGRAM_UPDATE_LEVELS:
value = DEFAULT_PROGRAM_UPDATE_LEVEL
self.ui.update_level.clear()
for level, description in PROGRAM_UPDATE_LEVELS.items():
# TODO: Remove temporary workaround once https://github.com/python-babel/babel/issues/415 has been resolved.
babel_415_workaround = description['title']
self.ui.update_level.addItem(_(babel_415_workaround), level)
idx = self.ui.update_level.findData(value)
if idx == -1:
idx = self.ui.update_level.findData(DEFAULT_PROGRAM_UPDATE_LEVEL)
self.ui.update_level.setCurrentIndex(idx)

def save(self):
config = get_config()
Expand All @@ -122,10 +130,9 @@ def save(self):
config.setting["cluster_new_files"] = self.ui.cluster_new_files.isChecked()
config.setting["ignore_file_mbids"] = self.ui.ignore_file_mbids.isChecked()
config.setting["check_for_plugin_updates"] = self.ui.check_for_plugin_updates.isChecked()
if self.tagger.autoupdate_enabled:
config.setting["check_for_updates"] = self.ui.check_for_updates.isChecked()
config.setting["update_level"] = self.ui.update_level.currentData(QtCore.Qt.ItemDataRole.UserRole)
config.setting["update_check_days"] = self.ui.update_check_days.value()
config.setting["check_for_updates"] = self.ui.check_for_updates.isChecked()
config.setting["update_level"] = self.ui.update_level.currentData(QtCore.Qt.ItemDataRole.UserRole)
config.setting["update_check_days"] = self.ui.update_check_days.value()

def update_server_host(self):
host = self.ui.server_host.currentText().strip()
Expand Down

0 comments on commit c6b5f15

Please sign in to comment.