Initial Commit
[uktrainplanner] / src / servicewindow.h
1 #ifndef SERVICEWINDOW_H
2 #define SERVICEWINDOW_H
3
4 #include <QMainWindow>
5 #include <QtNetwork>
6 #include <QtXml>
7 #include <QtXmlPatterns>
8 #include "departurewidget.h"
9 #include <QtGui>
10
11 namespace Ui {
12     class ServiceWindow;
13 }
14
15 class ServiceWindow : public QMainWindow
16 {
17     Q_OBJECT
18 public:
19     ServiceWindow(QWidget *parent = 0);
20     ~ServiceWindow();
21
22     void sendRequest(); //Send the network request
23     void show(QString serviceID);
24
25 protected:
26     void changeEvent(QEvent *e);
27
28 public slots:
29     void readResponse(QNetworkReply*); //Read the network response & extract the required data
30     void networkError(QNetworkReply::NetworkError);
31
32     void downloadProgress(qint64 rec, qint64 total);
33     void uploadProgress(qint64 rec, qint64 total);
34
35     void ensureConnection(); //Used to wait for a network connection
36     void cancel(); //Cancel the current request for the departure board
37
38 private:
39     Ui::ServiceWindow *ui;
40
41     QString serviceID;
42
43     QNetworkAccessManager * manager;
44     QNetworkReply * m_reply;
45
46     ServiceWindow * serviceWindow;
47
48     QBuffer received;
49     QString from;
50
51     void setupDialog();
52     void setupRequest();
53
54     QNetworkRequest request;
55     QString requestData;
56
57     inline QString queryOne(QXmlQuery & q, QString query);
58     inline QStringList queryList(QXmlQuery & q, QString query);
59
60     QVector<DepartureWidget *> departureWidgets;
61
62     QDialog * dialog; //Dialog with progress bar for the network request
63         QLayout * layout;
64             QProgressBar * progress;
65             QPushButton * cancelButton;
66
67     bool errorFlag;
68     bool firstTime;
69 };
70
71 #endif // SERVICEWINDOW_H