• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • services
  • storage
  • backup
backuprestorationjob.cpp
Go to the documentation of this file.
1 /*
2  <one line to give the library's name and an idea of what it does.>
3  Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 
21 #include "backuprestorationjob.h"
22 #include "backupfile.h"
23 #include "storage.h"
24 #include "nie.h"
25 #include <KDebug>
26 
27 #include <QtCore/QTimer>
28 #include <QtCore/QDir>
29 
30 using namespace Nepomuk2::Vocabulary;
31 
32 namespace Nepomuk2 {
33 
34 BackupRestorationJob::BackupRestorationJob(Storage* storageService, const QUrl& url, QObject* parent)
35  : KJob(parent)
36  , m_model( storageService->model() )
37  , m_storageService( storageService )
38  , m_url( url )
39 {
40 }
41 
42 void BackupRestorationJob::start()
43 {
44  QTimer::singleShot( 0, this, SLOT(doWork()) );
45 }
46 
47 void BackupRestorationJob::doWork()
48 {
49  kDebug() << "RESTORING!!!";
50  connect( m_storageService, SIGNAL(resetRepositoryDone(QString, QString)), this, SLOT(slotRestRepo(QString, QString)) );
51  QTimer::singleShot(0, m_storageService, SLOT(resetRepository()) );
52 
53  // Gives the users a sense that something is happening
54  emitPercent( 3, 100 );
55 }
56 
57 namespace {
58 
59  //
60  // Removes the old home directory and replaces it with the current one
61  // TODO: Make it OS independent
62  //
63  QUrl translateHomeUri( const QUrl & uri ) {
64  QString uriString = uri.toString();
65 
66  QRegExp regEx("^file://(/home/[^/]*)(/.*)$");
67  if( regEx.exactMatch( uriString ) ) {
68  QString newUriString = "file://" + QDir::homePath() + regEx.cap(2);
69 
70  uriString.replace( regEx, newUriString );
71  return QUrl( newUriString );
72  }
73  return uri;
74  }
75 }
76 
77 void BackupRestorationJob::slotRestRepo(const QString&, const QString& newPath)
78 {
79  m_oldRepoPath = newPath;
80 
81  BackupFile bf = BackupFile::fromUrl( m_url );
82  Soprano::StatementIterator it = bf.iterator();
83 
84  kDebug() << "Restore Statements:" << bf.numStatements();
85  int numStatements = 0;
86  while( it.next() ) {
87  Soprano::Statement st = it.current();
88  if( st.predicate() == NIE::url() ) {
89  QUrl url = st.object().uri();
90  if( url.scheme() == QLatin1String("file") ) {
91  //
92  // Check if the file exists
93  //
94  if( !QFile::exists( url.toLocalFile() ) ) {
95  url = translateHomeUri( url );
96 
97  // REMOVING THIS CHANGE TO nepomuk-backup because one can have removablemedia
98  // files which are currently not mounted. This change sucks but the restore
99  // utility will have to manually check each file
100  // if( !QFile::exists( url.toLocalFile() ) ) {
101  // url.setScheme("nepomuk-backup");
102  // }
103  if( QFile::exists( url.toLocalFile() ) )
104  st.setObject( url );
105  }
106  }
107  }
108 
109  Soprano::Error::ErrorCode err = m_model->addStatement( st );
110  if( err ) {
111  kWarning() << m_model->lastError();
112  setErrorText( m_model->lastError().message() );
113  emitResult();
114  return;
115  }
116 
117  numStatements++;
118  emitPercent( numStatements, bf.numStatements() );
119  }
120 
121  QTimer::singleShot(0, m_storageService, SLOT(openPublicInterfaces()) );
122  emitResult();
123 }
124 
125 
126 }
Nepomuk2::ErrorCode
ErrorCode
Definition: resource.h:44
backupfile.h
Nepomuk2::BackupRestorationJob::BackupRestorationJob
BackupRestorationJob(Nepomuk2::Storage *storageService, const QUrl &url, QObject *parent=0)
Definition: backuprestorationjob.cpp:34
Nepomuk2::Storage
Definition: storage.h:35
QObject
Nepomuk2::BackupRestorationJob::start
virtual void start()
Definition: backuprestorationjob.cpp:42
backuprestorationjob.h
storage.h
Nepomuk2::BackupFile::fromUrl
static BackupFile fromUrl(const QUrl &url)
Definition: backupfile.cpp:49
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal