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 "backupassistant.h" |
20 | #include "backup.h" |
21 | |
22 | #include <QLabel> |
23 | #include <QDateTime> |
24 | #include <QPushButton> |
25 | |
26 | #include <KAssistantDialog> |
27 | #include <KDebug> |
28 | #include <KFileDialog> |
29 | #include <KLocalizedString> |
30 | #include <KVBox> |
31 | |
32 | BackupAssistant::BackupAssistant( QWidget *parent ) : KAssistantDialog( parent ), m_selectFileButton( 0 ) |
33 | { |
34 | m_backup = new Backup( this ); |
35 | connect( m_backup, SIGNAL(completed(bool)), SLOT(slotBackupComplete(bool)) ); |
36 | bool possible = m_backup->possible(); |
37 | |
38 | KVBox *box1 = new KVBox( this ); |
39 | QLabel *label1 = new QLabel( box1 ); |
40 | label1->setWordWrap( true ); |
41 | if ( !possible ) { |
42 | label1->setText( QLatin1Char('\n') + i18n( "The backup cannot be made. Either the mysqldump application " |
43 | "is not installed, or the bzip2 application is not found. " |
44 | "Please install those and make sure they can be found in " |
45 | "the current path. Restart this Assistant when this is fixed." ) ); |
46 | } else { |
47 | label1->setText( QLatin1Char('\n') + i18n( "Please select the file where to store " |
48 | "the backup, give it the extension .tar.bz2" ) + QLatin1String("\n\n" ) ); |
49 | |
50 | m_selectFileButton = new QPushButton( i18n( "&Click Here to Select the Backup Location..." ), box1 ); |
51 | connect( m_selectFileButton, SIGNAL(clicked(bool)), SLOT(slotSelectFile()) ); |
52 | |
53 | QLabel *label2 = new QLabel( QLatin1String("\n\n" ) + i18n( "Press 'Next' to start the Backup" ), box1 ); |
54 | label2->setWordWrap( true ); |
55 | label2->setAlignment( Qt::AlignRight ); |
56 | } |
57 | m_page1 = new KPageWidgetItem( box1, i18n( "Welcome to the Backup Assistant" ) ); |
58 | setValid( m_page1, false ); |
59 | |
60 | m_backupProgressLabel = new QLabel( this ); |
61 | m_backupProgressLabel->setWordWrap( true ); |
62 | m_page2 = new KPageWidgetItem( m_backupProgressLabel, i18n( "Making the backup" ) ); |
63 | setValid( m_page2, false ); |
64 | |
65 | addPage( m_page1 ); |
66 | addPage( m_page2 ); |
67 | showButton( KDialog::Help, false ); |
68 | |
69 | connect( this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), |
70 | SLOT(slotPageChanged(KPageWidgetItem*,KPageWidgetItem*)) ); |
71 | } |
72 | |
73 | void BackupAssistant::slotSelectFile() |
74 | { |
75 | QString file = QLatin1String( "akonadibackup-" ) + |
76 | QDateTime::currentDateTime().toString( QLatin1String("yyyyMMdd" ) ) + QLatin1String(".tar.bz2" ); |
77 | |
78 | // Build one special, as we want the keyword /and/ a proposed filename |
79 | KFileDialog dlg( KUrl( QLatin1String("kfiledialog://BackupDir" ) ), QString(), this ); |
80 | dlg.setSelection( file ); |
81 | dlg.setOperationMode( KFileDialog::Saving ); |
82 | dlg.setMode( KFile::File ); |
83 | dlg.setWindowTitle( i18n( "Save As" ) ); |
84 | dlg.exec(); |
85 | |
86 | m_filename = dlg.selectedFile(); |
87 | if ( !m_filename.isEmpty() ) { |
88 | m_selectFileButton->setText( m_filename ); |
89 | setValid( m_page1, true ); |
90 | } |
91 | } |
92 | |
93 | void BackupAssistant::slotPageChanged( KPageWidgetItem *current, KPageWidgetItem* ) |
94 | { |
95 | if ( current != m_page2 ) |
96 | return; |
97 | |
98 | setValid( m_page2, false ); |
99 | m_backupProgressLabel->setText( i18n( "Please be patient, the backup is being created..." ) ); |
100 | m_backup->create( m_filename ); |
101 | } |
102 | |
103 | void BackupAssistant::slotBackupComplete( bool ok ) |
104 | { |
105 | if ( ok ) { |
106 | m_backupProgressLabel->setText( i18n( "The backup has been made. Please verify manually " |
107 | "if the backup is complete. Also note that KWallet " |
108 | "stored passwords are not in the backup, you might " |
109 | "want to verify you have a backup of those elsewhere." ) ); |
110 | setValid( m_page2, true ); |
111 | } else |
112 | m_backupProgressLabel->setText( i18n( "The backup process ended unexpectedly. Please " |
113 | "report a bug, so we can find out what the cause is." ) ); |
114 | } |
115 | |
116 | |