Skip to content

Commit

Permalink
Add a config upgrade hook to avoid any issue with saved header state …
Browse files Browse the repository at this point in the history
…and lock

- if the header state was saved during lock it was actually saving the state sets by locking itself
- new code avoids this, and always save the state before locking
  • Loading branch information
zas committed May 10, 2024
1 parent 6a89aab commit 380c85b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion picard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
PICARD_DISPLAY_NAME = "MusicBrainz Picard"
PICARD_APP_ID = "org.musicbrainz.Picard"
PICARD_DESKTOP_NAME = PICARD_APP_ID + ".desktop"
PICARD_VERSION = Version(3, 0, 0, 'dev', 3)
PICARD_VERSION = Version(3, 0, 0, 'dev', 4)


# optional build version
Expand Down
8 changes: 8 additions & 0 deletions picard/config_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,14 @@ def upgrade_to_v3_0_0dev3(config):
rename_option(config, old_opt, new_opt, BoolOption, False)


def upgrade_to_v3_0_0dev4(config):
"""Reset "file/album_view_header_state" if there were saved while locked."""
if config.persist['album_view_header_locked']:
config.persist.remove('album_view_header_state')
if config.persist['file_view_header_locked']:
config.persist.remove('file_view_header_state')


def rename_option(config, old_opt, new_opt, option_type, default):
_s = config.setting
if old_opt in _s:
Expand Down
22 changes: 22 additions & 0 deletions test/test_config_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
upgrade_to_v2_7_0dev5,
upgrade_to_v2_8_0dev2,
upgrade_to_v3_0_0dev3,
upgrade_to_v3_0_0dev4,
)
from picard.const.defaults import (
DEFAULT_FILE_NAMING_FORMAT,
Expand Down Expand Up @@ -519,3 +520,24 @@ def test_upgrade_to_v3_0_0dev3(self):
upgrade_to_v3_0_0dev3(self.config)
self.assertNotIn('toolbar_multiselect', self.config.setting)
self.assertTrue(self.config.setting['allow_multi_dirs_selection'])

def test_upgrade_to_v3_0_0dev4(self):
Option('persist', 'album_view_header_state', QByteArray())
Option('persist', 'file_view_header_state', QByteArray())
BoolOption('persist', 'album_view_header_locked', False)
BoolOption('persist', 'file_view_header_locked', False)

self.config.persist['album_view_header_state'] = b'foo'
self.config.persist['file_view_header_state'] = b'bar'

# test not locked, states shouldn't be modified
upgrade_to_v3_0_0dev4(self.config)
self.assertEqual(b'foo', self.config.persist['album_view_header_state'])
self.assertEqual(b'bar', self.config.persist['file_view_header_state'])

# test locked, states should be removed
self.config.persist['album_view_header_locked'] = True
self.config.persist['file_view_header_locked'] = True
upgrade_to_v3_0_0dev4(self.config)
self.assertEqual(b'', self.config.persist['album_view_header_state'])
self.assertEqual(b'', self.config.persist['file_view_header_state'])

0 comments on commit 380c85b

Please sign in to comment.