Fix highlight on Shortcut area
[staging/HomeScreen.git] / HomeScreen / src / appinfo.cpp
1 /*
2  * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
3  * Copyright (C) 2016 The Qt Company Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "appinfo.h"
19
20 #include <QtCore/QJsonObject>
21
22 class AppInfo::Private : public QSharedData
23 {
24 public:
25     Private();
26     Private(const Private &other);
27
28     QString id;
29     QString version;
30     int width;
31     int height;
32     QString name;
33     QString description;
34     QString shortname;
35     QString author;
36     QString iconPath;
37 };
38
39 AppInfo::Private::Private()
40     : width(-1)
41     , height(-1)
42 {
43 }
44
45 AppInfo::Private::Private(const Private &other)
46     : QSharedData(other)
47     , id(other.id)
48     , version(other.version)
49     , width(other.width)
50     , height(other.height)
51     , name(other.name)
52     , description(other.description)
53     , shortname(other.shortname)
54     , author(other.author)
55     , iconPath(other.iconPath)
56 {
57 }
58
59 AppInfo::AppInfo()
60     : d(new Private)
61 {
62 }
63
64 AppInfo::AppInfo(const QString &icon, const QString &name, const QString &id)
65     : d(new Private)
66 {
67     d->iconPath = icon;
68     d->name = name;
69     d->id = id;
70 }
71
72 AppInfo::AppInfo(const AppInfo &other)
73     : d(other.d)
74 {
75 }
76
77 AppInfo::~AppInfo()
78 {
79 }
80
81 AppInfo &AppInfo::operator =(const AppInfo &other)
82 {
83     d = other.d;
84     return *this;
85 }
86
87 QString AppInfo::id() const
88 {
89     return d->id;
90 }
91
92 QString AppInfo::version() const
93 {
94     return d->version;
95 }
96
97 int AppInfo::width() const
98 {
99     return d->width;
100 }
101
102 int AppInfo::height() const
103 {
104     return d->height;
105 }
106
107 QString AppInfo::name() const
108 {
109     return d->name;
110 }
111
112 QString AppInfo::description() const
113 {
114     return d->description;
115 }
116
117 QString AppInfo::shortname() const
118 {
119     return d->shortname;
120 }
121
122 QString AppInfo::author() const
123 {
124     return d->author;
125 }
126
127 QString AppInfo::iconPath() const
128 {
129     return d->iconPath;
130 }
131
132 void AppInfo::read(const QJsonObject &json)
133 {
134     d->id = json["id"].toString();
135     d->version = json["version"].toString();
136     d->width = json["width"].toInt();
137     d->height = json["height"].toInt();
138     d->name = json["name"].toString();
139     d->description = json["description"].toString();
140     d->shortname = json["shortname"].toString();
141     d->author = json["author"].toString();
142     d->iconPath = json["iconPath"].toString();
143 }
144
145 QDBusArgument &operator <<(QDBusArgument &argument, const AppInfo &appInfo)
146 {
147     argument.beginStructure();
148     argument << appInfo.d->id;
149     argument << appInfo.d->version;
150     argument << appInfo.d->width;
151     argument << appInfo.d->height;
152     argument << appInfo.d->name;
153     argument << appInfo.d->description;
154     argument << appInfo.d->shortname;
155     argument << appInfo.d->author;
156     argument << appInfo.d->iconPath;
157     argument.endStructure();
158
159     return argument;
160 }
161
162 const QDBusArgument &operator >>(const QDBusArgument &argument, AppInfo &appInfo)
163 {
164     argument.beginStructure();
165     argument >> appInfo.d->id;
166     argument >> appInfo.d->version;
167     argument >> appInfo.d->width;
168     argument >> appInfo.d->height;
169     argument >> appInfo.d->name;
170     argument >> appInfo.d->description;
171     argument >> appInfo.d->shortname;
172     argument >> appInfo.d->author;
173     argument >> appInfo.d->iconPath;
174     argument.endStructure();
175     return argument;
176 }