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.


Minor compile warning fixup and error checks
[palacios.git] / linux_usr / gui / palacios / vnc_module / remoteview.cpp
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 #include "remoteview.h"
26
27 #ifndef QTONLY
28     #include <KDebug>
29     #include <KStandardDirs>
30 #endif
31
32 #include <QBitmap>
33
34 RemoteView::RemoteView(QWidget *parent)
35         : QWidget(parent),
36         m_status(Disconnected),
37         m_host(QString()),
38         m_port(0),
39         m_viewOnly(false),
40         m_grabAllKeys(false),
41         m_scale(false),
42         m_keyboardIsGrabbed(false),
43 #ifndef QTONLY
44         m_wallet(0),
45 #endif
46         m_dotCursorState(CursorOff)
47 {
48 }
49
50 RemoteView::~RemoteView()
51 {
52 #ifndef QTONLY
53     delete m_wallet;
54 #endif
55 }
56
57 RemoteView::RemoteStatus RemoteView::status()
58 {
59     return m_status;
60 }
61
62 void RemoteView::setStatus(RemoteView::RemoteStatus s)
63 {
64     if (m_status == s)
65         return;
66
67     if (((1+ m_status) != s) && (s != Disconnected)) {
68         // follow state transition rules
69
70         if (s == Disconnecting) {
71             if (m_status == Disconnected)
72                 return;
73         } else {
74             Q_ASSERT(((int) s) >= 0);
75             if (m_status > s) {
76                 m_status = Disconnected;
77                 emit statusChanged(Disconnected);
78             }
79             // smooth state transition
80             RemoteStatus origState = m_status;
81             for (int i = origState; i < s; ++i) {
82                 m_status = (RemoteStatus) i;
83                 emit statusChanged((RemoteStatus) i);
84             }
85         }
86     }
87     m_status = s;
88     emit statusChanged(m_status);
89 }
90
91 bool RemoteView::supportsScaling() const
92 {
93     return false;
94 }
95
96 bool RemoteView::supportsLocalCursor() const
97 {
98     return false;
99 }
100
101 QString RemoteView::host()
102 {
103     return m_host;
104 }
105
106 QSize RemoteView::framebufferSize()
107 {
108     return QSize(0, 0);
109 }
110
111 void RemoteView::startQuitting()
112 {
113 }
114
115 bool RemoteView::isQuitting()
116 {
117     return false;
118 }
119
120 int RemoteView::port()
121 {
122     return m_port;
123 }
124
125 void RemoteView::updateConfiguration()
126 {
127 }
128
129 void RemoteView::keyEvent(QKeyEvent *)
130 {
131 }
132
133 bool RemoteView::viewOnly()
134 {
135     return m_viewOnly;
136 }
137
138 void RemoteView::setViewOnly(bool viewOnly)
139 {
140     m_viewOnly = viewOnly;
141 }
142
143 bool RemoteView::grabAllKeys()
144 {
145     return m_grabAllKeys;
146 }
147
148 void RemoteView::setGrabAllKeys(bool grabAllKeys)
149 {
150     m_grabAllKeys = grabAllKeys;
151
152     if (grabAllKeys) {
153         m_keyboardIsGrabbed = true;
154         grabKeyboard();
155     } else if (m_keyboardIsGrabbed) {
156         releaseKeyboard();
157     }
158 }
159
160 QPixmap RemoteView::takeScreenshot() 
161 {
162     return QPixmap::grabWidget(this);
163 }
164
165 void RemoteView::showDotCursor(DotCursorState state)
166 {
167     m_dotCursorState = state;
168 }
169
170 RemoteView::DotCursorState RemoteView::dotCursorState() const
171 {
172     return m_dotCursorState;
173 }
174
175 bool RemoteView::scaling() const
176 {
177     return m_scale;
178 }
179
180 void RemoteView::enableScaling(bool scale)
181 {
182     m_scale = scale;
183 }
184
185 void RemoteView::switchFullscreen(bool)
186 {
187 }
188
189 void RemoteView::scaleResize(int, int)
190 {
191 }
192
193 KUrl RemoteView::url()
194 {
195     return m_url;
196 }
197
198 #ifndef QTONLY
199 QString RemoteView::readWalletPassword(bool fromUserNameOnly)
200 {
201     const QString KRDCFOLDER = "KRDC";
202
203     window()->setDisabled(true); // WORKAROUND: disable inputs so users cannot close the current tab (see #181230)
204     m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), window()->winId());
205     window()->setDisabled(false);
206
207     if (m_wallet) {
208         bool walletOK = m_wallet->hasFolder(KRDCFOLDER);
209         if (!walletOK) {
210             walletOK = m_wallet->createFolder(KRDCFOLDER);
211             kDebug(5010) << "Wallet folder created";
212         }
213         if (walletOK) {
214             kDebug(5010) << "Wallet OK";
215             m_wallet->setFolder(KRDCFOLDER);
216             QString password;
217             
218             QString key;
219             if (fromUserNameOnly)
220                 key = m_url.userName();
221             else
222                 key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
223
224             if (m_wallet->hasEntry(key) &&
225                     !m_wallet->readPassword(key, password)) {
226                 kDebug(5010) << "Password read OK";
227
228                 return password;
229             }
230         }
231     }
232     return QString();
233 }
234
235 void RemoteView::saveWalletPassword(const QString &password, bool fromUserNameOnly)
236 {
237     QString key;
238     if (fromUserNameOnly)
239         key = m_url.userName();
240     else
241         key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
242
243     if (m_wallet && m_wallet->isOpen()) {
244         kDebug(5010) << "Write wallet password";
245         m_wallet->writePassword(key, password);
246     }
247 }
248 #endif
249
250 QCursor RemoteView::localDotCursor() const
251 {
252 #ifdef QTONLY
253     return QCursor(); //TODO
254 #else
255     QBitmap cursorBitmap(KGlobal::dirs()->findResource("appdata",
256                                                        "pics/pointcursor.png"));
257     QBitmap cursorMask(KGlobal::dirs()->findResource("appdata",
258                                                      "pics/pointcursormask.png"));
259     return QCursor(cursorBitmap, cursorMask);
260 #endif
261 }
262
263 void RemoteView::focusInEvent(QFocusEvent *event)
264 {
265     if (m_grabAllKeys) {
266         m_keyboardIsGrabbed = true;
267         grabKeyboard();
268     }
269
270     QWidget::focusInEvent(event);
271 }
272
273 void RemoteView::focusOutEvent(QFocusEvent *event)
274 {
275     if (m_grabAllKeys || m_keyboardIsGrabbed) {
276         m_keyboardIsGrabbed = false;
277         releaseKeyboard();
278     }
279
280     QWidget::focusOutEvent(event);
281 }
282
283 #include "moc_remoteview.cpp"