Add debug logging

This commit is contained in:
craig.p.drummond
2013-06-10 16:34:22 +00:00
parent 20217d1353
commit 58507f551b
17 changed files with 183 additions and 35 deletions

View File

@@ -58,6 +58,7 @@
37. For Qt4 linux builds, use system QJson if found.
38. Remove amazon cover fetching - required API key that Cantata never really
had.
39. Add debug logging. Please see README for details.
1.0.3
-----

27
README
View File

@@ -401,6 +401,33 @@ The Cantata source folder contains the following structure:
widgets - Widgets that are probably Cantata specific.
Debug Logging
=============
Cantata contains some debug logging, that might help to diagnose certain
issues. To enable this, you must set an environment variable before starting
Cantata. Therefore, its porobably better to start Cantata from the commandline.
The following debug values may be used:
MPD communications 1
Covers 2
Wikipedia context info 4
Last.fm context info 8
Combined context info 16
Context widget 32
Context backdrop 64
These values may be combined to enble multipe output. e.g. to enable MPD and
covers logging:
CANTATA_DEBUG=3 cantata
for just covers logging:
CANTATA_DEBUG=1 cantata
Credits
=======

View File

@@ -29,11 +29,13 @@
#include <QDebug>
#include <stdlib.h>
//#define DBUG qWarning() << metaObject()->className() << __FUNCTION__
#ifndef DBUG
#define DBUG qDebug()
#endif
#include <QDebug>
static bool debugEnabled=false;
#define DBUG if (debugEnabled) qWarning() << metaObject()->className() << __FUNCTION__
void BackdropCreator::enableDebug()
{
debugEnabled=true;
}
BackdropCreator::BackdropCreator()
: QObject(0)

View File

@@ -35,6 +35,8 @@ class BackdropCreator : public QObject
{
Q_OBJECT
public:
static void enableDebug();
BackdropCreator();
virtual ~BackdropCreator();

View File

@@ -48,13 +48,14 @@
#include <QComboBox>
#include <QStackedWidget>
#include <QAction>
#include <QDebug>
//#define DBUG qWarning() << metaObject()->className() << __FUNCTION__
#ifndef DBUG
#define DBUG qDebug()
#endif
static bool debugEnabled=false;
#define DBUG if (debugEnabled) qWarning() << metaObject()->className() << __FUNCTION__
void ContextWidget::enableDebug()
{
debugEnabled=true;
}
const QLatin1String ContextWidget::constApiKey(0); // API key required
const QLatin1String ContextWidget::constCacheDir("backdrops/");
@@ -527,6 +528,7 @@ void ContextWidget::getBackdrop()
url.setQuery(q);
#endif
job=NetworkAccessManager::self()->get(url, 5000);
DBUG << url.toString();
connect(job, SIGNAL(finished()), this, SLOT(searchResponse()));
}
@@ -537,6 +539,8 @@ void ContextWidget::searchResponse()
return;
}
DBUG << "status" << reply->error() << reply->errorString();
QString id;
if (QNetworkReply::NoError==reply->error()) {
QXmlStreamReader xml(reply);
@@ -581,7 +585,13 @@ void ContextWidget::searchResponse()
void ContextWidget::downloadResponse()
{
QNetworkReply *reply = getReply(sender());
if (!reply || QNetworkReply::NoError!=reply->error()) {
if (!reply) {
return;
}
DBUG << "status" << reply->error() << reply->errorString();
if (QNetworkReply::NoError!=reply->error()) {
return;
}

View File

@@ -56,6 +56,8 @@ class ContextWidget : public QWidget
Q_PROPERTY(float fade READ fade WRITE setFade)
public:
static void enableDebug();
static const QLatin1String constCacheDir;
static const QLatin1String constApiKey;

View File

@@ -31,13 +31,14 @@
#endif
#include <QXmlStreamReader>
#include <QRegExp>
#include <QDebug>
//#define DBUG qWarning() << metaObject()->className() << __FUNCTION__
#ifndef DBUG
#define DBUG qDebug()
#endif
static bool debugEnabled=false;
#define DBUG if (debugEnabled) qWarning() << metaObject()->className() << __FUNCTION__
void LastFmEngine::enableDebug()
{
debugEnabled=true;
}
const QLatin1String LastFmEngine::constLang("lastfm");
const QLatin1String LastFmEngine::constLinkPlaceholder("XXX_CONTEXT_READ_MORE_ON_LASTFM_XXX");

View File

@@ -35,6 +35,8 @@ public:
static const QLatin1String constLang;
static const QLatin1String constLinkPlaceholder;
static void enableDebug();
LastFmEngine(QObject *p);
QStringList getLangs() const;

View File

@@ -24,13 +24,14 @@
#include "metaengine.h"
#include "wikipediaengine.h"
#include "lastfmengine.h"
#include <QDebug>
//#define DBUG qWarning() << metaObject()->className() << __FUNCTION__
#ifndef DBUG
#define DBUG qDebug()
#endif
static bool debugEnabled=false;
#define DBUG if (debugEnabled) qWarning() << metaObject()->className() << __FUNCTION__
void MetaEngine::enableDebug()
{
debugEnabled=true;
}
static const QLatin1String constBlankResp("-");

View File

@@ -47,6 +47,8 @@ class MetaEngine : public ContextEngine
};
public:
static void enableDebug();
MetaEngine(QObject *p);
QStringList getLangs() const;

View File

@@ -31,13 +31,14 @@
#endif
#include <QXmlStreamReader>
#include <QRegExp>
#include <QDebug>
//#define DBUG qWarning() << metaObject()->className() << __FUNCTION__
#ifndef DBUG
#define DBUG qDebug()
#endif
static bool debugEnabled=false;
#define DBUG if (debugEnabled) qWarning() << metaObject()->className() << __FUNCTION__
void WikipediaEngine::enableDebug()
{
debugEnabled=true;
}
static const char * constModeProperty="mode";
static const char * constRedirectsProperty="redirects";

View File

@@ -32,6 +32,8 @@ class WikipediaEngine : public ContextEngine
Q_OBJECT
public:
static void enableDebug();
WikipediaEngine(QObject *p);
static const QLatin1String constReadMorePlaceholder;

View File

@@ -60,6 +60,15 @@
K_GLOBAL_STATIC(Covers, instance)
#endif
#include <QDebug>
static bool debugEnabled=false;
#define DBUG_CLASS(CLASS) if (debugEnabled) qWarning() << CLASS << __FUNCTION__
#define DBUG DBUG_CLASS(metaObject()->className())
void Covers::enableDebug()
{
debugEnabled=true;
}
const QLatin1String Covers::constLastFmApiKey("11172d35eb8cc2fd33250a9e45a2d486");
const QLatin1String Covers::constCoverDir("covers/");
const QLatin1String Covers::constCddaCoverDir("cdda/");
@@ -383,6 +392,7 @@ void CoverDownloader::stop()
void CoverDownloader::download(const Song &song)
{
DBUG << song.file << song.artist << song.albumartist << song.album;
bool isArtistImage=song.isArtistImageRequest();
if (jobs.end()!=findJob(Job(song, QString(), isArtistImage))) {
@@ -419,6 +429,7 @@ void CoverDownloader::downloadOnlineImage(Job &job)
QNetworkReply *j=manager->get(QNetworkRequest(QUrl(job.song.name)));
connect(j, SIGNAL(finished()), this, SLOT(jobFinished()));
jobs.insert(j, job);
DBUG << job.song.name;
}
bool CoverDownloader::downloadViaHttp(Job &job, JobType type)
@@ -451,6 +462,7 @@ bool CoverDownloader::downloadViaHttp(Job &job, JobType type)
QNetworkReply *j=manager->get(QNetworkRequest(u));
connect(j, SIGNAL(finished()), this, SLOT(jobFinished()));
jobs.insert(j, job);
DBUG << u.toString();
return true;
}
@@ -478,6 +490,7 @@ void CoverDownloader::downloadViaLastFm(Job &job)
connect(j, SIGNAL(finished()), this, SLOT(lastFmCallFinished()));
job.type=JobLastFm;
jobs.insert(j, job);
DBUG << url.toString();
}
void CoverDownloader::lastFmCallFinished()
@@ -487,6 +500,8 @@ void CoverDownloader::lastFmCallFinished()
return;
}
DBUG << "status" << reply->error() << reply->errorString();
QHash<QNetworkReply *, Job>::Iterator it(jobs.find(reply));
QHash<QNetworkReply *, Job>::Iterator end(jobs.end());
@@ -537,14 +552,18 @@ void CoverDownloader::lastFmCallFinished()
#endif
QNetworkReply *j=manager->get(QNetworkRequest(u));
connect(j, SIGNAL(finished()), this, SLOT(jobFinished()));
DBUG << "download" << u.toString();
jobs.insert(j, job);
} else {
if (job.isArtist) {
DBUG << "Failed to download artist image";
emit artistImage(job.song, QImage(), QString());
} else {
#if defined Q_OS_WIN
DBUG << "Failed to download cover image";
emit cover(job.song, QImage(), QString());
#else
DBUG << "Failed to download cover image - try other app";
Covers::Image img=otherAppCover(job);
emit cover(job.song, img.img, img.fileName);
#endif
@@ -561,6 +580,8 @@ void CoverDownloader::jobFinished()
return;
}
DBUG << "status" << reply->error() << reply->errorString();
QHash<QNetworkReply *, Job>::Iterator it(jobs.find(reply));
QHash<QNetworkReply *, Job>::Iterator end(jobs.end());
@@ -594,8 +615,10 @@ void CoverDownloader::jobFinished()
}
if (job.isArtist) {
DBUG << "artist image, null?" << img.img.isNull();
emit artistImage(job.song, img.img, img.fileName);
} else if (img.img.isNull()) {
DBUG << "failed to download cover image";
#if defined Q_OS_WIN
emit cover(job.song, QImage(), QString());
#else
@@ -603,6 +626,7 @@ void CoverDownloader::jobFinished()
emit cover(job.song, img.img, img.fileName);
#endif
} else {
DBUG << "got cover image" << img.fileName;
emit cover(job.song, img.img, img.fileName);
}
}
@@ -622,6 +646,7 @@ QString CoverDownloader::saveImg(const Job &job, const QImage &img, const QByteA
if (!dir.isEmpty()) {
savedName=save(mimeType, extension, dir+job.song.file.mid(7), img, raw);
if (!savedName.isEmpty()) {
DBUG << job.song.file << savedName;
return savedName;
}
}
@@ -632,6 +657,7 @@ QString CoverDownloader::saveImg(const Job &job, const QImage &img, const QByteA
// ONLINE: Cache dir is saved in Song.title
savedName=save(mimeType, extension, Utils::cacheDir(job.song.title)+Covers::encodeName(job.isArtist ? job.song.albumartist : (job.song.albumartist+" - "+job.song.album)), img, raw);
if (!savedName.isEmpty()) {
DBUG << job.song.file << savedName;
return savedName;
}
} else if (job.isArtist) {
@@ -642,6 +668,7 @@ QString CoverDownloader::saveImg(const Job &job, const QImage &img, const QByteA
d.cdUp();
savedName=save(mimeType, extension, d.absolutePath()+'/'+Covers::artistFileName(job.song), img, raw);
if (!savedName.isEmpty()) {
DBUG << job.song.file << savedName;
return savedName;
}
}
@@ -651,6 +678,7 @@ QString CoverDownloader::saveImg(const Job &job, const QImage &img, const QByteA
if (!dir.isEmpty()) {
savedName=save(mimeType, extension, dir+Covers::encodeName(job.song.albumartist), img, raw);
if (!savedName.isEmpty()) {
DBUG << job.song.file << savedName;
return savedName;
}
}
@@ -660,6 +688,7 @@ QString CoverDownloader::saveImg(const Job &job, const QImage &img, const QByteA
QString coverName=Covers::albumFileName(job.song);
savedName=save(mimeType, extension, job.dir+coverName, img, raw);
if (!savedName.isEmpty()) {
DBUG << job.song.file << savedName;
return savedName;
}
}
@@ -669,6 +698,7 @@ QString CoverDownloader::saveImg(const Job &job, const QImage &img, const QByteA
if (!dir.isEmpty()) {
savedName=save(mimeType, extension, dir+Covers::encodeName(job.song.album), img, raw);
if (!savedName.isEmpty()) {
DBUG << job.song.file << savedName;
return savedName;
}
}
@@ -736,6 +766,7 @@ void CoverLocator::locate()
}
QList<LocatedCover> covers;
foreach (const Song &s, toDo) {
DBUG << s.file << s.artist << s.albumartist << s.album;
Covers::Image img=Covers::locateImage(s);
covers.append(LocatedCover(s, img.img, img.fileName));
}
@@ -869,12 +900,14 @@ Covers::Image Covers::findImage(const Song &song, bool emitResult)
Covers::Image Covers::locateImage(const Song &song)
{
DBUG_CLASS("Covers") << song.file << song.artist << song.albumartist << song.album;
bool isArtistImage=song.isArtistImageRequest();
QString prevFileName=Covers::self()->getFilename(song, isArtistImage);
if (!prevFileName.isEmpty()) {
QImage img(prevFileName);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Found previous" << prevFileName;
return Image(img, prevFileName);
}
}
@@ -889,10 +922,12 @@ Covers::Image Covers::locateImage(const Song &song)
QImage img(baseName+ext);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got online from cache" << QString(baseName+ext);
return Image(img, baseName+ext);
}
}
}
DBUG_CLASS("Covers") << "Online image not in cache";
return Image(QImage(), QString());
}
@@ -922,6 +957,7 @@ Covers::Image Covers::locateImage(const Song &song)
QImage img(dirName+fileName);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got artist image" << QString(dirName+fileName);
return Image(img, dirName+fileName);
}
}
@@ -954,6 +990,7 @@ Covers::Image Covers::locateImage(const Song &song)
QImage img(dirName+fileName);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got cover image" << QString(dirName+fileName);
return Image(img, dirName+fileName);
}
}
@@ -964,6 +1001,7 @@ Covers::Image Covers::locateImage(const Song &song)
if (QFile::exists(fileName)) {
QImage img(Tags::readImage(fileName));
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got cover image from tag";
return Image(img, QString());
}
}
@@ -974,6 +1012,7 @@ Covers::Image Covers::locateImage(const Song &song)
QImage img(dirName+fileName);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got cover image" << QString(dirName+fileName);
return Image(img, dirName+fileName);
}
}
@@ -988,6 +1027,7 @@ Covers::Image Covers::locateImage(const Song &song)
if (QFile::exists(dir+artist+ext)) {
QImage img(dir+artist+ext);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got artist image" << QString(dir+artist+ext);
return Image(img, dir+artist+ext);
}
}
@@ -1000,6 +1040,7 @@ Covers::Image Covers::locateImage(const Song &song)
if (QFile::exists(dir+album+ext)) {
QImage img(dir+album+ext);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got cover image" << QString(dir+album+ext);
return Image(img, dir+album+ext);
}
}
@@ -1011,16 +1052,19 @@ Covers::Image Covers::locateImage(const Song &song)
// See if amarok, or clementine, has it...
Image app=otherAppCover(job);
if (!app.img.isNull()) {
DBUG_CLASS("Covers") << "Got cover image (other app)" << app.fileName;
return app;
}
#endif
}
DBUG_CLASS("Covers") << "Failed to locate image";
return Image(QImage(), QString());
}
Covers::Image Covers::requestImage(const Song &song)
{
DBUG << song.file << song.artist << song.albumartist << song.album;
if (retrieved>=constMaxPerLoopIteration) {
emit locate(song);
return Covers::Image();

View File

@@ -154,6 +154,8 @@ public:
QString fileName;
};
static void enableDebug();
static const QSize constMaxSize;
static const QLatin1String constLastFmApiKey;
static const QLatin1String constCoverDir;

View File

@@ -40,6 +40,15 @@
#include "initialsettingswizard.h"
#include "mainwindow.h"
// To enable debug...
#include "mpdconnection.h"
#include "covers.h"
#include "wikipediaengine.h"
#include "lastfmengine.h"
#include "metaengine.h"
#include "coverwidget.h"
#include "backdropcreator.h"
#ifndef ENABLE_KDE_SUPPORT
// Taken from Clementine!
//
@@ -84,8 +93,44 @@ static void loadTranslation(const QString &prefix, const QString &path, const QS
}
#endif
enum Debug {
Dbg_Mpd = 0x0001,
Dbg_Covers = 0x0002,
Dbg_Context_Wikipedia = 0x0004,
Dbg_Context_LastFm = 0x0008,
Dbg_Context_Meta = 0x0010,
Dbg_Context_Widget = 0x0020,
Dbg_Context_Backdrop = 0x0040
};
int main(int argc, char *argv[])
{
QString debug=qgetenv("CANTATA_DEBUG");
if (!debug.isEmpty()) {
int dbg=debug.toInt();
if (dbg&Dbg_Mpd) {
MPDConnection::enableDebug();
}
if (dbg&Dbg_Covers) {
Covers::enableDebug();
}
if (dbg&Dbg_Context_Wikipedia) {
WikipediaEngine::enableDebug();
}
if (dbg&Dbg_Context_LastFm) {
LastFmEngine::enableDebug();
}
if (dbg&Dbg_Context_Meta) {
MetaEngine::enableDebug();
}
if (dbg&Dbg_Context_Widget) {
ContextWidget::enableDebug();
}
if (dbg&Dbg_Context_Backdrop) {
BackdropCreator::enableDebug();
}
}
#ifdef ENABLE_KDE_SUPPORT
KAboutData aboutData(PACKAGE_NAME, 0,
ki18n("Cantata"), PACKAGE_VERSION_STRING,

View File

@@ -32,16 +32,18 @@
#include <KDE/KGlobal>
#endif
#include <QApplication>
#include <QDebug>
#include <QStringList>
#include <QTimer>
#include "thread.h"
#include "settings.h"
//#define DBUG qWarning() << "MPDConnection" << QThread::currentThreadId()
#ifndef DBUG
#define DBUG qDebug()
#endif
#include <QDebug>
static bool debugEnabled=false;
#define DBUG if (debugEnabled) qWarning() << "MPDConnection" << QThread::currentThreadId()
void MPDConnection::enableDebug()
{
debugEnabled=true;
}
static const int constSocketCommsTimeout=2000;
static const int constMaxReadAttempts=4;

View File

@@ -166,6 +166,8 @@ public:
QByteArray data;
};
static void enableDebug();
MPDConnection();
~MPDConnection();