KCoreAddons

kmessage.h
1 /*
2  This file is part of the KDE libraries
3 
4  SPDX-FileCopyrightText: 2006 Michaël Larouche <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-only
7 */
8 #ifndef KDECORE_KMESSAGE_H
9 #define KDECORE_KMESSAGE_H
10 
11 #include <kcoreaddons_export.h>
12 
13 #include <QString>
14 
15 class KMessageHandler;
16 /**
17  * @brief Display an informative message using a KMessageHandler.
18  *
19  * This class does not define how to display a message, it is just
20  * a clean interface for developers to use.
21  * The job is done by the current KMessageHandler set in the class.
22  *
23  * If no KMessageHandler is currently registered in KMessage,
24  * the message will be outputed to stderr.
25  *
26  * Use KMessage::setMessageHandler() to use a KMessageHandler.
27  *
28  * @code
29  * KMessage::setMessageHandler( new KMessageBoxHandler(this) );
30  * // some operation
31  *
32  * KMessage::message( KMessage::Error, i18n("Could not load service. Use kbuildsycoca to fix the service database."), i18n("KService") );
33  * @endcode
34  *
35  * Some KMessageHandler are already done such as KMessageBoxMessageHandler and KPassivePopupMessageHandler.
36  * @author Michaël Larouche <[email protected]>
37  */
38 namespace KMessage
39 {
41  /**
42  * Error message.
43  * Display critical information that affect the behavior of the application.
44  */
46  /**
47  * Information message.
48  * Display useful information to the user.
49  */
51  /**
52  * Warning message.
53  * Display a message that could affect the behavior of the application.
54  */
56  /**
57  * Sorry message.
58  * Display a message explaining that a task couldn't be accomplished.
59  */
61  /**
62  * Fatal message.
63  * Display a message before the application fail and close itself.
64  */
66 };
67 
68 /**
69  * @brief Display a long message of a certain type.
70  * A long message span on multiple lines and can have a caption.
71  *
72  * @param messageType Currrent type of message. See MessageType enum.
73  * @param text Long message to be displayed.
74  * @param caption Caption to be used. This is optional.
75  */
76 KCOREADDONS_EXPORT void message(KMessage::MessageType messageType, const QString &text, const QString &caption = QString());
77 
78 /**
79  * @brief Set the current KMessageHandler
80  * Note that this method takes ownership of the KMessageHandler.
81  * @param handler Instance of a real KMessageHandler.
82  *
83  * @warning This function isn't thread-safe. You don't want to
84  * change the message handler during the program's
85  * execution anyways. Do so <b>only</b> at start-up.
86  */
87 KCOREADDONS_EXPORT void setMessageHandler(KMessageHandler *handler);
88 }
89 
90 /**
91  * \class KMessageHandler kmessage.h <KMessageHandler>
92  *
93  * @brief Abstract class for KMessage handler.
94  * This class define how KMessage display a message.
95  *
96  * Reimplement the virtual methods then set your custom
97  * KMessageHandler using KMessage::setMessageHandler()
98  *
99  * @author Michaël Larouche <[email protected]>
100  */
101 class KCOREADDONS_EXPORT KMessageHandler
102 {
103 public:
104  virtual ~KMessageHandler()
105  {
106  } // KF6 TODO: de-inline (-Wweak-vtables)
107  /**
108  * @brief Display a long message of a certain type.
109  * A long message span on multiple lines and can have a caption.
110  *
111  * @param type Currrent type of message. See MessageType enum.
112  * @param text Long message to be displayed.
113  * @param caption Caption to be used. This is optional.
114  */
115  virtual void message(KMessage::MessageType type, const QString &text, const QString &caption) = 0;
116 };
117 
118 #endif
KCOREADDONS_EXPORT void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
Display a long message of a certain type.
Definition: kmessage.cpp:82
Information message.
Definition: kmessage.h:50
Display an informative message using a KMessageHandler.
Definition: kmessage.h:38
KCOREADDONS_EXPORT void setMessageHandler(KMessageHandler *handler)
Set the current KMessageHandler Note that this method takes ownership of the KMessageHandler.
Definition: kmessage.cpp:76
Error message.
Definition: kmessage.h:45
Sorry message.
Definition: kmessage.h:60
MessageType
Definition: kmessage.h:40
Warning message.
Definition: kmessage.h:55
Abstract class for KMessage handler.
Definition: kmessage.h:101
Fatal message.
Definition: kmessage.h:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 18 2021 23:02:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.