BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
systemfactory.cpp
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #include "miscellaneous/systemfactory.h"
32 
33 #include "definitions/definitions.h"
34 #include "network-web/networkfactory.h"
35 #include "application.h"
36 
37 #if defined(Q_OS_WIN)
38 #include <QSettings>
39 #endif
40 
41 #include <QString>
42 #include <QFile>
43 #include <QDomDocument>
44 #include <QDomElement>
45 #include <QDomAttr>
46 
47 
48 SystemFactory::SystemFactory() {
49 }
50 
51 SystemFactory::~SystemFactory() {
52 }
53 
54 QPair<UpdateInfo, QNetworkReply::NetworkError> SystemFactory::checkForUpdates() {
55  QPair<UpdateInfo, QNetworkReply::NetworkError> result;
56  QByteArray releases_xml;
57 
58  result.second = NetworkFactory::downloadFile(RELEASES_LIST,
59  5000,
60  releases_xml);
61 
62  if (result.second == QNetworkReply::NoError) {
63  result.first = parseUpdatesFile(releases_xml);
64  }
65 
66  return result;
67 }
68 
69 UpdateInfo SystemFactory::parseUpdatesFile(const QByteArray &updates_file) {
70  UpdateInfo update;
71  QDomDocument document; document.setContent(updates_file, false);
72  QDomNodeList releases = document.elementsByTagName("release");
73 
74  if (releases.size() == 1) {
75  QDomElement rel_elem = releases.at(0).toElement();
76  QString type = rel_elem.attributes().namedItem("type").toAttr().value();
77 
78  update.m_availableVersion = rel_elem.attributes().namedItem("version").toAttr().value();
79  update.m_changes = rel_elem.namedItem("changes").toElement().text();
80 
81  QDomNodeList urls = rel_elem.elementsByTagName("url");
82 
83  for (int j = 0; j < urls.size(); j++) {
84  UpdateUrl url;
85  QDomElement url_elem = urls.at(j).toElement();
86 
87  url.m_fileUrl = url_elem.text();
88  url.m_os = url_elem.attributes().namedItem("os").toAttr().value();
89  url.m_platform = url_elem.attributes().namedItem("platform").toAttr().value();
90 
91  update.m_urls.insert(url.m_os,
92  url);
93  }
94 
95  if (type == "maintenance") {
96  update.m_type = UpdateInfo::Maintenance;
97  }
98  else {
99  update.m_type = UpdateInfo::Evolution;
100  }
101  }
102  else {
103  update.m_availableVersion = QString();
104  }
105 
106 
107  return update;
108 }
static UpdateInfo parseUpdatesFile(const QByteArray &updates_file)
Performs parsing of downloaded file with list of updates.
static QPair< UpdateInfo, QNetworkReply::NetworkError > checkForUpdates()
Tries to synchronously download list with new updates.
Information about available update.
Definition: systemfactory.h:49
static QNetworkReply::NetworkError downloadFile(const QString &url, int timeout, QByteArray &output, bool protected_contents=false, const QString &username=QString(), const QString &password=QString())
Performs SYNCHRONOUS download of file with given URL and given timeout.
Information about update metadata.
Definition: systemfactory.h:41