Plasma
packagemetadata.cpp
Go to the documentation of this file.
00001 /****************************************************************************** 00002 * Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org> * 00003 * * 00004 * This library is free software; you can redistribute it and/or * 00005 * modify it under the terms of the GNU Library General Public * 00006 * License as published by the Free Software Foundation; either * 00007 * version 2 of the License, or (at your option) any later version. * 00008 * * 00009 * This library is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00012 * Library General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU Library General Public License * 00015 * along with this library; see the file COPYING.LIB. If not, write to * 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 00017 * Boston, MA 02110-1301, USA. * 00018 *******************************************************************************/ 00019 00020 #include <packagemetadata.h> 00021 00022 #include <QDir> 00023 00024 #include <kconfiggroup.h> 00025 #include <kdesktopfile.h> 00026 00027 namespace Plasma 00028 { 00029 00030 class PackageMetadataPrivate 00031 { 00032 public: 00033 PackageMetadataPrivate() 00034 : type("Service") 00035 { 00036 } 00037 00038 QString name; 00039 QString icon; 00040 QString description; 00041 QStringList keywords; 00042 QString author; 00043 QString email; 00044 QString version; 00045 QString website; 00046 QString license; 00047 QString app; 00048 QString category; 00049 QString requiredVersion; 00050 QString pluginName; 00051 QString type; 00052 QString serviceType; 00053 QString api; 00054 KUrl location; 00055 }; 00056 00057 PackageMetadata::PackageMetadata(const PackageMetadata &other) 00058 : d(new PackageMetadataPrivate(*other.d)) 00059 { 00060 } 00061 00062 PackageMetadata &PackageMetadata::operator=(const PackageMetadata &other) 00063 { 00064 *d = *other.d; 00065 return *this; 00066 } 00067 00068 PackageMetadata::PackageMetadata(const QString &path) 00069 : d(new PackageMetadataPrivate) 00070 { 00071 read(path); 00072 } 00073 00074 PackageMetadata::~PackageMetadata() 00075 { 00076 delete d; 00077 } 00078 00079 bool PackageMetadata::isValid() const 00080 { 00081 return ! (d->name.isEmpty() || 00082 d->author.isEmpty() || 00083 d->license.isEmpty() || 00084 d->type.isEmpty()); 00085 } 00086 00087 void PackageMetadata::write(const QString &filename) const 00088 { 00089 KDesktopFile cfg(filename); 00090 KConfigGroup config = cfg.desktopGroup(); 00091 config.writeEntry("Encoding", "UTF-8"); 00092 00093 config.writeEntry("Name", d->name); 00094 config.writeEntry("Icon", d->icon); 00095 config.writeEntry("Comment", d->description); 00096 config.writeEntry("Keywords", d->keywords); 00097 config.deleteEntry("X-KDE-Keywords"); 00098 config.writeEntry("X-KDE-ServiceTypes", d->serviceType); 00099 config.deleteEntry("ServiceTypes"); 00100 config.writeEntry("X-KDE-PluginInfo-Name", d->pluginName); 00101 config.writeEntry("X-KDE-PluginInfo-Author", d->author); 00102 config.writeEntry("X-KDE-PluginInfo-Email", d->email); 00103 config.writeEntry("X-KDE-PluginInfo-Version", d->version); 00104 config.writeEntry("X-KDE-PluginInfo-Website", d->website); 00105 config.writeEntry("X-KDE-PluginInfo-License", d->license); 00106 config.writeEntry("X-KDE-PluginInfo-Category", d->category); 00107 config.writeEntry("X-Plasma-API", d->api); 00108 config.writeEntry("X-KDE-ParentApp", d->app); 00109 config.writeEntry("Type", d->type); 00110 config.writeEntry("X-Plasma-RemoteLocation", d->location); 00111 } 00112 00113 void PackageMetadata::read(const QString &filename) 00114 { 00115 if (filename.isEmpty()) { 00116 return; 00117 } 00118 00119 KDesktopFile cfg(filename); 00120 KConfigGroup config = cfg.desktopGroup(); 00121 00122 d->name = config.readEntry("Name", d->name); 00123 d->icon = config.readEntry("Icon", d->icon); 00124 d->description = config.readEntry("Comment", d->description); 00125 bool hasKeywords = config.hasKey("Keywords"); 00126 bool hasXKdeKeywords = config.hasKey("X-KDE-Keywords"); 00127 if (hasKeywords && hasXKdeKeywords) { 00128 d->keywords = config.readEntry("Keywords", d->keywords); 00129 d->keywords.append(config.readEntry("X-KDE-Keywords", d->keywords)); 00130 } else if (hasKeywords) { 00131 d->keywords = config.readEntry("Keywords", d->keywords); 00132 } else if (hasXKdeKeywords) { 00133 d->keywords = config.readEntry("X-KDE-Keywords", d->keywords); 00134 } 00135 bool hasServiceTypes = config.hasKey("ServiceTypes"); 00136 bool hasXKdeServiceTypes = config.hasKey("X-KDE-ServiceTypes"); 00137 if (hasServiceTypes && hasXKdeServiceTypes) { 00138 d->serviceType = config.readEntry("ServiceTypes", d->serviceType); 00139 d->serviceType.append(','); 00140 d->serviceType.append(config.readEntry("X-KDE-ServiceTypes", d->serviceType)); 00141 } else if (hasServiceTypes) { 00142 d->serviceType = config.readEntry("ServiceTypes", d->serviceType); 00143 } else if (hasXKdeServiceTypes) { 00144 d->serviceType = config.readEntry("X-KDE-ServiceTypes", d->serviceType); 00145 } 00146 d->pluginName = config.readEntry("X-KDE-PluginInfo-Name", d->pluginName); 00147 d->author = config.readEntry("X-KDE-PluginInfo-Author", d->author); 00148 d->email = config.readEntry("X-KDE-PluginInfo-Email", d->email); 00149 d->version = config.readEntry("X-KDE-PluginInfo-Version", d->version); 00150 d->website = config.readEntry("X-KDE-PluginInfo-Website", d->website); 00151 d->license = config.readEntry("X-KDE-PluginInfo-License", d->license); 00152 d->category = config.readEntry("X-KDE-PluginInfo-Category", d->category); 00153 d->api = config.readEntry("X-Plasma-API", d->api); 00154 d->app = config.readEntry("X-KDE-ParentApp", d->app); 00155 d->type = config.readEntry("Type", d->type); 00156 d->location = config.readEntry("X-Plasma-RemoteLocation", d->location); 00157 } 00158 00159 QString PackageMetadata::name() const 00160 { 00161 return d->name; 00162 } 00163 00164 QString PackageMetadata::description() const 00165 { 00166 return d->description; 00167 } 00168 00169 QString PackageMetadata::serviceType() const 00170 { 00171 return d->serviceType; 00172 } 00173 00174 QString PackageMetadata::author() const 00175 { 00176 return d->author; 00177 } 00178 00179 QString PackageMetadata::email() const 00180 { 00181 return d->email; 00182 } 00183 00184 QString PackageMetadata::icon() const 00185 { 00186 return d->icon; 00187 } 00188 00189 void PackageMetadata::setIcon(const QString &icon) 00190 { 00191 d->icon = icon; 00192 } 00193 00194 QString PackageMetadata::version() const 00195 { 00196 return d->version; 00197 } 00198 00199 QString PackageMetadata::website() const 00200 { 00201 return d->website; 00202 } 00203 00204 QString PackageMetadata::license() const 00205 { 00206 return d->license; 00207 } 00208 00209 QString PackageMetadata::application() const 00210 { 00211 return d->app; 00212 } 00213 00214 QString PackageMetadata::category() const 00215 { 00216 return d->category; 00217 } 00218 00219 void PackageMetadata::setKeywords(const QStringList &keywords) 00220 { 00221 d->keywords = keywords; 00222 } 00223 00224 QStringList PackageMetadata::keywords() const 00225 { 00226 return d->keywords; 00227 } 00228 00229 QString PackageMetadata::requiredVersion() const 00230 { 00231 return d->requiredVersion; 00232 } 00233 00234 KUrl PackageMetadata::remoteLocation() const 00235 { 00236 return d->location; 00237 } 00238 00239 QString PackageMetadata::type() const 00240 { 00241 return d->type; 00242 } 00243 00244 QString PackageMetadata::implementationApi() const 00245 { 00246 return d->api; 00247 } 00248 00249 void PackageMetadata::setImplementationApi(const QString &api) 00250 { 00251 d->api = api; 00252 } 00253 00254 QString PackageMetadata::pluginName() const 00255 { 00256 return d->pluginName; 00257 } 00258 00259 void PackageMetadata::setPluginName(const QString &pluginName) 00260 { 00261 d->pluginName = pluginName; 00262 } 00263 00264 void PackageMetadata::setName(const QString &name) 00265 { 00266 d->name = name; 00267 } 00268 00269 void PackageMetadata::setDescription(const QString &description) 00270 { 00271 d->description = description; 00272 } 00273 00274 void PackageMetadata::setServiceType(const QString &serviceType) 00275 { 00276 d->serviceType = serviceType; 00277 } 00278 00279 void PackageMetadata::setAuthor(const QString &author) 00280 { 00281 d->author = author; 00282 } 00283 00284 void PackageMetadata::setEmail(const QString &email) 00285 { 00286 d->email = email; 00287 } 00288 00289 void PackageMetadata::setVersion(const QString &version) 00290 { 00291 d->version = version; 00292 } 00293 00294 void PackageMetadata::setWebsite(const QString &website) 00295 { 00296 d->website = website; 00297 } 00298 00299 void PackageMetadata::setLicense(const QString &license) 00300 { 00301 d->license = license; 00302 } 00303 00304 void PackageMetadata::setApplication(const QString &application) 00305 { 00306 d->app = application; 00307 } 00308 00309 void PackageMetadata::setCategory(const QString &category) 00310 { 00311 d->category = category; 00312 } 00313 00314 void PackageMetadata::setRequiredVersion(const QString &requiredVersion) 00315 { 00316 d->requiredVersion = requiredVersion; 00317 } 00318 00319 void PackageMetadata::setRemoteLocation(const KUrl &location) 00320 { 00321 d->location = location; 00322 } 00323 00324 void PackageMetadata::setType(const QString &type) 00325 { 00326 d->type = type; 00327 } 00328 00329 } // namespace Plasma 00330
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:30:44 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:30:44 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.