mirror of https://github.com/KDE/kasts.git
Send proper signals when adding or removing queue items
This commit is contained in:
parent
a9b86d0e44
commit
ed7f75de13
|
@ -252,6 +252,12 @@ int DataManager::queueCount() const
|
||||||
return m_queuemap.count();
|
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)
|
void DataManager::addtoQueue(const QString &feedurl, const QString &id)
|
||||||
{
|
{
|
||||||
// If item is already in queue, then stop here
|
// 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)
|
void DataManager::removeQueueItem(const int &index)
|
||||||
{
|
{
|
||||||
|
qDebug() << m_queuemap;
|
||||||
// First remove the item from the internal data structure
|
// First remove the item from the internal data structure
|
||||||
const QString id = m_queuemap[index];
|
const QString id = m_queuemap[index];
|
||||||
m_queuemap.removeAt(index);
|
m_queuemap.removeAt(index);
|
||||||
//qDebug() << m_queuemap;
|
|
||||||
|
|
||||||
// Then make sure that the database Queue table reflects these changes
|
// Then make sure that the database Queue table reflects these changes
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
@ -312,6 +318,10 @@ void DataManager::removeQueueItem(const QString id)
|
||||||
removeQueueItem(m_queuemap.indexOf(id));
|
removeQueueItem(m_queuemap.indexOf(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataManager::removeQueueItem(Entry* entry)
|
||||||
|
{
|
||||||
|
removeQueueItem(m_queuemap.indexOf(entry->id()));
|
||||||
|
}
|
||||||
void DataManager::importFeeds(const QString &path)
|
void DataManager::importFeeds(const QString &path)
|
||||||
{
|
{
|
||||||
QUrl url(path);
|
QUrl url(path);
|
||||||
|
|
|
@ -40,10 +40,12 @@ public:
|
||||||
|
|
||||||
Entry* getQueueEntry(int const &index) const;
|
Entry* getQueueEntry(int const &index) const;
|
||||||
int queueCount() 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 addtoQueue(const QString &feedurl, const QString &id);
|
||||||
Q_INVOKABLE void moveQueueItem(const int &from, const int &to);
|
Q_INVOKABLE void moveQueueItem(const int &from, const int &to);
|
||||||
Q_INVOKABLE void removeQueueItem(const int &index);
|
Q_INVOKABLE void removeQueueItem(const int &index);
|
||||||
Q_INVOKABLE void removeQueueItem(const QString id);
|
Q_INVOKABLE void removeQueueItem(const QString id);
|
||||||
|
Q_INVOKABLE void removeQueueItem(Entry* entry);
|
||||||
|
|
||||||
Q_INVOKABLE void importFeeds(const QString &path);
|
Q_INVOKABLE void importFeeds(const QString &path);
|
||||||
Q_INVOKABLE void exportFeeds(const QString &path);
|
Q_INVOKABLE void exportFeeds(const QString &path);
|
||||||
|
@ -56,7 +58,7 @@ Q_SIGNALS:
|
||||||
void feedEntriesUpdated(const QString &url);
|
void feedEntriesUpdated(const QString &url);
|
||||||
void queueEntryAdded(const int &index, const QString &id);
|
void queueEntryAdded(const int &index, const QString &id);
|
||||||
void queueEntryRemoved(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:
|
private:
|
||||||
DataManager();
|
DataManager();
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "datamanager.h"
|
||||||
#include "fetcher.h"
|
#include "fetcher.h"
|
||||||
|
|
||||||
Entry::Entry(Feed *feed, QString id)
|
Entry::Entry(Feed *feed, QString id)
|
||||||
|
@ -21,6 +22,16 @@ Entry::Entry(Feed *feed, QString id)
|
||||||
if(url == m_image)
|
if(url == m_image)
|
||||||
Q_EMIT imageChanged(url);
|
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;
|
QSqlQuery entryQuery;
|
||||||
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed AND id=:id;"));
|
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed AND id=:id;"));
|
||||||
entryQuery.bindValue(QStringLiteral(":feed"), m_feed->url());
|
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)
|
void Entry::setImage(const QString &image)
|
||||||
{
|
{
|
||||||
m_image = image;
|
m_image = image;
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Entry : public QObject
|
||||||
Q_PROPERTY(Enclosure *enclosure READ enclosure CONSTANT);
|
Q_PROPERTY(Enclosure *enclosure READ enclosure CONSTANT);
|
||||||
Q_PROPERTY(bool hasEnclosure READ hasEnclosure CONSTANT);
|
Q_PROPERTY(bool hasEnclosure READ hasEnclosure CONSTANT);
|
||||||
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
|
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
|
||||||
|
Q_PROPERTY(bool queueStatus READ queueStatus NOTIFY queueStatusChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Entry(Feed *feed, QString id);
|
Entry(Feed *feed, QString id);
|
||||||
|
@ -52,6 +53,7 @@ public:
|
||||||
Enclosure *enclosure() const;
|
Enclosure *enclosure() const;
|
||||||
bool hasEnclosure() const;
|
bool hasEnclosure() const;
|
||||||
QString image() const;
|
QString image() const;
|
||||||
|
bool queueStatus() const;
|
||||||
Feed *feed() const;
|
Feed *feed() const;
|
||||||
|
|
||||||
QString baseUrl() const;
|
QString baseUrl() const;
|
||||||
|
@ -66,6 +68,7 @@ Q_SIGNALS:
|
||||||
void readChanged(bool read);
|
void readChanged(bool read);
|
||||||
void newChanged(bool state);
|
void newChanged(bool state);
|
||||||
void imageChanged(const QString &url);
|
void imageChanged(const QString &url);
|
||||||
|
void queueStatusChanged(bool queueStatus);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Feed *m_feed;
|
Feed *m_feed;
|
||||||
|
|
|
@ -87,6 +87,12 @@ Kirigami.SwipeListItem {
|
||||||
icon.name: "delete"
|
icon.name: "delete"
|
||||||
onTriggered: entry.enclosure.deleteFile()
|
onTriggered: entry.enclosure.deleteFile()
|
||||||
visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloaded
|
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) }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,13 +94,14 @@ Kirigami.ScrollablePage {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: root.height * 0.2
|
height: root.height * 0.2
|
||||||
|
|
||||||
Kirigami.Icon {
|
Image {
|
||||||
source: page.feed.image === "" ? "rss" : Fetcher.image(page.feed.image)
|
source: page.feed.image === "" ? "rss" : "file://"+Fetcher.image(page.feed.image)
|
||||||
property int size: Kirigami.Units.iconSizes.large
|
property int size: Kirigami.Units.iconSizes.large
|
||||||
Layout.minimumWidth: size
|
Layout.minimumWidth: size
|
||||||
Layout.minimumHeight: size
|
Layout.minimumHeight: size
|
||||||
Layout.maximumWidth: size
|
Layout.maximumWidth: size
|
||||||
Layout.maximumHeight: size
|
Layout.maximumHeight: size
|
||||||
|
asynchronous: true
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
|
|
@ -56,7 +56,7 @@ Kirigami.ScrollablePage {
|
||||||
else entry.enclosure.deleteFile()
|
else entry.enclosure.deleteFile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
actions.right: Kirigami.Action {
|
actions.left: Kirigami.Action {
|
||||||
text: "Add to queue"
|
text: "Add to queue"
|
||||||
icon.name: "media-playlist-append"
|
icon.name: "media-playlist-append"
|
||||||
visible: entry.enclosure
|
visible: entry.enclosure
|
||||||
|
|
|
@ -38,7 +38,7 @@ Kirigami.SwipeListItem {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
Controls.Label {
|
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
|
Layout.fillWidth: true
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
font: Kirigami.Theme.smallFont
|
font: Kirigami.Theme.smallFont
|
||||||
|
|
Loading…
Reference in New Issue