SVN_SILENT
[kdenetwork.git] / krdc / remoteview.cpp
blobfa7c48a52fb92a039579727df9109aa2e0546c97
1 /****************************************************************************
2 **
3 ** Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de>
4 ** Copyright (C) 2007 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 #include <QBitmap>
28 #include <KDebug>
29 #include <KStandardDirs>
31 RemoteView::RemoteView(QWidget *parent)
32 : QWidget(parent),
33 m_status(Disconnected),
34 m_host(QString()),
35 m_port(0),
36 m_viewOnly(false),
37 m_wallet(0),
38 m_dotCursorState(CursorOff)
42 RemoteView::RemoteStatus RemoteView::status()
44 return m_status;
47 void RemoteView::setStatus(RemoteView::RemoteStatus s)
49 if (m_status == s)
50 return;
52 if (((1 + (int)m_status) != (int)s) && (s != Disconnected)) {
53 // follow state transition rules
55 if (s == Disconnecting) {
56 if (m_status == Disconnected)
57 return;
58 } else {
59 Q_ASSERT(((int) s) >= 0);
60 if (((int)m_status) > ((int)s)) {
61 m_status = Disconnected;
62 emit statusChanged(Disconnected);
64 // smooth state transition
65 int origState = (int)m_status;
66 for (int i = origState; i < (int)s; i++) {
67 m_status = (RemoteStatus) i;
68 emit statusChanged((RemoteStatus) i);
72 m_status = s;
73 emit statusChanged(m_status);
76 RemoteView::~RemoteView()
80 bool RemoteView::supportsScaling() const
82 return false;
85 bool RemoteView::supportsLocalCursor() const
87 return false;
90 QString RemoteView::host()
92 return m_host;
95 QSize RemoteView::framebufferSize()
97 return QSize(0, 0);
100 void RemoteView::startQuitting()
104 bool RemoteView::isQuitting()
106 return false;
109 int RemoteView::port()
111 return m_port;
114 void RemoteView::keyEvent(QKeyEvent *)
118 bool RemoteView::viewOnly()
120 return m_viewOnly;
123 void RemoteView::setViewOnly(bool viewOnly)
125 m_viewOnly = viewOnly;
128 void RemoteView::showDotCursor(DotCursorState state)
130 m_dotCursorState = state;
133 RemoteView::DotCursorState RemoteView::dotCursorState() const
135 return m_dotCursorState;
138 bool RemoteView::scaling() const
140 return false;
143 void RemoteView::enableScaling(bool)
147 void RemoteView::switchFullscreen(bool)
151 KUrl RemoteView::url()
153 return m_url;
156 QString RemoteView::readWalletPassword()
158 QString krdc_folder = "KRDC";
160 m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), window()->winId());
162 if (m_wallet) {
163 bool walletOK = m_wallet->hasFolder(krdc_folder);
164 if (!walletOK) {
165 walletOK = m_wallet->createFolder(krdc_folder);
166 kDebug(5010) << "Wallet folder created";
168 if (walletOK) {
169 kDebug(5010) << "Wallet OK";
170 m_wallet->setFolder(krdc_folder);
171 QString password;
173 if (m_wallet->hasEntry(m_url.prettyUrl(KUrl::RemoveTrailingSlash)) &&
174 !m_wallet->readPassword(m_url.prettyUrl(KUrl::RemoveTrailingSlash), password)) {
175 kDebug(5010) << "Password read OK";
177 return password;
181 return QString();
184 void RemoteView::saveWalletPassword(const QString &password)
186 if (m_wallet && m_wallet->isOpen() && !m_wallet->hasEntry(m_url.prettyUrl(KUrl::RemoveTrailingSlash))) {
187 kDebug(5010) << "Write wallet password";
188 m_wallet->writePassword(m_url.prettyUrl(KUrl::RemoveTrailingSlash), password);
192 QCursor RemoteView::localDotCursor() const
194 QBitmap cursorBitmap(KGlobal::dirs()->findResource("appdata",
195 "pics/pointcursor.png"));
196 QBitmap cursorMask(KGlobal::dirs()->findResource("appdata",
197 "pics/pointcursormask.png"));
198 return QCursor(cursorBitmap, cursorMask);
201 #include "remoteview.moc"