1
/* This file is part of the KDE project
2
Copyright (C) 2008 Omat Holding B.V. <info@omat.nl>
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.
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.
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.
24
#include <KStandardDirs>
30
#include <kio/netaccess.h>
32
#include <akonadi/private/xdgbasedirs_p.h>
35
using namespace Akonadi;
38
* Use this class to restore a backup. possible() will tell you if all
39
* apps needed for the restore are available. Don't proceed without them.
40
* After that call restore() to get it running. Please make sure the parameter
41
* has the tar.bz2 extension.
43
Restore::Restore( QWidget *parent ) : QWidget( parent )
47
bool Restore::possible()
49
const QString mysql = KStandardDirs::findExe( "mysql" );
50
const QString bzip2 = KStandardDirs::findExe( "bzip2" );
51
const QString tar = KStandardDirs::findExe( "tar" );
52
kDebug() << "mysql:" << mysql << "bzip2:" << bzip2 << "tar:" << tar;
53
return !mysql.isEmpty() && !bzip2.isEmpty() && !tar.isEmpty();
56
void Restore::restore( const KUrl& filename )
58
if ( filename.isEmpty() ) {
59
emit completed( false );
63
const QString sep = QDir::separator();
65
/* first create the temp folder. */
66
KTempDir *tempDir = new KTempDir( KStandardDirs::locateLocal( "tmp", "akonadi" ) );
67
tempDir->setAutoRemove( false );
68
kDebug() << "Temp dir: "<< tempDir->name();
70
/* Extract the nice tar file. */
71
KProcess *proc = new KProcess( this );
73
params << "-C" << tempDir->name();
75
params << filename.path();
76
proc->setWorkingDirectory( tempDir->name() );
77
proc->setProgram( KStandardDirs::findExe( "tar" ), params );
78
int result = proc->execute();
81
kWarning() << "Executed:" << KStandardDirs::findExe( "tar" ) << params << " Result: " << result;
84
emit completed( false );
88
/* Copy over the KDE configuration files. */
89
QDir dir( tempDir->name() + "kdeconfig" + sep );
90
dir.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
91
QFileInfoList list = dir.entryInfoList();
92
for ( int i = 0; i < list.size(); ++i ) {
93
QFileInfo fileInfo = list.at( i );
94
const QString source = fileInfo.absoluteFilePath();
95
const QString dest = KStandardDirs::locateLocal( "config", fileInfo.fileName() );
97
kDebug() << "Restoring: " << source << "to:" << dest;
98
KIO::NetAccess::file_copy( source, dest, this );
101
/* Copy over the Akonadi configuration files. */
102
const QString akonadiconfigfolder = XdgBaseDirs::findResourceDir( "config", "akonadi" );
103
dir.setPath( tempDir->name() + "akonadiconfig" + sep );
104
dir.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
105
list = dir.entryInfoList();
106
for ( int i = 0; i < list.size(); ++i ) {
107
QFileInfo fileInfo = list.at( i );
108
const QString source = fileInfo.absoluteFilePath();
109
const QString dest = akonadiconfigfolder + sep + fileInfo.fileName();
111
kDebug() << "Restoring: " << source << "to:" << dest;
112
KIO::NetAccess::file_copy( source, dest, this );
115
/* Restore the database */
117
proc = new KProcess( this );
119
params << global.dboptions() << global.dbname();
120
kDebug() << "Executing:" << KStandardDirs::findExe( "mysql" ) << params;
121
proc->setStandardInputFile( tempDir->name() + "db" + sep + "database.sql" );
122
proc->setProgram( KStandardDirs::findExe( "mysql" ), params );
123
result = proc->execute();
126
kWarning() << "Executed:" << KStandardDirs::findExe( "mysql" ) << params << " Result: " << result;
129
emit completed( false );
135
emit completed( true );
138
#include "restore.moc"