Add debugging logging categories

This commit is contained in:
Bart De Vries 2021-06-05 20:12:42 +02:00
parent 8437a44a7b
commit 2ed33aa750
8 changed files with 103 additions and 52 deletions

View File

@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
# SPDX-License-Identifier: BSD-2-Clause
set(SRCS_base
main.cpp
feedsmodel.cpp
@ -32,6 +31,55 @@ ecm_qt_declare_logging_category(SRCS_base
DEFAULT_SEVERITY Info
)
ecm_qt_declare_logging_category(SRCS_base
HEADER "datamanagerlogging.h"
IDENTIFIER "kastsDataManager"
CATEGORY_NAME "org.kde.kasts.datamanager"
DEFAULT_SEVERITY Info
)
ecm_qt_declare_logging_category(SRCS_base
HEADER "downloadprogressmodellogging.h"
IDENTIFIER "kastsDownloadProgressModel"
CATEGORY_NAME "org.kde.kasts.downloadprogressmodel"
DEFAULT_SEVERITY Info
)
ecm_qt_declare_logging_category(SRCS_base
HEADER "enclosurelogging.h"
IDENTIFIER "kastsEnclosure"
CATEGORY_NAME "org.kde.kasts.enclosure"
DEFAULT_SEVERITY Info
)
ecm_qt_declare_logging_category(SRCS_base
HEADER "feedlogging.h"
IDENTIFIER "kastsFeed"
CATEGORY_NAME "org.kde.kasts.feed"
DEFAULT_SEVERITY Info
)
ecm_qt_declare_logging_category(SRCS_base
HEADER "fetcherlogging.h"
IDENTIFIER "kastsFetcher"
CATEGORY_NAME "org.kde.kasts.fetcher"
DEFAULT_SEVERITY Info
)
ecm_qt_declare_logging_category(SRCS_base
HEADER "powermanagementinterfacelogging.h"
IDENTIFIER "kastsPowerManagementInterface"
CATEGORY_NAME "org.kde.kasts.powermanagementinterface"
DEFAULT_SEVERITY Info
)
ecm_qt_declare_logging_category(SRCS_base
HEADER "queuemodellogging.h"
IDENTIFIER "kastsQueueModel"
CATEGORY_NAME "org.kde.kasts.queuemodel"
DEFAULT_SEVERITY Info
)
if(ANDROID)
set (SRCS ${SRCS_base})
else()

View File

@ -5,6 +5,7 @@
*/
#include "datamanager.h"
#include "datamanagerlogging.h"
#include "audiomanager.h"
#include "database.h"
#include "fetcher.h"
@ -25,7 +26,7 @@ DataManager::DataManager()
&Fetcher::feedDetailsUpdated,
this,
[this](const QString &url, const QString &name, const QString &image, const QString &link, const QString &description, const QDateTime &lastUpdated) {
// qDebug() << "Start updating feed details" << m_feeds;
qCDebug(kastsDataManager) << "Start updating feed details" << m_feeds;
Feed *feed = getFeed(url);
if (feed != nullptr) {
feed->setName(name);
@ -33,7 +34,7 @@ DataManager::DataManager()
feed->setLink(link);
feed->setDescription(description);
feed->setLastUpdated(lastUpdated);
// qDebug() << "Retrieving authors";
qCDebug(kastsDataManager) << "Retrieving authors";
feed->updateAuthors();
// For feeds that have just been added, this is probably the point
// where the Feed object gets created; let's set refreshing to
@ -60,7 +61,6 @@ DataManager::DataManager()
Database::instance().execute(query);
while (query.next()) {
m_entrymap[feedurl] += query.value(QStringLiteral("id")).toString();
// qDebug() << m_entrymap[feedurl];
}
// Check for "new" entries
@ -74,7 +74,7 @@ DataManager::DataManager()
addToQueue(feedurl, id);
if (SettingsManager::self()->autoDownload()) {
if (getEntry(id) && getEntry(id)->hasEnclosure() && getEntry(id)->enclosure()) {
qDebug() << "Start downloading" << getEntry(id)->title();
qCDebug(kastsDataManager) << "Start downloading" << getEntry(id)->title();
getEntry(id)->enclosure()->download();
}
}
@ -93,7 +93,6 @@ DataManager::DataManager()
m_feedmap += query.value(QStringLiteral("url")).toString();
m_feeds[query.value(QStringLiteral("url")).toString()] = nullptr;
}
// qDebug() << m_feedmap;
for (auto &feedurl : m_feedmap) {
query.prepare(QStringLiteral("SELECT id FROM Entries WHERE feed=:feed ORDER BY updated DESC;"));
@ -102,17 +101,16 @@ DataManager::DataManager()
while (query.next()) {
m_entrymap[feedurl] += query.value(QStringLiteral("id")).toString();
m_entries[query.value(QStringLiteral("id")).toString()] = nullptr;
// qDebug() << m_entrymap[feedurl];
}
}
// qDebug() << m_entrymap;
// qCDebug(kastsDataManager) << "entrymap contains:" << m_entrymap;
query.prepare(QStringLiteral("SELECT id FROM Queue ORDER BY listnr;"));
Database::instance().execute(query);
while (query.next()) {
m_queuemap += query.value(QStringLiteral("id")).toString();
}
// qDebug() << m_queuemap;
qCDebug(kastsDataManager) << "Queuemap contains:" << m_queuemap;
}
Feed *DataManager::getFeed(const int index) const
@ -237,8 +235,7 @@ int DataManager::newEntryCount(const Feed *feed) const
void DataManager::removeFeed(Feed *feed)
{
qDebug() << feed->url();
qDebug() << "deleting feed with index" << m_feedmap.indexOf(feed->url());
qCDebug(kastsDataManager) << "deleting feed" << feed->url() << "with index" << m_feedmap.indexOf(feed->url());
removeFeed(m_feedmap.indexOf(feed->url()));
}
@ -250,7 +247,7 @@ void DataManager::removeFeed(const int index)
// Delete the object instances and mappings
// First delete entries in Queue
qDebug() << "delete queueentries of" << feedurl;
qCDebug(kastsDataManager) << "delete queueentries of" << feedurl;
for (auto &id : m_queuemap) {
if (getEntry(id)->feed()->url() == feedurl) {
if (AudioManager::instance().entry() == getEntry(id)) {
@ -261,7 +258,7 @@ void DataManager::removeFeed(const int index)
}
// Delete entries themselves
qDebug() << "delete entries of" << feedurl;
qCDebug(kastsDataManager) << "delete entries of" << feedurl;
for (auto &id : m_entrymap[feedurl]) {
if (getEntry(id)->hasEnclosure())
getEntry(id)->enclosure()->deleteFile(); // delete enclosure (if it exists)
@ -272,7 +269,7 @@ void DataManager::removeFeed(const int index)
}
m_entrymap.remove(feedurl); // remove all the entry mappings belonging to the feed
qDebug() << "Remove feed image" << feed->image() << "for feed" << feedurl;
qCDebug(kastsDataManager) << "Remove feed image" << feed->image() << "for feed" << feedurl;
if (!feed->image().isEmpty())
Fetcher::instance().removeImage(feed->image());
m_feeds.remove(m_feedmap[index]); // remove from m_feeds
@ -280,7 +277,7 @@ void DataManager::removeFeed(const int index)
delete feed; // remove the pointer
// Then delete everything from the database
qDebug() << "delete database part of" << feedurl;
qCDebug(kastsDataManager) << "delete database part of" << feedurl;
// Delete Authors
QSqlQuery query;
@ -317,12 +314,12 @@ void DataManager::addFeed(const QString &url, const bool fetch)
// a preliminary entry into the database. Those details (as well as entries,
// authors and enclosures) will be updated by calling Fetcher::fetch() which
// will trigger a full update of the feed and all related items.
qDebug() << "Adding feed";
qCDebug(kastsDataManager) << "Adding feed";
if (feedExists(url)) {
qDebug() << "Feed already exists";
qCDebug(kastsDataManager) << "Feed already exists";
return;
}
qDebug() << "Feed does not yet exist";
qCDebug(kastsDataManager) << "Feed does not yet exist";
QUrl urlFromInput = QUrl::fromUserInput(url);
QSqlQuery query;
@ -402,7 +399,7 @@ void DataManager::addToQueue(const QString &feedurl, const QString &id)
// Add to internal queuemap data structure
m_queuemap += id;
// qDebug() << m_queuemap;
qCDebug(kastsDataManager) << "Queue mapping is now:" << m_queuemap;
// Get index of this entry
const int index = m_queuemap.indexOf(id); // add new entry to end of queue
@ -434,7 +431,7 @@ void DataManager::moveQueueItem(const int from, const int to)
void DataManager::removeQueueItem(const int index)
{
// qDebug() << m_queuemap;
qCDebug(kastsDataManager) << "Queuemap is now:" << m_queuemap;
// Unset "new" state
getEntry(m_queuemap[index])->setNew(false);
// TODO: Make sure to unset the pointer in the Audio class once it's been
@ -506,7 +503,7 @@ void DataManager::importFeeds(const QString &path)
urls += xmlReader.attributes().value(QStringLiteral("xmlUrl")).toString();
}
}
qDebug() << urls;
qCDebug(kastsDataManager) << "Start importing urls:" << urls;
addFeeds(urls);
}
@ -552,7 +549,7 @@ void DataManager::loadEntry(const QString id) const
feed = getFeed(i.key());
}
if (!feed) {
qDebug() << "Failed to find feed belonging to entry" << id;
qCDebug(kastsDataManager) << "Failed to find feed belonging to entry" << id;
return;
}
m_entries[id] = new Entry(feed, id);

View File

@ -5,6 +5,7 @@
*/
#include "downloadprogressmodel.h"
#include "downloadprogressmodellogging.h"
#include "datamanager.h"
DownloadProgressModel::DownloadProgressModel()
@ -35,16 +36,16 @@ int DownloadProgressModel::rowCount(const QModelIndex &parent) const
void DownloadProgressModel::monitorDownloadProgress(Entry *entry, Enclosure::Status status)
{
// qDebug() << "download status changed:" << entry->title() << status;
qCDebug(kastsDownloadProgressModel) << "download status changed:" << entry->title() << status;
if (status == Enclosure::Downloading && !m_entries.contains(entry->id())) {
// qDebug() << "inserting dowloading entry" << entry->id() << "in position" << m_entries.count();
qCDebug(kastsDownloadProgressModel) << "inserting dowloading entry" << entry->id() << "in position" << m_entries.count();
beginInsertRows(QModelIndex(), m_entries.count(), m_entries.count());
m_entries += entry->id();
endInsertRows();
}
if (status != Enclosure::Downloading && m_entries.contains(entry->id())) {
int index = m_entries.indexOf(entry->id());
// qDebug() << "removing dowloading entry" << entry->id() << "in position" << index;
qCDebug(kastsDownloadProgressModel) << "removing dowloading entry" << entry->id() << "in position" << index;
beginRemoveRows(QModelIndex(), index, index);
m_entries.removeAt(index);
endRemoveRows();

View File

@ -6,6 +6,7 @@
*/
#include "enclosure.h"
#include "enclosurelogging.h"
#include <QFile>
#include <QNetworkReply>
@ -143,7 +144,7 @@ void Enclosure::processDownloadedFile()
// if not, correct the filesize in the database
// otherwise the file will get deleted because of mismatch in signature
if (file.size() != m_size) {
qDebug() << "enclosure file size mismatch" << m_entry->title();
qCDebug(kastsEnclosure) << "enclosure file size mismatch" << m_entry->title();
setSize(file.size());
}
@ -162,7 +163,7 @@ void Enclosure::processDownloadedFile()
void Enclosure::deleteFile()
{
// qDebug() << "Trying to delete enclosure file" << path();
qCDebug(kastsEnclosure) << "Trying to delete enclosure file" << path();
// First check if file still exists; you never know what has happened
if (QFile(path()).exists())
QFile(path()).remove();
@ -205,12 +206,12 @@ int Enclosure::size() const
void Enclosure::setPlayPosition(const qint64 &position)
{
m_playposition = position;
// qDebug() << "save playPosition" << position << m_entry->title();
qCDebug(kastsEnclosure) << "save playPosition" << position << m_entry->title();
Q_EMIT playPositionChanged();
// let's only save the play position to the database every 15 seconds
if ((abs(m_playposition - m_playposition_dbsave) > 15000) || position == 0) {
// qDebug() << "save playPosition to database" << position << m_entry->title();
qCDebug(kastsEnclosure) << "save playPosition to database" << position << m_entry->title();
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE Enclosures SET playposition=:playposition WHERE id=:id AND feed=:feed"));
query.bindValue(QStringLiteral(":id"), m_entry->id());
@ -227,7 +228,7 @@ void Enclosure::setDuration(const qint64 &duration)
Q_EMIT durationChanged();
// also save to database
// qDebug() << "updating entry duration" << duration << m_entry->title();
qCDebug(kastsEnclosure) << "updating entry duration" << duration << m_entry->title();
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE Enclosures SET duration=:duration WHERE id=:id AND feed=:feed"));
query.bindValue(QStringLiteral(":id"), m_entry->id());

View File

@ -11,6 +11,7 @@
#include "datamanager.h"
#include "entriesmodel.h"
#include "feed.h"
#include "feedlogging.h"
#include "fetcher.h"
Feed::Feed(const QString &feedurl)
@ -98,9 +99,9 @@ void Feed::updateAuthors()
QString name = authorQuery.value(QStringLiteral("name")).toString();
QString email = authorQuery.value(QStringLiteral("email")).toString();
QString url = authorQuery.value(QStringLiteral("uri")).toString();
// qDebug() << name << email << url;
qCDebug(kastsFeed) << name << email << url;
for (int i = 0; i < m_authors.count(); i++) {
// qDebug() << "old authors" << m_authors[i]->name() << m_authors[i]->email() << m_authors[i]->url();
qCDebug(kastsFeed) << "old authors" << m_authors[i]->name() << m_authors[i]->email() << m_authors[i]->url();
if (m_authors[i] && m_authors[i]->name() == name && m_authors[i]->email() == email && m_authors[i]->url() == url) {
existingAuthor = true;
newAuthors += m_authors[i];
@ -125,7 +126,7 @@ void Feed::updateAuthors()
if (haveAuthorsChanged)
Q_EMIT authorsChanged(m_authors);
// qDebug() << "feed" << m_name << "authors have changed?" << haveAuthorsChanged;
qCDebug(kastsFeed) << "feed" << m_name << "authors have changed?" << haveAuthorsChanged;
}
QString Feed::url() const

View File

@ -22,6 +22,7 @@
#include "database.h"
#include "fetcher.h"
#include "fetcherlogging.h"
#include "settingsmanager.h"
Fetcher::Fetcher()
@ -78,7 +79,7 @@ void Fetcher::fetchAll()
void Fetcher::retrieveFeed(const QString &url)
{
qDebug() << "Starting to fetch" << url;
qCDebug(kastsFetcher) << "Starting to fetch" << url;
Q_EMIT startedFetchingFeed(url);
@ -104,7 +105,7 @@ void Fetcher::retrieveFeed(const QString &url)
void Fetcher::updateMonitor(int progress)
{
// qDebug() << "Update monitor" << progress << "/" << m_updateTotal;
qCDebug(kastsFetcher) << "Update monitor" << progress << "/" << m_updateTotal;
// this method will watch for the end of the update process
if (progress > -1 && m_updateTotal > -1 && progress == m_updateTotal) {
m_updating = false;
@ -131,11 +132,11 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
if (query.next()) {
isNewFeed = query.value(QStringLiteral("new")).toBool();
} else {
qDebug() << "Feed not found in database" << url;
qCDebug(kastsFetcher) << "Feed not found in database" << url;
return;
}
if (isNewFeed)
qDebug() << "New feed" << feed->title() << ":" << isNewFeed;
qCDebug(kastsFetcher) << "New feed" << feed->title() << ":" << isNewFeed;
// Retrieve "other" fields; this will include the "itunes" tags
QMultiMap<QString, QDomElement> otherItems = feed->additionalProperties();
@ -170,7 +171,7 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
}
} else {
authorname = otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdauthor")).text();
// qDebug() << "authorname" << authorname;
qCDebug(kastsFetcher) << "authorname" << authorname;
}
if (!authorname.isEmpty()) {
processAuthor(url, QLatin1String(""), authorname, QLatin1String(""), authoremail);
@ -189,7 +190,7 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
query.bindValue(QStringLiteral(":image"), image);
Database::instance().execute(query);
qDebug() << "Updated feed details:" << feed->title();
qCDebug(kastsFetcher) << "Updated feed details:" << feed->title();
Q_EMIT feedDetailsUpdated(url, feed->title(), image, feed->link(), feed->description(), current);
@ -208,7 +209,7 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
Database::instance().execute(query);
QSqlQuery updateQuery;
while (query.next()) {
// qDebug() << "Marked as new:" << query.value(QStringLiteral("id")).toString();
qCDebug(kastsFetcher) << "Marked as new:" << query.value(QStringLiteral("id")).toString();
updateQuery.prepare(QStringLiteral("UPDATE Entries SET read=:read, new=:new WHERE id=:id AND feed=:feed;"));
updateQuery.bindValue(QStringLiteral(":read"), false);
updateQuery.bindValue(QStringLiteral(":new"), true);
@ -232,7 +233,7 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
bool Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, bool isNewFeed)
{
// qDebug() << "Processing" << entry->title();
qCDebug(kastsFetcher) << "Processing" << entry->title();
// Retrieve "other" fields; this will include the "itunes" tags
QMultiMap<QString, QDomElement> otherItems = entry->additionalProperties();
@ -270,7 +271,7 @@ bool Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, bool
if (image.startsWith(QStringLiteral("/")))
image = QUrl(url).adjusted(QUrl::RemovePath).toString() + image;
query.bindValue(QStringLiteral(":image"), image);
// qDebug() << "Entry image found" << image;
qCDebug(kastsFetcher) << "Entry image found" << image;
Database::instance().execute(query);
@ -378,7 +379,7 @@ QNetworkReply *Fetcher::download(const QString &url, const QString &filePath) co
void Fetcher::removeImage(const QString &url)
{
qDebug() << imagePath(url);
qCDebug(kastsFetcher) << "Removing image" << imagePath(url);
QFile(imagePath(url)).remove();
}

View File

@ -6,6 +6,7 @@
*/
#include "powermanagementinterface.h"
#include "powermanagementinterfacelogging.h"
#include <KLocalizedString>
@ -134,7 +135,7 @@ void PowerManagementInterface::uninhibitDBusCallFinishedPlasmaWorkspace(QDBusPen
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
QDBusPendingReply<> reply = *aWatcher;
if (reply.isError()) {
// qDebug() << "PowerManagementInterface::uninhibitDBusCallFinished" << reply.error();
qCDebug(kastsPowerManagementInterface) << "PowerManagementInterface::uninhibitDBusCallFinished" << reply.error();
} else {
d->mInhibitedSleep = false;
@ -151,7 +152,7 @@ void PowerManagementInterface::inhibitDBusCallFinishedGnomeWorkspace(QDBusPendin
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
QDBusPendingReply<uint> reply = *aWatcher;
if (reply.isError()) {
// qDebug() << "PowerManagementInterface::inhibitDBusCallFinishedGnomeWorkspace" << reply.error();
qCDebug(kastsPowerManagementInterface) << "PowerManagementInterface::inhibitDBusCallFinishedGnomeWorkspace" << reply.error();
} else {
d->mGnomeSleepCookie = reply.argumentAt<0>();
d->mInhibitedSleep = true;
@ -169,7 +170,7 @@ void PowerManagementInterface::uninhibitDBusCallFinishedGnomeWorkspace(QDBusPend
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
QDBusPendingReply<> reply = *aWatcher;
if (reply.isError()) {
// qDebug() << "PowerManagementInterface::uninhibitDBusCallFinished" << reply.error();
qCDebug(kastsPowerManagementInterface) << "PowerManagementInterface::uninhibitDBusCallFinished" << reply.error();
} else {
d->mInhibitedSleep = false;

View File

@ -11,6 +11,7 @@
#include "datamanager.h"
#include "entry.h"
#include "queuemodel.h"
#include "queuemodellogging.h"
QueueModel::QueueModel(QObject *parent)
: QAbstractListModel(parent)
@ -19,21 +20,21 @@ QueueModel::QueueModel(QObject *parent)
int to = (from < to_orig) ? to_orig + 1 : to_orig;
beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
endMoveRows();
// qDebug() << "Moved entry" << from << "to" << to;
qCDebug(kastsQueueModel) << "Moved entry" << from << "to" << to;
});
connect(&DataManager::instance(), &DataManager::queueEntryAdded, this, [this](int pos, const QString &id) {
Q_UNUSED(id)
beginInsertRows(QModelIndex(), pos, pos);
endInsertRows();
Q_EMIT timeLeftChanged();
// qDebug() << "Added entry at pos" << pos;
qCDebug(kastsQueueModel) << "Added entry at pos" << pos;
});
connect(&DataManager::instance(), &DataManager::queueEntryRemoved, this, [this](int pos, const QString &id) {
Q_UNUSED(id)
beginRemoveRows(QModelIndex(), pos, pos);
endRemoveRows();
Q_EMIT timeLeftChanged();
// qDebug() << "Removed entry at pos" << pos;
qCDebug(kastsQueueModel) << "Removed entry at pos" << pos;
});
// Connect positionChanged to make sure that the remaining playing time in
// the queue header is up-to-date
@ -47,7 +48,7 @@ QVariant QueueModel::data(const QModelIndex &index, int role) const
{
if (role != 0)
return QVariant();
// qDebug() << "return entry" << DataManager::instance().getQueueEntry(index.row());
qCDebug(kastsQueueModel) << "return entry" << DataManager::instance().getQueueEntry(index.row());
return QVariant::fromValue(DataManager::instance().getQueueEntry(index.row()));
}
@ -61,7 +62,7 @@ QHash<int, QByteArray> QueueModel::roleNames() const
int QueueModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
// qDebug() << "queueCount is" << DataManager::instance().queueCount();
qCDebug(kastsQueueModel) << "queueCount is" << DataManager::instance().queueCount();
return DataManager::instance().queueCount();
}
@ -75,7 +76,7 @@ int QueueModel::timeLeft() const
result += entry->enclosure()->duration() * 1000 - entry->enclosure()->playPosition();
}
}
// qDebug() << "timeLeft is" << result;
qCDebug(kastsQueueModel) << "timeLeft is" << result;
return result;
}