Add help text for attribute S/R.
[qpwmc.git] / pwmdSocketWidget.cpp
blobc5491ca84f5e8a47aa9081cd72aac4c8bce77df1
1 /*
2 Copyright (C) 2010-2024 Ben Kibbey <bjk@luxsci.net>
4 This file is part of qpwmc.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA
21 #include <QSettings>
22 #include <QDir>
23 #include <QStringList>
24 #include <QCommonStyle>
25 #include <QScroller>
26 #include <libpwmd.h>
27 #include <unistd.h>
28 #include "pwmdSocketWidget.h"
29 #include "pwmdRemoteHost.h"
30 #include "pwmdFileDialog.h"
31 #ifdef Q_OS_ANDROID
32 #include "pwmdAndroidJNI.h"
34 extern PwmdAndroidJNI *androidJni;
35 #endif
37 PwmdSocketWidget::PwmdSocketWidget (QWidget *p)
38 : QFrame (p)
40 ui.setupUi (this);
41 ipVersion = 0;
42 QSettings cfg ("qpwmc");
44 QStringList list = cfg.value ("localSockets").toStringList ();
45 for (int i = 0; i < list.size(); i++)
46 ui.cb_socket->addItem (list.at (i));
48 int size = cfg.beginReadArray ("remoteHosts");
49 unsigned features = pwmd_features ();
51 for (int i = 0; i < size; ++i)
53 cfg.setArrayIndex (i);
54 if (cfg.value ("name").toString ().isEmpty ())
55 continue;
57 QListWidgetItem *item = new QListWidgetItem (ui.lb_remoteHosts);
58 PwmdRemoteHost data = PwmdRemoteHost (cfg.value ("name").toString ());
59 Qt::ItemFlags flags = item->flags ();
61 data.setType (cfg.value ("type").toInt ());
62 data.setHostname (cfg.value ("hostname").toString ());
63 data.setPort (cfg.value ("port").toInt ());
64 data.setIpProtocol (cfg.value ("ipProtocol").toInt ());
65 data.setSocketArgs (cfg.value ("socketArgs").toStringList ());
66 data.setTlsVerify (cfg.value ("tlsVerify").toBool ());
67 data.setTlsPriority (cfg.value ("tlsPriority").toString ());
68 data.setConnectTimeout (cfg.value ("connectTimeout").toInt ());
69 data.setSocketTimeout (cfg.value ("socketTimeout").toInt ());
70 data.setSshUsername (cfg.value ("sshUsername").toString ());
71 data.setSshAgent (cfg.value ("sshAgent").toBool ());
72 #ifdef Q_OS_ANDROID
73 data.setClientCertificateAlias (cfg.value ("clientCertificateAlias").toString ());
74 #endif
75 item->setData (Qt::UserRole, QVariant::fromValue (data));
76 item->setText (data.name ());
78 if (data.type () == PWMD_SOCKET_SSH && !(features & PWMD_FEATURE_SSH))
79 flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
81 #ifndef Q_OS_ANDROID
82 else if (data.type () == PWMD_SOCKET_TLS
83 && !(features & PWMD_FEATURE_GNUTLS))
84 flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
85 #endif
87 item->setFlags (flags);
90 cfg.endArray ();
92 connect (ui.cb_socket, SIGNAL (activated (int)), this,
93 SLOT (slotLocalSocketChanged (int)));
94 connect (ui.pb_clearLocalSocket, SIGNAL (clicked()), this,
95 SLOT (slotClearLocalSocket ()));
96 connect (ui.pb_selectSocket, SIGNAL (clicked()), this,
97 SLOT (slotSelectSocket ()));
98 connect (ui.rb_ipany, SIGNAL (toggled (bool)),
99 SLOT (slotIpVersionToggled (bool)));
100 connect (ui.rb_ipv4, SIGNAL (toggled (bool)),
101 SLOT (slotIpVersionToggled (bool)));
102 connect (ui.rb_ipv6, SIGNAL (toggled (bool)),
103 SLOT (slotIpVersionToggled (bool)));
104 connect (ui.ck_remote, SIGNAL (toggled (bool)),
105 SLOT (slotRemoteToggled (bool)));
106 connect (ui.ck_agent, SIGNAL (toggled (bool)),
107 SLOT (slotUseAgentToggled (bool)));
109 connect (ui.cb_connectionType, SIGNAL (activated (int)), this,
110 SLOT (slotConnectionTypeChanged (int)));
111 ui.cb_connectionType->setCurrentIndex (cfg.value ("connectionType", 0).
112 toInt ());
113 connect (ui.pb_clientCert, SIGNAL (clicked ()), this,
114 SLOT (slotSelectTlsClientCert ()));
115 connect (ui.pb_clientKey, SIGNAL (clicked ()), this,
116 SLOT (slotSelectTlsClientKey ()));
117 connect (ui.pb_caCert, SIGNAL (clicked ()), this,
118 SLOT (slotSelectTlsCaCert ()));
119 connect (ui.pb_newHost, SIGNAL (clicked ()), this,
120 SLOT (slotNewRemoteHost ()));
121 ui.pb_newHost->setIcon (QIcon (":icons/matt-icons_list-add.svg"));
122 connect (ui.pb_removeHost, SIGNAL (clicked ()), this,
123 SLOT (slotRemoveRemoteHost ()));
124 ui.pb_removeHost->setIcon (QIcon (":icons/matt-icons_list-remove.svg"));
125 connect (ui.lb_remoteHosts,
126 SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)),
127 SLOT (slotRemoteHostItemChanged
128 (QListWidgetItem *, QListWidgetItem *)));
129 connect (ui.le_remoteName, SIGNAL (textEdited (const QString &)),
130 SLOT (slotRemoteHostNameChanged (const QString &)));
132 connect (ui.pb_identity, SIGNAL (clicked ()),
133 SLOT (slotChooseIdentityFile ()));
134 connect (ui.pb_knownhosts, SIGNAL (clicked ()),
135 SLOT (slotChooseKnownhostsFile ()));
137 if (!ui.ck_remote->isChecked ())
138 ui.gr_hostDetails->setEnabled (false);
140 if (features & PWMD_FEATURE_SSH)
141 ui.cb_connectionType->addItem (tr ("SSH"));
143 #ifndef Q_OS_ANDROID
144 if (features & PWMD_FEATURE_GNUTLS)
145 #endif
146 ui.cb_connectionType->addItem (tr ("TLS"));
148 #if !defined (Q_OS_ANDROID) && !defined (__MINGW32__)
149 if (!(features & PWMD_FEATURE_GNUTLS) && !(features & PWMD_FEATURE_SSH))
150 ui.ck_remote->setEnabled (false);
151 #else
152 ui.f_uds->setHidden (true);
153 ui.ck_remote->setEnabled (true);
154 ui.ck_remote->setChecked (true);
155 toggleRemote (true);
156 #endif
158 QScroller::grabGesture (ui.scrollArea, QScroller::TouchGesture);
159 QCommonStyle style;
160 ui.cb_socket->lineEdit()->setPlaceholderText (tr ("Default"));
161 ui.pb_clearLocalSocket->setIcon (QIcon (":icons/nicubunu-Broom.svg"));
162 ui.pb_selectSocket->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
163 ui.pb_knownhosts->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
164 ui.pb_identity->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
165 ui.pb_caCert->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
166 ui.pb_clientCert->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
167 ui.pb_clientKey->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
168 #ifdef Q_OS_ANDROID
169 ui.pb_certificateAlias->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
170 connect (ui.pb_certificateAlias, SIGNAL (clicked ()), this,
171 SLOT (slotSelectCertificateAlias ()));
172 #endif
174 ui.fr_certificateAlias->setHidden (true);
175 ui.fr_ssh->setHidden (true);
176 ui.fr_tls->setHidden (true);
179 PwmdSocketWidget::~PwmdSocketWidget ()
181 saveHosts ();
184 #ifdef Q_OS_ANDROID
185 void
186 PwmdSocketWidget::slotSelectCertificateAlias ()
188 androidJni->selectCertificateAlias (ui.le_certificateAlias);
190 #endif
192 void
193 PwmdSocketWidget::slotSelectSocket ()
195 PwmdFileDialog d (this, tr ("Local socket"));
197 d.setFilter (d.filter () | QDir::System);
198 d.setFileMode (PwmdFileDialog::ExistingFile);
199 d.setOption (PwmdFileDialog::ReadOnly);
200 #ifdef Q_OS_ANDROID
201 d.setWindowState (Qt::WindowFullScreen);
202 #endif
204 if (!d.exec () || !d.selectedFiles ().count ())
205 return;
207 ui.cb_socket->lineEdit ()->setText (d.selectedFiles ().at (0));
208 ui.cb_socket->addItem (d.selectedFiles ().at (0));
211 void
212 PwmdSocketWidget::slotClearLocalSocket ()
214 ui.cb_socket->lineEdit ()->setText ("");
217 void
218 PwmdSocketWidget::slotLocalSocketChanged (int)
222 void
223 PwmdSocketWidget::saveHosts ()
225 QSettings cfg ("qpwmc");
227 QStringList list;
228 for (int i = 0; i < ui.cb_socket->count (); i++)
230 QString s = ui.cb_socket->itemText (i);
232 for (int l = 0; l < list.size (); l++)
233 if (list.at (l) == s)
234 continue;
236 list.append (s);
239 cfg.setValue ("localSockets", list);
241 cfg.beginWriteArray ("remoteHosts");
242 QList < QListWidgetItem * >items = ui.lb_remoteHosts->findItems ("*", Qt::MatchWildcard);
244 for (int i = 0; i < items.size (); i++)
246 QListWidgetItem *item = items.at (i);
247 PwmdRemoteHost data = item->data (Qt::UserRole).value < PwmdRemoteHost > ();
249 cfg.setArrayIndex (i);
250 cfg.setValue ("name", data.name ());
251 cfg.setValue ("type", data.type ());
252 cfg.setValue ("hostname", data.hostname ());
253 cfg.setValue ("port", data.port ());
254 cfg.setValue ("ipProtocol", data.ipProtocol ());
255 cfg.setValue ("socketArgs", data.socketArgs ());
256 cfg.setValue ("tlsVerify", data.tlsVerify ());
257 cfg.setValue ("tlsPriority", data.tlsPriority ());
258 cfg.setValue ("connectTimeout", data.connectTimeout ());
259 cfg.setValue ("socketTimeout", data.socketTimeout ());
260 cfg.setValue ("sshUsername", data.sshUsername ());
261 cfg.setValue ("sshAgent", data.sshAgent ());
262 #ifdef Q_OS_ANDROID
263 cfg.setValue ("clientCertificateAlias", data.clientCertificateAlias ());
264 #endif
267 cfg.endArray ();
270 bool
271 PwmdSocketWidget::currentHostData (PwmdRemoteHost &hostData)
273 if (ui.ck_remote->isChecked ())
274 return PwmdRemoteHost::fillRemoteHost (ui.lb_remoteHosts->currentItem ()->text (), hostData);
276 return false;
279 void
280 PwmdSocketWidget::slotConnectionTypeChanged (int idx)
282 unsigned features = pwmd_features ();
283 #ifndef Q_OS_ANDROID
284 if (!(features & PWMD_FEATURE_GNUTLS) && !(features & PWMD_FEATURE_SSH))
285 return;
286 #endif
288 QSettings cfg ("qpwmc");
290 if (idx == 0 && (features & PWMD_FEATURE_SSH))
292 #ifdef Q_OS_ANDROID
293 ui.fr_certificateAlias->setHidden (true);
294 #else
295 ui.fr_tls->setHidden (true);
296 #endif
297 ui.fr_ssh->setHidden (false);
298 ui.sp_port->setValue (cfg.value ("sshPort", 22).toInt ());
300 else
302 #ifdef Q_OS_ANDROID
303 ui.fr_certificateAlias->setHidden (false);
304 #else
305 ui.fr_tls->setHidden (false);
306 #endif
307 ui.fr_ssh->setHidden (true);
308 ui.sp_port->setValue (cfg.value ("tlsPort", 6466).toInt ());
312 void
313 PwmdSocketWidget::slotIpVersionToggled (bool b)
315 (void) b;
317 if (ui.rb_ipany->isChecked ())
318 ipVersion = 0;
319 else if (ui.rb_ipv4->isChecked ())
320 ipVersion = 1;
321 else if (ui.rb_ipv6->isChecked ())
322 ipVersion = 2;
325 void
326 PwmdSocketWidget::slotChooseIdentityFile ()
328 PwmdFileDialog d (this, tr ("SSH identity file"));
330 d.setFileMode (PwmdFileDialog::ExistingFile);
331 d.setOption (PwmdFileDialog::ReadOnly);
332 #ifdef Q_OS_ANDROID
333 d.setWindowState (Qt::WindowFullScreen);
334 #endif
336 if (!d.exec () || !d.selectedFiles ().count ())
337 return;
338 ui.le_identity->setText (d.selectedFiles ().at (0));
341 void
342 PwmdSocketWidget::slotChooseKnownhostsFile ()
344 PwmdFileDialog d (this, tr ("SSH knownhosts file"),
345 #ifdef Q_OS_ANDROID
346 "/sdcard"
347 #else
348 QDir::home ().path ()
349 #endif
352 d.setFileMode (PwmdFileDialog::ExistingFile);
353 d.setOption (PwmdFileDialog::ReadOnly);
354 #ifdef Q_OS_ANDROID
355 d.setWindowState (Qt::WindowFullScreen);
356 #endif
358 if (!d.exec () || !d.selectedFiles ().count ())
359 return;
360 ui.le_knownhosts->setText (d.selectedFiles ().at (0));
363 void
364 PwmdSocketWidget::toggleRemote (bool b)
366 QListWidgetItem *item = ui.lb_remoteHosts->currentItem ();
367 Qt::ItemFlags flags;
369 if (item)
370 flags = item->flags ();
372 ui.cb_socket->setEnabled (!b);
373 ui.pb_clearLocalSocket->setEnabled (!b);
374 ui.pb_selectSocket->setEnabled (!b);
375 ui.ck_agent->setEnabled (b && getenv ("SSH_AUTH_SOCK") != nullptr);
376 slotConnectionTypeChanged (ui.cb_connectionType->currentIndex ());
377 ui.gr_hostDetails->setEnabled (b ? item && (flags & Qt::ItemIsEnabled)
378 ? b : false : b);
380 if (b)
381 slotUseAgentToggled (ui.ck_agent->isEnabled ()
382 && ui.ck_agent->isChecked ());
385 void
386 PwmdSocketWidget::slotRemoteToggled (bool b)
388 #if defined(Q_OS_ANDROID) || defined (__MINGW32__)
389 if (!b)
390 ui.ck_remote->setChecked (true);
391 return;
392 #endif
394 toggleRemote (b);
397 void
398 PwmdSocketWidget::slotUseAgentToggled (bool b)
400 ui.le_identity->setEnabled (!b);
401 ui.pb_identity->setEnabled (!b);
405 void
406 PwmdSocketWidget::slotSelectTlsClientCert ()
408 PwmdFileDialog d (this, tr ("TLS client certificate file"),
409 #ifdef Q_OS_ANDROID
410 "/sdcard"
411 #else
412 QDir::home ().path ()
413 #endif
416 d.setFileMode (PwmdFileDialog::ExistingFile);
417 d.setOption (PwmdFileDialog::ReadOnly);
418 #ifdef Q_OS_ANDROID
419 d.setWindowState (Qt::WindowFullScreen);
420 #endif
422 if (!d.exec () || !d.selectedFiles ().count ())
423 return;
424 ui.le_clientCert->setText (d.selectedFiles ().at (0));
427 void
428 PwmdSocketWidget::slotSelectTlsClientKey ()
430 PwmdFileDialog d (this, tr ("TLS client certificate key file"),
431 #ifdef Q_OS_ANDROID
432 "/sdcard"
433 #else
434 QDir::home ().path ()
435 #endif
438 d.setFileMode (PwmdFileDialog::ExistingFile);
439 d.setOption (PwmdFileDialog::ReadOnly);
440 #ifdef Q_OS_ANDROID
441 d.setWindowState (Qt::WindowFullScreen);
442 #endif
444 if (!d.exec () || !d.selectedFiles ().count ())
445 return;
446 ui.le_clientKey->setText (d.selectedFiles ().at (0));
449 void
450 PwmdSocketWidget::slotSelectTlsCaCert ()
452 PwmdFileDialog d (this, tr ("TLS CA certificate file"),
453 #ifdef Q_OS_ANDROID
454 "/sdcard"
455 #else
456 QDir::home ().path ()
457 #endif
460 d.setFileMode (PwmdFileDialog::ExistingFile);
461 d.setOption (PwmdFileDialog::ReadOnly);
462 #ifdef Q_OS_ANDROID
463 d.setWindowState (Qt::WindowFullScreen);
464 #endif
466 if (!d.exec () || !d.selectedFiles ().count ())
467 return;
468 ui.le_caCert->setText (d.selectedFiles ().at (0));
471 void
472 PwmdSocketWidget::initNewRemoteHost ()
474 ui.le_remoteName->setText ("");
475 ui.cb_connectionType->setCurrentIndex (0);
476 slotConnectionTypeChanged (0);
477 ui.le_hostname->setText ("");
478 ui.rb_ipany->setChecked (true);
479 ui.sp_port->setValue (22);
480 ui.le_identity->setText ("");
481 ui.ck_agent->setChecked (ui.ck_agent->isEnabled ());
482 ui.le_knownhosts->setText ("");
483 ui.sp_connectTimeout->setValue (120);
484 ui.sp_socketTimeout->setValue (300);
485 ui.le_clientCert->setText ("");
486 ui.le_clientKey->setText ("");
487 ui.le_caCert->setText ("");
488 ui.le_tlsServerFingerprint->setText ("");
489 ui.ck_tlsVerify->setChecked (true);
490 ui.le_tlsPriority->setText ("");
491 #ifndef __MINGW32__
492 ui.le_username->setText (getlogin () ? getlogin () : "");
493 #endif
496 void
497 PwmdSocketWidget::updateRemoteHost ()
499 updateRemoteHost (ui.lb_remoteHosts->currentItem ());
502 void
503 PwmdSocketWidget::updateRemoteHost (QListWidgetItem * item)
505 if (!item)
506 return;
508 PwmdRemoteHost data = item->data (Qt::UserRole).value < PwmdRemoteHost > ();
509 data.setName (ui.le_remoteName->text ());
511 if (ui.cb_connectionType->currentText () == "SSH")
512 data.setType (PWMD_SOCKET_SSH);
513 else
514 #ifdef Q_OS_ANDROID
515 data.setType (PWMD_SOCKET_USER);
516 #else
517 data.setType (PWMD_SOCKET_TLS);
518 #endif
520 data.setHostname (ui.le_hostname->text ());
521 data.setPort (ui.sp_port->value ());
523 if (ui.rb_ipany->isChecked ())
524 data.setIpProtocol (0);
525 else if (ui.rb_ipv4->isChecked ())
526 data.setIpProtocol (1);
527 else if (ui.rb_ipv6->isChecked ())
528 data.setIpProtocol (2);
530 QStringList list;
531 if (data.type () == PWMD_SOCKET_SSH)
533 list.append (ui.le_identity->text ());
534 list.append (ui.le_knownhosts->text ());
536 else
538 list.append (ui.le_clientCert->text ());
539 list.append (ui.le_clientKey->text ());
540 list.append (ui.le_caCert->text ());
541 list.append (ui.le_tlsServerFingerprint->text ());
544 data.setSocketArgs (list);
545 data.setTlsVerify (ui.ck_tlsVerify->isChecked ());
546 data.setTlsPriority (ui.le_tlsPriority->text ());
547 data.setConnectTimeout (ui.sp_connectTimeout->value ());
548 data.setSocketTimeout (ui.sp_socketTimeout->value ());
549 data.setSshUsername (ui.le_username->text ());
550 data.setSshAgent (ui.ck_agent->isChecked ());
551 #ifdef Q_OS_ANDROID
552 data.setClientCertificateAlias (ui.le_certificateAlias->text ());
553 #endif
554 item->setData (Qt::UserRole, QVariant::fromValue (data));
557 void
558 PwmdSocketWidget::slotNewRemoteHost ()
560 QListWidgetItem *item = ui.lb_remoteHosts->currentItem ();
562 updateRemoteHost (item);
563 ui.lb_remoteHosts->addItem (new QListWidgetItem (tr ("New host")));
564 ui.lb_remoteHosts->setCurrentItem (ui.lb_remoteHosts->item (ui.lb_remoteHosts->count () - 1));
565 ui.le_remoteName->setFocus (Qt::MouseFocusReason);
566 initNewRemoteHost ();
567 ui.gr_hostDetails->setEnabled (true);
570 void
571 PwmdSocketWidget::slotRemoveRemoteHost ()
573 if (!ui.lb_remoteHosts->currentItem ())
574 return;
576 QListWidgetItem *item =
577 ui.lb_remoteHosts->takeItem (ui.lb_remoteHosts->row (ui.lb_remoteHosts->currentItem ()));
578 delete item;
581 void
582 PwmdSocketWidget::slotRemoteHostItemChanged (QListWidgetItem * item,
583 QListWidgetItem * old)
585 #ifndef Q_OS_ANDROID
586 if (!(pwmd_features () & PWMD_FEATURE_SSH)
587 && !(pwmd_features () & PWMD_FEATURE_GNUTLS))
589 ui.ck_remote->setChecked (false);
590 return;
592 #endif
594 updateRemoteHost (old);
595 if (!item)
597 ui.gr_hostDetails->setEnabled (false);
598 initNewRemoteHost ();
599 return;
602 PwmdRemoteHost data = item->data (Qt::UserRole).value < PwmdRemoteHost > ();
603 ui.le_remoteName->setText (data.name ());
605 if (!data.type () || data.type () == PWMD_SOCKET_SSH)
607 ui.cb_connectionType->setCurrentIndex (0);
608 ui.fr_tls->setHidden (true);
609 #ifdef Q_OS_ANDROID
610 ui.fr_certificateAlias->setHidden (true);
611 ui.fr_socketProtocol->setHidden(false);
612 #endif
613 ui.fr_ssh->setHidden (false);
615 else if (data.type () == PWMD_SOCKET_TLS || data.type () == PWMD_SOCKET_USER)
617 if (!(pwmd_features () & PWMD_FEATURE_SSH))
618 ui.cb_connectionType->setCurrentIndex (0);
619 else
620 ui.cb_connectionType->setCurrentIndex (1);
622 #ifdef Q_OS_ANDROID
623 ui.fr_certificateAlias->setHidden (false);
624 ui.fr_socketProtocol->setHidden(true);
625 #else
626 ui.fr_tls->setHidden (false);
627 #endif
628 ui.fr_ssh->setHidden (true);
631 ui.le_hostname->setText (data.hostname ());
632 switch (data.ipProtocol ())
634 case 0:
635 ui.rb_ipany->setChecked (true);
636 break;
637 case 1:
638 ui.rb_ipv4->setChecked (true);
639 break;
640 case 2:
641 ui.rb_ipv6->setChecked (true);
642 break;
645 ui.sp_port->setValue (data.port ());
647 /* Fill the argument list. 6 is the maximum to pass to pwmd_connect() but
648 * any amount more than the known 5 used can be appended. */
649 QStringList args = data.socketArgs ();
650 for (int n = args.count () - 1; n < 6; n++)
651 args.append (QString (""));
653 if (data.type () == PWMD_SOCKET_SSH)
655 ui.le_identity->setText (args.at (0));
656 ui.le_knownhosts->setText (args.at (1));
658 else
660 ui.le_clientCert->setText (args.at (0));
661 ui.le_clientKey->setText (args.at (1));
662 ui.le_caCert->setText (args.at (2));
663 ui.le_tlsServerFingerprint->setText (args.at (3));
666 ui.le_username->setText (data.sshUsername ());
667 ui.sp_connectTimeout->setValue (data.connectTimeout ());
668 ui.sp_socketTimeout->setValue (data.socketTimeout ());
669 ui.ck_tlsVerify->setChecked (data.tlsVerify ());
670 ui.le_tlsPriority->setText (data.tlsPriority ());
671 ui.ck_agent->setChecked (data.sshAgent ());
672 #ifdef Q_OS_ANDROID
673 ui.le_certificateAlias->setText (data.clientCertificateAlias ());
674 #endif
675 ui.gr_hostDetails->setEnabled (true);
678 void
679 PwmdSocketWidget::slotRemoteHostNameChanged (const QString & str)
681 QListWidgetItem *item = ui.lb_remoteHosts->currentItem ();
683 if (!item)
685 ui.gr_hostDetails->setEnabled (false);
686 return;
689 PwmdRemoteHost data = item->data (Qt::UserRole).value < PwmdRemoteHost > ();
690 data.setName (str);
691 item->setData (Qt::UserRole, QVariant::fromValue (data));
692 item->setText (str);
695 QString
696 PwmdSocketWidget::socket ()
698 if (ui.ck_remote->isChecked ())
699 return ui.lb_remoteHosts->currentItem ()->text ();
701 return ui.cb_socket->lineEdit()->text ();
704 void
705 PwmdSocketWidget::setSelected (const QString &sock)
707 foreach (QListWidgetItem *item, ui.lb_remoteHosts->findItems ("*", Qt::MatchWildcard))
709 if (item->text () == sock)
711 ui.ck_remote->setChecked (true);
712 ui.lb_remoteHosts->setCurrentItem (item);
713 if (!(item->flags () & Qt::ItemIsEnabled))
714 ui.gr_hostDetails->setEnabled (false);
715 return;
719 ui.cb_socket->lineEdit()->setText (sock);