some more win32'fication to fix non-ascii filename handling
[kdelibs.git] / kutils / kcmoduleinfo.cpp
blob195f3159909f2870609032a232fb453d6f861852
1 /*
2 Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
3 Copyright (c) 2000 Matthias Elter <elter@kde.org>
4 Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
5 Copyright (c) 2003,2006 Matthias Kretz <kretz@kde.org>
7 This file is part of the KDE project
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License version 2, as published by the Free Software Foundation.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
24 #include "kcmoduleinfo.h"
26 #include <QtCore/QVariant>
28 #include <kdesktopfile.h>
29 #include <kdebug.h>
30 #include <kglobal.h>
31 #include <kstandarddirs.h>
32 #include <klocale.h>
34 class KCModuleInfo::Private
36 public:
37 Private();
38 Private( KService::Ptr );
40 QStringList keywords;
41 QString name, icon, lib, handle, fileName, doc, comment;
42 bool allLoaded;
43 int weight;
45 KService::Ptr service;
47 /**
48 * Reads the service entries specific for KCModule from the desktop file.
49 * The usual desktop entries are read in the Private ctor.
51 void loadAll();
54 KCModuleInfo::Private::Private()
58 KCModuleInfo::Private::Private( KService::Ptr s )
59 : allLoaded( false )
60 , service( s )
62 if ( !service )
64 kDebug(712) << "Could not find the service.";
65 return;
68 // set the modules simple attributes
69 name = service->name();
70 comment = service->comment();
71 icon = service->icon();
72 fileName = service->entryPath();
73 lib = service->library();
74 keywords = service->keywords();
77 KCModuleInfo::KCModuleInfo()
79 d = new Private;
82 KCModuleInfo::KCModuleInfo(const QString& desktopFile)
84 d = new Private( KService::serviceByStorageId(desktopFile) );
87 KCModuleInfo::KCModuleInfo( KService::Ptr moduleInfo )
89 d = new Private( moduleInfo );
92 KCModuleInfo::KCModuleInfo( const KCModuleInfo &rhs )
94 d = new Private;
95 ( *this ) = rhs;
98 KCModuleInfo &KCModuleInfo::operator=( const KCModuleInfo &rhs )
100 *d = *(rhs.d);
101 return *this;
104 bool KCModuleInfo::operator==( const KCModuleInfo & rhs ) const
106 return ( ( d->name == rhs.d->name ) && ( d->lib == rhs.d->lib ) && ( d->fileName == rhs.d->fileName ) );
109 bool KCModuleInfo::operator!=( const KCModuleInfo & rhs ) const
111 return ! operator==( rhs );
114 KCModuleInfo::~KCModuleInfo()
116 delete d;
119 void KCModuleInfo::Private::loadAll()
121 allLoaded = true;
123 if( !service ) /* We have a bogus service. All get functions will return empty/zero values */
124 return;
126 // get the documentation path
127 doc = service->property( "X-DocPath", QVariant::String ).toString();
128 if (doc.isEmpty())
129 doc = service->property( "DocPath", QVariant::String ).toString();
131 // read weight
132 QVariant tmp = service->property( "X-KDE-Weight", QVariant::Int );
133 weight = tmp.isValid() ? tmp.toInt() : 100;
135 // factory handle
136 tmp = service->property("X-KDE-FactoryName", QVariant::String);
137 handle = tmp.isValid() ? tmp.toString() : lib;
141 QString KCModuleInfo::fileName() const
143 return d->fileName;
146 QStringList KCModuleInfo::keywords() const
148 return d->keywords;
151 QString KCModuleInfo::moduleName() const
153 return d->name;
156 KService::Ptr KCModuleInfo::service() const
158 return d->service;
161 QString KCModuleInfo::comment() const
163 return d->comment;
166 QString KCModuleInfo::icon() const
168 return d->icon;
171 QString KCModuleInfo::library() const
173 return d->lib;
176 QString KCModuleInfo::docPath() const
178 if (!d->allLoaded)
179 d->loadAll();
181 return d->doc;
184 QString KCModuleInfo::handle() const
186 if (!d->allLoaded)
187 d->loadAll();
189 return d->handle;
192 int KCModuleInfo::weight() const
194 if (!d->allLoaded)
195 d->loadAll();
197 return d->weight;
200 // vim: ts=2 sw=2 et