• 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
kcomponentdata_p.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2007 Matthias Kretz <kretz@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 
20 #ifndef KERNEL_KCOMPONENTDATA_P_H
21 #define KERNEL_KCOMPONENTDATA_P_H
22 
23 #include "kcomponentdata.h"
24 #include <QAtomicInt>
25 #include <QtDebug>
26 #include <QString>
27 
28 #include <kconfig.h>
29 #include <kaboutdata.h>
30 #include <kstandarddirs.h>
31 #include <klocale.h>
32 
33 class KComponentDataPrivate
34 {
35 public:
36  KComponentDataPrivate(const KAboutData &aboutData_)
37  : dirs(0),
38  aboutData(aboutData_),
39  syncing(false),
40  refCount(1)
41  {
42  if (KGlobal::hasLocale()) {
43  KGlobal::locale()->insertCatalog(aboutData.catalogName());
44  shouldRemoveCatalog = true;
45  } else {
46  shouldRemoveCatalog = false;
47  }
48  }
49 
50  ~KComponentDataPrivate()
51  {
52  refCount.fetchAndStoreOrdered(-0x00FFFFFF); //prevent a reentering of the dtor
53  if (shouldRemoveCatalog && KGlobal::hasLocale())
54  KGlobal::locale()->removeCatalog(aboutData.catalogName());
55 
56  sharedConfig = 0; //delete the config object first, because it could access the standard dirs while syncing
57  delete dirs;
58  }
59 
60  inline void ref()
61  {
62  refCount.ref();
63  //qDebug() << refCount - 1 << "->" << refCount << kBacktrace() << endl;
64  }
65 
66  inline void deref()
67  {
68  const int refc = refCount.fetchAndAddOrdered(-1) - 1;
69  //qDebug() << refCount + 1 << "->" << refCount << kBacktrace() << endl;
70  if (refc == 0) {
71  delete this;
72  } else if (refc == 1 && sharedConfig && sharedConfig->componentData().d == this) { //sharedConfig has a reference to us
73  if (sharedConfig.count() == 1) { //we are the only class with a reference to the config object
74  delete this;
75  } else if (sharedConfig.count() > 0) { //there are other references to it.
76  sharedConfig->ref.deref(); //we don't have a reference to the config object anymore, but it has still a reference to us
77  //this breaks the circular dependencies
78  }
79  }
80  }
81 
82  void lazyInit(const KComponentData &component);
83  void configInit(const KComponentData &component); //call this only from lazyInit()!
84 
85  KStandardDirs *dirs;
86  KAboutData aboutData;
87  QString configName;
88  KSharedConfig::Ptr sharedConfig;
89  bool syncing;
90 
91 private:
92  bool shouldRemoveCatalog;
93  QAtomicInt refCount;
94  KComponentDataPrivate(const KComponentDataPrivate&);
95  KComponentDataPrivate &operator=(const KComponentDataPrivate&);
96 };
97 
98 #endif // KERNEL_KCOMPONENTDATA_P_H
99 // vim: sw=4 sts=4 et tw=100
KSharedPtr< KSharedConfig >
KComponentDataPrivate::syncing
bool syncing
Definition: kcomponentdata_p.h:89
KComponentDataPrivate::configInit
void configInit(const KComponentData &component)
Definition: kcomponentdata.cpp:165
kconfig.h
KLocale::removeCatalog
void removeCatalog(const QString &catalog)
Removes a catalog for translation lookup.
Definition: klocale.cpp:141
KConfig::componentData
const KComponentData & componentData() const
Returns the component data this configuration is for.
Definition: kconfig.cpp:255
QAtomicInt::fetchAndAddOrdered
int fetchAndAddOrdered(int valueToAdd)
QAtomicInt::ref
bool ref()
KSharedPtr::count
int count() const
Returns the number of references.
Definition: ksharedptr.h:144
KComponentDataPrivate::configName
QString configName
Definition: kcomponentdata_p.h:87
klocale.h
KAboutData::catalogName
QString catalogName() const
Returns the program's translation catalog name.
Definition: kaboutdata.cpp:765
KComponentDataPrivate::deref
void deref()
Definition: kcomponentdata_p.h:66
KComponentDataPrivate::KComponentDataPrivate
KComponentDataPrivate(const KAboutData &aboutData_)
Definition: kcomponentdata_p.h:36
KComponentDataPrivate::sharedConfig
KSharedConfig::Ptr sharedConfig
Definition: kcomponentdata_p.h:88
KComponentDataPrivate
Definition: kcomponentdata_p.h:33
QAtomicInt::fetchAndStoreOrdered
int fetchAndStoreOrdered(int newValue)
KComponentDataPrivate::ref
void ref()
Definition: kcomponentdata_p.h:60
KStandardDirs
Site-independent access to standard KDE directories.
Definition: kstandarddirs.h:171
KAboutData
This class is used to store information about a program.
Definition: kaboutdata.h:192
QAtomicInt
KComponentDataPrivate::lazyInit
void lazyInit(const KComponentData &component)
Definition: kcomponentdata.cpp:133
QString
KComponentDataPrivate::aboutData
KAboutData aboutData
Definition: kcomponentdata_p.h:86
KLocale::insertCatalog
void insertCatalog(const QString &catalog)
Adds another catalog to search for translation lookup.
Definition: klocale.cpp:136
KGlobal::locale
KLocale * locale()
Returns the global locale object.
Definition: kglobal.cpp:170
kstandarddirs.h
KComponentDataPrivate::~KComponentDataPrivate
~KComponentDataPrivate()
Definition: kcomponentdata_p.h:50
kaboutdata.h
KComponentDataPrivate::dirs
KStandardDirs * dirs
Definition: kcomponentdata_p.h:85
kcomponentdata.h
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:10 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