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