30 #include <KInputDialog>
31 #include <KMessageBox>
32 #include <KPasswordDialog>
35 #include <QX11EmbedContainer>
40 KConfigGroup configGroup,
41 const QString &user,
const QString &password)
56 m_container =
new QX11EmbedContainer(
this);
57 m_container->installEventFilter(
this);
72 if (event->type() == QEvent::KeyPress ||
73 event->type() == QEvent::KeyRelease ||
74 event->type() == QEvent::MouseButtonDblClick ||
75 event->type() == QEvent::MouseButtonPress ||
76 event->type() == QEvent::MouseButtonRelease ||
77 event->type() == QEvent::MouseMove)
80 return RemoteView::eventFilter(obj, event);
85 return m_container->minimumSizeHint();
95 kDebug(5012) <<
"About to quit";
98 m_process->terminate();
99 m_process->waitForFinished(1000);
100 m_container->discardClient();
113 if (
m_url.userName().isEmpty()) {
117 userName = KInputDialog::getText(i18n(
"Enter Username"),
118 i18n(
"Please enter the username you would like to use for login."),
122 m_url.setUserName(userName);
126 if (!
m_url.userName().isEmpty()) {
128 kDebug(5012) <<
"Is LDAP login:" << useLdapLogin <<
m_url.userName();
130 QString walletPassword = QString();
134 if (!walletPassword.isNull()) {
135 m_url.setPassword(walletPassword);
137 KPasswordDialog dialog(
this);
138 dialog.setPrompt(i18n(
"Access to the system requires a password."));
139 if (dialog.exec() == KPasswordDialog::Accepted) {
140 m_url.setPassword(dialog.password());
149 m_process =
new QProcess(m_container);
151 QStringList arguments;
154 if (m_hostPreferences->
width() > 0) {
155 width = m_hostPreferences->
width();
156 height = m_hostPreferences->
height();
158 width = this->parentWidget()->size().width();
159 height = this->parentWidget()->size().height();
161 arguments <<
"-g" << QString::number(width) +
'x' + QString::number(height);
163 arguments <<
"-k" << keymapToXfreerdp(m_hostPreferences->
keyboardLayout());
165 if (!
m_url.userName().isEmpty()) {
167 if (
m_url.userName().contains(
'\\')) {
168 const QStringList splittedName =
m_url.userName().split(
'\\');
169 arguments <<
"-d" << splittedName.at(0);
170 arguments <<
"-u" << splittedName.at(1);
172 arguments <<
"-u" <<
m_url.userName();
175 arguments <<
"-u" <<
"";
178 if (!
m_url.password().isNull())
179 arguments <<
"-p" <<
m_url.password();
182 arguments <<
"-X" << QString::number(m_container->winId());
183 arguments <<
"-a" << QString::number((m_hostPreferences->
colorDepth() + 1) * 8);
185 switch (m_hostPreferences->
sound()) {
190 arguments <<
"--plugin" <<
"rdpsnd";
197 if (!m_hostPreferences->
shareMedia().isEmpty()) {
198 QStringList shareMedia;
199 shareMedia <<
"--plugin" <<
"rdpdr" <<
"--data" <<
"disk:media:" + m_hostPreferences->
shareMedia() <<
"--";
200 arguments += shareMedia;
218 arguments <<
"-x" << performance;
220 if (m_hostPreferences->
console()) {
224 if (m_hostPreferences->
remoteFX()) {
225 arguments <<
"--rfx";
229 const QStringList additionalArguments = KShell::splitArgs(m_hostPreferences->
extraOptions());
230 arguments += additionalArguments;
236 arguments <<
"--ignore-certificate";
239 arguments <<
"--plugin" <<
"cliprdr";
241 arguments <<
"-t" << QString::number(
m_port);
244 kDebug(5012) <<
"Starting xfreerdp with arguments:" << arguments;
248 connect(m_process, SIGNAL(error(QProcess::ProcessError)), SLOT(processError(QProcess::ProcessError)));
249 connect(m_process, SIGNAL(readyReadStandardError()), SLOT(receivedStandardError()));
250 connect(m_process, SIGNAL(readyReadStandardOutput()), SLOT(receivedStandardOutput()));
251 connect(m_container, SIGNAL(clientClosed()), SLOT(connectionClosed()));
252 connect(m_container, SIGNAL(clientIsEmbedded()), SLOT(connectionOpened()));
254 m_process->start(
"xfreerdp", arguments);
261 return m_hostPreferences;
267 m_container->grabKeyboard();
271 void RdpView::connectionOpened()
273 kDebug(5012) <<
"Connection opened";
274 const QSize size = m_container->minimumSizeHint();
275 kDebug(5012) <<
"Size hint: " << size.width() <<
" " << size.height();
279 m_container->setFixedSize(size);
287 return QPixmap::grabWindow(m_container->clientWinId());
290 void RdpView::connectionClosed()
297 void RdpView::connectionError()
303 void RdpView::processError(QProcess::ProcessError error)
305 kDebug(5012) <<
"processError:" << error;
310 if (error == QProcess::FailedToStart) {
311 KMessageBox::error(0, i18n(
"Could not start \"xfreerdp\"; make sure xfreerdp is properly installed."),
312 i18n(
"RDP Failure"));
319 void RdpView::receivedStandardError()
321 const QString output(m_process->readAllStandardError());
322 kDebug(5012) <<
"receivedStandardError:" << output;
325 while (!(line = output.section(
'\n', i, i)).isEmpty()) {
334 if (line.contains(QLatin1String(
"X_ReparentWindow"))) {
335 KMessageBox::error(0, i18n(
"The version of \"xfreerdp\" you are using is too old.\n"
336 "xfreerdp 1.0.2 or greater is required."),
337 i18n(
"RDP Failure"));
345 void RdpView::receivedStandardOutput()
347 const QString output(m_process->readAllStandardOutput());
348 kDebug(5012) <<
"receivedStandardOutput:" << output;
351 while (!(line = output.section(
'\n', i, i)).isEmpty()) {
354 if (line.contains(QLatin1String(
"Name or service not known"))) {
355 KMessageBox::error(0, i18n(
"Name or service not known."),
356 i18n(
"Connection Failure"));
361 }
else if (line.contains(QLatin1String(
"unable to connect to"))) {
362 KMessageBox::error(0, i18n(
"Connection attempt to host failed."),
363 i18n(
"Connection Failure"));
369 }
else if (line.contains(QLatin1String(
"Error: protocol security negotiation failure"))) {
370 KMessageBox::error(0, i18n(
"Connection attempt to host failed."),
371 i18n(
"Connection Failure"));
382 Q_UNUSED(grabAllKeys);
386 QString RdpView::keymapToXfreerdp(
const QString &keyboadLayout)
397 QHash<QString, QString> RdpView::initKeymapToXfreerdp()
402 keymapToXfreerdpHash[
"ar"] =
"0x00000401";
405 keymapToXfreerdpHash[
"cs"] =
"0x00000405";
406 keymapToXfreerdpHash[
"da"] =
"0x00000406";
407 keymapToXfreerdpHash[
"fo"] =
"0x00000406";
408 keymapToXfreerdpHash[
"de"] =
"0x00000407";
410 keymapToXfreerdpHash[
"en-us"] =
"0x00000409";
411 keymapToXfreerdpHash[
"es"] =
"0x0000040A";
412 keymapToXfreerdpHash[
"fi"] =
"0x0000040B";
413 keymapToXfreerdpHash[
"fr"] =
"0x0000040C";
414 keymapToXfreerdpHash[
"he"] =
"0x0000040D";
415 keymapToXfreerdpHash[
"hu"] =
"0x0000040E";
416 keymapToXfreerdpHash[
"is"] =
"0x0000040F";
417 keymapToXfreerdpHash[
"it"] =
"0x00000410";
418 keymapToXfreerdpHash[
"ja"] =
"0x00000411";
419 keymapToXfreerdpHash[
"ko"] =
"0x00000412";
420 keymapToXfreerdpHash[
"nl"] =
"0x00000413";
421 keymapToXfreerdpHash[
"no"] =
"0x00000414";
422 keymapToXfreerdpHash[
"pl"] =
"0x00000415";
423 keymapToXfreerdpHash[
"pt-br"] =
"0x00000416";
425 keymapToXfreerdpHash[
"ru"] =
"0x00000419";
426 keymapToXfreerdpHash[
"hr"] =
"0x0000041A";
429 keymapToXfreerdpHash[
"sv"] =
"0x0000041D";
430 keymapToXfreerdpHash[
"th"] =
"0x0000041E";
431 keymapToXfreerdpHash[
"tr"] =
"0x0000041F";
435 keymapToXfreerdpHash[
"sl"] =
"0x00000424";
436 keymapToXfreerdpHash[
"et"] =
"0x00000425";
437 keymapToXfreerdpHash[
"lv"] =
"0x00000426";
438 keymapToXfreerdpHash[
"lt"] =
"0x00000427";
443 keymapToXfreerdpHash[
"mk"] =
"0x0000042F";
469 keymapToXfreerdpHash[
"de-ch"] =
"0x00000807";
470 keymapToXfreerdpHash[
"en-gb"] =
"0x00000809";
472 keymapToXfreerdpHash[
"fr-be"] =
"0x0000080C";
473 keymapToXfreerdpHash[
"nl-be"] =
"0x00000813";
474 keymapToXfreerdpHash[
"pt"] =
"0x00000816";
482 keymapToXfreerdpHash[
"fr-ca"] =
"0x00001009";
483 keymapToXfreerdpHash[
"fr-ch"] =
"0x0000100C";
494 keymapToXfreerdpHash[
"en-dv"] =
"0x00010409";
555 #include "rdpview.moc"
HostPreferences * hostPreferences()
Returns the current host preferences of this view.
virtual bool start()
Initialize the view (for example by showing configuration dialogs to the user) and start connecting...
bool eventFilter(QObject *obj, QEvent *event)
QString keyboardLayout() const
QString readWalletPassword(bool fromUserNameOnly=false)
void connected()
Emitted when the view connected successfully.
void disconnectedError()
Emitted when the view disconnected with error.
Generic widget that displays a remote framebuffer.
void disconnected()
Emitted when the view disconnected without error.
void framebufferSizeChanged(int w, int h)
Emitted when the size of the remote screen changes.
virtual QSize framebufferSize()
Returns the resolution of the remote framebuffer.
virtual bool isQuitting()
Checks whether the view is currently quitting.
virtual QPixmap takeScreenshot()
int height()
Saved height.
static QString defaultRdpUserName()
Get DefaultRdpUserName.
static bool recognizeLdapLogins()
Get RecognizeLdapLogins.
virtual void switchFullscreen(bool on)
static QHash< QString, QString > keymapToXfreerdpHash
void saveWalletPassword(const QString &password, bool fromUserNameOnly=false)
RemoteStatus m_status
The status of the remote view.
RdpView(QWidget *parent=0, const KUrl &url=KUrl(), KConfigGroup configGroup=KConfigGroup(), const QString &user=QString(), const QString &password=QString())
QString shareMedia() const
virtual void startQuitting()
Initiate the disconnection.
virtual void setStatus(RemoteStatus s)
Set the status of the connection.
void setGrabAllKeys(bool grabAllKeys)
Enables/disables grabbing all possible keys.
QString extraOptions() const