1 /****************************************************************************
3 ** Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de>
4 ** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
6 ** This file is part of KDE.
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 2 of the License, or
11 ** (at your option) any later version.
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; see the file COPYING. If not, write to
20 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ** Boston, MA 02110-1301, USA.
23 ****************************************************************************/
31 #define KRDCCORE_EXPORT
34 #include <KWallet/Wallet>
35 #include <krdc_export.h>
40 class HostPreferences;
43 * Generic widget that displays a remote framebuffer.
44 * Implement this if you want to add another backend.
46 * Things to take care of:
47 * @li The RemoteView is responsible for its size. In
48 * non-scaling mode, set the fixed size of the widget
49 * to the remote resolution. In scaling mode, set the
50 * maximum size to the remote size and minimum size to the
51 * smallest resolution that your scaler can handle.
52 * @li if you override mouseMoveEvent()
53 * you must ignore the QEvent, because the KRDC widget will
54 * need it for stuff like toolbar auto-hide and bump
55 * scrolling. If you use x11Event(), make sure that
56 * MotionNotify events will be forwarded.
59 class KRDCCORE_EXPORT RemoteView : public QWidget
75 * Describes the state of a local cursor, if there is such a concept in the backend.
76 * With local cursors, there are two cursors: the cursor on the local machine (client),
77 * and the cursor on the remote machine (server). Because there is usually some lag,
78 * some backends show both cursors simultanously. In the VNC backend the local cursor
79 * is a dot and the remote cursor is the 'real' cursor, usually an arrow.
82 Q_ENUMS(DotCursorState)
85 CursorOn, ///< Always show local cursor (and the remote one).
86 CursorOff, ///< Never show local cursor, only the remote one.
87 /// Try to measure the lag and enable the local cursor if the latency is too high.
92 * State of the connection. The state of the connection is returned
93 * by @ref RemoteView::status().
95 * Not every state transition is allowed. You are only allowed to transition
96 * a state to the following state, with three exceptions:
97 * @li You can move from every state directly to Disconnected
98 * @li You can move from every state except Disconnected to
100 * @li You can move from Disconnected to Connecting
102 * @ref RemoteView::setStatus() will follow this rules for you.
103 * (If you add/remove a state here, you must adapt it)
106 Q_ENUMS(RemoteStatus)
131 virtual ~RemoteView();
134 * Checks whether the backend supports scaling. The
135 * default implementation returns false.
136 * @return true if scaling is supported
139 virtual bool supportsScaling() const;
142 * Checks whether the widget is in scale mode. The
143 * default implementation always returns false.
144 * @return true if scaling is activated. Must always be
145 * false if @ref supportsScaling() returns false
146 * @see supportsScaling()
148 virtual bool scaling() const;
151 * Checks whether the backend supports the concept of local cursors. The
152 * default implementation returns false.
153 * @return true if local cursors are supported/known
154 * @see DotCursorState
155 * @see showDotCursor()
156 * @see dotCursorState()
158 virtual bool supportsLocalCursor() const;
161 * Sets the state of the dot cursor, if supported by the backend.
162 * The default implementation does nothing.
163 * @param state the new state (CursorOn, CursorOff or
165 * @see dotCursorState()
166 * @see supportsLocalCursor()
168 virtual void showDotCursor(DotCursorState state);
171 * Returns the state of the local cursor. The default implementation returns
173 * @return true if local cursors are supported/known
174 * @see showDotCursor()
175 * @see supportsLocalCursor()
177 virtual DotCursorState dotCursorState() const;
180 * Checks whether the view is in view-only mode. This means
181 * that all input is ignored.
183 virtual bool viewOnly();
186 * Checks whether grabbing all possible keys is enabled.
188 virtual bool grabAllKeys();
191 * Returns the resolution of the remote framebuffer.
192 * It should return a null @ref QSize when the size
194 * The backend must also emit a @ref framebufferSizeChanged()
195 * when the size of the framebuffer becomes available
196 * for the first time or the size changed.
197 * @return the remote framebuffer size, a null QSize
200 virtual QSize framebufferSize();
203 * Initiate the disconnection. This doesn't need to happen
204 * immediately. The call must not block.
207 virtual void startQuitting();
210 * Checks whether the view is currently quitting.
211 * @return true if it is quitting
212 * @see startQuitting()
215 virtual bool isQuitting();
218 * @return the host the view is connected to
220 virtual QString host();
223 * @return the port the view is connected to
228 * Initialize the view (for example by showing configuration
229 * dialogs to the user) and start connecting. Should not block
230 * without running the event loop (so displaying a dialog is ok).
231 * When the view starts connecting the application must call
232 * @ref setStatus() with the status Connecting.
233 * @return true if successful (so far), false
236 * @see disconnected()
237 * @see disconnectedError()
238 * @see statusChanged()
240 virtual bool start() = 0;
243 * Called when the configuration is changed.
244 * The default implementation does nothing.
246 virtual void updateConfiguration();
249 * @return screenshot of the view
251 virtual QPixmap takeScreenshot();
255 * Returns the current host preferences of this view.
257 virtual HostPreferences* hostPreferences() = 0;
261 * Returns the current status of the connection.
262 * @return the status of the connection
265 RemoteStatus status();
268 * @return the current url
274 * Called to enable or disable scaling.
275 * Ignored if @ref supportsScaling() is false.
276 * The default implementation does nothing.
277 * @param s true to enable, false to disable.
278 * @see supportsScaling()
281 virtual void enableScaling(bool scale);
284 * Enables/disables the view-only mode.
285 * Ignored if @ref supportsScaling() is false.
286 * The default implementation does nothing.
287 * @param viewOnly true to enable, false to disable.
288 * @see supportsScaling()
291 virtual void setViewOnly(bool viewOnly);
294 * Enables/disables grabbing all possible keys.
295 * @param grabAllKeys true to enable, false to disable.
299 virtual void setGrabAllKeys(bool grabAllKeys);
302 * Called to let the backend know it when
303 * we switch from/to fullscreen.
304 * @param on true when switching to fullscreen,
305 * false when switching from fullscreen.
307 virtual void switchFullscreen(bool on);
310 * Sends a QKeyEvent to the remote server.
311 * @param event the key to send
313 virtual void keyEvent(QKeyEvent *event);
316 * Called when the visible place changed so remote
317 * view can resize itself.
319 virtual void scaleResize(int w, int h);
323 * Emitted when the size of the remote screen changes. Also
324 * called when the size is known for the first time.
325 * @param x the width of the screen
326 * @param y the height of the screen
328 void framebufferSizeChanged(int w, int h);
331 * Emitted when the view connected successfully.
336 * Emitted when the view disconnected without error.
341 * Emitted when the view disconnected with error.
343 void disconnectedError();
346 * Emitted when the view has a specific error.
348 void errorMessage(const QString &title, const QString &message);
351 * Emitted when the status of the view changed.
352 * @param s the new status
354 void statusChanged(RemoteView::RemoteStatus s);
357 * Emitted when the password dialog is shown or hidden.
358 * @param b true when the dialog is shown, false when it has been hidden
360 void showingPasswordDialog(bool b);
363 * Emitted when the mouse on the remote side has been moved.
364 * @param x the new x coordinate
365 * @param y the new y coordinate
366 * @param buttonMask the mask of mouse buttons (bit 0 for first mouse
367 * button, 1 for second button etc)a
369 void mouseStateChanged(int x, int y, int buttonMask);
372 RemoteView(QWidget *parent = 0);
374 void focusInEvent(QFocusEvent *event);
375 void focusOutEvent(QFocusEvent *event);
378 * The status of the remote view.
380 RemoteStatus m_status;
383 * Set the status of the connection.
384 * Emits a statusChanged() signal.
385 * Note that the states need to be set in a certain order,
386 * see @ref Status. setStatus() will try to do this
387 * transition automatically, so if you are in Connecting
388 * and call setStatus(Preparing), setStatus() will
389 * emit a Authenticating and then Preparing.
390 * If you transition backwards, it will emit a
391 * Disconnected before doing the transition.
392 * @param s the new status
394 virtual void setStatus(RemoteStatus s);
396 QCursor localDotCursor() const;
403 bool m_keyboardIsGrabbed;
407 QString readWalletPassword(bool fromUserNameOnly = false);
408 void saveWalletPassword(const QString &password, bool fromUserNameOnly = false);
409 KWallet::Wallet *m_wallet;
412 DotCursorState m_dotCursorState;