1 /**************************************************************************
2 *   Copyright (C) 2005-2020 by Oleksandr Shneyder                         *
3 *                              <o.shneyder@phoca-gmbh.de>                 *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 *   This program is distributed in the hope that it will be useful,       *
10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 *   GNU General Public License for more details.                          *
13 *                                                                         *
14 *   You should have received a copy of the GNU General Public License     *
15 *   along with this program.  If not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17 
18 #include "sessionwidget.h"
19 #include "x2goutils.h"
20 #include <QBoxLayout>
21 #include <QLineEdit>
22 #include <QPushButton>
23 #include <QLabel>
24 #include <QGroupBox>
25 #include <QSpinBox>
26 #include <QIcon>
27 #include <QComboBox>
28 #include <QFileDialog>
29 #include <QDir>
30 #include <QTimer>
31 #include <QInputDialog>
32 #include <QCheckBox>
33 #include "onmainwindow.h"
34 #include "x2gosettings.h"
35 #include <QMessageBox>
36 #include <QButtonGroup>
37 #include <QRadioButton>
38 #include "folderexplorer.h"
39 #include "sessionexplorer.h"
40 
SessionWidget(bool newSession,QString id,ONMainWindow * mw,QWidget * parent,Qt::WindowFlags f)41 SessionWidget::SessionWidget ( bool newSession, QString id, ONMainWindow * mw,
42                                QWidget * parent, Qt::WindowFlags f )
43     : ConfigWidget ( id,mw,parent,f )
44 {
45     QVBoxLayout* sessLay=new QVBoxLayout ( this );
46 #ifdef Q_WS_HILDON
47     sessLay->setMargin ( 2 );
48 #endif
49     this->parent=mw;
50     this->newSession=newSession;
51 
52     sessName=new QLineEdit ( this );
53     icon=new QPushButton ( QString::null,this );
54     if ( !miniMode )
55     {
56         icon->setIconSize ( QSize ( 100,100 ) );
57         icon->setFixedSize ( 100,100 );
58     }
59     else
60     {
61         icon->setIconSize ( QSize ( 48,48 ) );
62         icon->setFixedSize ( 48,48 );
63     }
64     icon->setFlat ( true );
65 
66     QHBoxLayout* slay=new QHBoxLayout();
67     slay->addWidget ( new QLabel ( tr ( "Session name:" ),this ) );
68     slay->addWidget ( sessName );
69 
70     QHBoxLayout* ilay=new QHBoxLayout();
71     ilay->addWidget ( icon );
72     ilay->addWidget ( new QLabel ( tr ( "<< change icon" ),this ) );
73 
74     lPath=new QLabel(this);
75     lPath->setFrameStyle(QFrame::StyledPanel);
76     QPushButton* pathButton=new QPushButton("...",this);
77     QHBoxLayout* pathLay=new QHBoxLayout();
78     pathLay->addWidget(new QLabel(tr("Path:"), this),0);
79     pathLay->addWidget(lPath,1);
80     pathLay->addWidget(pathButton,0);
81 
82 #ifndef Q_WS_HILDON
83     QGroupBox *sgb=new QGroupBox ( tr ( "&Server" ),this );
84 #else
85     QFrame* sgb=this;
86 #endif
87     const QString ssh_port_tooltip_text = tr ("Values ranging from <b>0</b> to <b>65535</b> are allowed."
88                                               "<br />A value of <b>0</b> will either use the port specified in the "
89                                               "SSH configuration file belonging to a host or shortname, "
90                                               "or use the default of <b>22</b>.");
91     server=new QLineEdit ( sgb );
92     uname=new QLineEdit ( sgb );
93     sshPort=new QSpinBox ( sgb );
94     sshPort->setValue ( mainWindow->getDefaultSshPort().toInt() );
95     sshPort->setMinimum ( 0 );
96     sshPort->setMaximum ( 65535 );
97     sshPort->setToolTip (ssh_port_tooltip_text);
98 #ifdef Q_OS_UNIX
99     rdpPort=new QSpinBox ( sgb );
100     rdpPort->setValue ( mainWindow->getDefaultSshPort().toInt() );
101     rdpPort->setMinimum ( 0 );
102     rdpPort->setMaximum ( 65535 );
103     rdpPort->setToolTip (ssh_port_tooltip_text);
104 #endif
105     key=new QLineEdit ( sgb );
106 
107 #ifndef Q_WS_HILDON
108     openKey=new QPushButton (
109         QIcon ( mainWindow->iconsPath (
110                     "/32x32/file-open.png" ) ),
111         QString::null,sgb );
112     QVBoxLayout *sgbLay = new QVBoxLayout ( sgb );
113 #else
114     QPushButton* openKey=new QPushButton (
115         QIcon ( mainWindow->iconsPath ( "/16x16/file-open.png" ) ),
116         QString::null,sgb );
117     QVBoxLayout *sgbLay = new QVBoxLayout ();
118 #endif
119     QHBoxLayout *suLay =new QHBoxLayout();
120     QVBoxLayout *slLay =new QVBoxLayout();
121     QVBoxLayout *elLay =new QVBoxLayout();
122     slLay->addWidget ( new QLabel ( tr ( "Host:" ),sgb ) );
123     lLogin= new QLabel ( tr ( "Login:" ),sgb );
124     slLay->addWidget (lLogin );
125     lPort=new QLabel ( tr ( "SSH port:" ),sgb );
126     slLay->addWidget ( lPort );
127     elLay->addWidget ( server );
128     elLay->addWidget ( uname );
129     elLay->addWidget ( sshPort );
130 #ifdef Q_OS_UNIX
131     elLay->addWidget ( rdpPort );
132 #endif
133     suLay->addLayout ( slLay );
134     suLay->addLayout ( elLay );
135 #ifdef Q_WS_HILDON
136     sshPort->setFixedHeight ( int ( sshPort->sizeHint().height() *1.5 ) );
137 #endif
138 
139     QHBoxLayout *keyLay =new QHBoxLayout();
140     lKey=new QLabel ( tr ( "Use RSA/DSA key for ssh connection:" ),sgb );
141     keyLay->addWidget (lKey );
142     keyLay->addWidget ( key );
143     keyLay->addWidget ( openKey );
144 
145     sgbLay->addLayout ( suLay );
146     sgbLay->addLayout ( keyLay );
147     cbAutoLogin=new QCheckBox(tr("Try auto login (via SSH Agent or default SSH key)"),sgb);
148     cbKrbLogin=new QCheckBox(tr("Kerberos 5 (GSSAPI) authentication"),sgb);
149     cbKrbDelegation=new QCheckBox(tr("Delegation of GSSAPI credentials to the server"),sgb);
150     sgbLay->addWidget(cbAutoLogin);
151     sgbLay->addWidget(cbKrbLogin);
152     sgbLay->addWidget(cbKrbDelegation);
153     cbProxy=new QCheckBox(tr("Use Proxy server for SSH connection"),sgb);
154     proxyBox=new QGroupBox(tr("Proxy server"),sgb);
155     sgbLay->addWidget(cbProxy);
156     sgbLay->addWidget(proxyBox);
157     QGridLayout* proxyLaout=new QGridLayout(proxyBox);
158     QButtonGroup* proxyType=new QButtonGroup(proxyBox);
159     proxyType->setExclusive(true);
160     rbSshProxy=new QRadioButton(tr("SSH"),proxyBox);
161     rbHttpProxy=new QRadioButton(tr("HTTP"),proxyBox);
162     proxyType->addButton(rbSshProxy);
163     proxyType->addButton(rbHttpProxy);
164     proxyHost=new QLineEdit(proxyBox);
165     proxyPort=new QSpinBox(proxyBox);
166     proxyPort->setMinimum ( 0 );
167     proxyPort->setMaximum ( 65535 );
168     proxyPort->setToolTip (ssh_port_tooltip_text);
169 
170     cbProxySameUser=new QCheckBox(tr("Same login as on X2Go Server"), proxyBox);
171     proxyLogin=new QLineEdit(proxyBox);
172     cbProxySamePass=new QCheckBox(tr("Same password as on X2Go Server"), proxyBox);
173 
174     proxyKeyLabel=new QLabel( tr ( "RSA/DSA key:" ), proxyBox);
175     proxyKey=new QLineEdit(proxyBox);
176     pbOpenProxyKey=new QPushButton (
177         QIcon ( mainWindow->iconsPath ( "/16x16/file-open.png" ) ),
178         QString::null,proxyBox );
179     cbProxyAutologin=new QCheckBox(tr("SSH Agent or default SSH key"),proxyBox);
180     cbProxyKrbLogin=new QCheckBox(tr("Kerberos 5 (GSSAPI) authentication"),proxyBox);
181 
182 
183     proxyLaout->addWidget(new QLabel(tr("Type:"),proxyBox),0,0,1,2);
184     proxyLaout->addWidget(rbSshProxy,1,0,1,2);
185     proxyLaout->addWidget(rbHttpProxy,2,0,1,2);
186     proxyLaout->addWidget(new QLabel(tr("Host:"),proxyBox),3,0);
187     proxyLaout->addWidget(new QLabel(tr("Port:"),proxyBox),4,0);
188     proxyLaout->addWidget(proxyHost,3,1);
189     proxyLaout->addWidget(proxyPort,4,1);
190 
191     proxyLaout->addWidget(cbProxySameUser,0,3,1,3);
192     proxyLaout->addWidget(lProxyLogin=new QLabel(tr("Login:"),proxyBox),1,3,1,1);
193     proxyLaout->addWidget(proxyLogin,1,4,1,2);
194     proxyLaout->addWidget(cbProxySamePass,2,3,1,3);
195     proxyLaout->addWidget(proxyKeyLabel,3,3,1,1);
196     proxyLaout->addWidget(proxyKey,3,4,1,1);
197     proxyLaout->addWidget(pbOpenProxyKey,3,5,1,1);
198     proxyLaout->addWidget(cbProxyAutologin,4,3,1,3);
199     proxyLaout->addWidget(cbProxyKrbLogin,5,3,1,3);
200 
201 
202 #ifndef Q_WS_HILDON
203     QGroupBox *deskSess=new QGroupBox ( tr ( "&Session type" ),this );
204     QGridLayout* cmdLay=new QGridLayout ( deskSess );
205 #else
206     QFrame* deskSess=this;
207     QHBoxLayout* cmdLay=new QHBoxLayout ();
208     cmdLay->addWidget ( new QLabel ( tr ( "Session type:" ),this ) );
209 #endif
210     cbKdrive=new QCheckBox(tr("Run in X2GoKDrive (experimental)"));
211     sessBox=new QComboBox ( deskSess );
212     cmd=new QLineEdit ( deskSess );
213     cmdCombo=new QComboBox ( deskSess );
214     cmdCombo->setEditable ( true );
215     sessBox->addItem ( "KDE" );
216     sessBox->addItem ( "GNOME" );
217     sessBox->addItem ( "LXDE" );
218     sessBox->addItem ("LXQt");
219     sessBox->addItem ( "XFCE" );
220     sessBox->addItem ( "MATE" );
221     sessBox->addItem ( "UNITY" );
222     sessBox->addItem ( "CINNAMON" );
223     sessBox->addItem ( "TRINITY" );
224     sessBox->addItem ( "OPENBOX" );
225     sessBox->addItem ( "ICEWM" );
226     sessBox->addItem ( tr ( "Connect to Windows Terminal Server" ) );
227     sessBox->addItem ( tr ( "XDMCP" ) );
228     sessBox->addItem ( tr ( "X2Go/X11 Desktop Sharing" ) );
229     sessBox->addItem ( tr ( "Custom desktop" ) );
230     sessBox->addItem ( tr ( "Single application" ) );
231     sessBox->addItem ( tr ( "Published applications" ) );
232     cmdLay->addWidget ( cbKdrive,0,1,Qt::AlignLeft );
233     cmdLay->addWidget ( sessBox,1,1,Qt::AlignLeft );
234     leCmdIp=new QLabel ( tr ( "Command:" ),deskSess );
235     pbAdvanced=new QPushButton ( tr ( "Advanced options..." ),deskSess );
236     cmdLay->addWidget ( leCmdIp,1,2 );
237     cmdLay->setColumnStretch(6,1);
238     cmdLay->addWidget ( cmd ,1,3);
239     cmdLay->addWidget ( cmdCombo,1,4 );
240     cmdLay->addWidget ( pbAdvanced ,1,5);
241     cmdCombo->setSizePolicy ( QSizePolicy::Expanding,
242                               QSizePolicy::Preferred );
243     cmdCombo->hide();
244     pbAdvanced->hide();
245     cmdCombo->addItem ( "" );
246     cmdCombo->addItems ( mainWindow->transApplicationsNames() );
247     cmdCombo->lineEdit()->setText ( tr ( "Path to executable" ) );
248     cmdCombo->lineEdit()->selectAll();
249 #ifndef Q_WS_HILDON
250     sessLay->addLayout ( slay );
251     sessLay->addLayout ( ilay );
252     sessLay->addLayout ( pathLay );
253     if ( !miniMode )
254         sessLay->addSpacing ( 15 );
255     sessLay->addWidget ( sgb );
256     sessLay->addWidget ( deskSess );
257 #ifdef Q_OS_UNIX
258     cbDirectRDP=new QCheckBox(tr("Direct RDP connection"), deskSess);
259     cmdLay->addWidget(cbDirectRDP,2,0,1,6);
260     cbDirectRDP->hide();
261     connect(cbDirectRDP,SIGNAL(clicked()), this, SLOT(slot_rdpDirectClicked()));
262 #endif
263 
264 #else
265     QVBoxLayout* sHildILay = new QVBoxLayout();
266     sHildILay->addLayout ( slay );
267     sHildILay->addLayout ( ilay );
268     sHildILay->addStretch();
269     QHBoxLayout* sHildLay = new QHBoxLayout();
270     sHildLay->addLayout ( sHildILay );
271 
272     QFrame* vl=new QFrame;
273     vl->setLineWidth ( 0 );
274     vl->setFrameStyle ( QFrame::VLine|QFrame::Plain );
275     sHildLay->addWidget ( vl );
276     sHildLay->setSpacing ( 6 );
277     sHildLay->addLayout ( sgbLay );
278     sessLay->addLayout ( sHildLay );
279     sessLay->addStretch();
280     sessLay->addLayout ( cmdLay );
281 #endif
282     sessLay->addStretch();
283 
284     connect ( icon,SIGNAL ( clicked() ),this,SLOT ( slot_getIcon() ) );
285     connect ( openKey,SIGNAL ( clicked() ),this,SLOT ( slot_getKey() ) );
286     connect ( pbAdvanced,SIGNAL ( clicked() ),this,
287               SLOT ( slot_rdpOptions() ) );
288     connect ( sessBox,SIGNAL ( activated ( int ) ),this,
289               SLOT ( slot_changeCmd ( int ) ) );
290     connect ( sessName,SIGNAL ( textChanged ( const QString & ) ),this,
291               SIGNAL ( nameChanged ( const QString & ) ) );
292     connect (server, SIGNAL(textChanged(const QString&)),this, SLOT(slot_emitSettings()));
293     connect (uname, SIGNAL(textChanged(const QString&)),this, SLOT(slot_emitSettings()));
294     connect (cbKrbLogin, SIGNAL(clicked(bool)), this, SLOT(slot_krbChecked()));
295 #ifdef Q_OS_UNIX
296     connect (rdpPort, SIGNAL(valueChanged(int)),this, SLOT(slot_emitSettings()));
297 #endif
298 
299     connect ( pbOpenProxyKey,SIGNAL ( clicked() ),this,SLOT ( slot_proxyGetKey()) );
300     connect ( proxyType, SIGNAL ( buttonClicked(int)) ,this,SLOT ( slot_proxyType()));
301     connect (cbProxy, SIGNAL(clicked(bool)), this, SLOT(slot_proxyOptions()));
302     connect (cbProxySameUser, SIGNAL(clicked(bool)), this, SLOT(slot_proxySameLogin()));
303     connect ( pathButton, SIGNAL(clicked(bool)), this, SLOT(slot_openFolder()));
304 
305     readConfig();
306 }
307 
308 
~SessionWidget()309 SessionWidget::~SessionWidget()
310 {
311 }
312 
slot_proxyGetKey()313 void SessionWidget::slot_proxyGetKey()
314 {
315     QString path;
316     QString startDir=ONMainWindow::getHomeDirectory();
317 #ifdef Q_OS_WIN
318     if ( ONMainWindow::getPortable() &&
319             ONMainWindow::U3DevicePath().length() >0 )
320     {
321         startDir=ONMainWindow::U3DevicePath() +"/";
322     }
323 #endif
324     path = QFileDialog::getOpenFileName (
325                this,
326                tr ( "Open key file" ),
327                startDir,
328                tr ( "All files" ) +" (*)" );
329     if ( path!=QString::null )
330     {
331 #ifdef Q_OS_WIN
332         if ( ONMainWindow::getPortable() &&
333                 ONMainWindow::U3DevicePath().length() >0 )
334         {
335             if ( path.indexOf ( ONMainWindow::U3DevicePath() ) !=0 )
336             {
337                 QMessageBox::critical (
338                     0l,tr ( "Error" ),
339                     tr ( "X2Go Client is running in "
340                          "portable mode. You should "
341                          "use a path on your USB device "
342                          "to be able to access your data "
343                          "wherever you are." ),
344                     QMessageBox::Ok,QMessageBox::NoButton );
345                 slot_getKey();
346                 return;
347             }
348             path.replace ( ONMainWindow::U3DevicePath(),
349                            "(U3)" );
350         }
351 #endif
352         proxyKey->setText ( path );
353     }
354 
355 }
356 
slot_proxyOptions()357 void SessionWidget::slot_proxyOptions()
358 {
359     proxyBox->setVisible(cbProxy->isChecked() && cbProxy->isVisible());
360 }
361 
slot_proxySameLogin()362 void SessionWidget::slot_proxySameLogin()
363 {
364     lProxyLogin->setDisabled(cbProxySameUser->isChecked());
365     proxyLogin->setDisabled(cbProxySameUser->isChecked());
366 }
367 
slot_proxyType()368 void SessionWidget::slot_proxyType()
369 {
370     bool isSsh=rbSshProxy->isChecked();
371     cbProxyAutologin->setVisible(isSsh);
372     cbProxyKrbLogin->setVisible(isSsh);
373     proxyKey->setVisible(isSsh);
374     proxyKeyLabel->setVisible(isSsh);
375     pbOpenProxyKey->setVisible(isSsh);
376 }
377 
378 
379 #ifdef Q_OS_UNIX
slot_rdpDirectClicked()380 void SessionWidget::slot_rdpDirectClicked()
381 {
382     bool isDirectRDP=cbDirectRDP->isChecked();
383     bool isXDMCP=false;
384     if(sessBox->currentText()== tr("XDMCP"))
385     {
386         cbDirectRDP->setText( tr("Direct XDMCP connection"));
387         isXDMCP=true;
388     }
389     else
390     {
391         cbDirectRDP->setText( tr("Direct RDP connection"));
392     }
393     if (cbDirectRDP->isHidden())
394         isDirectRDP=false;
395     pbAdvanced->setVisible((!isDirectRDP) && (sessBox->currentIndex()==RDP));
396     leCmdIp->setVisible(!isDirectRDP);
397     cmd->setVisible(!isDirectRDP);
398     key->setVisible(!isDirectRDP);
399     cbAutoLogin->setVisible(!isDirectRDP);
400     lKey->setVisible(!isDirectRDP);
401     openKey->setVisible(!isDirectRDP);
402     sshPort->setVisible(!isDirectRDP);
403     rdpPort->setVisible(isDirectRDP && (!isXDMCP));
404     lPort->setVisible(!(isDirectRDP && isXDMCP));
405 
406     cbKrbDelegation->setVisible(!isDirectRDP);
407     cbKrbLogin->setVisible(!isDirectRDP);
408 
409     cbProxy->setVisible(!isDirectRDP);
410     proxyBox->setVisible(!isDirectRDP && cbProxy->isChecked());
411 
412     if (isDirectRDP)
413     {
414         lPort->setText(tr("RDP port:"));
415     }
416     else
417     {
418         lPort->setText(tr("SSH port:"));
419     }
420     lLogin->setVisible(!(isXDMCP&&isDirectRDP));
421     uname->setVisible(!(isXDMCP&&isDirectRDP));
422 
423 
424     emit directRDP(isDirectRDP, isXDMCP);
425     slot_emitSettings();
426 }
427 #endif
428 
slot_getIcon()429 void SessionWidget::slot_getIcon()
430 {
431     QString path= QFileDialog::getOpenFileName (
432                       this,
433                       tr ( "Open picture" ),
434                       QDir::homePath(),
435                       tr ( "Pictures" ) +" (*.png *.xpm *.jpg)" );
436     if ( path!=QString::null )
437     {
438         sessIcon = wrap_legacy_resource_URIs (path);
439         icon->setIcon ( QIcon ( sessIcon ) );
440     }
441 }
442 
slot_getKey()443 void SessionWidget::slot_getKey()
444 {
445     QString path;
446     QString startDir=ONMainWindow::getHomeDirectory();
447 #ifdef Q_OS_WIN
448     if ( ONMainWindow::getPortable() &&
449             ONMainWindow::U3DevicePath().length() >0 )
450     {
451         startDir=ONMainWindow::U3DevicePath() +"/";
452     }
453 #endif
454     path = QFileDialog::getOpenFileName (
455                this,
456                tr ( "Open key file" ),
457                startDir,
458                tr ( "All files" ) +" (*)" );
459     if ( path!=QString::null )
460     {
461 #ifdef Q_OS_WIN
462         if ( ONMainWindow::getPortable() &&
463                 ONMainWindow::U3DevicePath().length() >0 )
464         {
465             if ( path.indexOf ( ONMainWindow::U3DevicePath() ) !=0 )
466             {
467                 QMessageBox::critical (
468                     0l,tr ( "Error" ),
469                     tr ( "X2Go Client is running in "
470                          "portable mode. You should "
471                          "use a path on your USB device "
472                          "to be able to access your data "
473                          "wherever you are." ),
474                     QMessageBox::Ok,QMessageBox::NoButton );
475                 slot_getKey();
476                 return;
477             }
478             path.replace ( ONMainWindow::U3DevicePath(),
479                            "(U3)" );
480         }
481 #endif
482         key->setText ( path );
483     }
484 }
485 
486 
slot_changeCmd(int var)487 void SessionWidget::slot_changeCmd ( int var )
488 {
489     leCmdIp->setText ( tr ( "Command:" ) );
490     pbAdvanced->hide();
491 #ifdef Q_OS_UNIX
492     cbDirectRDP->hide();
493 #endif
494     leCmdIp->show();
495     cmd->show();
496     if ( var==APPLICATION )
497     {
498         cmd->hide();
499         cmdCombo->setVisible ( true );
500         cmdCombo->setEnabled(true);
501         cmdCombo->lineEdit()->selectAll();
502         cmdCombo->lineEdit()->setFocus();
503     }
504     else
505     {
506         cmdCombo->hide();
507         cmd->setVisible ( true );
508         if ( var==OTHER || var == RDP || var == XDMCP )
509         {
510             cmd->setText ( "" );
511             cmd->setEnabled ( true );
512             cmd->selectAll();
513             cmd->setFocus();
514             if ( var==RDP )
515             {
516                 leCmdIp->setText ( tr ( "Server:" ) );
517                 pbAdvanced->show();
518                 cmd->setText ( rdpServer );
519 #ifdef Q_OS_UNIX
520                 cbDirectRDP->show();
521 #endif
522             }
523             if ( var== XDMCP )
524             {
525                 leCmdIp->setText ( tr ( "XDMCP server:" ) );
526                 cmd->setText ( xdmcpServer );
527 #ifdef Q_OS_UNIX
528                 cbDirectRDP->show();
529                 cbDirectRDP->setText(tr ("direct XDMCP connection"));
530 #endif
531             }
532         }
533         else
534         {
535             cmd->setEnabled ( false );
536             cmd->setText ( "" );
537         }
538     }
539 #ifdef Q_OS_UNIX
540     slot_rdpDirectClicked();
541 #endif
542 }
543 
slot_rdpOptions()544 void SessionWidget::slot_rdpOptions()
545 {
546     bool ok;
547     QString text = QInputDialog::getText (
548                        this,
549                        tr ( "Connect to Windows Terminal Server" ),
550                        tr ( "rdesktop command line options:" ),
551                        QLineEdit::Normal,
552                        rdpOptions, &ok );
553     rdpOptions= text;
554 }
555 
readConfig()556 void SessionWidget::readConfig()
557 {
558 
559     X2goSettings st ( "sessions" );
560     QString name=st.setting()->value (
561                      sessionId+"/name",
562                      ( QVariant ) tr ( "New session" ) ).toString().trimmed();
563 
564     QStringList tails=name.split("/",QString::SkipEmptyParts);
565     QString path;
566     if(tails.count()>0)
567     {
568         name=tails.last();
569         tails.pop_back();
570         path=tails.join("/")+"/";
571     }
572     lPath->setText(path);
573     if(newSession)
574         lPath->setText(parent->getSessionExplorer()->getCurrentPath()+"/");
575 
576     sessName->setText (name);
577 
578     sessIcon = wrap_legacy_resource_URIs (st.setting ()->value (sessionId+"/icon",
579                                                                 (QVariant) ":/img/icons/128x128/x2gosession.png"
580                                                                ).toString ().trimmed ());
581     sessIcon = expandHome (sessIcon);
582     icon->setIcon ( QIcon ( sessIcon ) );
583 
584     server->setText ( st.setting()->value (
585                           sessionId+"/host",
586                           ( QVariant ) QString::null ).toString().trimmed() );
587     uname->setText ( st.setting()->value (
588                          sessionId+"/user",
589                          ( QVariant ) QString::null ).toString().trimmed() );
590     key->setText ( st.setting()->value (
591                        sessionId+"/key",
592                        ( QVariant ) QString::null ).toString().trimmed() );
593     cbAutoLogin->setChecked(st.setting()->value (
594                                 sessionId+"/autologin",
595                                 ( QVariant ) false ).toBool());
596     cbKrbLogin->setChecked(st.setting()->value (
597                                sessionId+"/krblogin",
598                                ( QVariant ) false ).toBool());
599     cbKrbDelegation->setChecked(st.setting()->value (
600                                     sessionId+"/krbdelegation",
601                                     ( QVariant ) false ).toBool());
602     sshPort->setValue (
603         st.setting()->value (
604             sessionId+"/sshport",
605             ( QVariant ) mainWindow->getDefaultSshPort().toInt()
606         ).toInt() );
607 #ifdef Q_OS_UNIX
608     rdpPort->setValue (
609         st.setting()->value (
610             sessionId+"/rdpport",3389
611         ).toInt() );
612 #endif
613 
614 
615     cbProxy->setChecked(st.setting()->value (
616                             sessionId+"/usesshproxy",
617                             false
618                         ).toBool() );
619 
620     QString prtype= st.setting()->value (
621                         sessionId+"/sshproxytype",
622                         "SSH"
623                     ).toString().trimmed() ;
624 
625     if(prtype=="HTTP")
626     {
627         rbHttpProxy->setChecked(true);
628     }
629     else
630     {
631         rbSshProxy->setChecked(true);
632     }
633 
634     proxyLogin->setText(st.setting()->value (
635                             sessionId+"/sshproxyuser",
636                             QString()
637                         ).toString().trimmed() );
638 
639     proxyKey->setText(st.setting()->value (
640                           sessionId+"/sshproxykeyfile",
641                           QString()
642                       ).toString().trimmed() );
643 
644     proxyHost->setText(st.setting()->value (
645                            sessionId+"/sshproxyhost",
646                            QString()
647                        ).toString().trimmed() );
648 
649     proxyPort->setValue(st.setting()->value (
650                             sessionId+"/sshproxyport",
651                             22
652                         ).toInt() );
653 
654     cbProxySamePass->setChecked(st.setting()->value (
655                                     sessionId+"/sshproxysamepass",
656                                     false
657                                 ).toBool() );
658     cbProxySameUser->setChecked(st.setting()->value (
659                                     sessionId+"/sshproxysameuser",
660                                     false
661                                 ).toBool() );
662     cbProxyAutologin->setChecked(st.setting()->value (
663                                      sessionId+"/sshproxyautologin",
664                                      false
665                                  ).toBool() );
666     cbProxyKrbLogin->setChecked(st.setting()->value (
667                                     sessionId+"/sshproxykrblogin",
668                                     false
669                                 ).toBool() );
670 
671 
672     QTimer::singleShot(1, this,SLOT(slot_proxySameLogin()));
673     QTimer::singleShot(2, this,SLOT(slot_proxyType()));
674     QTimer::singleShot(3, this,SLOT(slot_proxyOptions()));
675 
676 
677     QStringList appNames=st.setting()->value (
678                              sessionId+"/applications" ).toStringList();
679     bool rootless=st.setting()->value (
680                       sessionId+"/rootless",false ).toBool();
681     bool published=st.setting()->value (
682                        sessionId+"/published",false ).toBool();
683 
684     QString
685     command=st.setting()->value (
686                 sessionId+"/command",
687                 ( QVariant ) mainWindow->getDefaultCmd() ).toString().trimmed();
688 
689     rdpOptions=st.setting()->value ( sessionId+"/rdpoptions",
690                                      ( QVariant ) "" ).toString().trimmed();
691     rdpServer=st.setting()->value ( sessionId+"/rdpserver",
692                                     ( QVariant ) "" ).toString().trimmed();
693     xdmcpServer=st.setting()->value ( sessionId+"/xdmcpserver",
694                                       ( QVariant ) "localhost" ).toString().trimmed();
695 #ifdef Q_OS_UNIX
696     if(st.setting()->value (sessionId+"/directrdp",false ).toBool())
697     {
698         cbDirectRDP->setChecked(true);
699     }
700     if(st.setting()->value (sessionId+"/directxdmcp",false ).toBool())
701     {
702         cbDirectRDP->setChecked(true);
703     }
704 #endif
705 
706     for ( int i=0; i<appNames.count(); ++i )
707     {
708         QString app=mainWindow->transAppName ( appNames[i] );
709         if ( cmdCombo->findText ( app ) ==-1 )
710             cmdCombo->addItem ( app );
711     }
712     if ( published )
713     {
714         sessBox->setCurrentIndex( PUBLISHED );
715         cmdCombo->setDisabled(true);
716         slot_changeCmd(PUBLISHED);
717     }
718     else if ( rootless )
719     {
720         sessBox->setCurrentIndex ( APPLICATION );
721         QString app=mainWindow->transAppName ( command );
722         cmdCombo->lineEdit()->setText ( app );
723         slot_changeCmd ( APPLICATION );
724     }
725     else
726     {
727         if ( command=="KDE" )
728         {
729             sessBox->setCurrentIndex ( KDE );
730             cmd->setEnabled ( false );
731         }
732         else if ( command=="GNOME" )
733         {
734             sessBox->setCurrentIndex ( GNOME );
735             cmd->setEnabled ( false );
736         }
737         else if ( command=="LXDE" )
738         {
739             sessBox->setCurrentIndex ( LXDE );
740             cmd->setEnabled ( false );
741         }
742         else if (command == "LXQt")
743         {
744             sessBox->setCurrentIndex (LXQt);
745             cmd->setEnabled (false);
746         }
747         else if ( command=="UNITY" )
748         {
749             sessBox->setCurrentIndex ( UNITY );
750             cmd->setEnabled ( false );
751         }
752         else if ( command=="XFCE" )
753         {
754             sessBox->setCurrentIndex ( XFCE );
755             cmd->setEnabled ( false );
756         }
757         else if ( command=="SHADOW" )
758         {
759             sessBox->setCurrentIndex ( SHADOW );
760             cmd->setEnabled ( false );
761         }
762         else if ( command=="RDP" )
763         {
764             leCmdIp->setText ( tr ( "Server:" ) );
765             sessBox->setCurrentIndex ( RDP );
766             cmd->setEnabled ( true );
767             cmd->setText ( rdpServer );
768             pbAdvanced->show();
769 #ifdef Q_OS_UNIX
770             cbDirectRDP->show();
771             slot_rdpDirectClicked();
772 #endif
773         }
774         else if ( command=="XDMCP" )
775         {
776             leCmdIp->setText ( tr ( "XDMCP server:" ) );
777             sessBox->setCurrentIndex ( XDMCP );
778             cmd->setEnabled ( true );
779             cmd->setText ( xdmcpServer );
780 #ifdef Q_OS_UNIX
781             cbDirectRDP->show();
782             slot_rdpDirectClicked();
783 #endif
784         }
785         else
786         {
787             cmd->setText ( command );
788             sessBox->setCurrentIndex ( OTHER );
789             cmd->setEnabled ( true );
790         }
791     }
792     if ( sessName->text() ==tr ( "New session" ) )
793     {
794         sessName->selectAll();
795         sessName->setFocus();
796     }
797 
798     cbKdrive->setChecked(st.setting()->value (sessionId+"/kdrive", false).toBool() );
799 
800 #ifdef Q_OS_UNIX
801     slot_rdpDirectClicked();
802 #endif
803     slot_krbChecked();
804 }
805 
setDefaults()806 void SessionWidget::setDefaults()
807 {
808     cmd->setText ( "" );
809     sessBox->setCurrentIndex ( KDE );
810     cmdCombo->clear();
811     cmdCombo->addItem ( "" );
812     cbKdrive->setChecked(false);
813     cmdCombo->addItems ( mainWindow->transApplicationsNames() );
814     cbAutoLogin->setChecked(false);
815     cbKrbLogin->setChecked(false);
816     cmdCombo->lineEdit()->setText (
817 
818         tr ( "Path to executable" ) );
819     cmdCombo->lineEdit()->selectAll();
820     slot_changeCmd ( 0 );
821     cmd->setEnabled ( false );
822     sessIcon=":/img/icons/128x128/x2gosession.png";
823     icon->setIcon ( QIcon ( sessIcon ) );
824     sshPort->setValue (
825         mainWindow->getDefaultSshPort().toInt() );
826 #ifdef Q_OS_UNIX
827     rdpPort->setValue (3389);
828 #endif
829 
830 
831 
832     cbProxy->setChecked(false);
833 
834     rbSshProxy->setChecked(true);
835 
836 
837     proxyKey->setText(QString::null);
838 
839 
840     proxyPort->setValue(22);
841 
842     cbProxySamePass->setChecked(false);
843     cbProxySameUser->setChecked(false);
844     cbProxyAutologin->setChecked(false);
845     cbProxyKrbLogin->setChecked(false);
846 
847     QTimer::singleShot(1, this,SLOT(slot_proxySameLogin()));
848     QTimer::singleShot(2, this,SLOT(slot_proxyType()));
849     QTimer::singleShot(3, this,SLOT(slot_proxyOptions()));
850 
851 }
852 
853 
saveSettings()854 void SessionWidget::saveSettings()
855 {
856 
857     X2goSettings st ( "sessions" );
858 
859     QString normPath=(lPath->text()+"/"+sessName->text()).split("/",QString::SkipEmptyParts).join("/");
860 
861     st.setting()->setValue ( sessionId+"/name",
862                              ( QVariant ) normPath.trimmed() );
863     st.setting()->setValue ( sessionId+"/icon",
864                              ( QVariant ) sessIcon );
865     st.setting()->setValue ( sessionId+"/host",
866                              ( QVariant ) server->text().trimmed() );
867     st.setting()->setValue ( sessionId+"/user",
868                              ( QVariant ) uname->text().trimmed() );
869 
870     st.setting()->setValue ( sessionId+"/key",
871                              ( QVariant ) key->text().trimmed() );
872 #ifdef Q_OS_UNIX
873     st.setting()->setValue ( sessionId+"/rdpport",
874                              ( QVariant ) rdpPort->value() );
875 #endif
876     st.setting()->setValue ( sessionId+"/sshport",
877                              ( QVariant ) sshPort->value() );
878     st.setting()->setValue(sessionId+"/autologin",( QVariant ) cbAutoLogin->isChecked());
879     st.setting()->setValue(sessionId+"/krblogin",( QVariant ) cbKrbLogin->isChecked());
880     st.setting()->setValue(sessionId+"/krbdelegation",( QVariant ) cbKrbDelegation->isChecked());
881 #ifdef Q_OS_UNIX
882     st.setting()->setValue(sessionId+"/directrdp",( QVariant ) cbDirectRDP->isChecked());
883     st.setting()->setValue(sessionId+"/directxdmcp",( QVariant ) cbDirectRDP->isChecked());
884 #endif
885 
886     st.setting()->setValue(sessionId+"/kdrive",( QVariant ) cbKdrive->isChecked());
887     QString command;
888     bool rootless=false;
889     bool published=false;
890 
891 
892     if ( sessBox->currentIndex() < OTHER )
893         command=sessBox->currentText();
894     else
895         command=cmd->text().trimmed();
896     if ( sessBox->currentIndex() == RDP )
897     {
898         command="RDP";
899         rdpServer=cmd->text().trimmed();
900     }
901     if ( sessBox->currentIndex() == XDMCP )
902     {
903         command="XDMCP";
904         xdmcpServer=cmd->text().trimmed();
905     }
906     if ( sessBox->currentIndex() == SHADOW )
907     {
908         command="SHADOW";
909     }
910 
911     QStringList appList;
912     for ( int i=-1; i<cmdCombo->count(); ++i )
913     {
914         QString app;
915         if ( i==-1 )
916             app=mainWindow->internAppName (
917                     cmdCombo->lineEdit()->text () );
918         else
919             app=mainWindow->internAppName ( cmdCombo->itemText ( i ) );
920         if ( appList.indexOf ( app ) ==-1 && app!="" &&
921                 app!=tr ( "Path to executable" ) )
922         {
923             appList.append ( app );
924         }
925     }
926     if ( sessBox->currentIndex() ==APPLICATION )
927     {
928         rootless=true;
929         command=mainWindow->internAppName ( cmdCombo->lineEdit()->text().trimmed() );
930     }
931     if ( sessBox->currentIndex() == PUBLISHED)
932         published=true;
933 
934     st.setting()->setValue ( sessionId+"/rootless", ( QVariant ) rootless );
935     st.setting()->setValue ( sessionId+"/published", ( QVariant ) published );
936     st.setting()->setValue ( sessionId+"/applications",
937                              ( QVariant ) appList );
938     st.setting()->setValue ( sessionId+"/command",
939                              ( QVariant ) command );
940     st.setting()->setValue ( sessionId+"/rdpoptions",
941                              ( QVariant ) rdpOptions );
942     st.setting()->setValue ( sessionId+"/rdpserver",
943                              ( QVariant ) rdpServer );
944     st.setting()->setValue ( sessionId+"/xdmcpserver",
945                              ( QVariant ) xdmcpServer );
946 
947 
948     st.setting()->setValue (
949         sessionId+"/usesshproxy",cbProxy->isChecked());
950 
951 
952     if(rbHttpProxy->isChecked())
953     {
954         st.setting()->setValue ( sessionId+"/sshproxytype","HTTP");
955     }
956     else
957     {
958         st.setting()->setValue ( sessionId+"/sshproxytype","SSH");
959     }
960     st.setting()->setValue (sessionId+"/sshproxyuser",proxyLogin->text().trimmed());
961     st.setting()->setValue (sessionId+"/sshproxykeyfile",proxyKey->text().trimmed());
962     st.setting()->setValue (sessionId+"/sshproxyhost",proxyHost->text().trimmed());
963     st.setting()->setValue (sessionId+"/sshproxyport",proxyPort->value());
964     st.setting()->setValue (sessionId+"/sshproxysamepass",cbProxySamePass->isChecked());
965     st.setting()->setValue (sessionId+"/sshproxysameuser",cbProxySameUser->isChecked());
966     st.setting()->setValue (sessionId+"/sshproxyautologin",cbProxyAutologin->isChecked());
967     st.setting()->setValue (sessionId+"/sshproxykrblogin",cbProxyKrbLogin->isChecked());
968 
969     st.setting()->sync();
970 }
971 
sessionName()972 QString SessionWidget::sessionName()
973 {
974     return sessName->text();
975 }
976 
977 #ifdef Q_OS_UNIX
slot_emitSettings()978 void SessionWidget::slot_emitSettings()
979 {
980     emit settingsChanged(server->text(), QString::number( rdpPort->value()), uname->text());
981 }
982 #endif
983 
slot_krbChecked()984 void SessionWidget::slot_krbChecked()
985 {
986     cbKrbDelegation->setEnabled(cbKrbLogin->isChecked());
987 }
988 
slot_openFolder()989 void SessionWidget::slot_openFolder()
990 {
991     FolderExplorer explorer(lPath->text(), parent->getSessionExplorer(), this);
992     if(explorer.exec()==QDialog::Accepted)
993     {
994         lPath->setText(explorer.getCurrentPath());
995     }
996 }
997