• 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 <tdestandarddirs.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
56static void kglobal_init();
57
58TDEStandardDirs *TDEGlobal::dirs()
59{
60 MYASSERT(_instance);
61
62 return _instance->dirs();
63}
64
65TDEConfig *TDEGlobal::config()
66{
67 MYASSERT(_instance);
68
69 return _instance->config();
70}
71
72TDESharedConfig *TDEGlobal::sharedConfig()
73{
74 MYASSERT(_instance);
75
76 return _instance->sharedConfig();
77}
78
79TDEIconLoader *TDEGlobal::iconLoader()
80{
81 MYASSERT(_instance);
82
83 return _instance->iconLoader();
84}
85
86#ifdef __TDE_HAVE_TDEHWLIB
87TDEHardwareDevices *TDEGlobal::hardwareDevices()
88{
89 MYASSERT(_instance);
90
91 return _instance->hardwareDevices();
92}
93
94TDEGlobalNetworkManager *TDEGlobal::networkManager()
95{
96 MYASSERT(_instance);
97
98 return _instance->networkManager();
99}
100#endif
101
102TDEInstance *TDEGlobal::instance()
103{
104 MYASSERT(_instance);
105 return _instance;
106}
107
108TDELocale *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
124KCharsets *TDEGlobal::charsets()
125{
126 if( _charsets == 0 ) {
127 _charsets =new KCharsets();
128 kglobal_init();
129 }
130
131 return _charsets;
132}
133
134void TDEGlobal::setActiveInstance(TDEInstance *i)
135{
136 _activeInstance = i;
137 if (i && _locale)
138 _locale->setActiveCatalogue(TQString::fromUtf8(i->instanceName()));
139}
140
147const TQString &
148TDEGlobal::staticQString(const char *str)
149{
150 return staticQString(TQString::fromLatin1(str));
151}
152
153class KStringDict : public TQDict<TQString>
154{
155public:
156 KStringDict() : TQDict<TQString>(139) { }
157};
158
165const TQString &
166TDEGlobal::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
182class KStaticDeleterList: public TQPtrList<KStaticDeleterBase>
183{
184public:
185 KStaticDeleterList() { }
186};
187
188void
189TDEGlobal::registerStaticDeleter(KStaticDeleterBase *obj)
190{
191 if (!_staticDeleters)
192 kglobal_init();
193 if (_staticDeleters->find(obj) == -1)
194 _staticDeleters->append(obj);
195}
196
197void
198TDEGlobal::unregisterStaticDeleter(KStaticDeleterBase *obj)
199{
200 if (_staticDeleters)
201 _staticDeleters->removeRef(obj);
202}
203
204void
205TDEGlobal::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
221KStringDict *TDEGlobal::_stringDict = 0;
222TDEInstance *TDEGlobal::_instance = 0;
223TDEInstance *TDEGlobal::_activeInstance = 0;
224TDELocale *TDEGlobal::_locale = 0;
225KCharsets *TDEGlobal::_charsets = 0;
226KStaticDeleterList *TDEGlobal::_staticDeleters = 0;
227
228#ifdef WIN32
229#include <windows.h>
230static void kglobal_freeAll();
231BOOL 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
240static 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
253static void kglobal_init()
254{
255 if (TDEGlobal::_staticDeleters)
256 return;
257
258 TDEGlobal::_staticDeleters = new KStaticDeleterList;
259}
260
261int 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
285char* kasciitolower( char *s )
286{
287 if ( !s )
288 return 0;
289 for ( unsigned char *p = (unsigned char *) s; *p; ++p )
290 *p = ( *p >= 'A' && *p <= 'Z' ) ? (*p - 'A' + 'a') : *p;
291 return s;
292}
293
294char* kasciitoupper( char *s )
295{
296 if ( !s )
297 return 0;
298 for ( unsigned char *p = (unsigned char *) s; *p; ++p )
299 *p = ( *p >= 'a' && *p <= 'z' ) ? (*p - 'a' + 'A') : *p;
300 return s;
301}
KCharsets
Charset font and encoder/decoder handling.
Definition: kcharsets.h:44
KStaticDeleterBase
Static deleters are used to manage static resources.
Definition: kstaticdeleter.h:39
TDEConfig
Access KDE Configuration entries.
Definition: tdeconfig.h:44
TDEGlobal::iconLoader
static TDEIconLoader * iconLoader()
Returns an iconloader object.
Definition: tdeglobal.cpp:79
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
TDEGlobal::dirs
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
Definition: tdeglobal.cpp:58
TDEGlobal::sharedConfig
static TDESharedConfig * sharedConfig()
Returns the general config object.
Definition: tdeglobal.cpp:72
TDEGlobal::charsets
static KCharsets * charsets()
The global charset manager.
Definition: tdeglobal.cpp:124
TDEGlobal::instance
static TDEInstance * instance()
Returns the global instance.
Definition: tdeglobal.cpp:102
TDEGlobal::registerStaticDeleter
static void registerStaticDeleter(KStaticDeleterBase *d)
Registers a static deleter.
Definition: tdeglobal.cpp:189
TDEGlobal::locale
static TDELocale * locale()
Returns the global locale object.
Definition: tdeglobal.cpp:108
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
TDEGlobal::deleteStaticDeleters
static void deleteStaticDeleters()
Calls KStaticDeleterBase::destructObject() on all registered static deleters and unregisters them all...
Definition: tdeglobal.cpp:205
TDEGlobal::staticQString
static const TQString & staticQString(const char *str)
Creates a static TQString.
Definition: tdeglobal.cpp:148
TDEIconLoader
Iconloader for KDE.
Definition: kiconloader.h:78
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:48
TDEInstance::dirs
TDEStandardDirs * dirs() const
Returns the application standard dirs object.
Definition: kinstance.cpp:189
TDEInstance::instanceName
TQCString instanceName() const
Returns the name of the instance.
Definition: kinstance.cpp:342
TDEInstance::config
TDEConfig * config() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:212
TDEInstance::aboutData
const TDEAboutData * aboutData() const
Returns the about data of this instance Warning, can be 0L.
Definition: kinstance.cpp:336
TDEInstance::iconLoader
TDEIconLoader * iconLoader() const
Returns an iconloader object.
Definition: kinstance.cpp:276
TDEInstance::sharedConfig
TDESharedConfig * sharedConfig() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:261
TDELocale
TDELocale provides support for country specific stuff like the national language.
Definition: tdelocale.h:124
TDELocale::setActiveCatalogue
void setActiveCatalogue(const TQString &catalog)
Sets the active catalog for translation lookup.
Definition: tdelocale.cpp:702
TDESharedConfig
TDEConfig variant using shared memory.
Definition: tdeconfig.h:274
TDEStandardDirs
Site-independent access to standard TDE directories.
Definition: tdestandarddirs.h:126
tdelocale.h

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.