Commit 7e0616a6 authored by Guy Maurel's avatar Guy Maurel Committed by Daniel Vrátil
Browse files

Merge coding-style branch (squashed)

This changes the coding style in the entire Akonadi repo to follow the new
KDE PIM coding style (https://techbase.kde.org/Policies/Kdepim_Coding_Style)
parent 4737a062
......@@ -23,39 +23,39 @@
#include <QtCore/QStringList>
#include <QApplication>
int main( int argc, char *argv[] )
int main(int argc, char *argv[])
{
QApplication app( argc, argv );
app.setQuitOnLastWindowClosed( false );
if ( app.arguments().size() != 3 ) { // Expected usage: ./agent_launcher ${plugin_name} ${identifier}
qDebug() << "Invalid usage: expected: ./agent_launcher pluginName agentIdentifier";
return 1;
}
const QString agentPluginName = app.arguments().at( 1 );
const QString agentIdentifier = app.arguments().at( 2 );
AgentPluginLoader loader;
QPluginLoader *factory = loader.load( agentPluginName );
if ( factory == 0 ) {
return 1;
}
QObject *instance = 0;
const bool invokeSucceeded = QMetaObject::invokeMethod( factory->instance(),
"createInstance",
Qt::DirectConnection,
Q_RETURN_ARG( QObject*, instance ),
Q_ARG( QString, agentIdentifier ) );
if ( invokeSucceeded ) {
qDebug() << "Agent instance created in separate process.";
} else {
qDebug() << "Agent instance creation in separate process failed";
return 2;
}
const int rv = app.exec();
delete instance;
return rv;
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
if (app.arguments().size() != 3) { // Expected usage: ./agent_launcher ${plugin_name} ${identifier}
qDebug() << "Invalid usage: expected: ./agent_launcher pluginName agentIdentifier";
return 1;
}
const QString agentPluginName = app.arguments().at(1);
const QString agentIdentifier = app.arguments().at(2);
AgentPluginLoader loader;
QPluginLoader *factory = loader.load(agentPluginName);
if (factory == 0) {
return 1;
}
QObject *instance = 0;
const bool invokeSucceeded = QMetaObject::invokeMethod(factory->instance(),
"createInstance",
Qt::DirectConnection,
Q_RETURN_ARG(QObject *, instance),
Q_ARG(QString, agentIdentifier));
if (invokeSucceeded) {
qDebug() << "Agent instance created in separate process.";
} else {
qDebug() << "Agent instance creation in separate process failed";
return 2;
}
const int rv = app.exec();
delete instance;
return rv;
}
......@@ -25,28 +25,28 @@ using namespace Akonadi;
AgentPluginLoader::~AgentPluginLoader()
{
qDeleteAll( m_pluginLoaders );
m_pluginLoaders.clear();
qDeleteAll(m_pluginLoaders);
m_pluginLoaders.clear();
}
QPluginLoader *AgentPluginLoader::load( const QString &pluginName )
QPluginLoader *AgentPluginLoader::load(const QString &pluginName)
{
const QString pluginFile = XdgBaseDirs::findPluginFile( pluginName );
if ( pluginFile.isEmpty() ) {
akError() << Q_FUNC_INFO << "plugin file:" << pluginName << "not found!";
return 0;
}
if ( m_pluginLoaders.contains( pluginFile ) ) {
return m_pluginLoaders.value( pluginFile );
} else {
QPluginLoader *loader = new QPluginLoader( pluginFile );
if ( !loader->load() ) {
akError() << Q_FUNC_INFO << "Failed to load agent: " << loader->errorString();
delete loader;
return 0;
const QString pluginFile = XdgBaseDirs::findPluginFile(pluginName);
if (pluginFile.isEmpty()) {
akError() << Q_FUNC_INFO << "plugin file:" << pluginName << "not found!";
return 0;
}
if (m_pluginLoaders.contains(pluginFile)) {
return m_pluginLoaders.value(pluginFile);
} else {
QPluginLoader *loader = new QPluginLoader(pluginFile);
if (!loader->load()) {
akError() << Q_FUNC_INFO << "Failed to load agent: " << loader->errorString();
delete loader;
return 0;
}
m_pluginLoaders.insert(pluginFile, loader);
return loader;
}
m_pluginLoaders.insert( pluginFile, loader );
return loader;
}
}
......@@ -24,7 +24,7 @@
class AgentPluginLoader
{
public:
public:
/**
Deletes all instantiated QPluginLoaders.
*/
......@@ -37,9 +37,9 @@ class AgentPluginLoader
@return the plugin for @param pluginName or 0 if the plugin is not found.
*/
QPluginLoader *load( const QString &pluginName );
QPluginLoader *load(const QString &pluginName);
private:
private:
QHash<QString, QPluginLoader *> m_pluginLoaders;
};
......
......@@ -32,103 +32,103 @@
using namespace Akonadi;
AgentServer::AgentServer( QObject *parent )
: QObject( parent )
, m_processingConfigureRequests( false )
, m_quiting( false )
AgentServer::AgentServer(QObject *parent)
: QObject(parent)
, m_processingConfigureRequests(false)
, m_quiting(false)
{
QDBusConnection::sessionBus().registerObject( QLatin1String( AKONADI_DBUS_AGENTSERVER_PATH ),
this, QDBusConnection::ExportScriptableSlots );
QDBusConnection::sessionBus().registerObject(QLatin1String(AKONADI_DBUS_AGENTSERVER_PATH),
this, QDBusConnection::ExportScriptableSlots);
}
AgentServer::~AgentServer()
{
qDebug() << Q_FUNC_INFO;
if ( !m_quiting ) {
quit();
}
qDebug() << Q_FUNC_INFO;
if (!m_quiting) {
quit();
}
}
void AgentServer::agentInstanceConfigure( const QString &identifier, qlonglong windowId )
void AgentServer::agentInstanceConfigure(const QString &identifier, qlonglong windowId)
{
m_configureQueue.enqueue( ConfigureInfo( identifier, windowId ) );
if ( !m_processingConfigureRequests ) { // Start processing the requests if needed.
QTimer::singleShot( 0, this, SLOT(processConfigureRequest()) );
}
m_configureQueue.enqueue(ConfigureInfo(identifier, windowId));
if (!m_processingConfigureRequests) { // Start processing the requests if needed.
QTimer::singleShot(0, this, SLOT(processConfigureRequest()));
}
}
bool AgentServer::started( const QString &identifier ) const
bool AgentServer::started(const QString &identifier) const
{
return m_agents.contains( identifier );
return m_agents.contains(identifier);
}
void AgentServer::startAgent( const QString &identifier, const QString &typeIdentifier, const QString &fileName )
void AgentServer::startAgent(const QString &identifier, const QString &typeIdentifier, const QString &fileName)
{
akDebug() << Q_FUNC_INFO << identifier << typeIdentifier << fileName;
//First try to load it staticly
Q_FOREACH ( QObject *plugin, QPluginLoader::staticInstances() ) {
if ( plugin->objectName() == fileName ) {
AgentThread *thread = new AgentThread( identifier, plugin, this );
m_agents.insert( identifier, thread );
thread->start();
return;
akDebug() << Q_FUNC_INFO << identifier << typeIdentifier << fileName;
//First try to load it staticly
Q_FOREACH (QObject *plugin, QPluginLoader::staticInstances()) {
if (plugin->objectName() == fileName) {
AgentThread *thread = new AgentThread(identifier, plugin, this);
m_agents.insert(identifier, thread);
thread->start();
return;
}
}
}
QPluginLoader *loader = m_agentLoader.load( fileName );
if ( loader == 0 ) {
return; // No plugin found, debug output in AgentLoader.
}
QPluginLoader *loader = m_agentLoader.load(fileName);
if (loader == 0) {
return; // No plugin found, debug output in AgentLoader.
}
Q_ASSERT( loader->isLoaded() );
Q_ASSERT(loader->isLoaded());
AgentThread *thread = new AgentThread( identifier, loader->instance(), this );
m_agents.insert( identifier, thread );
thread->start();
AgentThread *thread = new AgentThread(identifier, loader->instance(), this);
m_agents.insert(identifier, thread);
thread->start();
}
void AgentServer::stopAgent( const QString &identifier )
void AgentServer::stopAgent(const QString &identifier)
{
if ( !m_agents.contains( identifier ) ) {
return;
}
AgentThread *thread = m_agents.take( identifier );
thread->quit();
thread->wait();
delete thread;
if (!m_agents.contains(identifier)) {
return;
}
AgentThread *thread = m_agents.take(identifier);
thread->quit();
thread->wait();
delete thread;
}
void AgentServer::quit()
{
Q_ASSERT( !m_quiting );
m_quiting = true;
Q_ASSERT(!m_quiting);
m_quiting = true;
QMutableHashIterator<QString, AgentThread *> it( m_agents );
while ( it.hasNext() ) {
it.next();
stopAgent( it.key() );
}
QMutableHashIterator<QString, AgentThread *> it(m_agents);
while (it.hasNext()) {
it.next();
stopAgent(it.key());
}
QCoreApplication::instance()->quit();
QCoreApplication::instance()->quit();
}
void AgentServer::processConfigureRequest()
{
if ( m_processingConfigureRequests ) {
return; // Protect against reentrancy
}
if (m_processingConfigureRequests) {
return; // Protect against reentrancy
}
m_processingConfigureRequests = true;
m_processingConfigureRequests = true;
while ( !m_configureQueue.empty() ) {
const ConfigureInfo info = m_configureQueue.dequeue();
// call configure on the agent with id info.first for windowId info.second.
Q_ASSERT( m_agents.contains( info.first ) );
AgentThread *thread = m_agents.value( info.first );
thread->configure( info.second );
}
while (!m_configureQueue.empty()) {
const ConfigureInfo info = m_configureQueue.dequeue();
// call configure on the agent with id info.first for windowId info.second.
Q_ASSERT(m_agents.contains(info.first));
AgentThread *thread = m_agents.value(info.first);
thread->configure(info.second);
}
m_processingConfigureRequests = false;
m_processingConfigureRequests = false;
}
......@@ -32,26 +32,26 @@ class AgentThread;
class AgentServer : public QObject
{
Q_OBJECT
Q_CLASSINFO( "D-Bus Interface", "org.freedesktop.Akonadi.AgentServer" )
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Akonadi.AgentServer")
typedef QPair<QString, qlonglong> ConfigureInfo;
typedef QPair<QString, qlonglong> ConfigureInfo;
public:
explicit AgentServer( QObject *parent = 0 );
public:
explicit AgentServer(QObject *parent = 0);
~AgentServer();
public Q_SLOTS:
Q_SCRIPTABLE void agentInstanceConfigure( const QString &identifier, qlonglong windowId );
Q_SCRIPTABLE bool started( const QString &identifier ) const;
Q_SCRIPTABLE void startAgent( const QString &identifier, const QString &typeIdentifier, const QString &fileName );
Q_SCRIPTABLE void stopAgent( const QString &identifier );
public Q_SLOTS:
Q_SCRIPTABLE void agentInstanceConfigure(const QString &identifier, qlonglong windowId);
Q_SCRIPTABLE bool started(const QString &identifier) const;
Q_SCRIPTABLE void startAgent(const QString &identifier, const QString &typeIdentifier, const QString &fileName);
Q_SCRIPTABLE void stopAgent(const QString &identifier);
Q_SCRIPTABLE void quit();
private Q_SLOTS:
private Q_SLOTS:
void processConfigureRequest();
private:
private:
QHash<QString, AgentThread *> m_agents;
QQueue<ConfigureInfo> m_configureQueue;
AgentPluginLoader m_agentLoader;
......
......@@ -29,35 +29,35 @@
using namespace Akonadi;
AgentThread::AgentThread( const QString &identifier, QObject *factory, QObject *parent )
: QThread( parent )
, m_identifier( identifier )
, m_factory( factory )
, m_instance( 0 )
AgentThread::AgentThread(const QString &identifier, QObject *factory, QObject *parent)
: QThread(parent)
, m_identifier(identifier)
, m_factory(factory)
, m_instance(0)
{
}
void AgentThread::run()
{
const bool invokeSucceeded = QMetaObject::invokeMethod( m_factory,
"createInstance",
Qt::DirectConnection,
Q_RETURN_ARG( QObject*, m_instance ),
Q_ARG( QString, m_identifier ) );
if ( invokeSucceeded ) {
qDebug() << Q_FUNC_INFO << "agent instance created: " << m_instance;
} else {
qDebug() << Q_FUNC_INFO << "agent instance creation failed";
}
exec();
delete m_instance;
const bool invokeSucceeded = QMetaObject::invokeMethod(m_factory,
"createInstance",
Qt::DirectConnection,
Q_RETURN_ARG(QObject *, m_instance),
Q_ARG(QString, m_identifier));
if (invokeSucceeded) {
qDebug() << Q_FUNC_INFO << "agent instance created: " << m_instance;
} else {
qDebug() << Q_FUNC_INFO << "agent instance creation failed";
}
exec();
delete m_instance;
}
void AgentThread::configure( qlonglong windowId )
void AgentThread::configure(qlonglong windowId)
{
QMetaObject::invokeMethod( m_instance,
"configure",
Qt::DirectConnection,
Q_ARG( WId, (WId)windowId ) );
QMetaObject::invokeMethod(m_instance,
"configure",
Qt::DirectConnection,
Q_ARG(WId, (WId)windowId));
}
......@@ -29,9 +29,9 @@ namespace Akonadi {
*/
class AgentThread : public QThread
{
Q_OBJECT
Q_OBJECT
public:
public:
/**
* Creates a new agent thread.
*
......@@ -39,19 +39,19 @@ class AgentThread : public QThread
* @param factory The factory object that creates the agent instance.
* @param parent The parent object.
*/
AgentThread( const QString &identifier, QObject *factory, QObject *parent = 0 );
AgentThread(const QString &identifier, QObject *factory, QObject *parent = 0);
/**
* Configures the agent.
*
* @param windowId The parent window id for the config dialog.
*/
void configure( qlonglong windowId );
void configure(qlonglong windowId);
protected:
protected:
void run();
private:
private:
QString m_identifier;
QObject *m_factory;
QObject *m_instance;
......
......@@ -28,23 +28,23 @@
#include <QtDBus/QDBusError>
#include <QApplication>
int main( int argc, char **argv )
int main(int argc, char **argv)
{
AkGuiApplication app( argc, argv );
app.setDescription( QLatin1String( "Akonadi Agent Server\nDo not run manually, use 'akonadictl' instead to start/stop Akonadi." ) );
app.parseCommandLine();
qApp->setQuitOnLastWindowClosed( false );
AkGuiApplication app(argc, argv);
app.setDescription(QLatin1String("Akonadi Agent Server\nDo not run manually, use 'akonadictl' instead to start/stop Akonadi."));
app.parseCommandLine();
qApp->setQuitOnLastWindowClosed(false);
if ( !QDBusConnection::sessionBus().interface()->isServiceRegistered( AkDBus::serviceName( AkDBus::ControlLock ) ) ) {
akError() << "Akonadi control process not found - aborting.";
akFatal() << "If you started akonadi_agent_server manually, try 'akonadictl start' instead.";
}
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(AkDBus::serviceName(AkDBus::ControlLock))) {
akError() << "Akonadi control process not found - aborting.";
akFatal() << "If you started akonadi_agent_server manually, try 'akonadictl start' instead.";
}
new Akonadi::AgentServer( &app );
new Akonadi::AgentServer(&app);
if ( !QDBusConnection::sessionBus().registerService( AkDBus::serviceName( AkDBus::AgentServer ) ) ) {
akFatal() << "Unable to connect to dbus service: " << QDBusConnection::sessionBus().lastError().message();
}
if (!QDBusConnection::sessionBus().registerService(AkDBus::serviceName(AkDBus::AgentServer))) {
akFatal() << "Unable to connect to dbus service: " << QDBusConnection::sessionBus().lastError().message();
}
return app.exec();
return app.exec();
}
......@@ -25,26 +25,26 @@
#include <QCoreApplication>
#include <QDebug>
int main( int argc, char **argv )
int main(int argc, char **argv)
{
AkCoreApplication app( argc, argv );
app.setDescription( QLatin1String( "Akonadi ASAP cat\n"
"This is a development tool, only use this if you know what you are doing.\n\n"
"Usage: asapcat [input]" ) );
boost::program_options::options_description options;
options.add_options()
( "input", boost::program_options::value<std::string>()->default_value( "-" ), "input to read commands from" );
app.addCommandLineOptions( options );
app.addPositionalCommandLineOption( "input", 1 );
app.parseCommandLine();
Session session( QString::fromStdString( app.commandLineArguments()["input"].as<std::string>() ) );
QObject::connect( &session, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()) );
QMetaObject::invokeMethod( &session, "connectToHost", Qt::QueuedConnection );
const int result = app.exec();
session.printStats();
return result;
AkCoreApplication app(argc, argv);
app.setDescription(QLatin1String("Akonadi ASAP cat\n"
"This is a development tool, only use this if you know what you are doing.\n\n"
"Usage: asapcat [input]"));
boost::program_options::options_description options;
options.add_options()
("input", boost::program_options::value<std::string>()->default_value("-"), "input to read commands from");
app.addCommandLineOptions(options);
app.addPositionalCommandLineOption("input", 1);
app.parseCommandLine();
Session session(QString::fromStdString(app.commandLineArguments()["input"].as<std::string>()));
QObject::connect(&session, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()));
QMetaObject::invokeMethod(&session, "connectToHost", Qt::QueuedConnection);
const int result = app.exec();
session.printStats();
return result;
}
......@@ -33,32 +33,32 @@
#include <fcntl.h>
#include <unistd.h>
Session::Session( const QString &input, QObject *parent )
: QObject( parent )
, m_input( 0 )
, m_session( 0 )
, m_notifier( 0 )
, m_receivedBytes( 0 )
, m_sentBytes( 0 )
Session::Session(const QString &input, QObject *parent)
: QObject(parent)
, m_input(0)
, m_session(0)
, m_notifier(0)
, m_receivedBytes(0)
, m_sentBytes(0)
{
QFile *file = new QFile( this );
if ( input != QLatin1String( "-" ) ) {
file->setFileName( input );
if ( !file->open( QFile::ReadOnly ) ) {
akFatal() << "Failed to open" << input;
QFile *file = new QFile(this);
if (input != QLatin1String("-")) {
file->setFileName(input);
if (!file->open(QFile::ReadOnly)) {
akFatal() << "Failed to open" << input;
}
} else {
// ### does that work on Windows?
const int flags = fcntl(0, F_GETFL);
fcntl(0, F_SETFL, flags | O_NONBLOCK);
if (!file->open(stdin, QFile::ReadOnly | QFile::Unbuffered)) {
akFatal() << "Failed to open stdin!";
}
m_notifier = new QSocketNotifier(0, QSocketNotifier::Read, this);
connect(m_notifier, SIGNAL(activated(int)), SLOT(inputAvailable()));
}
} else {
// ### does that work on Windows?
const int flags = fcntl( 0, F_GETFL );
fcntl( 0, F_SETFL, flags | O_NONBLOCK );
if ( !file->open( stdin, QFile::ReadOnly|QFile::Unbuffered ) ) {
akFatal() << "Failed to open stdin!";
}
m_notifier = new QSocketNotifier( 0, QSocketNotifier::Read, this );
connect( m_notifier, SIGNAL(activated(int)), SLOT(inputAvailable()) );
}
m_input = file;
m_input = file;
}
Session::~Session()
......@@ -67,87 +67,87 @@ Session::~Session()
void Session::connectToHost()
{
const QSettings connectionSettings( AkStandardDirs::connectionConfigFile(), QSettings::IniFormat );