summaryrefslogtreecommitdiffstats
path: root/keep/app/restorebackupwizard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'keep/app/restorebackupwizard.cpp')
-rw-r--r--keep/app/restorebackupwizard.cpp293
1 files changed, 293 insertions, 0 deletions
diff --git a/keep/app/restorebackupwizard.cpp b/keep/app/restorebackupwizard.cpp
new file mode 100644
index 0000000..de238e0
--- /dev/null
+++ b/keep/app/restorebackupwizard.cpp
@@ -0,0 +1,293 @@
+/* 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 "restorebackupwizard.h"
+
+#include <qpushbutton.h>
+#include <kiconloader.h>
+#include <klistview.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kactivelabel.h>
+#include <qcheckbox.h>
+#include <qradiobutton.h>
+#include <kurlrequester.h>
+#include <qvaluelist.h>
+#include <qdir.h>
+#include <kmessagebox.h>
+
+#include "backuplistviewitem.h"
+#include "backupconfig.h"
+
+#include "listviewtooltip.h"
+#include "incrementlistviewitem.h"
+
+RestoreBackupWizard::RestoreBackupWizard(QWidget *parent,const char* name): KWizard( parent, name, true)
+{
+ m_manager = new RDBManager();
+ connect( m_manager, SIGNAL(backupError(Backup,QString)), this, SLOT(slotRestoreError(Backup,QString)) );
+
+ KIconLoader icons;
+ this->setIcon( icons.loadIcon( "wizard",KIcon::Small ));
+ this->setCaption("Restore a backup");
+
+ m_popup = new KPopupMenu(this);
+ m_popup->insertTitle(i18n("Menu"));
+ m_popup->insertItem(i18n("Show differences destination/backup"), this, SLOT(slotShowDiff()));
+ m_popup->insertItem(i18n("List changed files"), this, SLOT(slotShowChanged()));
+ m_popup->insertItem(i18n("List files"), this, SLOT(slotShowList()));
+
+ setupPage1();
+ setupPage2();
+ setupPage3();
+
+ initConnections();
+
+ setNextEnabled(page1,false);
+ setNextEnabled(page2,true);
+ setFinishEnabled(page3, false);
+
+ resize( minimumSizeHint() );
+}
+
+RestoreBackupWizard::~RestoreBackupWizard()
+{
+ delete m_manager;
+}
+
+void RestoreBackupWizard::initConnections()
+{
+ // If custom source setted
+ connect(restoreBackupWizard1View->btnCustomSource, SIGNAL( toggled(bool)),this,SLOT(slotCustomSourceChecked(bool)));
+
+ // Date selection popup menu
+ connect(restoreBackupWizard3View->incrementList, SIGNAL(contextMenu (KListView *, QListViewItem *, const QPoint &)), this, SLOT(slotContextMenu(KListView *,QListViewItem*,const QPoint&)));
+
+ // Page 1 changes
+ connect(restoreBackupWizard1View->m_lstBackup,SIGNAL(selectionChanged()),this,SLOT(slotPage1Changed()));
+ connect(restoreBackupWizard1View->btnCustomSource,SIGNAL(toggled(bool)),this,SLOT(slotPage1Changed()));
+ connect(restoreBackupWizard1View->customSource,SIGNAL(textChanged(const QString &)),this,SLOT(slotPage1Changed()));
+
+ // Page 2 changes
+ connect(restoreBackupWizard2View->btnCustomDest,SIGNAL(toggled(bool)),this,SLOT(slotPage2Changed()));
+ connect(restoreBackupWizard2View->customDest,SIGNAL(textChanged(const QString &)),this,SLOT(slotPage2Changed()));
+
+ // Page 3 Changes
+ connect(restoreBackupWizard3View->incrementList,SIGNAL(selectionChanged()),this,SLOT(slotPage3Changed()));
+
+ // Finish button
+ connect(finishButton(),SIGNAL(clicked()),this,SLOT(slotRestoreBackup()));
+}
+
+void RestoreBackupWizard::slotPage1Changed()
+{
+ setNextEnabled(page1,false);
+ Backup b;
+ // Checks if a standard backup is selected.
+ if ( !restoreBackupWizard1View->btnCustomSource->isChecked() )
+ {
+ QListViewItem *item = restoreBackupWizard1View->m_lstBackup->selectedItem();
+ if ( item )
+ {
+ BackupListViewItem *backupItem = static_cast<BackupListViewItem*>(item);
+ b = backupItem->backup();
+ }
+ }
+ // If not, checks if a custom source
+ else
+ {
+ if ( restoreBackupWizard1View->customSource->url() != "" )
+ b.setDest(restoreBackupWizard1View->customSource->url());
+ }
+ if ( b.dest() != "" )
+ {
+ RDBManager manager;
+ QDateTime lastBackup = manager.lastIncrement(b);
+ restoreBackupWizard3View->lblLastBackup->setText(lastBackup.toString(Qt::LocalDate));
+ QValueList<QDateTime> increments = manager.incrementList(b);
+ if ( increments.size() != 0 )
+ {
+ restoreBackupWizard3View->incrementList->clear();
+ QValueList<QDateTime>::iterator it;
+ for ( it = increments.begin(); it != increments.end(); ++it )
+ {
+ IncrementListViewItem *item = new IncrementListViewItem(restoreBackupWizard3View->incrementList,(*it));
+ }
+ setBackup(b);
+ setNextEnabled(page1,true);
+ }
+ }
+}
+
+void RestoreBackupWizard::slotPage2Changed()
+{
+ setNextEnabled(page2,false);
+ if ( !restoreBackupWizard2View->btnCustomDest->isChecked() )
+ {
+ QListViewItem *item = restoreBackupWizard1View->m_lstBackup->selectedItem();
+ BackupListViewItem *backupItem = static_cast<BackupListViewItem*>(item);
+ setBackup(backupItem->backup());
+ setNextEnabled(page2,true);
+ }
+ else
+ {
+ QDir dir( restoreBackupWizard2View->customDest->url() );
+ if ( dir.exists() && restoreBackupWizard2View->customDest->url() != "" )
+ {
+ Backup b = backup();
+ b.setSource(restoreBackupWizard2View->customDest->url());
+ setBackup(b);
+ setNextEnabled(page2,true);
+ }
+ }
+}
+
+void RestoreBackupWizard::slotPage3Changed()
+{
+ setFinishEnabled(page3,false);
+ QListViewItem *item = restoreBackupWizard3View->incrementList->selectedItem();
+ if ( item )
+ setFinishEnabled(page3,true);
+}
+
+void RestoreBackupWizard::slotCustomSourceChecked(bool value)
+{
+ if ( value )
+ {
+ restoreBackupWizard2View->btnCustomDest->setChecked(true);
+ restoreBackupWizard2View->btnCustomDest->setEnabled(false);
+ }
+ else
+ restoreBackupWizard2View->btnCustomDest->setEnabled(true);
+}
+
+void RestoreBackupWizard::setupPage1()
+{
+ page1 = new QHBox( this );
+ page1->setSpacing(0);
+ page1->setMargin(0);
+
+ restoreBackupWizard1View = new RestoreBackupWizard1View(page1,"restoreBackupWizard1View");
+ BackupConfig *backupConfig = new BackupConfig();
+ QValueList<Backup> backupList = backupConfig->backupList();
+ QValueList<Backup>::iterator it;
+ for ( it = backupList.begin(); it != backupList.end(); ++it )
+ {
+ new BackupListViewItem(restoreBackupWizard1View->m_lstBackup,*it);
+ }
+
+ QToolTip::remove(restoreBackupWizard1View->m_lstBackup);
+ new ListViewToolTip(restoreBackupWizard1View->m_lstBackup);
+
+ restoreBackupWizard1View->customSource->setMode(KFile::Directory);
+
+ addPage( page1, "Directory to restore" );
+ delete backupConfig;
+}
+
+void RestoreBackupWizard::setupPage2()
+{
+ page2 = new QHBox( this );
+ page2->setSpacing(0);
+ page2->setMargin(0);
+
+ restoreBackupWizard2View = new RestoreBackupWizard2View(page2,"restoreBackupWizard2View");
+
+ restoreBackupWizard2View->customDest->setMode(KFile::Directory);
+
+ addPage(page2, "Destination directory" );
+}
+
+void RestoreBackupWizard::setupPage3()
+{
+ page3 = new QHBox( this );
+ page3->setSpacing(0);
+ page3->setMargin(0);
+
+ restoreBackupWizard3View = new RestoreBackupWizard3View(page3,"restoreBackupWizard3View");
+
+ restoreBackupWizard3View->incrementList->setSorting(0,false);
+ restoreBackupWizard3View->lblDate->setText(QDateTime::currentDateTime().toString(Qt::LocalDate));
+ addPage( page3, "Date to restore" );
+}
+
+void RestoreBackupWizard::slotContextMenu(KListView *list,QListViewItem *item,const QPoint&p)
+{
+ m_popup->popup(p, 1);
+}
+
+Backup RestoreBackupWizard::backup()
+{
+ return m_backup;
+}
+
+void RestoreBackupWizard::setBackup(Backup backup)
+{
+ m_backup = backup;
+}
+
+void RestoreBackupWizard::slotShowDiff()
+{
+ Backup b = backup();
+ QListViewItem *item2 = restoreBackupWizard3View->incrementList->selectedItem();
+ IncrementListViewItem *incrementItem = static_cast<IncrementListViewItem*>(item2);
+ QDateTime date = incrementItem->date();
+ QString diff = m_manager->compareAtTime(b,date);
+ QString message = "<p><b>" + i18n("List of modifications since the selected increment:") + "</b></p><p>" + diff + "</p>";
+ KMessageBox::information(this,message,i18n("Modifications"));
+}
+
+void RestoreBackupWizard::slotShowChanged()
+{
+ Backup b = backup();
+ QListViewItem *item2 = restoreBackupWizard3View->incrementList->selectedItem();
+ IncrementListViewItem *incrementItem = static_cast<IncrementListViewItem*>(item2);
+ QDateTime date = incrementItem->date();
+ QString changed = m_manager->listChangedSince(b,date);
+ if ( changed == "" )
+ changed = i18n("Nothing.");
+ QString message = "<p><b>" + i18n("List of changed files since the selected increment:") + "</b></p><p>" + changed + "</p>";
+ KMessageBox::information(this,message,i18n("Changed files"));
+}
+
+void RestoreBackupWizard::slotShowList()
+{
+ Backup b = backup();
+ QListViewItem *item2 = restoreBackupWizard3View->incrementList->selectedItem();
+ IncrementListViewItem *incrementItem = static_cast<IncrementListViewItem*>(item2);
+ QDateTime date = incrementItem->date();
+ QString list = m_manager->listAtTime(b,date);
+ QString message = "<p><b>" + i18n("List of files in the selected increment:") + "</b></p><p>" + list + "</p>";
+ KMessageBox::information(this,message,i18n("List of files"));
+}
+
+void RestoreBackupWizard::slotRestoreBackup()
+{
+ Backup b = backup();
+ QListViewItem *item2 = restoreBackupWizard3View->incrementList->selectedItem();
+ IncrementListViewItem *incrementItem = static_cast<IncrementListViewItem*>(item2);
+ QDateTime date = incrementItem->date();
+ m_manager->slotRestoreBackup(b,date);
+}
+
+void RestoreBackupWizard::slotRestoreError(Backup backup,QString errorMessage)
+{
+ KMessageBox::error(this,i18n("<p><b>An error occured restoring %1 backup:</b></p><p>%2</p>").arg(backup.dest()).arg(errorMessage));
+}
+
+#include "restorebackupwizard.moc"