29 #include <Soprano/PluginManager>
30 #include <Soprano/Serializer>
31 #include <Soprano/Util/SimpleStatementIterator>
33 #include <QtCore/QTimer>
34 #include <QtCore/QSettings>
37 #include <KTemporaryFile>
45 , m_filter( Filter_None )
51 QTimer::singleShot( 0,
this, SLOT(doWork()) );
60 void Nepomuk2::BackupGenerationJob::doWork()
62 KTemporaryFile uriListFile;
63 uriListFile.setAutoRemove(
false );
67 uriListGen->setProperty(
"filename", uriListFile.fileName() );
68 if( m_filter == Filter_TagsAndRatings )
71 connect( uriListGen, SIGNAL(finished(
KJob*)),
this, SLOT(slotResourceListFinished(
KJob*)) );
72 connect( uriListGen, SIGNAL(percent(
KJob*,ulong)),
this, SLOT(slotResourceListProgress(
KJob*,ulong)) );
77 void Nepomuk2::BackupGenerationJob::slotResourceListProgress(
KJob*, ulong progress)
80 float amt = progress * 0.20;
85 void Nepomuk2::BackupGenerationJob::slotResourceListFinished(
KJob* job)
87 Backup::ResourceListGenerator* uriListGen =
static_cast<Backup::ResourceListGenerator*
>(job);
89 if( uriListGen->error() ) {
91 setErrorText( uriListGen->errorString() );
96 const QString uriListFile = uriListGen->property(
"filename" ).toString();
98 KTemporaryFile stListFile;
99 stListFile.setAutoRemove(
false );
102 Backup::StatementGenerator* stGen =
new Backup::StatementGenerator( m_model, uriListFile,
103 stListFile.fileName(), this );
104 stGen->setProperty(
"filename", stListFile.fileName() );
105 stGen->setResourceCount( uriListGen->resourceCount() );
106 if( m_filter == Filter_TagsAndRatings )
109 connect( stGen, SIGNAL(finished(
KJob*)),
this, SLOT(slotStatementListGenerationFinished(
KJob*)) );
110 connect( stGen, SIGNAL(percent(
KJob*,ulong)),
this, SLOT(slotStatementListGeneratorProgress(
KJob*,ulong)) );
114 void Nepomuk2::BackupGenerationJob::slotStatementListGeneratorProgress(
KJob*, ulong progress)
117 float amt = 20 + (progress*0.40);
118 kDebug() <<
"FF" << amt;
122 void Nepomuk2::BackupGenerationJob::slotStatementListGenerationFinished(
KJob* job)
124 Backup::StatementGenerator* stGen =
static_cast<Backup::StatementGenerator*
>(job);
125 if( stGen->error() ) {
127 setErrorText( stGen->errorString() );
132 KTemporaryFile dataFile;
133 dataFile.setAutoRemove(
false );
136 const QString stListFile = stGen->property(
"filename" ).toString();
137 Backup::GraphGenerator* graphGen =
new Backup::GraphGenerator( m_model, stListFile,
138 dataFile.fileName(), this );
140 connect( graphGen, SIGNAL(finished(
KJob*)),
this, SLOT(slotGraphGenerationFinished(
KJob*)) );
141 connect( graphGen, SIGNAL(percent(
KJob*,ulong)),
this, SLOT(slotGraphGeneratorProgress(
KJob*,ulong)) );
143 graphGen->setInputCount( stGen->statementCount() );
144 graphGen->setProperty(
"filename", dataFile.fileName() );
148 void Nepomuk2::BackupGenerationJob::slotGraphGeneratorProgress(
KJob*, ulong progress)
150 float amt = 60 + (progress*0.40);
155 void Nepomuk2::BackupGenerationJob::slotGraphGenerationFinished(
KJob* job)
157 Backup::GraphGenerator* graphGen =
static_cast<Backup::GraphGenerator*
>(job);
158 if( graphGen->error() ) {
160 setErrorText( graphGen->errorString() );
165 const QString dataFile = graphGen->property(
"filename").toString();
168 KTemporaryFile tmpFile;
170 tmpFile.setAutoRemove(
false );
171 QString metdataFile = tmpFile.fileName();
174 QSettings iniFile( metdataFile, QSettings::IniFormat );
175 iniFile.setValue(
"NumStatements", graphGen->numStatements());
176 iniFile.setValue(
"Created", QDateTime::currentDateTime().toString() );
180 KTar tarFile( m_url.toLocalFile(), QString::fromLatin1(
"application/x-gzip") );
181 if( !tarFile.open( QIODevice::WriteOnly ) ) {
182 kWarning() <<
"File could not be opened : " << m_url.toLocalFile();
186 tarFile.addLocalFile( dataFile,
"data" );
187 tarFile.addLocalFile( metdataFile,
"metadata" );
BackupGenerationJob(Soprano::Model *model, const QUrl &url, QObject *parent=0)
This class generates a list of resource URIs that should be backed up.
void setFilter(Filter filter)
void setFilter(Filter filter)