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

KDECore

kcomponentdata_p.h

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #ifndef KERNEL_KCOMPONENTDATA_P_H
00021 #define KERNEL_KCOMPONENTDATA_P_H
00022 
00023 #include "kcomponentdata.h"
00024 #include <QAtomicInt>
00025 #include <QtDebug>
00026 #include <QString>
00027 
00028 #include <kconfig.h>
00029 #include <kaboutdata.h>
00030 #include <kstandarddirs.h>
00031 #include <klocale.h>
00032 
00033 class KComponentDataPrivate
00034 {
00035 public:
00036     KComponentDataPrivate(const KAboutData &aboutData_)
00037         : dirs(0),
00038         aboutData(aboutData_),
00039         syncing(false),
00040         refCount(1)
00041     {
00042         if (KGlobal::hasLocale()) {
00043             KGlobal::locale()->insertCatalog(aboutData.catalogName());
00044             shouldRemoveCatalog = true;
00045         } else {
00046             shouldRemoveCatalog = false;
00047     }
00048     }
00049 
00050     ~KComponentDataPrivate()
00051     {
00052         refCount.fetchAndStoreOrdered(-0x00FFFFFF); //prevent a reentering of the dtor
00053         if (shouldRemoveCatalog && KGlobal::hasLocale())
00054             KGlobal::locale()->removeCatalog(aboutData.catalogName());
00055 
00056         sharedConfig = 0;   //delete the config object first, because it could access the standard dirs while syncing
00057         delete dirs;
00058     }
00059 
00060     inline void ref()
00061     {
00062         refCount.ref();
00063         //qDebug() << refCount - 1 << "->" << refCount << kBacktrace() << endl;
00064     }
00065 
00066     inline void deref()
00067     {
00068         const int refc = refCount.fetchAndAddOrdered(-1) - 1;
00069         //qDebug() << refCount + 1 << "->" << refCount << kBacktrace() << endl;
00070         if (refc == 0) {
00071             delete this;
00072         } else if (refc == 1 && sharedConfig && sharedConfig->componentData().d == this) { //sharedConfig has a reference to us
00073             if (sharedConfig.count() == 1) {    //we are the only class with a reference to the config object
00074                 delete this;
00075             } else if (sharedConfig.count() > 0) {  //there are other references to it.
00076                 sharedConfig->ref.deref();  //we don't have a reference to the config object anymore, but it has still a reference to us
00077                                             //this breaks the circular dependencies
00078             }
00079         }
00080     }
00081 
00082     void lazyInit(const KComponentData &component);
00083     void configInit(const KComponentData &component);  //call this only from lazyInit()!
00084 
00085     KStandardDirs *dirs;
00086     KAboutData aboutData;
00087     QString configName;
00088     KSharedConfig::Ptr sharedConfig;
00089     bool syncing;
00090 
00091 private:
00092     bool shouldRemoveCatalog;
00093     QAtomicInt refCount;
00094     KComponentDataPrivate(const KComponentDataPrivate&);
00095     KComponentDataPrivate &operator=(const KComponentDataPrivate&);
00096 };
00097 
00098 #endif // KERNEL_KCOMPONENTDATA_P_H
00099 // vim: sw=4 sts=4 et tw=100

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal