From 3ce682a81fd6b64053159a3913239ed63c09b06a Mon Sep 17 00:00:00 2001 From: Matthew McElroy Date: Fri, 3 Nov 2023 20:19:20 +1000 Subject: [PATCH] feat: Adds support for passing custom arguments to the spotify client --- lib/include/lib/settings/spotify.hpp | 5 +++++ lib/src/settings/spotify.cpp | 2 ++ src/settingspage/spotify.cpp | 18 +++++++++++++++--- src/settingspage/spotify.hpp | 1 + src/spotifyclient/runner.cpp | 6 ++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/include/lib/settings/spotify.hpp b/lib/include/lib/settings/spotify.hpp index fe44e1cb..2daa0fa4 100644 --- a/lib/include/lib/settings/spotify.hpp +++ b/lib/include/lib/settings/spotify.hpp @@ -30,6 +30,11 @@ namespace lib */ std::string username; + /** + * Additional arugments to pass to the spotify client + */ + std::string additional_arguments; + /** * Always start Spotify client on application start */ diff --git a/lib/src/settings/spotify.cpp b/lib/src/settings/spotify.cpp index 94c5b310..fc990e18 100644 --- a/lib/src/settings/spotify.cpp +++ b/lib/src/settings/spotify.cpp @@ -14,6 +14,7 @@ void lib::setting::to_json(nlohmann::json &j, const spotify &s) {"start_client", s.start_client}, {"username", s.username}, {"volume", s.volume}, + {"additional_arguments", s.additional_arguments}, }; } @@ -35,4 +36,5 @@ void lib::setting::from_json(const nlohmann::json &j, spotify &s) lib::json::get(j, "start_client", s.start_client); lib::json::get(j, "username", s.username); lib::json::get(j, "volume", s.volume); + lib::json::get(j, "additional_arguments", s.additional_arguments); } diff --git a/src/settingspage/spotify.cpp b/src/settingspage/spotify.cpp index 68e2b085..103dd421 100644 --- a/src/settingspage/spotify.cpp +++ b/src/settingspage/spotify.cpp @@ -228,13 +228,20 @@ auto SettingsPage::Spotify::config() -> QWidget * sptDeviceType->addItem(QStringLiteral("Default")); sptLayout->addWidget(sptDeviceType, 3, 1); + // Additional arguments + auto *additionalArgumentsLabel = new QLabel(QStringLiteral("Additional arguments"), sptGroup); + sptLayout->addWidget(additionalArgumentsLabel, 4, 0); + + sptAdditionalArguments = new QLineEdit(QString::fromStdString(settings.spotify.additional_arguments), sptGroup); + sptLayout->addWidget(sptAdditionalArguments, 4, 1); + // Clear password #ifdef USE_KEYCHAIN auto *clearPasswordText = new QLabel(QStringLiteral("Clear saved password")); - sptLayout->addWidget(clearPasswordText, 4, 0); + sptLayout->addWidget(clearPasswordText, 5, 0); auto *clearPassword = new QPushButton(QStringLiteral("Clear"), this); - sptLayout->addWidget(clearPassword, 4, 1, Qt::AlignTrailing); + sptLayout->addWidget(clearPassword, 5, 1, Qt::AlignTrailing); QAbstractButton::connect(clearPassword, &QAbstractButton::clicked, this, &SettingsPage::Spotify::onClearPassword); @@ -244,7 +251,7 @@ auto SettingsPage::Spotify::config() -> QWidget * sptDiscovery = new QCheckBox("Enable discovery"); sptDiscovery->setToolTip("Enable discovery mode (librespot only)"); sptDiscovery->setChecked(!settings.spotify.disable_discovery); - sptLayout->addWidget(sptDiscovery, 5, 0); + sptLayout->addWidget(sptDiscovery, 6, 0); return Widget::layoutToWidget(content, this); } @@ -360,6 +367,11 @@ auto SettingsPage::Spotify::save() -> bool : lib::audio_quality::very_high; } + if (sptAdditionalArguments != nullptr) + { + settings.spotify.additional_arguments = sptAdditionalArguments->text().toStdString(); + } + if (sptAlways != nullptr) { settings.spotify.always_start = sptAlways->isChecked(); diff --git a/src/settingspage/spotify.hpp b/src/settingspage/spotify.hpp index bfdbc5d7..2fc628f7 100644 --- a/src/settingspage/spotify.hpp +++ b/src/settingspage/spotify.hpp @@ -37,6 +37,7 @@ namespace SettingsPage QLineEdit *sptPath = nullptr; QLineEdit *sptUsername = nullptr; QCheckBox *sptDiscovery = nullptr; + QLineEdit *sptAdditionalArguments = nullptr; QPushButton *startClient = nullptr; QLabel *clientStatus = nullptr; diff --git a/src/spotifyclient/runner.cpp b/src/spotifyclient/runner.cpp index 8f4ad26c..6bef9b0c 100644 --- a/src/spotifyclient/runner.cpp +++ b/src/spotifyclient/runner.cpp @@ -156,6 +156,12 @@ void SpotifyClient::Runner::start(const QString &username, const QString &passwo } } + auto additional_arguments = QString::fromStdString(settings.spotify.additional_arguments); + if (!additional_arguments.isEmpty()) + { + arguments.append(additional_arguments.split(' ')); + } + QProcess::connect(process, &QProcess::readyReadStandardOutput, this, &Runner::onReadyReadOutput);