diff options
author | dgerlach | 2012-09-24 16:20:24 -0500 |
---|---|---|
committer | dgerlach | 2012-09-24 16:20:24 -0500 |
commit | 5fdd11044a3b16284d5aee5774408acb2f79c313 (patch) | |
tree | d009e152ca603f56245e795c415ccbd93d9721c3 | |
parent | 0a8ddb3af96b77c5bc9c7e4163e261eb36ccdae6 (diff) | |
download | thermostat-demo-5fdd11044a3b16284d5aee5774408acb2f79c313.tar.gz thermostat-demo-5fdd11044a3b16284d5aee5774408acb2f79c313.tar.xz thermostat-demo-5fdd11044a3b16284d5aee5774408acb2f79c313.zip |
webdata: improved documentation
wundergrounddataengine: added cache flag setting
-rw-r--r-- | ThermostatDemoSource/forecastdatawidget.cpp | 2 | ||||
-rw-r--r-- | ThermostatDemoSource/webdata.cpp | 45 | ||||
-rw-r--r-- | ThermostatDemoSource/webdataengine/wundergrounddataengine.cpp | 13 | ||||
-rw-r--r-- | ThermostatDemoSource/webdataengine/wundergrounddataengine.h | 2 |
4 files changed, 54 insertions, 8 deletions
diff --git a/ThermostatDemoSource/forecastdatawidget.cpp b/ThermostatDemoSource/forecastdatawidget.cpp index 69a4026..ccaad56 100644 --- a/ThermostatDemoSource/forecastdatawidget.cpp +++ b/ThermostatDemoSource/forecastdatawidget.cpp | |||
@@ -65,7 +65,7 @@ ForecastDataWidget::ForecastDataWidget(QWidget *parent) : | |||
65 | 65 | ||
66 | } | 66 | } |
67 | 67 | ||
68 | //FUNCTION: createScreenLayout | 68 | //FUNCTION: setData |
69 | // | 69 | // |
70 | // A setter function that gives the widget the data list obtained from the web | 70 | // A setter function that gives the widget the data list obtained from the web |
71 | // | 71 | // |
diff --git a/ThermostatDemoSource/webdata.cpp b/ThermostatDemoSource/webdata.cpp index 2506f5b..691181f 100644 --- a/ThermostatDemoSource/webdata.cpp +++ b/ThermostatDemoSource/webdata.cpp | |||
@@ -13,6 +13,12 @@ | |||
13 | #include <QtDebug> | 13 | #include <QtDebug> |
14 | #include <QTime> | 14 | #include <QTime> |
15 | 15 | ||
16 | /*********************************************************************************************************** | ||
17 | * WebData | ||
18 | * Class that wraps a webdataengine used for retrieving data from an online API. Handles network connection | ||
19 | * manager and also configures the proxy, first by trying none and then a known one, then failing. | ||
20 | ************************************************************************************************************/ | ||
21 | |||
16 | WebData::WebData(QObject *parent) : | 22 | WebData::WebData(QObject *parent) : |
17 | QObject(parent) | 23 | QObject(parent) |
18 | { | 24 | { |
@@ -25,12 +31,17 @@ WebData::WebData(QObject *parent) : | |||
25 | connect(webDataEngine, SIGNAL(dataAvailable(WeatherData*)), this, SLOT(processDataAvailable(WeatherData*))); | 31 | connect(webDataEngine, SIGNAL(dataAvailable(WeatherData*)), this, SLOT(processDataAvailable(WeatherData*))); |
26 | connect(webDataEngine, SIGNAL(networkTimeout()), this, SLOT(processNetworkTimeout())); | 32 | connect(webDataEngine, SIGNAL(networkTimeout()), this, SLOT(processNetworkTimeout())); |
27 | 33 | ||
34 | //set proxy by default to none so we can try it | ||
28 | m_proxyState = WebData::ExternalTI; | 35 | m_proxyState = WebData::ExternalTI; |
29 | 36 | ||
30 | configureProxy(); | 37 | configureProxy(); |
31 | 38 | ||
32 | } | 39 | } |
33 | 40 | ||
41 | //FUNCTION: configureProxy() | ||
42 | // | ||
43 | // configures the correct proxy based on the ProxyState enum defined | ||
44 | |||
34 | void WebData::configureProxy() | 45 | void WebData::configureProxy() |
35 | { | 46 | { |
36 | //qDebug() << m_proxyState << manager->proxy().hostName() << manager->proxy().port(); | 47 | //qDebug() << m_proxyState << manager->proxy().hostName() << manager->proxy().port(); |
@@ -51,18 +62,30 @@ void WebData::configureProxy() | |||
51 | } | 62 | } |
52 | } | 63 | } |
53 | 64 | ||
65 | //FUNCTION: configureNoProxy() | ||
66 | // | ||
67 | // Sets the network access manager to use no proxy at all | ||
68 | |||
54 | void WebData::configureNoProxy() | 69 | void WebData::configureNoProxy() |
55 | { | 70 | { |
56 | manager->setProxy(QNetworkProxy(QNetworkProxy::NoProxy)); | 71 | manager->setProxy(QNetworkProxy(QNetworkProxy::NoProxy)); |
57 | m_proxyState = WebData::ExternalTI; | 72 | m_proxyState = WebData::ExternalTI; |
58 | } | 73 | } |
59 | 74 | ||
75 | //FUNCTION: configureTIProxy() | ||
76 | // | ||
77 | // Sets the network access manager to use the internal TI proxy | ||
78 | |||
60 | void WebData::configureTIProxy() | 79 | void WebData::configureTIProxy() |
61 | { | 80 | { |
62 | manager->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "wwwgate.ti.com", 80)); | 81 | manager->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "wwwgate.ti.com", 80)); |
63 | m_proxyState = WebData::InternalTI; | 82 | m_proxyState = WebData::InternalTI; |
64 | } | 83 | } |
65 | 84 | ||
85 | //FUNCTION: configureSetProxy() | ||
86 | // | ||
87 | // Sets the network access manager to use proxy that is configured in the settings | ||
88 | |||
66 | void WebData::configureSetProxy() | 89 | void WebData::configureSetProxy() |
67 | { | 90 | { |
68 | QNetworkProxy proxy; | 91 | QNetworkProxy proxy; |
@@ -73,22 +96,39 @@ void WebData::configureSetProxy() | |||
73 | m_proxyState = WebData::Configured; | 96 | m_proxyState = WebData::Configured; |
74 | } | 97 | } |
75 | 98 | ||
99 | //FUNCTION: changeCity() | ||
100 | // | ||
101 | // Sets the webDataEngine's city variable and then dispatches a request | ||
102 | |||
76 | void WebData::changeCity(QString city) | 103 | void WebData::changeCity(QString city) |
77 | { | 104 | { |
78 | webDataEngine->setCity(city); | 105 | webDataEngine->setCity(city); |
79 | webDataEngine->dispatchRequest(); | 106 | webDataEngine->dispatchRequest(); |
80 | } | 107 | } |
81 | 108 | ||
109 | //FUNCTION: loadLocalData() | ||
110 | // | ||
111 | // invokes the webdataengine's loadLocalData function to pull locally cached data | ||
112 | |||
82 | void WebData::loadLocalData() | 113 | void WebData::loadLocalData() |
83 | { | 114 | { |
84 | webDataEngine->loadLocalData(); | 115 | webDataEngine->loadLocalData(); |
85 | } | 116 | } |
86 | 117 | ||
118 | //FUNCTION: licenseString() | ||
119 | // | ||
120 | // Returns the defined license string in the webdataengine | ||
121 | |||
87 | QString WebData::licenseString() | 122 | QString WebData::licenseString() |
88 | { | 123 | { |
89 | return webDataEngine->licenseString(); | 124 | return webDataEngine->licenseString(); |
90 | } | 125 | } |
91 | 126 | ||
127 | //FUNCTION: processDataAvailable() | ||
128 | // | ||
129 | // Catches the dataAvailable signal from the webdataengine and sets the proxy if it worked | ||
130 | // Otherwise emits signal with either web data or cache data | ||
131 | |||
92 | void WebData::processDataAvailable(WeatherData *weatherData) | 132 | void WebData::processDataAvailable(WeatherData *weatherData) |
93 | { | 133 | { |
94 | qDebug() << weatherData->cachedData(); | 134 | qDebug() << weatherData->cachedData(); |
@@ -102,6 +142,11 @@ void WebData::processDataAvailable(WeatherData *weatherData) | |||
102 | emit dataAvailable(weatherData); | 142 | emit dataAvailable(weatherData); |
103 | } | 143 | } |
104 | 144 | ||
145 | //FUNCTION: processNetworkTimeout() | ||
146 | // | ||
147 | // Catches the networkTimeout signal form the webdataengine and tries a new proxy if | ||
148 | // still in the configuration phase. Other wise emits a normal networkTimeout signal | ||
149 | |||
105 | void WebData::processNetworkTimeout() | 150 | void WebData::processNetworkTimeout() |
106 | { | 151 | { |
107 | //if we fail with a particular proxy, move on to the next in the list | 152 | //if we fail with a particular proxy, move on to the next in the list |
diff --git a/ThermostatDemoSource/webdataengine/wundergrounddataengine.cpp b/ThermostatDemoSource/webdataengine/wundergrounddataengine.cpp index 042a14d..3dd747c 100644 --- a/ThermostatDemoSource/webdataengine/wundergrounddataengine.cpp +++ b/ThermostatDemoSource/webdataengine/wundergrounddataengine.cpp | |||
@@ -48,11 +48,11 @@ void WundergroundDataEngine::dispatchRequest() | |||
48 | connect(m_reply, SIGNAL(finished()),this,SLOT(responseReceived())); | 48 | connect(m_reply, SIGNAL(finished()),this,SLOT(responseReceived())); |
49 | } | 49 | } |
50 | 50 | ||
51 | void WundergroundDataEngine::parseXML(QByteArray* xmlData) | 51 | void WundergroundDataEngine::parseXML(QByteArray* xmlData, bool cached) |
52 | { | 52 | { |
53 | WeatherData *weatherData = NULL; | ||
54 | QBuffer xmlBuffer(xmlData); | 53 | QBuffer xmlBuffer(xmlData); |
55 | 54 | WeatherData *weatherData = NULL; | |
55 | ForecastData *forecastData = NULL; | ||
56 | // create XML reader on the document held in reply | 56 | // create XML reader on the document held in reply |
57 | reader.setDevice(&xmlBuffer); | 57 | reader.setDevice(&xmlBuffer); |
58 | xmlBuffer.open(QBuffer::ReadWrite); | 58 | xmlBuffer.open(QBuffer::ReadWrite); |
@@ -75,7 +75,7 @@ void WundergroundDataEngine::parseXML(QByteArray* xmlData) | |||
75 | name = reader.name().toString(); | 75 | name = reader.name().toString(); |
76 | if(name == "forecastday") | 76 | if(name == "forecastday") |
77 | { | 77 | { |
78 | ForecastData *forecastData = parseXMLForecastData(reader); | 78 | forecastData = parseXMLForecastData(reader); |
79 | weatherData->addForecastDay(forecastData); | 79 | weatherData->addForecastDay(forecastData); |
80 | } | 80 | } |
81 | if(name == "simpleforecast" && reader.isEndElement()) | 81 | if(name == "simpleforecast" && reader.isEndElement()) |
@@ -92,7 +92,8 @@ void WundergroundDataEngine::parseXML(QByteArray* xmlData) | |||
92 | else if (reader.atEnd()) { | 92 | else if (reader.atEnd()) { |
93 | qDebug() << "Reached end of XML document" << endl; | 93 | qDebug() << "Reached end of XML document" << endl; |
94 | } | 94 | } |
95 | 95 | if(cached) | |
96 | weatherData->setCachedDataFlag(); | ||
96 | 97 | ||
97 | emit dataAvailable(weatherData); | 98 | emit dataAvailable(weatherData); |
98 | xmlBuffer.close(); | 99 | xmlBuffer.close(); |
@@ -236,7 +237,7 @@ void WundergroundDataEngine::loadLocalData() | |||
236 | if(!result) | 237 | if(!result) |
237 | readFromCache(&xmlData, ":/data/cache.xml"); | 238 | readFromCache(&xmlData, ":/data/cache.xml"); |
238 | 239 | ||
239 | parseXML(&xmlData); | 240 | parseXML(&xmlData, true); |
240 | } | 241 | } |
241 | 242 | ||
242 | //FUNCTION writeToCache | 243 | //FUNCTION writeToCache |
diff --git a/ThermostatDemoSource/webdataengine/wundergrounddataengine.h b/ThermostatDemoSource/webdataengine/wundergrounddataengine.h index 5605b5e..793d095 100644 --- a/ThermostatDemoSource/webdataengine/wundergrounddataengine.h +++ b/ThermostatDemoSource/webdataengine/wundergrounddataengine.h | |||
@@ -22,7 +22,7 @@ signals: | |||
22 | 22 | ||
23 | public slots: | 23 | public slots: |
24 | void responseReceived(); | 24 | void responseReceived(); |
25 | void parseXML(QByteArray *xmlData); | 25 | void parseXML(QByteArray *xmlData, bool cached = false); |
26 | private: | 26 | private: |
27 | bool writeToCache(QByteArray *xmlData); | 27 | bool writeToCache(QByteArray *xmlData); |
28 | bool readFromCache(QByteArray *xmlData, QString alternateCacheFile = ""); | 28 | bool readFromCache(QByteArray *xmlData, QString alternateCacheFile = ""); |