SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kdat / BackupProfileWidget.cpp
blob5c19ce4964fb36f8d4299be05cf27294d88ddc19
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.
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
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>
31 #include "BackupProfile.h"
32 #include "BackupProfileWidget.h"
33 #include "Util.h"
34 #include <klocale.h>
36 #include "BackupProfileWidget.moc"
38 BackupProfileWidget::BackupProfileWidget( QWidget* parent, const char* name )
39 : KTabCtl( parent )
41 setObjectName(name);
42 QWidget* one = new QWidget( this );
43 addTab( one, i18n( "Backup" ) );
45 QLabel* lbl1 = new QLabel( i18n( "Archive name:" ), one );
46 lbl1->setFixedSize( lbl1->sizeHint() );
48 _archiveName = new QLineEdit( one );
49 _archiveName->setFixedHeight( _archiveName->sizeHint().height() );
51 QLabel* lbl2 = new QLabel( i18n( "Working folder:" ), one );
52 lbl2->setFixedSize( lbl2->sizeHint() );
54 _workingDir = new QComboBox( FALSE, one );
55 _workingDir->setFixedHeight( _workingDir->sizeHint().height() );
57 QLabel* lbl3 = new QLabel( i18n( "Backup files:" ), one );
58 lbl3->setFixedHeight( lbl3->sizeHint().height() );
60 _files = new Q3ListBox( one );
62 QWidget* two = new QWidget( this );
63 addTab( two, i18n( "Tar Options" ) );
65 _oneFilesystem = new QCheckBox( i18n( "Stay on one filesystem" ), two );
66 _oneFilesystem->setFixedHeight( _oneFilesystem->sizeHint().height() );
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 ) ) );
72 _snapshotLabel = new QLabel( i18n( "Snapshot file:" ), two );
73 _snapshotLabel->setFixedSize( _snapshotLabel->sizeHint() );
75 _snapshotFile = new QLineEdit( two );
76 _snapshotFile->setFixedHeight( _snapshotFile->sizeHint().height() );
78 _removeSnapshot = new QCheckBox( i18n( "Remove snapshot file before backup" ), two );
79 _removeSnapshot->setFixedHeight( _removeSnapshot->sizeHint().height() );
81 slotIncrementalToggled( FALSE );
83 QVBoxLayout* l1 = new QVBoxLayout( one, 8, 4 );
85 QHBoxLayout* l1_1 = new QHBoxLayout();
86 l1->addLayout( l1_1 );
87 l1_1->addWidget( lbl1 );
88 l1_1->addWidget( _archiveName, 1 );
90 QHBoxLayout* l1_2 = new QHBoxLayout();
91 l1->addLayout( l1_2 );
92 l1_2->addWidget( lbl2 );
93 l1_2->addWidget( _workingDir, 1 );
95 l1->addWidget( lbl3 );
96 l1->addWidget( _files, 1 );
98 QVBoxLayout* l2 = new QVBoxLayout( two, 8, 4 );
99 l2->addWidget( _oneFilesystem );
100 l2->addWidget( _incremental );
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 );
108 QHBoxLayout* l2_2 = new QHBoxLayout();
109 l2->addLayout( l2_2 );
110 l2_2->addSpacing( 20 );
111 l2_2->addWidget( _removeSnapshot );
113 l2->addStretch( 1 );
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 ) ) );
123 BackupProfileWidget::~BackupProfileWidget()
127 void BackupProfileWidget::slotTextChanged( const QString & )
129 emit sigSomethingChanged();
132 void BackupProfileWidget::slotToggled( bool )
134 emit sigSomethingChanged();
137 void BackupProfileWidget::slotIncrementalToggled( bool set )
139 _snapshotLabel->setEnabled( set );
140 _snapshotFile->setEnabled( set );
141 _removeSnapshot->setEnabled( set );
143 emit sigSomethingChanged();
146 void BackupProfileWidget::slotWorkingDirActivated( const QString & text )
148 while ( FALSE == _relativeFiles.isEmpty() ) {
149 QString my_first = _relativeFiles.first();
150 _relativeFiles.remove( my_first );
152 _files->clear();
154 QStringList::Iterator i = _absoluteFiles.begin();
155 int remove = text.length();
156 if ( remove > 1 ) {
157 remove++;
159 for ( ; i != _absoluteFiles.end(); ++i ) {
160 QString fn = *i;
161 fn.remove( 0, remove );
162 if ( fn.isEmpty() ) {
163 fn = ".";
165 _files->insertItem( fn );
166 _relativeFiles.append( fn );
169 emit sigSomethingChanged();
172 void BackupProfileWidget::setBackupProfile( BackupProfile* backupProfile )
174 // Set the archive name.
175 _archiveName->setText( backupProfile->getArchiveName() );
177 setAbsoluteFiles( backupProfile->getAbsoluteFiles() );
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;
191 // slotWorkingDirActivated( _workingDir->currentText() );
192 QString one = _workingDir->currentText();
193 slotWorkingDirActivated( one );
195 _oneFilesystem->setChecked( backupProfile->isOneFilesystem() );
196 _incremental->setChecked( backupProfile->isIncremental() );
197 _snapshotFile->setText( backupProfile->getSnapshotFile() );
198 _removeSnapshot->setChecked( backupProfile->getRemoveSnapshot() );
200 slotIncrementalToggled( backupProfile->isIncremental() );
203 void BackupProfileWidget::setAbsoluteFiles( const QStringList& files )
205 // Copy the string list.
206 _absoluteFiles = files;
208 QString prefix = Util::longestCommonPath( files );
210 _workingDir->clear();
211 for ( int pos = prefix.length(); pos > 0; pos = prefix.lastIndexOf( '/', pos - 1 ) ) {
212 _workingDir->insertItem( prefix.left( pos ) );
214 _workingDir->insertItem( "/" );
215 _workingDir->setCurrentItem( 0 );
217 slotWorkingDirActivated( _workingDir->currentText() );
220 QString BackupProfileWidget::getArchiveName()
222 return _archiveName->text();
225 QString BackupProfileWidget::getWorkingDirectory()
227 if ( _workingDir->count() > 0 ) {
228 return _workingDir->currentText();
229 } else {
230 return 0;
234 const QStringList& BackupProfileWidget::getRelativeFiles()
236 return _relativeFiles;
239 const QStringList& BackupProfileWidget::getAbsoluteFiles()
241 return _absoluteFiles;
244 bool BackupProfileWidget::isOneFilesystem()
246 return _oneFilesystem->isChecked();
249 bool BackupProfileWidget::isIncremental()
251 return _incremental->isChecked();
254 QString BackupProfileWidget::getSnapshotFile()
256 return _snapshotFile->text();
259 bool BackupProfileWidget::getRemoveSnapshot()
261 return _removeSnapshot->isChecked();