~x2go/x2go/x2goclient_master

« back to all changes in this revision

Viewing changes to src/sessionbutton.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 "sessionbutton.h"
 
19
#include "x2goclientconfig.h"
 
20
#include "x2goutils.h"
 
21
 
 
22
#include <QFont>
 
23
#include <QPixmap>
 
24
#include <QLabel>
 
25
#include "x2gosettings.h"
 
26
#include <QDir>
 
27
#include <QLayout>
 
28
#include <QComboBox>
 
29
#include <QMouseEvent>
 
30
#include <QMenu>
 
31
#include <QPushButton>
 
32
#include "onmainwindow.h"
 
33
#include "x2gologdebug.h"
 
34
#include <QApplication>
 
35
#include <QDesktopWidget>
 
36
#include "sessionexplorer.h"
 
37
 
 
38
 
 
39
SessionButton::SessionButton ( ONMainWindow* mw,QWidget *parent, QString id )
 
40
    : SVGFrame ( ":/svg/sessionbut.svg",false,parent )
 
41
{
 
42
    editable=mw->sessionEditEnabled();
 
43
 
 
44
 
 
45
    QPalette pal=palette();
 
46
    pal.setColor ( QPalette::Active, QPalette::WindowText, QPalette::Mid );
 
47
    pal.setColor ( QPalette::Active, QPalette::ButtonText, QPalette::Mid );
 
48
    pal.setColor ( QPalette::Active, QPalette::Text, QPalette::Mid );
 
49
    pal.setColor ( QPalette::Inactive, QPalette::WindowText, QPalette::Mid );
 
50
    pal.setColor ( QPalette::Inactive, QPalette::ButtonText, QPalette::Mid );
 
51
    pal.setColor ( QPalette::Inactive, QPalette::Text, QPalette::Mid );
 
52
 
 
53
    setPalette(pal);
 
54
 
 
55
 
 
56
 
 
57
    QFont fnt=font();
 
58
    if ( mw->retMiniMode() )
 
59
#ifdef Q_WS_HILDON
 
60
        fnt.setPointSize ( 10 );
 
61
#else
 
62
        fnt.setPointSize ( 9 );
 
63
#endif
 
64
    setFont ( fnt );
 
65
    setFocusPolicy ( Qt::NoFocus );
 
66
    bool miniMode=mw->retMiniMode();
 
67
    if ( !miniMode )
 
68
        setFixedSize ( 340,190 );
 
69
    else
 
70
        setFixedSize ( 250,145 );
 
71
 
 
72
 
 
73
    par= mw;
 
74
    connect ( this,SIGNAL ( clicked() ),this,SLOT ( slotClicked() ) );
 
75
 
 
76
    sid=id;
 
77
 
 
78
    cmdBox=new QComboBox ( this );
 
79
    cmdBox->setMouseTracking ( true );
 
80
    cmdBox->setFrame ( false );
 
81
    QPalette cpal=cmdBox->palette();
 
82
 
 
83
    cpal.setColor ( QPalette::Button,QColor ( 255,255,255 ) );
 
84
    cpal.setColor ( QPalette::Base,QColor ( 255,255,255 ) );
 
85
    cpal.setColor ( QPalette::Window,QColor ( 255,255,255 ) );
 
86
    cmdBox->setPalette ( cpal );
 
87
 
 
88
    geomBox=new QComboBox ( this );
 
89
    geomBox->setMouseTracking ( true );
 
90
    geomBox->setFrame ( false );
 
91
    geomBox->setEditable ( true );
 
92
    geomBox->setEditable ( false );
 
93
    geomBox->update();
 
94
    geomBox->setPalette ( cpal );
 
95
 
 
96
    sessName=new QLabel ( this );
 
97
    sessStatus=new QLabel ( this );
 
98
    fnt=sessName->font();
 
99
    fnt.setBold ( true );
 
100
    sessName->setFont ( fnt );
 
101
    icon=new QLabel ( this );
 
102
    cmd=new QLabel ( this );
 
103
    cmd->setMouseTracking ( true );
 
104
    serverIcon=new QLabel ( this );
 
105
    geomIcon=new QLabel ( this );
 
106
    geomIcon->setMouseTracking ( true );
 
107
    cmdIcon=new QLabel ( this );
 
108
    cmdIcon->setMouseTracking ( true );
 
109
    server=new QLabel ( this );
 
110
    geom=new QLabel ( this );
 
111
    geom->setMouseTracking ( true );
 
112
 
 
113
    sound=new QPushButton ( this );
 
114
    soundIcon=new QLabel ( this );
 
115
    sound->setPalette ( cpal );
 
116
    sound->setFlat ( true );
 
117
    sound->setMouseTracking ( true );
 
118
    connect ( sound,SIGNAL ( clicked() ),this,
 
119
              SLOT ( slot_soundClicked() ) );
 
120
 
 
121
    editBut=new QPushButton ( this );
 
122
    editBut->setMouseTracking ( true );
 
123
    connect ( editBut,SIGNAL ( pressed() ),this,SLOT ( slotShowMenu() ) );
 
124
    editBut->setIcon ( QIcon ( par->iconsPath ( "/16x16/preferences.png" ) ) );
 
125
    editBut->setIconSize ( QSize ( 16,16 ) );
 
126
    editBut->setFixedSize ( 24,24 );
 
127
    editBut->setFlat ( true );
 
128
    editBut->setPalette ( cpal );
 
129
    sessMenu=new QMenu ( this );
 
130
 
 
131
    connect ( sessMenu,SIGNAL ( aboutToHide() ),this,
 
132
              SLOT ( slotMenuHide() ) );
 
133
 
 
134
    act_edit=sessMenu->addAction (
 
135
                 QIcon (
 
136
                     mw->iconsPath ( "/16x16/edit.png" ) ),
 
137
                 tr ( "Session preferences..." ) );
 
138
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
 
139
    act_createIcon=sessMenu->addAction (
 
140
                       QIcon ( mw->iconsPath ( "/16x16/create_file.png" ) ),
 
141
                       tr (
 
142
                           "Create session icon on desktop..." ) );
 
143
#endif
 
144
    act_remove=sessMenu->addAction (
 
145
                   QIcon ( mw->iconsPath ( "/16x16/delete.png" ) ),
 
146
                   tr ( "Delete session" ) );
 
147
 
 
148
 
 
149
    connect ( act_edit,SIGNAL ( triggered ( bool ) ),this,
 
150
              SLOT ( slotEdit() ) );
 
151
 
 
152
    connect ( act_remove,SIGNAL ( triggered ( bool ) ),this,
 
153
              SLOT ( slotRemove() ) );
 
154
#if (!defined Q_WS_HILDON) && (!defined Q_OS_DARWIN)
 
155
    connect ( act_createIcon,SIGNAL ( triggered ( bool ) ),this,
 
156
              SLOT ( slotCreateSessionIcon() ) );
 
157
#endif
 
158
 
 
159
    editBut->setToolTip ( tr ( "Session actions" ) );
 
160
    cmdBox->setToolTip ( tr ( "Select type" ) );
 
161
 
 
162
    geomBox->setToolTip ( tr ( "Select resolution" ) );
 
163
    sound->setToolTip ( tr ( "Toggle sound support" ) );
 
164
    icon->move ( 10,10 );
 
165
 
 
166
    if ( !miniMode )
 
167
    {
 
168
        sessName->move ( 80,34 );
 
169
        sessStatus->move(80,50);
 
170
        editBut->move ( 307,156 );
 
171
        serverIcon->move ( 58,84 );
 
172
        server->move ( 80,84 );
 
173
        cmdIcon->move ( 58,108 );
 
174
        cmd->move ( 80,108 );
 
175
        cmdBox->move ( 80,108 );
 
176
        geomIcon->move ( 58,132 );
 
177
        geom->move ( 80,132 );
 
178
        geomBox->move ( 80,132 );
 
179
        soundIcon->move ( 58,156 );
 
180
        sound->move ( 76,156 );
 
181
    }
 
182
    else
 
183
    {
 
184
        editBut->move ( 218,113 );
 
185
        sessName->move ( 64,11 );
 
186
        sessStatus->hide();
 
187
        serverIcon->move ( 66,44 );
 
188
        server->move ( 88,44 );
 
189
        cmdIcon->move ( 66,68 );
 
190
        cmd->move ( 88,68 );
 
191
        cmdBox->move ( 88,68 );
 
192
        geomIcon->move ( 66,92 );
 
193
        geom->move ( 88,92 );
 
194
        geomBox->move ( 88,92 );
 
195
        soundIcon->move ( 66,116 );
 
196
        sound->move ( 86,116 );
 
197
    }
 
198
 
 
199
    if (mw->brokerMode)
 
200
    {
 
201
        icon->move(10,30);
 
202
        sessName->move(90,50);
 
203
        sessStatus->move(90,70);
 
204
        setFixedHeight(120);
 
205
    }
 
206
 
 
207
 
 
208
    cmdBox->hide();
 
209
    geomBox->hide();
 
210
    QPixmap spix;
 
211
    spix.load ( par->iconsPath ( "/16x16/session.png" ) );
 
212
    serverIcon->setPixmap ( spix );
 
213
    serverIcon->setFixedSize ( 16,16 );
 
214
 
 
215
    QPixmap rpix;
 
216
    rpix.load ( par->iconsPath ( "/16x16/resolution.png" ) );
 
217
    geomIcon->setPixmap ( rpix );
 
218
    geomIcon->setFixedSize ( 16,16 );
 
219
 
 
220
    QPixmap apix;
 
221
    apix.load ( par->iconsPath ( "/16x16/audio.png" ) );
 
222
    soundIcon->setPixmap ( apix );
 
223
    soundIcon->setFixedSize ( 16,16 );
 
224
    redraw();
 
225
 
 
226
    connect ( cmdBox,SIGNAL ( activated ( const QString& ) ),this,
 
227
              SLOT ( slot_cmd_change ( const QString& ) ) );
 
228
    connect ( geomBox,SIGNAL ( activated ( const QString& ) ),this,
 
229
              SLOT ( slot_geom_change ( const QString& ) ) );
 
230
 
 
231
    editBut->setFocusPolicy ( Qt::NoFocus );
 
232
    sound->setFocusPolicy ( Qt::NoFocus );
 
233
    cmdBox->setFocusPolicy ( Qt::NoFocus );
 
234
    geomBox->setFocusPolicy ( Qt::NoFocus );
 
235
    setMouseTracking(true);
 
236
 
 
237
    if (!editable)
 
238
    {
 
239
        editBut->hide();
 
240
        cmdBox->hide();
 
241
        geomBox->hide();
 
242
        sessMenu->hide();
 
243
        sound->setEnabled(false);
 
244
    }
 
245
    if (mw->brokerMode)
 
246
    {
 
247
        cmd->hide();
 
248
        cmdIcon->hide();
 
249
        server->hide();
 
250
        serverIcon->hide();
 
251
        geom->hide();
 
252
        geomIcon->hide();
 
253
        sound->hide();
 
254
        soundIcon->hide();
 
255
    }
 
256
}
 
257
 
 
258
SessionButton::~SessionButton()
 
259
{}
 
260
 
 
261
void SessionButton::slotClicked()
 
262
{
 
263
    emit sessionSelected ( this );
 
264
}
 
265
 
 
266
void SessionButton::slotEdit()
 
267
{
 
268
//      editBut->setFlat ( true );
 
269
    emit signal_edit ( this );
 
270
}
 
271
 
 
272
void SessionButton::slotRemove()
 
273
{
 
274
    emit ( signal_remove ( this ) );
 
275
}
 
276
 
 
277
void SessionButton::redraw()
 
278
{
 
279
    bool snd;
 
280
 
 
281
 
 
282
    X2goSettings *st;
 
283
 
 
284
    if (par->brokerMode)
 
285
        st=new X2goSettings(par->config.iniFile,QSettings::IniFormat);
 
286
    else
 
287
        st= new X2goSettings( "sessions" );
 
288
 
 
289
    QString name=st->setting()->value ( sid+"/name",
 
290
                                        ( QVariant ) tr ( "New Session" ) ).toString();
 
291
 
 
292
    QStringList tails=name.split("/",QString::SkipEmptyParts);
 
293
    if(tails.count()>0)
 
294
    {
 
295
        name=tails.last();
 
296
        tails.pop_back();
 
297
        path=tails.join("/");
 
298
    }
 
299
 
 
300
    sessName->setText (name);
 
301
 
 
302
    QString status=st->setting()->value ( sid+"/status",
 
303
                                          ( QVariant ) QString::null ).toString();
 
304
    if (status == "R")
 
305
    {
 
306
        sessStatus->setText("("+tr("running")+")");
 
307
    }
 
308
    if (status == "S")
 
309
    {
 
310
        sessStatus->setText("("+tr("suspended")+")");
 
311
    }
 
312
 
 
313
    QString sessIcon=st->setting()->value (
 
314
                         sid+"/icon",
 
315
                         ( QVariant )
 
316
                         ":icons/128x128/x2gosession.png"
 
317
                     ).toString();
 
318
    sessIcon = expandHome(sessIcon);
 
319
    QPixmap* pix;
 
320
 
 
321
    if (!par->brokerMode || sessIcon == ":icons/128x128/x2gosession.png")
 
322
        pix=new QPixmap( sessIcon );
 
323
    else
 
324
    {
 
325
        pix=new QPixmap;
 
326
        pix->loadFromData(QByteArray::fromBase64(sessIcon.toAscii()));
 
327
    }
 
328
    if ( !par->retMiniMode() )
 
329
        icon->setPixmap ( pix->scaled ( 64,64,Qt::IgnoreAspectRatio,
 
330
                                        Qt::SmoothTransformation ) );
 
331
    else
 
332
        icon->setPixmap ( pix->scaled ( 48,48,Qt::IgnoreAspectRatio,
 
333
                                        Qt::SmoothTransformation ) );
 
334
 
 
335
    delete pix;
 
336
    QString sv=st->setting()->value ( sid+"/host", ( QVariant )
 
337
                                      QString::null ).toString();
 
338
    QString uname=st->setting()->value ( sid+"/user", ( QVariant )
 
339
                                         QString::null ).toString();
 
340
    server->setText ( uname+"@"+sv );
 
341
 
 
342
    QString command=st->setting()->value ( sid+"/command",
 
343
                                           ( QVariant )
 
344
                                           tr (
 
345
                                                   "KDE" ) ).
 
346
                    toString();
 
347
    rootless=st->setting()->value ( sid+"/rootless",
 
348
                                    false ).toBool();
 
349
    published=st->setting()->value ( sid+"/published",
 
350
                                     false ).toBool();
 
351
 
 
352
 
 
353
    cmdBox->clear();
 
354
    cmdBox->addItem ( "KDE" );
 
355
    cmdBox->addItem ( "GNOME" );
 
356
    cmdBox->addItem ( "LXDE" );
 
357
    cmdBox->addItem ( "XFCE" );
 
358
    cmdBox->addItem ( "MATE" );
 
359
    cmdBox->addItem ( "UNITY" );
 
360
    cmdBox->addItem ( "CINNAMON" );
 
361
    cmdBox->addItem ( "TRINITY" );
 
362
    cmdBox->addItem ( "OPENBOX" );
 
363
    cmdBox->addItem ( "ICEWM" );
 
364
    cmdBox->addItem ( tr ( "RDP connection" ) );
 
365
    cmdBox->addItem ( tr ( "XDMCP" ) );
 
366
    cmdBox->addItem ( tr ( "Connection to local desktop" ) );
 
367
    cmdBox->addItem ( tr ( "Published applications" ) );
 
368
 
 
369
    cmdBox->addItems ( par->transApplicationsNames() );
 
370
 
 
371
    bool directRDP=false;
 
372
    QPixmap cmdpix;
 
373
    if ( command=="KDE" )
 
374
    {
 
375
        cmdpix.load ( par->iconsPath ( "/16x16/kde.png" ) );
 
376
        cmdBox->setCurrentIndex ( KDE );
 
377
    }
 
378
    else if ( command =="GNOME" )
 
379
    {
 
380
        cmdpix.load ( par->iconsPath ( "/16x16/gnome.png" ) );
 
381
        cmdBox->setCurrentIndex ( GNOME );
 
382
    }
 
383
    else if ( command =="UNITY" )
 
384
    {
 
385
        cmdpix.load ( par->iconsPath ( "/16x16/unity.png" ) );
 
386
        cmdBox->setCurrentIndex ( UNITY );
 
387
    }
 
388
    else if ( command == "XFCE" )
 
389
    {
 
390
        cmdpix.load ( par->iconsPath ( "/16x16/xfce.png" ) );
 
391
        cmdBox->setCurrentIndex ( XFCE );
 
392
    }
 
393
    else if ( command == "MATE" )
 
394
    {
 
395
        cmdpix.load ( par->iconsPath ( "/16x16/mate.png" ) );
 
396
        cmdBox->setCurrentIndex ( MATE );
 
397
    }
 
398
    else if ( command =="LXDE" )
 
399
    {
 
400
        cmdpix.load ( par->iconsPath ( "/16x16/lxde.png" ) );
 
401
        cmdBox->setCurrentIndex ( LXDE );
 
402
    }
 
403
    else if ( command == "CINNAMON" )
 
404
    {
 
405
        cmdpix.load ( par->iconsPath ( "/16x16/cinnamon.png" ) );
 
406
        cmdBox->setCurrentIndex ( CINNAMON );
 
407
    }
 
408
    else if ( command == "TRINITY" )
 
409
    {
 
410
        cmdpix.load ( par->iconsPath ( "/16x16/trinity.png" ) );
 
411
        cmdBox->setCurrentIndex ( TRINITY );
 
412
    }
 
413
    else if ( command == "OPENBOX" )
 
414
    {
 
415
        cmdpix.load ( par->iconsPath ( "/16x16/openbox.png" ) );
 
416
        cmdBox->setCurrentIndex ( OPENBOX );
 
417
    }
 
418
    else if ( command == "ICEWM" )
 
419
    {
 
420
        cmdpix.load ( par->iconsPath ( "/16x16/icewm.png" ) );
 
421
        cmdBox->setCurrentIndex ( ICEWM );
 
422
    }
 
423
    else if ( command =="SHADOW" )
 
424
    {
 
425
        cmdpix.load ( par->iconsPath ( "/16x16/X.png" ) );
 
426
        cmdBox->setCurrentIndex ( SHADOW );
 
427
        command=tr ( "Connection to local desktop" );
 
428
    }
 
429
    else if ( command =="RDP" )
 
430
    {
 
431
        if (st->setting()->value ( sid+"/directrdp",
 
432
                                   ( QVariant ) false ).toBool())
 
433
            directRDP=true;
 
434
        cmdpix.load ( par->iconsPath ( "/16x16/rdp.png" ) );
 
435
        cmdBox->setCurrentIndex ( RDP );
 
436
        command=tr ( "RDP connection" );
 
437
    }
 
438
    else if ( command =="XDMCP" )
 
439
    {
 
440
        cmdpix.load ( par->iconsPath ( "/16x16/X.png" ) );
 
441
        cmdBox->setCurrentIndex ( XDMCP );
 
442
        command=tr ( "XDMCP" );
 
443
    }
 
444
    else if (published)
 
445
    {
 
446
        cmdpix.load ( par->iconsPath ( "/16x16/X.png" ) );
 
447
        command=tr ("Published applications");
 
448
        cmdBox->setCurrentIndex (PUBLISHED);
 
449
    }
 
450
    else
 
451
    {
 
452
        cmdpix.load ( par->iconsPath ( "/16x16/X.png" ) );
 
453
        command=par->transAppName ( command );
 
454
        int id= cmdBox->findText ( command );
 
455
        if ( id ==-1 )
 
456
        {
 
457
            cmdBox->addItem ( command );
 
458
            cmdBox->setCurrentIndex ( cmdBox->count()-1 );
 
459
        }
 
460
        else
 
461
            cmdBox->setCurrentIndex ( id );
 
462
    }
 
463
 
 
464
 
 
465
 
 
466
    cmdIcon->setPixmap ( cmdpix );
 
467
    cmd->setText ( command );
 
468
 
 
469
 
 
470
    geomBox->clear();
 
471
    geomBox->addItem ( tr ( "fullscreen" ) );
 
472
    uint displays=QApplication::desktop()->numScreens();
 
473
    if (!directRDP)
 
474
        for (uint i=0; i<displays; ++i)
 
475
        {
 
476
            geomBox->addItem ( tr( "Display " )+QString::number(i+1));
 
477
 
 
478
            //add maximun available area
 
479
            geomBox->addItem( QString::number(QApplication::desktop()->availableGeometry(i).width()) + "x" + QString::number(QApplication::desktop()->availableGeometry(i).height()));
 
480
 
 
481
 
 
482
        }
 
483
#ifndef Q_WS_HILDON
 
484
 
 
485
 
 
486
    geomBox->addItem ( "1440x900" );
 
487
    geomBox->addItem ( "1280x1024" );
 
488
    geomBox->addItem ( "1024x768" );
 
489
    geomBox->addItem ( "800x600" );
 
490
#else
 
491
    geomBox->addItem ( tr ( "window" ) );
 
492
#endif
 
493
    if ( st->setting()->value ( sid+"/fullscreen",
 
494
                                ( QVariant ) false ).toBool() )
 
495
    {
 
496
        geom->setText ( tr ( "fullscreen" ) );
 
497
    }
 
498
    else if (st->setting()->value ( sid+"/multidisp",
 
499
                                    ( QVariant ) false ).toBool() && !directRDP)
 
500
    {
 
501
        uint disp=st->setting()->value ( sid+"/display",
 
502
                                         ( QVariant ) 1 ).toUInt();
 
503
        if (disp<=displays)
 
504
        {
 
505
            geom->setText( tr( "Display " )+QString::number(disp));
 
506
        }
 
507
        else
 
508
        {
 
509
            geom->setText( tr( "Display " )+QString::number(1));
 
510
        }
 
511
        for (int i=0; i<geomBox->count(); ++i)
 
512
            if (geomBox->itemText(i)==geom->text())
 
513
            {
 
514
                geomBox->setCurrentIndex(i);
 
515
                break;
 
516
            }
 
517
    }
 
518
    else
 
519
    {
 
520
#ifndef Q_WS_HILDON
 
521
        QString g=QString::number ( st->setting()->value (
 
522
                                        sid+"/width" ).toInt() );
 
523
        g+="x"+QString::number ( st->setting()->value (
 
524
                                     sid+"/height" ).toInt() );
 
525
        geom->setText ( g );
 
526
        if ( geomBox->findText ( g ) ==-1 )
 
527
            geomBox->addItem ( g );
 
528
        geomBox->setCurrentIndex ( geomBox->findText ( g ) );
 
529
#else
 
530
        geom->setText ( tr ( "window" ) );
 
531
        geomBox->setCurrentIndex ( 1 );
 
532
#endif
 
533
    }
 
534
 
 
535
    if (directRDP)
 
536
    {
 
537
        geomBox->addItem ( tr("Maximum") );
 
538
        if (st->setting()->value ( sid+"/maxdim",
 
539
                                   ( QVariant ) false ).toBool())
 
540
        {
 
541
            geom->setText ( tr("Maximum") );
 
542
            geomBox->setCurrentIndex ( geomBox->findText ( tr("Maximum") ));
 
543
        }
 
544
    }
 
545
 
 
546
 
 
547
    snd=st->setting()->value ( sid+"/sound", ( QVariant ) true ).toBool();
 
548
    if ( snd )
 
549
        sound->setText ( tr ( "Enabled" ) );
 
550
    else
 
551
        sound->setText ( tr ( "Disabled" ) );
 
552
    soundIcon->setEnabled ( snd );
 
553
    QFontMetrics fm ( sound->font() );
 
554
    sound->setFixedSize ( fm.size ( Qt::TextSingleLine,sound->text() ) +
 
555
                          QSize ( 8,4 ) );
 
556
 
 
557
    sessName->setMinimumSize ( sessName->sizeHint() );
 
558
    geom->setMinimumSize ( geom->sizeHint() );
 
559
    cmd->setMinimumSize ( cmd->sizeHint() );
 
560
    server->setMinimumSize ( server->sizeHint() );
 
561
    delete st;
 
562
}
 
563
 
 
564
void SessionButton::mousePressEvent ( QMouseEvent * event )
 
565
{
 
566
    SVGFrame::mousePressEvent ( event );
 
567
    loadBg ( ":/svg/sessionbut_grey.svg" );
 
568
}
 
569
 
 
570
void SessionButton::mouseReleaseEvent ( QMouseEvent * event )
 
571
{
 
572
    SVGFrame::mouseReleaseEvent ( event );
 
573
    int x=event->x();
 
574
    int y=event->y();
 
575
    loadBg ( ":/svg/sessionbut.svg" );
 
576
    if ( x>=0 && x< width() && y>=0 && y<height() )
 
577
        emit clicked();
 
578
}
 
579
 
 
580
void SessionButton::mouseMoveEvent ( QMouseEvent * event )
 
581
{
 
582
 
 
583
    SVGFrame::mouseMoveEvent ( event );
 
584
    if (!editable)
 
585
        return;
 
586
    if ( cmd->isVisible() )
 
587
        if ( event->x() > cmd->x() && event->x() < cmd->x() +
 
588
                cmd->width() &&
 
589
                event->y() >cmd->y() && event->y() <cmd->y() +
 
590
                cmd->height() )
 
591
        {
 
592
            if ( cmdBox->width() <cmd->width() )
 
593
                cmdBox->setFixedWidth ( cmd->width() +20 );
 
594
            if ( cmdBox->height() !=cmd->height() )
 
595
                cmdBox->setFixedHeight ( cmd->height() );
 
596
            cmd->hide();
 
597
            cmdBox->show();
 
598
        }
 
599
    if ( cmdBox->isVisible() )
 
600
        if ( event->x() < cmdBox->x() || event->x() > cmdBox->x() +
 
601
                cmdBox->width() ||
 
602
                event->y() <cmdBox->y() || event->y() >cmdBox->y() +
 
603
                cmdBox->height() )
 
604
        {
 
605
            cmdBox->hide();
 
606
            cmd->show();
 
607
        }
 
608
 
 
609
 
 
610
    if ( sound->isFlat() )
 
611
    {
 
612
        if ( event->x() > sound->x() && event->x() < sound->x() +
 
613
                sound->width() &&
 
614
                event->y() >sound->y() && event->y() <sound->y() +
 
615
                sound->height() )
 
616
        {
 
617
            sound->setFlat ( false );
 
618
        }
 
619
    }
 
620
    else
 
621
    {
 
622
        if ( event->x() < sound->x() || event->x() > sound->x() +
 
623
                sound->width() ||
 
624
                event->y() <sound->y() || event->y() >sound->y() +
 
625
                sound->height() )
 
626
        {
 
627
            sound->setFlat ( true );
 
628
        }
 
629
    }
 
630
 
 
631
 
 
632
    if ( editBut->isFlat() )
 
633
    {
 
634
        if ( event->x() > editBut->x() && event->x() < editBut->x() +
 
635
                editBut->width() &&
 
636
                event->y() >editBut->y() && event->y() <editBut->y() +
 
637
                editBut->height() )
 
638
            editBut->setFlat ( false );
 
639
    }
 
640
    else
 
641
    {
 
642
        if ( event->x() < editBut->x() || event->x() > editBut->x() +
 
643
                editBut->width() ||
 
644
                event->y() <editBut->y() || event->y() >editBut->y() +
 
645
                editBut->height() )
 
646
            editBut->setFlat ( true );
 
647
    }
 
648
 
 
649
    if ( geom->isVisible() )
 
650
        if ( event->x() > geom->x() && event->x() < geom->x() +
 
651
                geom->width() &&
 
652
                event->y() >geom->y() && event->y() <geom->y() +
 
653
                geom->height() )
 
654
        {
 
655
            if ( geomBox->width() <geom->width() )
 
656
                geomBox->setFixedWidth ( geom->width() +20 );
 
657
            if ( geomBox->height() !=geom->height() )
 
658
                geomBox->setFixedHeight ( geom->height() );
 
659
            geom->hide();
 
660
            geomBox->show();
 
661
        }
 
662
    if ( geomBox->isVisible() )
 
663
        if ( event->x() < geomBox->x() || event->x() > geomBox->x() +
 
664
                geomBox->width() ||
 
665
                event->y() <geomBox->y() || event->y() >geomBox->y() +
 
666
                geomBox->height() )
 
667
        {
 
668
            geomBox->hide();
 
669
            geom->show();
 
670
        }
 
671
}
 
672
 
 
673
 
 
674
void SessionButton::slot_soundClicked()
 
675
{
 
676
    bool snd=!soundIcon->isEnabled();
 
677
    soundIcon->setEnabled ( snd );
 
678
    if ( snd )
 
679
        sound->setText ( tr ( "Enabled" ) );
 
680
    else
 
681
        sound->setText ( tr ( "Disabled" ) );
 
682
    QFontMetrics fm ( sound->font() );
 
683
    sound->setFixedSize ( fm.size ( Qt::TextSingleLine,sound->text() ) +
 
684
                          QSize ( 8,4 ) );
 
685
 
 
686
    X2goSettings st ( "sessions" );
 
687
    st.setting()->setValue ( sid+"/sound", ( QVariant ) snd );
 
688
    st.setting()->sync();
 
689
 
 
690
 
 
691
}
 
692
 
 
693
void SessionButton::slot_cmd_change ( const QString& command )
 
694
{
 
695
    cmd->setText ( command );
 
696
    QPixmap pix;
 
697
    bool newRootless=rootless;
 
698
    published=false;
 
699
    QString cmd=command;
 
700
    if ( command=="KDE" )
 
701
    {
 
702
        newRootless=false;
 
703
        pix.load ( par->iconsPath ( "/16x16/kde.png" ) );
 
704
    }
 
705
    else if ( command =="GNOME" )
 
706
    {
 
707
        newRootless=false;
 
708
        pix.load ( par->iconsPath ( "/16x16/gnome.png" ) );
 
709
    }
 
710
    else if ( command =="LXDE" )
 
711
    {
 
712
        newRootless=false;
 
713
        pix.load ( par->iconsPath ( "/16x16/lxde.png" ) );
 
714
    }
 
715
    else if ( command =="UNITY" )
 
716
    {
 
717
        newRootless=false;
 
718
        pix.load ( par->iconsPath ( "/16x16/unity.png" ) );
 
719
    }
 
720
    else if ( command == "XFCE" )
 
721
    {
 
722
        newRootless=false;
 
723
        pix.load ( par->iconsPath ( "/16x16/xfce.png" ) );
 
724
    }
 
725
    else if ( command == "MATE" )
 
726
    {
 
727
        newRootless=false;
 
728
        pix.load ( par->iconsPath ( "/16x16/mate.png" ) );
 
729
    }
 
730
    else if ( command == "CINNAMON" )
 
731
    {
 
732
        newRootless=false;
 
733
        // As of 2014-10-01, Cinnamon does not have a logo. This icon is the
 
734
        // gear, which is the default start menu icon as of 2.2.
 
735
        pix.load ( par->iconsPath ( "/16x16/cinnamon.png" ) );
 
736
    }
 
737
    else if ( command == "TRINITY" )
 
738
    {
 
739
        newRootless=false;
 
740
        pix.load ( par->iconsPath ( "/16x16/trinity.png" ) );
 
741
    }
 
742
    else if ( command == "OPENBOX" )
 
743
    {
 
744
        newRootless=false;
 
745
        pix.load ( par->iconsPath ( "/16x16/openbox.png" ) );
 
746
    }
 
747
    else if ( command == "ICEWM" )
 
748
    {
 
749
        newRootless=false;
 
750
        pix.load ( par->iconsPath ( "/16x16/icewm.png" ) );
 
751
    }
 
752
    else if ( command ==tr ( "Connection to local desktop" ) )
 
753
    {
 
754
        newRootless=false;
 
755
        pix.load ( par->iconsPath ( "/16x16/X.png" ) );
 
756
        cmd="SHADOW";
 
757
    }
 
758
    else if ( command == tr ( "RDP connection" ) )
 
759
    {
 
760
        newRootless=false;
 
761
        pix.load ( par->iconsPath ( "/16x16/rdp.png" ) );
 
762
        cmd="RDP";
 
763
    }
 
764
    else if ( command == tr ( "XDMCP" ) )
 
765
    {
 
766
        newRootless=false;
 
767
        pix.load ( par->iconsPath ( "/16x16/X.png" ) );
 
768
        cmd="XDMCP";
 
769
    }
 
770
    else
 
771
        pix.load ( par->iconsPath ( "/16x16/X.png" ) );
 
772
    cmdIcon->setPixmap ( pix );
 
773
 
 
774
    X2goSettings st ( "sessions" );
 
775
    if ( command=="startkde" )
 
776
    {
 
777
        cmd="KDE";
 
778
        newRootless=false;
 
779
    }
 
780
    if ( command=="gnome-session" )
 
781
    {
 
782
        cmd="GNOME";
 
783
        newRootless=false;
 
784
    }
 
785
    if ( command=="LXDE" )
 
786
    {
 
787
        cmd="LXDE";
 
788
        newRootless=false;
 
789
    }
 
790
    if ( command=="unity" )
 
791
    {
 
792
        cmd="UNITY";
 
793
        newRootless=false;
 
794
    }
 
795
    if ( command=="xfce4-session" )
 
796
    {
 
797
        cmd="XFCE";
 
798
        newRootless=false;
 
799
    }
 
800
    if ( command=="mate-session" )
 
801
    {
 
802
        cmd="MATE";
 
803
        newRootless=false;
 
804
    }
 
805
    if ( command=="cinnamon-session" )
 
806
    {
 
807
        cmd="CINNAMON";
 
808
        newRootless=false;
 
809
    }
 
810
    if (command== tr("Published applications"))
 
811
    {
 
812
        published=true;
 
813
        cmd="PUBLISHED";
 
814
    }
 
815
    bool found=false;
 
816
    cmd=par->internAppName ( cmd,&found );
 
817
    if ( found )
 
818
        newRootless=true;
 
819
    st.setting()->setValue ( sid+"/command", ( QVariant ) cmd );
 
820
    st.setting()->setValue ( sid+"/rootless", ( QVariant ) newRootless );
 
821
    st.setting()->setValue ( sid+"/published", ( QVariant ) published );
 
822
    st.setting()->sync();
 
823
 
 
824
}
 
825
 
 
826
 
 
827
void SessionButton::slot_geom_change ( const QString& new_g )
 
828
{
 
829
    geom->setText ( new_g );
 
830
    X2goSettings st ( "sessions" );
 
831
    if ( new_g==tr ( "fullscreen" ) )
 
832
    {
 
833
        st.setting()->setValue ( sid+"/fullscreen", ( QVariant ) true );
 
834
        st.setting()->setValue ( sid+"/multidisp", ( QVariant ) false );
 
835
        st.setting()->setValue ( sid+"/maxdim", ( QVariant ) false );
 
836
    }
 
837
    else if ( new_g==tr ( "Maximum" ))
 
838
    {
 
839
        st.setting()->setValue ( sid+"/fullscreen", ( QVariant ) false );
 
840
        st.setting()->setValue ( sid+"/multidisp", ( QVariant ) false );
 
841
        st.setting()->setValue ( sid+"/maxdim", ( QVariant ) true );
 
842
    }
 
843
    else if (new_g.indexOf(tr("Display "))==0)
 
844
    {
 
845
        QString g= new_g;
 
846
        g.replace(tr("Display "),"");
 
847
        st.setting()->setValue ( sid+"/multidisp", ( QVariant ) true );
 
848
        st.setting()->setValue ( sid+"/display", ( QVariant ) g.toUInt());
 
849
        st.setting()->setValue ( sid+"/fullscreen", ( QVariant ) false );
 
850
        st.setting()->setValue ( sid+"/maxdim", ( QVariant ) false );
 
851
    }
 
852
    else
 
853
    {
 
854
        QString new_geom=new_g;
 
855
#ifdef Q_WS_HILDON
 
856
        new_geom="800x600";
 
857
#endif
 
858
        st.setting()->setValue ( sid+"/fullscreen", ( QVariant ) false );
 
859
        st.setting()->setValue ( sid+"/multidisp", ( QVariant ) false );
 
860
        st.setting()->setValue ( sid+"/maxdim", ( QVariant ) false );
 
861
        QStringList lst=new_geom.split ( 'x' );
 
862
        st.setting()->setValue ( sid+"/width", ( QVariant ) lst[0] );
 
863
        st.setting()->setValue ( sid+"/height", ( QVariant ) lst[1] );
 
864
    }
 
865
    st.setting()->sync();
 
866
}
 
867
 
 
868
bool SessionButton::lessThen ( const SessionButton* b1,
 
869
                               const SessionButton* b2 )
 
870
{
 
871
    return b1->sessName->text().toLower().localeAwareCompare (
 
872
               b2->sessName->text().toLower() ) <0;
 
873
}
 
874
 
 
875
QString SessionButton::name()
 
876
{
 
877
    return sessName->text();
 
878
}
 
879
 
 
880
void SessionButton::slotMenuHide()
 
881
{
 
882
    editBut->setDown ( false );
 
883
    editBut->setFlat ( true );
 
884
}
 
885
 
 
886
 
 
887
void SessionButton::slotShowMenu()
 
888
{
 
889
    sessMenu->popup ( mapToGlobal ( QPoint ( editBut->x() +editBut->width(),
 
890
                                    editBut->y() +editBut->height() ) ) );
 
891
}
 
892
 
 
893
 
 
894
void SessionButton::slotCreateSessionIcon()
 
895
{
 
896
    par->getSessionExplorer()->slotCreateDesktopIcon ( this );
 
897
}