2021-04-02 17:06:27 +02:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "feed.h"
|
|
|
|
#include "entry.h"
|
|
|
|
|
|
|
|
class DataManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
static DataManager &instance()
|
|
|
|
{
|
|
|
|
static DataManager _instance;
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
Feed* getFeed(int const index) const;
|
|
|
|
Feed* getFeed(QString const feedurl) const;
|
2021-04-02 22:31:34 +02:00
|
|
|
Entry* getEntry(int const feed_index, int const entry_index) const;
|
|
|
|
Entry* getEntry(const Feed* feed, int const entry_index) const;
|
2021-04-10 09:36:55 +02:00
|
|
|
Q_INVOKABLE Entry* getEntry(const QString id) const;
|
2021-04-02 22:31:34 +02:00
|
|
|
int feedCount() const;
|
|
|
|
int entryCount(const int feed_index) const;
|
|
|
|
int entryCount(const Feed* feed) const;
|
|
|
|
int unreadEntryCount(const Feed* feed) const;
|
2021-04-07 10:39:12 +02:00
|
|
|
int newEntryCount(const Feed* feed) const;
|
2021-04-02 22:31:34 +02:00
|
|
|
Q_INVOKABLE void addFeed(const QString &url);
|
|
|
|
Q_INVOKABLE void removeFeed(const Feed* feed);
|
|
|
|
Q_INVOKABLE void removeFeed(const int &index);
|
|
|
|
|
2021-04-03 13:49:33 +02:00
|
|
|
//Q_INVOKABLE void addEntry(const QString &url); // TODO: implement these methods
|
2021-04-02 22:31:34 +02:00
|
|
|
//Q_INVOKABLE void removeEntry(const QString &url);
|
|
|
|
//Q_INVOKABLE void removeEntry(const Feed* feed, const int &index);
|
|
|
|
|
2021-04-03 13:49:33 +02:00
|
|
|
Entry* getQueueEntry(int const &index) const;
|
|
|
|
int queueCount() const;
|
2021-04-11 23:07:21 +02:00
|
|
|
QStringList getQueue() const;
|
2021-04-16 20:38:13 +02:00
|
|
|
Q_INVOKABLE bool entryInQueue(const Entry* entry);
|
2021-04-07 22:10:39 +02:00
|
|
|
Q_INVOKABLE bool entryInQueue(const QString &feedurl, const QString &id) const;
|
2021-04-15 23:10:40 +02:00
|
|
|
Q_INVOKABLE void addToQueue(const Entry* entry);
|
|
|
|
Q_INVOKABLE void addToQueue(const QString &feedurl, const QString &id);
|
2021-04-03 13:49:33 +02:00
|
|
|
Q_INVOKABLE void moveQueueItem(const int &from, const int &to);
|
2021-04-03 19:29:40 +02:00
|
|
|
Q_INVOKABLE void removeQueueItem(const int &index);
|
2021-04-03 21:39:20 +02:00
|
|
|
Q_INVOKABLE void removeQueueItem(const QString id);
|
2021-04-07 22:10:39 +02:00
|
|
|
Q_INVOKABLE void removeQueueItem(Entry* entry);
|
2021-04-03 13:49:33 +02:00
|
|
|
|
2021-04-02 22:31:34 +02:00
|
|
|
Q_INVOKABLE void importFeeds(const QString &path);
|
|
|
|
Q_INVOKABLE void exportFeeds(const QString &path);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void feedAdded(const QString &url);
|
|
|
|
void feedRemoved(const int &index);
|
2021-04-03 11:44:08 +02:00
|
|
|
void entryAdded(const QString &feedurl, const QString &id);
|
2021-04-03 13:49:33 +02:00
|
|
|
//void entryRemoved(const Feed*, const int &index); // TODO: implement this signal
|
2021-04-02 22:31:34 +02:00
|
|
|
void feedEntriesUpdated(const QString &url);
|
2021-04-03 19:29:40 +02:00
|
|
|
void queueEntryAdded(const int &index, const QString &id);
|
|
|
|
void queueEntryRemoved(const int &index, const QString &id);
|
2021-04-07 22:10:39 +02:00
|
|
|
void queueEntryMoved(const int &from, const int &to);
|
2021-04-02 17:06:27 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
DataManager();
|
|
|
|
void loadFeed(QString feedurl) const;
|
2021-04-02 22:31:34 +02:00
|
|
|
void loadEntry(QString id) const;
|
|
|
|
bool feedExists(const QString &url);
|
2021-04-03 19:29:40 +02:00
|
|
|
void updateQueueListnrs() const;
|
2021-04-02 17:06:27 +02:00
|
|
|
|
2021-04-03 13:49:33 +02:00
|
|
|
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
|
|
|
|
QStringList m_queuemap; // list of entries/enclosures in the order that they should show up in queuelist
|
2021-04-02 17:06:27 +02:00
|
|
|
};
|