SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kdat / BackupProfileInfoWidget.cpp
blob7383155871ddaeaed6985576202706ef7cec743c
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 <stdlib.h>
20 #include <time.h>
22 #include <QLabel>
23 #include <QLayout>
24 #include <QLineEdit>
25 //Added by qt3to4:
26 #include <QVBoxLayout>
27 #include <QHBoxLayout>
29 #include <kpushbutton.h>
30 #include <KStandardGuiItem>
32 #include "BackupProfile.h"
33 #include "BackupProfileInfoWidget.h"
34 #include "BackupProfileWidget.h"
35 #include "KDatMainWindow.h"
36 #include "Options.h"
37 #include <klocale.h>
39 #include "BackupProfileInfoWidget.moc"
41 BackupProfileInfoWidget::BackupProfileInfoWidget( QWidget* parent, const char* name )
42 : QWidget( parent, name ),
43 _backupProfile( 0 )
45 QLabel* lbl1 = new QLabel( i18n( "Backup profile name:" ), this );
47 int max = lbl1->sizeHint().width();
49 lbl1->setFixedSize( max, lbl1->sizeHint().height() );
51 _name = new QLineEdit( this );
52 _name->setFixedHeight( _name->sizeHint().height() );
54 _profile = new BackupProfileWidget( this );
56 QPushButton* getSelection = new QPushButton( i18n( "Files >>" ), this );
57 getSelection->setFixedSize( 80, getSelection->sizeHint().height() );
59 QPushButton* setSelection = new QPushButton( i18n( "<< Files" ), this );
60 setSelection->setFixedSize( 80, setSelection->sizeHint().height() );
62 _apply = new KPushButton( KStandardGuiItem::apply(), this );
63 _apply->setFixedSize( 80, _apply->sizeHint().height() );
64 _apply->setEnabled( FALSE );
66 QVBoxLayout* l1 = new QVBoxLayout( this, 4, 4 );
68 QHBoxLayout* l1_1 = new QHBoxLayout();
69 l1->addLayout( l1_1 );
70 l1_1->addWidget( lbl1 );
71 l1_1->addWidget( _name, 1 );
73 l1->addWidget( _profile, 1 );
75 QHBoxLayout* l1_2 = new QHBoxLayout();
76 l1->addLayout( l1_2 );
77 l1_2->addWidget( setSelection );
78 l1_2->addWidget( getSelection );
79 l1_2->addStretch( 1 );
80 l1_2->addWidget( _apply );
82 connect( setSelection, SIGNAL( clicked() ) , this, SLOT( slotSetSelection() ) );
83 connect( getSelection, SIGNAL( clicked() ) , this, SLOT( slotGetSelection() ) );
84 connect( _name , SIGNAL( textChanged( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) );
85 connect( _profile , SIGNAL( sigSomethingChanged() ) , this, SLOT( slotSomethingChanged() ) );
86 connect( _apply , SIGNAL( clicked() ) , this, SLOT( slotApply() ) );
89 BackupProfileInfoWidget::~BackupProfileInfoWidget()
93 void BackupProfileInfoWidget::setBackupProfile( BackupProfile* backupProfile )
95 _backupProfile = backupProfile;
97 if ( !_backupProfile ) {
98 return;
101 _name->setText( _backupProfile->getName() );
103 _profile->setBackupProfile( _backupProfile );
106 bool BackupProfileInfoWidget::isModified()
108 if ( _backupProfile->getName() != _name->text() ) {
109 return TRUE;
112 if ( _profile->getArchiveName() != _backupProfile->getArchiveName() ) {
113 return TRUE;
116 QString one = _backupProfile->getWorkingDirectory();
117 QString two = _profile->getWorkingDirectory();
118 // 7/31/01: this breaks
119 // if ( _profile->getWorkingDirectory() != _backupProfile->getWorkingDirectory() ) {
120 if( one != two ){
121 return TRUE;
124 if ( _profile->getAbsoluteFiles().count() != _backupProfile->getAbsoluteFiles().count() ) {
125 return TRUE;
128 QStringList list1 = _profile->getAbsoluteFiles();
129 QStringList list2 = _backupProfile->getAbsoluteFiles();
130 QStringList::Iterator i = list1.begin();
131 QStringList::Iterator j = list2.begin();
132 for ( ; i != list1.end(); ++i ) {
133 for ( ; j != list2.end(); ++j ) {
134 if ( *i == *j ) {
135 break;
138 if ( j == list2.end() ) {
139 // Could not find i.current() in j => lists are not equal.
140 return TRUE;
144 if ( _profile->isOneFilesystem() != _backupProfile->isOneFilesystem() ) {
145 return TRUE;
148 if ( _profile->isIncremental() != _backupProfile->isIncremental() ) {
149 return TRUE;
152 if ( _profile->getSnapshotFile() != _backupProfile->getSnapshotFile() ) {
153 return TRUE;
156 if ( _profile->getRemoveSnapshot() != _backupProfile->getRemoveSnapshot() ) {
157 return TRUE;
160 return FALSE;
163 void BackupProfileInfoWidget::slotTextChanged( const QString & )
165 if ( !_backupProfile ) {
166 return;
169 _apply->setEnabled( isModified() );
172 void BackupProfileInfoWidget::slotSomethingChanged()
174 if ( !_backupProfile ) {
175 return;
178 _apply->setEnabled( isModified() );
181 void BackupProfileInfoWidget::slotApply()
183 if ( !_backupProfile ) {
184 return;
187 _backupProfile->setName( _name->text() );
188 _backupProfile->setArchiveName( _profile->getArchiveName() );
189 _backupProfile->setWorkingDirectory( _profile->getWorkingDirectory() );
190 _backupProfile->setAbsoluteFiles( _profile->getAbsoluteFiles() );
191 _backupProfile->setOneFilesystem( _profile->isOneFilesystem() );
192 _backupProfile->setIncremental( _profile->isIncremental() );
193 _backupProfile->setSnapshotFile( _profile->getSnapshotFile() );
194 _backupProfile->setRemoveSnapshot( _profile->getRemoveSnapshot() );
196 _backupProfile->save();
198 _apply->setEnabled( FALSE );
201 void BackupProfileInfoWidget::slotSetSelection()
203 KDatMainWindow::getInstance()->setBackupFiles( _profile->getAbsoluteFiles() );
206 void BackupProfileInfoWidget::slotGetSelection()
208 QStringList files;
209 KDatMainWindow::getInstance()->getBackupFiles( files );
210 _profile->setAbsoluteFiles( files );