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 void RemoteView::showDotCursor(DotCursorState state)
162 m_dotCursorState = state;
165 RemoteView::DotCursorState RemoteView::dotCursorState() const
167 return m_dotCursorState;
170 bool RemoteView::scaling() const
175 void RemoteView::enableScaling(bool scale)
180 void RemoteView::switchFullscreen(bool)
184 void RemoteView::scaleResize(int, int)
188 KUrl RemoteView::url()
194 QString RemoteView::readWalletPassword(bool fromUserNameOnly)
196 const QString KRDCFOLDER = "KRDC";
198 window()->setDisabled(true); // WORKAROUND: disable inputs so users cannot close the current tab (see #181230)
199 m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), window()->winId());
200 window()->setDisabled(false);
203 bool walletOK = m_wallet->hasFolder(KRDCFOLDER);
205 walletOK = m_wallet->createFolder(KRDCFOLDER);
206 kDebug(5010) << "Wallet folder created";
209 kDebug(5010) << "Wallet OK";
210 m_wallet->setFolder(KRDCFOLDER);
214 if (fromUserNameOnly)
215 key = m_url.userName();
217 key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
219 if (m_wallet->hasEntry(key) &&
220 !m_wallet->readPassword(key, password)) {
221 kDebug(5010) << "Password read OK";
230 void RemoteView::saveWalletPassword(const QString &password, bool fromUserNameOnly)
233 if (fromUserNameOnly)
234 key = m_url.userName();
236 key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
238 if (m_wallet && m_wallet->isOpen()) {
239 kDebug(5010) << "Write wallet password";
240 m_wallet->writePassword(key, password);
245 QCursor RemoteView::localDotCursor() const
247 //we take care of this in paintEvent()
248 return QCursor(Qt::BlankCursor);
251 void RemoteView::focusInEvent(QFocusEvent *event)
254 m_keyboardIsGrabbed = true;
258 QWidget::focusInEvent(event);
261 void RemoteView::focusOutEvent(QFocusEvent *event)
263 if (m_grabAllKeys || m_keyboardIsGrabbed) {
264 m_keyboardIsGrabbed = false;
268 QWidget::focusOutEvent(event);
271 #include "moc_remoteview.cpp"