• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.4 API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • plasma
packagemetadata.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 * Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org> *
3 * *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Library General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2 of the License, or (at your option) any later version. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Library General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Library General Public License *
15 * along with this library; see the file COPYING.LIB. If not, write to *
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301, USA. *
18 *******************************************************************************/
19 
20 #include <packagemetadata.h>
21 
22 #include <QDir>
23 
24 #include <kconfiggroup.h>
25 #include <kdesktopfile.h>
26 
27 namespace Plasma
28 {
29 
30 class PackageMetadataPrivate
31 {
32  public:
33  PackageMetadataPrivate()
34  : type("Service")
35  {
36  }
37 
38  QString name;
39  QString icon;
40  QString description;
41  QStringList keywords;
42  QString author;
43  QString email;
44  QString version;
45  QString website;
46  QString license;
47  QString app;
48  QString category;
49  QString requiredVersion;
50  QString pluginName;
51  QString type;
52  QString serviceType;
53  QString api;
54  KUrl location;
55  QStringList requiredDataEngines;
56 };
57 
58 PackageMetadata::PackageMetadata(const PackageMetadata &other)
59  : d(new PackageMetadataPrivate(*other.d))
60 {
61 }
62 
63 PackageMetadata &PackageMetadata::operator=(const PackageMetadata &other)
64 {
65  *d = *other.d;
66  return *this;
67 }
68 
69 PackageMetadata::PackageMetadata(const QString &path)
70  : d(new PackageMetadataPrivate)
71 {
72  read(path);
73 }
74 
75 PackageMetadata::~PackageMetadata()
76 {
77  delete d;
78 }
79 
80 bool PackageMetadata::isValid() const
81 {
82  return ! (d->name.isEmpty() ||
83  d->author.isEmpty() ||
84  d->license.isEmpty() ||
85  d->type.isEmpty());
86 }
87 
88 void PackageMetadata::write(const QString &filename) const
89 {
90  KDesktopFile cfg(filename);
91  KConfigGroup config = cfg.desktopGroup();
92  config.writeEntry("Encoding", "UTF-8");
93 
94  config.writeEntry("Name", d->name);
95  config.writeEntry("Icon", d->icon);
96  config.writeEntry("Comment", d->description);
97  config.writeEntry("Keywords", d->keywords);
98  config.deleteEntry("X-KDE-Keywords");
99  config.writeEntry("X-KDE-ServiceTypes", d->serviceType);
100  config.deleteEntry("ServiceTypes");
101  config.writeEntry("X-KDE-PluginInfo-Name", d->pluginName);
102  config.writeEntry("X-KDE-PluginInfo-Author", d->author);
103  config.writeEntry("X-KDE-PluginInfo-Email", d->email);
104  config.writeEntry("X-KDE-PluginInfo-Version", d->version);
105  config.writeEntry("X-KDE-PluginInfo-Website", d->website);
106  config.writeEntry("X-KDE-PluginInfo-License", d->license);
107  config.writeEntry("X-KDE-PluginInfo-Category", d->category);
108  config.writeEntry("X-Plasma-API", d->api);
109  config.writeEntry("X-KDE-ParentApp", d->app);
110  config.writeEntry("Type", d->type);
111  config.writeEntry("X-Plasma-RemoteLocation", d->location);
112  config.writeEntry("X-Plasma-RequiredDataEngines", d->requiredDataEngines);
113 }
114 
115 void PackageMetadata::read(const QString &filename)
116 {
117  if (filename.isEmpty()) {
118  return;
119  }
120 
121  KDesktopFile cfg(filename);
122  KConfigGroup config = cfg.desktopGroup();
123 
124  d->name = config.readEntry("Name", d->name);
125  d->icon = config.readEntry("Icon", d->icon);
126  d->description = config.readEntry("Comment", d->description);
127  bool hasKeywords = config.hasKey("Keywords");
128  bool hasXKdeKeywords = config.hasKey("X-KDE-Keywords");
129  if (hasKeywords && hasXKdeKeywords) {
130  d->keywords = config.readEntry("Keywords", d->keywords);
131  d->keywords.append(config.readEntry("X-KDE-Keywords", d->keywords));
132  } else if (hasKeywords) {
133  d->keywords = config.readEntry("Keywords", d->keywords);
134  } else if (hasXKdeKeywords) {
135  d->keywords = config.readEntry("X-KDE-Keywords", d->keywords);
136  }
137  bool hasServiceTypes = config.hasKey("ServiceTypes");
138  bool hasXKdeServiceTypes = config.hasKey("X-KDE-ServiceTypes");
139  if (hasServiceTypes && hasXKdeServiceTypes) {
140  d->serviceType = config.readEntry("ServiceTypes", d->serviceType);
141  d->serviceType.append(',');
142  d->serviceType.append(config.readEntry("X-KDE-ServiceTypes", d->serviceType));
143  } else if (hasServiceTypes) {
144  d->serviceType = config.readEntry("ServiceTypes", d->serviceType);
145  } else if (hasXKdeServiceTypes) {
146  d->serviceType = config.readEntry("X-KDE-ServiceTypes", d->serviceType);
147  }
148  d->pluginName = config.readEntry("X-KDE-PluginInfo-Name", d->pluginName);
149  d->author = config.readEntry("X-KDE-PluginInfo-Author", d->author);
150  d->email = config.readEntry("X-KDE-PluginInfo-Email", d->email);
151  d->version = config.readEntry("X-KDE-PluginInfo-Version", d->version);
152  d->website = config.readEntry("X-KDE-PluginInfo-Website", d->website);
153  d->license = config.readEntry("X-KDE-PluginInfo-License", d->license);
154  d->category = config.readEntry("X-KDE-PluginInfo-Category", d->category);
155  d->api = config.readEntry("X-Plasma-API", d->api);
156  d->app = config.readEntry("X-KDE-ParentApp", d->app);
157  d->type = config.readEntry("Type", d->type);
158  d->location = config.readEntry("X-Plasma-RemoteLocation", d->location);
159  d->requiredDataEngines = config.readEntry("X-Plasma-RequiredDataEngines", d->requiredDataEngines);
160 }
161 
162 QString PackageMetadata::name() const
163 {
164  return d->name;
165 }
166 
167 QString PackageMetadata::description() const
168 {
169  return d->description;
170 }
171 
172 QString PackageMetadata::serviceType() const
173 {
174  return d->serviceType;
175 }
176 
177 QString PackageMetadata::author() const
178 {
179  return d->author;
180 }
181 
182 QString PackageMetadata::email() const
183 {
184  return d->email;
185 }
186 
187 QString PackageMetadata::icon() const
188 {
189  return d->icon;
190 }
191 
192 void PackageMetadata::setIcon(const QString &icon)
193 {
194  d->icon = icon;
195 }
196 
197 QString PackageMetadata::version() const
198 {
199  return d->version;
200 }
201 
202 QString PackageMetadata::website() const
203 {
204  return d->website;
205 }
206 
207 QString PackageMetadata::license() const
208 {
209  return d->license;
210 }
211 
212 QString PackageMetadata::application() const
213 {
214  return d->app;
215 }
216 
217 QString PackageMetadata::category() const
218 {
219  return d->category;
220 }
221 
222 void PackageMetadata::setKeywords(const QStringList &keywords)
223 {
224  d->keywords = keywords;
225 }
226 
227 QStringList PackageMetadata::keywords() const
228 {
229  return d->keywords;
230 }
231 
232 QString PackageMetadata::requiredVersion() const
233 {
234  return d->requiredVersion;
235 }
236 
237 KUrl PackageMetadata::remoteLocation() const
238 {
239  return d->location;
240 }
241 
242 QString PackageMetadata::type() const
243 {
244  return d->type;
245 }
246 
247 QString PackageMetadata::implementationApi() const
248 {
249  return d->api;
250 }
251 
252 QStringList PackageMetadata::requiredDataEngines() const
253 {
254  return d->requiredDataEngines;
255 }
256 
257 void PackageMetadata::setImplementationApi(const QString &api)
258 {
259  d->api = api;
260 }
261 
262 QString PackageMetadata::pluginName() const
263 {
264  return d->pluginName;
265 }
266 
267 void PackageMetadata::setPluginName(const QString &pluginName)
268 {
269  d->pluginName = pluginName;
270 }
271 
272 void PackageMetadata::setName(const QString &name)
273 {
274  d->name = name;
275 }
276 
277 void PackageMetadata::setDescription(const QString &description)
278 {
279  d->description = description;
280 }
281 
282 void PackageMetadata::setServiceType(const QString &serviceType)
283 {
284  d->serviceType = serviceType;
285 }
286 
287 void PackageMetadata::setAuthor(const QString &author)
288 {
289  d->author = author;
290 }
291 
292 void PackageMetadata::setEmail(const QString &email)
293 {
294  d->email = email;
295 }
296 
297 void PackageMetadata::setVersion(const QString &version)
298 {
299  d->version = version;
300 }
301 
302 void PackageMetadata::setWebsite(const QString &website)
303 {
304  d->website = website;
305 }
306 
307 void PackageMetadata::setLicense(const QString &license)
308 {
309  d->license = license;
310 }
311 
312 void PackageMetadata::setApplication(const QString &application)
313 {
314  d->app = application;
315 }
316 
317 void PackageMetadata::setCategory(const QString &category)
318 {
319  d->category = category;
320 }
321 
322 void PackageMetadata::setRequiredVersion(const QString &requiredVersion)
323 {
324  d->requiredVersion = requiredVersion;
325 }
326 
327 void PackageMetadata::setRemoteLocation(const KUrl &location)
328 {
329  d->location = location;
330 }
331 
332 void PackageMetadata::setRequiredDataEngines(const QStringList &requiredDataEngines)
333 {
334  d->requiredDataEngines = requiredDataEngines;
335 }
336 
337 void PackageMetadata::setType(const QString &type)
338 {
339  d->type = type;
340 }
341 
342 } // namespace Plasma
343 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Mon Jul 15 2013 05:09:30 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.10.4 API Reference

Skip menu "kdelibs-4.10.4 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal