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 | #include "flighttimes.h" |
23 | #include "node.h" |
24 | |
25 | #include <QStack> |
26 | |
27 | FlightTimes::FlightTimes(Direction direction, QObject *parent) |
28 | : XmlDataSource(parent), |
29 | m_timeFrom(1), // default |
30 | m_timeTo(7), // default |
31 | m_direction(direction) |
32 | { |
33 | // "http://flydata.avinor.no/XmlFeed.asp?TimeFrom=1&TimeTo=7&airport=OSL&direction=D&lastUpdate=2009-03-10T15:03:00" |
34 | setUrl(QUrl("http://flydata.avinor.no/XmlFeed.asp" )); |
35 | setRefreshRate(180000); //msecs == 3m |
36 | setTimeFrom(1); |
37 | setTimeTo(7); |
38 | setDirection(direction); |
39 | } |
40 | |
41 | FlightTimes::~FlightTimes() |
42 | { |
43 | } |
44 | |
45 | int FlightTimes::timeFrom() const |
46 | { |
47 | return m_timeFrom; |
48 | } |
49 | |
50 | /*! |
51 | Number of hours back in time the flight times start. |
52 | Non-obligatory. |
53 | */ |
54 | void FlightTimes::setTimeFrom(int time) |
55 | { |
56 | m_timeFrom = time; |
57 | insertQuery("TimeFrom" , QString::number(time)); |
58 | emit timeFromChanged(); |
59 | } |
60 | |
61 | /*! |
62 | Number of hours forwards in time the flight times end. |
63 | Non-obligatory. |
64 | */ |
65 | int FlightTimes::timeTo() const |
66 | { |
67 | return m_timeTo; |
68 | } |
69 | |
70 | void FlightTimes::setTimeTo(int time) |
71 | { |
72 | m_timeTo = time; |
73 | insertQuery("TimeTo" , QString::number(time)); |
74 | emit timeToChanged(); |
75 | } |
76 | |
77 | QString FlightTimes::airportCode() const |
78 | { |
79 | return m_airportCode; |
80 | } |
81 | |
82 | void FlightTimes::setAirportCode(const QString &code) |
83 | { |
84 | m_airportCode = code; |
85 | insertQuery("airport" , code); |
86 | emit airportCodeChanged(); |
87 | } |
88 | |
89 | FlightTimes::Direction FlightTimes::direction() const |
90 | { |
91 | return m_direction; |
92 | } |
93 | |
94 | void FlightTimes::setDirection(Direction direction) |
95 | { |
96 | m_direction = direction; |
97 | insertQuery("direction" , toString(direction)); |
98 | emit directionChanged(); |
99 | } |
100 | |
101 | QString FlightTimes::directionString() const |
102 | { |
103 | return toString(direction()); |
104 | } |
105 | |
106 | void FlightTimes::setDirectionString(const QString &direction) |
107 | { |
108 | setDirection(fromString(direction)); |
109 | } |
110 | |
111 | QDateTime FlightTimes::lastUpdate() const |
112 | { |
113 | return m_lastUpdate; |
114 | } |
115 | |
116 | void FlightTimes::setLastUpdate(const QDateTime &time) |
117 | { |
118 | m_lastUpdate = time; |
119 | insertQuery("lastUpdate" , time.toString(Qt::ISODate)); |
120 | emit lastUpdateChanged(); |
121 | } |
122 | |
123 | QString FlightTimes::toString(Direction direction) |
124 | { |
125 | switch (direction) { |
126 | case Departures: return "D" ; |
127 | case Arrivals: return "A" ; |
128 | case All: |
129 | default: |
130 | break; |
131 | } |
132 | return QString(); |
133 | } |
134 | |
135 | FlightTimes::Direction FlightTimes::fromString(const QString &direction) |
136 | { |
137 | if (direction == "D" ) |
138 | return Departures; |
139 | if (direction == "A" ) |
140 | return Arrivals; |
141 | return All; |
142 | } |
143 | |