File indexing completed on 2024-05-12 16:21:28
0001 /** 0002 * SPDX-FileCopyrightText: 2021-2022 Bart De Vries <bart@mogwai.be> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <QHash> 0010 #include <QObject> 0011 #include <QString> 0012 #include <QStringList> 0013 0014 #include "models/abstractepisodeproxymodel.h" 0015 #include "models/episodemodel.h" 0016 0017 class Entry; 0018 class Feed; 0019 0020 class DataManager : public QObject 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 static DataManager &instance() 0026 { 0027 static DataManager _instance; 0028 return _instance; 0029 } 0030 0031 Feed *getFeed(const int index) const; 0032 Q_INVOKABLE Feed *getFeed(const QString &feedurl) const; 0033 Entry *getEntry(const int feed_index, const int entry_index) const; 0034 Entry *getEntry(const Feed *feed, const int entry_index) const; 0035 Q_INVOKABLE Entry *getEntry(const QString &id) const; 0036 int feedCount() const; 0037 QStringList getIdList(const Feed *feed) const; 0038 int entryCount(const int feed_index) const; 0039 int entryCount(const Feed *feed) const; 0040 Q_INVOKABLE void addFeed(const QString &url); 0041 void addFeed(const QString &url, const bool fetch); 0042 void addFeeds(const QStringList &urls); 0043 void addFeeds(const QStringList &urls, const bool fetch); 0044 Q_INVOKABLE void removeFeed(Feed *feed); 0045 void removeFeed(const int index); 0046 void removeFeeds(const QStringList &feedurls); 0047 Q_INVOKABLE void removeFeeds(const QVariantList feedsVariantList); 0048 void removeFeeds(const QList<Feed *> &feeds); 0049 0050 Entry *getQueueEntry(int index) const; 0051 int queueCount() const; 0052 QStringList queue() const; 0053 bool entryInQueue(const Entry *entry); 0054 bool entryInQueue(const QString &id) const; 0055 Q_INVOKABLE void moveQueueItem(const int from, const int to); 0056 void addToQueue(const QString &id); 0057 void removeFromQueue(const QString &id); 0058 Q_INVOKABLE void sortQueue(AbstractEpisodeProxyModel::SortType sortType); 0059 0060 Q_INVOKABLE QString lastPlayingEntry(); 0061 Q_INVOKABLE void setLastPlayingEntry(const QString &id); 0062 0063 Q_INVOKABLE void deletePlayedEnclosures(); 0064 0065 Q_INVOKABLE void importFeeds(const QString &path); 0066 Q_INVOKABLE void exportFeeds(const QString &path); 0067 Q_INVOKABLE bool feedExists(const QString &url); 0068 0069 Q_INVOKABLE void bulkMarkRead(bool state, QStringList list); 0070 Q_INVOKABLE void bulkMarkNew(bool state, QStringList list); 0071 Q_INVOKABLE void bulkMarkFavorite(bool state, QStringList list); 0072 Q_INVOKABLE void bulkQueueStatus(bool state, QStringList list); 0073 Q_INVOKABLE void bulkDownloadEnclosures(QStringList list); 0074 Q_INVOKABLE void bulkDeleteEnclosures(QStringList list); 0075 0076 Q_INVOKABLE void bulkMarkReadByIndex(bool state, QModelIndexList list); 0077 Q_INVOKABLE void bulkMarkNewByIndex(bool state, QModelIndexList list); 0078 Q_INVOKABLE void bulkMarkFavoriteByIndex(bool state, QModelIndexList list); 0079 Q_INVOKABLE void bulkQueueStatusByIndex(bool state, QModelIndexList list); 0080 Q_INVOKABLE void bulkDownloadEnclosuresByIndex(QModelIndexList list); 0081 Q_INVOKABLE void bulkDeleteEnclosuresByIndex(QModelIndexList list); 0082 0083 Q_SIGNALS: 0084 void feedAdded(const QString &url); 0085 void feedRemoved(const int &index); 0086 void feedEntriesUpdated(const QString &url); 0087 void queueEntryAdded(const int &index, const QString &id); 0088 void queueEntryRemoved(const int &index, const QString &id); 0089 void queueEntryMoved(const int &from, const int &to); 0090 void queueSorted(); 0091 0092 void unreadEntryCountChanged(const QString &url); 0093 void newEntryCountChanged(const QString &url); 0094 void favoriteEntryCountChanged(const QString &url); 0095 0096 void bulkReadStatusActionFinished(); 0097 void bulkNewStatusActionFinished(); 0098 void bulkFavoriteStatusActionFinished(); 0099 0100 // this will relay the AudioManager::playbackRateChanged signal; this is 0101 // required to avoid a dependency loop on startup 0102 // TODO: find less hackish solution 0103 void playbackRateChanged(); 0104 0105 private: 0106 DataManager(); 0107 void loadFeed(const QString &feedurl) const; 0108 void loadEntry(QString id) const; 0109 void updateQueueListnrs() const; 0110 0111 QString cleanUrl(const QString &url); 0112 0113 QStringList getIdsFromModelIndexList(const QModelIndexList &list) const; 0114 0115 mutable QHash<QString, Feed *> m_feeds; // hash of pointers to all feeds in db, key = url (lazy loading) 0116 mutable QHash<QString, Entry *> m_entries; // hash of pointers to all entries in db, key = id (lazy loading) 0117 0118 QStringList m_feedmap; // list of feedurls in the order that they should appear in feedlist 0119 QHash<QString, QStringList> m_entrymap; // list of entries (per feed; key = url) in the order that they should appear in entrylist 0120 QStringList m_queuemap; // list of entries/enclosures in the order that they should show up in queuelist 0121 };