~x2go/x2go/x2goclient_master

« back to all changes in this revision

Viewing changes to exportdialog.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 "x2goclientconfig.h"
19
 
#include "exportdialog.h"
20
 
#include "editconnectiondialog.h"
21
 
#include <QBoxLayout>
22
 
#include <QGroupBox>
23
 
#include <QPushButton>
24
 
#include <QLabel>
25
 
#include "x2gosettings.h"
26
 
#include <QListView>
27
 
#include <QDir>
28
 
#include <QStringListModel>
29
 
#include <QShortcut>
30
 
#include "sessionbutton.h"
31
 
#include "onmainwindow.h"
32
 
#include <QFileDialog>
33
 
#include "sessionexplorer.h"
34
 
 
35
 
ExportDialog::ExportDialog ( QString sid,QWidget * par, Qt::WFlags f )
36
 
    : QDialog ( par,f )
37
 
{
38
 
    sessionId=sid;
39
 
    QVBoxLayout* ml=new QVBoxLayout ( this );
40
 
    QFrame *fr=new QFrame ( this );
41
 
    QHBoxLayout* frLay=new QHBoxLayout ( fr );
42
 
 
43
 
    parent= ( ONMainWindow* ) par;
44
 
 
45
 
    QPushButton* cancel=new QPushButton ( tr ( "&Cancel" ),this );
46
 
    QHBoxLayout* bLay=new QHBoxLayout();
47
 
 
48
 
    sessions=new QListView ( fr );
49
 
    frLay->addWidget ( sessions );
50
 
 
51
 
    exportDir=new QPushButton ( tr ( "&share" ),fr );
52
 
    editSession=new QPushButton ( tr ( "&Preferences ..." ),fr );
53
 
    newDir=new QPushButton ( tr ( "&Custom folder ..." ),fr );
54
 
 
55
 
 
56
 
    QVBoxLayout* actLay=new QVBoxLayout();
57
 
    actLay->addWidget ( exportDir );
58
 
    actLay->addWidget ( editSession );
59
 
    actLay->addWidget ( newDir );
60
 
    actLay->addStretch();
61
 
    frLay->addLayout ( actLay );
62
 
 
63
 
    QShortcut* sc=new QShortcut ( QKeySequence ( tr ( "Delete","Delete" ) ),
64
 
                                  this );
65
 
    connect ( cancel,SIGNAL ( clicked() ),this,SLOT ( close() ) );
66
 
    connect ( sc,SIGNAL ( activated() ),exportDir,SIGNAL ( clicked() ) );
67
 
    connect ( editSession,SIGNAL ( clicked() ),this,SLOT ( slot_edit() ) );
68
 
    connect ( newDir,SIGNAL ( clicked() ),this,SLOT ( slotNew() ) );
69
 
    connect ( exportDir,SIGNAL ( clicked() ),this,SLOT ( slot_accept() ) );
70
 
    bLay->setSpacing ( 5 );
71
 
    bLay->addStretch();
72
 
    bLay->addWidget ( cancel );
73
 
    ml->addWidget ( fr );
74
 
    ml->addLayout ( bLay );
75
 
 
76
 
    fr->setFrameStyle ( QFrame::StyledPanel | QFrame::Raised );
77
 
    fr->setLineWidth ( 2 );
78
 
 
79
 
    setSizeGripEnabled ( true );
80
 
    setWindowTitle ( tr ( "share folders" ) );
81
 
    connect ( sessions,SIGNAL ( clicked ( const QModelIndex& ) ),
82
 
              this,SLOT ( slot_activated ( const QModelIndex& ) ) );
83
 
    connect ( sessions,SIGNAL ( doubleClicked ( const QModelIndex& ) ),
84
 
              this,SLOT ( slot_dclicked ( const QModelIndex& ) ) );
85
 
    loadSessions();
86
 
}
87
 
 
88
 
 
89
 
ExportDialog::~ExportDialog()
90
 
{}
91
 
 
92
 
void ExportDialog::loadSessions()
93
 
{
94
 
    QStringListModel *model= ( QStringListModel* ) sessions->model();
95
 
    if ( !model )
96
 
        model=new QStringListModel();
97
 
    sessions->setModel ( model );
98
 
 
99
 
    QStringList dirs;
100
 
    model->setStringList ( dirs );
101
 
 
102
 
    X2goSettings st ( "sessions" );
103
 
 
104
 
 
105
 
    QString exports=st.setting()->value ( sessionId+"/export",
106
 
                                          ( QVariant ) QString::null ).toString();
107
 
 
108
 
    QStringList lst=exports.split ( ";",QString::SkipEmptyParts );
109
 
    for ( int i=0; i<lst.size(); ++i )
110
 
    {
111
 
#ifndef Q_OS_WIN
112
 
        QStringList tails=lst[i].split ( ":",QString::SkipEmptyParts );
113
 
#else
114
 
        QStringList tails=lst[i].split ( "#",QString::SkipEmptyParts );
115
 
#endif
116
 
        dirs<<tails[0];
117
 
    }
118
 
 
119
 
 
120
 
    model->setStringList ( dirs );
121
 
 
122
 
 
123
 
    //     removeSession->setEnabled(false);
124
 
    exportDir->setEnabled ( false );
125
 
    sessions->setEditTriggers ( QAbstractItemView::NoEditTriggers );
126
 
}
127
 
 
128
 
 
129
 
void ExportDialog::slot_activated ( const QModelIndex& )
130
 
{
131
 
    //     removeSession->setEnabled(true);
132
 
    exportDir->setEnabled ( true );
133
 
}
134
 
 
135
 
void ExportDialog::slot_dclicked ( const QModelIndex& )
136
 
{
137
 
    slot_accept();
138
 
}
139
 
 
140
 
 
141
 
void ExportDialog::slotNew()
142
 
{
143
 
    directory=QString::null;
144
 
    directory= QFileDialog::getExistingDirectory (
145
 
                   this,
146
 
                   tr ( "Select folder" ),
147
 
                   QDir::homePath() );
148
 
 
149
 
    if ( directory!=QString::null )
150
 
        accept();
151
 
 
152
 
}
153
 
 
154
 
 
155
 
void ExportDialog::slot_edit()
156
 
{
157
 
    const QList<SessionButton*>* sess=parent->getSessionExplorer()->getSessionsList();
158
 
    for ( int i=0; i< sess->size(); ++i )
159
 
    {
160
 
        if ( sess->at ( i )->id() ==sessionId )
161
 
        {
162
 
            parent->getSessionExplorer()->exportsEdit ( sess->at ( i ) );
163
 
            break;
164
 
        }
165
 
    }
166
 
    loadSessions();
167
 
}
168
 
 
169
 
 
170
 
 
171
 
void ExportDialog::slot_accept()
172
 
{
173
 
    int ind=sessions->currentIndex().row();
174
 
    if ( ind<0 )
175
 
        return;
176
 
    QStringListModel *model= ( QStringListModel* ) sessions->model();
177
 
    directory=model->stringList() [ind];
178
 
    accept();
179
 
}