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

tdecore

  • tdecore
tdeglobal.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Sirtaj Singh Kanq <taj@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 /*
19 * tdeglobal.cpp -- Implementation of class TDEGlobal.
20 * Author: Sirtaj Singh Kang
21 * Version: $Id$
22 * Generated: Sat May 1 02:08:43 EST 1999
23 */
24 
25 #include <tqglobal.h>
26 #include <tqdict.h>
27 #include <tqptrlist.h>
28 #include "tdeglobal.h"
29 
30 #include <tdeapplication.h>
31 #include <tdeaboutdata.h>
32 #include <kdebug.h>
33 #include <tdeconfig.h>
34 #include <tdelocale.h>
35 #include <kcharsets.h>
36 #include <kiconloader.h>
37 #ifdef __TDE_HAVE_TDEHWLIB
38 #include <tdehardwaredevices.h>
39 #include <tdenetworkconnections.h>
40 #endif
41 #include <kstandarddirs.h>
42 #include <kinstance.h>
43 #include "kstaticdeleter.h"
44 
45 #include <tqfont.h>
46 
47 #ifndef NDEBUG
48 #define MYASSERT(x) if (!x) \
49  tqFatal("Fatal error: you need to have a TDEInstance object before\n" \
50  "you do anything that requires it! Examples of this are config\n" \
51  "objects, standard directories or translations.");
52 #else
53 #define MYASSERT(x) /* nope */
54 #endif
55 
56 static void kglobal_init();
57 
58 TDEStandardDirs *TDEGlobal::dirs()
59 {
60  MYASSERT(_instance);
61 
62  return _instance->dirs();
63 }
64 
65 TDEConfig *TDEGlobal::config()
66 {
67  MYASSERT(_instance);
68 
69  return _instance->config();
70 }
71 
72 TDESharedConfig *TDEGlobal::sharedConfig()
73 {
74  MYASSERT(_instance);
75 
76  return _instance->sharedConfig();
77 }
78 
79 TDEIconLoader *TDEGlobal::iconLoader()
80 {
81  MYASSERT(_instance);
82 
83  return _instance->iconLoader();
84 }
85 
86 #ifdef __TDE_HAVE_TDEHWLIB
87 TDEHardwareDevices *TDEGlobal::hardwareDevices()
88 {
89  MYASSERT(_instance);
90 
91  return _instance->hardwareDevices();
92 }
93 
94 TDEGlobalNetworkManager *TDEGlobal::networkManager()
95 {
96  MYASSERT(_instance);
97 
98  return _instance->networkManager();
99 }
100 #endif
101 
102 TDEInstance *TDEGlobal::instance()
103 {
104  MYASSERT(_instance);
105  return _instance;
106 }
107 
108 TDELocale *TDEGlobal::locale()
109 {
110  if( _locale == 0 ) {
111  if (!_instance)
112  return 0;
113  kglobal_init();
114 
115  // will set _locale if it works - otherwise 0 is returned
116  TDELocale::initInstance();
117  if( _instance->aboutData())
118  _instance->aboutData()->translateInternalProgramName();
119  }
120 
121  return _locale;
122 }
123 
124 KCharsets *TDEGlobal::charsets()
125 {
126  if( _charsets == 0 ) {
127  _charsets =new KCharsets();
128  kglobal_init();
129  }
130 
131  return _charsets;
132 }
133 
134 void TDEGlobal::setActiveInstance(TDEInstance *i)
135 {
136  _activeInstance = i;
137  if (i && _locale)
138  _locale->setActiveCatalogue(TQString::fromUtf8(i->instanceName()));
139 }
140 
147 const TQString &
148 TDEGlobal::staticQString(const char *str)
149 {
150  return staticQString(TQString::fromLatin1(str));
151 }
152 
153 class KStringDict : public TQDict<TQString>
154 {
155 public:
156  KStringDict() : TQDict<TQString>(139) { }
157 };
158 
165 const TQString &
166 TDEGlobal::staticQString(const TQString &str)
167 {
168  if (!_stringDict) {
169  _stringDict = new KStringDict;
170  _stringDict->setAutoDelete( true );
171  kglobal_init();
172  }
173  TQString *result = _stringDict->find(str);
174  if (!result)
175  {
176  result = new TQString(str);
177  _stringDict->insert(str, result);
178  }
179  return *result;
180 }
181 
182 class KStaticDeleterList: public TQPtrList<KStaticDeleterBase>
183 {
184 public:
185  KStaticDeleterList() { }
186 };
187 
188 void
189 TDEGlobal::registerStaticDeleter(KStaticDeleterBase *obj)
190 {
191  if (!_staticDeleters)
192  kglobal_init();
193  if (_staticDeleters->find(obj) == -1)
194  _staticDeleters->append(obj);
195 }
196 
197 void
198 TDEGlobal::unregisterStaticDeleter(KStaticDeleterBase *obj)
199 {
200  if (_staticDeleters)
201  _staticDeleters->removeRef(obj);
202 }
203 
204 void
205 TDEGlobal::deleteStaticDeleters()
206 {
207  if (!TDEGlobal::_staticDeleters)
208  return;
209 
210  for(;_staticDeleters->count();)
211  {
212  _staticDeleters->take(0)->destructObject();
213  }
214 
215  delete TDEGlobal::_staticDeleters;
216  TDEGlobal::_staticDeleters = 0;
217 }
218 
219 // The Variables
220 
221 KStringDict *TDEGlobal::_stringDict = 0;
222 TDEInstance *TDEGlobal::_instance = 0;
223 TDEInstance *TDEGlobal::_activeInstance = 0;
224 TDELocale *TDEGlobal::_locale = 0;
225 KCharsets *TDEGlobal::_charsets = 0;
226 KStaticDeleterList *TDEGlobal::_staticDeleters = 0;
227 
228 #ifdef WIN32
229 #include <windows.h>
230 static void kglobal_freeAll();
231 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID impLoad )
232 {
233  if (reason == DLL_PROCESS_DETACH)
234  kglobal_freeAll();
235  return TRUE;
236 }
237 #else
238 __attribute__((destructor))
239 #endif
240 static void kglobal_freeAll()
241 {
242  delete TDEGlobal::_locale;
243  TDEGlobal::_locale = 0;
244  delete TDEGlobal::_charsets;
245  TDEGlobal::_charsets = 0;
246  delete TDEGlobal::_stringDict;
247  TDEGlobal::_stringDict = 0;
248  TDEGlobal::deleteStaticDeleters();
249  // so that we don't hold a reference and see memory leaks :/
250  TDEGlobal::setActiveInstance(0);
251 }
252 
253 static void kglobal_init()
254 {
255  if (TDEGlobal::_staticDeleters)
256  return;
257 
258  TDEGlobal::_staticDeleters = new KStaticDeleterList;
259 }
260 
261 int kasciistricmp( const char *str1, const char *str2 )
262 {
263  const unsigned char *s1 = (const unsigned char *)str1;
264  const unsigned char *s2 = (const unsigned char *)str2;
265  int res;
266  unsigned char c1, c2;
267 
268  if ( !s1 || !s2 )
269  return s1 ? 1 : (s2 ? -1 : 0);
270  if ( !*s1 || !*s2 )
271  return *s1 ? 1 : (*s2 ? -1 : 0);
272  for (;*s1; ++s1, ++s2) {
273  c1 = *s1; c2 = *s2;
274  if (c1 >= 'A' && c1 <= 'Z')
275  c1 += 'a' - 'A';
276  if (c2 >= 'A' && c2 <= 'Z')
277  c2 += 'a' - 'A';
278 
279  if ((res = c1 - c2))
280  break;
281  }
282  return *s1 ? res : (*s2 ? -1 : 0);
283 }
284 
TDEConfig
Access KDE Configuration entries.
Definition: tdeconfig.h:43
KCharsets
Charset font and encoder/decoder handling.
Definition: kcharsets.h:43
TDEInstance::iconLoader
TDEIconLoader * iconLoader() const
Returns an iconloader object.
Definition: kinstance.cpp:274
TDEInstance::dirs
TDEStandardDirs * dirs() const
Returns the application standard dirs object.
Definition: kinstance.cpp:187
TDEGlobal::iconLoader
static TDEIconLoader * iconLoader()
Returns an iconloader object.
Definition: tdeglobal.cpp:79
TDEInstance::aboutData
const TDEAboutData * aboutData() const
Returns the about data of this instance Warning, can be 0L.
Definition: kinstance.cpp:314
TDEStandardDirs
Site-independent access to standard KDE directories.
Definition: kstandarddirs.h:125
TDEGlobal::dirs
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
Definition: tdeglobal.cpp:58
tdelocale.h
TDEGlobal::sharedConfig
static TDESharedConfig * sharedConfig()
Returns the general config object.
Definition: tdeglobal.cpp:72
TDEGlobal::instance
static TDEInstance * instance()
Returns the global instance.
Definition: tdeglobal.cpp:102
TDELocale::setActiveCatalogue
void setActiveCatalogue(const TQString &catalog)
Sets the active catalog for translation lookup.
Definition: tdelocale.cpp:702
TDEGlobal::charsets
static KCharsets * charsets()
The global charset manager.
Definition: tdeglobal.cpp:124
TDELocale
TDELocale provides support for country specific stuff like the national language. ...
Definition: tdelocale.h:123
TDEGlobal::registerStaticDeleter
static void registerStaticDeleter(KStaticDeleterBase *d)
Registers a static deleter.
Definition: tdeglobal.cpp:189
TDEInstance::instanceName
TQCString instanceName() const
Returns the name of the instance.
Definition: kinstance.cpp:320
TDEGlobal::staticQString
static const TQString & staticQString(const char *str)
Creates a static TQString.
Definition: tdeglobal.cpp:148
TDEIconLoader
Iconloader for KDE.
Definition: kiconloader.h:77
TDEGlobal::deleteStaticDeleters
static void deleteStaticDeleters()
Calls KStaticDeleterBase::destructObject() on all registered static deleters and unregisters them all...
Definition: tdeglobal.cpp:205
TDEInstance::config
TDEConfig * config() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:210
TDEGlobal::locale
static TDELocale * locale()
Returns the global locale object.
Definition: tdeglobal.cpp:108
TDESharedConfig
TDEConfig variant using shared memory.
Definition: tdeconfig.h:273
KStaticDeleterBase
Static deleters are used to manage static resources.
Definition: kstaticdeleter.h:39
TDEInstance::sharedConfig
TDESharedConfig * sharedConfig() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:259
TDEGlobal::config
static TDEConfig * config()
Returns the general config object.
Definition: tdeglobal.cpp:65
TDEGlobal::unregisterStaticDeleter
static void unregisterStaticDeleter(KStaticDeleterBase *d)
Unregisters a static deleter.
Definition: tdeglobal.cpp:198
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:47
TDEGlobal::setActiveInstance
static void setActiveInstance(TDEInstance *d)
The instance currently active (useful in a multi-instance application, such as a KParts application)...
Definition: tdeglobal.cpp:134

tdecore

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

tdecore

Skip menu "tdecore"
  • 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 tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.