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

KDECore

  • 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 23 2013 21:56:48 by doxygen 1.8.1.1 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-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 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
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