• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kutils
 

kutils

  • kutils
kcmoduleinfo.cpp
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 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 <tqvariant.h>
25 
26 #include <kdesktopfile.h>
27 #include <kdebug.h>
28 #include <kglobal.h>
29 #include <kstandarddirs.h>
30 #include <klocale.h>
31 
32 #include "kcmoduleinfo.h"
33 
34 class KCModuleInfo::KCModuleInfoPrivate
35 {
36  public:
37  KCModuleInfoPrivate() :
38  testModule( false )
39  {}
40  ~KCModuleInfoPrivate()
41  { }
42 
43  TQString factoryName;
44  bool testModule;
45 
46 };
47 
48 KCModuleInfo::KCModuleInfo()
49 {
50  _allLoaded = false;
51  d = new KCModuleInfoPrivate;
52 }
53 
54 KCModuleInfo::KCModuleInfo(const TQString& desktopFile)
55 {
56  KService::Ptr service = KService::serviceByStorageId(desktopFile);
57  if(!service) setName(desktopFile);
58  init(service);
59 }
60 
61 KCModuleInfo::KCModuleInfo( KService::Ptr moduleInfo )
62 {
63  init(moduleInfo);
64 }
65 
66 KCModuleInfo::KCModuleInfo( const KCModuleInfo &rhs )
67 {
68  d = new KCModuleInfoPrivate;
69  ( *this ) = rhs;
70 }
71 
72 // this re-implementation exists to ensure that other code always calls
73 // our re-implementation, so in case we add data to the d pointer in the future
74 // we can be sure that we get called when we are copied.
75 KCModuleInfo &KCModuleInfo::operator=( const KCModuleInfo &rhs )
76 {
77  _keywords = rhs._keywords;
78  _name = rhs._name;
79  _icon = rhs._icon;
80  _lib = rhs._lib;
81  _handle = rhs._handle;
82  _fileName = rhs._fileName;
83  _doc = rhs._doc;
84  _comment = rhs._comment;
85  _needsRootPrivileges = rhs._needsRootPrivileges;
86  _isHiddenByDefault = rhs._isHiddenByDefault;
87  _allLoaded = rhs._allLoaded;
88  _service = rhs._service;
89 
90  *d = *(rhs.d);
91 
92  return *this;
93 }
94 
95 TQString KCModuleInfo::factoryName() const
96 {
97  if( d->factoryName.isEmpty() )
98  {
99  d->factoryName = _service->property("X-KDE-FactoryName", TQVariant::String).toString();
100  if ( d->factoryName.isEmpty() )
101  d->factoryName = library();
102  }
103 
104  return d->factoryName;
105 }
106 
107 bool KCModuleInfo::operator==( const KCModuleInfo & rhs ) const
108 {
109  return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) );
110 }
111 
112 bool KCModuleInfo::operator!=( const KCModuleInfo & rhs ) const
113 {
114  return ! operator==( rhs );
115 }
116 
117 KCModuleInfo::~KCModuleInfo()
118 {
119  delete d;
120 }
121 
122 void KCModuleInfo::init(KService::Ptr s)
123 {
124  _allLoaded = false;
125  d = new KCModuleInfoPrivate;
126 
127  if ( s )
128  _service = s;
129  else
130  {
131  kdDebug(712) << "Could not find the service." << endl;
132  return;
133  }
134 
135  // set the modules simple attributes
136  setName(_service->name());
137  setComment(_service->comment());
138  setIcon(_service->icon());
139 
140  _fileName = ( _service->desktopEntryPath() );
141 
142  // library and factory
143  setLibrary(_service->library());
144 
145  // get the keyword list
146  setKeywords(_service->keywords());
147 }
148 
149 void
150 KCModuleInfo::loadAll()
151 {
152  if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */
153  return;
154 
155  _allLoaded = true;
156 
157  // library and factory
158  setHandle(_service->property("X-KDE-FactoryName", TQVariant::String).toString());
159 
160  TQVariant tmp;
161 
162  // read weight
163  tmp = _service->property( "X-KDE-Weight", TQVariant::Int );
164  setWeight( tmp.isValid() ? tmp.toInt() : 100 );
165 
166  // does the module need super user privileges?
167  tmp = _service->property( "X-KDE-RootOnly", TQVariant::Bool );
168  setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false );
169 
170  // does the module need to be shown to root only?
171  // Deprecated ! KDE 4
172  tmp = _service->property( "X-KDE-IsHiddenByDefault", TQVariant::Bool );
173  setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false );
174 
175  // get the documentation path
176  setDocPath( _service->property( "DocPath", TQVariant::String ).toString() );
177 
178  tmp = _service->property( "X-KDE-Test-Module", TQVariant::Bool );
179  setNeedsTest( tmp.isValid() ? tmp.asBool() : false );
180 }
181 
182 TQString
183 KCModuleInfo::docPath() const
184 {
185  if (!_allLoaded)
186  const_cast<KCModuleInfo*>(this)->loadAll();
187 
188  return _doc;
189 }
190 
191 TQString
192 KCModuleInfo::handle() const
193 {
194  if (!_allLoaded)
195  const_cast<KCModuleInfo*>(this)->loadAll();
196 
197  if (_handle.isEmpty())
198  return _lib;
199 
200  return _handle;
201 }
202 
203 int
204 KCModuleInfo::weight() const
205 {
206  if (!_allLoaded)
207  const_cast<KCModuleInfo*>(this)->loadAll();
208 
209  return _weight;
210 }
211 
212 bool
213 KCModuleInfo::needsRootPrivileges() const
214 {
215  if (!_allLoaded)
216  const_cast<KCModuleInfo*>(this)->loadAll();
217 
218  return _needsRootPrivileges;
219 }
220 
221 bool
222 KCModuleInfo::isHiddenByDefault() const
223 {
224  if (!_allLoaded)
225  const_cast<KCModuleInfo*>(this)->loadAll();
226 
227  return _isHiddenByDefault;
228 }
229 
230 bool KCModuleInfo::needsTest() const
231 {
232  return d->testModule;
233 }
234 
235 void KCModuleInfo::setNeedsTest( bool val )
236 {
237  d->testModule = val;
238 }
239 
240 
241 
242 // vim: ts=2 sw=2 et
KCModuleInfo::setDocPath
void setDocPath(const TQString &p)
Sets the object&#39;s documentation path.
Definition: kcmoduleinfo.h:262
KCModuleInfo::setHandle
void setHandle(const TQString &handle)
Sets the factory name.
Definition: kcmoduleinfo.h:226
KCModuleInfo::service
KService::Ptr service() const
Definition: kcmoduleinfo.h:137
KCModuleInfo::loadAll
void loadAll()
Reads the service entries specific for KCModule from the desktop file.
Definition: kcmoduleinfo.cpp:150
KCModuleInfo::docPath
TQString docPath() const
Definition: kcmoduleinfo.cpp:183
KCModuleInfo::setLibrary
void setLibrary(const TQString &lib)
Set the object&#39;s library.
Definition: kcmoduleinfo.h:220
KCModuleInfo::~KCModuleInfo
~KCModuleInfo()
Default destructor.
Definition: kcmoduleinfo.cpp:117
KCModuleInfo::factoryName
TQString factoryName() const
Returns the module&#39;s factory name, if it&#39;s set.
Definition: kcmoduleinfo.cpp:95
KCModuleInfo::handle
TQString handle() const
Definition: kcmoduleinfo.cpp:192
kdDebug
kdbgstream kdDebug(int area=0)
KCModuleInfo::setName
void setName(const TQString &name)
Sets the object&#39;s name.
Definition: kcmoduleinfo.h:202
klocale.h
KCModuleInfo::needsRootPrivileges
bool needsRootPrivileges() const
Definition: kcmoduleinfo.cpp:213
KCModuleInfo::isHiddenByDefault
bool isHiddenByDefault() const KDE_DEPRECATED
Definition: kcmoduleinfo.cpp:222
KCModuleInfo::setIsHiddenByDefault
void setIsHiddenByDefault(bool isHiddenByDefault)
Definition: kcmoduleinfo.h:255
KCModuleInfo::library
TQString library() const
Definition: kcmoduleinfo.h:157
KCModuleInfo::setNeedsTest
void setNeedsTest(bool val)
Sets if the module should be tested for loading.
Definition: kcmoduleinfo.cpp:235
KCModuleInfo::weight
int weight() const
Definition: kcmoduleinfo.cpp:204
KCModuleInfo::operator!=
bool operator!=(const KCModuleInfo &rhs) const
Definition: kcmoduleinfo.cpp:112
KCModuleInfo::operator==
bool operator==(const KCModuleInfo &rhs) const
Equal operator.
Definition: kcmoduleinfo.cpp:107
KCModuleInfo::setWeight
void setWeight(int weight)
Sets the object&#39;s weight property which determines in what order modules will be displayed.
Definition: kcmoduleinfo.h:234
KCModuleInfo::setNeedsRootPrivileges
void setNeedsRootPrivileges(bool needsRootPrivileges)
Toggles whether the represented module needs root privileges.
Definition: kcmoduleinfo.h:249
KCModuleInfo::needsTest
bool needsTest() const
Definition: kcmoduleinfo.cpp:230
KCModuleInfo
A class that provides information about a KCModule.
Definition: kcmoduleinfo.h:49
KCModuleInfo::setIcon
void setIcon(const TQString &icon)
Sets the object&#39;s icon.
Definition: kcmoduleinfo.h:214
KCModuleInfo::KCModuleInfo
KCModuleInfo()
Same as above but creates an empty KCModuleInfo.
Definition: kcmoduleinfo.cpp:48
KCModuleInfo::operator=
KCModuleInfo & operator=(const KCModuleInfo &rhs)
Assignment operator.
Definition: kcmoduleinfo.cpp:75
KCModuleInfo::setComment
void setComment(const TQString &comment)
Sets the object&#39;s name.
Definition: kcmoduleinfo.h:208
endl
kndbgstream & endl(kndbgstream &s)
KCModuleInfo::setKeywords
void setKeywords(const TQStringList &keyword)
Sets the object&#39;s keywords.
Definition: kcmoduleinfo.h:196

kutils

Skip menu "kutils"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kutils

Skip menu "kutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kutils by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |