1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-17 19:18:36 +01:00

Ask before opening url, fix some typos

This commit is contained in:
Jonas Kvinge 2018-12-24 00:15:53 +01:00
parent cbf262be71
commit a20a2dbb71
3 changed files with 34 additions and 18 deletions

View File

@ -13,7 +13,7 @@ Unreleased:
* Fixed key up causing playback to reset
* New improved last.fm and musicbrainz album cover providers
* Removed liblastfm dependency
* Replace sha2 with QCryptographicHash
* Replaced sha2 with QCryptographicHash
Version 0.4.2:

View File

@ -144,10 +144,9 @@ void ListenBrainzScrobbler::Authenticate() {
bool result = QDesktopServices::openUrl(url);
if (!result) {
QMessageBox box(QMessageBox::NoIcon, "Scrobbler Authentication", QString("Please open this URL in your browser: <a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
box.setTextFormat(Qt::RichText);
qLog(Debug) << "Scrobbler authentication URL: " << url.toString();
box.exec();
QMessageBox messagebox(QMessageBox::Information, "ListenBrainz Authentication", QString("Please open this URL in your browser:<br /><a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
messagebox.setTextFormat(Qt::RichText);
messagebox.exec();
}
}
@ -241,7 +240,7 @@ void ListenBrainzScrobbler::AuthenticateReplyFinished(QNetworkReply *reply) {
}
if (!json_obj.contains("access_token") || !json_obj.contains("expires_in") || !json_obj.contains("token_type") || !json_obj.contains("refresh_token")) {
AuthError("Json session object is missing values.");
AuthError("Json access_token, expires_in or token_type is missing.");
return;
}
@ -289,7 +288,7 @@ QByteArray ListenBrainzScrobbler::GetReplyData(QNetworkReply *reply) {
Error(error_reason);
}
else {
// See if there is Json data containing "error" and "error_description" - then use that instead.
// See if there is Json data containing "code" and "error" - then use that instead.
data = reply->readAll();
QJsonParseError error;
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
@ -299,8 +298,8 @@ QByteArray ListenBrainzScrobbler::GetReplyData(QNetworkReply *reply) {
QJsonObject json_obj = json_doc.object();
if (json_obj.contains("code") && json_obj.contains("error")) {
error_code = json_obj["code"].toInt();
QString message = json_obj["error"].toString();
error_reason = QString("%1 (%2)").arg(message).arg(error_code);
QString error_message = json_obj["error"].toString();
error_reason = QString("%1 (%2)").arg(error_message).arg(error_code);
}
else {
error_reason = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
@ -460,7 +459,7 @@ void ListenBrainzScrobbler::ScrobbleRequestFinished(QNetworkReply *reply, QList<
if (json_obj.contains("status")) {
QString status = json_obj["status"].toString();
qLog(Debug) << "MusicBrainz: Received scrobble status:" << status;
qLog(Debug) << "ListenBrainz: Received scrobble status:" << status;
}
cache_->Flush(list);

View File

@ -22,7 +22,9 @@
#include <algorithm>
#include <QtGlobal>
#include <QApplication>
#include <QDesktopServices>
#include <QClipboard>
#include <QVariant>
#include <QByteArray>
#include <QString>
@ -131,12 +133,27 @@ void ScrobblingAPI20::Authenticate() {
url_query.addQueryItem("cb", redirect_url.toString());
url.setQuery(url_query);
bool result = QDesktopServices::openUrl(url);
if (!result) {
QMessageBox box(QMessageBox::NoIcon, "Scrobbler Authentication", QString("Please open this URL in your browser: <a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
box.setTextFormat(Qt::RichText);
qLog(Debug) << "Scrobbler authentication URL: " << url.toString();
box.exec();
QMessageBox messagebox(QMessageBox::Information, QString("%1 Scrobbler Authentication").arg(name_), QString("Open URL in web browser?<br /><a href=\"%1\">%1</a><br />Press \"Save\" to copy the URL to clipboard and manually open it in a web browser.").arg(url.toString()), QMessageBox::Open|QMessageBox::Save|QMessageBox::Cancel);
messagebox.setTextFormat(Qt::RichText);
int result = messagebox.exec();
switch (result) {
case QMessageBox::Open:{
bool openurl_result = QDesktopServices::openUrl(url);
if (openurl_result) {
break;
}
QMessageBox messagebox_error(QMessageBox::Warning, "Scrobbler Authentication", QString("Could not open URL. Please open this URL in your browser: <a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
messagebox_error.setTextFormat(Qt::RichText);
messagebox_error.exec();
}
case QMessageBox::Save:
QApplication::clipboard()->setText(url.toString());
break;
case QMessageBox::Cancel:
AuthError("Authentication was cancelled.");
break;
default:
break;
}
}
@ -466,7 +483,7 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, QList<quint6
int error = json_obj["error"].toInt();
Error(QString("Error: %1: %2").arg(QString::number(error)).arg(error));
}
Error("Json reply from server is missing session.");
Error("Json reply from server is missing scrobbles.");
cache()->ClearSent(list);
return;
}
@ -612,7 +629,7 @@ void ScrobblingAPI20::SingleScrobbleRequestFinished(QNetworkReply *reply, quint6
int error = json_obj["error"].toInt();
Error(QString("Error: %1: %2").arg(QString::number(error)).arg(error));
}
Error("Json reply from server is missing session.");
Error("Json reply from server is missing scrobbles.");
return;
}