Commit 80087e3b authored by Volker Krause's avatar Volker Krause
Browse files

The agent manager now handles all kind of agents, not just resources.

This includes support for autostarting single-instance agents such as
the mail threader.

svn path=/trunk/KDE/kdepim/akonadi/server/; revision=727187
parent 23a7da4e
......@@ -8,6 +8,7 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" )
########### next target ###############
set( control_SRCS
agentinfo.cpp
agentmanager.cpp
controlmanager.cpp
kcrash.cpp
......
/*
Copyright (c) 2007 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 "agentinfo.h"
#include "agentmanager.h"
#include "xdgbasedirs.h"
#include "processcontrol.h"
#include <QSettings>
using namespace Akonadi;
QLatin1String AgentInfo::CapabilityUnique = QLatin1String( "Unique" );
QLatin1String AgentInfo::CapabilityResource = QLatin1String( "Resource" );
QLatin1String AgentInfo::CapabilityAutostart = QLatin1String( "Autostart" );
AgentInfo::AgentInfo() :
instanceCounter( 0 )
{
}
bool AgentInfo::load(const QString & fileName, AgentManager * manager)
{
QSettings file( fileName, QSettings::IniFormat );
file.beginGroup( "Desktop Entry" );
name = file.value( "Name" ).toString();
comment = file.value( "Comment" ).toString();
icon = file.value( "Icon" ).toString();
mimeTypes = file.value( "X-Akonadi-MimeTypes" ).toStringList();
capabilities = file.value( "X-Akonadi-Capabilities" ).toStringList();
exec = file.value( "Exec" ).toString();
identifier = file.value( "X-Akonadi-Identifier" ).toString();
file.endGroup();
if ( identifier.isEmpty() ) {
manager->tracer()->error( QLatin1String( "AgentInfo::readInfo" ),
QString( "Agent desktop file '%1' contains empty identifier" ).arg( fileName ) );
return false;
}
if ( exec.isEmpty() ) {
manager->tracer()->error( QLatin1String( "AgentInfo::readInfo" ),
QString( "Agent desktop file '%1' contains empty Exec entry" ).arg( fileName ) );
return false;
}
// autostart implies unique
if ( capabilities.contains( CapabilityAutostart ) && !capabilities.contains( CapabilityUnique ) )
capabilities << CapabilityUnique;
// load instance count if needed
if ( !capabilities.contains( CapabilityUnique ) ) {
QSettings agentrc( manager->configPath( false ), QSettings::IniFormat );
instanceCounter = agentrc.value( QString::fromLatin1( "InstanceCounters/%1/InstanceCounter" )
.arg( identifier ), 0 ).toInt();
}
return true;
}
void AgentInfo::save( QSettings *config ) const
{
Q_ASSERT( config );
if ( !capabilities.contains( CapabilityUnique ) ) {
config->setValue( QString::fromLatin1( "InstanceCounters/%1/InstanceCounter" ).arg( identifier ), instanceCounter );
}
}
AgentInstanceInfo::AgentInstanceInfo() :
controller( 0 ),
agentInterface( 0 ),
resourceInterface( 0 )
{
}
bool AgentInstanceInfo::start( const AgentInfo &agentInfo, AgentManager *manager )
{
Q_ASSERT( !identifier.isEmpty() );
if ( identifier.isEmpty() )
return false;
const QString executable = Akonadi::XdgBaseDirs::findExecutableFile( agentInfo.exec );
if ( executable.isEmpty() ) {
manager->tracer()->error( QLatin1String( "AgentInstanceInfo::start" ),
QString::fromLatin1( "Unable to find agent executable '%1'" ).arg( agentInfo.exec ) );
return false;
}
controller = new Akonadi::ProcessControl( manager );
QStringList arguments;
arguments << "--identifier" << identifier;
controller->start( executable, arguments );
return true;
}
/*
Copyright (c) 2007 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.
*/
#ifndef AKONADI_AGENTINFO_H
#define AKONADI_AGENTINFO_H
#include "agentinterface.h"
#include "resourceinterface.h"
#include "tracerinterface.h"
#include <QString>
#include <QStringList>
namespace Akonadi {
class ProcessControl;
}
class AgentManager;
class QSettings;
class AgentInfo
{
public:
AgentInfo();
bool load( const QString &fileName, AgentManager *manager );
void save( QSettings *config ) const;
QString identifier;
QString name;
QString comment;
QString icon;
QStringList mimeTypes;
QStringList capabilities;
QString exec;
uint instanceCounter;
static QLatin1String CapabilityUnique;
static QLatin1String CapabilityResource;
static QLatin1String CapabilityAutostart;
};
class AgentInstanceInfo
{
public:
AgentInstanceInfo();
bool start( const AgentInfo &agentInfo, AgentManager* manager );
QString identifier;
QString agentType;
Akonadi::ProcessControl *controller;
org::kde::Akonadi::Agent *agentInterface;
org::kde::Akonadi::Resource *resourceInterface;
};
#endif
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
* Copyright (c) 2007 Volker Krause <vkrause@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
......@@ -20,11 +21,11 @@
#ifndef AGENTMANAGER_H
#define AGENTMANAGER_H
#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QStringList>
#include "agentinterface.h"
#include "resourceinterface.h"
#include "agentinfo.h"
#include "tracerinterface.h"
class QDir;
......@@ -62,6 +63,13 @@ class AgentManager : public QObject
*/
void cleanup();
/**
* Returns the path of the config file.
*/
static QString configPath( bool writeable );
org::kde::Akonadi::Tracer* tracer() const { return mTracer; }
public Q_SLOTS:
/**
* Returns the list of identifiers of all available
......@@ -240,7 +248,7 @@ class AgentManager : public QObject
private Q_SLOTS:
void updatePluginInfos();
void resourceRegistered( const QString&, const QString&, const QString& );
void agentRegistered( const QString&, const QString&, const QString& );
void resourceStatusChanged( int status, const QString &message );
void resourceProgressChanged( uint progress, const QString &message );
void resourceNameChanged( const QString& );
......@@ -252,11 +260,6 @@ class AgentManager : public QObject
*/
static QStringList pluginInfoPathList();
/**
* Returns the path of the config file.
*/
static QString configPath( bool writeable );
/**
* Loads the internal state from config file.
*/
......@@ -279,60 +282,26 @@ class AgentManager : public QObject
*/
void readPluginInfos( const QDir &directory );
/**
* Internal method.
*/
bool checkInterface( const QString &identifier, const QString &method ) const;
class PluginInfo
{
public:
QString identifier;
QString name;
QString comment;
QString icon;
QStringList mimeTypes;
QStringList capabilities;
QString exec;
};
class InstanceInfo
{
public:
uint instanceCounter;
};
class Instance
{
public:
QString agentType;
Akonadi::ProcessControl *controller;
org::kde::Akonadi::Agent *agentInterface;
org::kde::Akonadi::Resource *resourceInterface;
};
bool checkAgentInterface( const QString &identifier ) const;
bool checkResourceInterface( const QString &identifier, const QString &method ) const;
bool checkAgentExists( const QString &identifier ) const;
void ensureAutoStart( const AgentInfo &info );
private:
/**
* The map which stores the .desktop file
* entries for every agent type.
*
* Key is the agent type (e.g. 'file' or 'imap').
*/
QMap<QString, PluginInfo> mPluginInfos;
/**
* The map which stores the instance specific
* settings for every plugin type.
*
* Key is the agent type.
*/
QMap<QString, InstanceInfo> mInstanceInfos;
QHash<QString, AgentInfo> mAgents;
/**
* The map which stores the active instances.
*
* Key is the instance identifier.
*/
QMap<QString, Instance> mInstances;
QHash<QString, AgentInstanceInfo> mAgentInstances;
org::kde::Akonadi::Tracer *mTracer;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment