1
/**************************************************************************
2
* Copyright (C) 2005-2015 by Oleksandr Shneyder *
3
* o.shneyder@phoca-gmbh.de *
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. *
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
***************************************************************************/
18
#include "sharewidget.h"
19
#include "onmainwindow.h"
22
#include <QStandardItemModel>
24
#include <QPushButton>
28
#include <QHeaderView>
30
#include <QTextStream>
31
#include <QMessageBox>
33
#include "x2gologdebug.h"
35
#include <QFileDialog>
37
#include "x2gosettings.h"
39
ShareWidget::ShareWidget ( QString id, ONMainWindow * mw,
40
QWidget * parent, Qt::WindowFlags f )
41
: ConfigWidget ( id,mw,parent,f )
43
QGroupBox *egb=new QGroupBox ( tr ( "&Folders" ),this );
44
expTv=new QTreeView ( egb );
45
expTv->setItemsExpandable ( false );
46
expTv->setRootIsDecorated ( false );
48
model=new QStandardItemModel ( 0,2 );
49
ldir=new QLabel ( egb );
52
model->setHeaderData ( 0,Qt::Horizontal,QVariant (
53
( QString ) tr ( "Path" ) ) );
54
model->setHeaderData ( 1,Qt::Horizontal,QVariant (
55
( QString ) tr ( "Automount" ) ) );
56
expTv->setEditTriggers ( QAbstractItemView::NoEditTriggers );
60
QPushButton* openDir=new QPushButton (
61
QIcon ( mainWindow->iconsPath ( "/16x16/file-open.png" ) ),
64
QPushButton* addDir=new QPushButton ( tr ( "Add" ),egb );
65
QPushButton* delDir=new QPushButton ( tr ( "Delete" ),egb );
67
QSize sz=addDir->sizeHint();
68
sz.setHeight ( ( int ) ( sz.height() /1.5 ) );
69
addDir->setFixedSize ( sz );
70
sz=delDir->sizeHint();
71
sz.setHeight ( ( int ) ( sz.height() /1.5 ) );
72
delDir->setFixedSize ( sz );
75
QLabel *dirPrompt=new QLabel ( tr ( "Path:" ),egb );
76
dirPrompt->setFixedSize ( dirPrompt->sizeHint() );
77
openDir->setFixedSize ( openDir->sizeHint() );
79
ldir->setFrameStyle ( QFrame::StyledPanel|QFrame::Sunken );
81
cbFsConv=new QCheckBox (
82
tr ( "Filename encoding"
85
QHBoxLayout* enclay=new QHBoxLayout;
86
cbFrom=new QComboBox ( egb );
87
cbTo=new QComboBox ( egb );
88
lFrom=new QLabel ( tr ( "local:" ),egb );
89
lTo=new QLabel ( tr ( "remote:" ),egb );
91
enclay->addWidget ( cbFsConv );
92
enclay->addWidget ( lFrom );
93
enclay->addWidget ( cbFrom );
94
enclay->addWidget ( lTo );
95
enclay->addWidget ( cbTo );
100
cbFsSshTun=new QCheckBox (
101
tr ( "Use ssh port forwarding to tunnel file system "
102
"connections through firewalls" ),egb );
104
QVBoxLayout* expLay=new QVBoxLayout ( this );
105
expLay->addWidget ( egb );
107
QHBoxLayout *tvLay=new QHBoxLayout ( egb );
109
QHBoxLayout *dirLAy=new QHBoxLayout();
110
dirLAy->addWidget ( dirPrompt );
111
dirLAy->addWidget ( ldir );
112
dirLAy->addWidget ( openDir );
114
QVBoxLayout* leftLay=new QVBoxLayout();
115
leftLay->addLayout ( dirLAy );
116
leftLay->addSpacing ( 10 );
117
leftLay->addWidget ( expTv );
118
expLay->addLayout ( enclay );
119
expLay->addWidget ( cbFsSshTun );
121
QVBoxLayout* rightLay=new QVBoxLayout();
122
rightLay->addWidget ( addDir );
123
rightLay->addStretch();
124
rightLay->addWidget ( delDir );
125
rightLay->addStretch();
128
tvLay->addLayout ( leftLay );
129
tvLay->addSpacing ( 10 );
130
tvLay->addLayout ( rightLay );
134
expTv->setModel ( ( QAbstractItemModel* ) model );
135
QFontMetrics fm1 ( expTv->font() );
136
expTv->header()->resizeSection ( 1,
137
fm1.width ( tr ( "Automount" ) ) +10 );
138
connect ( openDir,SIGNAL ( clicked() ),this,SLOT ( slot_openDir() ) );
139
connect ( addDir,SIGNAL ( clicked() ),this,SLOT ( slot_addDir() ) );
140
connect ( delDir,SIGNAL ( clicked() ),this,SLOT ( slot_delDir() ) );
141
connect ( cbFsConv,SIGNAL ( clicked() ),this
142
,SLOT ( slot_convClicked() ) );
147
ShareWidget::~ShareWidget()
151
void ShareWidget::slot_openDir()
153
QString startDir=ONMainWindow::getHomeDirectory();
155
if ( ONMainWindow::getPortable() &&
156
ONMainWindow::U3DevicePath().length() >0 )
158
startDir=ONMainWindow::U3DevicePath() +"/";
162
QString path= QFileDialog::getExistingDirectory (
164
tr ( "Select folder" ),
166
if ( path!=QString::null )
169
if ( ONMainWindow::getPortable() &&
170
ONMainWindow::U3DevicePath().length() >0 )
172
if ( path.indexOf ( ONMainWindow::U3DevicePath() ) !=0 )
174
QMessageBox::critical (
176
tr ( "x2goclient is running in "
177
"portable mode. You should "
178
"use a path on your usb device "
179
"to be able to access your data "
180
"whereever you are" ),
181
QMessageBox::Ok,QMessageBox::NoButton );
185
path.replace ( ONMainWindow::U3DevicePath(),
189
ldir->setText ( path );
194
void ShareWidget::slot_addDir()
196
QString path=ldir->text();
197
if ( path.length() <1 )
199
for ( int i=0; i<model->rowCount(); ++i )
200
if ( model->index ( i,0 ).data().toString() ==path )
203
item= new QStandardItem ( path );
204
model->setItem ( model->rowCount(),0,item );
205
item= new QStandardItem();
206
item->setCheckable ( true );
207
model->setItem ( model->rowCount()-1,1,item );
208
ldir->setText ( QString::null );
212
void ShareWidget::slot_delDir()
214
model->removeRow ( expTv->currentIndex().row() );
218
void ShareWidget::readConfig()
221
X2goSettings st ( "sessions" );
223
QString exportDir=st.setting()->value ( sessionId+"/export",
224
( QVariant ) QString::null ).toString();
226
cbFsSshTun->setChecked ( st.setting()->value ( sessionId+"/fstunnel",
228
QStringList lst=exportDir.split ( ";",QString::SkipEmptyParts );
230
QString toCode=st.setting()->value ( sessionId+"/iconvto",
231
( QVariant ) "UTF-8" ).toString();
234
QString fromCode=st.setting()->value ( sessionId+"/iconvfrom",
236
"WINDOWS-1252" ) ).toString();
239
QString fromCode=st.setting()->value ( sessionId+"/iconvfrom",
241
"UTF-8" ).toString();
244
QString fromCode=st.setting()->value ( sessionId+"/iconvfrom",
246
"ISO8859-1" ) ).toString();
249
cbFsConv->setChecked ( st.setting()->value ( sessionId+"/useiconv",
250
( QVariant ) false ).toBool() );
253
int ind=cbFrom->findText ( fromCode );
255
cbFrom->setCurrentIndex ( ind );
257
ind=cbTo->findText ( toCode );
259
cbTo->setCurrentIndex ( ind );
261
for ( int i=0; i<lst.size(); ++i )
264
QStringList tails=lst[i].split ( ":",QString::SkipEmptyParts );
266
QStringList tails=lst[i].split ( "#",QString::SkipEmptyParts );
269
item= new QStandardItem ( tails[0] );
270
model->setItem ( model->rowCount(),0,item );
271
item= new QStandardItem();
272
item->setCheckable ( true );
274
item->setCheckState ( Qt::Checked );
275
model->setItem ( model->rowCount()-1,1,item );
279
void ShareWidget::setDefaults()
281
cbFsSshTun->setChecked ( true );
283
QString toCode="UTF-8";
286
QString fromCode=tr ( "WINDOWS-1252" );
289
QString fromCode="UTF-8";
292
QString fromCode=tr ( "ISO8859-1" );
295
cbFsConv->setChecked ( false );
298
int ind=cbFrom->findText ( fromCode );
300
cbFrom->setCurrentIndex ( ind );
301
ind=cbTo->findText ( toCode );
303
cbTo->setCurrentIndex ( ind );
307
void ShareWidget::saveSettings()
310
X2goSettings st ( "sessions" );
311
st.setting()->setValue ( sessionId+"/fstunnel",
312
( QVariant ) cbFsSshTun->isChecked() );
315
for ( int i=0; i<model->rowCount(); ++i )
318
exportDirs+=model->index ( i,0 ).data().toString() +":";
320
exportDirs+=model->index ( i,0 ).data().toString() +"#";
323
if ( model->item ( i,1 )->checkState() ==Qt::Checked )
328
st.setting()->setValue ( sessionId+"/export", ( QVariant ) exportDirs );
331
st.setting()->setValue ( sessionId+"/iconvto",cbTo->currentText() );
332
st.setting()->setValue ( sessionId+"/iconvfrom",cbFrom->currentText() );
333
st.setting()->setValue ( sessionId+"/useiconv",cbFsConv->isChecked() );
334
st.setting()->sync();
338
void ShareWidget::loadEnc ( QComboBox* cb )
340
QFile file ( ":/txt/encodings" );
341
if ( !file.open ( QIODevice::ReadOnly | QIODevice::Text ) )
344
QTextStream in ( &file );
345
while ( !in.atEnd() )
347
QString line = in.readLine();
348
line=line.replace ( "//","" );
349
cb->addItem ( line );
353
void ShareWidget::slot_convClicked()
355
bool val=cbFsConv->isChecked();
356
cbTo->setEnabled ( val );
357
cbFrom->setEnabled ( val );
358
lTo->setEnabled ( val );
359
lFrom->setEnabled ( val );