summaryrefslogtreecommitdiffstats
path: root/kdat/BackupProfileInfoWidget.cpp
blob: 07f7c357c475e614ce7333e7903b899b3186bdd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// KDat - a tar-based DAT archiver
// Copyright (C) 1998-2000  Sean Vyain, svyain@mail.tds.net
// Copyright (C) 2001-2002  Lawrence Widman, kdat@cardiothink.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#include <stdlib.h>
#include <time.h>

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>

#include <tdeapplication.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>

#include "BackupProfile.h"
#include "BackupProfileInfoWidget.h"
#include "BackupProfileWidget.h"
#include "KDatMainWindow.h"
#include "Options.h"
#include <tdelocale.h>

#include "BackupProfileInfoWidget.moc"

BackupProfileInfoWidget::BackupProfileInfoWidget( TQWidget* parent, const char* name )
        : TQWidget( parent, name ),
          _backupProfile( 0 )
{
    TQLabel* lbl1 = new TQLabel( i18n( "Backup profile name:" ), this );

    int max = lbl1->sizeHint().width();

    lbl1->setFixedSize( max, lbl1->sizeHint().height() );

    _name = new TQLineEdit( this );
    _name->setFixedHeight( _name->sizeHint().height() );

    _profile = new BackupProfileWidget( this );

    TQPushButton* getSelection = new TQPushButton( i18n( "Files >>" ), this );
    getSelection->setFixedSize( 80, getSelection->sizeHint().height() );

    TQPushButton* setSelection = new TQPushButton( i18n( "<< Files" ), this );
    setSelection->setFixedSize( 80, setSelection->sizeHint().height() );

    _apply = new KPushButton( KStdGuiItem::apply(), this );
    _apply->setFixedSize( 80, _apply->sizeHint().height() );
    _apply->setEnabled( FALSE );

    TQVBoxLayout* l1 = new TQVBoxLayout( this, 4, 4 );

    TQHBoxLayout* l1_1 = new TQHBoxLayout();
    l1->addLayout( l1_1 );
    l1_1->addWidget( lbl1 );
    l1_1->addWidget( _name, 1 );

    l1->addWidget( _profile, 1 );

    TQHBoxLayout* l1_2 = new TQHBoxLayout();
    l1->addLayout( l1_2 );
    l1_2->addWidget( setSelection );
    l1_2->addWidget( getSelection );
    l1_2->addStretch( 1 );
    l1_2->addWidget( _apply );

    connect( setSelection, TQ_SIGNAL( clicked() )                 , this, TQ_SLOT( slotSetSelection() ) );
    connect( getSelection, TQ_SIGNAL( clicked() )                 , this, TQ_SLOT( slotGetSelection() ) );
    connect( _name       , TQ_SIGNAL( textChanged( const TQString & ) ), this, TQ_SLOT( slotTextChanged( const TQString & ) ) );
    connect( _profile    , TQ_SIGNAL( sigSomethingChanged() )     , this, TQ_SLOT( slotSomethingChanged() ) );
    connect( _apply      , TQ_SIGNAL( clicked() )                 , this, TQ_SLOT( slotApply() ) );
}

BackupProfileInfoWidget::~BackupProfileInfoWidget()
{
}

void BackupProfileInfoWidget::setBackupProfile( BackupProfile* backupProfile )
{
    _backupProfile = backupProfile;

    if ( !_backupProfile ) {
        return;
    }

    _name->setText( _backupProfile->getName() );

    _profile->setBackupProfile( _backupProfile );
}

bool BackupProfileInfoWidget::isModified()
{
    if ( _backupProfile->getName() != _name->text() ) {
        return TRUE;
    }

    if ( _profile->getArchiveName() != _backupProfile->getArchiveName() ) {
        return TRUE;
    }

    TQString one = _backupProfile->getWorkingDirectory();
    TQString two = _profile->getWorkingDirectory();
    // 7/31/01: this breaks
    //    if ( _profile->getWorkingDirectory() != _backupProfile->getWorkingDirectory() ) {
    if( one != two ){
        return TRUE;
    }

    if ( _profile->getAbsoluteFiles().count() != _backupProfile->getAbsoluteFiles().count() ) {
        return TRUE;
    }

    TQStringList list1 = _profile->getAbsoluteFiles();
    TQStringList list2 = _backupProfile->getAbsoluteFiles();
    TQStringList::Iterator i = list1.begin();
    TQStringList::Iterator j = list2.begin();
    for ( ; i != list1.end(); ++i ) {
        for ( ; j != list2.end(); ++j ) {
            if ( *i == *j ) {
                break;
            }
        }
        if ( j == list2.end() ) {
            // Could not find i.current() in j => lists are not equal.
            return TRUE;
        }
    }

    if ( _profile->isOneFilesystem() != _backupProfile->isOneFilesystem() ) {
        return TRUE;
    }

    if ( _profile->isIncremental() != _backupProfile->isIncremental() ) {
        return TRUE;
    }

    if ( _profile->getSnapshotFile() != _backupProfile->getSnapshotFile() ) {
        return TRUE;
    }

    if ( _profile->getRemoveSnapshot() != _backupProfile->getRemoveSnapshot() ) {
        return TRUE;
    }

    return FALSE;
}

void BackupProfileInfoWidget::slotTextChanged( const TQString & )
{
    if ( !_backupProfile ) {
        return;
    }

    _apply->setEnabled( isModified() );
}

void BackupProfileInfoWidget::slotSomethingChanged()
{
    if ( !_backupProfile ) {
        return;
    }

    _apply->setEnabled( isModified() );
}

void BackupProfileInfoWidget::slotApply()
{
    if ( !_backupProfile ) {
        return;
    }

    _backupProfile->setName( _name->text() );
    _backupProfile->setArchiveName( _profile->getArchiveName() );
    _backupProfile->setWorkingDirectory( _profile->getWorkingDirectory() );
    _backupProfile->setAbsoluteFiles( _profile->getAbsoluteFiles() );
    _backupProfile->setOneFilesystem( _profile->isOneFilesystem() );
    _backupProfile->setIncremental( _profile->isIncremental() );
    _backupProfile->setSnapshotFile( _profile->getSnapshotFile() );
    _backupProfile->setRemoveSnapshot( _profile->getRemoveSnapshot() );
    
    _backupProfile->save();

    _apply->setEnabled( FALSE );
}

void BackupProfileInfoWidget::slotSetSelection()
{
    KDatMainWindow::getInstance()->setBackupFiles( _profile->getAbsoluteFiles() );
}

void BackupProfileInfoWidget::slotGetSelection()
{
    TQStringList files;
    KDatMainWindow::getInstance()->getBackupFiles( files );
    _profile->setAbsoluteFiles( files );
}