Akonadi

agentfactory.cpp
1 /*
2  This file is part of akonadiresources.
3 
4  Copyright (c) 2006 Till Adam <[email protected]>
5  Copyright (c) 2007 Volker Krause <[email protected]>
6 
7  This library is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Library General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to the
19  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301, USA.
21 */
22 
23 #include "agentfactory.h"
24 #include "servermanager.h"
25 #include "servermanager_p.h"
26 
27 #include <KLocalizedString>
28 #include <KGlobal>
29 
30 #include <QThread>
31 #include <QThreadStorage>
32 
33 QThreadStorage<KComponentData *> s_agentComponentDatas;
34 
35 using namespace Akonadi;
36 
37 class Akonadi::AgentFactoryBasePrivate
38 {
39 public:
40  QString catalogName;
41 };
42 
43 AgentFactoryBase::AgentFactoryBase(const char *catalogName, QObject *parent)
44  : QObject(parent)
45  , d(new AgentFactoryBasePrivate)
46 {
47  d->catalogName = QString::fromLatin1(catalogName);
49  new KComponentData("AkonadiAgentServer", "libakonadi", KComponentData::RegisterAsMainComponent);
50  }
52 
53  Internal::setClientType(Internal::Agent);
54  ServerManager::self(); // make sure it's created in the main thread
55 }
56 
57 AgentFactoryBase::~AgentFactoryBase()
58 {
59  delete d;
60 }
61 
62 void AgentFactoryBase::createComponentData(const QString &identifier) const
63 {
64  Q_ASSERT(!s_agentComponentDatas.hasLocalData());
65 
67  s_agentComponentDatas.setLocalData(new KComponentData(ServerManager::addNamespace(identifier).toLatin1(), d->catalogName.toLatin1(),
68  KComponentData::SkipMainComponentRegistration));
69  } else {
70  s_agentComponentDatas.setLocalData(new KComponentData(ServerManager::addNamespace(identifier).toLatin1(), d->catalogName.toLatin1()));
71  }
72 }
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
static void setApplicationDomain(const char *domain)
QThread * thread() const const
AgentFactoryBase(const char *catalogName, QObject *parent=nullptr)
Creates a new agent factory.
void setLocalData(T data)
bool hasLocalData() const const
QCoreApplication * instance()
QThread * currentThread()
Helper integration between Akonadi and Qt.
bool hasMainComponent()
QString fromLatin1(const char *str, int size)
static QString addNamespace(const QString &string)
Adds the multi-instance namespace to string if required (with &#39;_&#39; as separator).
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.