Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Palacios GUI Added
[palacios.git] / linux_usr / gui / palacios / vnc_module / remoteview.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de>
4 ** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
5 **
6 ** This file is part of KDE.
7 **
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.
12 **
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.
17 **
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.
22 **
23 ****************************************************************************/
24
25 #ifndef REMOTEVIEW_H
26 #define REMOTEVIEW_H
27
28 #ifdef QTONLY
29     #include <QUrl>
30     #define KUrl QUrl
31     #define KRDCCORE_EXPORT
32 #else
33     #include <KUrl>
34     #include <KWallet/Wallet>
35     #include <krdc_export.h>
36 #endif
37
38 #include <QWidget>
39
40 class HostPreferences;
41
42 /**
43  * Generic widget that displays a remote framebuffer.
44  * Implement this if you want to add another backend.
45  *
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.
57  *
58  */
59 class KRDCCORE_EXPORT RemoteView : public QWidget
60 {
61     Q_OBJECT
62
63 public:
64
65     Q_ENUMS(Quality)
66
67     enum Quality {
68         Unknown,
69         High,
70         Medium,
71         Low
72     };
73
74     /**
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.
80     */
81
82     Q_ENUMS(DotCursorState)
83
84     enum 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.
88         CursorAuto
89     };
90
91     /**
92     * State of the connection. The state of the connection is returned
93     * by @ref RemoteView::status().
94     *
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
99     *     Disconnecting
100     * @li You can move from Disconnected to Connecting
101     *
102     * @ref RemoteView::setStatus() will follow this rules for you.
103     * (If you add/remove a state here, you must adapt it)
104     */
105
106     Q_ENUMS(RemoteStatus)
107
108     enum RemoteStatus {
109         Connecting     = 0,
110         Authenticating = 1,
111         Preparing      = 2,
112         Connected      = 3,
113         Disconnecting  = -1,
114         Disconnected   = -2
115     };
116
117     Q_ENUMS(ErrorCode)
118
119     enum ErrorCode {
120         Nonne = 0,
121         Internal,
122         Connection,
123         Protocol,
124         IO,
125         Name,
126         NoServer,
127         ServerBlocked,
128         Authentication
129     };
130
131     virtual ~RemoteView();
132
133     /**
134      * Checks whether the backend supports scaling. The
135      * default implementation returns false.
136      * @return true if scaling is supported
137      * @see scaling()
138      */
139     virtual bool supportsScaling() const;
140
141     /**
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()
147      */
148     virtual bool scaling() const;
149
150     /**
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()
157      */
158     virtual bool supportsLocalCursor() const;
159
160     /**
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
164      *        CursorAuto)
165      * @see dotCursorState()
166      * @see supportsLocalCursor()
167      */
168     virtual void showDotCursor(DotCursorState state);
169
170     /**
171      * Returns the state of the local cursor. The default implementation returns
172      * always CursorOff.
173      * @return true if local cursors are supported/known
174      * @see showDotCursor()
175      * @see supportsLocalCursor()
176      */
177     virtual DotCursorState dotCursorState() const;
178
179     /**
180      * Checks whether the view is in view-only mode. This means
181      * that all input is ignored.
182      */
183     virtual bool viewOnly();
184
185     /**
186      * Checks whether grabbing all possible keys is enabled.
187      */
188     virtual bool grabAllKeys();
189
190     /**
191      * Returns the resolution of the remote framebuffer.
192      * It should return a null @ref QSize when the size
193      * is not known.
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
198      *         if unknown
199      */
200     virtual QSize framebufferSize();
201
202     /**
203      * Initiate the disconnection. This doesn't need to happen
204      * immediately. The call must not block.
205      * @see isQuitting()
206      */
207     virtual void startQuitting();
208
209     /**
210      * Checks whether the view is currently quitting.
211      * @return true if it is quitting
212      * @see startQuitting()
213      * @see setStatus()
214      */
215     virtual bool isQuitting();
216
217     /**
218      * @return the host the view is connected to
219      */
220     virtual QString host();
221
222     /**
223      * @return the port the view is connected to
224      */
225     virtual int port();
226
227     /**
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
234      *         otherwise
235      * @see connected()
236      * @see disconnected()
237      * @see disconnectedError()
238      * @see statusChanged()
239      */
240     virtual bool start() = 0;
241     
242     /**
243      * Called when the configuration is changed.
244      * The default implementation does nothing.
245      */
246     virtual void updateConfiguration();
247     
248     /**
249      * @return screenshot of the view
250      */
251     virtual QPixmap takeScreenshot();
252     
253 #ifndef QTONLY
254     /**
255      * Returns the current host preferences of this view.
256      */
257     virtual HostPreferences* hostPreferences() = 0;
258 #endif
259     
260     /**
261      * Returns the current status of the connection.
262      * @return the status of the connection
263      * @see setStatus()
264      */
265     RemoteStatus status();
266
267     /**
268      * @return the current url
269      */
270     KUrl url();
271
272 public slots:
273     /**
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()
279      * @see scaling()
280      */
281     virtual void enableScaling(bool scale);
282
283     /**
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()
289      * @see viewOnly()
290      */
291     virtual void setViewOnly(bool viewOnly);
292
293     /**
294      * Enables/disables grabbing all possible keys.
295      * @param grabAllKeys true to enable, false to disable.
296      * Default is false.
297      * @see grabAllKeys()
298      */
299     virtual void setGrabAllKeys(bool grabAllKeys);
300
301     /**
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.
306      */
307     virtual void switchFullscreen(bool on);
308
309     /**
310      * Sends a QKeyEvent to the remote server.
311      * @param event the key to send
312      */
313     virtual void keyEvent(QKeyEvent *event);
314
315     /**
316      * Called when the visible place changed so remote
317      * view can resize itself.
318      */
319     virtual void scaleResize(int w, int h);
320
321 signals:
322     /**
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
327      */
328     void framebufferSizeChanged(int w, int h);
329
330     /**
331      * Emitted when the view connected successfully.
332      */
333     void connected();
334
335     /**
336      * Emitted when the view disconnected without error.
337      */
338     void disconnected();
339
340     /**
341      * Emitted when the view disconnected with error.
342      */
343     void disconnectedError();
344
345     /**
346      * Emitted when the view has a specific error.
347      */
348     void errorMessage(const QString &title, const QString &message);
349  
350     /**
351      * Emitted when the status of the view changed.
352      * @param s the new status
353         */
354     void statusChanged(RemoteView::RemoteStatus s);
355
356     /**
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
359      */
360     void showingPasswordDialog(bool b);
361
362     /**
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
368      */
369     void mouseStateChanged(int x, int y, int buttonMask);
370
371 protected:
372     RemoteView(QWidget *parent = 0);
373
374     void focusInEvent(QFocusEvent *event);
375     void focusOutEvent(QFocusEvent *event);
376
377     /**
378      * The status of the remote view.
379      */
380     RemoteStatus m_status;
381
382     /**
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
393      */
394     virtual void setStatus(RemoteStatus s);
395
396     QCursor localDotCursor() const;
397
398     QString m_host;
399     int m_port;
400     bool m_viewOnly;
401     bool m_grabAllKeys;
402     bool m_scale;
403     bool m_keyboardIsGrabbed;
404     KUrl m_url;
405
406 #ifndef QTONLY
407     QString readWalletPassword(bool fromUserNameOnly = false);
408     void saveWalletPassword(const QString &password, bool fromUserNameOnly = false);
409     KWallet::Wallet *m_wallet;
410 #endif
411
412     DotCursorState m_dotCursorState;
413 };
414
415 #endif