Add "new" and "playposition" to database

These fields have been added to, respectively, Entries and Enclosures.
This commit is contained in:
Bart De Vries 2021-04-07 10:39:12 +02:00
parent 5efd4f85f8
commit 06bffdb5e3
10 changed files with 50 additions and 4 deletions

View File

@ -47,9 +47,9 @@ 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, 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, hasEnclosure BOOL, image TEXT);")));
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, 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);"))); //, filename TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Queue (listnr INTEGER, feed TEXT, id TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;")));
return true;

View File

@ -136,6 +136,17 @@ int DataManager::unreadEntryCount(const Feed* feed) const
return query.value(0).toInt();
}
int DataManager::newEntryCount(const Feed* feed) const
{
QSqlQuery query;
query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries where feed=:feed AND new=1;"));
query.bindValue(QStringLiteral(":feed"), feed->url());
Database::instance().execute(query);
if (!query.next())
return -1;
return query.value(0).toInt();
}
void DataManager::removeFeed(const Feed* feed)
{
removeFeed(m_feedmap.indexOf(feed->url()));

View File

@ -29,6 +29,7 @@ public:
int entryCount(const int feed_index) const;
int entryCount(const Feed* feed) const;
int unreadEntryCount(const Feed* feed) const;
int newEntryCount(const Feed* feed) const;
Q_INVOKABLE void addFeed(const QString &url);
Q_INVOKABLE void removeFeed(const Feed* feed);
Q_INVOKABLE void removeFeed(const int &index);

View File

@ -33,6 +33,7 @@ Enclosure::Enclosure(Entry *entry)
m_title = query.value(QStringLiteral("title")).toString();
m_type = query.value(QStringLiteral("type")).toString();
m_url = query.value(QStringLiteral("url")).toString();
m_playposition = query.value(QStringLiteral("playposition")).toInt();
QFile file(path());
if(file.size() == m_size) {

View File

@ -25,6 +25,7 @@ class Enclosure : public QObject
Q_PROPERTY(Status status MEMBER m_status NOTIFY statusChanged)
Q_PROPERTY(double downloadProgress MEMBER m_downloadProgress NOTIFY downloadProgressChanged)
Q_PROPERTY(QString path READ path CONSTANT)
Q_PROPERTY(QString playposition MEMBER m_playposition CONSTANT)
public:
Enclosure(Entry *entry);
@ -55,6 +56,7 @@ private:
QString m_title;
QString m_type;
QString m_url;
int m_playposition;
double m_downloadProgress = 0;
Status m_status;
};

View File

@ -46,6 +46,7 @@ Entry::Entry(Feed *feed, QString id)
m_content = entryQuery.value(QStringLiteral("content")).toString();
m_link = entryQuery.value(QStringLiteral("link")).toString();
m_read = entryQuery.value(QStringLiteral("read")).toBool();
m_new = entryQuery.value(QStringLiteral("new")).toBool();
if (entryQuery.value(QStringLiteral("hasEnclosure")).toBool()) {
m_hasenclosure = true;
@ -99,6 +100,11 @@ bool Entry::read() const
return m_read;
}
bool Entry::getNew() const
{
return m_new;
}
QString Entry::baseUrl() const
{
return QUrl(m_link).adjusted(QUrl::RemovePath).toString();
@ -117,6 +123,18 @@ void Entry::setRead(bool read)
Q_EMIT m_feed->unreadEntryCountChanged();
}
void Entry::setNew(bool state)
{
m_new = state;
Q_EMIT newChanged(m_new);
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE Entries SET new=:new WHERE id=:id AND feed=:feed"));
query.bindValue(QStringLiteral(":id"), m_id);
query.bindValue(QStringLiteral(":feed"), m_feed->url());
query.bindValue(QStringLiteral(":new"), m_new);
Database::instance().execute(query);
// Q_EMIT m_feed->newEntryCountChanged(); // TODO: signal and slots to be implemented
}
QString Entry::adjustedContent(int width, int fontSize)
{
QString ret(m_content);

View File

@ -31,6 +31,7 @@ class Entry : public QObject
Q_PROPERTY(QString link READ link CONSTANT)
Q_PROPERTY(QString baseUrl READ baseUrl CONSTANT)
Q_PROPERTY(bool read READ read WRITE setRead NOTIFY readChanged);
Q_PROPERTY(bool new READ getNew WRITE setNew NOTIFY newChanged);
Q_PROPERTY(Enclosure *enclosure READ enclosure CONSTANT);
Q_PROPERTY(bool hasEnclosure READ hasEnclosure CONSTANT);
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
@ -47,6 +48,7 @@ public:
QDateTime updated() const;
QString link() const;
bool read() const;
bool getNew() const;
Enclosure *enclosure() const;
bool hasEnclosure() const;
QString image() const;
@ -55,12 +57,14 @@ public:
QString baseUrl() const;
void setRead(bool read);
void setNew(bool state);
void setImage(const QString &url);
Q_INVOKABLE QString adjustedContent(int width, int fontSize);
Q_SIGNALS:
void readChanged(bool read);
void newChanged(bool state);
void imageChanged(const QString &url);
private:
@ -73,6 +77,7 @@ private:
QDateTime m_updated;
QString m_link;
bool m_read;
bool m_new;
Enclosure *m_enclosure = nullptr;
QString m_image;
bool m_hasenclosure = false;

View File

@ -215,6 +215,11 @@ int Feed::unreadEntryCount() const
return DataManager::instance().unreadEntryCount(this);
}
int Feed::newEntryCount() const
{
return DataManager::instance().newEntryCount(this);
}
bool Feed::refreshing() const
{
return m_refreshing;

View File

@ -32,6 +32,7 @@ class Feed : public QObject
Q_PROPERTY(bool notify READ notify WRITE setNotify NOTIFY notifyChanged)
Q_PROPERTY(int entryCount READ entryCount NOTIFY entryCountChanged)
Q_PROPERTY(int unreadEntryCount READ unreadEntryCount NOTIFY unreadEntryCountChanged)
Q_PROPERTY(int newEntryCount READ newEntryCount NOTIFY newEntryCountChanged)
Q_PROPERTY(int errorId READ errorId WRITE setErrorId NOTIFY errorIdChanged)
Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged)
Q_PROPERTY(EntriesModel *entries MEMBER m_entries CONSTANT)
@ -55,6 +56,7 @@ public:
bool notify() const;
int entryCount() const;
int unreadEntryCount() const;
int newEntryCount() const;
bool read() const;
int errorId() const;
QString errorString() const;
@ -88,6 +90,7 @@ Q_SIGNALS:
void notifyChanged(bool notify);
void entryCountChanged();
void unreadEntryCountChanged();
void newEntryCountChanged();
void errorIdChanged(int &errorId);
void errorStringChanged(const QString &errorString);

View File

@ -144,7 +144,7 @@ void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url)
if (query.value(0).toInt() != 0)
return;
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated, :link, 0, :hasEnclosure, :image);"));
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated, :link, 0, 1, :hasEnclosure, :image);"));
query.bindValue(QStringLiteral(":feed"), url);
query.bindValue(QStringLiteral(":id"), entry->id());
query.bindValue(QStringLiteral(":title"), QTextDocumentFragment::fromHtml(entry->title()).toPlainText());
@ -202,7 +202,7 @@ void Fetcher::processAuthor(const QString &url, const QString &entryId, const QS
void Fetcher::processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl)
{
QSqlQuery query;
query.prepare(QStringLiteral("INSERT INTO Enclosures VALUES (:feed, :id, :duration, :size, :title, :type, :url);"));
query.prepare(QStringLiteral("INSERT INTO Enclosures VALUES (:feed, :id, :duration, :size, :title, :type, :url, 0);"));
query.bindValue(QStringLiteral(":feed"), feedUrl);
query.bindValue(QStringLiteral(":id"), entry->id());
query.bindValue(QStringLiteral(":duration"), enclosure->duration());