Detach launcher application from HomeScreen
[apps/launcher.git] / launcher / 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
21 #include <QtCore/QJsonObject>
22
23 class AppInfo::Private : public QSharedData
24 {
25 public:
26     Private();
27     Private(const Private &other);
28
29     QString id;
30     QString version;
31     int width;
32     int height;
33     QString name;
34     QString description;
35     QString shortname;
36     QString author;
37     QString iconPath;
38 };
39
40 AppInfo::Private::Private()
41     : width(-1)
42     , height(-1)
43 {
44 }
45
46 AppInfo::Private::Private(const Private &other)
47     : QSharedData(other)
48     , id(other.id)
49     , version(other.version)
50     , width(other.width)
51     , height(other.height)
52     , name(other.name)
53     , description(other.description)
54     , shortname(other.shortname)
55     , author(other.author)
56     , iconPath(other.iconPath)
57 {
58 }
59
60 AppInfo::AppInfo()
61     : d(new Private)
62 {
63 }
64
65 AppInfo::AppInfo(const QString &icon, const QString &name, const QString &id)
66     : d(new Private)
67 {
68     d->iconPath = icon;
69     d->name = name;
70     d->id = id;
71 }
72
73 AppInfo::AppInfo(const AppInfo &other)
74     : d(other.d)
75 {
76 }
77
78 AppInfo::~AppInfo()
79 {
80 }
81
82 AppInfo &AppInfo::operator =(const AppInfo &other)
83 {
84     d = other.d;
85     return *this;
86 }
87
88 QString AppInfo::id() const
89 {
90     return d->id;
91 }
92
93 QString AppInfo::version() const
94 {
95     return d->version;
96 }
97
98 int AppInfo::width() const
99 {
100     return d->width;
101 }
102
103 int AppInfo::height() const
104 {
105     return d->height;
106 }
107
108 QString AppInfo::name() const
109 {
110     return d->name;
111 }
112
113 QString AppInfo::description() const
114 {
115     return d->description;
116 }
117
118 QString AppInfo::shortname() const
119 {
120     return d->shortname;
121 }
122
123 QString AppInfo::author() const
124 {
125     return d->author;
126 }
127
128 QString AppInfo::iconPath() const
129 {
130     return d->iconPath;
131 }
132
133 void AppInfo::read(const QJsonObject &json)
134 {
135     d->id = json["id"].toString();
136     d->version = json["version"].toString();
137     d->width = json["width"].toInt();
138     d->height = json["height"].toInt();
139     d->name = json["name"].toString();
140     d->description = json["description"].toString();
141     d->shortname = json["shortname"].toString();
142     d->author = json["author"].toString();
143     d->iconPath = json["iconPath"].toString();
144 }
145
146 QDBusArgument &operator <<(QDBusArgument &argument, const AppInfo &appInfo)
147 {
148     argument.beginStructure();
149     argument << appInfo.d->id;
150     argument << appInfo.d->version;
151     argument << appInfo.d->width;
152     argument << appInfo.d->height;
153     argument << appInfo.d->name;
154     argument << appInfo.d->description;
155     argument << appInfo.d->shortname;
156     argument << appInfo.d->author;
157     argument << appInfo.d->iconPath;
158     argument.endStructure();
159
160     return argument;
161 }
162
163 const QDBusArgument &operator >>(const QDBusArgument &argument, AppInfo &appInfo)
164 {
165     argument.beginStructure();
166     argument >> appInfo.d->id;
167     argument >> appInfo.d->version;
168     argument >> appInfo.d->width;
169     argument >> appInfo.d->height;
170     argument >> appInfo.d->name;
171     argument >> appInfo.d->description;
172     argument >> appInfo.d->shortname;
173     argument >> appInfo.d->author;
174     argument >> appInfo.d->iconPath;
175     argument.endStructure();
176     return argument;
177 }