2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 #ifndef NETWORKACCESSMANAGER_H
23 #define NETWORKACCESSMANAGER_H
27 #include <QNetworkReply>
28 #include <QNetworkRequest>
29 #include <QAbstractNetworkCache>
32 class QNetworkAccessManager;
35 * @brief NetworkAccessManager class.
37 * This class handles network requests and receives network replies.
38 * NetworkAccessManager queues requests when disconnected from network
39 * and makes requests when connected to network.
41 class NetworkAccessManager : public QObject
45 /*******************************************************************************
46 * MEMBER FUNCTIONS AND SLOTS
47 ******************************************************************************/
52 * @param parent QObject
54 NetworkAccessManager(QObject *parent = 0);
57 * @brief Returns connection state.
59 * @return true if connected, false otherwise
64 * @brief Makes get request and returns reply.
66 * @param request QNetworkRequest
67 * @param onlineRequestsOnly true if does only requests when online, false otherwise
68 * @return QNetworkReply
70 QNetworkReply *get(const QNetworkRequest &request, bool onlineRequestsOnly = false);
73 * @brief Makes post request and returns reply.
75 * @param request QNetworkRequest
76 * @param data QByteArray
77 * @param onlineRequestsOnly bool
78 * @return QNetworkReply
80 QNetworkReply *post(const QNetworkRequest &request, QByteArray &data,
81 bool onlineRequestsOnly = false);
86 * @param cache QAbstractNetworkCache instance
88 void setCache(QAbstractNetworkCache *cache);
91 * @brief Returns cache.
93 * @return QAbstractNetworkCache
95 QAbstractNetworkCache *cache() const;
99 * @brief Slot for network connected state.
104 * @brief Slot for network disconnected state.
109 * @brief Slot for finished download.
111 * @param reply reply from network
113 void downloadFinished(QNetworkReply *reply);
115 /*******************************************************************************
117 ******************************************************************************/
120 * Signal for finished download.
122 * @param reply reply from network
124 void finished(QNetworkReply *reply);
126 /*******************************************************************************
128 ******************************************************************************/
130 bool m_connected; ///< Connection flag
131 NetworkHandler *m_networkHandler; ///< Instance of NetworkHandler
132 QNetworkAccessManager *m_networkAccessManagerPrivate; ///< Instance of QNetworkAccessManager
133 QList<QNetworkRequest> m_requestQueue; ///< Queue for requests
134 QHash<QString, QNetworkReply*> m_offlineReplyQueue; ///< Queue for offline replies
135 QHash<QString, QNetworkReply*> m_temporaryReplyQueue; ///< Queue for temporary replies
138 #endif // NETWORKACCESSMANAGER_H