~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to nepomuk/services/backupsync/gui/backupwizardpages.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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>
5
 
 
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.
13
 
 
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.
18
 
 
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/>.
21
 
*/
22
 
 
23
 
 
24
 
#include "backupwizardpages.h"
25
 
#include "backupwizard.h"
26
 
 
27
 
#include "identifierwidget.h"
28
 
 
29
 
#include <KDebug>
30
 
#include <KLineEdit>
31
 
#include <KStandardDirs>
32
 
#include <KFileDialog>
33
 
#include <KUrlRequester>
34
 
 
35
 
#include <QtGui/QVBoxLayout>
36
 
#include <QtGui/QGroupBox>
37
 
#include <QtGui/QLineEdit>
38
 
 
39
 
Nepomuk::IntroPage::IntroPage(QWidget* parent)
40
 
    : QWizardPage( parent )
41
 
{
42
 
    setupUi( this );
43
 
    setTitle( i18n("Nepomuk Backup") );
44
 
    setSubTitle( i18n("Please choose one of the following options") );
45
 
}
46
 
 
47
 
int Nepomuk::IntroPage::nextId() const
48
 
{
49
 
    if( m_backup->isChecked() )
50
 
        return BackupWizard::Id_BackupSettingsPage;
51
 
    else if( m_restore->isChecked() )
52
 
        return BackupWizard::Id_RestoreSelectionPage;
53
 
 
54
 
    return -1;
55
 
}
56
 
 
57
 
 
58
 
//
59
 
// Backup Page
60
 
//
61
 
Nepomuk::BackupPage::BackupPage(QWidget* parent)
62
 
    : QWizardPage(parent),
63
 
      m_backupDone(false)
64
 
{
65
 
    setupUi( this );
66
 
    setTitle( i18n("Nepomuk Backup") );
67
 
    setSubTitle( i18n("Performing backup") );
68
 
    setCommitPage(true);
69
 
 
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()) );
74
 
}
75
 
 
76
 
void Nepomuk::BackupPage::initializePage()
77
 
{
78
 
    m_backupDone = false;
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() );
84
 
}
85
 
 
86
 
bool Nepomuk::BackupPage::isComplete() const
87
 
{
88
 
    return m_backupDone;
89
 
}
90
 
 
91
 
int Nepomuk::BackupPage::nextId() const
92
 
{
93
 
    return -1;
94
 
}
95
 
 
96
 
void Nepomuk::BackupPage::slotBackupDone()
97
 
{
98
 
    m_backupDone = true;
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 );
104
 
 
105
 
    emit completeChanged();
106
 
}
107
 
 
108
 
//
109
 
// Restore Selection Page
110
 
//
111
 
 
112
 
Nepomuk::RestoreSelectionPage::RestoreSelectionPage(QWidget* parent): QWizardPage(parent)
113
 
{
114
 
    setupUi( this );
115
 
}
116
 
 
117
 
void Nepomuk::RestoreSelectionPage::initializePage()
118
 
{
119
 
    QDir dir( KStandardDirs::locateLocal( "data", "nepomuk/backupsync/backups/" ) );
120
 
    QStringList backupFiles = dir.entryList( QDir::Files | QDir::NoDotAndDotDot, QDir::Name );
121
 
 
122
 
    foreach( const QString & backup, backupFiles ) {
123
 
        m_listWidget->addItem( backup );
124
 
    }
125
 
 
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);
134
 
    }
135
 
 
136
 
    connect( m_customBackupButton, SIGNAL(clicked(bool)), this, SLOT(slotCustomBackupUrl()) );
137
 
    connect( m_listWidget, SIGNAL(itemSelectionChanged()),
138
 
             this, SLOT(slotSelectionChanged()) );
139
 
 
140
 
    registerField( "backupToRestorePath", this, "backupFilePath" );
141
 
}
142
 
 
143
 
bool Nepomuk::RestoreSelectionPage::isComplete() const
144
 
{
145
 
    return QFile::exists(m_backupFilePath);
146
 
}
147
 
 
148
 
int Nepomuk::RestoreSelectionPage::nextId() const
149
 
{
150
 
    return BackupWizard::Id_RestorePage;
151
 
}
152
 
 
153
 
 
154
 
void Nepomuk::RestoreSelectionPage::slotSelectionChanged()
155
 
{
156
 
    if( QListWidgetItem* item = m_listWidget->currentItem() )
157
 
        m_backupFilePath = KStandardDirs::locateLocal("data", QLatin1String("nepomuk/backupsync/backups/") + item->data( Qt::DisplayRole ).toString() );
158
 
    else
159
 
        m_backupFilePath.truncate(0);
160
 
    kDebug() << m_backupFilePath;
161
 
    emit completeChanged();
162
 
}
163
 
 
164
 
void Nepomuk::RestoreSelectionPage::slotCustomBackupUrl()
165
 
{
166
 
    m_backupFilePath = KFileDialog::getOpenFileName( KUrl(), QString(), this );
167
 
    kDebug() << "NEW BACKUP URL : " << m_backupFilePath;
168
 
    if( isComplete() ) {
169
 
        wizard()->next();
170
 
    }
171
 
}
172
 
 
173
 
 
174
 
//
175
 
// Restore Page
176
 
//
177
 
Nepomuk::RestorePage::RestorePage(QWidget* parent)
178
 
    : QWizardPage(parent)
179
 
{
180
 
    // Page Properties
181
 
    setTitle( i18n("Restoring Backup") );
182
 
    setSubTitle( i18n("The backup is being restored...") );
183
 
 
184
 
    m_backupManager = new BackupManager( QLatin1String("org.kde.nepomuk.services.nepomukbackupsync"),
185
 
                                         "/backupmanager",
186
 
                                         QDBusConnection::sessionBus(), this);
187
 
    m_identifier = Identifier::instance();
188
 
 
189
 
    connect( m_identifier, SIGNAL(identificationDone(int,int)),
190
 
             this, SLOT(slotIdentificationDone(int,int)) );
191
 
}
192
 
 
193
 
 
194
 
void Nepomuk::RestorePage::initializePage()
195
 
{
196
 
    QString backupUrl = field("backupToRestorePath").toString();
197
 
    kDebug() << "Restoring : " << backupUrl;
198
 
 
199
 
 
200
 
    if( backupUrl.isEmpty() )
201
 
        backupUrl = KStandardDirs::locateLocal( "data", "nepomuk/backupsync/backup" );
202
 
 
203
 
    m_id = Identifier::instance()->process( SyncFile(backupUrl) );
204
 
 
205
 
    if( m_id == -1 ) {
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";
209
 
 
210
 
        QLabel * invalidLabel = new QLabel( i18n("Invalid backup file"), this );
211
 
        m_identifierWidget->hide();
212
 
        layout()->addWidget( invalidLabel );
213
 
    }
214
 
 
215
 
 
216
 
    QHBoxLayout * layout = new QHBoxLayout( this );
217
 
    setLayout( layout );
218
 
 
219
 
    m_identifierWidget = new IdentifierWidget( m_id, this );
220
 
    layout->addWidget( m_identifierWidget );
221
 
}
222
 
 
223
 
int Nepomuk::RestorePage::nextId() const
224
 
{
225
 
    return BackupWizard::Id_RestoreFinalPage;
226
 
}
227
 
 
228
 
bool Nepomuk::RestorePage::validatePage()
229
 
{
230
 
    m_identifier->completeIdentification( m_id );
231
 
    return true;
232
 
}
233
 
 
234
 
void Nepomuk::RestorePage::slotIdentificationDone(int id, int unidentified)
235
 
{
236
 
    if( id == m_id && unidentified == 0 ) {
237
 
        wizard()->next();
238
 
    }
239
 
}
240
 
 
241
 
//
242
 
// Backup Settings Page
243
 
//
244
 
 
245
 
Nepomuk::BackupSettingsPage::BackupSettingsPage(QWidget *parent)
246
 
    : QWizardPage(parent)
247
 
{
248
 
    setupUi(this);
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()));
255
 
 
256
 
    registerField(QLatin1String("backupUrl"), this, "backupUrl");
257
 
}
258
 
 
259
 
KUrl Nepomuk::BackupSettingsPage::backupUrl() const
260
 
{
261
 
    return m_editBackupUrl->url();
262
 
}
263
 
 
264
 
bool Nepomuk::BackupSettingsPage::isComplete() const
265
 
{
266
 
    const KUrl url = m_editBackupUrl->url();
267
 
    return  QDir( url.directory() ).exists() && url.isValid();
268
 
}
269
 
 
270
 
int Nepomuk::BackupSettingsPage::nextId() const
271
 
{
272
 
    return BackupWizard::Id_BackupPage;
273
 
}
274
 
 
275
 
 
276
 
//
277
 
// Backup Final Page
278
 
//
279
 
 
280
 
Nepomuk::RestoreFinalPage::RestoreFinalPage(QWidget* parent): QWizardPage(parent)
281
 
{
282
 
    setupUi( this );
283
 
    setCommitPage( true );
284
 
    m_merger = Merger::instance();
285
 
    connect( m_merger, SIGNAL(completed(int)), this, SLOT(slotDone(int)) );
286
 
 
287
 
    m_progressBar->setMinimum( 0 );
288
 
    m_progressBar->setMaximum( 100 );
289
 
 
290
 
    m_status->setText( i18nc("@info", "Merging the backup into the local Nepomuk database...") );
291
 
}
292
 
 
293
 
void Nepomuk::RestoreFinalPage::initializePage()
294
 
{
295
 
    QWizardPage::initializePage();
296
 
}
297
 
 
298
 
int Nepomuk::RestoreFinalPage::nextId() const
299
 
{
300
 
    return -1;
301
 
}
302
 
 
303
 
void Nepomuk::RestoreFinalPage::slotDone(int per)
304
 
{
305
 
    m_progressBar->setValue( per );
306
 
    if( per == 100 ) {
307
 
        m_status->setText( i18nc("@info", "Backup restored successfully") );
308
 
    }
309
 
}
310
 
 
311
 
 
312
 
Nepomuk::ErrorPage::ErrorPage( QWidget* parent )
313
 
    : QWizardPage(parent)
314
 
{
315
 
    setupUi(this);
316
 
    setFinalPage(true);
317
 
    m_labelPixmap->setPixmap(KIcon(QLatin1String("dialog-error")).pixmap(48,48));
318
 
    registerField( QLatin1String("errorMessage"), this, "errorMessage" );
319
 
}
320
 
 
321
 
QString Nepomuk::ErrorPage::message() const
322
 
{
323
 
    return m_labelMessage->text();
324
 
}
325
 
 
326
 
void Nepomuk::ErrorPage::setMessage(const QString& s)
327
 
{
328
 
    m_labelMessage->setText(s);
329
 
}
330
 
 
331
 
#include "backupwizardpages.moc"