Skip to content

Commit

Permalink
feat: Adds support for passing custom arguments to the spotify client
Browse files Browse the repository at this point in the history
  • Loading branch information
JustABubble committed Nov 4, 2023
1 parent 9fa7eb0 commit ef5c5a5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
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

0 comments on commit ef5c5a5

Please sign in to comment.