You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rdesktoplauncher.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include <QStringList>
  2. #include "rdesktoplauncher.h"
  3. #include "x11helper.h"
  4. #include <QDebug>
  5. RDesktopLauncher::RDesktopLauncher(QObject *parent)
  6. : QObject(parent)
  7. , m_process(0)
  8. , m_windowLookUpTimer(0)
  9. {
  10. }
  11. void RDesktopLauncher::start(RdpOptions options)
  12. {
  13. if (m_process) {
  14. return;
  15. }
  16. QStringList args;
  17. args.append("-u");
  18. args.append(options.username());
  19. args.append("-p");
  20. args.append(options.password());
  21. args.append("-a");
  22. args.append(QString("%1").arg((int)options.colors()));
  23. if (!options.fullscreen())
  24. {
  25. args.append("-g");
  26. QSize reso = options.resolution();
  27. args.append(QString("%1x%2").arg(reso.width()).arg(reso.height()));
  28. }
  29. else
  30. {
  31. args.append("-f");
  32. }
  33. if (options.bitmapCache())
  34. {
  35. args.append("-P");
  36. }
  37. if (!options.metaKeys())
  38. {
  39. args.append("-K");
  40. }
  41. if (options.useShell())
  42. {
  43. args.append("-s");
  44. args.append(options.shell());
  45. args.append("-c");
  46. args.append(options.shellWorkingDir());
  47. }
  48. args.append("-k");
  49. args.append(options.keymap());
  50. args.append("-r");
  51. args.append("clipboard:PRIMARYCLIPBOARD");
  52. args.append("-r");
  53. args.append("disk:rootfs=/");
  54. args.append("-r");
  55. args.append("sound:local:alsa");
  56. if (!options.windowTitle().isEmpty()) {
  57. args.append("-T");
  58. args.append(options.windowTitle());
  59. }
  60. args.append(options.host());
  61. m_options = options;
  62. m_process = new QProcess(this);
  63. connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onProcessFinished(int, QProcess::ExitStatus)));
  64. m_process->start("rdesktop", args);
  65. m_windowLookUpTimer = new QTimer(this);
  66. connect(m_windowLookUpTimer, SIGNAL(timeout()), this, SLOT(lookUpWindow()));
  67. m_windowLookUpTimer->start(500);
  68. }
  69. QString RDesktopLauncher::getExitStatusString(int status)
  70. {
  71. switch (status) {
  72. case 0:
  73. return tr("RDP session terminated normally");
  74. case 1:
  75. return tr("Server initiated disconnect (also returned for logoff by XP joined to a domain)");
  76. case 2:
  77. return tr("Server initiated logoff");
  78. case 3:
  79. return tr("Server idle timeout reached");
  80. case 4:
  81. return tr("Server logon timeout reached");
  82. case 5:
  83. return tr("The session was replaced");
  84. case 6:
  85. return tr("The server is out of memory");
  86. case 7:
  87. return tr("The server denied the connection");
  88. case 8:
  89. return tr("The server denied the connection for security reason");
  90. case 9:
  91. return tr("The user cannot connect to the server due to insufficient access privileges");
  92. case 10:
  93. return tr("The server does not accept saved user credentials and requires that the user enter their credentials for each connection");
  94. case 11:
  95. return tr("Disconnect initiated by administration tool");
  96. case 12:
  97. return tr("Disconnect initiated by user");
  98. case 16:
  99. return tr("Internal licensing error");
  100. case 17:
  101. return tr("No license server available");
  102. case 18:
  103. return tr("No valid license available");
  104. case 19:
  105. return tr("Invalid licensing message");
  106. case 20:
  107. return tr("Hardware id doesn't match software license");
  108. case 21:
  109. return tr("Client license error");
  110. case 22:
  111. return tr("Network error during licensing protocol");
  112. case 23:
  113. return tr("Licensing protocol was not completed");
  114. case 24:
  115. return tr("Incorrect client license enryption");
  116. case 25:
  117. return tr("Can't upgrade license");
  118. case 26:
  119. return tr("The server is not licensed to accept remote connections");
  120. case 62:
  121. return tr("The local client window was closed");
  122. case 63:
  123. return tr("Some other, unknown error occured");
  124. case 64:
  125. return tr("Command line usage error");
  126. case 69:
  127. return tr("A service or resource (such as memory) is unavailable");
  128. case 70:
  129. return tr("An internal software error has been detected");
  130. case 71:
  131. return tr("Operating system error");
  132. case 76:
  133. return tr("Protocol error or unable to connect to remote host");
  134. default:
  135. return tr("Unknown error");
  136. }
  137. }
  138. void RDesktopLauncher::kill()
  139. {
  140. clearWindowLookUpTimer();
  141. if (m_process) {
  142. m_process->kill();
  143. }
  144. }
  145. void RDesktopLauncher::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
  146. {
  147. clearWindowLookUpTimer();
  148. m_process->deleteLater();
  149. m_process = 0;
  150. emit finished(exitCode);
  151. }
  152. void RDesktopLauncher::lookUpWindow()
  153. {
  154. QMap<WId, QString> windows = X11Helper::getRootWindows();
  155. QList<WId> keys = windows.keys();
  156. for (int i = 0; i < keys.size(); ++i) {
  157. WId key = keys[i];
  158. QString name = windows[key];
  159. if (name.startsWith(m_options.windowTitle())) {
  160. clearWindowLookUpTimer();
  161. emit windowFound(key);
  162. return;
  163. }
  164. }
  165. }
  166. void RDesktopLauncher::clearWindowLookUpTimer()
  167. {
  168. if (m_windowLookUpTimer) {
  169. m_windowLookUpTimer->stop();
  170. m_windowLookUpTimer->deleteLater();
  171. m_windowLookUpTimer = 0;
  172. }
  173. }