You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
281 lines
6.3 KiB
281 lines
6.3 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1999 Sirtaj Singh Kanq <taj@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
/*
|
||
12 years ago
|
* tdeglobal.cpp -- Implementation of class TDEGlobal.
|
||
15 years ago
|
* Author: Sirtaj Singh Kang
|
||
|
* Version: $Id$
|
||
|
* Generated: Sat May 1 02:08:43 EST 1999
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqglobal.h>
|
||
|
#include <tqdict.h>
|
||
|
#include <tqptrlist.h>
|
||
12 years ago
|
#include "tdeglobal.h"
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
|
#include <tdeaboutdata.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kcharsets.h>
|
||
|
#include <kiconloader.h>
|
||
13 years ago
|
#include <tdehardwaredevices.h>
|
||
12 years ago
|
#include <tdenetworkconnections.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
|
#include <kinstance.h>
|
||
|
#include "kstaticdeleter.h"
|
||
|
|
||
15 years ago
|
#include <tqfont.h>
|
||
15 years ago
|
|
||
|
#ifndef NDEBUG
|
||
|
#define MYASSERT(x) if (!x) \
|
||
12 years ago
|
tqFatal("Fatal error: you need to have a TDEInstance object before\n" \
|
||
15 years ago
|
"you do anything that requires it! Examples of this are config\n" \
|
||
|
"objects, standard directories or translations.");
|
||
|
#else
|
||
|
#define MYASSERT(x) /* nope */
|
||
|
#endif
|
||
|
|
||
|
static void kglobal_init();
|
||
|
|
||
12 years ago
|
TDEStandardDirs *TDEGlobal::dirs()
|
||
15 years ago
|
{
|
||
|
MYASSERT(_instance);
|
||
|
|
||
|
return _instance->dirs();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEConfig *TDEGlobal::config()
|
||
15 years ago
|
{
|
||
|
MYASSERT(_instance);
|
||
|
|
||
|
return _instance->config();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDESharedConfig *TDEGlobal::sharedConfig()
|
||
15 years ago
|
{
|
||
|
MYASSERT(_instance);
|
||
|
|
||
|
return _instance->sharedConfig();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIconLoader *TDEGlobal::iconLoader()
|
||
15 years ago
|
{
|
||
|
MYASSERT(_instance);
|
||
|
|
||
|
return _instance->iconLoader();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEHardwareDevices *TDEGlobal::hardwareDevices()
|
||
13 years ago
|
{
|
||
|
MYASSERT(_instance);
|
||
|
|
||
|
return _instance->hardwareDevices();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEGlobalNetworkManager *TDEGlobal::networkManager()
|
||
12 years ago
|
{
|
||
|
MYASSERT(_instance);
|
||
|
|
||
|
return _instance->networkManager();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEInstance *TDEGlobal::instance()
|
||
15 years ago
|
{
|
||
|
MYASSERT(_instance);
|
||
|
return _instance;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDELocale *TDEGlobal::locale()
|
||
15 years ago
|
{
|
||
|
if( _locale == 0 ) {
|
||
|
if (!_instance)
|
||
|
return 0;
|
||
|
kglobal_init();
|
||
|
|
||
|
// will set _locale if it works - otherwise 0 is returned
|
||
12 years ago
|
TDELocale::initInstance();
|
||
15 years ago
|
if( _instance->aboutData())
|
||
|
_instance->aboutData()->translateInternalProgramName();
|
||
|
}
|
||
|
|
||
|
return _locale;
|
||
|
}
|
||
|
|
||
12 years ago
|
KCharsets *TDEGlobal::charsets()
|
||
15 years ago
|
{
|
||
|
if( _charsets == 0 ) {
|
||
|
_charsets =new KCharsets();
|
||
|
kglobal_init();
|
||
|
}
|
||
|
|
||
|
return _charsets;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEGlobal::setActiveInstance(TDEInstance *i)
|
||
15 years ago
|
{
|
||
|
_activeInstance = i;
|
||
|
if (i && _locale)
|
||
15 years ago
|
_locale->setActiveCatalogue(TQString::fromUtf8(i->instanceName()));
|
||
15 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Create a static QString
|
||
|
*
|
||
|
* To be used inside functions(!) like:
|
||
12 years ago
|
* static const TQString &myString = TDEGlobal::staticQString("myText");
|
||
15 years ago
|
*/
|
||
15 years ago
|
const TQString &
|
||
12 years ago
|
TDEGlobal::staticQString(const char *str)
|
||
15 years ago
|
{
|
||
13 years ago
|
return staticQString(TQString::fromLatin1(str));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
class KStringDict : public TQDict<TQString>
|
||
15 years ago
|
{
|
||
|
public:
|
||
15 years ago
|
KStringDict() : TQDict<TQString>(139) { }
|
||
15 years ago
|
};
|
||
|
|
||
|
/**
|
||
|
* Create a static QString
|
||
|
*
|
||
|
* To be used inside functions(!) like:
|
||
12 years ago
|
* static const TQString &myString = TDEGlobal::staticQString(i18n("My Text"));
|
||
15 years ago
|
*/
|
||
15 years ago
|
const TQString &
|
||
12 years ago
|
TDEGlobal::staticQString(const TQString &str)
|
||
15 years ago
|
{
|
||
|
if (!_stringDict) {
|
||
|
_stringDict = new KStringDict;
|
||
|
_stringDict->setAutoDelete( true );
|
||
|
kglobal_init();
|
||
|
}
|
||
14 years ago
|
TQString *result = _stringDict->find(str);
|
||
15 years ago
|
if (!result)
|
||
|
{
|
||
15 years ago
|
result = new TQString(str);
|
||
15 years ago
|
_stringDict->insert(str, result);
|
||
|
}
|
||
|
return *result;
|
||
|
}
|
||
|
|
||
15 years ago
|
class KStaticDeleterList: public TQPtrList<KStaticDeleterBase>
|
||
15 years ago
|
{
|
||
|
public:
|
||
|
KStaticDeleterList() { }
|
||
|
};
|
||
|
|
||
|
void
|
||
12 years ago
|
TDEGlobal::registerStaticDeleter(KStaticDeleterBase *obj)
|
||
15 years ago
|
{
|
||
|
if (!_staticDeleters)
|
||
|
kglobal_init();
|
||
14 years ago
|
if (_staticDeleters->find(obj) == -1)
|
||
15 years ago
|
_staticDeleters->append(obj);
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDEGlobal::unregisterStaticDeleter(KStaticDeleterBase *obj)
|
||
15 years ago
|
{
|
||
|
if (_staticDeleters)
|
||
|
_staticDeleters->removeRef(obj);
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDEGlobal::deleteStaticDeleters()
|
||
15 years ago
|
{
|
||
12 years ago
|
if (!TDEGlobal::_staticDeleters)
|
||
15 years ago
|
return;
|
||
|
|
||
|
for(;_staticDeleters->count();)
|
||
|
{
|
||
|
_staticDeleters->take(0)->destructObject();
|
||
|
}
|
||
|
|
||
12 years ago
|
delete TDEGlobal::_staticDeleters;
|
||
|
TDEGlobal::_staticDeleters = 0;
|
||
15 years ago
|
}
|
||
|
|
||
|
// The Variables
|
||
|
|
||
12 years ago
|
KStringDict *TDEGlobal::_stringDict = 0;
|
||
|
TDEInstance *TDEGlobal::_instance = 0;
|
||
|
TDEInstance *TDEGlobal::_activeInstance = 0;
|
||
12 years ago
|
TDELocale *TDEGlobal::_locale = 0;
|
||
12 years ago
|
KCharsets *TDEGlobal::_charsets = 0;
|
||
|
KStaticDeleterList *TDEGlobal::_staticDeleters = 0;
|
||
15 years ago
|
|
||
|
#ifdef WIN32
|
||
|
#include <windows.h>
|
||
|
static void kglobal_freeAll();
|
||
|
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID impLoad )
|
||
|
{
|
||
|
if (reason == DLL_PROCESS_DETACH)
|
||
|
kglobal_freeAll();
|
||
|
return TRUE;
|
||
|
}
|
||
|
#else
|
||
|
__attribute__((destructor))
|
||
|
#endif
|
||
|
static void kglobal_freeAll()
|
||
|
{
|
||
12 years ago
|
delete TDEGlobal::_locale;
|
||
|
TDEGlobal::_locale = 0;
|
||
|
delete TDEGlobal::_charsets;
|
||
|
TDEGlobal::_charsets = 0;
|
||
|
delete TDEGlobal::_stringDict;
|
||
|
TDEGlobal::_stringDict = 0;
|
||
|
TDEGlobal::deleteStaticDeleters();
|
||
15 years ago
|
// so that we don't hold a reference and see memory leaks :/
|
||
12 years ago
|
TDEGlobal::setActiveInstance(0);
|
||
15 years ago
|
}
|
||
|
|
||
|
static void kglobal_init()
|
||
|
{
|
||
12 years ago
|
if (TDEGlobal::_staticDeleters)
|
||
15 years ago
|
return;
|
||
|
|
||
12 years ago
|
TDEGlobal::_staticDeleters = new KStaticDeleterList;
|
||
15 years ago
|
}
|
||
|
|
||
|
int kasciistricmp( const char *str1, const char *str2 )
|
||
|
{
|
||
|
const unsigned char *s1 = (const unsigned char *)str1;
|
||
|
const unsigned char *s2 = (const unsigned char *)str2;
|
||
|
int res;
|
||
|
unsigned char c1, c2;
|
||
|
|
||
|
if ( !s1 || !s2 )
|
||
|
return s1 ? 1 : (s2 ? -1 : 0);
|
||
|
if ( !*s1 || !*s2 )
|
||
|
return *s1 ? 1 : (*s2 ? -1 : 0);
|
||
|
for (;*s1; ++s1, ++s2) {
|
||
|
c1 = *s1; c2 = *s2;
|
||
|
if (c1 >= 'A' && c1 <= 'Z')
|
||
|
c1 += 'a' - 'A';
|
||
|
if (c2 >= 'A' && c2 <= 'Z')
|
||
|
c2 += 'a' - 'A';
|
||
|
|
||
|
if ((res = c1 - c2))
|
||
|
break;
|
||
|
}
|
||
|
return *s1 ? res : (*s2 ? -1 : 0);
|
||
|
}
|
||
|
|