~ubuntu-branches/ubuntu/quantal/akonadi/quantal

« back to all changes in this revision

Viewing changes to shared/akdbus.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-01-24 23:43:13 UTC
  • mto: (3.1.12 sid)
  • mto: This revision was merged to the branch mainline in revision 69.
  • Revision ID: package-import@ubuntu.com-20120124234313-ooald4uh9w8jilyw
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2011 Volker Krause <vkrause@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
    02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "akdbus.h"
 
21
#include "akapplication.h"
 
22
 
 
23
#include <libs/protocol_p.h>
 
24
 
 
25
#include <QString>
 
26
#include <QStringBuilder>
 
27
#include <QStringList>
 
28
 
 
29
static QString makeServiceName( const char* base )
 
30
{
 
31
  if (!AkApplication::hasInstanceIdentifier())
 
32
    return QLatin1String(base);
 
33
  return QLatin1String(base) % QLatin1Literal(".") % AkApplication::instanceIdentifier();
 
34
}
 
35
 
 
36
 
 
37
QString AkDBus::serviceName(AkDBus::ServiceType serviceType)
 
38
{
 
39
  switch(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);
 
45
  }
 
46
  Q_ASSERT(!"WTF?");
 
47
  return QString();
 
48
}
 
49
 
 
50
QString AkDBus::parseAgentServiceName(const QString &serviceName, AkDBus::AgentType& agentType)
 
51
{
 
52
  agentType = Unknown;
 
53
  if ( !serviceName.startsWith( QLatin1String("org.freedesktop.Akonadi." ) ) )
 
54
    return QString();
 
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)) )
 
58
  {
 
59
    // switch on parts.at(0)
 
60
    if (parts.first() == QLatin1String("Agent"))
 
61
      agentType = Agent;
 
62
    else if (parts.first() == QLatin1String("Resource"))
 
63
      agentType = Resource;
 
64
    else if (parts.first() == QLatin1String("Preprocessor"))
 
65
      agentType = Preprocessor;
 
66
    else
 
67
      return QString();
 
68
    return parts.at(1);
 
69
  }
 
70
  
 
71
  return QString();
 
72
}
 
73
 
 
74
QString AkDBus::agentServiceName(const QString& agentIdentifier, AkDBus::AgentType agentType)
 
75
{
 
76
  Q_ASSERT( !agentIdentifier.isEmpty() );
 
77
  Q_ASSERT( agentType != Unknown );
 
78
  QString serviceName = QLatin1String( "org.freedesktop.Akonadi." );
 
79
  switch (agentType) {
 
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?");
 
84
  }
 
85
  serviceName += agentIdentifier;
 
86
  if ( AkApplication::hasInstanceIdentifier() )
 
87
    serviceName += QLatin1Char('.' ) % AkApplication::instanceIdentifier();
 
88
  return serviceName;
 
89
}