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

« back to all changes in this revision

Viewing changes to kdat/BackupProfileInfoWidget.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 <stdlib.h>
20
 
#include <time.h>
21
 
 
22
 
#include <QLabel>
23
 
#include <QLayout>
24
 
#include <QLineEdit>
25
 
//Added by qt3to4:
26
 
#include <QVBoxLayout>
27
 
#include <QHBoxLayout>
28
 
 
29
 
#include <kpushbutton.h>
30
 
#include <KStandardGuiItem>
31
 
 
32
 
#include "BackupProfile.h"
33
 
#include "BackupProfileInfoWidget.h"
34
 
#include "BackupProfileWidget.h"
35
 
#include "KDatMainWindow.h"
36
 
#include "Options.h"
37
 
#include <klocale.h>
38
 
 
39
 
#include "BackupProfileInfoWidget.moc"
40
 
 
41
 
BackupProfileInfoWidget::BackupProfileInfoWidget( QWidget* parent, const char* name )
42
 
        : QWidget( parent, name ),
43
 
          _backupProfile( 0 )
44
 
{
45
 
    QLabel* lbl1 = new QLabel( i18n( "Backup profile name:" ), this );
46
 
 
47
 
    int max = lbl1->sizeHint().width();
48
 
 
49
 
    lbl1->setFixedSize( max, lbl1->sizeHint().height() );
50
 
 
51
 
    _name = new QLineEdit( this );
52
 
    _name->setFixedHeight( _name->sizeHint().height() );
53
 
 
54
 
    _profile = new BackupProfileWidget( this );
55
 
 
56
 
    QPushButton* getSelection = new QPushButton( i18n( "Files >>" ), this );
57
 
    getSelection->setFixedSize( 80, getSelection->sizeHint().height() );
58
 
 
59
 
    QPushButton* setSelection = new QPushButton( i18n( "<< Files" ), this );
60
 
    setSelection->setFixedSize( 80, setSelection->sizeHint().height() );
61
 
 
62
 
    _apply = new KPushButton( KStandardGuiItem::apply(), this );
63
 
    _apply->setFixedSize( 80, _apply->sizeHint().height() );
64
 
    _apply->setEnabled( FALSE );
65
 
 
66
 
    QVBoxLayout* l1 = new QVBoxLayout( this, 4, 4 );
67
 
 
68
 
    QHBoxLayout* l1_1 = new QHBoxLayout();
69
 
    l1->addLayout( l1_1 );
70
 
    l1_1->addWidget( lbl1 );
71
 
    l1_1->addWidget( _name, 1 );
72
 
 
73
 
    l1->addWidget( _profile, 1 );
74
 
 
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 );
81
 
 
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() ) );
87
 
}
88
 
 
89
 
BackupProfileInfoWidget::~BackupProfileInfoWidget()
90
 
{
91
 
}
92
 
 
93
 
void BackupProfileInfoWidget::setBackupProfile( BackupProfile* backupProfile )
94
 
{
95
 
    _backupProfile = backupProfile;
96
 
 
97
 
    if ( !_backupProfile ) {
98
 
        return;
99
 
    }
100
 
 
101
 
    _name->setText( _backupProfile->getName() );
102
 
 
103
 
    _profile->setBackupProfile( _backupProfile );
104
 
}
105
 
 
106
 
bool BackupProfileInfoWidget::isModified()
107
 
{
108
 
    if ( _backupProfile->getName() != _name->text() ) {
109
 
        return TRUE;
110
 
    }
111
 
 
112
 
    if ( _profile->getArchiveName() != _backupProfile->getArchiveName() ) {
113
 
        return TRUE;
114
 
    }
115
 
 
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;
122
 
    }
123
 
 
124
 
    if ( _profile->getAbsoluteFiles().count() != _backupProfile->getAbsoluteFiles().count() ) {
125
 
        return TRUE;
126
 
    }
127
 
 
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;
136
 
            }
137
 
        }
138
 
        if ( j == list2.end() ) {
139
 
            // Could not find i.current() in j => lists are not equal.
140
 
            return TRUE;
141
 
        }
142
 
    }
143
 
 
144
 
    if ( _profile->isOneFilesystem() != _backupProfile->isOneFilesystem() ) {
145
 
        return TRUE;
146
 
    }
147
 
 
148
 
    if ( _profile->isIncremental() != _backupProfile->isIncremental() ) {
149
 
        return TRUE;
150
 
    }
151
 
 
152
 
    if ( _profile->getSnapshotFile() != _backupProfile->getSnapshotFile() ) {
153
 
        return TRUE;
154
 
    }
155
 
 
156
 
    if ( _profile->getRemoveSnapshot() != _backupProfile->getRemoveSnapshot() ) {
157
 
        return TRUE;
158
 
    }
159
 
 
160
 
    return FALSE;
161
 
}
162
 
 
163
 
void BackupProfileInfoWidget::slotTextChanged( const QString & )
164
 
{
165
 
    if ( !_backupProfile ) {
166
 
        return;
167
 
    }
168
 
 
169
 
    _apply->setEnabled( isModified() );
170
 
}
171
 
 
172
 
void BackupProfileInfoWidget::slotSomethingChanged()
173
 
{
174
 
    if ( !_backupProfile ) {
175
 
        return;
176
 
    }
177
 
 
178
 
    _apply->setEnabled( isModified() );
179
 
}
180
 
 
181
 
void BackupProfileInfoWidget::slotApply()
182
 
{
183
 
    if ( !_backupProfile ) {
184
 
        return;
185
 
    }
186
 
 
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() );
195
 
    
196
 
    _backupProfile->save();
197
 
 
198
 
    _apply->setEnabled( FALSE );
199
 
}
200
 
 
201
 
void BackupProfileInfoWidget::slotSetSelection()
202
 
{
203
 
    KDatMainWindow::getInstance()->setBackupFiles( _profile->getAbsoluteFiles() );
204
 
}
205
 
 
206
 
void BackupProfileInfoWidget::slotGetSelection()
207
 
{
208
 
    QStringList files;
209
 
    KDatMainWindow::getInstance()->getBackupFiles( files );
210
 
    _profile->setAbsoluteFiles( files );
211
 
}