warehouse for ces2019
[apps/onscreenapp.git] / app / src / appinfo.cpp
1 /*
2  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
3  * Copyright (C) 2016 The Qt Company Ltd.
4  * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include "appinfo.h"
20 #include "hmi-debug.h"
21
22 class AppInfo::Private : public QSharedData {
23  public:
24   Private();
25   Private(const Private& other);
26
27   QString id;
28   QString version;
29   int width;
30   int height;
31   QString name;
32   QString description;
33   QString shortname;
34   QString author;
35   QString iconPath;
36   AppState state;
37   qreal progress;
38
39   QString serverid;
40   QString wgtpath;
41   QString filename;
42   QString categoryid;
43   QString categoryname;
44   QString deviceid;
45   QString devicename;
46   double createdtime;
47 };
48
49 AppInfo::Private::Private() : width(-1), height(-1) {}
50
51 AppInfo::Private::Private(const Private& other)
52     : QSharedData(other),
53       id(other.id),
54       version(other.version),
55       width(other.width),
56       height(other.height),
57       name(other.name),
58       description(other.description),
59       shortname(other.shortname),
60       author(other.author),
61       iconPath(other.iconPath),
62       state(other.state),
63       progress(other.progress),
64       serverid(other.serverid),
65       wgtpath(other.wgtpath),
66       filename(other.filename),
67       categoryid(other.categoryid),
68       categoryname(other.categoryname),
69       deviceid(other.deviceid),
70       devicename(other.devicename),
71       createdtime(other.createdtime) {}
72
73 AppInfo::AppInfo() : d(new Private) {}
74
75 AppInfo::AppInfo(const QString& icon, const QString& name, const QString& id)
76     : d(new Private) {
77   d->iconPath = icon;
78   d->name = name;
79   d->id = id;
80 }
81
82 AppInfo::AppInfo(const AppInfo& other) : d(other.d) {}
83
84 AppInfo::~AppInfo() {}
85
86 AppInfo& AppInfo::operator=(const AppInfo& other) {
87   d = other.d;
88   return *this;
89 }
90
91 QString AppInfo::id() const {
92   return d->id;
93 }
94
95 QString AppInfo::version() const {
96   return d->version;
97 }
98
99 int AppInfo::width() const {
100   return d->width;
101 }
102
103 int AppInfo::height() const {
104   return d->height;
105 }
106
107 QString AppInfo::name() const {
108   return d->name;
109 }
110
111 QString AppInfo::description() const {
112   return d->description;
113 }
114
115 QString AppInfo::shortname() const {
116   return d->shortname;
117 }
118
119 QString AppInfo::author() const {
120   return d->author;
121 }
122
123 QString AppInfo::iconPath() const {
124   return d->iconPath;
125 }
126
127 AppInfo::AppState AppInfo::state() const {
128   return d->state;
129 }
130
131 qreal AppInfo::progress() const {
132   return d->progress;
133 }
134
135 QString AppInfo::serverId() const {
136   return d->serverid;
137 }
138 QString AppInfo::wgtPath() const {
139   return d->wgtpath;
140 }
141 QString AppInfo::fileName() const {
142   return d->filename;
143 }
144
145 QString AppInfo::categoryId() const {
146   return d->categoryid;
147 }
148 QString AppInfo::categoryName() const {
149   return d->categoryname;
150 }
151 QString AppInfo::deviceId() const {
152   return d->deviceid;
153 }
154 QString AppInfo::deviceName() const {
155   return d->devicename;
156 }
157 double AppInfo::createdTime() const {
158   return d->createdtime;
159 }
160
161 void AppInfo::setState(const AppState state) {
162   d->state = state;
163 }
164
165 void AppInfo::setProgress(const qreal progress) {
166   d->progress = progress;
167 }
168
169 void AppInfo::read(const QJsonObject& json) {
170   d->id = json["id"].toString();
171   d->version = json["version"].toString();
172   d->width = json["width"].toInt();
173   d->height = json["height"].toInt();
174   d->name = json["name"].toString();
175   d->description = json["description"].toString();
176   d->shortname = json["shortname"].toString();
177   d->author = json["author"].toString();
178   d->iconPath = json["icon"].toString();
179   d->state = Launch;
180 }
181
182 void AppInfo::readFromServer(const QJsonObject& json) {
183   d->name = json["appName"].toString();
184   d->description = json["appAbstract"].toString();
185   d->version = json["versionName"].toString();
186   d->id = json["appIdCustom"].toString() + "@" + d->version;
187   d->serverid = json["appId"].toString();
188   d->wgtpath = json["verFilePath"].toString();
189   d->filename = json["verFilePath"].toString().section('/', -1);
190   d->author = json["developerName"].toString();
191   d->categoryid = json["typeId"].toString();
192   d->categoryname = json["typeName"].toString();
193   d->deviceid = json["appDeviceTypeId"].toString();
194   d->devicename = json["appDeviceTypeName"].toString();
195   d->createdtime = json["updateDate"].toDouble();
196   // d->iconPath = json["icon"].toString();
197   d->iconPath = "file:///var/local/lib/afm/applications/launcher/0.1/icon.svg";
198   d->state = Install;
199   d->progress = 0.0;
200 }