Apply clang-format

This commit is contained in:
Bart De Vries 2021-05-01 21:35:37 +02:00
parent e774e09f48
commit 1b1654d1f4
33 changed files with 411 additions and 474 deletions

View File

@ -7,13 +7,13 @@
#include "audiomanager.h"
#include <algorithm>
#include <QTimer>
#include <QAudio>
#include <QEventLoop>
#include <QTimer>
#include <algorithm>
#include "powermanagementinterface.h"
#include "datamanager.h"
#include "powermanagementinterface.h"
#include "settingsmanager.h"
static const double MAX_RATE = 1.0;
@ -22,25 +22,25 @@ static const qint64 SKIP_STEP = 10000;
class AudioManagerPrivate
{
private:
PowerManagementInterface mPowerInterface;
QMediaPlayer m_player;
Entry* m_entry = nullptr;
Entry *m_entry = nullptr;
bool m_readyToPlay = false;
bool m_isSeekable = false;
bool m_lockPositionSaving = false; // sort of lock mutex to prevent updating the player position while changing sources (which will emit lots of playerPositionChanged signals)
bool m_lockPositionSaving =
false; // sort of lock mutex to prevent updating the player position while changing sources (which will emit lots of playerPositionChanged signals)
void prepareAudioStream();
friend class AudioManager;
};
AudioManager::AudioManager(QObject *parent) : QObject(parent), d(std::make_unique<AudioManagerPrivate>())
AudioManager::AudioManager(QObject *parent)
: QObject(parent)
, d(std::make_unique<AudioManagerPrivate>())
{
connect(&d->m_player, &QMediaPlayer::mutedChanged, this, &AudioManager::playerMutedChanged);
connect(&d->m_player, &QMediaPlayer::volumeChanged, this, &AudioManager::playerVolumeChanged);
@ -70,7 +70,7 @@ AudioManager::~AudioManager()
d->mPowerInterface.setPreventSleep(false);
}
Entry* AudioManager::entry () const
Entry *AudioManager::entry() const
{
return d->m_entry;
}
@ -165,45 +165,45 @@ QMediaPlayer::MediaStatus AudioManager::status() const
return d->m_player.mediaStatus();
}
void AudioManager::setEntry(Entry* entry)
void AudioManager::setEntry(Entry *entry)
{
d->m_lockPositionSaving = true;
// First check if the previous track needs to be marked as read
// TODO: make grace time a setting in SettingsManager
if (d->m_entry) {
//qDebug() << "Checking previous track";
//qDebug() << "Left time" << (duration()-position());
//qDebug() << "MediaStatus" << d->m_player.mediaStatus();
if (( (duration()-position()) < 15000)
|| (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia) ) {
//qDebug() << "Mark as read:" << d->m_entry->title();
// qDebug() << "Checking previous track";
// qDebug() << "Left time" << (duration()-position());
// qDebug() << "MediaStatus" << d->m_player.mediaStatus();
if (((duration() - position()) < 15000) || (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia)) {
// qDebug() << "Mark as read:" << d->m_entry->title();
d->m_entry->setRead(true);
d->m_entry->enclosure()->setPlayPosition(0);
d->m_entry->setQueueStatus(false); // i.e. remove from queue TODO: make this a choice in settings
}
}
//qDebug() << entry->hasEnclosure() << entry->enclosure() << entry->enclosure()->status();
// qDebug() << entry->hasEnclosure() << entry->enclosure() << entry->enclosure()->status();
// do some checks on the new entry to see whether it's valid and not corrupted
if (entry != nullptr && entry->hasEnclosure() && entry->enclosure() && entry->enclosure()->status() == Enclosure::Downloaded) {
//qDebug() << "Going to change source";
// qDebug() << "Going to change source";
d->m_entry = entry;
Q_EMIT entryChanged(entry);
// the gst-pipeline is required to make sure that the pitch is not
// changed when speeding up the audio stream
// TODO: find a solution for Android (GStreamer not available on android by default)
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
//qDebug() << "use custom pipeline";
d->m_player.setMedia(QUrl(QStringLiteral("gst-pipeline: playbin uri=file://") + d->m_entry->enclosure()->path() + QStringLiteral(" audio_sink=\"scaletempo ! audioconvert ! audioresample ! autoaudiosink\" video_sink=\"fakevideosink\"")));
// qDebug() << "use custom pipeline";
d->m_player.setMedia(QUrl(QStringLiteral("gst-pipeline: playbin uri=file://") + d->m_entry->enclosure()->path()
+ QStringLiteral(" audio_sink=\"scaletempo ! audioconvert ! audioresample ! autoaudiosink\" video_sink=\"fakevideosink\"")));
#else
//qDebug() << "regular audio backend";
d->m_player.setMedia(QUrl(QStringLiteral("file://")+d->m_entry->enclosure()->path()));
// qDebug() << "regular audio backend";
d->m_player.setMedia(QUrl(QStringLiteral("file://") + d->m_entry->enclosure()->path()));
#endif
// save the current playing track in the settingsfile for restoring on startup
DataManager::instance().setLastPlayingEntry(d->m_entry->id());
//qDebug() << "Changed source to" << d->m_entry->title();
// qDebug() << "Changed source to" << d->m_entry->title();
d->prepareAudioStream();
d->m_readyToPlay = true;
@ -214,11 +214,11 @@ void AudioManager::setEntry(Entry* entry)
Q_EMIT canGoNextChanged();
d->m_isSeekable = true;
Q_EMIT seekableChanged(true);
//qDebug() << "Duration" << d->m_player.duration()/1000 << d->m_entry->enclosure()->duration();
// qDebug() << "Duration" << d->m_player.duration()/1000 << d->m_entry->enclosure()->duration();
// Finally, check if duration mentioned in enclosure corresponds to real duration
if ((d->m_player.duration()/1000) != d->m_entry->enclosure()->duration()) {
d->m_entry->enclosure()->setDuration(d->m_player.duration()/1000);
//qDebug() << "Correcting duration of" << d->m_entry->id() << "to" << d->m_player.duration()/1000;
if ((d->m_player.duration() / 1000) != d->m_entry->enclosure()->duration()) {
d->m_entry->enclosure()->setDuration(d->m_player.duration() / 1000);
// qDebug() << "Correcting duration of" << d->m_entry->id() << "to" << d->m_player.duration()/1000;
}
} else {
DataManager::instance().setLastPlayingEntry(QStringLiteral("none"));
@ -246,7 +246,7 @@ void AudioManager::setMuted(bool muted)
void AudioManager::setVolume(qreal volume)
{
//qDebug() << "AudioManager::setVolume" << volume;
// qDebug() << "AudioManager::setVolume" << volume;
auto realVolume = static_cast<qreal>(QAudio::convertVolume(volume / 100.0, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale));
d->m_player.setVolume(qRound(realVolume * 100));
@ -263,21 +263,21 @@ void AudioManager::setSource(const QUrl &source)
void AudioManager::setPosition(qint64 position)
{
//qDebug() << "AudioManager::setPosition" << position;
// qDebug() << "AudioManager::setPosition" << position;
d->m_player.setPosition(position);
}
void AudioManager::setPlaybackRate(const qreal rate)
{
//qDebug() << "AudioManager::setPlaybackRate" << rate;
// qDebug() << "AudioManager::setPlaybackRate" << rate;
d->m_player.setPlaybackRate(rate);
}
void AudioManager::play()
{
//qDebug() << "AudioManager::play";
// qDebug() << "AudioManager::play";
d->prepareAudioStream();
d->m_player.play();
@ -288,7 +288,7 @@ void AudioManager::play()
void AudioManager::pause()
{
//qDebug() << "AudioManager::pause";
// qDebug() << "AudioManager::pause";
d->m_isSeekable = true;
d->m_player.pause();
@ -305,7 +305,7 @@ void AudioManager::playPause()
void AudioManager::stop()
{
//qDebug() << "AudioManager::stop";
// qDebug() << "AudioManager::stop";
d->m_player.stop();
d->m_isSeekable = false;
@ -315,20 +315,20 @@ void AudioManager::stop()
void AudioManager::seek(qint64 position)
{
//qDebug() << "AudioManager::seek" << position;
// qDebug() << "AudioManager::seek" << position;
d->m_player.setPosition(position);
}
void AudioManager::skipForward()
{
//qDebug() << "AudioManager::skipForward";
// qDebug() << "AudioManager::skipForward";
seek(std::min((position() + SKIP_STEP), duration()));
}
void AudioManager::skipBackward()
{
//qDebug() << "AudioManager::skipBackward";
// qDebug() << "AudioManager::skipBackward";
seek(std::max((qint64)0, (position() - SKIP_STEP)));
}
@ -339,10 +339,10 @@ bool AudioManager::canGoNext() const
int index = DataManager::instance().queue().indexOf(d->m_entry->id());
if (index >= 0) {
// check if there is a next track
if (index < DataManager::instance().queue().count()-1) {
Entry* next_entry = DataManager::instance().getEntry(DataManager::instance().queue()[index+1]);
if (index < DataManager::instance().queue().count() - 1) {
Entry *next_entry = DataManager::instance().getEntry(DataManager::instance().queue()[index + 1]);
if (next_entry->enclosure()) {
//qDebug() << "Enclosure status" << next_entry->enclosure()->path() << next_entry->enclosure()->status();
// qDebug() << "Enclosure status" << next_entry->enclosure()->path() << next_entry->enclosure()->status();
if (next_entry->enclosure()->status() == Enclosure::Downloaded) {
return true;
}
@ -358,18 +358,19 @@ void AudioManager::next()
if (canGoNext()) {
QMediaPlayer::State previousTrackState = playbackState();
int index = DataManager::instance().queue().indexOf(d->m_entry->id());
//qDebug() << "Skipping to" << DataManager::instance().queue()[index+1];
setEntry(DataManager::instance().getEntry(DataManager::instance().queue()[index+1]));
if (previousTrackState == QMediaPlayer::PlayingState) play();
// qDebug() << "Skipping to" << DataManager::instance().queue()[index+1];
setEntry(DataManager::instance().getEntry(DataManager::instance().queue()[index + 1]));
if (previousTrackState == QMediaPlayer::PlayingState)
play();
} else {
//qDebug() << "Next track cannot be played, changing entry to nullptr";
// qDebug() << "Next track cannot be played, changing entry to nullptr";
setEntry(nullptr);
}
}
void AudioManager::mediaStatusChanged()
{
//qDebug() << "AudioManager::mediaStatusChanged" << d->m_player.mediaStatus();
// qDebug() << "AudioManager::mediaStatusChanged" << d->m_player.mediaStatus();
// File has reached the end and has stopped
if (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia) {
@ -382,7 +383,7 @@ void AudioManager::mediaStatusChanged()
if (d->m_player.mediaStatus() == QMediaPlayer::InvalidMedia) {
// save pointer to this bad entry to allow
// us to delete the enclosure after the track has been unloaded
Entry* badEntry = d->m_entry;
Entry *badEntry = d->m_entry;
DataManager::instance().setLastPlayingEntry(QStringLiteral("none"));
stop();
next();
@ -394,10 +395,9 @@ void AudioManager::mediaStatusChanged()
void AudioManager::playerStateChanged()
{
//qDebug() << "AudioManager::playerStateChanged" << d->m_player.state();
// qDebug() << "AudioManager::playerStateChanged" << d->m_player.state();
switch(d->m_player.state())
{
switch (d->m_player.state()) {
case QMediaPlayer::State::StoppedState:
Q_EMIT stopped();
d->mPowerInterface.setPreventSleep(false);
@ -417,16 +417,20 @@ void AudioManager::playerStateChanged()
void AudioManager::playerVolumeChanged()
{
//qDebug() << "AudioManager::playerVolumeChanged" << d->m_player.volume();
// qDebug() << "AudioManager::playerVolumeChanged" << d->m_player.volume();
QTimer::singleShot(0, [this]() {Q_EMIT volumeChanged();});
QTimer::singleShot(0, [this]() {
Q_EMIT volumeChanged();
});
}
void AudioManager::playerMutedChanged()
{
//qDebug() << "AudioManager::playerMutedChanged";
// qDebug() << "AudioManager::playerMutedChanged";
QTimer::singleShot(0, [this]() {Q_EMIT mutedChanged(muted());});
QTimer::singleShot(0, [this]() {
Q_EMIT mutedChanged(muted());
});
}
void AudioManager::savePlayPosition(qint64 position)
@ -438,7 +442,7 @@ void AudioManager::savePlayPosition(qint64 position)
}
}
}
//qDebug() << d->m_player.mediaStatus();
// qDebug() << d->m_player.mediaStatus();
}
void AudioManagerPrivate::prepareAudioStream()
@ -452,7 +456,7 @@ void AudioManagerPrivate::prepareAudioStream()
* Unfortunately, this will produce an audible glitch with the current
* QMediaPlayer backend.
*/
//qDebug() << "voodoo happening";
// qDebug() << "voodoo happening";
qint64 startingPosition = m_entry->enclosure()->playPosition();
m_player.play();
if (!m_player.isSeekable()) {
@ -460,9 +464,9 @@ void AudioManagerPrivate::prepareAudioStream()
QTimer timer;
timer.setSingleShot(true);
timer.setInterval(2000);
loop.connect(&timer, SIGNAL (timeout()), &loop, SLOT (quit()) );
loop.connect(&m_player, SIGNAL (seekableChanged(bool)), &loop, SLOT (quit()));
//qDebug() << "Starting waiting loop";
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.connect(&m_player, SIGNAL(seekableChanged(bool)), &loop, SLOT(quit()));
// qDebug() << "Starting waiting loop";
loop.exec();
}
if (m_player.mediaStatus() != QMediaPlayer::BufferedMedia) {
@ -470,11 +474,12 @@ void AudioManagerPrivate::prepareAudioStream()
QTimer timer;
timer.setSingleShot(true);
timer.setInterval(2000);
loop.connect(&timer, SIGNAL (timeout()), &loop, SLOT (quit()) );
loop.connect(&m_player, SIGNAL (mediaStatusChanged(QMediaPlayer::MediaStatus)), &loop, SLOT (quit()));
//qDebug() << "Starting waiting loop on media status" << d->m_player.mediaStatus();
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.connect(&m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), &loop, SLOT(quit()));
// qDebug() << "Starting waiting loop on media status" << d->m_player.mediaStatus();
loop.exec();
} //qDebug() << "Changing position";
if (startingPosition > 1000) m_player.setPosition(startingPosition);
} // qDebug() << "Changing position";
if (startingPosition > 1000)
m_player.setPosition(startingPosition);
m_player.pause();
}

View File

@ -7,10 +7,10 @@
#pragma once
#include <QObject>
#include <QUrl>
#include <QMediaPlayer>
#include <QObject>
#include <QString>
#include <QUrl>
#include <memory>
@ -22,69 +22,22 @@ class AudioManager : public QObject
{
Q_OBJECT
Q_PROPERTY(Entry* entry
READ entry
WRITE setEntry
NOTIFY entryChanged)
Q_PROPERTY(bool muted
READ muted
WRITE setMuted
NOTIFY mutedChanged)
Q_PROPERTY(qreal volume
READ volume
WRITE setVolume
NOTIFY volumeChanged)
Q_PROPERTY(QMediaPlayer::MediaStatus status
READ status
NOTIFY statusChanged)
Q_PROPERTY(QMediaPlayer::State playbackState
READ playbackState
NOTIFY playbackStateChanged)
Q_PROPERTY(qreal playbackRate
READ playbackRate
WRITE setPlaybackRate
NOTIFY playbackRateChanged)
Q_PROPERTY(QMediaPlayer::Error error
READ error
NOTIFY errorChanged)
Q_PROPERTY(qint64 duration
READ duration
NOTIFY durationChanged)
Q_PROPERTY(qint64 position
READ position
WRITE setPosition
NOTIFY positionChanged)
Q_PROPERTY(bool seekable
READ seekable
NOTIFY seekableChanged)
Q_PROPERTY(bool canPlay
READ canPlay
NOTIFY canPlayChanged)
Q_PROPERTY(bool canSkipForward
READ canSkipForward
NOTIFY canSkipForwardChanged)
Q_PROPERTY(bool canSkipBackward
READ canSkipBackward
NOTIFY canSkipBackwardChanged)
Q_PROPERTY(bool canGoNext
READ canGoNext
NOTIFY canGoNextChanged)
Q_PROPERTY(Entry *entry READ entry WRITE setEntry NOTIFY entryChanged)
Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged)
Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(QMediaPlayer::MediaStatus status READ status NOTIFY statusChanged)
Q_PROPERTY(QMediaPlayer::State playbackState READ playbackState NOTIFY playbackStateChanged)
Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
Q_PROPERTY(QMediaPlayer::Error error READ error NOTIFY errorChanged)
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(bool seekable READ seekable NOTIFY seekableChanged)
Q_PROPERTY(bool canPlay READ canPlay NOTIFY canPlayChanged)
Q_PROPERTY(bool canSkipForward READ canSkipForward NOTIFY canSkipForwardChanged)
Q_PROPERTY(bool canSkipBackward READ canSkipBackward NOTIFY canSkipBackwardChanged)
Q_PROPERTY(bool canGoNext READ canGoNext NOTIFY canGoNextChanged)
public:
explicit AudioManager(QObject *parent = nullptr);
static AudioManager &instance()
@ -95,7 +48,7 @@ public:
~AudioManager() override;
[[nodiscard]] Entry* entry() const;
[[nodiscard]] Entry *entry() const;
[[nodiscard]] bool muted() const;
@ -133,7 +86,7 @@ public:
Q_SIGNALS:
void entryChanged(Entry* entry);
void entryChanged(Entry *entry);
void mutedChanged(bool muted);
@ -173,13 +126,13 @@ Q_SIGNALS:
public Q_SLOTS:
void setEntry(Entry* entry);
void setEntry(Entry *entry);
void setMuted(bool muted);
void setVolume(qreal volume);
//void setSource(const QUrl &source); //source should only be set by audiomanager itself
// void setSource(const QUrl &source); //source should only be set by audiomanager itself
void setPosition(qint64 position);
@ -214,9 +167,7 @@ private Q_SLOTS:
void savePlayPosition(qint64 position);
private:
friend class AudioManagerPrivate;
std::unique_ptr<AudioManagerPrivate> d;
};

View File

@ -14,12 +14,12 @@
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "settingsmanager.h"
#include "database.h"
#include "fetcher.h"
#include "settingsmanager.h"
#define TRUE_OR_RETURN(x) \
if (!x) \
#define TRUE_OR_RETURN(x) \
if (!x) \
return false;
Database::Database()
@ -47,10 +47,16 @@ bool Database::migrate()
bool Database::migrateTo1()
{
qDebug() << "Migrating database to version 1";
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT, image TEXT, link TEXT, description TEXT, deleteAfterCount INTEGER, deleteAfterType INTEGER, subscribed INTEGER, lastUpdated INTEGER, new BOOL, notify BOOL);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Entries (feed TEXT, id TEXT UNIQUE, title TEXT, content TEXT, created INTEGER, updated INTEGER, link TEXT, read bool, new bool, hasEnclosure BOOL, image TEXT);")));
TRUE_OR_RETURN(
execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT, image TEXT, link TEXT, description TEXT, deleteAfterCount INTEGER, "
"deleteAfterType INTEGER, subscribed INTEGER, lastUpdated INTEGER, new BOOL, notify BOOL);")));
TRUE_OR_RETURN(
execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Entries (feed TEXT, id TEXT UNIQUE, title TEXT, content TEXT, created INTEGER, updated INTEGER, "
"link TEXT, read bool, new bool, hasEnclosure BOOL, image TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Authors (feed TEXT, id TEXT, name TEXT, uri TEXT, email TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Enclosures (feed TEXT, id TEXT, duration INTEGER, size INTEGER, title TEXT, type TEXT, url TEXT, playposition INTEGER, downloaded BOOL);"))); //, filename TEXT);")));
TRUE_OR_RETURN(
execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Enclosures (feed TEXT, id TEXT, duration INTEGER, size INTEGER, title TEXT, type TEXT, url TEXT, "
"playposition INTEGER, downloaded BOOL);"))); //, filename TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Queue (listnr INTEGER, feed TEXT, id TEXT, playing BOOL);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Errors (url TEXT, id TEXT, code INTEGER, message TEXT, date INTEGER);")));
TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;")));

View File

@ -4,6 +4,10 @@
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "datamanager.h"
#include "database.h"
#include "fetcher.h"
#include "settingsmanager.h"
#include <QDateTime>
#include <QDir>
#include <QSqlDatabase>
@ -12,28 +16,28 @@
#include <QUrl>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "datamanager.h"
#include "fetcher.h"
#include "database.h"
#include "settingsmanager.h"
DataManager::DataManager()
{
connect(&Fetcher::instance(), &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;
Feed* feed = getFeed(url);
if (feed != nullptr) {
feed->setName(name);
feed->setImage(image);
feed->setLink(link);
feed->setDescription(description);
feed->setLastUpdated(lastUpdated);
//qDebug() << "Retrieving authors";
feed->updateAuthors();
// TODO: signal feedmodel: Q_EMIT dataChanged(createIndex(i, 0), createIndex(i, 0));
// quite sure that this is actually not needed
}
});
connect(
&Fetcher::instance(),
&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;
Feed *feed = getFeed(url);
if (feed != nullptr) {
feed->setName(name);
feed->setImage(image);
feed->setLink(link);
feed->setDescription(description);
feed->setLastUpdated(lastUpdated);
// qDebug() << "Retrieving authors";
feed->updateAuthors();
// TODO: signal feedmodel: Q_EMIT dataChanged(createIndex(i, 0), createIndex(i, 0));
// quite sure that this is actually not needed
}
});
connect(&Fetcher::instance(), &Fetcher::entryAdded, this, [this](const QString &feedurl, const QString &id) {
// Only add the new entry to m_entries
// we will repopulate m_entrymap once all new entries have been added,
@ -52,7 +56,7 @@ DataManager::DataManager()
Database::instance().execute(query);
while (query.next()) {
m_entrymap[feedurl] += query.value(QStringLiteral("id")).toString();
//qDebug() << m_entrymap[feedurl];
// qDebug() << m_entrymap[feedurl];
}
// Check for "new" entries
@ -85,7 +89,7 @@ DataManager::DataManager()
m_feedmap += query.value(QStringLiteral("url")).toString();
m_feeds[query.value(QStringLiteral("url")).toString()] = nullptr;
}
//qDebug() << m_feedmap;
// qDebug() << m_feedmap;
for (auto &feedurl : m_feedmap) {
query.prepare(QStringLiteral("SELECT id FROM Entries WHERE feed=:feed ORDER BY updated DESC;"));
@ -94,49 +98,49 @@ 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[feedurl];
}
}
//qDebug() << m_entrymap;
// qDebug() << 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;
// qDebug() << m_queuemap;
}
Feed* DataManager::getFeed(const int index) const
Feed *DataManager::getFeed(const int index) const
{
return getFeed(m_feedmap[index]);
}
Feed* DataManager::getFeed(const QString &feedurl) const
Feed *DataManager::getFeed(const QString &feedurl) const
{
if (m_feeds[feedurl] == nullptr)
loadFeed(feedurl);
return m_feeds[feedurl];
}
Entry* DataManager::getEntry(const int feed_index, const int entry_index) const
Entry *DataManager::getEntry(const int feed_index, const int entry_index) const
{
return getEntry(m_entrymap[m_feedmap[feed_index]][entry_index]);
}
Entry* DataManager::getEntry(const Feed* feed, const int entry_index) const
Entry *DataManager::getEntry(const Feed *feed, const int entry_index) const
{
return getEntry(m_entrymap[feed->url()][entry_index]);
}
Entry* DataManager::getEntry(const QString &id) const
Entry *DataManager::getEntry(const QString &id) const
{
if (m_entries[id] == nullptr)
loadEntry(id);
return m_entries[id];
}
Entry* DataManager::getEntry(const EpisodeModel::Type type, const int entry_index) const
Entry *DataManager::getEntry(const EpisodeModel::Type type, const int entry_index) const
{
QSqlQuery entryQuery;
if (type == EpisodeModel::All || type == EpisodeModel::New || type == EpisodeModel::Unread || type == EpisodeModel::Downloaded) {
@ -149,7 +153,9 @@ Entry* DataManager::getEntry(const EpisodeModel::Type type, const int entry_inde
} else if (type == EpisodeModel::All) {
entryQuery.prepare(QStringLiteral("SELECT id FROM Entries ORDER BY updated DESC LIMIT 1 OFFSET :index;"));
} else { // i.e. EpisodeModel::Downloaded
entryQuery.prepare(QStringLiteral("SELECT * FROM Enclosures INNER JOIN Entries ON Enclosures.id = Entries.id WHERE downloaded=:downloaded ORDER BY updated DESC LIMIT 1 OFFSET :index;"));
entryQuery.prepare(
QStringLiteral("SELECT * FROM Enclosures INNER JOIN Entries ON Enclosures.id = Entries.id WHERE downloaded=:downloaded ORDER BY updated DESC "
"LIMIT 1 OFFSET :index;"));
entryQuery.bindValue(QStringLiteral(":downloaded"), true);
}
entryQuery.bindValue(QStringLiteral(":index"), entry_index);
@ -174,7 +180,7 @@ int DataManager::entryCount(const int feed_index) const
return m_entrymap[m_feedmap[feed_index]].count();
}
int DataManager::entryCount(const Feed* feed) const
int DataManager::entryCount(const Feed *feed) const
{
return m_entrymap[feed->url()].count();
}
@ -203,7 +209,7 @@ int DataManager::entryCount(const EpisodeModel::Type type) const
return -1;
}
int DataManager::unreadEntryCount(const Feed* feed) const
int DataManager::unreadEntryCount(const Feed *feed) const
{
QSqlQuery query;
query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries where feed=:feed AND read=0;"));
@ -214,7 +220,7 @@ int DataManager::unreadEntryCount(const Feed* feed) const
return query.value(0).toInt();
}
int DataManager::newEntryCount(const Feed* feed) const
int DataManager::newEntryCount(const Feed *feed) const
{
QSqlQuery query;
query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries where feed=:feed AND new=1;"));
@ -225,7 +231,7 @@ int DataManager::newEntryCount(const Feed* feed) const
return query.value(0).toInt();
}
void DataManager::removeFeed(Feed* feed)
void DataManager::removeFeed(Feed *feed)
{
qDebug() << feed->url();
qDebug() << "deleting feed with index" << m_feedmap.indexOf(feed->url());
@ -235,13 +241,13 @@ void DataManager::removeFeed(Feed* feed)
void DataManager::removeFeed(const int index)
{
// Get feed pointer
Feed* feed = getFeed(m_feedmap[index]);
Feed *feed = getFeed(m_feedmap[index]);
const QString feedurl = feed->url();
// Delete the object instances and mappings
// First delete entries in Queue
qDebug() << "delete queueentries of" << feedurl;
for (auto& id : m_queuemap) {
for (auto &id : m_queuemap) {
if (getEntry(id)->feed()->url() == feedurl) {
removeQueueItem(id);
}
@ -249,16 +255,19 @@ void DataManager::removeFeed(const int index)
// Delete entries themselves
qDebug() << "delete entries of" << feedurl;
for (auto& id : m_entrymap[feedurl]) {
if (getEntry(id)->hasEnclosure()) getEntry(id)->enclosure()->deleteFile(); // delete enclosure (if it exists)
if (!getEntry(id)->image().isEmpty()) Fetcher::instance().removeImage(getEntry(id)->image()); // delete entry images
for (auto &id : m_entrymap[feedurl]) {
if (getEntry(id)->hasEnclosure())
getEntry(id)->enclosure()->deleteFile(); // delete enclosure (if it exists)
if (!getEntry(id)->image().isEmpty())
Fetcher::instance().removeImage(getEntry(id)->image()); // delete entry images
delete m_entries[id]; // delete pointer
m_entries.remove(id); // delete the hash key
}
m_entrymap.remove(feedurl); // remove all the entry mappings belonging to the feed
qDebug() << "Remove feed image" << feed->image() << "for feed" << feedurl;
if (!feed->image().isEmpty()) Fetcher::instance().removeImage(feed->image());
if (!feed->image().isEmpty())
Fetcher::instance().removeImage(feed->image());
m_feeds.remove(m_feedmap[index]); // remove from m_feeds
m_feedmap.removeAt(index); // remove from m_feedmap
delete feed; // remove the pointer
@ -310,7 +319,8 @@ void DataManager::addFeed(const QString &url, const bool fetch)
QUrl urlFromInput = QUrl::fromUserInput(url);
QSqlQuery query;
query.prepare(QStringLiteral("INSERT INTO Feeds VALUES (:name, :url, :image, :link, :description, :deleteAfterCount, :deleteAfterType, :subscribed, :lastUpdated, :new, :notify);"));
query.prepare(QStringLiteral(
"INSERT INTO Feeds VALUES (:name, :url, :image, :link, :description, :deleteAfterCount, :deleteAfterType, :subscribed, :lastUpdated, :new, :notify);"));
query.bindValue(QStringLiteral(":name"), urlFromInput.toString());
query.bindValue(QStringLiteral(":url"), urlFromInput.toString());
query.bindValue(QStringLiteral(":image"), QLatin1String(""));
@ -329,20 +339,22 @@ void DataManager::addFeed(const QString &url, const bool fetch)
Q_EMIT feedAdded(urlFromInput.toString());
if (fetch) Fetcher::instance().fetch(urlFromInput.toString());
if (fetch)
Fetcher::instance().fetch(urlFromInput.toString());
}
void DataManager::addFeeds(const QStringList &urls)
{
if (urls.count() == 0) return;
if (urls.count() == 0)
return;
for (int i=0; i<urls.count(); i++) {
addFeed(urls[i], false); // add preliminary feed entries, but do not fetch yet
for (int i = 0; i < urls.count(); i++) {
addFeed(urls[i], false); // add preliminary feed entries, but do not fetch yet
}
Fetcher::instance().fetch(urls);
}
Entry* DataManager::getQueueEntry(int index) const
Entry *DataManager::getQueueEntry(int index) const
{
return getEntry(m_queuemap[index]);
}
@ -357,7 +369,7 @@ QStringList DataManager::queue() const
return m_queuemap;
}
bool DataManager::entryInQueue(const Entry* entry)
bool DataManager::entryInQueue(const Entry *entry)
{
return entryInQueue(entry->feed()->url(), entry->id());
}
@ -368,7 +380,7 @@ bool DataManager::entryInQueue(const QString &feedurl, const QString &id) const
return m_queuemap.contains(id);
}
void DataManager::addToQueue(const Entry* entry)
void DataManager::addToQueue(const Entry *entry)
{
if (entry != nullptr) {
return addToQueue(entry->feed()->url(), entry->id());
@ -378,11 +390,12 @@ void DataManager::addToQueue(const Entry* entry)
void DataManager::addToQueue(const QString &feedurl, const QString &id)
{
// If item is already in queue, then stop here
if (m_queuemap.contains(id)) return;
if (m_queuemap.contains(id))
return;
// Add to internal queuemap data structure
m_queuemap += id;
//qDebug() << m_queuemap;
// qDebug() << m_queuemap;
// Get index of this entry
const int index = m_queuemap.indexOf(id); // add new entry to end of queue
@ -414,7 +427,7 @@ void DataManager::moveQueueItem(const int from, const int to)
void DataManager::removeQueueItem(const int index)
{
//qDebug() << m_queuemap;
// qDebug() << 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
@ -441,7 +454,7 @@ void DataManager::removeQueueItem(const QString id)
removeQueueItem(m_queuemap.indexOf(id));
}
void DataManager::removeQueueItem(Entry* entry)
void DataManager::removeQueueItem(Entry *entry)
{
removeQueueItem(m_queuemap.indexOf(entry->id()));
}
@ -452,11 +465,12 @@ QString DataManager::lastPlayingEntry()
query.prepare(QStringLiteral("SELECT id FROM Queue WHERE playing=:playing;"));
query.bindValue(QStringLiteral(":playing"), true);
Database::instance().execute(query);
if (!query.next()) return QStringLiteral("none");
if (!query.next())
return QStringLiteral("none");
return query.value(QStringLiteral("id")).toString();
}
void DataManager::setLastPlayingEntry(const QString& id)
void DataManager::setLastPlayingEntry(const QString &id)
{
QSqlQuery query;
// First set playing to false for all Queue items
@ -479,9 +493,9 @@ void DataManager::importFeeds(const QString &path)
QStringList urls;
QXmlStreamReader xmlReader(&file);
while(!xmlReader.atEnd()) {
while (!xmlReader.atEnd()) {
xmlReader.readNext();
if(xmlReader.tokenType() == 4 && xmlReader.attributes().hasAttribute(QStringLiteral("xmlUrl"))) {
if (xmlReader.tokenType() == 4 && xmlReader.attributes().hasAttribute(QStringLiteral("xmlUrl"))) {
urls += xmlReader.attributes().value(QStringLiteral("xmlUrl")).toString();
}
}
@ -505,7 +519,7 @@ void DataManager::exportFeeds(const QString &path)
QSqlQuery query;
query.prepare(QStringLiteral("SELECT url, name FROM Feeds;"));
Database::instance().execute(query);
while(query.next()) {
while (query.next()) {
xmlWriter.writeEmptyElement(QStringLiteral("outline"));
xmlWriter.writeAttribute(QStringLiteral("xmlUrl"), query.value(0).toString());
xmlWriter.writeAttribute(QStringLiteral("title"), query.value(1).toString());
@ -523,7 +537,7 @@ void DataManager::loadFeed(const QString feedurl) const
void DataManager::loadEntry(const QString id) const
{
// First find the feed that this entry belongs to
Feed* feed = nullptr;
Feed *feed = nullptr;
QHashIterator<QString, QStringList> i(m_entrymap);
while (i.hasNext()) {
i.next();
@ -545,7 +559,7 @@ bool DataManager::feedExists(const QString &url)
void DataManager::updateQueueListnrs() const
{
QSqlQuery query;
for (int i=0; i<m_queuemap.count(); i++) {
for (int i = 0; i < m_queuemap.count(); i++) {
query.prepare(QStringLiteral("UPDATE Queue SET listnr=:i WHERE id=:id;"));
query.bindValue(QStringLiteral(":i"), i);
query.bindValue(QStringLiteral(":id"), m_queuemap[i]);

View File

@ -6,9 +6,9 @@
#pragma once
#include "feed.h"
#include "entry.h"
#include "episodemodel.h"
#include "feed.h"
class DataManager : public QObject
{
@ -21,42 +21,42 @@ public:
return _instance;
}
Feed* getFeed(const int index) const;
Feed* getFeed(const QString &feedurl) const;
Entry* getEntry(const int feed_index, const int entry_index) const;
Entry* getEntry(const Feed* feed, const int entry_index) const;
Entry* getEntry(const EpisodeModel::Type type, const int entry_index) const;
Q_INVOKABLE Entry* getEntry(const QString &id) const;
Feed *getFeed(const int index) const;
Feed *getFeed(const QString &feedurl) const;
Entry *getEntry(const int feed_index, const int entry_index) const;
Entry *getEntry(const Feed *feed, const int entry_index) const;
Entry *getEntry(const EpisodeModel::Type type, const int entry_index) const;
Q_INVOKABLE Entry *getEntry(const QString &id) const;
int feedCount() const;
int entryCount(const int feed_index) const;
int entryCount(const Feed* feed) const;
int entryCount(const Feed *feed) const;
int entryCount(const EpisodeModel::Type type) const;
int unreadEntryCount(const Feed* feed) const;
int newEntryCount(const Feed* feed) const;
int unreadEntryCount(const Feed *feed) const;
int newEntryCount(const Feed *feed) const;
Q_INVOKABLE void addFeed(const QString &url);
void addFeed(const QString &url, const bool fetch);
void addFeeds(const QStringList &urls);
Q_INVOKABLE void removeFeed(Feed* feed);
Q_INVOKABLE void removeFeed(Feed *feed);
void removeFeed(const int index);
//Q_INVOKABLE void addEntry(const QString &url); // TODO: implement these methods
//Q_INVOKABLE void removeEntry(const QString &url);
//Q_INVOKABLE void removeEntry(const Feed* feed, const int &index);
// Q_INVOKABLE void addEntry(const QString &url); // TODO: implement these methods
// Q_INVOKABLE void removeEntry(const QString &url);
// Q_INVOKABLE void removeEntry(const Feed* feed, const int &index);
Entry* getQueueEntry(int index) const;
Entry *getQueueEntry(int index) const;
int queueCount() const;
QStringList queue() const;
Q_INVOKABLE bool entryInQueue(const Entry* entry);
Q_INVOKABLE bool entryInQueue(const Entry *entry);
Q_INVOKABLE bool entryInQueue(const QString &feedurl, const QString &id) const;
Q_INVOKABLE void addToQueue(const Entry* entry);
Q_INVOKABLE void addToQueue(const Entry *entry);
Q_INVOKABLE void addToQueue(const QString &feedurl, const QString &id);
Q_INVOKABLE void moveQueueItem(const int from, const int to);
Q_INVOKABLE void removeQueueItem(const int index);
Q_INVOKABLE void removeQueueItem(const QString id);
Q_INVOKABLE void removeQueueItem(Entry* entry);
Q_INVOKABLE void removeQueueItem(Entry *entry);
Q_INVOKABLE QString lastPlayingEntry();
Q_INVOKABLE void setLastPlayingEntry(const QString& id);
Q_INVOKABLE void setLastPlayingEntry(const QString &id);
Q_INVOKABLE void importFeeds(const QString &path);
Q_INVOKABLE void exportFeeds(const QString &path);
@ -65,7 +65,7 @@ Q_SIGNALS:
void feedAdded(const QString &url);
void feedRemoved(const int &index);
void entryAdded(const QString &feedurl, const QString &id);
//void entryRemoved(const Feed*, const int &index); // TODO: implement this signal, is this needed?
// void entryRemoved(const Feed*, const int &index); // TODO: implement this signal, is this needed?
void feedEntriesUpdated(const QString &url);
void queueEntryAdded(const int &index, const QString &id);
void queueEntryRemoved(const int &index, const QString &id);
@ -82,8 +82,8 @@ private:
bool feedExists(const QString &url);
void updateQueueListnrs() const;
mutable QHash<QString, Feed*> m_feeds; // hash of pointers to all feeds in db, key = url (lazy loading)
mutable QHash<QString, Entry*> m_entries; // hash of pointers to all entries in db, key = id (lazy loading)
mutable QHash<QString, Feed *> m_feeds; // hash of pointers to all feeds in db, key = url (lazy loading)
mutable QHash<QString, Entry *> m_entries; // hash of pointers to all entries in db, key = id (lazy loading)
QStringList m_feedmap; // list of feedurls in the order that they should appear in feedlist
QHash<QString, QStringList> m_entrymap; // list of entries (per feed; key = url) in the order that they should appear in entrylist

View File

@ -7,7 +7,6 @@
#include "downloadprogressmodel.h"
#include "datamanager.h"
DownloadProgressModel::DownloadProgressModel()
: QAbstractListModel(nullptr)
{
@ -34,18 +33,18 @@ int DownloadProgressModel::rowCount(const QModelIndex &parent) const
return m_entries.count();
}
void DownloadProgressModel::monitorDownloadProgress(Entry* entry, Enclosure::Status status)
void DownloadProgressModel::monitorDownloadProgress(Entry *entry, Enclosure::Status status)
{
//qDebug() << "download status changed:" << entry->title() << status;
// qDebug() << "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();
// qDebug() << "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;
// qDebug() << "removing dowloading entry" << entry->id() << "in position" << index;
beginRemoveRows(QModelIndex(), index, index);
m_entries.removeAt(index);
endRemoveRows();

View File

@ -11,8 +11,8 @@
#include <QObject>
#include <QVariant>
#include "entry.h"
#include "enclosure.h"
#include "entry.h"
class DownloadProgressModel : public QAbstractListModel
{
@ -30,7 +30,7 @@ public:
int rowCount(const QModelIndex &parent) const override;
public Q_SLOTS:
void monitorDownloadProgress(Entry* entry, Enclosure::Status status);
void monitorDownloadProgress(Entry *entry, Enclosure::Status status);
private:
explicit DownloadProgressModel();

View File

@ -13,11 +13,11 @@
#include "database.h"
#include "datamanager.h"
#include "downloadprogressmodel.h"
#include "enclosuredownloadjob.h"
#include "entry.h"
#include "fetcher.h"
#include "downloadprogressmodel.h"
#include "errorlogmodel.h"
#include "fetcher.h"
Enclosure::Enclosure(Entry *entry)
: QObject(entry)
@ -28,7 +28,7 @@ Enclosure::Enclosure(Entry *entry)
Q_EMIT downloadStatusChanged(m_entry, m_status);
});
connect(this, &Enclosure::downloadStatusChanged, &DownloadProgressModel::instance(), &DownloadProgressModel::monitorDownloadProgress);
connect(this,&Enclosure::downloadError, &ErrorLogModel::instance(), &ErrorLogModel::monitorErrorMessages);
connect(this, &Enclosure::downloadError, &ErrorLogModel::instance(), &ErrorLogModel::monitorErrorMessages);
QSqlQuery query;
query.prepare(QStringLiteral("SELECT * FROM Enclosures WHERE id=:id"));
@ -52,7 +52,7 @@ Enclosure::Enclosure(Entry *entry)
// something changed on disk
QFile file(path());
if (file.exists()) {
if(file.size() == m_size && file.size() > 0) {
if (file.size() == m_size && file.size() > 0) {
if (m_status == Downloadable) {
// file is on disk, but was not expected, write to database
// this should never happen
@ -100,11 +100,11 @@ void Enclosure::download()
m_entry->feed()->setErrorString(QString());
connect(downloadJob, &KJob::result, this, [this, downloadJob]() {
if(downloadJob->error() == 0) {
if (downloadJob->error() == 0) {
processDownloadedFile();
} else {
m_status = Downloadable;
if(downloadJob->error() != QNetworkReply::OperationCanceledError) {
if (downloadJob->error() != QNetworkReply::OperationCanceledError) {
m_entry->feed()->setErrorId(downloadJob->error());
m_entry->feed()->setErrorString(downloadJob->errorString());
Q_EMIT downloadError(m_entry->feed()->url(), m_entry->id(), downloadJob->error(), downloadJob->errorString());
@ -122,7 +122,7 @@ void Enclosure::download()
disconnect(this, &Enclosure::cancelDownload, this, nullptr);
});
connect(downloadJob, &KJob::percentChanged, this, [=](KJob*, unsigned long percent) {
connect(downloadJob, &KJob::percentChanged, this, [=](KJob *, unsigned long percent) {
m_downloadProgress = percent;
Q_EMIT downloadProgressChanged();
});
@ -131,7 +131,8 @@ void Enclosure::download()
Q_EMIT statusChanged();
}
void Enclosure::processDownloadedFile() {
void Enclosure::processDownloadedFile()
{
// This will be run if the enclosure has been downloaded successfully
// First check if file size is larger than 0; otherwise something unexpected
@ -145,7 +146,7 @@ void Enclosure::processDownloadedFile() {
// Check if reported filesize in rss feed corresponds to real file size
// if not, correct the filesize in the database
// otherwise the file will get deleted because of mismatch in signature
if(file.size() != m_size) {
if (file.size() != m_size) {
qDebug() << "enclosure file size mismatch" << m_entry->title();
setSize(file.size());
}
@ -157,14 +158,15 @@ void Enclosure::processDownloadedFile() {
query.bindValue(QStringLiteral(":downloaded"), true);
Database::instance().execute(query);
// Unset "new" status of item
if (m_entry->getNew()) m_entry->setNew(false);
if (m_entry->getNew())
m_entry->setNew(false);
Q_EMIT DataManager::instance().downloadCountChanged(m_entry->feed()->url());
}
void Enclosure::deleteFile()
{
//qDebug() << "Trying to delete enclosure file" << path();
// qDebug() << "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();
@ -207,12 +209,12 @@ int Enclosure::size() const
void Enclosure::setPlayPosition(const qint64 &position)
{
m_playposition = position;
//qDebug() << "save playPosition" << position << m_entry->title();
// qDebug() << "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();
// qDebug() << "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());
@ -229,7 +231,7 @@ void Enclosure::setDuration(const qint64 &duration)
Q_EMIT durationChanged();
// also save to database
//qDebug() << "updating entry duration" << duration << m_entry->title();
// qDebug() << "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

@ -58,11 +58,10 @@ Q_SIGNALS:
void playPositionChanged();
void durationChanged();
void sizeChanged();
void downloadStatusChanged(Entry* entry, Status status);
void downloadStatusChanged(Entry *entry, Status status);
void downloadError(const QString &url, const QString &id, const int errorId, const QString &errorString);
private:
void processDownloadedFile();
Entry *m_entry;

View File

@ -12,7 +12,7 @@
#include "enclosuredownloadjob.h"
#include "fetcher.h"
EnclosureDownloadJob::EnclosureDownloadJob(const QString& url, const QString& filename, const QString& title, QObject *parent)
EnclosureDownloadJob::EnclosureDownloadJob(const QString &url, const QString &filename, const QString &title, QObject *parent)
: KJob(parent)
, m_url(url)
, m_filename(filename)
@ -49,7 +49,6 @@ void EnclosureDownloadJob::startDownload()
bool EnclosureDownloadJob::doKill()
{
m_reply->abort();
return true;
m_reply->abort();
return true;
}

View File

@ -11,7 +11,6 @@
class EnclosureDownloadJob : public KJob
{
public:
explicit EnclosureDownloadJob(const QString &url, const QString &filename, const QString &title, QObject *parent = nullptr);

View File

@ -7,9 +7,9 @@
#include <QString>
#include "datamanager.h"
#include "entriesmodel.h"
#include "entry.h"
#include "datamanager.h"
EntriesModel::EntriesModel(Feed *feed)
: QAbstractListModel(feed)
@ -30,7 +30,7 @@ QVariant EntriesModel::data(const QModelIndex &index, int role) const
{
if (role != 0)
return QVariant();
//qDebug() << "fetching item" << index.row();
// qDebug() << "fetching item" << index.row();
return QVariant::fromValue(DataManager::instance().getEntry(m_feed, index.row()));
}
@ -47,7 +47,7 @@ int EntriesModel::rowCount(const QModelIndex &parent) const
return DataManager::instance().entryCount(m_feed);
}
Feed* EntriesModel::feed() const
Feed *EntriesModel::feed() const
{
return m_feed;
}

View File

@ -8,9 +8,9 @@
#pragma once
#include <QAbstractListModel>
#include <QVariant>
#include <QHash>
#include <QObject>
#include <QVariant>
#include "feed.h"

View File

@ -20,7 +20,7 @@ Entry::Entry(Feed *feed, const QString &id)
, m_feed(feed)
{
connect(&Fetcher::instance(), &Fetcher::downloadFinished, this, [this](QString url) {
if(url == m_image) {
if (url == m_image) {
Q_EMIT imageChanged(url);
Q_EMIT cachedImageChanged(cachedImage());
} else if (m_image.isEmpty() && url == m_feed->image()) {
@ -30,12 +30,12 @@ Entry::Entry(Feed *feed, const QString &id)
});
connect(&DataManager::instance(), &DataManager::queueEntryAdded, this, [this](const int &index, const QString &id) {
Q_UNUSED(index)
if(id == m_id)
if (id == m_id)
Q_EMIT queueStatusChanged(queueStatus());
});
connect(&DataManager::instance(), &DataManager::queueEntryRemoved, this, [this](const int &index, const QString &id) {
Q_UNUSED(index)
if(id == m_id)
if (id == m_id)
Q_EMIT queueStatusChanged(queueStatus());
});
QSqlQuery entryQuery;
@ -52,7 +52,10 @@ Entry::Entry(Feed *feed, const QString &id)
Database::instance().execute(authorQuery);
while (authorQuery.next()) {
m_authors += new Author(authorQuery.value(QStringLiteral("name")).toString(), authorQuery.value(QStringLiteral("email")).toString(), authorQuery.value(QStringLiteral("uri")).toString(), nullptr);
m_authors += new Author(authorQuery.value(QStringLiteral("name")).toString(),
authorQuery.value(QStringLiteral("email")).toString(),
authorQuery.value(QStringLiteral("uri")).toString(),
nullptr);
}
m_created.setSecsSinceEpoch(entryQuery.value(QStringLiteral("created")).toInt());
@ -139,7 +142,7 @@ void Entry::setRead(bool read)
Database::instance().execute(query);
Q_EMIT m_feed->unreadEntryCountChanged();
Q_EMIT DataManager::instance().unreadEntryCountChanged(m_feed->url());
//TODO: can one of the two slots be removed??
// TODO: can one of the two slots be removed??
}
void Entry::setNew(bool state)

View File

@ -7,7 +7,6 @@
#include "episodemodel.h"
#include "datamanager.h"
EpisodeModel::EpisodeModel()
: QAbstractListModel(nullptr)
{
@ -65,8 +64,7 @@ void EpisodeModel::setType(EpisodeModel::Type type)
beginResetModel();
endResetModel();
});
}
else if (m_type == EpisodeModel::Downloaded) { // TODO: this needs to be removed !!!!!!
} else if (m_type == EpisodeModel::Downloaded) { // TODO: this needs to be removed !!!!!!
connect(&DataManager::instance(), &DataManager::downloadCountChanged, this, [this](const QString &url) {
Q_UNUSED(url)
// we have to reset the entire model in case entries are removed or added

View File

@ -6,10 +6,10 @@
#pragma once
#include "datamanager.h"
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QDateTime>
#include "datamanager.h"
class Error : public QObject
{
@ -23,7 +23,8 @@ class Error : public QObject
Q_PROPERTY(QString title READ title CONSTANT)
public:
Error(const QString url, const QString id, const int code, const QString message, const QDateTime date): QObject(nullptr)
Error(const QString url, const QString id, const int code, const QString message, const QDateTime date)
: QObject(nullptr)
{
this->url = url;
this->id = id;

View File

@ -8,10 +8,9 @@
#include <QSqlQuery>
#include "fetcher.h"
#include "database.h"
#include "datamanager.h"
#include "fetcher.h"
ErrorLogModel::ErrorLogModel()
: QAbstractListModel(nullptr)
@ -25,7 +24,11 @@ ErrorLogModel::ErrorLogModel()
QString id = query.value(QStringLiteral("id")).toString();
QString url = query.value(QStringLiteral("url")).toString();
Error* error = new Error(url, id, query.value(QStringLiteral("code")).toInt(), query.value(QStringLiteral("message")).toString(), QDateTime::fromSecsSinceEpoch(query.value(QStringLiteral("date")).toInt()));
Error *error = new Error(url,
id,
query.value(QStringLiteral("code")).toInt(),
query.value(QStringLiteral("message")).toString(),
QDateTime::fromSecsSinceEpoch(query.value(QStringLiteral("date")).toInt()));
m_errors += error;
}
}
@ -51,12 +54,12 @@ int ErrorLogModel::rowCount(const QModelIndex &parent) const
return m_errors.count();
}
void ErrorLogModel::monitorErrorMessages(const QString &url, const QString& id, const int errorCode, const QString& errorString)
void ErrorLogModel::monitorErrorMessages(const QString &url, const QString &id, const int errorCode, const QString &errorString)
{
qDebug() << "Error happened:" << url << id << errorCode << errorString;
QString title;
Error* error = new Error(url, id, errorCode, errorString, QDateTime::currentDateTime());
Error *error = new Error(url, id, errorCode, errorString, QDateTime::currentDateTime());
beginInsertRows(QModelIndex(), 0, 0);
m_errors.prepend(error);
endInsertRows();
@ -75,7 +78,7 @@ void ErrorLogModel::monitorErrorMessages(const QString &url, const QString& id,
void ErrorLogModel::clearAll()
{
beginResetModel();
for (auto& error : m_errors) {
for (auto &error : m_errors) {
delete error;
}
m_errors.clear();

View File

@ -7,10 +7,10 @@
#pragma once
#include <QAbstractListModel>
#include <QDateTime>
#include <QHash>
#include <QObject>
#include <QVariant>
#include <QDateTime>
#include "error.h"
@ -37,5 +37,5 @@ public:
private:
explicit ErrorLogModel();
QList<Error*> m_errors;
QList<Error *> m_errors;
};

View File

@ -16,7 +16,6 @@
Feed::Feed(const QString &feedurl)
: QObject(nullptr)
{
QSqlQuery query;
query.prepare(QStringLiteral("SELECT * FROM Feeds WHERE url=:feedurl;"));
query.bindValue(QStringLiteral(":feedurl"), feedurl);
@ -60,19 +59,19 @@ Feed::Feed(const QString &feedurl)
});
connect(&Fetcher::instance(), &Fetcher::error, this, [this](const QString &url, const QString &id, int errorId, const QString &errorString) {
Q_UNUSED(id)
if(url == m_url) {
if (url == m_url) {
setErrorId(errorId);
setErrorString(errorString);
setRefreshing(false);
}
});
connect(&Fetcher::instance(), &Fetcher::feedUpdateFinished, this, [this](const QString &url) {
if(url == m_url) {
if (url == m_url) {
setRefreshing(false);
}
});
connect(&Fetcher::instance(), &Fetcher::downloadFinished, this, [this](QString url) {
if(url == m_image) {
if (url == m_image) {
Q_EMIT imageChanged(url);
Q_EMIT cachedImageChanged(cachedImage());
}
@ -100,12 +99,10 @@ 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;
for (int i=0; i < m_authors.count(); i++) {
//qDebug() << "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) {
// qDebug() << 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();
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];
}
@ -118,7 +115,7 @@ void Feed::updateAuthors()
// Finally check whether m_authors and newAuthors are identical
// if not, then delete the authors that were removed
for (int i=0; i < m_authors.count(); i++) {
for (int i = 0; i < m_authors.count(); i++) {
if (!newAuthors.contains(m_authors[i])) {
delete m_authors[i];
haveAuthorsChanged = true;
@ -127,8 +124,9 @@ void Feed::updateAuthors()
m_authors = newAuthors;
if (haveAuthorsChanged) Q_EMIT authorsChanged(m_authors);
//qDebug() << "feed" << m_name << "authors have changed?" << haveAuthorsChanged;
if (haveAuthorsChanged)
Q_EMIT authorsChanged(m_authors);
// qDebug() << "feed" << m_name << "authors have changed?" << haveAuthorsChanged;
}
QString Feed::url() const
@ -265,7 +263,7 @@ void Feed::setDescription(const QString &description)
void Feed::setAuthors(const QVector<Author *> &authors)
{
for (auto& author : m_authors) {
for (auto &author : m_authors) {
delete author;
}
m_authors.clear();

View File

@ -56,7 +56,7 @@ void FeedsModel::removeFeed(int index)
void FeedsModel::refreshAll()
{
// for (auto &feed : m_feeds) {
// feed->refresh();
// }
// for (auto &feed : m_feeds) {
// feed->refresh();
// }
}

View File

@ -8,15 +8,15 @@
#include <QCryptographicHash>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QDomElement>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QMultiMap>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QStandardPaths>
#include <QTextDocumentFragment>
#include <QDomElement>
#include <QMultiMap>
#include <Syndication/Syndication>
@ -44,7 +44,8 @@ void Fetcher::fetch(const QString &url)
void Fetcher::fetch(const QStringList &urls)
{
if (m_updating) return; // update is already running, do nothing
if (m_updating)
return; // update is already running, do nothing
m_updating = true;
m_updateProgress = 0;
@ -54,7 +55,7 @@ void Fetcher::fetch(const QStringList &urls)
Q_EMIT updateProgressChanged(m_updateProgress);
Q_EMIT updateTotalChanged(m_updateTotal);
for (int i=0; i<urls.count(); i++) {
for (int i = 0; i < urls.count(); i++) {
retrieveFeed(urls[i]);
}
}
@ -66,7 +67,8 @@ void Fetcher::fetchAll()
query.prepare(QStringLiteral("SELECT url FROM Feeds;"));
Database::instance().execute(query);
while (query.next()) {
urls += query.value(0).toString();;
urls += query.value(0).toString();
;
}
if (urls.count() > 0) {
@ -84,7 +86,7 @@ void Fetcher::retrieveFeed(const QString &url)
request.setTransferTimeout();
QNetworkReply *reply = get(request);
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
if(reply->error()) {
if (reply->error()) {
qWarning() << "Error fetching feed";
qWarning() << reply->errorString();
Q_EMIT error(url, QString(), reply->error(), reply->errorString());
@ -102,7 +104,7 @@ void Fetcher::retrieveFeed(const QString &url)
void Fetcher::updateMonitor(int progress)
{
//qDebug() << "Update monitor" << progress << "/" << m_updateTotal;
// qDebug() << "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;
@ -110,8 +112,8 @@ void Fetcher::updateMonitor(int progress)
m_updateTotal = -1;
disconnect(this, &Fetcher::updateProgressChanged, this, &Fetcher::updateMonitor);
Q_EMIT updatingChanged(m_updating);
//Q_EMIT updateProgressChanged(m_updateProgress);
//Q_EMIT updateTotalChanged(m_updateTotal);
// Q_EMIT updateProgressChanged(m_updateProgress);
// Q_EMIT updateTotalChanged(m_updateTotal);
}
}
@ -132,12 +134,14 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
qDebug() << "Feed not found in database" << url;
return;
}
if (isNewFeed) qDebug() << "New feed" << feed->title() << ":" << isNewFeed;
if (isNewFeed)
qDebug() << "New feed" << feed->title() << ":" << isNewFeed;
// Retrieve "other" fields; this will include the "itunes" tags
QMultiMap<QString, QDomElement> otherItems = feed->additionalProperties();
query.prepare(QStringLiteral("UPDATE Feeds SET name=:name, image=:image, link=:link, description=:description, lastUpdated=:lastUpdated, new=:new WHERE url=:url;"));
query.prepare(
QStringLiteral("UPDATE Feeds SET name=:name, image=:image, link=:link, description=:description, lastUpdated=:lastUpdated, new=:new WHERE url=:url;"));
query.bindValue(QStringLiteral(":name"), feed->title());
query.bindValue(QStringLiteral(":url"), url);
query.bindValue(QStringLiteral(":link"), feed->link());
@ -168,14 +172,13 @@ 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;
// qDebug() << "authorname" << authorname;
}
if (!authorname.isEmpty()) {
processAuthor(url, QLatin1String(""), authorname, QLatin1String(""), authoremail);
}
}
QString image = feed->image()->url();
// If there is no regular image tag, then try the itunes tags
if (image.isEmpty()) {
@ -207,7 +210,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();
// qDebug() << "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);
@ -217,13 +220,14 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
}
}
if (updatedEntries || isNewFeed) Q_EMIT feedUpdated(url);
if (updatedEntries || isNewFeed)
Q_EMIT feedUpdated(url);
Q_EMIT feedUpdateFinished(url);
}
bool Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, bool isNewFeed)
{
//qDebug() << "Processing" << entry->title();
// qDebug() << "Processing" << entry->title();
// Retrieve "other" fields; this will include the "itunes" tags
QMultiMap<QString, QDomElement> otherItems = entry->additionalProperties();
@ -235,7 +239,7 @@ bool Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, bool
query.next();
if (query.value(0).toInt() != 0)
return false; // entry already exists
return false; // entry already exists
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated, :link, :read, :new, :hasEnclosure, :image);"));
query.bindValue(QStringLiteral(":feed"), url);
@ -261,7 +265,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;
// qDebug() << "Entry image found" << image;
Database::instance().execute(query);
@ -272,7 +276,8 @@ bool Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, bool
} else {
// As fallback, check if there is itunes "author" information
QString authorName = otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdauthor")).text();
if (!authorName.isEmpty()) processAuthor(url, entry->id(), authorName, QLatin1String(""), QLatin1String(""));
if (!authorName.isEmpty())
processAuthor(url, entry->id(), authorName, QLatin1String(""), QLatin1String(""));
}
for (const auto &enclosure : entry->enclosures()) {
@ -332,11 +337,11 @@ void Fetcher::processEnclosure(Syndication::EnclosurePtr enclosure, Syndication:
Database::instance().execute(query);
}
QString Fetcher::image(const QString& url) const
QString Fetcher::image(const QString &url) const
{
QString path = imagePath(url);
if (QFileInfo::exists(path)) {
if (QFileInfo(path).size() != 0 )
if (QFileInfo(path).size() != 0)
return path;
}
@ -380,7 +385,6 @@ QString Fetcher::imagePath(const QString &url) const
return path + QString::fromStdString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex().toStdString());
}
QString Fetcher::enclosurePath(const QString &url) const
{
QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QStringLiteral("/enclosures/");

View File

@ -41,7 +41,12 @@ public:
Q_SIGNALS:
void startedFetchingFeed(const QString &url);
void feedUpdated(const QString &url);
void feedDetailsUpdated(const QString &url, const QString &name, const QString &image, const QString &link, const QString &description, const QDateTime &lastUpdated);
void feedDetailsUpdated(const QString &url,
const QString &name,
const QString &image,
const QString &link,
const QString &description,
const QDateTime &lastUpdated);
void feedUpdateFinished(const QString &url);
void error(const QString &url, const QString &id, const int errorId, const QString &errorString);
void entryAdded(const QString &feedurl, const QString &id);
@ -59,14 +64,12 @@ private:
void retrieveFeed(const QString &url);
void processFeed(Syndication::FeedPtr feed, const QString &url);
bool processEntry(Syndication::ItemPtr entry, const QString &url, bool isNewFeed); // returns true if this is a new entry; false if it already existed
bool processEntry(Syndication::ItemPtr entry, const QString &url, bool isNewFeed); // returns true if this is a new entry; false if it already existed
void processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail);
void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl);
QNetworkAccessManager *manager;
int m_updateProgress;
int m_updateTotal;
bool m_updating;
};

View File

@ -5,12 +5,11 @@
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include <QCommandLineParser>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickView>
#include <QQuickStyle>
#include <QQuickView>
#ifdef Q_OS_ANDROID
#include <QGuiApplication>
@ -23,18 +22,18 @@
#include <KLocalizedString>
#include "alligator-version.h"
#include "settingsmanager.h"
#include "audiomanager.h"
#include "database.h"
#include "datamanager.h"
#include "downloadprogressmodel.h"
#include "entriesmodel.h"
#include "episodemodel.h"
#include "errorlogmodel.h"
#include "feedsmodel.h"
#include "fetcher.h"
#include "queuemodel.h"
#include "episodemodel.h"
#include "downloadprogressmodel.h"
#include "errorlogmodel.h"
#include "datamanager.h"
#include "audiomanager.h"
#include "mpris2/mpris2.h"
#include "queuemodel.h"
#include "settingsmanager.h"
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
@ -84,7 +83,7 @@ int main(int argc, char *argv[])
qmlRegisterType<AudioManager>("org.kde.alligator", 1, 0, "AudioManager");
qmlRegisterType<Mpris2>("org.kde.alligator", 1, 0, "Mpris2");
qRegisterMetaType<Entry*>("const Entry*"); // "hack" to make qml understand Entry*
qRegisterMetaType<Entry *>("const Entry*"); // "hack" to make qml understand Entry*
QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
@ -93,7 +92,12 @@ int main(int argc, char *argv[])
QCommandLineParser parser;
parser.setApplicationDescription(i18n("RSS/Atom Feed Reader"));
KAboutData about(QStringLiteral("alligator"), i18n("Alligator"), QStringLiteral(ALLIGATOR_VERSION_STRING), i18n("Feed Reader"), KAboutLicense::GPL, i18n("© 2020-2021 KDE Community"));
KAboutData about(QStringLiteral("alligator"),
i18n("Alligator"),
QStringLiteral(ALLIGATOR_VERSION_STRING),
i18n("Feed Reader"),
KAboutLicense::GPL,
i18n("© 2020-2021 KDE Community"));
about.addAuthor(i18n("Tobias Fella"), QString(), QStringLiteral("fella@posteo.de"));
about.addAuthor(i18n("Bart De Vries"), QString(), QStringLiteral("bart@mogwai.be"));
KAboutData::setApplicationData(about);

View File

@ -12,13 +12,12 @@
#include <KCoreAddons/KAboutData>
MediaPlayer2::MediaPlayer2(QObject* parent)
MediaPlayer2::MediaPlayer2(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
}
MediaPlayer2::~MediaPlayer2()
= default;
MediaPlayer2::~MediaPlayer2() = default;
bool MediaPlayer2::CanQuit() const
{
@ -61,11 +60,11 @@ QStringList MediaPlayer2::SupportedUriSchemes() const
QStringList MediaPlayer2::SupportedMimeTypes() const
{
// KService::Ptr app = KService::serviceByDesktopName(KCmdLineArgs::aboutData()->appName());
// KService::Ptr app = KService::serviceByDesktopName(KCmdLineArgs::aboutData()->appName());
// if (app) {
// return app->mimeTypes();
// }
// if (app) {
// return app->mimeTypes();
// }
return QStringList();
}

View File

@ -11,7 +11,6 @@
#include <QDBusAbstractAdaptor>
#include <QStringList>
class MediaPlayer2 : public QDBusAbstractAdaptor
{
Q_OBJECT
@ -20,15 +19,13 @@ class MediaPlayer2 : public QDBusAbstractAdaptor
Q_PROPERTY(bool CanQuit READ CanQuit CONSTANT)
Q_PROPERTY(bool CanRaise READ CanRaise CONSTANT)
Q_PROPERTY(bool HasTrackList READ HasTrackList CONSTANT)
Q_PROPERTY(QString Identity READ Identity CONSTANT)
Q_PROPERTY(QString DesktopEntry READ DesktopEntry CONSTANT)
Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes CONSTANT)
Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes CONSTANT)
public:
explicit MediaPlayer2(QObject* parent = nullptr);
explicit MediaPlayer2(QObject *parent = nullptr);
~MediaPlayer2() override;
[[nodiscard]] bool CanQuit() const;
@ -47,5 +44,4 @@ public Q_SLOTS:
Q_SIGNALS:
void raisePlayer();
};

View File

@ -9,60 +9,47 @@
#include "mediaplayer2player.h"
#include "mpris2.h"
#include "fetcher.h"
#include "datamanager.h"
#include "audiomanager.h"
#include "datamanager.h"
#include "fetcher.h"
#include <QCryptographicHash>
#include <QStringList>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QStringList>
MediaPlayer2Player::MediaPlayer2Player(AudioManager *audioPlayer, bool showProgressOnTaskBar, QObject* parent)
: QDBusAbstractAdaptor(parent), m_audioPlayer(audioPlayer),
mProgressIndicatorSignal(QDBusMessage::createSignal(QStringLiteral("/org/kde/alligator"),
QStringLiteral("com.canonical.Unity.LauncherEntry"),
QStringLiteral("Update"))),
mShowProgressOnTaskBar(showProgressOnTaskBar)
MediaPlayer2Player::MediaPlayer2Player(AudioManager *audioPlayer, bool showProgressOnTaskBar, QObject *parent)
: QDBusAbstractAdaptor(parent)
, m_audioPlayer(audioPlayer)
, mProgressIndicatorSignal(
QDBusMessage::createSignal(QStringLiteral("/org/kde/alligator"), QStringLiteral("com.canonical.Unity.LauncherEntry"), QStringLiteral("Update")))
, mShowProgressOnTaskBar(showProgressOnTaskBar)
{
// This will signal when the track is changed
connect(m_audioPlayer, &AudioManager::entryChanged,
this, &MediaPlayer2Player::setEntry);
connect(m_audioPlayer, &AudioManager::entryChanged, this, &MediaPlayer2Player::setEntry);
// Signals from AudioManager which are directly forwarded
connect(m_audioPlayer, &AudioManager::playbackRateChanged,
this, &MediaPlayer2Player::rateChanged);
connect(m_audioPlayer, &AudioManager::playbackRateChanged, this, &MediaPlayer2Player::rateChanged);
// TODO: implement this in AudioManager, such that it can be forwarded
//connect(m_audioPlayer, &AudioManager::minimumRateChanged,
// connect(m_audioPlayer, &AudioManager::minimumRateChanged,
// this, &MediaPlayer2Player::mimimumRateChanged);
//connect(m_audioPlayer, &AudioManager::maximumRateChanged,
// connect(m_audioPlayer, &AudioManager::maximumRateChanged,
// this, &MediaPlayer2Player::maximumRateChanged);
connect(m_audioPlayer, &AudioManager::seekableChanged,
this, &MediaPlayer2Player::canSeekChanged);
connect(m_audioPlayer, &AudioManager::seekableChanged, this, &MediaPlayer2Player::canSeekChanged);
// Signals which are semi-wrapped signals from AudioManager
connect(m_audioPlayer, &AudioManager::playbackStateChanged,
this, &MediaPlayer2Player::playerPlaybackStateChanged);
connect(m_audioPlayer, &AudioManager::volumeChanged,
this, &MediaPlayer2Player::playerVolumeChanged);
connect(m_audioPlayer, &AudioManager::positionChanged,
this, &MediaPlayer2Player::playerSeeked); // Implement Seeked signal
connect(m_audioPlayer, &AudioManager::canSkipForwardChanged,
this, &MediaPlayer2Player::playerCanGoNextChanged);
connect(m_audioPlayer, &AudioManager::canSkipBackwardChanged,
this, &MediaPlayer2Player::playerCanGoPreviousChanged);
connect(m_audioPlayer, &AudioManager::canPlayChanged,
this, &MediaPlayer2Player::playerCanPlayChanged);
connect(m_audioPlayer, &AudioManager::canPauseChanged,
this, &MediaPlayer2Player::playerCanPauseChanged);
connect(m_audioPlayer, &AudioManager::seekableChanged,
this, &MediaPlayer2Player::playerCanSeekChanged);
connect(m_audioPlayer, &AudioManager::playbackStateChanged, this, &MediaPlayer2Player::playerPlaybackStateChanged);
connect(m_audioPlayer, &AudioManager::volumeChanged, this, &MediaPlayer2Player::playerVolumeChanged);
connect(m_audioPlayer, &AudioManager::positionChanged, this, &MediaPlayer2Player::playerSeeked); // Implement Seeked signal
connect(m_audioPlayer, &AudioManager::canSkipForwardChanged, this, &MediaPlayer2Player::playerCanGoNextChanged);
connect(m_audioPlayer, &AudioManager::canSkipBackwardChanged, this, &MediaPlayer2Player::playerCanGoPreviousChanged);
connect(m_audioPlayer, &AudioManager::canPlayChanged, this, &MediaPlayer2Player::playerCanPlayChanged);
connect(m_audioPlayer, &AudioManager::canPauseChanged, this, &MediaPlayer2Player::playerCanPauseChanged);
connect(m_audioPlayer, &AudioManager::seekableChanged, this, &MediaPlayer2Player::playerCanSeekChanged);
// signals needed for progress indicator on taskbar
connect(m_audioPlayer, &AudioManager::durationChanged,
this, &MediaPlayer2Player::audioDurationChanged);
connect(m_audioPlayer, &AudioManager::positionChanged,
this, &MediaPlayer2Player::audioPositionChanged);
connect(m_audioPlayer, &AudioManager::durationChanged, this, &MediaPlayer2Player::audioDurationChanged);
connect(m_audioPlayer, &AudioManager::positionChanged, this, &MediaPlayer2Player::audioPositionChanged);
if (m_audioPlayer) {
m_volume = m_audioPlayer->volume() / 100;
@ -74,8 +61,7 @@ MediaPlayer2Player::MediaPlayer2Player(AudioManager *audioPlayer, bool showProgr
}
}
MediaPlayer2Player::~MediaPlayer2Player()
= default;
MediaPlayer2Player::~MediaPlayer2Player() = default;
QString MediaPlayer2Player::PlaybackStatus() const
{
@ -130,7 +116,6 @@ bool MediaPlayer2Player::CanGoPrevious() const
return false;
}
void MediaPlayer2Player::Previous()
{
if (m_audioPlayer)
@ -187,10 +172,10 @@ double MediaPlayer2Player::Volume() const
void MediaPlayer2Player::setVolume(double volume)
{
if (m_audioPlayer) {
m_volume= qBound(0.0, volume, 1.0);
m_volume = qBound(0.0, volume, 1.0);
emit volumeChanged(m_volume);
m_audioPlayer->setVolume(100 * m_volume);
m_audioPlayer->setVolume(100 * m_volume);
signalPropertiesChange(QStringLiteral("Volume"), Volume());
}
@ -296,7 +281,7 @@ void MediaPlayer2Player::audioPositionChanged()
void MediaPlayer2Player::audioDurationChanged()
{
//qDebug() << "Signal change of audio duration through MPRIS2";
// qDebug() << "Signal change of audio duration through MPRIS2";
// We reset all metadata in case the audioDuration changed
// This is done because duration is not yet available when setEntry is
// called (this is before the QMediaPlayer has read the new track
@ -322,34 +307,34 @@ void MediaPlayer2Player::playerVolumeChanged()
void MediaPlayer2Player::playerCanPlayChanged()
{
signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay());
//Q_EMIT canPlayChanged();
// Q_EMIT canPlayChanged();
}
void MediaPlayer2Player::playerCanPauseChanged()
{
signalPropertiesChange(QStringLiteral("CanPause"), CanPause());
//Q_EMIT canPauseChanged();
// Q_EMIT canPauseChanged();
}
void MediaPlayer2Player::playerCanGoNextChanged()
{
signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext());
//Q_EMIT canGoNextChanged();
// Q_EMIT canGoNextChanged();
}
void MediaPlayer2Player::playerCanGoPreviousChanged()
{
signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoNext());
//Q_EMIT canGoPreviousChanged();
// Q_EMIT canGoPreviousChanged();
}
void MediaPlayer2Player::playerCanSeekChanged()
{
signalPropertiesChange(QStringLiteral("CanSeek"), CanSeek());
//Q_EMIT canSeekChanged();
// Q_EMIT canSeekChanged();
}
void MediaPlayer2Player::setEntry(Entry* entry)
void MediaPlayer2Player::setEntry(Entry *entry)
{
if (entry == nullptr)
return;
@ -358,7 +343,7 @@ void MediaPlayer2Player::setEntry(Entry* entry)
if (m_audioPlayer->entry()) {
if (m_audioPlayer->entry() == entry) {
int queuenr = DataManager::instance().queue().indexOf(m_audioPlayer->entry()->id());
//qDebug() << "MPRIS2: Setting entry" << entry->title();
// qDebug() << "MPRIS2: Setting entry" << entry->title();
m_currentTrackId = QDBusObjectPath(QLatin1String("/org/kde/alligator/playlist/") + QString::number(queuenr)).path();
m_metadata = getMetadataOfCurrentTrack();
@ -384,11 +369,11 @@ QVariantMap MediaPlayer2Player::getMetadataOfCurrentTrack()
return {};
}
Entry* entry = m_audioPlayer->entry();
Entry *entry = m_audioPlayer->entry();
result[QStringLiteral("mpris:trackid")] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(m_currentTrackId));
result[QStringLiteral("mpris:length")] = qlonglong(m_audioPlayer->duration()) * 1000;
//convert milli-seconds into micro-seconds
// convert milli-seconds into micro-seconds
if (!entry->title().isEmpty()) {
result[QStringLiteral("xesam:title")] = entry->title();
}
@ -398,7 +383,8 @@ QVariantMap MediaPlayer2Player::getMetadataOfCurrentTrack()
}
if (entry->authors().count() > 0) {
QStringList authors;
for (auto &author : entry->authors()) authors.append(author->name());
for (auto &author : entry->authors())
authors.append(author->name());
result[QStringLiteral("xesam:artist")] = authors;
}
if (!entry->image().isEmpty()) {
@ -417,8 +403,7 @@ void MediaPlayer2Player::setPropertyPosition(int newPositionInMs)
* to limit DBus traffic
*/
const auto incrementalProgress = static_cast<double>(newPositionInMs - mPreviousProgressPosition) / m_audioPlayer->duration();
if (mShowProgressOnTaskBar && (incrementalProgress > 0.01 || incrementalProgress < 0))
{
if (mShowProgressOnTaskBar && (incrementalProgress > 0.01 || incrementalProgress < 0)) {
mPreviousProgressPosition = newPositionInMs;
QVariantMap parameters;
parameters.insert(QStringLiteral("progress-visible"), true);
@ -436,7 +421,8 @@ void MediaPlayer2Player::signalPropertiesChange(const QString &property, const Q
properties[property] = value;
const int ifaceIndex = metaObject()->indexOfClassInfo("D-Bus Interface");
QDBusMessage msg = QDBusMessage::createSignal(QStringLiteral("/org/mpris/MediaPlayer2"),
QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"));
QStringLiteral("org.freedesktop.DBus.Properties"),
QStringLiteral("PropertiesChanged"));
msg << QLatin1String(metaObject()->classInfo(ifaceIndex).value());
msg << properties;

View File

@ -9,8 +9,8 @@
#pragma once
#include <QDBusAbstractAdaptor>
#include <QDBusObjectPath>
#include <QDBusMessage>
#include <QDBusObjectPath>
class AudioManager;
class Entry;
@ -35,9 +35,7 @@ class MediaPlayer2Player : public QDBusAbstractAdaptor
Q_PROPERTY(bool CanSeek READ CanSeek NOTIFY canSeekChanged)
public:
explicit MediaPlayer2Player(AudioManager *audioPlayer,
bool showProgressOnTaskBar,
QObject* parent = nullptr);
explicit MediaPlayer2Player(AudioManager *audioPlayer, bool showProgressOnTaskBar, QObject *parent = nullptr);
~MediaPlayer2Player() override;
QString PlaybackStatus() const;
@ -105,7 +103,7 @@ private Q_SLOTS:
private:
void signalPropertiesChange(const QString &property, const QVariant &value);
void setEntry(Entry* entry);
void setEntry(Entry *entry);
QVariantMap getMetadataOfCurrentTrack();
@ -114,7 +112,6 @@ private:
QString m_currentTrackId;
double m_volume = 0.0;
// progress on taskbar
void setPropertyPosition(int newPositionInMs);

View File

@ -7,20 +7,19 @@
*/
#include "mpris2.h"
#include "audiomanager.h"
#include "mediaplayer2.h"
#include "mediaplayer2player.h"
#include "audiomanager.h"
#include <QDBusConnection>
#if defined Q_OS_WIN
#include <Windows.h>
#else
#include <unistd.h>
#endif
Mpris2::Mpris2(QObject* parent)
Mpris2::Mpris2(QObject *parent)
: QObject(parent)
{
}
@ -52,8 +51,7 @@ void Mpris2::initDBusService()
}
}
Mpris2::~Mpris2()
= default;
Mpris2::~Mpris2() = default;
QString Mpris2::playerName() const
{

View File

@ -20,28 +20,17 @@ class Mpris2 : public QObject
{
Q_OBJECT
Q_PROPERTY(QString playerName
READ playerName
WRITE setPlayerName
NOTIFY playerNameChanged)
Q_PROPERTY(AudioManager* audioPlayer
READ audioPlayer
WRITE setAudioPlayer
NOTIFY audioPlayerChanged)
Q_PROPERTY(bool showProgressOnTaskBar
READ showProgressOnTaskBar
WRITE setShowProgressOnTaskBar
NOTIFY showProgressOnTaskBarChanged)
Q_PROPERTY(QString playerName READ playerName WRITE setPlayerName NOTIFY playerNameChanged)
Q_PROPERTY(AudioManager *audioPlayer READ audioPlayer WRITE setAudioPlayer NOTIFY audioPlayerChanged)
Q_PROPERTY(bool showProgressOnTaskBar READ showProgressOnTaskBar WRITE setShowProgressOnTaskBar NOTIFY showProgressOnTaskBarChanged)
public:
explicit Mpris2(QObject* parent = nullptr);
explicit Mpris2(QObject *parent = nullptr);
~Mpris2() override;
[[nodiscard]] QString playerName() const;
[[nodiscard]] AudioManager* audioPlayer() const;
[[nodiscard]] AudioManager *audioPlayer() const;
[[nodiscard]] bool showProgressOnTaskBar() const;
@ -49,7 +38,7 @@ public Q_SLOTS:
void setPlayerName(const QString &playerName);
void setAudioPlayer(AudioManager* audioPlayer);
void setAudioPlayer(AudioManager *audioPlayer);
void setShowProgressOnTaskBar(bool value);
@ -63,12 +52,11 @@ Q_SIGNALS:
void showProgressOnTaskBarChanged();
private:
void initDBusService();
std::unique_ptr<MediaPlayer2> m_mp2;
std::unique_ptr<MediaPlayer2Player> m_mp2p;
QString m_playerName;
AudioManager* m_audioPlayer = nullptr;
AudioManager *m_audioPlayer = nullptr;
bool mShowProgressOnTaskBar = true;
};

View File

@ -16,22 +16,20 @@
#endif
#if defined Q_OS_WIN
#include <windows.h>
#include <winbase.h>
#include <windows.h>
#endif
#include <QString>
#include <QDebug>
#include <QCoreApplication>
#include <QDebug>
#include <QString>
#include "inhibitinterface.h"
#include "gnomesessioninterface.h"
#include "inhibitinterface.h"
class PowerManagementInterfacePrivate
{
public:
bool mPreventSleep = false;
bool mInhibitedSleep = false;
@ -41,24 +39,25 @@ public:
uint mGnomeSleepCookie = 0;
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
OrgFreedesktopPowerManagementInhibitInterface* mInhibitInterface;
OrgGnomeSessionManagerInterface* mGnomeInterface;
OrgFreedesktopPowerManagementInhibitInterface *mInhibitInterface;
OrgGnomeSessionManagerInterface *mGnomeInterface;
#endif
};
PowerManagementInterface::PowerManagementInterface(QObject *parent) : QObject(parent), d(std::make_unique<PowerManagementInterfacePrivate>())
PowerManagementInterface::PowerManagementInterface(QObject *parent)
: QObject(parent)
, d(std::make_unique<PowerManagementInterfacePrivate>())
{
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
d->mInhibitInterface = new OrgFreedesktopPowerManagementInhibitInterface(QStringLiteral("org.freedesktop.PowerManagement.Inhibit"),
QStringLiteral("/org/freedesktop/PowerManagement/Inhibit"),
QDBusConnection::sessionBus(),
this);
QStringLiteral("/org/freedesktop/PowerManagement/Inhibit"),
QDBusConnection::sessionBus(),
this);
d->mGnomeInterface = new OrgGnomeSessionManagerInterface(QStringLiteral("org.gnome.SessionManager"),
QStringLiteral("/org/gnome/SessionManager"),
QDBusConnection::sessionBus(),
this);
QStringLiteral("/org/gnome/SessionManager"),
QDBusConnection::sessionBus(),
this);
#endif
}
@ -133,7 +132,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();
// qDebug() << "PowerManagementInterface::uninhibitDBusCallFinished" << reply.error();
} else {
d->mInhibitedSleep = false;
@ -150,7 +149,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();
// qDebug() << "PowerManagementInterface::inhibitDBusCallFinishedGnomeWorkspace" << reply.error();
} else {
d->mGnomeSleepCookie = reply.argumentAt<0>();
d->mInhibitedSleep = true;
@ -168,7 +167,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();
// qDebug() << "PowerManagementInterface::uninhibitDBusCallFinished" << reply.error();
} else {
d->mInhibitedSleep = false;
@ -183,13 +182,12 @@ void PowerManagementInterface::uninhibitDBusCallFinishedGnomeWorkspace(QDBusPend
void PowerManagementInterface::inhibitSleepPlasmaWorkspace()
{
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
auto asyncReply = d->mInhibitInterface->Inhibit(QCoreApplication::applicationName(),
i18nc("explanation for sleep inhibit during play of music", "Playing Music"));
auto asyncReply =
d->mInhibitInterface->Inhibit(QCoreApplication::applicationName(), i18nc("explanation for sleep inhibit during play of music", "Playing Music"));
auto replyWatcher = new QDBusPendingCallWatcher(asyncReply, this);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished,
this, &PowerManagementInterface::inhibitDBusCallFinishedPlasmaWorkspace);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInterface::inhibitDBusCallFinishedPlasmaWorkspace);
#endif
}
@ -200,8 +198,7 @@ void PowerManagementInterface::uninhibitSleepPlasmaWorkspace()
auto replyWatcher = new QDBusPendingCallWatcher(asyncReply, this);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished,
this, &PowerManagementInterface::uninhibitDBusCallFinishedPlasmaWorkspace);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInterface::uninhibitDBusCallFinishedPlasmaWorkspace);
#endif
}
@ -215,8 +212,7 @@ void PowerManagementInterface::inhibitSleepGnomeWorkspace()
auto replyWatcher = new QDBusPendingCallWatcher(asyncReply, this);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished,
this, &PowerManagementInterface::inhibitDBusCallFinishedGnomeWorkspace);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInterface::inhibitDBusCallFinishedGnomeWorkspace);
#endif
}
@ -227,8 +223,7 @@ void PowerManagementInterface::uninhibitSleepGnomeWorkspace()
auto replyWatcher = new QDBusPendingCallWatcher(asyncReply, this);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished,
this, &PowerManagementInterface::uninhibitDBusCallFinishedGnomeWorkspace);
QObject::connect(replyWatcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInterface::uninhibitDBusCallFinishedGnomeWorkspace);
#endif
}

View File

@ -16,20 +16,12 @@ class PowerManagementInterfacePrivate;
class PowerManagementInterface : public QObject
{
Q_OBJECT
Q_PROPERTY(bool preventSleep
READ preventSleep
WRITE setPreventSleep
NOTIFY preventSleepChanged)
Q_PROPERTY(bool sleepInhibited
READ sleepInhibited
NOTIFY sleepInhibitedChanged)
Q_PROPERTY(bool preventSleep READ preventSleep WRITE setPreventSleep NOTIFY preventSleepChanged)
Q_PROPERTY(bool sleepInhibited READ sleepInhibited NOTIFY sleepInhibitedChanged)
public:
explicit PowerManagementInterface(QObject *parent = nullptr);
~PowerManagementInterface() override;
@ -63,7 +55,6 @@ private Q_SLOTS:
void uninhibitDBusCallFinishedGnomeWorkspace(QDBusPendingCallWatcher *aWatcher);
private:
void inhibitSleepPlasmaWorkspace();
void uninhibitSleepPlasmaWorkspace();
@ -77,5 +68,4 @@ private:
void uninhibitSleepWindowsWorkspace();
std::unique_ptr<PowerManagementInterfacePrivate> d;
};

View File

@ -6,9 +6,9 @@
#include <QString>
#include "queuemodel.h"
#include "entry.h"
#include "datamanager.h"
#include "entry.h"
#include "queuemodel.h"
QueueModel::QueueModel(QObject *parent)
: QAbstractListModel(parent)
@ -17,19 +17,19 @@ 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;
// qDebug() << "Moved entry" << from << "to" << to;
});
connect(&DataManager::instance(), &DataManager::queueEntryAdded, this, [this](const int pos, const QString &id) {
Q_UNUSED(id)
beginInsertRows(QModelIndex(), pos, pos);
endInsertRows();
//qDebug() << "Added entry at pos" << pos;
// qDebug() << "Added entry at pos" << pos;
});
connect(&DataManager::instance(), &DataManager::queueEntryRemoved, this, [this](const int pos, const QString &id) {
Q_UNUSED(id)
beginRemoveRows(QModelIndex(), pos, pos);
endRemoveRows();
//qDebug() << "Removed entry at pos" << pos;
// qDebug() << "Removed entry at pos" << pos;
});
}
@ -37,7 +37,7 @@ QVariant QueueModel::data(const QModelIndex &index, int role) const
{
if (role != 0)
return QVariant();
//qDebug() << "return entry" << DataManager::instance().getQueueEntry(index.row());
// qDebug() << "return entry" << DataManager::instance().getQueueEntry(index.row());
return QVariant::fromValue(DataManager::instance().getQueueEntry(index.row()));
}
@ -51,6 +51,6 @@ QHash<int, QByteArray> QueueModel::roleNames() const
int QueueModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
//qDebug() << "queueCount is" << DataManager::instance().queueCount();
// qDebug() << "queueCount is" << DataManager::instance().queueCount();
return DataManager::instance().queueCount();
}

View File

@ -16,7 +16,7 @@ class QueueModel : public QAbstractListModel
Q_OBJECT
public:
explicit QueueModel(QObject* = nullptr);
explicit QueueModel(QObject * = nullptr);
//~QueueModel() override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;