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

tdeutils

  • tdeutils
tdecmoduleinfo.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 <tdeglobal.h>
29 #include <kstandarddirs.h>
30 #include <tdelocale.h>
31 
32 #include "tdecmoduleinfo.h"
33 
34 class TDECModuleInfo::TDECModuleInfoPrivate
35 {
36  public:
37  TDECModuleInfoPrivate() :
38  testModule( false )
39  {}
40  ~TDECModuleInfoPrivate()
41  { }
42 
43  TQString factoryName;
44  bool testModule;
45 
46 };
47 
48 TDECModuleInfo::TDECModuleInfo()
49 {
50  _allLoaded = false;
51  d = new TDECModuleInfoPrivate;
52 }
53 
54 TDECModuleInfo::TDECModuleInfo(const TQString& desktopFile)
55 {
56  KService::Ptr service = KService::serviceByStorageId(desktopFile);
57  if(!service) setName(desktopFile);
58  init(service);
59 }
60 
61 TDECModuleInfo::TDECModuleInfo( KService::Ptr moduleInfo )
62 {
63  init(moduleInfo);
64 }
65 
66 TDECModuleInfo::TDECModuleInfo( const TDECModuleInfo &rhs )
67 {
68  d = new TDECModuleInfoPrivate;
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 TDECModuleInfo &TDECModuleInfo::operator=( const TDECModuleInfo &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 TDECModuleInfo::factoryName() const
96 {
97  if( d->factoryName.isEmpty() )
98  {
99  d->factoryName = _service->property("X-TDE-FactoryName", TQVariant::String).toString();
100  if ( d->factoryName.isEmpty() )
101  d->factoryName = library();
102  }
103 
104  return d->factoryName;
105 }
106 
107 bool TDECModuleInfo::operator==( const TDECModuleInfo & rhs ) const
108 {
109  return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) );
110 }
111 
112 bool TDECModuleInfo::operator!=( const TDECModuleInfo & rhs ) const
113 {
114  return ! operator==( rhs );
115 }
116 
117 TDECModuleInfo::~TDECModuleInfo()
118 {
119  delete d;
120 }
121 
122 void TDECModuleInfo::init(KService::Ptr s)
123 {
124  _allLoaded = false;
125  d = new TDECModuleInfoPrivate;
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 TDECModuleInfo::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-TDE-FactoryName", TQVariant::String).toString());
159 
160  TQVariant tmp;
161 
162  // read weight
163  tmp = _service->property( "X-TDE-Weight", TQVariant::Int );
164  setWeight( tmp.isValid() ? tmp.toInt() : 100 );
165 
166  // does the module need super user privileges?
167  tmp = _service->property( "X-TDE-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-TDE-IsHiddenByDefault", TQVariant::Bool );
173  setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false );
174 
175  // get the documentation path
176  setDocPath( _service->property( "X-DocPath", TQVariant::String ).toString() );
177 
178  tmp = _service->property( "X-TDE-Test-Module", TQVariant::Bool );
179  setNeedsTest( tmp.isValid() ? tmp.asBool() : false );
180 }
181 
182 TQString
183 TDECModuleInfo::docPath() const
184 {
185  if (!_allLoaded)
186  const_cast<TDECModuleInfo*>(this)->loadAll();
187 
188  return _doc;
189 }
190 
191 TQString
192 TDECModuleInfo::handle() const
193 {
194  if (!_allLoaded)
195  const_cast<TDECModuleInfo*>(this)->loadAll();
196 
197  if (_handle.isEmpty())
198  return _lib;
199 
200  return _handle;
201 }
202 
203 int
204 TDECModuleInfo::weight() const
205 {
206  if (!_allLoaded)
207  const_cast<TDECModuleInfo*>(this)->loadAll();
208 
209  return _weight;
210 }
211 
212 bool
213 TDECModuleInfo::needsRootPrivileges() const
214 {
215  if (!_allLoaded)
216  const_cast<TDECModuleInfo*>(this)->loadAll();
217 
218  return _needsRootPrivileges;
219 }
220 
221 bool
222 TDECModuleInfo::isHiddenByDefault() const
223 {
224  if (!_allLoaded)
225  const_cast<TDECModuleInfo*>(this)->loadAll();
226 
227  return _isHiddenByDefault;
228 }
229 
230 bool TDECModuleInfo::needsTest() const
231 {
232  return d->testModule;
233 }
234 
235 void TDECModuleInfo::setNeedsTest( bool val )
236 {
237  d->testModule = val;
238 }
TDECModuleInfo::needsRootPrivileges
bool needsRootPrivileges() const
Definition: tdecmoduleinfo.cpp:213
TDECModuleInfo::setNeedsRootPrivileges
void setNeedsRootPrivileges(bool needsRootPrivileges)
Toggles whether the represented module needs root privileges.
Definition: tdecmoduleinfo.h:249
TDECModuleInfo
A class that provides information about a TDECModule.
Definition: tdecmoduleinfo.h:49
TDECModuleInfo::docPath
TQString docPath() const
Definition: tdecmoduleinfo.cpp:183
TDECModuleInfo::setComment
void setComment(const TQString &comment)
Sets the object's name.
Definition: tdecmoduleinfo.h:208
TDECModuleInfo::operator==
bool operator==(const TDECModuleInfo &rhs) const
Equal operator.
Definition: tdecmoduleinfo.cpp:107
TDECModuleInfo::setName
void setName(const TQString &name)
Sets the object's name.
Definition: tdecmoduleinfo.h:202
TDECModuleInfo::setNeedsTest
void setNeedsTest(bool val)
Sets if the module should be tested for loading.
Definition: tdecmoduleinfo.cpp:235
kdDebug
kdbgstream kdDebug(int area=0)
TDECModuleInfo::TDECModuleInfo
TDECModuleInfo()
Same as above but creates an empty TDECModuleInfo.
Definition: tdecmoduleinfo.cpp:48
TDECModuleInfo::factoryName
TQString factoryName() const
Returns the module's factory name, if it's set.
Definition: tdecmoduleinfo.cpp:95
TDECModuleInfo::setIsHiddenByDefault
void setIsHiddenByDefault(bool isHiddenByDefault)
Definition: tdecmoduleinfo.h:255
tdelocale.h
TDECModuleInfo::library
TQString library() const
Definition: tdecmoduleinfo.h:157
TDECModuleInfo::weight
int weight() const
Definition: tdecmoduleinfo.cpp:204
TDECModuleInfo::setLibrary
void setLibrary(const TQString &lib)
Set the object's library.
Definition: tdecmoduleinfo.h:220
TDECModuleInfo::~TDECModuleInfo
~TDECModuleInfo()
Default destructor.
Definition: tdecmoduleinfo.cpp:117
TDECModuleInfo::isHiddenByDefault
bool isHiddenByDefault() const KDE_DEPRECATED
Definition: tdecmoduleinfo.cpp:222
TDECModuleInfo::service
KService::Ptr service() const
Definition: tdecmoduleinfo.h:137
TDECModuleInfo::setWeight
void setWeight(int weight)
Sets the object's weight property which determines in what order modules will be displayed.
Definition: tdecmoduleinfo.h:234
TDECModuleInfo::setIcon
void setIcon(const TQString &icon)
Sets the object's icon.
Definition: tdecmoduleinfo.h:214
TDECModuleInfo::handle
TQString handle() const
Definition: tdecmoduleinfo.cpp:192
TDECModuleInfo::setKeywords
void setKeywords(const TQStringList &keyword)
Sets the object's keywords.
Definition: tdecmoduleinfo.h:196
TDECModuleInfo::operator!=
bool operator!=(const TDECModuleInfo &rhs) const
Definition: tdecmoduleinfo.cpp:112
TDECModuleInfo::loadAll
void loadAll()
Reads the service entries specific for TDECModule from the desktop file.
Definition: tdecmoduleinfo.cpp:150
TDECModuleInfo::needsTest
bool needsTest() const
Definition: tdecmoduleinfo.cpp:230
TDECModuleInfo::setHandle
void setHandle(const TQString &handle)
Sets the factory name.
Definition: tdecmoduleinfo.h:226
endl
kndbgstream & endl(kndbgstream &s)
TDECModuleInfo::setDocPath
void setDocPath(const TQString &p)
Sets the object's documentation path.
Definition: tdecmoduleinfo.h:262
TDECModuleInfo::operator=
TDECModuleInfo & operator=(const TDECModuleInfo &rhs)
Assignment operator.
Definition: tdecmoduleinfo.cpp:75

tdeutils

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

tdeutils

Skip menu "tdeutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeutils by doxygen 1.8.8
This website is maintained by Timothy Pearson.