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("Comment", d->description); 00095 config.writeEntry("Keywords", d->keywords); 00096 config.writeEntry("X-KDE-ServiceTypes", d->serviceType); 00097 config.writeEntry("X-KDE-PluginInfo-Name", d->pluginName); 00098 config.writeEntry("X-KDE-PluginInfo-Author", d->author); 00099 config.writeEntry("X-KDE-PluginInfo-Email", d->email); 00100 config.writeEntry("X-KDE-PluginInfo-Version", d->version); 00101 config.writeEntry("X-KDE-PluginInfo-Website", d->website); 00102 config.writeEntry("X-KDE-PluginInfo-License", d->license); 00103 config.writeEntry("X-KDE-PluginInfo-Category", d->category); 00104 config.writeEntry("X-Plasma-API", d->api); 00105 config.writeEntry("X-KDE-ParentApp", d->app); 00106 config.writeEntry("Type", d->type); 00107 config.writeEntry("X-Plasma-RemoteLocation", d->location); 00108 } 00109 00110 void PackageMetadata::read(const QString &filename) 00111 { 00112 if (filename.isEmpty()) { 00113 return; 00114 } 00115 00116 KDesktopFile cfg(filename); 00117 KConfigGroup config = cfg.desktopGroup(); 00118 00119 d->name = config.readEntry("Name", d->name); 00120 d->icon = config.readEntry("Icon", d->name); 00121 d->description = config.readEntry("Comment", d->description); 00122 d->keywords = config.readEntry("Keywords", d->keywords); 00123 d->serviceType = config.readEntry("X-KDE-ServiceTypes", d->serviceType); 00124 d->pluginName = config.readEntry("X-KDE-PluginInfo-Name", d->pluginName); 00125 d->author = config.readEntry("X-KDE-PluginInfo-Author", d->author); 00126 d->email = config.readEntry("X-KDE-PluginInfo-Email", d->email); 00127 d->version = config.readEntry("X-KDE-PluginInfo-Version", d->version); 00128 d->website = config.readEntry("X-KDE-PluginInfo-Website", d->website); 00129 d->license = config.readEntry("X-KDE-PluginInfo-License", d->license); 00130 d->category = config.readEntry("X-KDE-PluginInfo-Category", d->category); 00131 d->api = config.readEntry("X-Plasma-API", d->api); 00132 d->app = config.readEntry("X-KDE-ParentApp", d->app); 00133 d->type = config.readEntry("Type", d->type); 00134 d->location = config.readEntry("X-Plasma-RemoteLocation", d->location); 00135 } 00136 00137 QString PackageMetadata::name() const 00138 { 00139 return d->name; 00140 } 00141 00142 QString PackageMetadata::description() const 00143 { 00144 return d->description; 00145 } 00146 00147 QString PackageMetadata::serviceType() const 00148 { 00149 return d->serviceType; 00150 } 00151 00152 QString PackageMetadata::author() const 00153 { 00154 return d->author; 00155 } 00156 00157 QString PackageMetadata::email() const 00158 { 00159 return d->email; 00160 } 00161 00162 QString PackageMetadata::icon() const 00163 { 00164 return d->icon; 00165 } 00166 00167 void PackageMetadata::setIcon(const QString &icon) 00168 { 00169 d->icon = icon; 00170 } 00171 00172 QString PackageMetadata::version() const 00173 { 00174 return d->version; 00175 } 00176 00177 QString PackageMetadata::website() const 00178 { 00179 return d->website; 00180 } 00181 00182 QString PackageMetadata::license() const 00183 { 00184 return d->license; 00185 } 00186 00187 QString PackageMetadata::application() const 00188 { 00189 return d->app; 00190 } 00191 00192 QString PackageMetadata::category() const 00193 { 00194 return d->category; 00195 } 00196 00197 void PackageMetadata::setKeywords(const QStringList &keywords) 00198 { 00199 d->keywords = keywords; 00200 } 00201 00202 QStringList PackageMetadata::keywords() const 00203 { 00204 return d->keywords; 00205 } 00206 00207 QString PackageMetadata::requiredVersion() const 00208 { 00209 return d->requiredVersion; 00210 } 00211 00212 KUrl PackageMetadata::remoteLocation() const 00213 { 00214 return d->location; 00215 } 00216 00217 QString PackageMetadata::type() const 00218 { 00219 return d->type; 00220 } 00221 00222 QString PackageMetadata::implementationApi() const 00223 { 00224 return d->api; 00225 } 00226 00227 void PackageMetadata::setImplementationApi(const QString &api) 00228 { 00229 d->api = api; 00230 } 00231 00232 QString PackageMetadata::pluginName() const 00233 { 00234 return d->pluginName; 00235 } 00236 00237 void PackageMetadata::setPluginName(const QString &pluginName) 00238 { 00239 d->pluginName = pluginName; 00240 } 00241 00242 void PackageMetadata::setName(const QString &name) 00243 { 00244 d->name = name; 00245 } 00246 00247 void PackageMetadata::setDescription(const QString &description) 00248 { 00249 d->description = description; 00250 } 00251 00252 void PackageMetadata::setServiceType(const QString &serviceType) 00253 { 00254 d->serviceType = serviceType; 00255 } 00256 00257 void PackageMetadata::setAuthor(const QString &author) 00258 { 00259 d->author = author; 00260 } 00261 00262 void PackageMetadata::setEmail(const QString &email) 00263 { 00264 d->email = email; 00265 } 00266 00267 void PackageMetadata::setVersion(const QString &version) 00268 { 00269 d->version = version; 00270 } 00271 00272 void PackageMetadata::setWebsite(const QString &website) 00273 { 00274 d->website = website; 00275 } 00276 00277 void PackageMetadata::setLicense(const QString &license) 00278 { 00279 d->license = license; 00280 } 00281 00282 void PackageMetadata::setApplication(const QString &application) 00283 { 00284 d->app = application; 00285 } 00286 00287 void PackageMetadata::setCategory(const QString &category) 00288 { 00289 d->category = category; 00290 } 00291 00292 void PackageMetadata::setRequiredVersion(const QString &requiredVersion) 00293 { 00294 d->requiredVersion = requiredVersion; 00295 } 00296 00297 void PackageMetadata::setRemoteLocation(const KUrl &location) 00298 { 00299 d->location = location; 00300 } 00301 00302 void PackageMetadata::setType(const QString &type) 00303 { 00304 d->type = type; 00305 } 00306 00307 } // namespace Plasma 00308
KDE 4.6 API Reference