Line data Source code
1 : #ifndef LOADNEWSOPERATION_H
2 : #define LOADNEWSOPERATION_H
3 :
4 : #include <QObject>
5 : #include <QList>
6 :
7 : #include "DBOperation.h"
8 : #include "../models/FeedItem.h"
9 : #include "../models/NewsItem.h"
10 :
11 : /*!
12 : \brief Loads a batch of NewsItems.
13 : */
14 : class LoadNewsOperation : public DBOperation
15 : {
16 : Q_OBJECT
17 : public:
18 :
19 : enum LoadMode {
20 : Error = -1, // Runtime error
21 : Initial = 0, // Loads loadLimit items from the bookmark, plus loadlimit items above bookmark
22 : Append, // Appends loadLimit items (load next)
23 : Prepend // Prepends loadLimit items (load previous)
24 : };
25 :
26 : /*!
27 : \param parent The manager
28 : \param feedItem The feed item to grab
29 : \param mode Type of load operation (see above)
30 : \param loadLimit Max number of news items to load
31 : */
32 : explicit LoadNewsOperation(OperationManager *parent, FeedItem* feedItem, LoadMode mode, int loadLimit = 15);
33 :
34 : virtual ~LoadNewsOperation();
35 :
36 : static LoadMode stringToMode(QString modeString);
37 : static QString modeToString(LoadMode mode);
38 :
39 : public slots:
40 : virtual void execute();
41 :
42 : /*!
43 : \return The Feed associated with this load.
44 : */
45 0 : inline FeedItem* getFeedItem() { return feedItem; }
46 :
47 : /*!
48 : \return Returns the operational mode.
49 : */
50 7 : inline LoadNewsOperation::LoadMode getMode() { return mode; }
51 :
52 : /*!
53 : \return List of items that this load appended.
54 : */
55 13 : inline QList<NewsItem*>& getAppendList() { return listAppend; }
56 :
57 : /*!
58 : \return List of items that this load prepended.
59 : */
60 0 : inline QList<NewsItem*>& getPrependList() { return listPrepend; }
61 :
62 : /*!
63 : \return Max number of items to load (specified as loadLimit in constructor.)
64 : */
65 7 : inline int getLoadLimit() const { return loadLimit; }
66 :
67 : protected slots:
68 :
69 : /*!
70 : \brief Extracts news items from a database query.
71 : \param query Database query containing zero or more News Items.
72 : \param list The list of items items we just created.
73 : */
74 : void queryToNewsList(QSqlQuery& query, QList<NewsItem*>* list);
75 :
76 : /*!
77 : \brief Call this during the initial load of a feed.
78 : \return id of feed's bookmark.
79 : */
80 : qint64 getBookmarkID();
81 :
82 : /*!
83 : \brief Finds the very first item available in this feed, loaded or not. This is
84 : used to determine whether or not to display the top bookmark.
85 : \return id of the first item in the entire feed.
86 : */
87 : virtual qint64 getFirstNewsID();
88 :
89 : bool doAppend(qint64 startId);
90 :
91 : bool doPrepend(qint64 startId);
92 :
93 : /*!
94 : \brief Performs the actual query and loads the results into the appropriate list
95 : \param startId ID to start with
96 : \param append Which direction and which list to load into
97 : \return True if successful, false on an error
98 : */
99 : virtual bool executeLoadQuery(qint64 startId, bool append);
100 :
101 : // Returns the next ID after the last item in the feed's news list, or -1
102 : qint64 getStartIDForAppend();
103 :
104 : // Returns the first ID in the feed's news list, or -1
105 : qint64 getStartIDForPrepend();
106 :
107 : protected:
108 :
109 : // Feed we're adding to.
110 : FeedItem* feedItem;
111 :
112 : // List of items we appended.
113 : QList<NewsItem*> listAppend;
114 :
115 : // List of items we prepended.
116 : QList<NewsItem*> listPrepend;
117 :
118 : // True if we're appending.
119 : LoadMode mode;
120 :
121 : // Max # of news items to add.
122 : int loadLimit;
123 : };
124 :
125 : #endif // LOADNEWSOPERATION_H
|