1 /****************************************************************************
3 ** Copyright (C) 2002 Arend van Beelen jr. <arend@auton.nl>
4 ** Copyright (C) 2007 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 ****************************************************************************/
29 #include <KInputDialog>
30 #include <KMessageBox>
31 #include <KPasswordDialog>
33 #include <QX11EmbedContainer>
36 RdpView::RdpView(QWidget
*parent
,
38 const QString
&user
, const QString
&password
,
39 int flags
, const QString
&domain
,
40 const QString
&shell
, const QString
&directory
,
41 const QString
&caption
)
48 m_directory(directory
),
58 m_port
= TCP_PORT_RDP
;
61 m_container
= new QX11EmbedContainer(this);
62 m_container
->installEventFilter(this);
70 // filter out key and mouse events to the container if we are view only
71 //FIXME: X11 events are passed to the app before getting caught in the Qt event processing
72 bool RdpView::eventFilter(QObject
*obj
, QEvent
*event
)
75 if (event
->type() == QEvent::KeyPress
||
76 event
->type() == QEvent::KeyRelease
||
77 event
->type() == QEvent::MouseButtonDblClick
||
78 event
->type() == QEvent::MouseButtonPress
||
79 event
->type() == QEvent::MouseButtonRelease
||
80 event
->type() == QEvent::MouseMove
)
83 return RemoteView::eventFilter(obj
, event
);
86 QSize
RdpView::framebufferSize()
88 return m_container
->minimumSizeHint();
91 QSize
RdpView::sizeHint() const
96 void RdpView::startQuitting()
98 kDebug(5012) << "About to quit";
101 m_process
->terminate();
102 m_process
->waitForFinished(1000);
103 m_container
->discardClient();
107 bool RdpView::isQuitting()
112 bool RdpView::start()
114 m_hostPreferences
= new RdpHostPreferences(m_url
.prettyUrl(KUrl::RemoveTrailingSlash
), false, this);
117 m_container
->setWindowTitle(m_caption
);
119 if (m_hostPreferences
->walletSupport()) {
120 if (m_url
.userName().isEmpty()) {
124 userName
= KInputDialog::getText(i18n("Enter Username"),
125 i18n("Please enter the username you would like to use for login."),
126 QString(), &ok
, this);
129 m_url
.setUserName(userName
);
132 if (!m_url
.userName().isEmpty()) {
133 QString walletPassword
= readWalletPassword();
135 if (!walletPassword
.isNull())
136 m_url
.setPassword(walletPassword
);
138 KPasswordDialog
dialog(this);
139 dialog
.setPixmap(KIcon("dialog-password").pixmap(48));
140 dialog
.setPrompt(i18n("Access to the system requires a password."));
141 if (dialog
.exec() == KPasswordDialog::Accepted
) {
142 m_url
.setPassword(dialog
.password());
144 if (m_hostPreferences
->walletSupport())
145 saveWalletPassword(dialog
.password());
151 m_process
= new QProcess(m_container
);
153 QStringList arguments
;
154 arguments
<< "-g" << (QString::number(m_hostPreferences
->width()) + 'x' +
155 QString::number(m_hostPreferences
->height()));
156 arguments
<< "-k" << m_hostPreferences
->keyboardLayout();
158 if (!m_url
.userName().isEmpty())
159 arguments
<< "-u" << m_url
.userName();
160 else if (!Settings::sendCurrentUserName())
161 arguments
<< "-u" << "";
163 if (!m_url
.password().isNull())
164 arguments
<< "-p" << m_url
.password();
166 arguments
<< "-X" << QString::number(m_container
->winId());
167 arguments
<< "-a" << QString::number((m_hostPreferences
->colorDepth() + 1) * 8);
170 switch (m_hostPreferences
->sound()) {
181 arguments
<< "-r" << "sound:" + sound
;
183 if (!m_hostPreferences
->extraOptions().isEmpty()) {
184 QStringList additionalArguments
= m_hostPreferences
->extraOptions().split(' ');
185 arguments
+= additionalArguments
;
188 arguments
<< (m_host
+ ':' + QString::number(m_port
));
190 kDebug(5012) << arguments
;
192 setStatus(Connecting
);
194 connect(m_process
, SIGNAL(error(QProcess::ProcessError
)), SLOT(processError(QProcess::ProcessError
)));
195 connect(m_process
, SIGNAL(readyReadStandardError()), SLOT(receivedStandardError()));
196 connect(m_container
, SIGNAL(clientClosed()), SLOT(connectionClosed()));
197 connect(m_container
, SIGNAL(clientIsEmbedded()), SLOT(connectionOpened()));
199 m_process
->start("rdesktop", arguments
);
204 void RdpView::switchFullscreen(bool on
)
207 m_container
->grabKeyboard();
211 void RdpView::connectionOpened()
213 kDebug(5012) << "Connection opened";
214 QSize size
= m_container
->minimumSizeHint();
215 kDebug(5012) << "Size hint: " << size
.width() << " " << size
.height();
216 setStatus(Connected
);
219 m_container
->setFixedSize(size
);
220 emit
changeSize(size
.width(), size
.height());
225 void RdpView::connectionClosed()
228 setStatus(Disconnected
);
232 void RdpView::processError(QProcess::ProcessError error
)
234 if (m_status
== Connecting
) {
235 setStatus(Disconnected
);
237 if (error
== QProcess::FailedToStart
) {
238 KMessageBox::error(0, i18n("Could not start rdesktop; make sure rdesktop is properly installed."),
239 i18n("rdesktop Failure"));
243 if (m_clientVersion
.isEmpty()) {
244 KMessageBox::error(0, i18n("Connection attempt to host failed."),
245 i18n("Connection Failure"));
247 KMessageBox::error(0, i18n("The version of rdesktop you are using (%1) is too old:\n"
248 "rdesktop 1.3.2 or greater is required.", m_clientVersion
),
249 i18n("rdesktop Failure"));
251 emit
disconnectedError();
255 void RdpView::receivedStandardError()
257 QString
output(m_process
->readAllStandardError());
260 while (!(line
= output
.section('\n', i
, i
)).isEmpty()) {
261 if (line
.startsWith("Version ")) {
262 m_clientVersion
= line
.section(' ', 1, 1);
263 m_clientVersion
= m_clientVersion
.left(m_clientVersion
.length() - 1);
266 kDebug(5012) << "Process error output: " << line
;
272 #include "rdpview.moc"