~ubuntu-branches/ubuntu/natty/kdeadmin/natty-proposed

« back to all changes in this revision

Viewing changes to kdat/BackupProfileWidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-02-27 21:36:45 UTC
  • mfrom: (1.2.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20100227213645-ronst6mahkgf6j9w
Tags: 4:4.4.1-0ubuntu1
* New upstream release
  - Bump build-depends
  - Update kcron.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// KDat - a tar-based DAT archiver
2
 
// Copyright (C) 1998-2000  Sean Vyain, svyain@mail.tds.net
3
 
// Copyright (C) 2001-2002  Lawrence Widman, kdat@cardiothink.com
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
 
//
10
 
// This program is distributed in the hope that it will be useful,
11
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
// GNU General Public License for more details.
14
 
//
15
 
// You should have received a copy of the GNU General Public License
16
 
// along with this program; if not, write to the Free Software
17
 
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 
19
 
#include <QCheckBox>
20
 
#include <QComboBox>
21
 
#include <QLabel>
22
 
#include <QLayout>
23
 
#include <QLineEdit>
24
 
#include <q3listbox.h>
25
 
#include <QPushButton>
26
 
//Added by qt3to4:
27
 
#include <QVBoxLayout>
28
 
#include <QHBoxLayout>
29
 
 
30
 
 
31
 
#include "BackupProfile.h"
32
 
#include "BackupProfileWidget.h"
33
 
#include "Util.h"
34
 
#include <klocale.h>
35
 
 
36
 
#include "BackupProfileWidget.moc"
37
 
 
38
 
BackupProfileWidget::BackupProfileWidget( QWidget* parent, const char* name )
39
 
        : KTabCtl( parent )
40
 
{
41
 
        setObjectName(name);
42
 
    QWidget* one = new QWidget( this );
43
 
    addTab( one, i18n( "Backup" ) );
44
 
 
45
 
    QLabel* lbl1 = new QLabel( i18n( "Archive name:" ), one );
46
 
    lbl1->setFixedSize( lbl1->sizeHint() );
47
 
 
48
 
    _archiveName = new QLineEdit( one );
49
 
    _archiveName->setFixedHeight( _archiveName->sizeHint().height() );
50
 
 
51
 
    QLabel* lbl2 = new QLabel( i18n( "Working folder:" ), one );
52
 
    lbl2->setFixedSize( lbl2->sizeHint() );
53
 
 
54
 
    _workingDir = new QComboBox( FALSE, one );
55
 
    _workingDir->setFixedHeight( _workingDir->sizeHint().height() );
56
 
 
57
 
    QLabel* lbl3 = new QLabel( i18n( "Backup files:" ), one );
58
 
    lbl3->setFixedHeight( lbl3->sizeHint().height() );
59
 
 
60
 
    _files = new Q3ListBox( one );
61
 
 
62
 
    QWidget* two = new QWidget( this );
63
 
    addTab( two, i18n( "Tar Options" ) );
64
 
 
65
 
    _oneFilesystem = new QCheckBox( i18n( "Stay on one filesystem" ), two );
66
 
    _oneFilesystem->setFixedHeight( _oneFilesystem->sizeHint().height() );
67
 
 
68
 
    _incremental = new QCheckBox( i18n( "GNU listed incremental" ), two );
69
 
    _incremental->setFixedHeight( _incremental->sizeHint().height() );
70
 
    connect( _incremental, SIGNAL( toggled( bool ) ), this, SLOT( slotIncrementalToggled( bool ) ) );
71
 
 
72
 
    _snapshotLabel = new QLabel( i18n( "Snapshot file:" ), two );
73
 
    _snapshotLabel->setFixedSize( _snapshotLabel->sizeHint() );
74
 
 
75
 
    _snapshotFile = new QLineEdit( two );
76
 
    _snapshotFile->setFixedHeight( _snapshotFile->sizeHint().height() );
77
 
 
78
 
    _removeSnapshot = new QCheckBox( i18n( "Remove snapshot file before backup" ), two );
79
 
    _removeSnapshot->setFixedHeight( _removeSnapshot->sizeHint().height() );
80
 
 
81
 
    slotIncrementalToggled( FALSE );
82
 
 
83
 
    QVBoxLayout* l1 = new QVBoxLayout( one, 8, 4 );
84
 
 
85
 
    QHBoxLayout* l1_1 = new QHBoxLayout();
86
 
    l1->addLayout( l1_1 );
87
 
    l1_1->addWidget( lbl1 );
88
 
    l1_1->addWidget( _archiveName, 1 );
89
 
 
90
 
    QHBoxLayout* l1_2 = new QHBoxLayout();
91
 
    l1->addLayout( l1_2 );
92
 
    l1_2->addWidget( lbl2 );
93
 
    l1_2->addWidget( _workingDir, 1 );
94
 
 
95
 
    l1->addWidget( lbl3 );
96
 
    l1->addWidget( _files, 1 );
97
 
 
98
 
    QVBoxLayout* l2 = new QVBoxLayout( two, 8, 4 );
99
 
    l2->addWidget( _oneFilesystem );
100
 
    l2->addWidget( _incremental );
101
 
 
102
 
    QHBoxLayout* l2_1 = new QHBoxLayout();
103
 
    l2->addLayout( l2_1 );
104
 
    l2_1->addSpacing( 20 );
105
 
    l2_1->addWidget( _snapshotLabel );
106
 
    l2_1->addWidget( _snapshotFile, 1 );
107
 
 
108
 
    QHBoxLayout* l2_2 = new QHBoxLayout();
109
 
    l2->addLayout( l2_2 );
110
 
    l2_2->addSpacing( 20 );
111
 
    l2_2->addWidget( _removeSnapshot );
112
 
 
113
 
    l2->addStretch( 1 );
114
 
 
115
 
    connect( _archiveName   , SIGNAL( textChanged( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) );
116
 
    connect( _workingDir    , SIGNAL( activated( const QString & ) )  , this, SLOT( slotWorkingDirActivated( const QString & ) ) );
117
 
    connect( _oneFilesystem , SIGNAL( toggled( bool ) )           , this, SLOT( slotToggled( bool ) ) );
118
 
    connect( _incremental   , SIGNAL( toggled( bool ) )           , this, SLOT( slotIncrementalToggled( bool ) ) );
119
 
    connect( _snapshotFile  , SIGNAL( textChanged( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) );
120
 
    connect( _removeSnapshot, SIGNAL( toggled( bool ) )           , this, SLOT( slotToggled( bool ) ) );
121
 
}
122
 
 
123
 
BackupProfileWidget::~BackupProfileWidget()
124
 
{
125
 
}
126
 
 
127
 
void BackupProfileWidget::slotTextChanged( const QString & )
128
 
{
129
 
    emit sigSomethingChanged();
130
 
}
131
 
 
132
 
void BackupProfileWidget::slotToggled( bool )
133
 
{
134
 
    emit sigSomethingChanged();
135
 
}
136
 
 
137
 
void BackupProfileWidget::slotIncrementalToggled( bool set )
138
 
{
139
 
    _snapshotLabel->setEnabled( set );
140
 
    _snapshotFile->setEnabled( set );
141
 
    _removeSnapshot->setEnabled( set );
142
 
 
143
 
    emit sigSomethingChanged();
144
 
}
145
 
 
146
 
void BackupProfileWidget::slotWorkingDirActivated( const QString & text )
147
 
{
148
 
    while ( FALSE == _relativeFiles.isEmpty() ) {
149
 
      QString my_first = _relativeFiles.first();
150
 
      _relativeFiles.remove( my_first );
151
 
    }
152
 
    _files->clear();
153
 
 
154
 
    QStringList::Iterator i = _absoluteFiles.begin();
155
 
    int remove = text.length();
156
 
    if ( remove > 1 ) {
157
 
        remove++;
158
 
    }
159
 
    for ( ; i != _absoluteFiles.end(); ++i ) {
160
 
        QString fn = *i;
161
 
        fn.remove( 0, remove );
162
 
        if ( fn.isEmpty() ) {
163
 
            fn = ".";
164
 
        }
165
 
        _files->insertItem( fn );
166
 
        _relativeFiles.append( fn );
167
 
    }
168
 
 
169
 
    emit sigSomethingChanged();
170
 
}
171
 
 
172
 
void BackupProfileWidget::setBackupProfile( BackupProfile* backupProfile )
173
 
{
174
 
    // Set the archive name.
175
 
    _archiveName->setText( backupProfile->getArchiveName() );
176
 
 
177
 
    setAbsoluteFiles( backupProfile->getAbsoluteFiles() );
178
 
 
179
 
    if ( !backupProfile->getWorkingDirectory().isNull() ) {
180
 
        for ( int ii = 0; ii < _workingDir->count(); ii++ ) {
181
 
            QString one = _workingDir->text( ii );
182
 
            QString two = backupProfile->getWorkingDirectory();
183
 
              // if ( _workingDir->text( ii ) == backupProfile->getWorkingDirectory() ) {
184
 
            if( one == two ){
185
 
                _workingDir->setCurrentItem( ii );
186
 
                break;
187
 
            }
188
 
        }
189
 
    }
190
 
 
191
 
    //    slotWorkingDirActivated( _workingDir->currentText() );
192
 
    QString one = _workingDir->currentText();
193
 
    slotWorkingDirActivated( one );
194
 
 
195
 
    _oneFilesystem->setChecked( backupProfile->isOneFilesystem() );
196
 
    _incremental->setChecked( backupProfile->isIncremental() );
197
 
    _snapshotFile->setText( backupProfile->getSnapshotFile() );
198
 
    _removeSnapshot->setChecked( backupProfile->getRemoveSnapshot() );
199
 
 
200
 
    slotIncrementalToggled( backupProfile->isIncremental() );
201
 
}
202
 
 
203
 
void BackupProfileWidget::setAbsoluteFiles( const QStringList& files )
204
 
{
205
 
    // Copy the string list.
206
 
    _absoluteFiles = files;
207
 
 
208
 
    QString prefix = Util::longestCommonPath( files );
209
 
 
210
 
    _workingDir->clear();
211
 
    for ( int pos = prefix.length(); pos > 0; pos = prefix.lastIndexOf( '/', pos - 1 ) ) {
212
 
        _workingDir->insertItem( prefix.left( pos ) );
213
 
    }
214
 
    _workingDir->insertItem( "/" );
215
 
    _workingDir->setCurrentItem( 0 );
216
 
 
217
 
    slotWorkingDirActivated( _workingDir->currentText() );
218
 
}
219
 
 
220
 
QString BackupProfileWidget::getArchiveName()
221
 
{
222
 
    return _archiveName->text();
223
 
}
224
 
 
225
 
QString BackupProfileWidget::getWorkingDirectory()
226
 
{
227
 
    if ( _workingDir->count() > 0 ) {
228
 
        return _workingDir->currentText();
229
 
    } else {
230
 
        return 0;
231
 
    }
232
 
}
233
 
 
234
 
const QStringList& BackupProfileWidget::getRelativeFiles()
235
 
{
236
 
    return _relativeFiles;
237
 
}
238
 
 
239
 
const QStringList& BackupProfileWidget::getAbsoluteFiles()
240
 
{
241
 
    return _absoluteFiles;
242
 
}
243
 
 
244
 
bool BackupProfileWidget::isOneFilesystem()
245
 
{
246
 
    return _oneFilesystem->isChecked();
247
 
}
248
 
 
249
 
bool BackupProfileWidget::isIncremental()
250
 
{
251
 
    return _incremental->isChecked();
252
 
}
253
 
 
254
 
QString BackupProfileWidget::getSnapshotFile()
255
 
{
256
 
    return _snapshotFile->text();
257
 
}
258
 
 
259
 
bool BackupProfileWidget::getRemoveSnapshot()
260
 
{
261
 
    return _removeSnapshot->isChecked();
262
 
}