2
Copyright (c) 2011 Volker Krause <vkrause@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
#include "akapplication.h"
23
#include <libs/protocol_p.h>
26
#include <QStringBuilder>
27
#include <QStringList>
29
static QString makeServiceName( const char* base )
31
if (!AkApplication::hasInstanceIdentifier())
32
return QLatin1String(base);
33
return QLatin1String(base) % QLatin1Literal(".") % AkApplication::instanceIdentifier();
37
QString AkDBus::serviceName(AkDBus::ServiceType serviceType)
40
case Server: return makeServiceName(AKONADI_DBUS_SERVER_SERVICE);
41
case Control: return makeServiceName(AKONADI_DBUS_CONTROL_SERVICE);
42
case ControlLock: return makeServiceName(AKONADI_DBUS_CONTROL_SERVICE_LOCK);
43
case AgentServer: return makeServiceName(AKONADI_DBUS_AGENTSERVER_SERVICE);
44
case StorageJanitor: return makeServiceName(AKONADI_DBUS_STORAGEJANITOR_SERVICE);
50
QString AkDBus::parseAgentServiceName(const QString &serviceName, AkDBus::AgentType& agentType)
53
if ( !serviceName.startsWith( QLatin1String("org.freedesktop.Akonadi." ) ) )
55
const QStringList parts = serviceName.mid( 24 ).split( QLatin1Char('.') );
56
if ( (parts.size() == 2 && !AkApplication::hasInstanceIdentifier())
57
|| (parts.size() == 3 && AkApplication::hasInstanceIdentifier() && AkApplication::instanceIdentifier() == parts.at(2)) )
59
// switch on parts.at(0)
60
if (parts.first() == QLatin1String("Agent"))
62
else if (parts.first() == QLatin1String("Resource"))
64
else if (parts.first() == QLatin1String("Preprocessor"))
65
agentType = Preprocessor;
74
QString AkDBus::agentServiceName(const QString& agentIdentifier, AkDBus::AgentType agentType)
76
Q_ASSERT( !agentIdentifier.isEmpty() );
77
Q_ASSERT( agentType != Unknown );
78
QString serviceName = QLatin1String( "org.freedesktop.Akonadi." );
80
case Agent: serviceName += QLatin1String( "Agent." ); break;
81
case Resource: serviceName += QLatin1String( "Resource." ); break;
82
case Preprocessor: serviceName += QLatin1String( "Preprocessor."); break;
83
default: Q_ASSERT(!"WTF?");
85
serviceName += agentIdentifier;
86
if ( AkApplication::hasInstanceIdentifier() )
87
serviceName += QLatin1Char('.' ) % AkApplication::instanceIdentifier();