#include #include "rdesktoplauncher.h" #include "x11helper.h" RDesktopLauncher::RDesktopLauncher(QObject *parent) : QObject(parent) , m_process(0) , m_windowLookUpTimer(0) { } void RDesktopLauncher::start(RdpOptions options) { if (m_process) { return; } QStringList args; args.append("-u"); args.append(options.username()); args.append("-p"); args.append(options.password()); args.append("-a"); args.append(QString("%1").arg((int)options.colors())); if (!options.fullscreen()) { args.append("-g"); QSize reso = options.resolution(); args.append(QString("%1x%2").arg(reso.width()).arg(reso.height())); } else { args.append("-f"); } if (options.bitmapCache()) { args.append("-P"); } if (!options.metaKeys()) { args.append("-K"); } if (options.useShell()) { args.append("-s"); args.append(options.shell()); args.append("-c"); args.append(options.shellWorkingDir()); } args.append("-k"); args.append(options.keymap()); args.append("-r"); args.append("clipboard:PRIMARYCLIPBOARD"); args.append("-r"); args.append("disk:rootfs=/"); args.append("-r"); args.append("sound:local:alsa"); if (!options.windowTitle().isEmpty()) { args.append("-T"); args.append(options.windowTitle()); } args.append(options.host()); m_options = options; m_process = new QProcess(this); connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onProcessFinished(int, QProcess::ExitStatus))); m_process->start("rdesktop", args); m_windowLookUpTimer = new QTimer(this); connect(m_windowLookUpTimer, SIGNAL(timeout()), this, SLOT(lookUpWindow())); m_windowLookUpTimer->start(500); } QString RDesktopLauncher::getExitStatusString(int status) { switch (status) { case 0: return tr("RDP session terminated normally"); case 1: return tr("Server initiated disconnect (also returned for logoff by XP joined to a domain)"); case 2: return tr("Server initiated logoff"); case 3: return tr("Server idle timeout reached"); case 4: return tr("Server logon timeout reached"); case 5: return tr("The session was replaced"); case 6: return tr("The server is out of memory"); case 7: return tr("The server denied the connection"); case 8: return tr("The server denied the connection for security reason"); case 9: return tr("The user cannot connect to the server due to insufficient access privileges"); case 10: return tr("The server does not accept saved user credentials and requires that the user enter their credentials for each connection"); case 11: return tr("Disconnect initiated by administration tool"); case 12: return tr("Disconnect initiated by user"); case 16: return tr("Internal licensing error"); case 17: return tr("No license server available"); case 18: return tr("No valid license available"); case 19: return tr("Invalid licensing message"); case 20: return tr("Hardware id doesn't match software license"); case 21: return tr("Client license error"); case 22: return tr("Network error during licensing protocol"); case 23: return tr("Licensing protocol was not completed"); case 24: return tr("Incorrect client license enryption"); case 25: return tr("Can't upgrade license"); case 26: return tr("The server is not licensed to accept remote connections"); case 62: return tr("The local client window was closed"); case 63: return tr("Some other, unknown error occured"); case 64: return tr("Command line usage error"); case 69: return tr("A service or resource (such as memory) is unavailable"); case 70: return tr("An internal software error has been detected"); case 71: return tr("Operating system error"); case 76: return tr("Protocol error or unable to connect to remote host"); default: return tr("Unknown error"); } } void RDesktopLauncher::kill() { clearWindowLookUpTimer(); if (m_process) { m_process->kill(); } } void RDesktopLauncher::onProcessFinished(int exitCode, QProcess::ExitStatus) { clearWindowLookUpTimer(); m_process->deleteLater(); m_process = 0; emit finished(exitCode); } void RDesktopLauncher::lookUpWindow() { QMap windows = X11Helper::getRootWindows(); QList keys = windows.keys(); for (int i = 0; i < keys.size(); ++i) { WId key = keys[i]; QString name = windows[key]; if (name.startsWith(m_options.windowTitle())) { clearWindowLookUpTimer(); emit windowFound(key); return; } } } void RDesktopLauncher::clearWindowLookUpTimer() { if (m_windowLookUpTimer) { m_windowLookUpTimer->stop(); m_windowLookUpTimer->deleteLater(); m_windowLookUpTimer = 0; } }