1 | /* This file is part of the KDE project |
2 | Copyright (C) 2008 Omat Holding B.V. <info@omat.nl> |
3 | |
4 | This program is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | */ |
18 | |
19 | #include "restoreassistant.h" |
20 | #include "restore.h" |
21 | |
22 | #include <QLabel> |
23 | #include <QPushButton> |
24 | |
25 | #include <KAssistantDialog> |
26 | #include <KDebug> |
27 | #include <KFileDialog> |
28 | #include <KLocalizedString> |
29 | #include <KVBox> |
30 | |
31 | RestoreAssistant::RestoreAssistant( QWidget *parent ) : KAssistantDialog( parent ), m_selectFileButton(0) |
32 | { |
33 | m_restore = new Restore( this ); |
34 | connect( m_restore, SIGNAL(completed(bool)), SLOT(slotRestoreComplete(bool)) ); |
35 | bool possible = m_restore->possible(); |
36 | |
37 | KVBox *box1 = new KVBox( this ); |
38 | QLabel *label1 = new QLabel( box1 ); |
39 | label1->setWordWrap( true ); |
40 | if ( !possible ) { |
41 | label1->setText( QLatin1Char('\n') + i18n( "The backup cannot be restored. Either the mysql application " |
42 | "is not installed, or the bzip2 application is not found. " |
43 | "Please install those and make sure they can be found in " |
44 | "the current path. Restart this Assistant when this is fixed." ) ); |
45 | } else { |
46 | label1->setText( QLatin1Char('\n') + i18n( "Please select the file to restore. Note that restoring a " |
47 | "backup will overwrite all existing data. You might want to " |
48 | "make a backup first and please consider closing all Akonadi " |
49 | "applications (but do not stop the akonadi server)." ) + QLatin1String("\n\n" ) ); |
50 | |
51 | m_selectFileButton = new QPushButton( i18n( "&Click Here to Select the File to Restore..." ), box1 ); |
52 | connect( m_selectFileButton, SIGNAL(clicked(bool)), SLOT(slotSelectFile()) ); |
53 | |
54 | QLabel *label2 = new QLabel( QLatin1String("\n\n" ) + i18n( "Press 'Next' to start the Restore" ), box1 ); |
55 | label2->setWordWrap( true ); |
56 | label2->setAlignment( Qt::AlignRight ); |
57 | } |
58 | m_page1 = new KPageWidgetItem( box1, i18n( "Welcome to the Restore Assistant" ) ); |
59 | setValid( m_page1, false ); |
60 | |
61 | m_restoreProgressLabel = new QLabel( this ); |
62 | m_restoreProgressLabel->setWordWrap( true ); |
63 | m_page2 = new KPageWidgetItem( m_restoreProgressLabel, i18n( "Restoring" ) ); |
64 | setValid( m_page2, false ); |
65 | |
66 | addPage( m_page1 ); |
67 | addPage( m_page2 ); |
68 | showButton( KDialog::Help, false ); |
69 | |
70 | connect( this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), |
71 | SLOT(slotPageChanged(KPageWidgetItem*,KPageWidgetItem*)) ); |
72 | } |
73 | |
74 | void RestoreAssistant::slotSelectFile() |
75 | { |
76 | m_filename = KFileDialog::getOpenFileName( KUrl( QLatin1String("kfiledialog://BackupDir" ) ) ); |
77 | if ( !m_filename.isEmpty() ) { |
78 | m_selectFileButton->setText( m_filename ); |
79 | setValid( m_page1, true ); |
80 | } |
81 | } |
82 | |
83 | void RestoreAssistant::slotPageChanged( KPageWidgetItem *current, KPageWidgetItem* ) |
84 | { |
85 | if ( current != m_page2 ) |
86 | return; |
87 | |
88 | setValid( m_page2, false ); |
89 | m_restoreProgressLabel->setText( i18n( "Please be patient, the backup is being restored..." ) ); |
90 | m_restore->restore( m_filename ); |
91 | } |
92 | |
93 | void RestoreAssistant::slotRestoreComplete( bool ok ) |
94 | { |
95 | if ( ok ) { |
96 | m_restoreProgressLabel->setText( i18n( "The backup has been restored. Note that KWallet " |
97 | "stored passwords are not restored, so applications might " |
98 | "ask for those." ) ); |
99 | setValid( m_page2, true ); |
100 | } else |
101 | m_restoreProgressLabel->setText( i18n( "The restore process ended unexpectedly. Please " |
102 | "report a bug, so we can find out what the cause is." ) ); |
103 | } |
104 | |
105 | |