KUtils
kcmoduleinfo.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "kcmoduleinfo.h"
00025
00026 #include <QtCore/QVariant>
00027
00028 #include <kdesktopfile.h>
00029 #include <kdebug.h>
00030 #include <kglobal.h>
00031 #include <kstandarddirs.h>
00032 #include <klocale.h>
00033
00034 class KCModuleInfo::Private
00035 {
00036 public:
00037 Private();
00038 Private( KService::Ptr );
00039
00040 QStringList keywords;
00041 QString name, icon, lib, handle, fileName, doc, comment;
00042 bool allLoaded;
00043 int weight;
00044
00045 KService::Ptr service;
00046
00051 void loadAll();
00052 };
00053
00054 KCModuleInfo::Private::Private()
00055 {
00056 }
00057
00058 KCModuleInfo::Private::Private( KService::Ptr s )
00059 : allLoaded( false )
00060 , service( s )
00061 {
00062 if ( !service )
00063 {
00064 kDebug(712) << "Could not find the service.";
00065 return;
00066 }
00067
00068
00069 name = service->name();
00070 comment = service->comment();
00071 icon = service->icon();
00072 fileName = service->entryPath();
00073 lib = service->library();
00074 keywords = service->keywords();
00075 }
00076
00077 KCModuleInfo::KCModuleInfo()
00078 {
00079 d = new Private;
00080 }
00081
00082 KCModuleInfo::KCModuleInfo(const QString& desktopFile)
00083 {
00084 d = new Private( KService::serviceByStorageId(desktopFile) );
00085 }
00086
00087 KCModuleInfo::KCModuleInfo( KService::Ptr moduleInfo )
00088 {
00089 d = new Private( moduleInfo );
00090 }
00091
00092 KCModuleInfo::KCModuleInfo( const KCModuleInfo &rhs )
00093 {
00094 d = new Private;
00095 ( *this ) = rhs;
00096 }
00097
00098 KCModuleInfo &KCModuleInfo::operator=( const KCModuleInfo &rhs )
00099 {
00100 *d = *(rhs.d);
00101 return *this;
00102 }
00103
00104 bool KCModuleInfo::operator==( const KCModuleInfo & rhs ) const
00105 {
00106 return ( ( d->name == rhs.d->name ) && ( d->lib == rhs.d->lib ) && ( d->fileName == rhs.d->fileName ) );
00107 }
00108
00109 bool KCModuleInfo::operator!=( const KCModuleInfo & rhs ) const
00110 {
00111 return ! operator==( rhs );
00112 }
00113
00114 KCModuleInfo::~KCModuleInfo()
00115 {
00116 delete d;
00117 }
00118
00119 void KCModuleInfo::Private::loadAll()
00120 {
00121 allLoaded = true;
00122
00123 if( !service )
00124 return;
00125
00126
00127 doc = service->property( "X-DocPath", QVariant::String ).toString();
00128 if (doc.isEmpty())
00129 doc = service->property( "DocPath", QVariant::String ).toString();
00130
00131
00132 QVariant tmp = service->property( "X-KDE-Weight", QVariant::Int );
00133 weight = tmp.isValid() ? tmp.toInt() : 100;
00134
00135
00136 tmp = service->property("X-KDE-FactoryName", QVariant::String);
00137 handle = tmp.isValid() ? tmp.toString() : lib;
00138
00139 }
00140
00141 QString KCModuleInfo::fileName() const
00142 {
00143 return d->fileName;
00144 }
00145
00146 QStringList KCModuleInfo::keywords() const
00147 {
00148 return d->keywords;
00149 }
00150
00151 QString KCModuleInfo::moduleName() const
00152 {
00153 return d->name;
00154 }
00155
00156 KService::Ptr KCModuleInfo::service() const
00157 {
00158 return d->service;
00159 }
00160
00161 QString KCModuleInfo::comment() const
00162 {
00163 return d->comment;
00164 }
00165
00166 QString KCModuleInfo::icon() const
00167 {
00168 return d->icon;
00169 }
00170
00171 QString KCModuleInfo::library() const
00172 {
00173 return d->lib;
00174 }
00175
00176 QString KCModuleInfo::docPath() const
00177 {
00178 if (!d->allLoaded)
00179 d->loadAll();
00180
00181 return d->doc;
00182 }
00183
00184 QString KCModuleInfo::handle() const
00185 {
00186 if (!d->allLoaded)
00187 d->loadAll();
00188
00189 return d->handle;
00190 }
00191
00192 int KCModuleInfo::weight() const
00193 {
00194 if (!d->allLoaded)
00195 d->loadAll();
00196
00197 return d->weight;
00198 }
00199
00200