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

kdecore

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

kdecore

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

kdecore

Skip menu "kdecore"
  • 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 kdecore by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |