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.1KB

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