~x2go/x2go/x2goclient_master

« back to all changes in this revision

Viewing changes to sessionwidget.cpp

  • Committer: Mihai Moldovan
  • Date: 2015-03-04 20:15:47 UTC
  • Revision ID: git-v1:b7398771a7abd84ddcff407063edb95dd0a205d3
general: move *.cpp and *.h files to src/ and *.ts files to src/i18n/.

Show diffs side-by-side

added added

removed removed

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