LCOV - code coverage report
Current view: top level - src/models - FeedItem.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 62.5 % 40 25
Test Date: 2026-03-23 10:19:47 Functions: 75.0 % 32 24

            Line data    Source code
       1              : #ifndef FEEDITEM_H
       2              : #define FEEDITEM_H
       3              : 
       4              : #include <QString>
       5              : #include <QUrl>
       6              : #include <QDateTime>
       7              : #include <QVariant>
       8              : #include <QTextStream>
       9              : 
      10              : #include "DBObject.h"
      11              : #include "ListModel.h"
      12              : #include "src/models/NewsList.h"
      13              : 
      14              : class NewsItem;
      15              : class NewsList;
      16              : 
      17              : // IDs of special feeds.  (Normal feed IDs start at 0.)
      18              : 
      19              : enum SpecialFeedID {
      20              :     FEED_ID_SEARCH = -3,
      21              :     FEED_ID_ALLNEWS = -2,
      22              :     FEED_ID_PINNED = -1
      23              : };
      24              : 
      25              : enum FeedType { FeedTypeRSS = 0, FeedTypeGoogleNewsSitemap = 1 };
      26              : 
      27              : class FeedItem : public ListItem, DBObject
      28              : {
      29              :     Q_OBJECT
      30              :     
      31              : public:
      32              :     
      33              :     enum Roles {
      34              :         TitleRole = Qt::UserRole+1,
      35              :         SubtitleRole,
      36              :         LastUpdatedRole,
      37              :         MinutesToUpdateRole,
      38              :         UrlRole,
      39              :         SiteURLRole,
      40              :         ImageURLRole,
      41              :         IsUpdatingRole,
      42              :         UnreadCountRole,
      43              :         DropTargetRole,
      44              :         ErrorFlagRole,
      45              :         IsSelectedRole,
      46              :         IsSpecialFeedRole,
      47              :         IsFolderRole,
      48              :         ParentFolderRole,
      49              :         FolderOpenRole,
      50              :         BookmarksEnabledRole,
      51              :         UIDRole,
      52              :         SelfRole,
      53              :         IsSearchFeedRole
      54              :     };
      55              :     
      56              :     FeedItem(QObject *parent = nullptr);
      57              :     
      58              :     // This class is immutable, so this is the c'tor you'll want to use.
      59              :     explicit FeedItem(
      60              :             const qint64 id,
      61              :             const qint32 ordinal,
      62              :             const QString& title,
      63              :             const QString& subtitle,
      64              :             const QDateTime& lastUpdated,
      65              :             quint32 minutesToUpdate,
      66              :             const QUrl& url,
      67              :             const QUrl& siteURL,
      68              :             const QString& userURL,
      69              :             const QUrl& imageURL,
      70              :             const QDateTime& lastIconUpdate,
      71              :             qint64 parentFolder = -1,
      72              :             bool folderOpen = true,
      73              :             FeedType feedType = FeedTypeRSS,
      74              :             QObject *parent = nullptr);
      75              :     
      76              :     virtual ~FeedItem();
      77              :     
      78              :     /*!
      79              :         \brief Ordinal-based sort, used for re-sorting the list.
      80              :         \param rhs
      81              :         \return
      82              :      */
      83              :     bool operator<(const FeedItem& rhs);
      84              :     
      85              :     QVariant data(int role) const;
      86              :     bool setData(const QVariant &value, int role);
      87              :     Qt::ItemFlags flags() const;
      88              :     QHash<int, QByteArray> roleNames() const;
      89              :     
      90              :     void setIsUpdating(bool isUpdating);
      91              :     
      92              :     // Unused, required for ListItem base class.
      93            0 :     inline QString id() const {
      94            0 :         QString ret;
      95            0 :         QTextStream output(&ret);
      96            0 :         output << "FeedItem_" << _id;
      97            0 :         return ret;
      98            0 :     }
      99              : 
     100              : public slots:
     101              :     
     102           17 :     inline QString getTitle() const { return title; }
     103            4 :     inline QString getSubtitle() const { return subtitle; }
     104            3 :     inline QDateTime getLastUpdated() const { return lastUpdated; }
     105            4 :     inline quint32 getMinutesToUpdate() const { return minutesToUpdate; }
     106           29 :     inline QUrl getURL() const { return url; }
     107           14 :     inline QUrl getSiteURL() const { return siteURL; }
     108            2 :     inline QString getUserURL() const { return userURL; }
     109            4 :     inline QUrl getImageURL() const { return imageURL; }
     110           20 :     inline int getIsUpdating() const { return isUpdating; }
     111            6 :     inline quint32 getUnreadCount() const { return unreadCount; }
     112            5 :     inline QString getDropTarget() const { return dropTarget; }
     113            2 :     inline FeedItem* getSelf() const { return const_cast<FeedItem*>(this); }
     114          629 :     virtual inline qint64 getDbID() const { return _id; }
     115          100 :     inline bool isSpecialFeed() const { return _id < 0; }
     116            0 :     inline bool isSearchFeed() const { return _id == FEED_ID_SEARCH; }
     117            0 :     inline FeedType getFeedType() const { return _feedType; }
     118            0 :     inline QString getEtag() const { return etag; }
     119            0 :     inline QString getLastModified() const { return lastModified; }
     120              :     void setEtag(const QString& value);
     121              :     void setLastModified(const QString& value);
     122              :     
     123              :     void setImageURL(const QUrl& url);
     124              :     
     125              :     void setTitle(const QString& newTitle);
     126              :     
     127              :     void setDropTarget(const QString& dropTarget);
     128              :     
     129              :     void setIsSelected(bool s);
     130              : 
     131              :     // Override for folders.
     132           17 :     virtual bool isFolder() const { return false; }
     133            0 :     virtual void setIsFolder(bool isFolder) {
     134              :         Q_UNUSED(isFolder);
     135            0 :         qCritical() << "FeedItem::setIsFolder: Unsupported on base type";
     136            0 :     }
     137              : 
     138              :     void setParentFolder(qint64 parentFolder);
     139              :     void setFolderOpen(bool folderOpen);
     140              :     
     141              :     /*!
     142              :         \brief Clears all news items.  Does NOT signal.
     143              :         \return
     144              :      */
     145              :     virtual void clearNews();
     146              :     
     147              :     /*!
     148              :         \brief Provides direct access to the news list.
     149              : 
     150              :         Note: This represents news items that are loaded and can be viewed. As such it will
     151              :         slowly grow as more news items are added to the feed.
     152              :      */
     153         2994 :     inline NewsList* getNewsList() { return &newsList; }
     154              :     
     155              :     /*!
     156              :         \brief Used to set the bookmark internally.  External classes shouldn't need to call this.
     157              :         \param bookmark Item ID or -1 to clear.t
     158              :      */
     159              :     virtual void setBookmark(qint64 toBookmarkID);
     160              :     
     161              :     /*!
     162              :         \param item
     163              :         \param allowBackward
     164              :         \return True if this item can be bookmarked.
     165              :      */
     166              :     virtual bool canBookmark(qint64 proposedBookmarkID, bool allowBackward);
     167              :     
     168              :     /*!
     169              :         \brief Returns the current bookmark ID or -1 if none.
     170              :         \return
     171              :      */
     172          806 :     inline qint64 getBookmarkID() const { return _bookmarkID; }
     173              :     
     174              :     /*!
     175              :         \brief Detaches the feed ID when this feed is being disconnected.
     176              :      */
     177            0 :     inline void clearDbId() { _id = -100; }
     178              :     
     179              :     /*!
     180              :         \return The ID of the very first item in the feed that we have in our database;
     181              :                 not the ID that's necessarily currently loaded.
     182              :      */
     183            3 :     inline qint64 getFirstNewsID() { return firstNewsID; }
     184              :     
     185              :     /*!
     186              :         \brief setFirstNewsID Sets the first item available in the feed.  This is used
     187              :                               to tell if we should draw the top bookmark to unbookmark all.
     188              :         \param id
     189              :      */
     190            8 :     inline void setFirstNewsID(qint64 id) { firstNewsID = id; }
     191              :     
     192              :     /*!
     193              :         \brief Sets the unread count to the new value and emits a change signal.
     194              :         \param unreadCount
     195              :      */
     196              :     void setUnreadCount(qint32 unreadCount);
     197              :     
     198              :     /*!
     199              :         \brief Returns the ordinal (note: only really used in resorting the list.)
     200              :         \return
     201              :      */
     202            8 :     inline int getOrdinal() const { return ordinal; }
     203              :     
     204              :     /*!
     205              :         \brief Sets the ordinal.
     206              :      */
     207              :     void setOrdinal(int newOrdinal);
     208              :     
     209              :     /*!
     210              :         \brief Sets the optional error flag.  Used in batch import.
     211              :         \param errorFlag
     212              :      */
     213              :     void setErrorFlag(bool errorFlag);
     214              :     
     215              :     /*!
     216              :         \return True if error flag is set, else false.
     217              :      */
     218           18 :     inline bool getErrorFlag() const { return _errorFlag; }
     219              :     
     220              :     /*!
     221              :         \brief Changes the URL.
     222              :         \param url
     223              :      */
     224              :     void setURL(QUrl url);
     225              :     
     226              :     /*!
     227              :         \return True if this item is selected.
     228              :      */
     229           20 :     inline bool getIsSelected() const { return isSelected; }
     230              :     
     231            0 :     void setLastIconUpdate(QDateTime last) { lastIconUpdate = last; }
     232            1 :     QDateTime getLastIconUpdate() { return lastIconUpdate; }
     233              : 
     234              :     /*!
     235              :         \brief If true, the feed supports bookmarks.  Otherwise false.
     236              :         \return  By default, returns true.  Override if you want it to return false.
     237              :      */
     238              :     virtual bool bookmarksEnabled() const;
     239              : 
     240              :     /*!
     241              :         \brief getParentFolderID
     242              :         \return The ID of the parent folder, or -1 if none.
     243              :      */
     244           66 :     qint64 getParentFolderID() const {
     245           66 :         return _parentFolder;
     246              :     }
     247              :     
     248              : signals:
     249              :     
     250              :     void appended(NewsItem* item);
     251              :     void removed(NewsItem* item);
     252              :     void titleChanged();
     253              :     void unreadCountChanged(quint32 unread);
     254              :     void folderOpenChanged();
     255              :         
     256              : private:
     257              :     qint64 _id;
     258              :     qint32 ordinal;
     259              :     QString title;
     260              :     QString subtitle;
     261              :     QDateTime lastUpdated;
     262              :     quint32 minutesToUpdate;
     263              :     QUrl url;
     264              :     QUrl siteURL;
     265              :     QString userURL;
     266              :     QUrl imageURL;
     267              :     NewsList newsList;
     268              :     int isUpdating;
     269              :     qint32 unreadCount;
     270              :     qint64 _bookmarkID;
     271              :     QString dropTarget;
     272              :     bool _errorFlag;
     273              :     bool isSelected;
     274              :     QDateTime lastIconUpdate;
     275              :     qint64 firstNewsID;
     276              :     qint64 _parentFolder;
     277              :     bool _folderOpen;
     278              :     FeedType _feedType;
     279              :     QString etag;
     280              :     QString lastModified;
     281              : };
     282              : 
     283              : #endif // FEEDITEM_H
        

Generated by: LCOV version 2.0-1