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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#ifndef BOARD_H
#define BOARD_H
#include <QtCore/QDateTime>
#include <QtCore/QObject>
#include <QtCore/QPair>
#include <QtCore/QQueue>
#include <QtSql/QSqlDatabase>
class Action;
class XmlRpcInterface;
class Board : public QObject
{
Q_OBJECT
public:
explicit Board(const QString& boardUrl, QObject *parent = 0);
~Board();
static const QLatin1String CURRENT_DB_VERSION;
bool busy() const;
void enqueueAction(Action* action);
QSqlDatabase database();
XmlRpcInterface *service();
// Configuration table
QString getConfig(const QString& key) const;
void setConfig(const QString& key, const QString &value);
// Some helper functions
QString removeHtml(QString text) const;
QString removeBbcode(QString text) const;
QString bbcodeToRichText(QString text) const;
QString renderHumanDate(const QDateTime& dateTime);
QString renderHumanTime(const QDateTime& dateTime);
// These functions wrap emitting the signals below
void notifyConfigChanged();
void notifyForumsChanged();
void notifyForumTopicsChanged(int forumId, int start, int end);
void notifyTopicPostsChanged(int topicId, int start, int end);
signals:
void configChanged();
void forumsChanged();
void imageChanged(const QString& imageUrl);
void forumTopicsChanged(int forumId, int start, int end);
void topicPostsChanged(int topicId, int start, int end);
private:
static QString createSlug(const QString& forumUrl);
static QString getDbPathFor(const QString& slug);
static QString getTempDbPathFor(const QString& slug);
bool checkCompatibleDb();
bool initializeDb();
bool eraseDb();
bool cleanDb();
bool removeFromActionQueue(Action *action);
void executeActionFromQueue();
void initializeBbCode();
void fetchConfigIfOutdated();
void fetchForumsIfOutdated();
private slots:
void handleActionFinished(Action *action);
void handleActionError(Action *action, const QString& message);
private:
QString _url;
QString _slug;
QSqlDatabase _db;
XmlRpcInterface *_iface;
QQueue<Action*> _queue;
QList< QPair<QRegExp, QString> > _bbcodes;
};
inline bool Board::busy() const
{
return !_queue.empty();
}
inline QSqlDatabase Board::database()
{
return _db;
}
inline XmlRpcInterface * Board::service()
{
return _iface;
}
#endif // BOARD_H
|