1/*
2* Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU Lesser General Public License as published by
6* the Free Software Foundation; either version 2.1 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU Lesser General Public License
15* along with this program; if not, write to the
16* Free Software Foundation, Inc.,
17* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
18*/
19
20#ifndef HELPER_SUPPORT_H
21#define HELPER_SUPPORT_H
22
23#include <QtCore/QObject>
24#include <QtCore/QVariant>
25
26#include <kdecore_export.h>
27
28#define KDE4_AUTH_HELPER_MAIN(ID, HelperClass) \
29 int main(int argc, char **argv) { return KAuth::HelperSupport::helperMain(argc, argv, ID, new HelperClass()); }
30
31namespace KAuth
32{
33
34/**
35 * @brief Support class with some KDECORE_EXPORT methods useful to the helper's code
36 *
37 * This class provides the API to write the helper tool that executes your actions.
38 * You don't create instances of HelperSupport. Instead, you use its KDECORE_EXPORT methods.
39 *
40 * This them you can notify the application of progress in your action's execution
41 * and you can check if the application asked you to terminate it.
42 *
43 * @since 4.4
44 */
45namespace HelperSupport
46{
47/**
48 * @brief Send a progressStep signal to the caller application
49 *
50 * You can use this method to notify progress information about the
51 * action execution. When you call this method, the ActionWatcher
52 * object associated with the current action will emit the progressStep(int)
53 * signal. The meaning of the integer passed here is totally application dependent,
54 * but you'll want to use it as a sort of percentage.
55 * If you need to be more expressive, use the other overload which takes a QVariantMap
56 *
57 * @param step The progress indicator
58 */
59KDECORE_EXPORT void progressStep(int step);
60
61/**
62* @brief Send a progressStep signal to the caller application
63*
64* You can use this method to notify progress information about the
65* action execution. When you call this method, the ActionWatcher
66* object associated with the current action will emit the progressStep(QVariantMap)
67* signal. The meaning of the data passed here is totally application dependent.
68* If you only need a simple percentage value, use the other overload which takes an int.
69*
70* @param data The progress data
71*/
72KDECORE_EXPORT void progressStep(const QVariantMap &data);
73
74/**
75 * @brief Check if the caller asked the helper to stop the execution
76 *
77 * This method will return true if the helper has been asked to stop the
78 * execution of the current action. If this happens, your helper should
79 * return (NOT exit). The meaning of the data you return in this case is
80 * application-dependent.
81 * It's good practice to check it regularly if you have a long-running action
82 *
83 * @return true if the helper has been asked to stop, false otherwise
84 */
85KDECORE_EXPORT bool isStopped();
86
87
88/**
89 * @brief Method that implements the main function of the helper tool. Do not call directly
90 *
91 * This method is called in the proper way by the code generated by the KDE4_AUTH_HELPER_MAIN(),
92 * which creates a main() function for the helper tool.
93 * macro. You shouldn't call this method directly.
94 *
95 * @param argc The argc parameter from the main() function.
96 * @param argv The argv parameter from the main() function.
97 * @param id The helper ID as passed to the macro
98 * @param responder The responder object for the helper. The macro passes a default-constructed,
99 * heap-allocated object of the class specified as the last macro parameter
100 */
101KDECORE_EXPORT int helperMain(int argc, char **argv, const char *id, QObject *responder);
102} // namespace HelperSupport
103
104} // namespace Auth
105
106#endif
107