Sync Mk with ports
[dports.git] / net / krdc / files / patch-git8436cc62
1 --- rdp/rdpview.cpp
2 +++ rdp/rdpview.cpp
3 @@ -146,102 +146,205 @@ bool RdpView::start()
4          }
5      }
6  
7 +    // Check the version of FreeRDP so we can use pre-1.1 switches if needed
8 +    QProcess *xfreeRDPVersionCheck = new QProcess(this);
9 +    xfreeRDPVersionCheck->start("xfreerdp", QStringList("--version"));
10 +    xfreeRDPVersionCheck->waitForFinished();
11 +    QString versionOutput = xfreeRDPVersionCheck->readAllStandardOutput();
12 +    xfreeRDPVersionCheck->deleteLater();
13 +
14      m_process = new QProcess(m_container);
15  
16      QStringList arguments;
17  
18 -    int width, height;
19 -    if (m_hostPreferences->width() > 0) {
20 -        width = m_hostPreferences->width();
21 -        height = m_hostPreferences->height();
22 -    } else {
23 -        width = this->parentWidget()->size().width();
24 -        height = this->parentWidget()->size().height();
25 -    }
26 -    arguments << "-g" << QString::number(width) + 'x' + QString::number(height);
27 -
28 -    arguments << "-k" << keymapToXfreerdp(m_hostPreferences->keyboardLayout());
29 +    if (versionOutput.contains(QLatin1String(" 1.0"))) {
30 +        kDebug(5012) << "Use FreeRDP 1.0 compatible arguments";
31  
32 -    if (!m_url.userName().isEmpty()) {
33 -        // if username contains a domain, it needs to be set with another parameter
34 -        if (m_url.userName().contains('\\')) {
35 -            const QStringList splittedName = m_url.userName().split('\\');
36 -            arguments << "-d" << splittedName.at(0);
37 -            arguments << "-u" << splittedName.at(1);
38 +        int width, height;
39 +        if (m_hostPreferences->width() > 0) {
40 +            width = m_hostPreferences->width();
41 +            height = m_hostPreferences->height();
42          } else {
43 -            arguments << "-u" << m_url.userName();
44 +            width = this->parentWidget()->size().width();
45 +            height = this->parentWidget()->size().height();
46          }
47 +        arguments << "-g" << QString::number(width) + 'x' + QString::number(height);
48 +
49 +        arguments << "-k" << keymapToXfreerdp(m_hostPreferences->keyboardLayout());
50 +
51 +        if (!m_url.userName().isEmpty()) {
52 +            // if username contains a domain, it needs to be set with another parameter
53 +            if (m_url.userName().contains('\\')) {
54 +                const QStringList splittedName = m_url.userName().split('\\');
55 +                arguments << "-d" << splittedName.at(0);
56 +                arguments << "-u" << splittedName.at(1);
57 +            } else {
58 +                arguments << "-u" << m_url.userName();
59 +            }
60 +        } else {
61 +            arguments << "-u" << "";
62 +        }
63 +
64 +        arguments << "-D";  // request the window has no decorations
65 +        arguments << "-X" << QString::number(m_container->winId());
66 +        arguments << "-a" << QString::number((m_hostPreferences->colorDepth() + 1) * 8);
67 +
68 +        switch (m_hostPreferences->sound()) {
69 +        case 1:
70 +            arguments << "-o";
71 +            break;
72 +        case 0:
73 +            arguments << "--plugin" << "rdpsnd";
74 +            break;
75 +        case 2:
76 +        default:
77 +            break;
78 +        }
79 +
80 +        if (!m_hostPreferences->shareMedia().isEmpty()) {
81 +            QStringList shareMedia;
82 +            shareMedia << "--plugin" << "rdpdr" << "--data" << "disk:media:" + m_hostPreferences->shareMedia() << "--";
83 +            arguments += shareMedia;
84 +        }
85 +
86 +        QString performance;
87 +        switch (m_hostPreferences->performance()) {
88 +        case 0:
89 +            performance = 'm';
90 +            break;
91 +        case 1:
92 +            performance = 'b';
93 +            break;
94 +        case 2:
95 +            performance = 'l';
96 +            break;
97 +        default:
98 +            break;
99 +        }
100 +
101 +        arguments << "-x" << performance;
102 +
103 +        if (m_hostPreferences->console()) {
104 +            arguments << "-0";
105 +        }
106 +
107 +        if (m_hostPreferences->remoteFX()) {
108 +            arguments << "--rfx";
109 +        }
110 +
111 +        if (!m_hostPreferences->extraOptions().isEmpty()) {
112 +            const QStringList additionalArguments = KShell::splitArgs(m_hostPreferences->extraOptions());
113 +            arguments += additionalArguments;
114 +        }
115 +
116 +        // krdc has no support for certificate management yet; it would not be possbile to connect to any host:
117 +        // "The host key for example.com has changed" ...
118 +        // "Add correct host key in ~/.freerdp/known_hosts to get rid of this message."
119 +        arguments << "--ignore-certificate";
120 +
121 +        // clipboard sharing is activated in KRDC; user can disable it at runtime
122 +        arguments << "--plugin" << "cliprdr";
123 +
124 +        arguments << "-t" << QString::number(m_port);
125 +        arguments << m_host;
126 +
127 +        kDebug(5012) << "Starting xfreerdp with arguments: " << arguments.join(" ");
128 +
129 +        arguments.removeLast(); // host must be last, remove and re-add it after the password
130 +        if (!m_url.password().isNull())
131 +            arguments << "-p" << m_url.password();
132 +        arguments << m_host;
133 +
134      } else {
135 -        arguments << "-u" << "";
136 -    }
137 +        kDebug(5012) << "Use FreeRDP 1.1+ compatible arguments";
138  
139 -    if (!m_url.password().isNull())
140 -        arguments << "-p" << m_url.password();
141 -
142 -    arguments << "-D";  // request the window has no decorations
143 -    arguments << "-X" << QString::number(m_container->winId());
144 -    arguments << "-a" << QString::number((m_hostPreferences->colorDepth() + 1) * 8);
145 -
146 -    switch (m_hostPreferences->sound()) {
147 -    case 1:
148 -        arguments << "-o";
149 -        break;
150 -    case 0:
151 -        arguments << "--plugin" << "rdpsnd";
152 -        break;
153 -    case 2:
154 -    default:
155 -        break;
156 -    }
157 +        int width, height;
158 +        if (m_hostPreferences->width() > 0) {
159 +            width = m_hostPreferences->width();
160 +            height = m_hostPreferences->height();
161 +        } else {
162 +            width = this->parentWidget()->size().width();
163 +            height = this->parentWidget()->size().height();
164 +        }
165 +        arguments << "-decorations";
166 +        arguments << "/w:" + QString::number(width);
167 +        arguments << "/h:" + QString::number(height);
168 +
169 +        arguments << "/kbd:" + keymapToXfreerdp(m_hostPreferences->keyboardLayout());
170 +
171 +        if (!m_url.userName().isEmpty()) {
172 +            // if username contains a domain, it needs to be set with another parameter
173 +            if (m_url.userName().contains('\\')) {
174 +                const QStringList splittedName = m_url.userName().split('\\');
175 +                arguments << "/d:" + splittedName.at(0);
176 +                arguments << "/u:" + splittedName.at(1);
177 +            } else {
178 +                arguments << "/u:" + m_url.userName();
179 +            }
180 +        } else {
181 +            arguments << "/u:";
182 +        }
183  
184 -    if (!m_hostPreferences->shareMedia().isEmpty()) {
185 -        QStringList shareMedia;
186 -        shareMedia << "--plugin" << "rdpdr" << "--data" << "disk:media:" + m_hostPreferences->shareMedia() << "--";
187 -        arguments += shareMedia;
188 -    }
189 +        arguments << "/parent-window:" + QString::number(m_container->winId());
190 +        arguments << "/bpp:" + QString::number((m_hostPreferences->colorDepth() + 1) * 8);
191 +        arguments << "/audio-mode:" + QString::number(m_hostPreferences->sound());
192  
193 -    QString performance;
194 -    switch (m_hostPreferences->performance()) {
195 -    case 0:
196 -        performance = 'm';
197 -        break;
198 -    case 1:
199 -        performance = 'b';
200 -        break;
201 -    case 2:
202 -        performance = 'l';
203 -        break;
204 -    default:
205 -        break;
206 -    }
207 +        if (!m_hostPreferences->shareMedia().isEmpty()) {
208 +            QStringList shareMedia;
209 +            shareMedia << "/drive:media," + m_hostPreferences->shareMedia();
210 +            arguments += shareMedia;
211 +        }
212  
213 -    arguments << "-x" << performance;
214 +        QString performance;
215 +        switch (m_hostPreferences->performance()) {
216 +        case 0:
217 +            performance = "modem";
218 +            break;
219 +        case 1:
220 +            performance = "broadband";
221 +            break;
222 +        case 2:
223 +            performance = "lan";
224 +            break;
225 +        default:
226 +            break;
227 +        }
228  
229 -    if (m_hostPreferences->console()) {
230 -        arguments << "-0";
231 -    }
232 +        arguments << "/network:" + performance;
233  
234 -    if (m_hostPreferences->remoteFX()) {
235 -        arguments << "--rfx";
236 -    }
237 +        if (m_hostPreferences->console()) {
238 +            arguments << "/admin";
239 +        }
240  
241 -    if (!m_hostPreferences->extraOptions().isEmpty()) {
242 -        const QStringList additionalArguments = KShell::splitArgs(m_hostPreferences->extraOptions());
243 -        arguments += additionalArguments;
244 -    }
245 +        if (m_hostPreferences->remoteFX()) {
246 +            arguments << "/rfx";
247 +        }
248 +
249 +        if (!m_hostPreferences->extraOptions().isEmpty()) {
250 +            const QStringList additionalArguments = KShell::splitArgs(m_hostPreferences->extraOptions());
251 +            arguments += additionalArguments;
252 +        }
253 +
254 +        // krdc has no support for certificate management yet; it would not be possbile to connect to any host:
255 +        // "The host key for example.com has changed" ...
256 +        // "Add correct host key in ~/.freerdp/known_hosts to get rid of this message."
257 +        arguments << "/cert-ignore";
258 +
259 +        // clipboard sharing is activated in KRDC; user can disable it at runtime
260 +        arguments << "+clipboard";
261  
262 -    // krdc has no support for certificate management yet; it would not be possbile to connect to any host:
263 -    // "The host key for example.com has changed" ...
264 -    // "Add correct host key in ~/.freerdp/known_hosts to get rid of this message."
265 -    arguments << "--ignore-certificate";
266 +        arguments << "/port:" + QString::number(m_port);
267 +        arguments << "/v:" + m_host;
268  
269 -    // clipboard sharing is activated in KRDC; user can disable it at runtime
270 -    arguments << "--plugin" << "cliprdr";
271 +        kDebug(5012) << "Starting xfreerdp with arguments: " << arguments.join(" ");
272  
273 -    arguments << "-t" << QString::number(m_port);
274 -    arguments << m_host;
275 +        //avoid printing the password in debug
276 +        if (!m_url.password().isNull()) {
277 +            arguments << "/p:" + m_url.password();
278 +        }
279 +        kDebug(5012) << "Starting xfreerdp with arguments: " << arguments.join(" ");
280  
281 -    kDebug(5012) << "Starting xfreerdp with arguments:" << arguments;
282 +    }
283  
284      setStatus(Connecting);
285  
286 @@ -302,7 +405,7 @@ void RdpView::connectionError()
287  
288  void RdpView::processError(QProcess::ProcessError error)
289  {
290 -    kDebug(5012) << "processError:" << error;
291 +    kDebug(5012) << error;
292      if (m_quitFlag) // do not try to show error messages while quitting (prevent crashes)
293          return;
294  
295 @@ -319,11 +422,11 @@ void RdpView::processError(QProcess::ProcessError error)
296  void RdpView::receivedStandardError()
297  {
298      const QString output(m_process->readAllStandardError());
299 -    kDebug(5012) << "receivedStandardError:" << output;
300 +    kDebug(5012) << output;
301      QString line;
302      int i = 0;
303      while (!(line = output.section('\n', i, i)).isEmpty()) {
304 -        
305 +
306          // the following error is issued by freerdp because of a bug in freerdp 1.0.1 and below;
307          // see: https://github.com/FreeRDP/FreeRDP/pull/576
308          //"X Error of failed request:  BadWindow (invalid Window parameter)
309 @@ -345,7 +448,7 @@ void RdpView::receivedStandardError()
310  void RdpView::receivedStandardOutput()
311  {
312      const QString output(m_process->readAllStandardOutput());
313 -    kDebug(5012) << "receivedStandardOutput:" << output;
314 +    kDebug(5012) << output;
315      QString line;
316      int i = 0;
317      while (!(line = output.section('\n', i, i)).isEmpty()) {