Akonadi

agentwidgetbase.h
1/*
2 This file is part of akonadiresources.
3
4 SPDX-FileCopyrightText: 2006 Till Adam <adam@kde.org>
5 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
6 SPDX-FileCopyrightText: 2008 Kevin Krammer <kevin.krammer@gmx.at>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#pragma once
12
13#include "akonadiagentwidgetbase_export.h"
14
15#include <QApplication>
16#include <akonadi/agentbase.h>
17
18namespace Akonadi
19{
20
21class AKONADIAGENTWIDGETBASE_EXPORT AgentWidgetBase : public AgentBase
22{
23public:
24 /**
25 * Use this method in the main function of your agent
26 * application to initialize your agent subclass.
27 * This method also takes care of creating a QApplication
28 * object and parsing command line arguments.
29 *
30 * @note In case the given class is also derived from AgentBase::Observer
31 * it gets registered as its own observer (see AgentBase::Observer), e.g.
32 * <tt>agentInstance->registerObserver( agentInstance );</tt>
33 *
34 * @code
35 *
36 * class MyAgent : public AgentBase
37 * {
38 * ...
39 * };
40 *
41 * AKONADI_AGENT_MAIN( MyAgent )
42 *
43 * @endcode
44 *
45 * @param argc number of arguments
46 * @param argv arguments for the function
47 */
48 template<typename T>
49 static int init(int argc, char **argv)
50 {
51 // Disable session management
52 qunsetenv("SESSION_MANAGER");
53
54 QApplication app(argc, argv);
55 debugAgent(argc, argv);
56 const QString id = parseArguments(argc, argv);
57 T r(id);
58
59 // check if T also inherits AgentBase::Observer and
60 // if it does, automatically register it on itself
61 auto observer = dynamic_cast<Observer *>(&r);
62 if (observer != nullptr) {
63 r.registerObserver(observer);
64 }
65 r.initTheming();
66 return AgentBase::init(r);
67 }
68
69protected:
70 AgentWidgetBase(const QString &id);
71
72private:
73 void initTheming();
74};
75}
76
77#ifndef AKONADI_AGENT_MAIN
78/**
79 * Convenience Macro for the most common main() function for Akonadi agents.
80 */
81#define AKONADI_AGENT_MAIN(agentClass) \
82 int main(int argc, char **argv) \
83 { \
84 return Akonadi::AgentWidgetBase::init<agentClass>(argc, argv); \
85 }
86#endif
The base class for all Akonadi agents and resources.
Definition agentbase.h:74
Helper integration between Akonadi and Qt.
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:53:20 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.