Send proper signals when adding or removing queue items

This commit is contained in:
Bart De Vries 2021-04-07 22:10:39 +02:00
parent a9b86d0e44
commit ed7f75de13
8 changed files with 44 additions and 6 deletions

View File

@ -252,6 +252,12 @@ int DataManager::queueCount() const
return m_queuemap.count();
}
bool DataManager::entryInQueue(const QString &feedurl, const QString &id) const
{
Q_UNUSED(feedurl);
return m_queuemap.contains(id);
}
void DataManager::addtoQueue(const QString &feedurl, const QString &id)
{
// If item is already in queue, then stop here
@ -290,10 +296,10 @@ void DataManager::moveQueueItem(const int &from, const int &to)
void DataManager::removeQueueItem(const int &index)
{
qDebug() << m_queuemap;
// First remove the item from the internal data structure
const QString id = m_queuemap[index];
m_queuemap.removeAt(index);
//qDebug() << m_queuemap;
// Then make sure that the database Queue table reflects these changes
QSqlQuery query;
@ -312,6 +318,10 @@ void DataManager::removeQueueItem(const QString id)
removeQueueItem(m_queuemap.indexOf(id));
}
void DataManager::removeQueueItem(Entry* entry)
{
removeQueueItem(m_queuemap.indexOf(entry->id()));
}
void DataManager::importFeeds(const QString &path)
{
QUrl url(path);

View File

@ -40,10 +40,12 @@ public:
Entry* getQueueEntry(int const &index) const;
int queueCount() const;
Q_INVOKABLE bool entryInQueue(const QString &feedurl, const QString &id) const;
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 importFeeds(const QString &path);
Q_INVOKABLE void exportFeeds(const QString &path);
@ -56,7 +58,7 @@ Q_SIGNALS:
void feedEntriesUpdated(const QString &url);
void queueEntryAdded(const int &index, const QString &id);
void queueEntryRemoved(const int &index, const QString &id);
void queueEntryMoved(const int &from, const int $to);
void queueEntryMoved(const int &from, const int &to);
private:
DataManager();

View File

@ -11,6 +11,7 @@
#include <QUrl>
#include "database.h"
#include "datamanager.h"
#include "fetcher.h"
Entry::Entry(Feed *feed, QString id)
@ -21,6 +22,16 @@ Entry::Entry(Feed *feed, QString id)
if(url == m_image)
Q_EMIT imageChanged(url);
});
connect(&DataManager::instance(), &DataManager::queueEntryAdded, this, [this](const int &index, const QString &id) {
Q_UNUSED(index)
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)
Q_EMIT queueStatusChanged(queueStatus());
});
QSqlQuery entryQuery;
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed AND id=:id;"));
entryQuery.bindValue(QStringLiteral(":feed"), m_feed->url());
@ -188,6 +199,11 @@ QString Entry::image() const
}
}
bool Entry::queueStatus() const
{
return DataManager::instance().entryInQueue(m_feed->url(), m_id);
}
void Entry::setImage(const QString &image)
{
m_image = image;

View File

@ -35,6 +35,7 @@ class Entry : public QObject
Q_PROPERTY(Enclosure *enclosure READ enclosure CONSTANT);
Q_PROPERTY(bool hasEnclosure READ hasEnclosure CONSTANT);
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
Q_PROPERTY(bool queueStatus READ queueStatus NOTIFY queueStatusChanged)
public:
Entry(Feed *feed, QString id);
@ -52,6 +53,7 @@ public:
Enclosure *enclosure() const;
bool hasEnclosure() const;
QString image() const;
bool queueStatus() const;
Feed *feed() const;
QString baseUrl() const;
@ -66,6 +68,7 @@ Q_SIGNALS:
void readChanged(bool read);
void newChanged(bool state);
void imageChanged(const QString &url);
void queueStatusChanged(bool queueStatus);
private:
Feed *m_feed;

View File

@ -87,6 +87,12 @@ Kirigami.SwipeListItem {
icon.name: "delete"
onTriggered: entry.enclosure.deleteFile()
visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloaded
},
Kirigami.Action {
text: i18n("Add to queue")
icon.name: "media-playlist-append"
visible: entry.enclosure && !entry.queueStatus
onTriggered: { DataManager.addtoQueue(entry.feed.url, entry.id) }
}
]
}

View File

@ -94,13 +94,14 @@ Kirigami.ScrollablePage {
width: parent.width
height: root.height * 0.2
Kirigami.Icon {
source: page.feed.image === "" ? "rss" : Fetcher.image(page.feed.image)
Image {
source: page.feed.image === "" ? "rss" : "file://"+Fetcher.image(page.feed.image)
property int size: Kirigami.Units.iconSizes.large
Layout.minimumWidth: size
Layout.minimumHeight: size
Layout.maximumWidth: size
Layout.maximumHeight: size
asynchronous: true
}
ColumnLayout {

View File

@ -56,7 +56,7 @@ Kirigami.ScrollablePage {
else entry.enclosure.deleteFile()
}
}
actions.right: Kirigami.Action {
actions.left: Kirigami.Action {
text: "Add to queue"
icon.name: "media-playlist-append"
visible: entry.enclosure

View File

@ -38,7 +38,7 @@ Kirigami.SwipeListItem {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
Controls.Label {
text: entry.updated.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + (entry.enclosure ? " · " + Math.floor(entry.enclosure.size/(1024*1024)) + "MB" : "")
text: entry.updated.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + (entry.enclosure ? ( entry.enclosure.size !== 0 ? " · " + Math.floor(entry.enclosure.size/(1024*1024)) + "MB" : "") : "" )
Layout.fillWidth: true
elide: Text.ElideRight
font: Kirigami.Theme.smallFont