Greatly improve experience for LDAP (e.g. MS Active Directory) administrators.
[kdenetwork.git] / krdc / remoteview.cpp
blob267f1d438f15fa1989ca4d2f7885d9b48232fcd9
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::~RemoteView()
52 #ifndef QTONLY
53 delete m_wallet;
54 #endif
57 RemoteView::RemoteStatus RemoteView::status()
59 return m_status;
62 void RemoteView::setStatus(RemoteView::RemoteStatus s)
64 if (m_status == s)
65 return;
67 if (((1+ m_status) != s) && (s != Disconnected)) {
68 // follow state transition rules
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);
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);
87 m_status = s;
88 emit statusChanged(m_status);
91 bool RemoteView::supportsScaling() const
93 return false;
96 bool RemoteView::supportsLocalCursor() const
98 return false;
101 QString RemoteView::host()
103 return m_host;
106 QSize RemoteView::framebufferSize()
108 return QSize(0, 0);
111 void RemoteView::startQuitting()
115 bool RemoteView::isQuitting()
117 return false;
120 int RemoteView::port()
122 return m_port;
125 void RemoteView::updateConfiguration()
129 void RemoteView::keyEvent(QKeyEvent *)
133 bool RemoteView::viewOnly()
135 return m_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;
152 if (grabAllKeys) {
153 m_keyboardIsGrabbed = true;
154 grabKeyboard();
155 } else if (m_keyboardIsGrabbed) {
156 releaseKeyboard();
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
172 return m_scale;
175 void RemoteView::enableScaling(bool scale)
177 m_scale = scale;
180 void RemoteView::switchFullscreen(bool)
184 void RemoteView::scaleResize(int, int)
188 KUrl RemoteView::url()
190 return m_url;
193 #ifndef QTONLY
194 QString RemoteView::readWalletPassword(bool fromUserNameOnly)
196 const QString KRDCFOLDER = "KRDC";
198 m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), window()->winId());
200 if (m_wallet) {
201 bool walletOK = m_wallet->hasFolder(KRDCFOLDER);
202 if (!walletOK) {
203 walletOK = m_wallet->createFolder(KRDCFOLDER);
204 kDebug(5010) << "Wallet folder created";
206 if (walletOK) {
207 kDebug(5010) << "Wallet OK";
208 m_wallet->setFolder(KRDCFOLDER);
209 QString password;
211 QString key;
212 if (fromUserNameOnly)
213 key = m_url.userName();
214 else
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";
221 return password;
225 return QString();
228 void RemoteView::saveWalletPassword(const QString &password, bool fromUserNameOnly)
230 QString key;
231 if (fromUserNameOnly)
232 key = m_url.userName();
233 else
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);
241 #endif
243 QCursor RemoteView::localDotCursor() const
245 #ifdef QTONLY
246 return QCursor(); //TODO
247 #else
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);
253 #endif
256 void RemoteView::focusInEvent(QFocusEvent *event)
258 if (m_grabAllKeys) {
259 m_keyboardIsGrabbed = true;
260 grabKeyboard();
263 QWidget::focusInEvent(event);
266 void RemoteView::focusOutEvent(QFocusEvent *event)
268 if (m_grabAllKeys || m_keyboardIsGrabbed) {
269 m_keyboardIsGrabbed = false;
270 releaseKeyboard();
273 QWidget::focusOutEvent(event);
276 #ifndef QTONLY
277 #include "moc_remoteview.cpp"
278 #endif