1/****************************************************************************
2
3 Copyright (C) 2001-2003 Lubos Lunak <l.lunak@kde.org>
4
5Permission is hereby granted, free of charge, to any person obtaining a
6copy of this software and associated documentation files (the "Software"),
7to deal in the Software without restriction, including without limitation
8the rights to use, copy, modify, merge, publish, distribute, sublicense,
9and/or sell copies of the Software, and to permit persons to whom the
10Software is furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21DEALINGS IN THE SOFTWARE.
22
23****************************************************************************/
24
25#ifndef KXMESSAGES_H
26#define KXMESSAGES_H
27
28#include <kdeui_export.h>
29#include <QtGui/QWidget>
30#include <QtCore/QMap>
31#ifdef Q_WS_X11
32#include <X11/X.h>
33
34class QString;
35
36class KXMessagesPrivate;
37/**
38 * Sending string messages to other applications using the X Client Messages.
39 *
40 * Used internally by KStartupInfo. You usually don't want to use this, use DBUS
41 * instead.
42 *
43 * @author Lubos Lunak <l.lunak@kde.org>
44 */
45// KDE4 - make this internal for KStartupInfo only?
46class KDEUI_EXPORT KXMessages
47 : public QWidget
48 {
49 Q_OBJECT
50 public:
51 /**
52 * Creates an instance which will receive X messages.
53 *
54 * @param accept_broadcast if non-NULL, all broadcast messages with
55 * this message type will be received.
56 * @param parent the parent of this widget
57 * @param obsolete always set to false (needed for backwards compatibility
58 * with KDE3.1 and older)
59 */
60 KXMessages( const char* accept_broadcast, QWidget* parent, bool obsolete );
61 /**
62 * @deprecated
63 * This method is equivalent to the other constructor with obsolete = true.
64 */
65 explicit KXMessages( const char* accept_broadcast = NULL, QWidget* parent = NULL );
66
67 virtual ~KXMessages();
68 /**
69 * Sends the given message with the given message type only to given
70 * window.
71 *
72 * @param w X11 handle for the destination window
73 * @param msg_type the type of the message
74 * @param message the message itself
75 * @param obsolete always set to false (needed for backwards compatibility
76 * with KDE3.1 and older)
77 */
78 void sendMessage( WId w, const char* msg_type, const QString& message,
79 bool obsolete );
80 /**
81 * @deprecated
82 * This method is equivalent to sendMessage() with obsolete = true.
83 */
84 void sendMessage( WId w, const char* msg_type, const QString& message );
85 /**
86 * Broadcasts the given message with the given message type.
87 * @param msg_type the type of the message
88 * @param message the message itself
89 * @param screen X11 screen to use, -1 for the default
90 * @param obsolete always set to false (needed for backwards compatibility
91 * with KDE3.1 and older)
92 */
93 void broadcastMessage( const char* msg_type, const QString& message,
94 int screen, bool obsolete );
95 /**
96 * @deprecated
97 * This method is equivalent to broadcastMessage() with obsolete = true.
98 */
99 void broadcastMessage( const char* msg_type, const QString& message );
100
101 /**
102 * Sends the given message with the given message type only to given
103 * window.
104 *
105 * @param disp X11 connection which will be used instead of
106 * qt_x11display()
107 * @param w X11 handle for the destination window
108 * @param msg_type the type of the message
109 * @param message the message itself
110 * @param obsolete always set to false (needed for backwards compatibility
111 * with KDE3.1 and older)
112 * @return false when an error occurred, true otherwise
113 */
114 static bool sendMessageX( Display* disp, WId w, const char* msg_type,
115 const QString& message, bool obsolete );
116 /**
117 * @deprecated
118 * This method is equivalent to sendMessageX() with obsolete = true.
119 */
120 static bool sendMessageX( Display* disp, WId w, const char* msg_type,
121 const QString& message );
122
123 /**
124 * Broadcasts the given message with the given message type.
125 *
126 * @param disp X11 connection which will be used instead of
127 * qt_x11display()
128 * @param msg_type the type of the message
129 * @param message the message itself
130 * @param screen X11 screen to use, -1 for the default
131 * @param obsolete always set to false (needed for backwards compatibility
132 * with KDE3.1 and older)
133 * @return false when an error occurred, true otherwise
134 */
135 static bool broadcastMessageX( Display* disp, const char* msg_type,
136 const QString& message, int screen, bool obsolete );
137 /**
138 * @deprecated
139 * This method is equivalent to broadcastMessageX() with obsolete = true.
140 */
141 static bool broadcastMessageX( Display* disp, const char* msg_type,
142 const QString& message );
143 Q_SIGNALS:
144 /**
145 * Emitted when a message was received.
146 * @param message the message that has been received
147 */
148 void gotMessage( const QString& message );
149 protected:
150 /**
151 * @internal
152 */
153 virtual bool x11Event( XEvent* ev );
154 private:
155 static void send_message_internal( WId w_P, const QString& msg_P, long mask_P,
156 Display* disp, Atom atom1_P, Atom atom2_P, Window handle_P );
157 KXMessagesPrivate * const d;
158 };
159
160#endif
161#endif
162
163