feat: hide iPod tab/button/menu when no device + fix settings persistence

- Hide iPod tab when no iPod connected, show on device detection
- Disable Transfer button and context menu item when no iPod mounted
- Add missing settings load/save: video_resolution, use_musicbrainz, show_download
- Fix clean_temp section mismatch (was [General], now [Advanced])
- Add _save_settings() called on closeEvent
This commit is contained in:
Maksim Totmin 2026-06-01 01:05:05 +07:00
parent 1ae1e90ae3
commit 61bcaec7a3
2 changed files with 43 additions and 4 deletions

View File

@ -97,7 +97,6 @@ class ConfigLoader:
self.config.set('General', 'output_dir', os.path.join(os.path.expanduser("~"), "Music", "iPod"))
self.config.set('General', 'format', 'm4a')
self.config.set('General', 'quality', '256')
self.config.set('General', 'clean_temp', 'true')
# Video section
if not self.config.has_section('Video'):
@ -127,6 +126,8 @@ class ConfigLoader:
self.config.set('Advanced', 'temp_dir', 'temp')
self.config.set('Advanced', 'concurrent_downloads', '2')
self.config.set('Advanced', 'debug', 'false')
self.config.set('Advanced', 'clean_temp', 'true')
self.config.set('Advanced', 'show_download', 'false')
# Hotkeys section
if not self.config.has_section('Hotkeys'):

View File

@ -285,6 +285,7 @@ class MainWindow(QMainWindow):
self.ipod_devices: List[Dict] = []
self.current_mount_point: Optional[str] = None
self.show_download_tab = False
self.ipod_tab_index = 2
self.config_loader = ConfigLoader()
self.hotkey_manager: Optional[HotkeyManager] = None
@ -324,15 +325,39 @@ class MainWindow(QMainWindow):
self.enable_video_check.setChecked(
config.get_boolean("Video", "enable_video", fallback=False)
)
self.video_resolution_combo.setCurrentText(
config.get("Video", "resolution", fallback="640x480")
)
self.embed_artwork_check.setChecked(
config.get_boolean("Metadata", "embed_artwork", fallback=True)
)
self.use_musicbrainz_check.setChecked(
config.get_boolean("Metadata", "use_musicbrainz", fallback=False)
)
self.clean_temp_check.setChecked(
config.get_boolean("Advanced", "clean_temp", fallback=True)
)
self.auto_detect_check.setChecked(
config.get_boolean("Device", "auto_detect", fallback=True)
)
show_download = config.get_boolean("Advanced", "show_download", fallback=False)
self.show_download_check.setChecked(show_download)
self.show_download_tab = show_download
self.tab_widget.setTabVisible(self.download_tab_index, show_download)
def _save_settings(self):
config = self.config_loader
config.set("General", "output_dir", self.output_dir_input.text())
config.set("General", "format", self.format_combo.currentText())
config.set("General", "quality", str(self.quality_spin.value()))
config.set("Video", "enable_video", str(self.enable_video_check.isChecked()).lower())
config.set("Video", "resolution", self.video_resolution_combo.currentText())
config.set("Metadata", "embed_artwork", str(self.embed_artwork_check.isChecked()).lower())
config.set("Metadata", "use_musicbrainz", str(self.use_musicbrainz_check.isChecked()).lower())
config.set("Advanced", "clean_temp", str(self.clean_temp_check.isChecked()).lower())
config.set("Device", "auto_detect", str(self.auto_detect_check.isChecked()).lower())
config.set("Advanced", "show_download", str(self.show_download_check.isChecked()).lower())
config.save()
def _setup_hotkeys(self):
self.hotkey_manager = HotkeyManager(self, self.config_loader)
@ -346,7 +371,7 @@ class MainWindow(QMainWindow):
"seek_backward": self._seek_backward,
"tab_download": lambda: self.tab_widget.setCurrentIndex(self.download_tab_index),
"tab_library": lambda: self.tab_widget.setCurrentIndex(1),
"tab_ipod": lambda: self.tab_widget.setCurrentIndex(2),
"tab_ipod": lambda: self.tab_widget.setCurrentIndex(self.ipod_tab_index),
"tab_settings": lambda: self.tab_widget.setCurrentIndex(3),
"search_focus": self._focus_search,
"select_all": self._select_all_current,
@ -387,6 +412,7 @@ class MainWindow(QMainWindow):
self._setup_settings_tab(settings_tab)
self.tab_widget.setTabVisible(self.download_tab_index, self.show_download_tab)
self.tab_widget.setTabVisible(self.ipod_tab_index, False)
self.statusBar().showMessage("Ready")
self.setCentralWidget(main_widget)
@ -1147,7 +1173,7 @@ class MainWindow(QMainWindow):
has_ready = ready_count > 0
has_source = source_count > 0
self.library_transfer_btn.setEnabled(has_ready)
self.library_transfer_btn.setEnabled(has_ready and self.current_mount_point is not None)
self.library_convert_btn.setEnabled(has_source)
self.library_remove_btn.setEnabled(len(all_tracks) > 0)
self.library_edit_btn.setEnabled(len(all_tracks) > 0)
@ -1391,7 +1417,7 @@ class MainWindow(QMainWindow):
play_action = menu.addAction("\u25B6 Play")
play_action.triggered.connect(lambda: self._play_track_from_index(row))
if is_ready:
if is_ready and self.current_mount_point is not None:
transfer_action = menu.addAction("\uD83D\uDCE4 Transfer to iPod")
transfer_action.triggered.connect(self._on_library_transfer_clicked)
else:
@ -1659,9 +1685,12 @@ class MainWindow(QMainWindow):
self.mount_button.setEnabled(False)
self.eject_button.setEnabled(True)
self.tab_widget.setTabVisible(self.ipod_tab_index, True)
self._load_ipod_tracks()
def _set_device_unmounted(self, device: dict):
self.current_mount_point = None
self.device_info_label.setText(
f"Device: {device['name']}\n"
f"Click 'Mount' to connect"
@ -1674,8 +1703,12 @@ class MainWindow(QMainWindow):
self.export_button.setEnabled(False)
self.export_progress.setVisible(False)
self.export_status.setVisible(False)
self.library_transfer_btn.setEnabled(False)
self.tab_widget.setTabVisible(self.ipod_tab_index, True)
def _set_device_not_found(self):
self.current_mount_point = None
self.device_info_label.setText("No iPod devices found")
self.device_status_label.setText("Status: Not connected")
self.device_combo.clear()
@ -1686,6 +1719,9 @@ class MainWindow(QMainWindow):
self.export_button.setEnabled(False)
self.export_progress.setVisible(False)
self.export_status.setVisible(False)
self.library_transfer_btn.setEnabled(False)
self.tab_widget.setTabVisible(self.ipod_tab_index, False)
def _on_mount_clicked(self):
if not self.ipod_devices:
@ -1732,6 +1768,7 @@ class MainWindow(QMainWindow):
success = ipod.unmount_device()
if success or True:
self.current_mount_point = None
self.library_transfer_btn.setEnabled(False)
if self.ipod_devices:
self.ipod_devices[0]["mounted"] = False
self.ipod_devices[0]["mount_point"] = None
@ -2012,6 +2049,7 @@ class MainWindow(QMainWindow):
self.worker_thread.stop()
self.worker_thread.wait(5000)
self.worker_thread.deleteLater()
self._save_settings()
event.accept()