mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
93 lines
3.1 KiB
C++
93 lines
3.1 KiB
C++
/* This file is part of the KDE project
|
|
Copyright (C) 2007 Matthias Kretz <kretz@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.
|
|
|
|
*/
|
|
|
|
#ifndef KERNEL_KCOMPONENTDATA_P_H
|
|
#define KERNEL_KCOMPONENTDATA_P_H
|
|
|
|
#include "kcomponentdata.h"
|
|
|
|
#include <kconfig.h>
|
|
#include <kaboutdata.h>
|
|
#include <kstandarddirs.h>
|
|
#include <klocale.h>
|
|
|
|
class KComponentDataPrivate
|
|
{
|
|
public:
|
|
KComponentDataPrivate(const KAboutData &aboutData_)
|
|
: dirs(nullptr),
|
|
aboutData(aboutData_),
|
|
refCount(1)
|
|
{
|
|
if (KGlobal::hasLocale()) {
|
|
KGlobal::locale()->insertCatalog(aboutData.catalogName());
|
|
shouldRemoveCatalog = true;
|
|
} else {
|
|
shouldRemoveCatalog = false;
|
|
}
|
|
}
|
|
|
|
~KComponentDataPrivate()
|
|
{
|
|
refCount.fetchAndStoreOrdered(-0x00FFFFFF); //prevent a reentering of the dtor
|
|
if (shouldRemoveCatalog && KGlobal::hasLocale())
|
|
KGlobal::locale()->removeCatalog(aboutData.catalogName());
|
|
|
|
sharedConfig = 0; //delete the config object first, because it could access the standard dirs while syncing
|
|
delete dirs;
|
|
}
|
|
|
|
inline void ref()
|
|
{
|
|
refCount.ref();
|
|
//qDebug() << refCount - 1 << "->" << refCount << kBacktrace();
|
|
}
|
|
|
|
inline void deref()
|
|
{
|
|
const int refc = refCount.fetchAndAddOrdered(-1) - 1;
|
|
//qDebug() << refCount + 1 << "->" << refCount << kBacktrace();
|
|
if (refc == 0) {
|
|
delete this;
|
|
} else if (refc == 1 && sharedConfig && sharedConfig->componentData().d == this) { //sharedConfig has a reference to us
|
|
if (sharedConfig.count() == 1) { //we are the only class with a reference to the config object
|
|
delete this;
|
|
} else if (sharedConfig.count() > 0) { //there are other references to it.
|
|
sharedConfig->ref.deref(); //we don't have a reference to the config object anymore, but it has still a reference to us
|
|
//this breaks the circular dependencies
|
|
}
|
|
}
|
|
}
|
|
|
|
void lazyInit(const KComponentData &component);
|
|
|
|
KStandardDirs *dirs;
|
|
KAboutData aboutData;
|
|
QString configName;
|
|
KSharedConfig::Ptr sharedConfig;
|
|
|
|
private:
|
|
bool shouldRemoveCatalog;
|
|
QAtomicInt refCount;
|
|
KComponentDataPrivate(const KComponentDataPrivate&);
|
|
KComponentDataPrivate &operator=(const KComponentDataPrivate&);
|
|
};
|
|
|
|
#endif // KERNEL_KCOMPONENTDATA_P_H
|
|
// vim: sw=4 sts=4 et tw=100
|