1 | /* |
2 | * Copyright (C) 2012 Cutehacks AS. All rights reserved. |
3 | * info@cutehacks.com |
4 | * http://cutehacks.com |
5 | * |
6 | * This file is part of Fly. |
7 | * |
8 | * Fly is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * Fly is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with Fly. If not, see <http://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | #ifndef XMLDATASOURCE_H |
23 | #define XMLDATASOURCE_H |
24 | |
25 | #include <QHash> |
26 | #include <QObject> |
27 | #include <QBasicTimer> |
28 | #include <QDateTime> |
29 | #include <QUrl> |
30 | |
31 | class XmlReceiver; |
32 | class Node; |
33 | |
34 | class XmlDataSource : public QObject |
35 | { |
36 | Q_OBJECT |
37 | Q_PROPERTY(int refershRate READ refreshRate WRITE setRefreshRate) |
38 | Q_PROPERTY(QUrl url READ url WRITE setUrl) |
39 | Q_PROPERTY(bool waiting READ isWaiting) |
40 | public: |
41 | XmlDataSource(QObject *parent = 0); |
42 | ~XmlDataSource(); |
43 | |
44 | int refreshRate() const; |
45 | void setRefreshRate(int rate); |
46 | |
47 | QUrl url() const; |
48 | void setUrl(const QUrl &url); |
49 | |
50 | bool isWaiting() const; |
51 | |
52 | void insertQuery(const QString &name, const QString &value); |
53 | void removeQuery(const QString &name); |
54 | |
55 | Q_SIGNALS: |
56 | void dataUpdated(Node *root); |
57 | |
58 | public Q_SLOTS: |
59 | void start(); |
60 | void stop(); |
61 | |
62 | protected Q_SLOTS: |
63 | void dataReceived(); |
64 | void executeQuery(); |
65 | |
66 | protected: |
67 | void timerEvent(QTimerEvent *event); |
68 | |
69 | Node *root() const; |
70 | |
71 | private: |
72 | XmlReceiver *m_receiver; |
73 | QBasicTimer m_timer; |
74 | int m_refreshRate; |
75 | QUrl m_url; |
76 | bool m_waiting; |
77 | QDateTime m_timestamp; |
78 | QHash<QString, QString> m_queryItems; |
79 | }; |
80 | |
81 | #endif |
82 | |