• 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 #include <tdehardwaredevices.h>
38 #include <tdenetworkconnections.h>
39 #include <kstandarddirs.h>
40 #include <kinstance.h>
41 #include "kstaticdeleter.h"
42 
43 #include <tqfont.h>
44 
45 #ifndef NDEBUG
46 #define MYASSERT(x) if (!x) \
47  tqFatal("Fatal error: you need to have a TDEInstance object before\n" \
48  "you do anything that requires it! Examples of this are config\n" \
49  "objects, standard directories or translations.");
50 #else
51 #define MYASSERT(x) /* nope */
52 #endif
53 
54 static void kglobal_init();
55 
56 TDEStandardDirs *TDEGlobal::dirs()
57 {
58  MYASSERT(_instance);
59 
60  return _instance->dirs();
61 }
62 
63 TDEConfig *TDEGlobal::config()
64 {
65  MYASSERT(_instance);
66 
67  return _instance->config();
68 }
69 
70 TDESharedConfig *TDEGlobal::sharedConfig()
71 {
72  MYASSERT(_instance);
73 
74  return _instance->sharedConfig();
75 }
76 
77 TDEIconLoader *TDEGlobal::iconLoader()
78 {
79  MYASSERT(_instance);
80 
81  return _instance->iconLoader();
82 }
83 
84 TDEHardwareDevices *TDEGlobal::hardwareDevices()
85 {
86  MYASSERT(_instance);
87 
88  return _instance->hardwareDevices();
89 }
90 
91 TDEGlobalNetworkManager *TDEGlobal::networkManager()
92 {
93  MYASSERT(_instance);
94 
95  return _instance->networkManager();
96 }
97 
98 TDEInstance *TDEGlobal::instance()
99 {
100  MYASSERT(_instance);
101  return _instance;
102 }
103 
104 TDELocale *TDEGlobal::locale()
105 {
106  if( _locale == 0 ) {
107  if (!_instance)
108  return 0;
109  kglobal_init();
110 
111  // will set _locale if it works - otherwise 0 is returned
112  TDELocale::initInstance();
113  if( _instance->aboutData())
114  _instance->aboutData()->translateInternalProgramName();
115  }
116 
117  return _locale;
118 }
119 
120 KCharsets *TDEGlobal::charsets()
121 {
122  if( _charsets == 0 ) {
123  _charsets =new KCharsets();
124  kglobal_init();
125  }
126 
127  return _charsets;
128 }
129 
130 void TDEGlobal::setActiveInstance(TDEInstance *i)
131 {
132  _activeInstance = i;
133  if (i && _locale)
134  _locale->setActiveCatalogue(TQString::fromUtf8(i->instanceName()));
135 }
136 
143 const TQString &
144 TDEGlobal::staticQString(const char *str)
145 {
146  return staticQString(TQString::fromLatin1(str));
147 }
148 
149 class KStringDict : public TQDict<TQString>
150 {
151 public:
152  KStringDict() : TQDict<TQString>(139) { }
153 };
154 
161 const TQString &
162 TDEGlobal::staticQString(const TQString &str)
163 {
164  if (!_stringDict) {
165  _stringDict = new KStringDict;
166  _stringDict->setAutoDelete( true );
167  kglobal_init();
168  }
169  TQString *result = _stringDict->find(str);
170  if (!result)
171  {
172  result = new TQString(str);
173  _stringDict->insert(str, result);
174  }
175  return *result;
176 }
177 
178 class KStaticDeleterList: public TQPtrList<KStaticDeleterBase>
179 {
180 public:
181  KStaticDeleterList() { }
182 };
183 
184 void
185 TDEGlobal::registerStaticDeleter(KStaticDeleterBase *obj)
186 {
187  if (!_staticDeleters)
188  kglobal_init();
189  if (_staticDeleters->find(obj) == -1)
190  _staticDeleters->append(obj);
191 }
192 
193 void
194 TDEGlobal::unregisterStaticDeleter(KStaticDeleterBase *obj)
195 {
196  if (_staticDeleters)
197  _staticDeleters->removeRef(obj);
198 }
199 
200 void
201 TDEGlobal::deleteStaticDeleters()
202 {
203  if (!TDEGlobal::_staticDeleters)
204  return;
205 
206  for(;_staticDeleters->count();)
207  {
208  _staticDeleters->take(0)->destructObject();
209  }
210 
211  delete TDEGlobal::_staticDeleters;
212  TDEGlobal::_staticDeleters = 0;
213 }
214 
215 // The Variables
216 
217 KStringDict *TDEGlobal::_stringDict = 0;
218 TDEInstance *TDEGlobal::_instance = 0;
219 TDEInstance *TDEGlobal::_activeInstance = 0;
220 TDELocale *TDEGlobal::_locale = 0;
221 KCharsets *TDEGlobal::_charsets = 0;
222 KStaticDeleterList *TDEGlobal::_staticDeleters = 0;
223 
224 #ifdef WIN32
225 #include <windows.h>
226 static void kglobal_freeAll();
227 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID impLoad )
228 {
229  if (reason == DLL_PROCESS_DETACH)
230  kglobal_freeAll();
231  return TRUE;
232 }
233 #else
234 __attribute__((destructor))
235 #endif
236 static void kglobal_freeAll()
237 {
238  delete TDEGlobal::_locale;
239  TDEGlobal::_locale = 0;
240  delete TDEGlobal::_charsets;
241  TDEGlobal::_charsets = 0;
242  delete TDEGlobal::_stringDict;
243  TDEGlobal::_stringDict = 0;
244  TDEGlobal::deleteStaticDeleters();
245  // so that we don't hold a reference and see memory leaks :/
246  TDEGlobal::setActiveInstance(0);
247 }
248 
249 static void kglobal_init()
250 {
251  if (TDEGlobal::_staticDeleters)
252  return;
253 
254  TDEGlobal::_staticDeleters = new KStaticDeleterList;
255 }
256 
257 int kasciistricmp( const char *str1, const char *str2 )
258 {
259  const unsigned char *s1 = (const unsigned char *)str1;
260  const unsigned char *s2 = (const unsigned char *)str2;
261  int res;
262  unsigned char c1, c2;
263 
264  if ( !s1 || !s2 )
265  return s1 ? 1 : (s2 ? -1 : 0);
266  if ( !*s1 || !*s2 )
267  return *s1 ? 1 : (*s2 ? -1 : 0);
268  for (;*s1; ++s1, ++s2) {
269  c1 = *s1; c2 = *s2;
270  if (c1 >= 'A' && c1 <= 'Z')
271  c1 += 'a' - 'A';
272  if (c2 >= 'A' && c2 <= 'Z')
273  c2 += 'a' - 'A';
274 
275  if ((res = c1 - c2))
276  break;
277  }
278  return *s1 ? res : (*s2 ? -1 : 0);
279 }
280 

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