mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Fixed RemoteLibrary to load server settings from preferences and updated
RemoteLibrarySettingsLayout. Next up: read/write values from settings.
This commit is contained in:
parent
cf522a5bb9
commit
6cb63c1a6f
@ -38,6 +38,7 @@
|
||||
#include <core/config.h>
|
||||
#include <core/support/Common.h>
|
||||
#include <core/support/Preferences.h>
|
||||
#include <core/support/PreferenceKeys.h>
|
||||
#include <core/library/Indexer.h>
|
||||
#include <core/library/IQuery.h>
|
||||
#include <core/library/LibraryFactory.h>
|
||||
@ -57,10 +58,6 @@ using namespace musik::core::runtime;
|
||||
#define MESSAGE_RECONNECT_SOCKET 5001
|
||||
#define MESSAGE_UPDATE_CONNECTION_STATE 5002
|
||||
|
||||
static const std::string kServerHost = "192.168.1.227";
|
||||
static const std::string kServerPassword = "842655";
|
||||
static const short kServerPort = 7905;
|
||||
|
||||
class NullIndexer: public musik::core::IIndexer {
|
||||
public:
|
||||
virtual ~NullIndexer() override { }
|
||||
@ -101,9 +98,9 @@ RemoteLibrary::RemoteLibrary(std::string name, int id)
|
||||
, exit(false)
|
||||
, messageQueue(nullptr)
|
||||
, wsc(this) {
|
||||
this->wsc.Connect(kServerHost, kServerPort, kServerPassword);
|
||||
this->identifier = std::to_string(id);
|
||||
this->thread = new std::thread(std::bind(&RemoteLibrary::ThreadProc, this));
|
||||
this->ReloadConnectionFromPreferences();
|
||||
}
|
||||
|
||||
RemoteLibrary::~RemoteLibrary() {
|
||||
@ -325,7 +322,7 @@ void RemoteLibrary::ProcessMessage(musik::core::runtime::IMessage &message) {
|
||||
}
|
||||
else if (message.Type() == MESSAGE_RECONNECT_SOCKET) {
|
||||
if (this->wsc.ConnectionState() == Client::State::Disconnected) {
|
||||
this->wsc.Connect(kServerHost, kServerPort, kServerPassword);
|
||||
this->ReloadConnectionFromPreferences();
|
||||
}
|
||||
}
|
||||
else if (message.Type() == MESSAGE_UPDATE_CONNECTION_STATE) {
|
||||
@ -386,17 +383,31 @@ std::string RemoteLibrary::GetTrackUri(musik::core::sdk::ITrack* track, const st
|
||||
}
|
||||
}
|
||||
|
||||
const std::string uri = "http://" + kServerHost + ":7906/audio/id/" + std::to_string(track->GetId());
|
||||
auto prefs = Preferences::ForComponent(core::prefs::components::Settings);
|
||||
auto host = prefs->GetString(core::prefs::keys::RemoteLibraryHostname, "127.0.0.1");
|
||||
auto port = (short) prefs->GetInt(core::prefs::keys::RemoteLibraryHttpPort, 7905);
|
||||
auto password = prefs->GetString(core::prefs::keys::RemoteLibraryPassword, "");
|
||||
|
||||
const std::string uri = "http://" + host + ":" + std::to_string(port) + "/audio/id/" + std::to_string(track->GetId());
|
||||
nlohmann::json path = {
|
||||
{ "uri", uri },
|
||||
{ "type", type },
|
||||
{ "password", kServerPassword }
|
||||
{ "password", password }
|
||||
};
|
||||
|
||||
return "musikcore://remote-track/" + path.dump();
|
||||
}
|
||||
|
||||
/* RemoteLibrary */
|
||||
|
||||
const net::WebSocketClient& RemoteLibrary::WebSocketClient() const {
|
||||
return this->wsc;
|
||||
}
|
||||
|
||||
void RemoteLibrary::ReloadConnectionFromPreferences() {
|
||||
auto prefs = Preferences::ForComponent(core::prefs::components::Settings);
|
||||
auto host = prefs->GetString(core::prefs::keys::RemoteLibraryHostname, "127.0.0.1");
|
||||
auto port = (short) prefs->GetInt(core::prefs::keys::RemoteLibraryWssPort, 7905);
|
||||
auto password = prefs->GetString(core::prefs::keys::RemoteLibraryPassword, "");
|
||||
this->wsc.Connect(host, port, password);
|
||||
}
|
@ -95,6 +95,7 @@ namespace musik { namespace core { namespace library {
|
||||
virtual std::string GetTrackUri(musik::core::sdk::ITrack* track, const std::string& defaultUri) override;
|
||||
|
||||
/* RemoteLibrary */
|
||||
void ReloadConnectionFromPreferences();
|
||||
const musik::core::net::WebSocketClient& WebSocketClient() const;
|
||||
|
||||
private:
|
||||
|
@ -67,7 +67,8 @@ namespace musik { namespace core { namespace prefs {
|
||||
const std::string keys::AuddioApiToken = "AuddioApiToken";
|
||||
const std::string keys::LibraryType = "LibraryType";
|
||||
const std::string keys::RemoteLibraryHostname = "RemoteLibraryHostname";
|
||||
const std::string keys::RemoteLibraryPort = "RemoteLibraryPort";
|
||||
const std::string keys::RemoteLibraryWssPort = "RemoteLibraryWssPort";
|
||||
const std::string keys::RemoteLibraryHttpPort = "RemoteLibraryHttpPort";
|
||||
const std::string keys::RemoteLibraryPassword = "RemoteLibraryPassword";
|
||||
|
||||
} } }
|
||||
|
@ -71,7 +71,8 @@ namespace musik { namespace core { namespace prefs {
|
||||
extern const std::string AuddioApiToken;
|
||||
extern const std::string LibraryType;
|
||||
extern const std::string RemoteLibraryHostname;
|
||||
extern const std::string RemoteLibraryPort;
|
||||
extern const std::string RemoteLibraryWssPort;
|
||||
extern const std::string RemoteLibraryHttpPort;
|
||||
extern const std::string RemoteLibraryPassword;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,8 @@ RemoteLibrarySettingsLayout::~RemoteLibrarySettingsLayout() {
|
||||
void RemoteLibrarySettingsLayout::OnLayout() {
|
||||
size_t labelWidth = longestStringLength({
|
||||
"settings_library_type_remote_hostname",
|
||||
"settings_library_type_remote_port",
|
||||
"settings_library_type_remote_wss_port",
|
||||
"settings_library_type_remote_http_port",
|
||||
"settings_library_type_remote_password"
|
||||
});
|
||||
|
||||
@ -81,10 +82,13 @@ void RemoteLibrarySettingsLayout::OnLayout() {
|
||||
int y = 0;
|
||||
this->hostLabel->MoveAndResize(0, y, labelWidth, 1);
|
||||
this->hostInput->MoveAndResize(labelWidth + 1, y++, inputWidth, 1);
|
||||
this->portLabel->MoveAndResize(0, y, labelWidth, 1);
|
||||
this->portInput->MoveAndResize(labelWidth + 1, y++, 5, 1);
|
||||
this->wssPortLabel->MoveAndResize(0, y, labelWidth, 1);
|
||||
this->wssPortInput->MoveAndResize(labelWidth + 1, y++, 5, 1);
|
||||
this->httpPortLabel->MoveAndResize(0, y, labelWidth, 1);
|
||||
this->httpPortInput->MoveAndResize(labelWidth + 1, y++, 5, 1);
|
||||
this->pwLabel->MoveAndResize(0, y, labelWidth, 1);
|
||||
this->pwInput->MoveAndResize(labelWidth + 1, y++, inputWidth, 1);
|
||||
++y;
|
||||
this->ipv6Cb->MoveAndResize(0, y++, cx, 1);
|
||||
}
|
||||
|
||||
@ -95,9 +99,13 @@ void RemoteLibrarySettingsLayout::InitializeWindows() {
|
||||
this->hostLabel->SetText(_TSTR("settings_library_type_remote_hostname"), text::AlignRight);
|
||||
this->hostInput.reset(new TextInput(TextInput::StyleLine));
|
||||
|
||||
this->portLabel.reset(new TextLabel());
|
||||
this->portLabel->SetText(_TSTR("settings_library_type_remote_port"), text::AlignRight);
|
||||
this->portInput.reset(new TextInput(TextInput::StyleLine));
|
||||
this->wssPortLabel.reset(new TextLabel());
|
||||
this->wssPortLabel->SetText(_TSTR("settings_library_type_remote_wss_port"), text::AlignRight);
|
||||
this->wssPortInput.reset(new TextInput(TextInput::StyleLine));
|
||||
|
||||
this->httpPortLabel.reset(new TextLabel());
|
||||
this->httpPortLabel->SetText(_TSTR("settings_library_type_remote_http_port"), text::AlignRight);
|
||||
this->httpPortInput.reset(new TextInput(TextInput::StyleLine));
|
||||
|
||||
this->pwLabel.reset(new TextLabel());
|
||||
this->pwLabel->SetText(_TSTR("settings_library_type_remote_password"), text::AlignRight);
|
||||
@ -108,15 +116,20 @@ void RemoteLibrarySettingsLayout::InitializeWindows() {
|
||||
|
||||
this->AddWindow(this->hostLabel);
|
||||
this->AddWindow(this->hostInput);
|
||||
this->AddWindow(this->portLabel);
|
||||
this->AddWindow(this->portInput);
|
||||
this->AddWindow(this->hostLabel);
|
||||
this->AddWindow(this->hostInput);
|
||||
this->AddWindow(this->wssPortLabel);
|
||||
this->AddWindow(this->wssPortInput);
|
||||
this->AddWindow(this->httpPortLabel);
|
||||
this->AddWindow(this->httpPortInput);
|
||||
this->AddWindow(this->pwLabel);
|
||||
this->AddWindow(this->pwInput);
|
||||
this->AddWindow(this->ipv6Cb);
|
||||
|
||||
int order = 0;
|
||||
this->hostInput->SetFocusOrder(order++);
|
||||
this->portInput->SetFocusOrder(order++);
|
||||
this->wssPortInput->SetFocusOrder(order++);
|
||||
this->httpPortInput->SetFocusOrder(order++);
|
||||
this->pwInput->SetFocusOrder(order++);
|
||||
this->ipv6Cb->SetFocusOrder(order++);
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ namespace musik { namespace cube {
|
||||
musik::core::ILibraryPtr library;
|
||||
|
||||
std::shared_ptr<musik::core::Preferences> prefs;
|
||||
std::shared_ptr<cursespp::TextLabel> portLabel, hostLabel, pwLabel;
|
||||
std::shared_ptr<cursespp::TextInput> portInput, hostInput, pwInput;
|
||||
std::shared_ptr<cursespp::TextLabel> httpPortLabel, wssPortLabel, hostLabel, pwLabel;
|
||||
std::shared_ptr<cursespp::TextInput> httpPortInput, wssPortInput, hostInput, pwInput;
|
||||
std::shared_ptr<cursespp::Checkbox> ipv6Cb;
|
||||
};
|
||||
} }
|
||||
|
@ -334,7 +334,7 @@ void SettingsLayout::OnLayout() {
|
||||
}
|
||||
else {
|
||||
this->localLibraryLayout->Hide();
|
||||
this->remoteLibraryLayout->MoveAndResize(2, 3, cx - 4, 4);
|
||||
this->remoteLibraryLayout->MoveAndResize(2, 3, cx - 4, 6);
|
||||
libraryLayout = this->remoteLibraryLayout;
|
||||
}
|
||||
libraryLayout->Show();
|
||||
|
@ -109,7 +109,8 @@
|
||||
"settings_library_type_local": "local",
|
||||
"settings_library_type_remote": "remote",
|
||||
"settings_library_type_remote_hostname": "hostname:",
|
||||
"settings_library_type_remote_port": "port:",
|
||||
"settings_library_type_remote_wss_port": "metadata port:",
|
||||
"settings_library_type_remote_http_port": "audio port:",
|
||||
"settings_library_type_remote_password": "password:",
|
||||
"settings_library_type_overlay_title": "library type",
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user