Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds support for passing custom arguments to the spotify client #232

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/include/lib/settings/spotify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/src/settings/spotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
}

Expand All @@ -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);
}
18 changes: 15 additions & 3 deletions src/settingspage/spotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/settingspage/spotify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace SettingsPage
QLineEdit *sptPath = nullptr;
QLineEdit *sptUsername = nullptr;
QCheckBox *sptDiscovery = nullptr;
QLineEdit *sptAdditionalArguments = nullptr;

QPushButton *startClient = nullptr;
QLabel *clientStatus = nullptr;
Expand Down
6 changes: 6 additions & 0 deletions src/spotifyclient/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down