diff options
Diffstat (limited to 'src/plugins/General/scrobbler/settingsdialog.cpp')
| -rw-r--r-- | src/plugins/General/scrobbler/settingsdialog.cpp | 101 |
1 files changed, 74 insertions, 27 deletions
diff --git a/src/plugins/General/scrobbler/settingsdialog.cpp b/src/plugins/General/scrobbler/settingsdialog.cpp index dad403c5f..6e3db8e50 100644 --- a/src/plugins/General/scrobbler/settingsdialog.cpp +++ b/src/plugins/General/scrobbler/settingsdialog.cpp @@ -21,23 +21,28 @@ #include <QSettings> #include <QMessageBox> #include <qmmp/qmmp.h> -#include "lastfmscrobbler.h" +#include "scrobbler.h" +#include "defines.h" #include "settingsdialog.h" SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent) { m_ui.setupUi(this); - m_lastfmAuth = new LastfmAuth(this); + m_lastfmAuth = new ScrobblerAuth(SCROBBLER_LASTFM_URL, LASTFM_AUTH_URL, "lastfm", this); + m_librefmAuth = new ScrobblerAuth(SCROBBLER_LIBREFM_URL, LIBREFM_AUTH_URL, "librefm", this); connect(m_lastfmAuth, SIGNAL(tokenRequestFinished(int)), SLOT(processTokenResponse(int))); connect(m_lastfmAuth, SIGNAL(sessionRequestFinished(int)), SLOT(processSessionResponse(int))); connect(m_lastfmAuth, SIGNAL(checkSessionFinished(int)), SLOT(processCheckResponse(int))); + connect(m_librefmAuth, SIGNAL(tokenRequestFinished(int)), SLOT(processTokenResponse(int))); + connect(m_librefmAuth, SIGNAL(sessionRequestFinished(int)), SLOT(processSessionResponse(int))); + connect(m_librefmAuth, SIGNAL(checkSessionFinished(int)), SLOT(processCheckResponse(int))); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Scrobbler"); m_ui.lastfmGroupBox->setChecked(settings.value("use_lastfm", false).toBool()); - m_ui.sessionLineEdit_lastfm->setText(settings.value("lastfm_session").toString()); m_ui.librefmGroupBox->setChecked(settings.value("use_librefm", false).toBool()); - m_ui.userLineEdit_libre->setText(settings.value("librefm_login").toString()); - m_ui.passwordLineEdit_libre->setText(settings.value("librefm_password").toString()); + m_ui.sessionLineEdit_lastfm->setText(settings.value("lastfm_session").toString()); + m_ui.sessionLineEdit_librefm->setText(settings.value("librefm_session").toString()); settings.endGroup(); } @@ -49,10 +54,9 @@ void SettingsDialog::accept() QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Scrobbler"); settings.setValue("use_lastfm", m_ui.lastfmGroupBox->isChecked()); - settings.setValue("lastfm_session",m_ui.sessionLineEdit_lastfm->text()); settings.setValue("use_librefm", m_ui.librefmGroupBox->isChecked()); - settings.setValue("librefm_login",m_ui.userLineEdit_libre->text()); - settings.setValue("librefm_password", m_ui.passwordLineEdit_libre->text()); + settings.setValue("lastfm_session",m_ui.sessionLineEdit_lastfm->text()); + settings.setValue("librefm_session",m_ui.sessionLineEdit_librefm->text()); settings.endGroup(); QDialog::accept(); } @@ -63,24 +67,42 @@ void SettingsDialog::on_newSessionButton_lastfm_clicked() m_lastfmAuth->getToken(); } +void SettingsDialog::on_newSessionButton_librefm_clicked() +{ + m_ui.newSessionButton_librefm->setEnabled(false); + m_librefmAuth->getToken(); +} + void SettingsDialog::processTokenResponse(int error) { - m_ui.newSessionButton_lastfm->setEnabled(true); + if(sender() == m_lastfmAuth) + m_ui.newSessionButton_lastfm->setEnabled(true); + else if(sender() == m_librefmAuth) + m_ui.newSessionButton_librefm->setEnabled(true); switch(error) { - case LastfmAuth::NO_ERROR: + case ScrobblerAuth::NO_ERROR: QMessageBox::information(this, tr("Message"), tr("1. Wait for browser startup") + "\n" + - tr("2. Allow Qmmp to scrobble tracks to your Last.fm account") + "\n" + + tr("2. Allow Qmmp to scrobble tracks to your %1 account") + .arg((sender() == m_lastfmAuth) ? "Last.fm" : "Libre.fm") + "\n" + tr("3. Press \"OK\"")); - m_ui.newSessionButton_lastfm->setEnabled(false); - m_lastfmAuth->getSession(); + if(sender() == m_lastfmAuth) + { + m_ui.newSessionButton_lastfm->setEnabled(false); + m_lastfmAuth->getSession(); + } + else if(sender() == m_librefmAuth) + { + m_ui.newSessionButton_librefm->setEnabled(false); + m_librefmAuth->getSession(); + } break; - case LastfmAuth::NETWORK_ERROR: + case ScrobblerAuth::NETWORK_ERROR: QMessageBox::warning(this, tr("Error"), tr("Network error")); break; - case LastfmAuth::LASTFM_ERROR: + case ScrobblerAuth::LASTFM_ERROR: default: QMessageBox::warning(this, tr("Error"), tr("Unable to register new session")); } @@ -88,22 +110,32 @@ void SettingsDialog::processTokenResponse(int error) void SettingsDialog::processSessionResponse(int error) { - m_ui.newSessionButton_lastfm->setEnabled(true); + if(sender() == m_lastfmAuth) + m_ui.newSessionButton_lastfm->setEnabled(true); + else if(sender() == m_librefmAuth) + m_ui.newSessionButton_librefm->setEnabled(true); switch(error) { - case LastfmAuth::NO_ERROR: + case ScrobblerAuth::NO_ERROR: { QMessageBox::information(this, tr("Message"), tr("New session has been received successfully")); - m_ui.sessionLineEdit_lastfm->setText(m_lastfmAuth->session()); - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - settings.setValue("Scrobbler/lastfm_session",m_ui.sessionLineEdit_lastfm->text()); + if(sender() == m_lastfmAuth) + { + m_ui.sessionLineEdit_lastfm->setText(m_lastfmAuth->session()); + settings.setValue("Scrobbler/lastfm_session",m_ui.sessionLineEdit_lastfm->text()); + } + else if(sender() == m_librefmAuth) + { + m_ui.sessionLineEdit_librefm->setText(m_librefmAuth->session()); + settings.setValue("Scrobbler/librefm_session",m_ui.sessionLineEdit_librefm->text()); + } break; } - case LastfmAuth::NETWORK_ERROR: + case ScrobblerAuth::NETWORK_ERROR: QMessageBox::warning(this, tr("Error"), tr("Network error")); break; - case LastfmAuth::LASTFM_ERROR: + case ScrobblerAuth::LASTFM_ERROR: default: QMessageBox::warning(this, tr("Error"), tr("Unable to register new session")); } @@ -118,21 +150,36 @@ void SettingsDialog::on_checkButton_lastfm_clicked() } } +void SettingsDialog::on_checkButton_librefm_clicked() +{ + if(!m_ui.sessionLineEdit_librefm->text().isEmpty()) + { + m_ui.checkButton_librefm->setEnabled(false); + m_librefmAuth->checkSession(m_ui.sessionLineEdit_librefm->text()); + } +} + void SettingsDialog::processCheckResponse(int error) { - m_ui.checkButton_lastfm->setEnabled(true); + if(sender() == m_lastfmAuth) + m_ui.checkButton_lastfm->setEnabled(true); + else if(sender() == m_librefmAuth) + m_ui.checkButton_librefm->setEnabled(true); switch(error) { - case LastfmAuth::NO_ERROR: + case ScrobblerAuth::NO_ERROR: { QMessageBox::information(this, tr("Message"), tr("Permission granted")); - m_ui.sessionLineEdit_lastfm->setText(m_lastfmAuth->session()); + if(sender() == m_lastfmAuth) + m_ui.sessionLineEdit_lastfm->setText(m_lastfmAuth->session()); + else if(sender() == m_librefmAuth) + m_ui.sessionLineEdit_librefm->setText(m_librefmAuth->session()); break; } - case LastfmAuth::NETWORK_ERROR: + case ScrobblerAuth::NETWORK_ERROR: QMessageBox::warning(this, tr("Error"), tr("Network error")); break; - case LastfmAuth::LASTFM_ERROR: + case ScrobblerAuth::LASTFM_ERROR: default: QMessageBox::warning(this, tr("Error"), tr("Permission denied")); } |
