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 "connectionwidget.h"
19
20 #include <QPushButton>
21 #include <QLabel>
22 #include <QSlider>
23 #include <QStringList>
24 #include <QGroupBox>
25 #include <QBoxLayout>
26 #include <QSpinBox>
27 #include <QComboBox>
28 #include "x2gosettings.h"
29 #include <QFile>
30 #include <QTextStream>
31 #include <QDir>
32 #include "onmainwindow.h"
ConnectionWidget(QString id,ONMainWindow * mw,QWidget * parent,Qt::WindowFlags f)33 ConnectionWidget::ConnectionWidget ( QString id, ONMainWindow * mw,
34 QWidget * parent, Qt::WindowFlags f )
35 : ConfigWidget ( id,mw,parent,f )
36 {
37 QVBoxLayout *connLay=new QVBoxLayout ( this );
38 #ifndef Q_WS_HILDON
39 QGroupBox* netSpd=new QGroupBox ( tr ( "&Connection speed" ),this );
40 QVBoxLayout *spdLay=new QVBoxLayout ( netSpd );
41 #else
42 QFrame* netSpd=this ;
43 QVBoxLayout *spdLay=new QVBoxLayout ();
44 spdLay->addWidget ( new QLabel ( tr ( "Connection speed:" ),netSpd ) );
45 #endif
46 spd=new QSlider ( Qt::Horizontal,netSpd );
47 spd->setMinimum ( 0 );
48 spd->setMaximum ( 4 );
49 spd->setTickPosition ( QSlider::TicksBelow );
50 spd->setTickInterval ( 1 );
51 spd->setSingleStep ( 1 );
52 spd->setPageStep ( 1 );
53
54 QHBoxLayout *tickLay=new QHBoxLayout();
55 QHBoxLayout *slideLay=new QHBoxLayout();
56 slideLay->addWidget ( spd );
57 QLabel* mlab= new QLabel ( "MODEM",netSpd );
58 tickLay->addWidget ( mlab );
59 tickLay->addStretch();
60 tickLay->addWidget ( new QLabel ( "ISDN",netSpd ) );
61 tickLay->addStretch();
62 tickLay->addWidget ( new QLabel ( "ADSL",netSpd ) );
63 tickLay->addStretch();
64 tickLay->addWidget ( new QLabel ( "WAN",netSpd ) );
65 tickLay->addStretch();
66 tickLay->addWidget ( new QLabel ( "LAN",netSpd ) );
67 spdLay->addLayout ( slideLay );
68 spdLay->addLayout ( tickLay );
69 QFontMetrics fm ( mlab->font() );
70 slideLay->insertSpacing ( 0,fm.width ( "MODEM" ) /2 );
71 slideLay->addSpacing ( fm.width ( "LAN" ) /2 );
72
73 #ifndef Q_WS_HILDON
74 QGroupBox* compr=new QGroupBox ( tr ( "C&ompression" ),this );
75 QHBoxLayout* comprLay=new QHBoxLayout ( compr );
76 #else
77 QFrame* compr=this;
78 QHBoxLayout* comprLay=new QHBoxLayout ();
79 #endif
80 packMethode = new QComboBox ( this );
81 quali= new QSpinBox ( this );
82 quali->setRange ( 0,9 );
83 #ifdef Q_WS_HILDON
84 quali->setFixedHeight ( int ( quali->sizeHint().height() *1.5 ) );
85 #endif
86
87 QVBoxLayout* colLay=new QVBoxLayout();
88 QVBoxLayout* cowLay=new QVBoxLayout();
89 QHBoxLayout* spbl=new QHBoxLayout();
90 #ifndef Q_WS_HILDON
91 colLay->addWidget ( new QLabel ( tr ( "Method:" ),compr ) );
92 #else
93 colLay->addWidget ( new QLabel ( tr ( "Compression method:" ),compr ) );
94 #endif
95 colLay->addWidget ( qualiLabel=new QLabel ( tr ( "Image quality:" ),
96 compr ) );
97 cowLay->addWidget ( packMethode );
98 spbl->addWidget ( quali );
99 spbl->addStretch();
100 cowLay->addLayout ( spbl );
101 comprLay->addLayout ( colLay );
102 comprLay->addLayout ( cowLay );
103 #ifndef Q_WS_HILDON
104 connLay->addWidget ( netSpd );
105 connLay->addWidget ( compr );
106 #else
107 connLay->addLayout ( spdLay );
108 connLay->addLayout ( comprLay );
109 #endif
110 connLay->addStretch();
111
112 connect ( packMethode,SIGNAL ( activated ( const QString& ) ),this,
113 SLOT ( slot_changePack ( const QString& ) ) );
114 readConfig();
115 }
116
117
~ConnectionWidget()118 ConnectionWidget::~ConnectionWidget()
119 {
120 }
121
loadPackMethods()122 void ConnectionWidget::loadPackMethods()
123 {
124 QFile file ( ":/txt/packs" );
125 if ( !file.open ( QIODevice::ReadOnly | QIODevice::Text ) )
126 return;
127 QTextStream in ( &file );
128 while ( !in.atEnd() )
129 {
130 QString pc=in.readLine();
131 if ( pc.indexOf ( "-%" ) !=-1 )
132 {
133 pc=pc.left ( pc.indexOf ( "-%" ) );
134 qualiList<<pc;
135 }
136 packMethode->addItem ( pc );
137 }
138 file.close();
139 }
140
141
slot_changePack(const QString & pc)142 void ConnectionWidget::slot_changePack ( const QString& pc )
143 {
144 bool ct=qualiList.contains ( pc );
145 quali->setEnabled ( ct );
146 qualiLabel->setEnabled ( ct );
147 }
148
readConfig()149 void ConnectionWidget::readConfig()
150 {
151
152 loadPackMethods();
153 X2goSettings st ( "sessions" );
154
155 spd->setValue ( st.setting()->value (
156 sessionId+"/speed",
157 ( QVariant ) mainWindow->getDefaultLink()
158 ).toInt() );
159 QString mt=st.setting()->value (
160 sessionId+"/pack",
161 ( QVariant ) mainWindow->getDefaultPack() ).toString();
162
163
164 packMethode->setCurrentIndex ( packMethode->findText ( mt ) );
165 quali->setValue ( st.setting()->value ( sessionId+"/quality",
166 mainWindow->getDefaultQuality() ).toInt() );
167 slot_changePack ( mt );
168 }
169
170
setDefaults()171 void ConnectionWidget::setDefaults()
172 {
173 spd->setValue ( 2 );
174 packMethode->setCurrentIndex (
175 packMethode->findText ( "16m-jpeg" ) );
176 quali->setValue ( 9 );
177 slot_changePack ( "16m-jpeg" );
178 }
179
saveSettings()180 void ConnectionWidget::saveSettings()
181 {
182
183 X2goSettings st ( "sessions" );
184 st.setting()->setValue ( sessionId+"/speed", ( QVariant ) spd->value() );
185 st.setting()->setValue ( sessionId+"/pack",
186 ( QVariant ) packMethode->currentText() );
187 st.setting()->setValue ( sessionId+"/quality", ( QVariant ) quali->value() );
188 st.setting()->sync();
189 }
190