1 | /* |
2 | Copyright (c) 2010 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 "agentthread.h" |
21 | |
22 | #include <QtCore/QCoreApplication> |
23 | #include <QtCore/QDebug> |
24 | #include <QtCore/QPluginLoader> |
25 | #include <QWidget> // Needed for WId |
26 | |
27 | #include <shared/akdebug.h> |
28 | #include <qmetaobject.h> |
29 | |
30 | using namespace Akonadi; |
31 | |
32 | AgentThread::AgentThread(const QString &identifier, QObject *factory, QObject *parent) |
33 | : QThread(parent) |
34 | , m_identifier(identifier) |
35 | , m_factory(factory) |
36 | , m_instance(0) |
37 | { |
38 | } |
39 | |
40 | void AgentThread::run() |
41 | { |
42 | const bool invokeSucceeded = QMetaObject::invokeMethod(m_factory, |
43 | "createInstance" , |
44 | Qt::DirectConnection, |
45 | Q_RETURN_ARG(QObject *, m_instance), |
46 | Q_ARG(QString, m_identifier)); |
47 | if (invokeSucceeded) { |
48 | qDebug() << Q_FUNC_INFO << "agent instance created: " << m_instance; |
49 | } else { |
50 | qDebug() << Q_FUNC_INFO << "agent instance creation failed" ; |
51 | } |
52 | |
53 | exec(); |
54 | delete m_instance; |
55 | } |
56 | |
57 | void AgentThread::configure(qlonglong windowId) |
58 | { |
59 | QMetaObject::invokeMethod(m_instance, |
60 | "configure" , |
61 | Qt::DirectConnection, |
62 | Q_ARG(WId, (WId)windowId)); |
63 | } |
64 | |