diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 379116215..c530a9f8c 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -264,15 +264,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co // Initialise the UI ui_->setupUi(this); - connect(app_->current_albumcover_loader(), SIGNAL(AlbumCoverLoaded(Song, AlbumCoverLoaderResult)), SLOT(AlbumCoverLoaded(Song, AlbumCoverLoaderResult))); album_cover_choice_controller_->Init(app); - connect(album_cover_choice_controller_->cover_from_file_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); - connect(album_cover_choice_controller_->cover_to_file_action(), SIGNAL(triggered()), this, SLOT(SaveCoverToFile())); - connect(album_cover_choice_controller_->cover_from_url_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromURL())); - connect(album_cover_choice_controller_->search_for_cover_action(), SIGNAL(triggered()), this, SLOT(SearchForCover())); - connect(album_cover_choice_controller_->unset_cover_action(), SIGNAL(triggered()), this, SLOT(UnsetCover())); - connect(album_cover_choice_controller_->show_cover_action(), SIGNAL(triggered()), this, SLOT(ShowCover())); - connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically())); ui_->multi_loading_indicator->SetTaskManager(app_->task_manager()); context_view_->Init(app_, collection_view_->view(), album_cover_choice_controller_); @@ -429,7 +421,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co connect(ui_->action_auto_complete_tags, SIGNAL(triggered()), SLOT(AutoCompleteTags())); #endif connect(ui_->action_settings, SIGNAL(triggered()), SLOT(OpenSettingsDialog())); - connect(ui_->action_toggle_show_sidebar, SIGNAL(toggled(bool)), ui_->sidebar_layout, SLOT(setVisible(bool))); + connect(ui_->action_toggle_show_sidebar, SIGNAL(toggled(bool)), SLOT(ToggleSidebar(bool))); connect(ui_->action_about_strawberry, SIGNAL(triggered()), SLOT(ShowAboutDialog())); connect(ui_->action_about_qt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(ui_->action_shuffle, SIGNAL(triggered()), app_->playlist_manager(), SLOT(ShuffleCurrent())); @@ -549,6 +541,16 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co connect(app_->task_manager(), SIGNAL(PauseCollectionWatchers()), app_->collection(), SLOT(PauseWatcher())); connect(app_->task_manager(), SIGNAL(ResumeCollectionWatchers()), app_->collection(), SLOT(ResumeWatcher())); + connect(app_->current_albumcover_loader(), SIGNAL(AlbumCoverLoaded(Song, AlbumCoverLoaderResult)), SLOT(AlbumCoverLoaded(Song, AlbumCoverLoaderResult))); + connect(album_cover_choice_controller_->cover_from_file_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); + connect(album_cover_choice_controller_->cover_to_file_action(), SIGNAL(triggered()), this, SLOT(SaveCoverToFile())); + connect(album_cover_choice_controller_->cover_from_url_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromURL())); + connect(album_cover_choice_controller_->search_for_cover_action(), SIGNAL(triggered()), this, SLOT(SearchForCover())); + connect(album_cover_choice_controller_->unset_cover_action(), SIGNAL(triggered()), this, SLOT(UnsetCover())); + connect(album_cover_choice_controller_->show_cover_action(), SIGNAL(triggered()), this, SLOT(ShowCover())); + connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically())); + connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(toggled(bool)), SLOT(ToggleSearchCoverAuto(bool))); + #ifndef Q_OS_WIN // Devices connections connect(device_view_->view(), SIGNAL(AddToPlaylistSignal(QMimeData*)), SLOT(AddToPlaylist(QMimeData*))); @@ -804,10 +806,10 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co if (tab_mode == FancyTabWidget::Mode_None) tab_mode = default_mode; ui_->tabs->SetMode(tab_mode); - file_view_->SetPath(settings_.value("file_path", QDir::homePath()).toString()); - TabSwitched(); + file_view_->SetPath(settings_.value("file_path", QDir::homePath()).toString()); + // Users often collapse one side of the splitter by mistake and don't know how to restore it. This must be set after the state is restored above. ui_->splitter->setChildrenCollapsible(false); @@ -822,10 +824,10 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co #ifdef Q_OS_MACOS // Always show mainwindow on startup if on macos show(); #else - QSettings settings; - settings.beginGroup(BehaviourSettingsPage::kSettingsGroup); - StartupBehaviour behaviour = StartupBehaviour(settings.value("startupbehaviour", Startup_Remember).toInt()); - settings.endGroup(); + QSettings s; + s.beginGroup(BehaviourSettingsPage::kSettingsGroup); + StartupBehaviour behaviour = StartupBehaviour(s.value("startupbehaviour", Startup_Remember).toInt()); + s.endGroup(); bool hidden = settings_.value("hidden", false).toBool(); if (hidden && (!QSystemTrayIcon::isSystemTrayAvailable() || !tray_icon_ || !tray_icon_->IsVisible())) { hidden = false; @@ -847,6 +849,10 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co } #endif + bool show_sidebar = settings_.value("show_sidebar", true).toBool(); + ui_->sidebar_layout->setVisible(show_sidebar); + ui_->action_toggle_show_sidebar->setChecked(show_sidebar); + QShortcut *close_window_shortcut = new QShortcut(this); close_window_shortcut->setKey(Qt::CTRL + Qt::Key_W); connect(close_window_shortcut, SIGNAL(activated()), SLOT(SetHiddenInTray())); @@ -871,35 +877,28 @@ MainWindow::~MainWindow() { void MainWindow::ReloadSettings() { - QSettings settings; + QSettings s; #ifndef Q_OS_MACOS - settings.beginGroup(BehaviourSettingsPage::kSettingsGroup); - bool showtrayicon = settings.value("showtrayicon", QSystemTrayIcon::isSystemTrayAvailable()).toBool(); - settings.endGroup(); + s.beginGroup(BehaviourSettingsPage::kSettingsGroup); + bool showtrayicon = s.value("showtrayicon", QSystemTrayIcon::isSystemTrayAvailable()).toBool(); + s.endGroup(); if (tray_icon_) tray_icon_->SetVisible(showtrayicon); if ((!showtrayicon || !QSystemTrayIcon::isSystemTrayAvailable()) && !isVisible()) show(); #endif - settings.beginGroup(BehaviourSettingsPage::kSettingsGroup); - playing_widget_ = settings.value("playing_widget", true).toBool(); + s.beginGroup(BehaviourSettingsPage::kSettingsGroup); + playing_widget_ = s.value("playing_widget", true).toBool(); if (playing_widget_ != ui_->widget_playing->IsEnabled()) TabSwitched(); - doubleclick_addmode_ = BehaviourSettingsPage::AddBehaviour(settings.value("doubleclick_addmode", BehaviourSettingsPage::AddBehaviour_Append).toInt()); - doubleclick_playmode_ = BehaviourSettingsPage::PlayBehaviour(settings.value("doubleclick_playmode", BehaviourSettingsPage::PlayBehaviour_IfStopped).toInt()); - doubleclick_playlist_addmode_ = BehaviourSettingsPage::PlaylistAddBehaviour(settings.value("doubleclick_playlist_addmode", BehaviourSettingsPage::PlaylistAddBehaviour_Play).toInt()); - menu_playmode_ = BehaviourSettingsPage::PlayBehaviour(settings.value("menu_playmode", BehaviourSettingsPage::PlayBehaviour_IfStopped).toInt()); - settings.endGroup(); + doubleclick_addmode_ = BehaviourSettingsPage::AddBehaviour(s.value("doubleclick_addmode", BehaviourSettingsPage::AddBehaviour_Append).toInt()); + doubleclick_playmode_ = BehaviourSettingsPage::PlayBehaviour(s.value("doubleclick_playmode", BehaviourSettingsPage::PlayBehaviour_IfStopped).toInt()); + doubleclick_playlist_addmode_ = BehaviourSettingsPage::PlaylistAddBehaviour(s.value("doubleclick_playlist_addmode", BehaviourSettingsPage::PlaylistAddBehaviour_Play).toInt()); + menu_playmode_ = BehaviourSettingsPage::PlayBehaviour(s.value("menu_playmode", BehaviourSettingsPage::PlayBehaviour_IfStopped).toInt()); + s.endGroup(); - settings.beginGroup(kSettingsGroup); - bool show_sidebar = settings_.value("show_sidebar", true).toBool(); - ui_->sidebar_layout->setVisible(show_sidebar); - ui_->action_toggle_show_sidebar->setChecked(show_sidebar); - album_cover_choice_controller_->search_cover_auto_action()->setChecked(settings.value("search_for_cover_auto", true).toBool()); - settings.endGroup(); - - settings.beginGroup(BackendSettingsPage::kSettingsGroup); - bool volume_control = settings.value("volume_control", true).toBool(); - settings.endGroup(); + s.beginGroup(BackendSettingsPage::kSettingsGroup); + bool volume_control = s.value("volume_control", true).toBool(); + s.endGroup(); if (volume_control != ui_->volume->isEnabled()) { ui_->volume->SetEnabled(volume_control); if (volume_control) { @@ -912,10 +911,12 @@ void MainWindow::ReloadSettings() { } } + album_cover_choice_controller_->search_cover_auto_action()->setChecked(settings_.value("search_for_cover_auto", true).toBool()); + #ifdef HAVE_SUBSONIC - settings.beginGroup(SubsonicSettingsPage::kSettingsGroup); - bool enable_subsonic = settings.value("enabled", false).toBool(); - settings.endGroup(); + s.beginGroup(SubsonicSettingsPage::kSettingsGroup); + bool enable_subsonic = s.value("enabled", false).toBool(); + s.endGroup(); if (enable_subsonic) ui_->tabs->EnableTab(subsonic_view_); else @@ -923,9 +924,9 @@ void MainWindow::ReloadSettings() { #endif #ifdef HAVE_TIDAL - settings.beginGroup(TidalSettingsPage::kSettingsGroup); - bool enable_tidal = settings.value("enabled", false).toBool(); - settings.endGroup(); + s.beginGroup(TidalSettingsPage::kSettingsGroup); + bool enable_tidal = s.value("enabled", false).toBool(); + s.endGroup(); if (enable_tidal) ui_->tabs->EnableTab(tidal_view_); else @@ -977,11 +978,8 @@ void MainWindow::SaveSettings() { ui_->playlist->view()->SaveSettings(); app_->scrobbler()->WriteCache(); - QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("show_sidebar", ui_->action_toggle_show_sidebar->isChecked()); - s.setValue("search_for_cover_auto", album_cover_choice_controller_->search_cover_auto_action()->isChecked()); - s.endGroup(); + settings_.setValue("show_sidebar", ui_->action_toggle_show_sidebar->isChecked()); + settings_.setValue("search_for_cover_auto", album_cover_choice_controller_->search_cover_auto_action()->isChecked()); } @@ -1164,7 +1162,7 @@ void MainWindow::TrackSkipped(PlaylistItemPtr item) { void MainWindow::TabSwitched() { - if (playing_widget_ && (ui_->tabs->tabBar()->tabData(ui_->tabs->currentIndex()).toString().toLower() != "context" || !context_view_->album_enabled())) { + if (playing_widget_ && ui_->sidebar_layout->isVisible() && (ui_->tabs->tabBar()->tabData(ui_->tabs->currentIndex()).toString().toLower() != "context" || !context_view_->album_enabled())) { ui_->widget_playing->SetEnabled(); } else { @@ -1173,6 +1171,18 @@ void MainWindow::TabSwitched() { } +void MainWindow::ToggleSidebar(const bool checked) { + + ui_->sidebar_layout->setVisible(checked); + TabSwitched(); + settings_.setValue("show_sidebar", checked); + +} + +void MainWindow::ToggleSearchCoverAuto(const bool checked) { + settings_.setValue("search_for_cover_auto", checked); +} + void MainWindow::SaveGeometry() { if (!initialised_) return; @@ -1896,7 +1906,7 @@ void MainWindow::EditValue() { void MainWindow::AddFile() { // Last used directory - QString directory =settings_.value("add_media_path", QDir::currentPath()).toString(); + QString directory = settings_.value("add_media_path", QDir::currentPath()).toString(); PlaylistParser parser(app_->collection_backend()); @@ -1923,7 +1933,7 @@ void MainWindow::AddFile() { void MainWindow::AddFolder() { // Last used directory - QString directory =settings_.value("add_folder_path", QDir::currentPath()).toString(); + QString directory = settings_.value("add_folder_path", QDir::currentPath()).toString(); // Show dialog directory = QFileDialog::getExistingDirectory(this, tr("Add folder"), directory); diff --git a/src/core/mainwindow.h b/src/core/mainwindow.h index 4adfe8ca1..0bb4eae4d 100644 --- a/src/core/mainwindow.h +++ b/src/core/mainwindow.h @@ -232,6 +232,8 @@ class MainWindow : public QMainWindow, public PlatformInterface { void OpenSettingsDialogAtPage(SettingsDialog::Page page); void TabSwitched(); + void ToggleSidebar(const bool checked); + void ToggleSearchCoverAuto(const bool checked); void SaveGeometry(); void SavePlaybackStatus(); void LoadPlaybackStatus(); diff --git a/src/settings/contextsettingspage.cpp b/src/settings/contextsettingspage.cpp index af4abeaac..c163c17bf 100644 --- a/src/settings/contextsettingspage.cpp +++ b/src/settings/contextsettingspage.cpp @@ -38,6 +38,7 @@ #include #include "core/iconloader.h" +#include "core/mainwindow.h" #include "settingspage.h" #include "settingsdialog.h" #include "contextsettingspage.h" @@ -46,20 +47,14 @@ const char *ContextSettingsPage::kSettingsGroup = "Context"; const char *ContextSettingsPage::kSettingsTitleFmt = "TitleFmt"; const char *ContextSettingsPage::kSettingsSummaryFmt = "SummaryFmt"; -const char *ContextSettingsPage::kSettingsGroupLabels[ContextSettingsOrder::NELEMS] = { - "Technical Data", - "Engine and Device", - "Albums by Artist", - "Song Lyrics", - "Album", - "Automatically search for song lyrics", -}; + const char *ContextSettingsPage::kSettingsGroupEnable[ContextSettingsOrder::NELEMS] = { - "TechnicalDataEnable", + "AlbumEnable", "EngineAndDeviceEnable", + "TechnicalDataEnable", "AlbumsByArtistEnable", "SongLyricsEnable", - "AlbumEnable", + "SearchCoverEnable", "SearchLyricsEnable", }; @@ -70,12 +65,13 @@ ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) : SettingsPage( ui_->setupUi(this); setWindowIcon(IconLoader::Load("view-choose")); - checkboxes[ContextSettingsOrder::ALBUM] = ui_->checkbox_album; - checkboxes[ContextSettingsOrder::TECHNICAL_DATA] = ui_->checkbox_technical_data; - checkboxes[ContextSettingsOrder::ENGINE_AND_DEVICE] = ui_->checkbox_engine_device; - checkboxes[ContextSettingsOrder::ALBUMS_BY_ARTIST] = ui_->checkbox_albums; - checkboxes[ContextSettingsOrder::SONG_LYRICS] = ui_->checkbox_song_lyrics; - checkboxes[ContextSettingsOrder::SEARCH_LYRICS] = ui_->checkbox_search_lyrics; + checkboxes_[ContextSettingsOrder::ALBUM] = ui_->checkbox_album; + checkboxes_[ContextSettingsOrder::ENGINE_AND_DEVICE] = ui_->checkbox_engine_device; + checkboxes_[ContextSettingsOrder::TECHNICAL_DATA] = ui_->checkbox_technical_data; + checkboxes_[ContextSettingsOrder::ALBUMS_BY_ARTIST] = ui_->checkbox_albums; + checkboxes_[ContextSettingsOrder::SONG_LYRICS] = ui_->checkbox_song_lyrics; + checkboxes_[ContextSettingsOrder::SEARCH_COVER] = ui_->checkbox_search_cover; + checkboxes_[ContextSettingsOrder::SEARCH_LYRICS] = ui_->checkbox_search_lyrics; // Create and populate the helper menus QMenu *menu = new QMenu(this); @@ -133,8 +129,9 @@ void ContextSettingsPage::Load() { s.beginGroup(ContextSettingsPage::kSettingsGroup); ui_->context_custom_text1->setText(s.value(kSettingsTitleFmt, "%title% - %artist%").toString()); ui_->context_custom_text2->setText(s.value(kSettingsSummaryFmt, "%album%").toString()); + for (int i = 0 ; i < ContextSettingsOrder::NELEMS ; ++i) { - checkboxes[i]->setChecked(s.value(kSettingsGroupEnable[i], i != ContextSettingsOrder::ALBUMS_BY_ARTIST).toBool()); + checkboxes_[i]->setChecked(s.value(kSettingsGroupEnable[i], i != ContextSettingsOrder::ALBUMS_BY_ARTIST).toBool()); } // Fonts @@ -153,6 +150,10 @@ void ContextSettingsPage::Load() { s.endGroup(); + s.beginGroup(MainWindow::kSettingsGroup); + ui_->checkbox_search_cover->setChecked(s.value("search_for_cover_auto", true).toBool()); + s.endGroup(); + } void ContextSettingsPage::Save() { @@ -163,7 +164,7 @@ void ContextSettingsPage::Save() { s.setValue(kSettingsTitleFmt, ui_->context_custom_text1->text()); s.setValue(kSettingsSummaryFmt, ui_->context_custom_text2->text()); for (int i = 0; i < ContextSettingsOrder::NELEMS; ++i) { - s.setValue(kSettingsGroupEnable[i], checkboxes[i]->isChecked()); + s.setValue(kSettingsGroupEnable[i], checkboxes_[i]->isChecked()); } s.setValue("font_headline", ui_->font_headline->currentFont().family()); s.setValue("font_normal", ui_->font_normal->currentFont().family()); @@ -171,6 +172,10 @@ void ContextSettingsPage::Save() { s.setValue("font_size_normal", ui_->font_size_normal->value()); s.endGroup(); + s.beginGroup(MainWindow::kSettingsGroup); + s.setValue("search_for_cover_auto", ui_->checkbox_search_cover->isChecked()); + s.endGroup(); + } void ContextSettingsPage::InsertVariableFirstLine(QAction* action) { diff --git a/src/settings/contextsettingspage.h b/src/settings/contextsettingspage.h index 80767ce6f..51d55f87e 100644 --- a/src/settings/contextsettingspage.h +++ b/src/settings/contextsettingspage.h @@ -43,11 +43,12 @@ public: ~ContextSettingsPage(); enum ContextSettingsOrder { - TECHNICAL_DATA, + ALBUM, ENGINE_AND_DEVICE, + TECHNICAL_DATA, ALBUMS_BY_ARTIST, SONG_LYRICS, - ALBUM, + SEARCH_COVER, SEARCH_LYRICS, NELEMS }; @@ -55,7 +56,6 @@ public: static const char *kSettingsGroup; static const char *kSettingsTitleFmt; static const char *kSettingsSummaryFmt; - static const char *kSettingsGroupLabels[ContextSettingsOrder::NELEMS]; static const char *kSettingsGroupEnable[ContextSettingsOrder::NELEMS]; static const qreal kDefaultFontSizeHeadline; @@ -71,7 +71,7 @@ public: private: Ui_ContextSettingsPage *ui_; - QCheckBox *checkboxes[ContextSettingsOrder::NELEMS]; + QCheckBox *checkboxes_[ContextSettingsOrder::NELEMS]; }; #endif // CONTEXTSETTINGSPAGE_H diff --git a/src/settings/contextsettingspage.ui b/src/settings/contextsettingspage.ui index 2edd3d9d2..87f3e57b9 100644 --- a/src/settings/contextsettingspage.ui +++ b/src/settings/contextsettingspage.ui @@ -196,6 +196,16 @@ + + + + Automatically search for album cover + + + true + + +