• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • kernel
kglobal.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Sirtaj Singh Kanq <taj@kde.org>
3  Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #ifndef _KGLOBAL_H
20 #define _KGLOBAL_H
21 
22 #include <kdecore_export.h>
23 #include <QtCore/QAtomicPointer>
24 #include <sys/types.h>
25 #include <QtCore/QObject>
26 
27 //
28 // WARNING!!
29 // This code uses undocumented Qt API
30 // Do not copy it to your application! Use only the functions that are here!
31 // Otherwise, it could break when a new version of Qt ships.
32 //
33 
34 class KComponentData;
35 class KCharsets;
36 class KConfig;
37 class KLocale;
38 class KStandardDirs;
39 class KSharedConfig;
40 template <typename T>
41 class KSharedPtr;
42 typedef KSharedPtr<KSharedConfig> KSharedConfigPtr;
43 
45 
49 typedef void (*KdeCleanUpFunction)();
50 
57 class KCleanUpGlobalStatic
58 {
59  public:
60  KdeCleanUpFunction func;
61 
62  inline ~KCleanUpGlobalStatic() { func(); }
63 };
64 
65 #ifdef Q_CC_MSVC
66 
72 # define K_GLOBAL_STATIC_STRUCT_NAME(NAME) _k_##NAME##__LINE__
73 #else
74 
79 # define K_GLOBAL_STATIC_STRUCT_NAME(NAME)
80 #endif
81 
83 
221 #define K_GLOBAL_STATIC(TYPE, NAME) K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ())
222 
255 #define K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
256 static QBasicAtomicPointer<TYPE > _k_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0); \
257 static bool _k_static_##NAME##_destroyed; \
258 static struct K_GLOBAL_STATIC_STRUCT_NAME(NAME) \
259 { \
260  inline bool isDestroyed() const \
261  { \
262  return _k_static_##NAME##_destroyed; \
263  } \
264  inline bool exists() const \
265  { \
266  return _k_static_##NAME != 0; \
267  } \
268  inline operator TYPE*() \
269  { \
270  return operator->(); \
271  } \
272  inline TYPE *operator->() \
273  { \
274  if (!_k_static_##NAME) { \
275  if (isDestroyed()) { \
276  qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \
277  "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \
278  } \
279  TYPE *x = new TYPE ARGS; \
280  if (!_k_static_##NAME.testAndSetOrdered(0, x) \
281  && _k_static_##NAME != x ) { \
282  delete x; \
283  } else { \
284  static KCleanUpGlobalStatic cleanUpObject = { destroy }; \
285  } \
286  } \
287  return _k_static_##NAME; \
288  } \
289  inline TYPE &operator*() \
290  { \
291  return *operator->(); \
292  } \
293  static void destroy() \
294  { \
295  _k_static_##NAME##_destroyed = true; \
296  TYPE *x = _k_static_##NAME; \
297  _k_static_##NAME = 0; \
298  delete x; \
299  } \
300 } NAME;
301 
318 class KDECORE_EXPORT KCatalogLoader
319 {
320  public:
321  KCatalogLoader(const QString &catalogName);
322 };
323 
333 namespace KGlobal
334 {
335 
342  KDECORE_EXPORT const KComponentData &mainComponent(); //krazy:exclude=constref (don't mess up ref-counting)
343 
348  KDECORE_EXPORT bool hasMainComponent();
349 
354  KDECORE_EXPORT KStandardDirs *dirs();
355 
360  KDECORE_EXPORT KSharedConfigPtr config();
361 
368  KDECORE_EXPORT void insertCatalog(const QString& catalog);
369 
380  KDECORE_EXPORT KLocale *locale();
385  KDECORE_EXPORT bool hasLocale();
386 
391  KDECORE_EXPORT KCharsets *charsets();
392 
397  KDECORE_EXPORT mode_t umask();
398 
416  KDECORE_EXPORT const QString& staticQString(const char *str); //krazy:exclude=constref (doesn't make sense otherwise)
417 
435  KDECORE_EXPORT const QString& staticQString(const QString &str); //krazy:exclude=constref (doesn't make sense otherwise)
436 
458  KDECORE_EXPORT void ref();
459 
464  KDECORE_EXPORT void deref();
465 
481  KDECORE_EXPORT void setAllowQuit(bool allowQuit);
482 
489  KDECORE_EXPORT KComponentData activeComponent();
490 
497  KDECORE_EXPORT void setActiveComponent(const KComponentData &d);
498 
507  KDECORE_EXPORT QString caption();
508 
510  KDECORE_EXPORT QObject* findDirectChild_helper(const QObject* parent, const QMetaObject& mo);
511 
517  template<typename T>
518  inline T findDirectChild(const QObject* object) {
519  return static_cast<T>(findDirectChild_helper(object, (static_cast<T>(0))->staticMetaObject));
520  }
521 
525  enum CopyCatalogs { DoCopyCatalogs, DontCopyCatalogs};
526 
528  KDECORE_EXPORT void setLocale(KLocale *, CopyCatalogs copy = DoCopyCatalogs);
529 }
530 
531 #ifdef KDE_SUPPORT
532 
537 #define KMIN(a,b) qMin(a,b)
538 
543 #define KMAX(a,b) qMax(a,b)
544 
549 #define KABS(a) qAbs(a)
550 
556 #define KCLAMP(x,low,high) qBound(low,x,high)
557 
558 #define kMin qMin
559 #define kMax qMax
560 #define kAbs qAbs
561 
569 template<class T>
570 inline KDE_DEPRECATED T kClamp( const T& x, const T& low, const T& high )
571 {
572  if ( x < low ) return low;
573  else if ( high < x ) return high;
574  return x;
575 }
576 
577 #endif
578 
579 #endif // _KGLOBAL_H
580 
KGlobal::caption
QString caption()
Returns a text for the window caption.
Definition: kglobal.cpp:292
KSharedPtr
Can be used to control the lifetime of an object that has derived QSharedData.
Definition: kconfiggroup.h:38
KSharedConfig
KConfig variant using shared memory.
Definition: ksharedconfig.h:40
KCharsets
Charset font and encoder/decoder handling.
Definition: kcharsets.h:46
KSharedConfigPtr
KSharedPtr< KSharedConfig > KSharedConfigPtr
Definition: kglobal.h:41
T
#define T
kdecore_export.h
KGlobal::DoCopyCatalogs
Definition: kglobal.h:525
KGlobal::dirs
KStandardDirs * dirs()
Returns the application standard dirs object.
KGlobal::findDirectChild
T findDirectChild(const QObject *object)
Returns the child of the given object that can be cast into type T, or 0 if there is no such object...
Definition: kglobal.h:518
KGlobal::CopyCatalogs
CopyCatalogs
For setLocale.
Definition: kglobal.h:525
KGlobal::DontCopyCatalogs
Definition: kglobal.h:525
KGlobal::ref
void ref()
Tells KGlobal about one more operations that should be finished before the application exits...
Definition: kglobal.cpp:321
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:139
QMetaObject
KGlobal::deref
void deref()
Tells KGlobal that one operation such as those described in ref() just finished.
Definition: kglobal.cpp:326
KGlobal::setLocale
void setLocale(KLocale *, CopyCatalogs copy=DoCopyCatalogs)
Definition: kglobal.cpp:256
QObject
KStandardDirs
Site-independent access to standard KDE directories.
Definition: kstandarddirs.h:171
KGlobal::umask
mode_t umask()
Returns the umask of the process.
Definition: kglobal.cpp:224
KGlobal::setAllowQuit
void setAllowQuit(bool allowQuit)
If refcounting reaches 0 (or less), and allowQuit is true, the instance of the application will autom...
Definition: kglobal.cpp:334
KGlobal::activeComponent
KComponentData activeComponent()
The component currently active (useful in a multi-component application, such as a KParts application...
Definition: kglobal.cpp:230
KGlobal::charsets
KCharsets * charsets()
The global charset manager.
Definition: kglobal.cpp:214
QString
KGlobal::insertCatalog
void insertCatalog(const QString &catalog)
Inserts the catalog in the main locale object if it exists.
Definition: kglobal.cpp:160
KGlobal::setActiveComponent
void setActiveComponent(const KComponentData &d)
Set the active component for use by KAboutDialog and KBugReport.
Definition: kglobal.cpp:237
KGlobal::locale
KLocale * locale()
Returns the global locale object.
Definition: kglobal.cpp:170
KConfig
The central class of the KDE configuration data system.
Definition: kconfig.h:70
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:69
KGlobal::findDirectChild_helper
QObject * findDirectChild_helper(const QObject *parent, const QMetaObject &mo)
Definition: kglobal.cpp:346
KCatalogLoader
This class is useful in libraries where you want to make sure that anyone that uses your library will...
Definition: kglobal.h:318
KGlobal::mainComponent
const KComponentData & mainComponent()
Returns the global component data.
Definition: kglobal.cpp:145
KGlobal::hasMainComponent
bool hasMainComponent()
Definition: kglobal.cpp:151
KGlobal::staticQString
const QString & staticQString(const char *str)
Creates a static QString.
Definition: kglobal.cpp:271
KGlobal::hasLocale
bool hasLocale()
Definition: kglobal.cpp:205
KComponentData
Per component data.
Definition: kcomponentdata.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal