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 ****************************************************************************/
25 #include "remoteview.h"
29 #include <KStandardDirs>
34 RemoteView::RemoteView(QWidget *parent)
36 m_status(Disconnected),
42 m_keyboardIsGrabbed(false),
46 m_dotCursorState(CursorOff)
50 RemoteView::~RemoteView()
57 RemoteView::RemoteStatus RemoteView::status()
62 void RemoteView::setStatus(RemoteView::RemoteStatus s)
67 if (((1+ m_status) != s) && (s != Disconnected)) {
68 // follow state transition rules
70 if (s == Disconnecting) {
71 if (m_status == Disconnected)
74 Q_ASSERT(((int) s) >= 0);
76 m_status = Disconnected;
77 emit statusChanged(Disconnected);
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);
88 emit statusChanged(m_status);
91 bool RemoteView::supportsScaling() const
96 bool RemoteView::supportsLocalCursor() const
101 QString RemoteView::host()
106 QSize RemoteView::framebufferSize()
111 void RemoteView::startQuitting()
115 bool RemoteView::isQuitting()
120 int RemoteView::port()
125 void RemoteView::updateConfiguration()
129 void RemoteView::keyEvent(QKeyEvent *)
133 bool RemoteView::viewOnly()
138 void RemoteView::setViewOnly(bool viewOnly)
140 m_viewOnly = viewOnly;
143 bool RemoteView::grabAllKeys()
145 return m_grabAllKeys;
148 void RemoteView::setGrabAllKeys(bool grabAllKeys)
150 m_grabAllKeys = grabAllKeys;
153 m_keyboardIsGrabbed = true;
155 } else if (m_keyboardIsGrabbed) {
160 QPixmap RemoteView::takeScreenshot()
162 return QPixmap::grabWidget(this);
165 void RemoteView::showDotCursor(DotCursorState state)
167 m_dotCursorState = state;
170 RemoteView::DotCursorState RemoteView::dotCursorState() const
172 return m_dotCursorState;
175 bool RemoteView::scaling() const
180 void RemoteView::enableScaling(bool scale)
185 void RemoteView::switchFullscreen(bool)
189 void RemoteView::scaleResize(int, int)
193 KUrl RemoteView::url()
199 QString RemoteView::readWalletPassword(bool fromUserNameOnly)
201 const QString KRDCFOLDER = "KRDC";
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);
208 bool walletOK = m_wallet->hasFolder(KRDCFOLDER);
210 walletOK = m_wallet->createFolder(KRDCFOLDER);
211 kDebug(5010) << "Wallet folder created";
214 kDebug(5010) << "Wallet OK";
215 m_wallet->setFolder(KRDCFOLDER);
219 if (fromUserNameOnly)
220 key = m_url.userName();
222 key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
224 if (m_wallet->hasEntry(key) &&
225 !m_wallet->readPassword(key, password)) {
226 kDebug(5010) << "Password read OK";
235 void RemoteView::saveWalletPassword(const QString &password, bool fromUserNameOnly)
238 if (fromUserNameOnly)
239 key = m_url.userName();
241 key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
243 if (m_wallet && m_wallet->isOpen()) {
244 kDebug(5010) << "Write wallet password";
245 m_wallet->writePassword(key, password);
250 QCursor RemoteView::localDotCursor() const
253 return QCursor(); //TODO
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);
263 void RemoteView::focusInEvent(QFocusEvent *event)
266 m_keyboardIsGrabbed = true;
270 QWidget::focusInEvent(event);
273 void RemoteView::focusOutEvent(QFocusEvent *event)
275 if (m_grabAllKeys || m_keyboardIsGrabbed) {
276 m_keyboardIsGrabbed = false;
280 QWidget::focusOutEvent(event);
283 #include "moc_remoteview.cpp"