2
This file is part of the Nepomuk KDE project.
3
Copyright (C) 2010 Vishesh Handa <handa.vish@gmail.com>
4
Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) version 3, or any
10
later version accepted by the membership of KDE e.V. (or its
11
successor approved by the membership of KDE e.V.), which shall
12
act as a proxy defined in Section 6 of version 3 of the license.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library. If not, see <http://www.gnu.org/licenses/>.
24
#include "backupwizardpages.h"
25
#include "backupwizard.h"
27
#include "identifierwidget.h"
31
#include <KStandardDirs>
32
#include <KFileDialog>
33
#include <KUrlRequester>
35
#include <QtGui/QVBoxLayout>
36
#include <QtGui/QGroupBox>
37
#include <QtGui/QLineEdit>
39
Nepomuk::IntroPage::IntroPage(QWidget* parent)
40
: QWizardPage( parent )
43
setTitle( i18n("Nepomuk Backup") );
44
setSubTitle( i18n("Please choose one of the following options") );
47
int Nepomuk::IntroPage::nextId() const
49
if( m_backup->isChecked() )
50
return BackupWizard::Id_BackupSettingsPage;
51
else if( m_restore->isChecked() )
52
return BackupWizard::Id_RestoreSelectionPage;
61
Nepomuk::BackupPage::BackupPage(QWidget* parent)
62
: QWizardPage(parent),
66
setTitle( i18n("Nepomuk Backup") );
67
setSubTitle( i18n("Performing backup") );
70
m_backupManager = new BackupManager( QLatin1String("org.kde.nepomuk.services.nepomukbackupsync"),
71
QLatin1String("/backupmanager"),
72
QDBusConnection::sessionBus(), this);
73
connect( m_backupManager, SIGNAL(backupDone()), this, SLOT(slotBackupDone()) );
76
void Nepomuk::BackupPage::initializePage()
79
KUrl backupUrl = field(QLatin1String("backupUrl")).value<KUrl>();
80
kDebug() << backupUrl;
81
m_status->setText( i18nc("@info", "Writing Nepomuk database backup to <filename>%1</filename>...",
82
field(QLatin1String("backupUrl")).value<KUrl>().pathOrUrl()));
83
m_backupManager->backup( backupUrl.toLocalFile() );
86
bool Nepomuk::BackupPage::isComplete() const
91
int Nepomuk::BackupPage::nextId() const
96
void Nepomuk::BackupPage::slotBackupDone()
99
m_status->setText( i18nc("@info","Backup of the Nepomuk database successfully written to <filename>%1</filename>.",
100
field(QLatin1String("backupUrl")).value<KUrl>().pathOrUrl()) );
101
setSubTitle( i18n("Backup completed successfully") );
102
m_progressBar->setMaximum( 100 );
103
m_progressBar->setValue( 100 );
105
emit completeChanged();
109
// Restore Selection Page
112
Nepomuk::RestoreSelectionPage::RestoreSelectionPage(QWidget* parent): QWizardPage(parent)
117
void Nepomuk::RestoreSelectionPage::initializePage()
119
QDir dir( KStandardDirs::locateLocal( "data", "nepomuk/backupsync/backups/" ) );
120
QStringList backupFiles = dir.entryList( QDir::Files | QDir::NoDotAndDotDot, QDir::Name );
122
foreach( const QString & backup, backupFiles ) {
123
m_listWidget->addItem( backup );
126
if( backupFiles.isEmpty() ) {
127
QLabel * errorLabel = new QLabel( i18nc("@info", "No system backups found. Please select a custom backup path.") , this);
128
QGridLayout* layout = new QGridLayout(m_listWidget);
129
layout->addWidget(errorLabel, 1, 1);
130
layout->setRowStretch(0,1);
131
layout->setRowStretch(2,1);
132
layout->setColumnStretch(0,1);
133
layout->setColumnStretch(2,1);
136
connect( m_customBackupButton, SIGNAL(clicked(bool)), this, SLOT(slotCustomBackupUrl()) );
137
connect( m_listWidget, SIGNAL(itemSelectionChanged()),
138
this, SLOT(slotSelectionChanged()) );
140
registerField( "backupToRestorePath", this, "backupFilePath" );
143
bool Nepomuk::RestoreSelectionPage::isComplete() const
145
return QFile::exists(m_backupFilePath);
148
int Nepomuk::RestoreSelectionPage::nextId() const
150
return BackupWizard::Id_RestorePage;
154
void Nepomuk::RestoreSelectionPage::slotSelectionChanged()
156
if( QListWidgetItem* item = m_listWidget->currentItem() )
157
m_backupFilePath = KStandardDirs::locateLocal("data", QLatin1String("nepomuk/backupsync/backups/") + item->data( Qt::DisplayRole ).toString() );
159
m_backupFilePath.truncate(0);
160
kDebug() << m_backupFilePath;
161
emit completeChanged();
164
void Nepomuk::RestoreSelectionPage::slotCustomBackupUrl()
166
m_backupFilePath = KFileDialog::getOpenFileName( KUrl(), QString(), this );
167
kDebug() << "NEW BACKUP URL : " << m_backupFilePath;
177
Nepomuk::RestorePage::RestorePage(QWidget* parent)
178
: QWizardPage(parent)
181
setTitle( i18n("Restoring Backup") );
182
setSubTitle( i18n("The backup is being restored...") );
184
m_backupManager = new BackupManager( QLatin1String("org.kde.nepomuk.services.nepomukbackupsync"),
186
QDBusConnection::sessionBus(), this);
187
m_identifier = Identifier::instance();
189
connect( m_identifier, SIGNAL(identificationDone(int,int)),
190
this, SLOT(slotIdentificationDone(int,int)) );
194
void Nepomuk::RestorePage::initializePage()
196
QString backupUrl = field("backupToRestorePath").toString();
197
kDebug() << "Restoring : " << backupUrl;
200
if( backupUrl.isEmpty() )
201
backupUrl = KStandardDirs::locateLocal( "data", "nepomuk/backupsync/backup" );
203
m_id = Identifier::instance()->process( SyncFile(backupUrl) );
206
//FIXME: This isn't implemented in the service. It's just there so that we have a
207
// string that can be translated.
208
kDebug() << "Invalid sync file";
210
QLabel * invalidLabel = new QLabel( i18n("Invalid backup file"), this );
211
m_identifierWidget->hide();
212
layout()->addWidget( invalidLabel );
216
QHBoxLayout * layout = new QHBoxLayout( this );
219
m_identifierWidget = new IdentifierWidget( m_id, this );
220
layout->addWidget( m_identifierWidget );
223
int Nepomuk::RestorePage::nextId() const
225
return BackupWizard::Id_RestoreFinalPage;
228
bool Nepomuk::RestorePage::validatePage()
230
m_identifier->completeIdentification( m_id );
234
void Nepomuk::RestorePage::slotIdentificationDone(int id, int unidentified)
236
if( id == m_id && unidentified == 0 ) {
242
// Backup Settings Page
245
Nepomuk::BackupSettingsPage::BackupSettingsPage(QWidget *parent)
246
: QWizardPage(parent)
249
setTitle( i18n("Nepomuk Backup") );
250
setSubTitle( i18n("Please configure the Nepomuk backup") );
251
connect(m_editBackupUrl, SIGNAL(textChanged(QString)),
252
this, SIGNAL(completeChanged()));
253
connect(m_editBackupUrl, SIGNAL(urlSelected(KUrl)),
254
this, SIGNAL(completeChanged()));
256
registerField(QLatin1String("backupUrl"), this, "backupUrl");
259
KUrl Nepomuk::BackupSettingsPage::backupUrl() const
261
return m_editBackupUrl->url();
264
bool Nepomuk::BackupSettingsPage::isComplete() const
266
const KUrl url = m_editBackupUrl->url();
267
return QDir( url.directory() ).exists() && url.isValid();
270
int Nepomuk::BackupSettingsPage::nextId() const
272
return BackupWizard::Id_BackupPage;
280
Nepomuk::RestoreFinalPage::RestoreFinalPage(QWidget* parent): QWizardPage(parent)
283
setCommitPage( true );
284
m_merger = Merger::instance();
285
connect( m_merger, SIGNAL(completed(int)), this, SLOT(slotDone(int)) );
287
m_progressBar->setMinimum( 0 );
288
m_progressBar->setMaximum( 100 );
290
m_status->setText( i18nc("@info", "Merging the backup into the local Nepomuk database...") );
293
void Nepomuk::RestoreFinalPage::initializePage()
295
QWizardPage::initializePage();
298
int Nepomuk::RestoreFinalPage::nextId() const
303
void Nepomuk::RestoreFinalPage::slotDone(int per)
305
m_progressBar->setValue( per );
307
m_status->setText( i18nc("@info", "Backup restored successfully") );
312
Nepomuk::ErrorPage::ErrorPage( QWidget* parent )
313
: QWizardPage(parent)
317
m_labelPixmap->setPixmap(KIcon(QLatin1String("dialog-error")).pixmap(48,48));
318
registerField( QLatin1String("errorMessage"), this, "errorMessage" );
321
QString Nepomuk::ErrorPage::message() const
323
return m_labelMessage->text();
326
void Nepomuk::ErrorPage::setMessage(const QString& s)
328
m_labelMessage->setText(s);
331
#include "backupwizardpages.moc"