Implement scaling of remote desktop for VNC protocol.
[kdenetwork.git] / krdc / remoteview.cpp
blob171047fdc400949d76350f7afe8b380a8d326563
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.
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 ****************************************************************************/
25 #include "remoteview.h"
27 #ifndef QTONLY
28 #include <KDebug>
29 #include <KStandardDirs>
30 #endif
32 #include <QBitmap>
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)
50 RemoteView::RemoteStatus RemoteView::status()
52 return m_status;
55 void RemoteView::setStatus(RemoteView::RemoteStatus s)
57 if (m_status == s)
58 return;
60 if (((1+ m_status) != s) && (s != Disconnected)) {
61 // follow state transition rules
63 if (s == Disconnecting) {
64 if (m_status == Disconnected)
65 return;
66 } else {
67 Q_ASSERT(((int) s) >= 0);
68 if (m_status > s) {
69 m_status = Disconnected;
70 emit statusChanged(Disconnected);
72 // smooth state transition
73 RemoteStatus origState = m_status;
74 for (int i = origState; i < s; i++) {
75 m_status = (RemoteStatus) i;
76 emit statusChanged((RemoteStatus) i);
80 m_status = s;
81 emit statusChanged(m_status);
84 RemoteView::~RemoteView()
88 bool RemoteView::supportsScaling() const
90 return false;
93 bool RemoteView::supportsLocalCursor() const
95 return false;
98 QString RemoteView::host()
100 return m_host;
103 QSize RemoteView::framebufferSize()
105 return QSize(0, 0);
108 void RemoteView::startQuitting()
112 bool RemoteView::isQuitting()
114 return false;
117 int RemoteView::port()
119 return m_port;
122 void RemoteView::keyEvent(QKeyEvent *)
126 bool RemoteView::viewOnly()
128 return m_viewOnly;
131 void RemoteView::setViewOnly(bool viewOnly)
133 m_viewOnly = viewOnly;
136 bool RemoteView::grabAllKeys()
138 return m_grabAllKeys;
141 void RemoteView::setGrabAllKeys(bool grabAllKeys)
143 m_grabAllKeys = grabAllKeys;
145 if (grabAllKeys) {
146 m_keyboardIsGrabbed = true;
147 grabKeyboard();
148 } else if (m_keyboardIsGrabbed) {
149 releaseKeyboard();
153 void RemoteView::showDotCursor(DotCursorState state)
155 m_dotCursorState = state;
158 RemoteView::DotCursorState RemoteView::dotCursorState() const
160 return m_dotCursorState;
163 bool RemoteView::scaling() const
165 return m_scale;
168 void RemoteView::enableScaling(bool scale)
170 m_scale = scale;
173 void RemoteView::switchFullscreen(bool)
177 KUrl RemoteView::url()
179 return m_url;
182 #ifndef QTONLY
183 QString RemoteView::readWalletPassword()
185 QString krdc_folder = "KRDC";
187 m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), window()->winId());
189 if (m_wallet) {
190 bool walletOK = m_wallet->hasFolder(krdc_folder);
191 if (!walletOK) {
192 walletOK = m_wallet->createFolder(krdc_folder);
193 kDebug(5010) << "Wallet folder created";
195 if (walletOK) {
196 kDebug(5010) << "Wallet OK";
197 m_wallet->setFolder(krdc_folder);
198 QString password;
200 if (m_wallet->hasEntry(m_url.prettyUrl(KUrl::RemoveTrailingSlash)) &&
201 !m_wallet->readPassword(m_url.prettyUrl(KUrl::RemoveTrailingSlash), password)) {
202 kDebug(5010) << "Password read OK";
204 return password;
208 return QString();
211 void RemoteView::saveWalletPassword(const QString &password)
213 if (m_wallet && m_wallet->isOpen() && !m_wallet->hasEntry(m_url.prettyUrl(KUrl::RemoveTrailingSlash))) {
214 kDebug(5010) << "Write wallet password";
215 m_wallet->writePassword(m_url.prettyUrl(KUrl::RemoveTrailingSlash), password);
218 #endif
220 QCursor RemoteView::localDotCursor() const
222 #ifdef QTONLY
223 return QCursor(); //TODO
224 #else
225 QBitmap cursorBitmap(KGlobal::dirs()->findResource("appdata",
226 "pics/pointcursor.png"));
227 QBitmap cursorMask(KGlobal::dirs()->findResource("appdata",
228 "pics/pointcursormask.png"));
229 return QCursor(cursorBitmap, cursorMask);
230 #endif
233 void RemoteView::focusInEvent(QFocusEvent *event)
235 if (m_grabAllKeys) {
236 m_keyboardIsGrabbed = true;
237 grabKeyboard();
240 QWidget::focusInEvent(event);
243 void RemoteView::focusOutEvent(QFocusEvent *event)
245 if (m_grabAllKeys || m_keyboardIsGrabbed) {
246 m_keyboardIsGrabbed = false;
247 releaseKeyboard();
250 QWidget::focusOutEvent(event);
253 #include "moc_remoteview.cpp"