File indexing completed on 2024-05-12 16:21:30

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
0003  * SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 #pragma once
0009 
0010 #include <QDateTime>
0011 #include <QObject>
0012 #include <QString>
0013 #include <QVector>
0014 
0015 #include "author.h"
0016 #include "models/entriesproxymodel.h"
0017 
0018 class Feed : public QObject
0019 {
0020     Q_OBJECT
0021 
0022     Q_PROPERTY(QString url READ url CONSTANT)
0023     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
0024     Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
0025     Q_PROPERTY(QString cachedImage READ cachedImage NOTIFY cachedImageChanged)
0026     Q_PROPERTY(QString link READ link WRITE setLink NOTIFY linkChanged)
0027     Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
0028     Q_PROPERTY(QVector<Author *> authors READ authors WRITE setAuthors NOTIFY authorsChanged)
0029     Q_PROPERTY(bool refreshing READ refreshing WRITE setRefreshing NOTIFY refreshingChanged)
0030     Q_PROPERTY(int deleteAfterCount READ deleteAfterCount WRITE setDeleteAfterCount NOTIFY deleteAfterCountChanged)
0031     Q_PROPERTY(int deleteAfterType READ deleteAfterType WRITE setDeleteAfterType NOTIFY deleteAfterTypeChanged)
0032     Q_PROPERTY(QDateTime subscribed READ subscribed CONSTANT)
0033     Q_PROPERTY(QDateTime lastUpdated READ lastUpdated WRITE setLastUpdated NOTIFY lastUpdatedChanged)
0034     Q_PROPERTY(bool notify READ notify WRITE setNotify NOTIFY notifyChanged)
0035     Q_PROPERTY(QString dirname READ dirname WRITE setDirname NOTIFY dirnameChanged)
0036     Q_PROPERTY(int entryCount READ entryCount NOTIFY entryCountChanged)
0037     Q_PROPERTY(int unreadEntryCount READ unreadEntryCount WRITE setUnreadEntryCount NOTIFY unreadEntryCountChanged)
0038     Q_PROPERTY(int newEntryCount READ newEntryCount NOTIFY newEntryCountChanged)
0039     Q_PROPERTY(int favoriteEntryCount READ favoriteEntryCount NOTIFY favoriteEntryCountChanged)
0040     Q_PROPERTY(int errorId READ errorId WRITE setErrorId NOTIFY errorIdChanged)
0041     Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged)
0042     Q_PROPERTY(EntriesProxyModel *entries MEMBER m_entries CONSTANT)
0043 
0044 public:
0045     Feed(const QString &feedurl);
0046 
0047     ~Feed();
0048 
0049     void updateAuthors();
0050 
0051     QString url() const;
0052     QString name() const;
0053     QString image() const;
0054     QString cachedImage() const;
0055     QString link() const;
0056     QString description() const;
0057     QVector<Author *> authors() const;
0058     int deleteAfterCount() const;
0059     int deleteAfterType() const;
0060     QDateTime subscribed() const;
0061     QDateTime lastUpdated() const;
0062     bool notify() const;
0063     QString dirname() const;
0064     int entryCount() const;
0065     int unreadEntryCount() const;
0066     int newEntryCount() const;
0067     int favoriteEntryCount() const;
0068     bool read() const;
0069     int errorId() const;
0070     QString errorString() const;
0071 
0072     bool refreshing() const;
0073 
0074     void setName(const QString &name);
0075     void setImage(const QString &image);
0076     void setLink(const QString &link);
0077     void setDescription(const QString &description);
0078     void setAuthors(const QVector<Author *> &authors);
0079     void setDeleteAfterCount(int count);
0080     void setDeleteAfterType(int type);
0081     void setLastUpdated(const QDateTime &lastUpdated);
0082     void setNotify(bool notify);
0083     void setDirname(const QString &dirname);
0084     void setUnreadEntryCount(const int count);
0085     void setRefreshing(bool refreshing);
0086     void setErrorId(int errorId);
0087     void setErrorString(const QString &errorString);
0088 
0089     Q_INVOKABLE void refresh();
0090 
0091 Q_SIGNALS:
0092     void nameChanged(const QString &name);
0093     void imageChanged(const QString &image);
0094     void cachedImageChanged(const QString &imagePath);
0095     void linkChanged(const QString &link);
0096     void descriptionChanged(const QString &description);
0097     void authorsChanged(const QVector<Author *> &authors);
0098     void deleteAfterCountChanged(int count);
0099     void deleteAfterTypeChanged(int type);
0100     void lastUpdatedChanged(const QDateTime &lastUpdated);
0101     void notifyChanged(bool notify);
0102     void dirnameChanged(const QString &dirname);
0103     void entryCountChanged();
0104     void unreadEntryCountChanged();
0105     void newEntryCountChanged();
0106     void favoriteEntryCountChanged();
0107     void errorIdChanged(int &errorId);
0108     void errorStringChanged(const QString &errorString);
0109 
0110     void refreshingChanged(bool refreshing);
0111 
0112 private:
0113     void updateUnreadEntryCountFromDB();
0114     void updateNewEntryCountFromDB();
0115     void updateFavoriteEntryCountFromDB();
0116 
0117     QString m_url;
0118     QString m_name;
0119     QString m_image;
0120     QString m_link;
0121     QString m_description;
0122     QVector<Author *> m_authors;
0123     int m_deleteAfterCount;
0124     int m_deleteAfterType;
0125     QDateTime m_subscribed;
0126     QDateTime m_lastUpdated;
0127     bool m_notify;
0128     QString m_dirname;
0129     int m_errorId;
0130     QString m_errorString;
0131     int m_unreadEntryCount = -1;
0132     int m_newEntryCount = -1;
0133     int m_favoriteEntryCount = -1;
0134 
0135     EntriesProxyModel *m_entries;
0136 
0137     bool m_refreshing = false;
0138 };