/
newsfeedmodel.h
executable file
·60 lines (54 loc) · 1.59 KB
/
newsfeedmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef NEWSFEEDMODEL_H
#define NEWSFEEDMODEL_H
#include <QAbstractListModel>
#include <newsfeed.h>
#include <QWeakPointer>
namespace vk {
class Contact;
} //namespace vk
class NewsFeedModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QObject* client READ client WRITE setClient NOTIFY clientChanged)
public:
enum Roles {
TypeRole = Qt::UserRole,
PostIdRole,
SourceRole,
DateRole,
BodyRole,
AttachmentsRole,
LikesRole,
RepostsRole,
CommentsRole,
OwnerNameRole,
SourcePhotoRole,
SourceNameRole
};
explicit NewsFeedModel(QObject *parent = 0);
QObject* client() const;
void setClient(QObject* arg);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &) const;
int count() const;
public slots:
void getNews(int filters = vk::NewsFeed::FilterPost | vk::NewsFeed::FilterPhoto,
quint8 count = 10, int offset = 0);
int findNews(int id);
void clear();
void truncate(int count);
signals:
void clientChanged(QObject* client);
void requestFinished();
protected:
void insertNews(int index, const vk::NewsItem &data);
vk::Contact *findContact(int id) const;
private slots:
void onNewsAdded(const vk::NewsItem &data);
private:
QWeakPointer<vk::Client> m_client;
QWeakPointer<vk::NewsFeed> m_newsFeed;
vk::NewsItemList m_newsList;
Qt::SortOrder m_sortOrder;
};
#endif // NEWSFEEDMODEL_H