Skip to content

Conversation

knguyen1
Copy link
Contributor

@knguyen1 knguyen1 commented Sep 8, 2025

Summary

  • This is a…
    • Bug fix
    • Feature addition
    • Refactoring
    • Minor / simple change (like a typo)
    • Other
  • Describe this change in 1-2 sentences: Implements session management functionality allowing users to save and restore their Picard workspace state, including file locations, metadata overrides, and configuration options.

Problem

Users lose their work state when closing Picard, including file placements, manual metadata edits, and album configurations.

Solution

Core Components

Session Data Structures (session_data.py):

  • SessionItemLocation: Tracks file placement (unclustered, cluster, album, track, NAT)
  • SessionData: Complete session container with version, options, items, and metadata overrides

Session Exporter (session_exporter.py):

  • Captures workspace state including file locations and metadata deltas
  • Exports only user-visible tags (excludes internal ~ tags)
  • Supports optional MusicBrainz data caching

Session Loader (session_loader.py):

  • Restores complete session with progress reporting
  • Handles asynchronous file loading with retry mechanisms
  • Applies metadata overrides after files are ready

Supporting Modules:

  • location_detector.py: Determines file placement within session structure
  • metadata_handler.py: Serializes/deserializes metadata with error handling
  • track_mover.py: Handles file-to-track movement with retry logic
  • retry_helper.py: Centralized retry mechanism

Key Features

  • Safe Restore: Respects session_safe_restore setting to prevent overwriting unsaved changes
  • Metadata Preservation: Saves only deltas vs original metadata
  • Location Tracking: Supports all file placement types
  • Configuration Persistence: Saves/restores file processing options
  • UI State: Preserves album expansion state

File Format

  • Extension: .mbps.gz (gzip-compressed YAML)
  • Version: Format version 1 with extensibility

Configuration Options

Five new options added:

  • session_safe_restore: Honor local edits on load (default: True)
  • session_load_last_on_startup: Auto-load last session (default: False)
  • session_autosave_interval_min: Auto-save interval in minutes (default: 0 = disabled)
  • session_backup_on_crash: Keep backup on unexpected shutdown (default: True)
  • session_include_mb_data: Include MB data in sessions (default: False)

Action

Additional actions required:

Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few comments, I didn't test yet (I will soon).
That's a very promising improvement :)

Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the automatic saving (based on time).

Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI-wise it works well, thanks for all recent additions.
And it works well.

Though I have concerns about only saving 3 options, and IMHO this isn't enough (see my comment about that)

Resolved conflicts by:
- Keeping enable_tag_saving handler from master in mainwindow/__init__.py
- Merging session-related options with master's filter column defaults in options.py
- Preserving session constants while adding master's DEFAULT_FILTER_COLUMNS in defaults.py
@knguyen1 knguyen1 force-pushed the feat/PICARD-3118/add-save-session-feature branch from b9d8434 to 1bee982 Compare September 22, 2025 23:35
@knguyen1
Copy link
Contributor Author

Try now. All test comments should have been addressed.

Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zas zas merged commit 94124ed into metabrainz:master Sep 30, 2025
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants