1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
Copyright (c) 2011 Volker Krause <vkrause@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 as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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.
*/
#include "akdbus.h"
#include "akapplication.h"
#include <libs/protocol_p.h>
#include <QString>
#include <QStringBuilder>
#include <QStringList>
static QString makeServiceName( const char* base )
{
if (!AkApplication::hasInstanceIdentifier())
return QLatin1String(base);
return QLatin1String(base) % QLatin1Literal(".") % AkApplication::instanceIdentifier();
}
QString AkDBus::serviceName(AkDBus::ServiceType serviceType)
{
switch(serviceType) {
case Server: return makeServiceName(AKONADI_DBUS_SERVER_SERVICE);
case Control: return makeServiceName(AKONADI_DBUS_CONTROL_SERVICE);
case ControlLock: return makeServiceName(AKONADI_DBUS_CONTROL_SERVICE_LOCK);
case AgentServer: return makeServiceName(AKONADI_DBUS_AGENTSERVER_SERVICE);
case StorageJanitor: return makeServiceName(AKONADI_DBUS_STORAGEJANITOR_SERVICE);
}
Q_ASSERT(!"WTF?");
return QString();
}
QString AkDBus::parseAgentServiceName(const QString &serviceName, AkDBus::AgentType& agentType)
{
agentType = Unknown;
if ( !serviceName.startsWith( QLatin1String("org.freedesktop.Akonadi." ) ) )
return QString();
const QStringList parts = serviceName.mid( 24 ).split( QLatin1Char('.') );
if ( (parts.size() == 2 && !AkApplication::hasInstanceIdentifier())
|| (parts.size() == 3 && AkApplication::hasInstanceIdentifier() && AkApplication::instanceIdentifier() == parts.at(2)) )
{
// switch on parts.at(0)
if (parts.first() == QLatin1String("Agent"))
agentType = Agent;
else if (parts.first() == QLatin1String("Resource"))
agentType = Resource;
else if (parts.first() == QLatin1String("Preprocessor"))
agentType = Preprocessor;
else
return QString();
return parts.at(1);
}
return QString();
}
QString AkDBus::agentServiceName(const QString& agentIdentifier, AkDBus::AgentType agentType)
{
Q_ASSERT( !agentIdentifier.isEmpty() );
Q_ASSERT( agentType != Unknown );
QString serviceName = QLatin1String( "org.freedesktop.Akonadi." );
switch (agentType) {
case Agent: serviceName += QLatin1String( "Agent." ); break;
case Resource: serviceName += QLatin1String( "Resource." ); break;
case Preprocessor: serviceName += QLatin1String( "Preprocessor."); break;
default: Q_ASSERT(!"WTF?");
}
serviceName += agentIdentifier;
if ( AkApplication::hasInstanceIdentifier() )
serviceName += QLatin1Char('.' ) % AkApplication::instanceIdentifier();
return serviceName;
}
|