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> |
6 | |
7 | This file is part of the KDE project |
8 | |
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. |
12 | |
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. |
17 | |
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. |
22 | */ |
23 | |
24 | #include "kcmoduleinfo.h" |
25 | |
26 | #include <QtCore/QVariant> |
27 | |
28 | #include <kdesktopfile.h> |
29 | #include <kdebug.h> |
30 | #include <kglobal.h> |
31 | #include <kstandarddirs.h> |
32 | #include <klocale.h> |
33 | |
34 | class KCModuleInfo::Private |
35 | { |
36 | public: |
37 | Private(); |
38 | Private( KService::Ptr ); |
39 | |
40 | QStringList keywords; |
41 | QString name, icon, lib, handle, fileName, doc, ; |
42 | bool allLoaded; |
43 | int weight; |
44 | |
45 | KService::Ptr service; |
46 | |
47 | /** |
48 | * Reads the service entries specific for KCModule from the desktop file. |
49 | * The usual desktop entries are read in the Private ctor. |
50 | */ |
51 | void loadAll(); |
52 | }; |
53 | |
54 | KCModuleInfo::Private::Private() |
55 | { |
56 | } |
57 | |
58 | KCModuleInfo::Private::Private( KService::Ptr s ) |
59 | : allLoaded( false ) |
60 | , service( s ) |
61 | { |
62 | if ( !service ) |
63 | { |
64 | kDebug(712) << "Could not find the service." ; |
65 | return; |
66 | } |
67 | |
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(); |
75 | } |
76 | |
77 | KCModuleInfo::KCModuleInfo() |
78 | { |
79 | d = new Private; |
80 | } |
81 | |
82 | KCModuleInfo::KCModuleInfo(const QString& desktopFile) |
83 | { |
84 | d = new Private( KService::serviceByStorageId(desktopFile) ); |
85 | } |
86 | |
87 | KCModuleInfo::KCModuleInfo( KService::Ptr moduleInfo ) |
88 | { |
89 | d = new Private( moduleInfo ); |
90 | } |
91 | |
92 | KCModuleInfo::KCModuleInfo( const KCModuleInfo &rhs ) |
93 | { |
94 | d = new Private; |
95 | ( *this ) = rhs; |
96 | } |
97 | |
98 | KCModuleInfo &KCModuleInfo::operator=( const KCModuleInfo &rhs ) |
99 | { |
100 | *d = *(rhs.d); |
101 | return *this; |
102 | } |
103 | |
104 | bool KCModuleInfo::operator==( const KCModuleInfo & rhs ) const |
105 | { |
106 | return ( ( d->name == rhs.d->name ) && ( d->lib == rhs.d->lib ) && ( d->fileName == rhs.d->fileName ) ); |
107 | } |
108 | |
109 | bool KCModuleInfo::operator!=( const KCModuleInfo & rhs ) const |
110 | { |
111 | return ! operator==( rhs ); |
112 | } |
113 | |
114 | KCModuleInfo::~KCModuleInfo() |
115 | { |
116 | delete d; |
117 | } |
118 | |
119 | void KCModuleInfo::Private::loadAll() |
120 | { |
121 | allLoaded = true; |
122 | |
123 | if( !service ) /* We have a bogus service. All get functions will return empty/zero values */ |
124 | return; |
125 | |
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(); |
130 | |
131 | // read weight |
132 | QVariant tmp = service->property( "X-KDE-Weight" , QVariant::Int ); |
133 | weight = tmp.isValid() ? tmp.toInt() : 100; |
134 | |
135 | // factory handle |
136 | tmp = service->property("X-KDE-FactoryName" , QVariant::String); |
137 | handle = tmp.isValid() ? tmp.toString() : lib; |
138 | |
139 | } |
140 | |
141 | QString KCModuleInfo::fileName() const |
142 | { |
143 | return d->fileName; |
144 | } |
145 | |
146 | QStringList KCModuleInfo::keywords() const |
147 | { |
148 | return d->keywords; |
149 | } |
150 | |
151 | QString KCModuleInfo::moduleName() const |
152 | { |
153 | return d->name; |
154 | } |
155 | |
156 | KService::Ptr KCModuleInfo::service() const |
157 | { |
158 | return d->service; |
159 | } |
160 | |
161 | QString KCModuleInfo::() const |
162 | { |
163 | return d->comment; |
164 | } |
165 | |
166 | QString KCModuleInfo::icon() const |
167 | { |
168 | return d->icon; |
169 | } |
170 | |
171 | QString KCModuleInfo::library() const |
172 | { |
173 | return d->lib; |
174 | } |
175 | |
176 | QString KCModuleInfo::docPath() const |
177 | { |
178 | if (!d->allLoaded) |
179 | d->loadAll(); |
180 | |
181 | return d->doc; |
182 | } |
183 | |
184 | QString KCModuleInfo::handle() const |
185 | { |
186 | if (!d->allLoaded) |
187 | d->loadAll(); |
188 | |
189 | return d->handle; |
190 | } |
191 | |
192 | int KCModuleInfo::weight() const |
193 | { |
194 | if (!d->allLoaded) |
195 | d->loadAll(); |
196 | |
197 | return d->weight; |
198 | } |
199 | |
200 | // vim: ts=2 sw=2 et |
201 | |