summaryrefslogtreecommitdiffstats
path: root/keep/app/addbackupwizard.cpp
blob: 5de42e1e06d3ee27ae3fdbef1e7cc0fea9c72472 (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
/* This file is part of the Keep project
   Copyright (C) 2005 Jean-Rémy Falleri <jr.falleri@laposte.net>

   Keep 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.

   Keep 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 Keep; if not, write to the
   Free Software Foundation, Inc.,
   51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.           */

#include "addbackupwizard.h"

#include <tqpushbutton.h>
#include <kiconloader.h>
#include <tqcheckbox.h>
#include <kurlrequester.h>
#include <knuminput.h>
#include <kdebug.h>

AddBackupWizard::AddBackupWizard(TQWidget *parent,const char* name): KWizard( parent, name, true)
{
	initView();
	resize( minimumSizeHint() );

	setNextEnabled(page1,false);
	setNextEnabled(page2,false);
	setFinishEnabled(page3, false);
	
	this->setCaption("Add a backup");

	initConnections();
}

AddBackupWizard::AddBackupWizard(Backup backup,TQWidget *parent,const char* name): KWizard( parent, name, true)
{
	initView();

	this->setCaption("Edit backup");
	
	addBackupWizard1View->source->setURL(backup.source());
	addBackupWizard1View->useIncludeExclude->setChecked(backup.useIncludeExclude());
	addBackupWizard2View->dest->setURL(backup.dest());
	addBackupWizard3View->interval->setValue(backup.interval());
	addBackupWizard3View->deleteAfter->setValue(backup.deleteAfter());
	addBackupWizard3View->neverDelete->setChecked(backup.neverDelete());
	addBackupWizard3View->useCompression->setChecked(backup.useCompression());
	addBackupWizard3View->excludeSpecialFiles->setChecked(backup.excludeSpecialFiles());
	addBackupWizard3View->useAdvancedConfig->setChecked(backup.useAdvancedConfig());

	includeExcludeDialog->setIncludeExcludeList(backup.includeExcludeList());
	advancedBackupConfigDialog->setOptionList(backup.optionList());

	resize( minimumSizeHint() );

	setNextEnabled(page1,true);
	setNextEnabled(page2,true);
	setFinishEnabled(page3, true);

	initConnections();
}

void AddBackupWizard::initView()
{
	advancedBackupConfigDialog = new AdvancedBackupConfigDialog(this);
	includeExcludeDialog = new IncludeExcludeDialog(this);

	TDEIconLoader icons;
	this->setIcon( icons.loadIcon( "wizard",TDEIcon::Small ));

	setupPage1();
	setupPage2();
	setupPage3();
}

void AddBackupWizard::initConnections()
{
	connect( addBackupWizard1View->source, TQ_SIGNAL( textChanged(const TQString&)), this, TQ_SLOT( slotPage1Changed() ) );
	connect( addBackupWizard2View->dest, TQ_SIGNAL( textChanged(const TQString&)), this, TQ_SLOT( slotPage2Changed() ) );
	connect( addBackupWizard3View->advancedConfig, TQ_SIGNAL( clicked()),this,TQ_SLOT(slotShowAdvancedConfig()));
	connect( addBackupWizard1View->includeExclude, TQ_SIGNAL( clicked()),this,TQ_SLOT(slotShowIncludeExclude()));
	connect( finishButton(), TQ_SIGNAL( clicked()), this, TQ_SLOT( slotFinishClicked() ) );
}

void AddBackupWizard::setupPage1()
{
	page1 = new TQHBox( this );
	page1->setSpacing(0);
	page1->setMargin(0);

	addBackupWizard1View = new AddBackupWizard1View(page1,"addBackupWizard1View");
	addBackupWizard1View->source->setMode(KFile::Directory);
	TDEIconLoader *icons = TDEGlobal::iconLoader();
	addBackupWizard1View->includeExclude->setPixmap(icons->loadIcon("configure",TDEIcon::Toolbar,16));

	addPage( page1, "Directory to backup" );
}

void AddBackupWizard::setupPage2()
{
	page2 = new TQHBox( this );
	page2->setSpacing(0);
	page2->setMargin(0);

	addBackupWizard2View = new AddBackupWizard2View(page2,"addBackupWizard2View");
	addBackupWizard2View->dest->setMode(KFile::Directory);

	addPage( page2, "Backup location" );
}

void AddBackupWizard::setupPage3()
{
	page3 = new TQHBox( this );
	page3->setSpacing(0);
	page3->setMargin(0);

	addBackupWizard3View = new AddBackupWizard3View(page3,"addBackupWizard3View");
	TDEIconLoader *icons = TDEGlobal::iconLoader();
	addBackupWizard3View->advancedConfig->setPixmap(icons->loadIcon("configure",TDEIcon::Toolbar,16));

	addPage( page3, "Backup options" );
}

void AddBackupWizard::slotPage1Changed()
{
	setNextEnabled(page1,false);
	setFinishEnabled(page3,false);
	if ( addBackupWizard1View->source->url() != "" )
	{
		setNextEnabled(page1,true);
		if ( addBackupWizard2View->dest->url() != "" )
			setFinishEnabled(page3,true);	
	}
}

void AddBackupWizard::slotPage2Changed()
{
	setNextEnabled(page2,false);
	setFinishEnabled(page3,false);
	if ( addBackupWizard2View->dest->url() != "" )
	{
		setNextEnabled(page2,true);
		if (  addBackupWizard1View->source->url() != "" )
			setFinishEnabled(page3,true);	
	}
}

void AddBackupWizard::slotShowAdvancedConfig()
{
	advancedBackupConfigDialog->show();
}

void AddBackupWizard::slotShowIncludeExclude()
{
	includeExcludeDialog->show();
}

Backup AddBackupWizard::backup()
{
	TQString source = addBackupWizard1View->source->url();
	TQString dest = addBackupWizard2View->dest->url();
	int interval = addBackupWizard3View->interval->value();
	int deleteAfter = addBackupWizard3View->deleteAfter->value();
	bool neverDelete = addBackupWizard3View->neverDelete->isChecked();
	bool useCompression = addBackupWizard3View->useCompression->isChecked();
	bool excludeSpecialFiles = addBackupWizard3View->excludeSpecialFiles->isChecked();
	bool useAdvancedConfig = addBackupWizard3View->useAdvancedConfig->isChecked();
	TQStringList optionList = advancedBackupConfigDialog->optionList();
	bool useIncludeExclude = addBackupWizard1View->useIncludeExclude->isChecked();
	TQStringList includeExcludeList = includeExcludeDialog->includeExcludeList();
	Backup backup(source,dest,interval,deleteAfter,neverDelete,useCompression,excludeSpecialFiles,useAdvancedConfig,optionList,useIncludeExclude,includeExcludeList);
	
	return backup;
}

void AddBackupWizard::slotFinishClicked()
{
	emit backupSetted(backup());
}

#include "addbackupwizard.moc"