Switch between library types without restarting the app via

MasterLibrary pimpl-style implementation.
This commit is contained in:
casey langen 2020-10-10 01:50:37 -07:00
parent 3ae8aed29a
commit beef38501a
6 changed files with 23 additions and 7 deletions

View File

@ -121,6 +121,8 @@ void MasterLibrary::LoadDefaultLibrary() {
this->wrappedLibrary->QueryCompleted.connect(this, &MasterLibrary::OnQueryCompleted);
this->wrappedLibrary->ConnectionStateChanged.connect(this, &MasterLibrary::OnConectionStateChanged);
}
this->LibraryChanged();
}
}

View File

@ -50,6 +50,8 @@ namespace musik { namespace core { namespace library {
class MasterLibrary: public ILibrary, public sigslot::has_slots<> {
public:
sigslot::signal0<> LibraryChanged;
MasterLibrary();
virtual ~MasterLibrary();

View File

@ -111,6 +111,7 @@ MainLayout::MainLayout(
this->prefs = Preferences::ForComponent("settings");
library->ConnectionStateChanged.connect(this, &MainLayout::OnLibraryConnectionStateChanged);
library->LibraryChanged.connect(this, &MainLayout::OnLibraryChanged);
library->Indexer()->Started.connect(this, &MainLayout::OnIndexerStarted);
library->Indexer()->Finished.connect(this, &MainLayout::OnIndexerFinished);
library->Indexer()->Progress.connect(this, &MainLayout::OnIndexerProgress);
@ -302,6 +303,12 @@ void MainLayout::OnLibraryConnectionStateChanged(ILibrary::ConnectionState state
}
}
void MainLayout::OnLibraryChanged() {
this->playback.Stop();
this->libraryLayout.reset(new LibraryLayout(playback, library));
this->Layout();
}
void MainLayout::OnIndexerStarted() {
this->Post(message::IndexerStarted);
}

View File

@ -75,6 +75,7 @@ namespace musik {
void OnIndexerFinished(int count);
void OnTrackChanged(size_t index, musik::core::TrackPtr track);
void OnLibraryConnectionStateChanged(musik::core::ILibrary::ConnectionState state);
void OnLibraryChanged();
bool IsLibraryConnected();

View File

@ -161,7 +161,7 @@ static void setTransportType(TransportType type) {
SettingsLayout::SettingsLayout(
cursespp::App& app,
musik::core::ILibraryPtr library,
MasterLibraryPtr library,
musik::core::audio::PlaybackService& playback)
: LayoutBase()
, app(app)
@ -215,7 +215,10 @@ void SettingsLayout::OnCheckboxChanged(cursespp::Checkbox* cb, bool checked) {
}
void SettingsLayout::OnLibraryTypeDropdownActivated(cursespp::TextLabel* label) {
SettingsOverlays::ShowLibraryTypeOverlay([this]() { this->LoadPreferences(); });
SettingsOverlays::ShowLibraryTypeOverlay([this]() {
this->LoadPreferences();
this->library->LoadDefaultLibrary();
});
}
void SettingsLayout::OnLocaleDropdownActivate(cursespp::TextLabel* label) {

View File

@ -48,13 +48,12 @@
#include <core/audio/PlaybackService.h>
#include <core/audio/MasterTransport.h>
#include <core/library/MasterLibrary.h>
#include <core/support/Preferences.h>
#include <app/window/TrackListView.h>
#include <app/model/DirectoryAdapter.h>
#include <core/library/ILibrary.h>
#include <core/support/Preferences.h>
#include <sigslot/sigslot.h>
#include "LocalLibrarySettingsLayout.h"
@ -66,9 +65,11 @@ namespace musik { namespace cube {
public sigslot::has_slots<>
{
public:
using MasterLibraryPtr = std::shared_ptr<musik::core::library::MasterLibrary>;
SettingsLayout(
cursespp::App& app,
musik::core::ILibraryPtr library,
MasterLibraryPtr library,
musik::core::audio::PlaybackService& playback);
virtual ~SettingsLayout();
@ -106,7 +107,7 @@ namespace musik { namespace cube {
void OnAdvancedSettingsActivate(cursespp::TextLabel* label);
cursespp::App& app;
musik::core::ILibraryPtr library;
MasterLibraryPtr library;
musik::core::IIndexer* indexer;
musik::core::audio::PlaybackService& playback;