2012-06-28 18:41:51 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2012-2013, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-06-28 18:41:51 +02:00
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-06-28 18:41:51 +02:00
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-06-28 18:41:51 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lastfmcompat.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
|
2012-06-28 18:41:51 +02:00
|
|
|
#include "core/logging.h"
|
|
|
|
|
|
|
|
namespace lastfm {
|
|
|
|
namespace compat {
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBLASTFM1
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
XmlQuery EmptyXmlQuery() { return XmlQuery(); }
|
2012-06-28 18:41:51 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool ParseQuery(const QByteArray& data, XmlQuery* query,
|
|
|
|
bool* connection_problems) {
|
2012-06-28 18:41:51 +02:00
|
|
|
const bool ret = query->parse(data);
|
|
|
|
|
|
|
|
if (connection_problems) {
|
2020-09-18 16:15:19 +02:00
|
|
|
*connection_problems = !ret && query->parseError().enumValue() ==
|
|
|
|
lastfm::ws::MalformedResponse;
|
2012-06-28 18:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseUserList(QNetworkReply* reply, QList<User>* users) {
|
|
|
|
lastfm::XmlQuery lfm;
|
|
|
|
if (!lfm.parse(reply->readAll())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*users = lastfm::UserList(lfm).users();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
uint ScrobbleTimeMin() { return lastfm::ScrobblePoint::scrobbleTimeMin(); }
|
2012-06-28 18:41:51 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#else // HAVE_LIBLASTFM1
|
2012-06-28 18:41:51 +02:00
|
|
|
|
|
|
|
XmlQuery EmptyXmlQuery() {
|
|
|
|
QByteArray dummy;
|
|
|
|
return XmlQuery(dummy);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool ParseQuery(const QByteArray& data, XmlQuery* query,
|
|
|
|
bool* connection_problems) {
|
2012-06-28 18:41:51 +02:00
|
|
|
try {
|
|
|
|
*query = lastfm::XmlQuery(data);
|
2014-02-07 16:34:20 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
if (lastfm::ws::last_parse_error != lastfm::ws::NoError) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // Q_OS_WIN32
|
2014-12-17 19:02:21 +01:00
|
|
|
} catch (lastfm::ws::ParseError e) {
|
2012-06-28 18:41:51 +02:00
|
|
|
qLog(Error) << "Last.fm parse error: " << e.enumValue();
|
|
|
|
if (connection_problems) {
|
|
|
|
*connection_problems = e.enumValue() == lastfm::ws::MalformedResponse;
|
|
|
|
}
|
|
|
|
return false;
|
2014-12-17 19:02:21 +01:00
|
|
|
} catch (std::runtime_error& e) {
|
2012-06-28 18:41:51 +02:00
|
|
|
qLog(Error) << e.what();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connection_problems) {
|
|
|
|
*connection_problems = false;
|
|
|
|
}
|
|
|
|
|
2013-02-05 14:12:39 +01:00
|
|
|
// Check for app errors.
|
|
|
|
if (QDomElement(*query).attribute("status") == "failed") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-28 18:41:51 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseUserList(QNetworkReply* reply, QList<User>* users) {
|
|
|
|
try {
|
|
|
|
*users = lastfm::User::list(reply);
|
2014-02-07 16:34:20 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
if (lastfm::ws::last_parse_error != lastfm::ws::NoError) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // Q_OS_WIN32
|
2014-12-17 19:02:21 +01:00
|
|
|
} catch (std::runtime_error& e) {
|
2012-06-28 18:41:51 +02:00
|
|
|
qLog(Error) << e.what();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
uint ScrobbleTimeMin() { return ScrobblePoint::kScrobbleMinLength; }
|
2012-06-28 18:41:51 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // HAVE_LIBLASTFM1
|
2014-12-17 19:02:21 +01:00
|
|
|
} // namespace compat
|
|
|
|
} // namespace lastfm
|