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 m_wallet
= KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), window()->winId());
201 bool walletOK
= m_wallet
->hasFolder(KRDCFOLDER
);
203 walletOK
= m_wallet
->createFolder(KRDCFOLDER
);
204 kDebug(5010) << "Wallet folder created";
207 kDebug(5010) << "Wallet OK";
208 m_wallet
->setFolder(KRDCFOLDER
);
212 if (fromUserNameOnly
)
213 key
= m_url
.userName();
215 key
= m_url
.prettyUrl(KUrl::RemoveTrailingSlash
);
217 if (m_wallet
->hasEntry(key
) &&
218 !m_wallet
->readPassword(key
, password
)) {
219 kDebug(5010) << "Password read OK";
228 void RemoteView::saveWalletPassword(const QString
&password
, bool fromUserNameOnly
)
231 if (fromUserNameOnly
)
232 key
= m_url
.userName();
234 key
= m_url
.prettyUrl(KUrl::RemoveTrailingSlash
);
236 if (m_wallet
&& m_wallet
->isOpen() && !m_wallet
->hasEntry(key
) {
237 kDebug(5010) << "Write wallet password";
238 m_wallet
->writePassword(key
, password
);
243 QCursor
RemoteView::localDotCursor() const
246 return QCursor(); //TODO
248 QBitmap
cursorBitmap(KGlobal::dirs()->findResource("appdata",
249 "pics/pointcursor.png"));
250 QBitmap
cursorMask(KGlobal::dirs()->findResource("appdata",
251 "pics/pointcursormask.png"));
252 return QCursor(cursorBitmap
, cursorMask
);
256 void RemoteView::focusInEvent(QFocusEvent
*event
)
259 m_keyboardIsGrabbed
= true;
263 QWidget::focusInEvent(event
);
266 void RemoteView::focusOutEvent(QFocusEvent
*event
)
268 if (m_grabAllKeys
|| m_keyboardIsGrabbed
) {
269 m_keyboardIsGrabbed
= false;
273 QWidget::focusOutEvent(event
);
277 #include "moc_remoteview.cpp"