From 2954dd3fe3ce4a698ff72e3623c31f849fc5d5dd Mon Sep 17 00:00:00 2001 From: Reto Zingg Date: Sat, 15 Dec 2012 19:28:49 +0200 Subject: [PATCH] adapt sharedkvtmlfiles.cpp for querymee --- sharedkvtmlfiles.cpp | 187 +++++++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 87 deletions(-) diff --git a/sharedkvtmlfiles.cpp b/sharedkvtmlfiles.cpp index a5f45a2..37f8218 100644 --- a/sharedkvtmlfiles.cpp +++ b/sharedkvtmlfiles.cpp @@ -1,7 +1,13 @@ +/*************************************************************************** +* this file is from kdeedu project. Filename: sharedkvtmlfiles.cpp +***************************************************************************/ + /*************************************************************************** scan a group of KVTML documents to get information from them ----------------------------------------------------------------------- copyright : (C) 2007 Jeremy Whiting + + Copyright 2010, 2012 Reto Zingg ***************************************************************************/ /*************************************************************************** @@ -15,18 +21,18 @@ #include "sharedkvtmlfiles.h" -#include "keduvocdocument.h" +#include "qmvocdocument.h" -#include -#include -#include -#include +// #include +// #include +// #include +// #include #include #include #include -#include +// #include class SharedKvtmlFilesPrivate { @@ -61,47 +67,51 @@ K_GLOBAL_STATIC( SharedKvtmlFilesPrivate, sharedKvtmlFilesPrivate ) void SharedKvtmlFilesPrivate::rescan() { - this->m_titleList.clear(); - this->m_commentList.clear(); - this->m_filesByLang.clear(); - this->m_fileList.clear(); - - QStringList locales; - - QStringList dataPaths = KGlobal::dirs()->findDirs( "data", "kvtml/" ); - for ( int i = 0; i < dataPaths.size(); ++i ) { - locales += QDir( dataPaths[i] ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ); - } - - // remove duplicates - locales = locales.toSet().toList(); - - for ( int i = 0; i < locales.size(); ++i ) { - // get all files for this language - QStringList thisLangFiles = KGlobal::dirs()->findAllResources( "data", - QString( "kvtml/%1/*.kvtml" ).arg( QDir( locales[i] ).dirName() ) ); - // add them to the big list - this->m_fileList << thisLangFiles; - - // then add them to their respective language maps - for ( int j = 0; j < thisLangFiles.size(); ++j ) { - this->m_filesByLang[locales[i]].append( thisLangFiles[j] ); - } - } - - KEduVocDocument *doc = new KEduVocDocument(); - for ( int i = 0; i < this->m_fileList.size(); ++i ) { - - // open the file - doc->open( KUrl::fromPath( this->m_fileList[i] ) ); - - // add it's title to the title list - this->m_titleList.append( doc->title() ); - - // add it's comment to the comment list - this->m_commentList.append( doc->documentComment() ); - } - delete doc; + qCritical("FIXME: no fuction rescan..."); +// this->m_titleList.clear(); +// this->m_commentList.clear(); +// this->m_filesByLang.clear(); +// this->m_fileList.clear(); +// +// QStringList locales; +// +// QStringList dataPaths = KGlobal::dirs()->findDirs( "data", "kvtml/" ); +// +// for ( int i = 0; i < dataPaths.size(); ++i ) { +// locales += QDir( dataPaths[i] ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ); +// } +// +// // remove duplicates +// locales = locales.toSet().toList(); +// +// for ( int i = 0; i < locales.size(); ++i ) { +// // get all files for this language +// QStringList thisLangFiles = KGlobal::dirs()->findAllResources( "data", +// QString( "kvtml/%1/*.kvtml" ).arg( QDir( locales[i] ).dirName() ) ); +// +// +// // add them to the big list +// this->m_fileList << thisLangFiles; +// +// // then add them to their respective language maps +// for ( int j = 0; j < thisLangFiles.size(); ++j ) { +// this->m_filesByLang[locales[i]].append( thisLangFiles[j] ); +// } +// } +// +// QmVocDocument *doc = new QmVocDocument(); +// for ( int i = 0; i < this->m_fileList.size(); ++i ) { +// +// // open the file +// doc->open( KUrl::Path( this->m_fileList[i] ) ); +// +// // add it's title to the title list +// this->m_titleList.append( doc->title() ); +// +// // add it's comment to the comment list +// this->m_commentList.append( doc->documentComment() ); +// } +// delete doc; } void SharedKvtmlFiles::rescan() @@ -155,45 +165,48 @@ QStringList SharedKvtmlFiles::comments( const QString &language ) void SharedKvtmlFiles::sortDownloadedFiles() { - QStringList unsortedFiles = KGlobal::dirs()->findAllResources( "data", - QString( "kvtml/*.kvtml" ) ); - - KEduVocDocument doc; - - while ( !unsortedFiles.isEmpty() ) { - KUrl fileUrl( KUrl::fromPath( unsortedFiles.first() ) ); - // find the file's locale - // open the file - doc.open( fileUrl ); - - if (doc.identifierCount() == 1) { - QString locale = doc.identifier( 0 ).locale(); - - // make sure the locale sub-folder exists - KUrl pathUrl( fileUrl ); - pathUrl.setFileName( QString() ); - pathUrl.addPath( locale ); - KIO::mkdir( pathUrl ); - - // move the file into the locale sub-folder - KIO::move( fileUrl, pathUrl ); - } - - // take off the one we just did - unsortedFiles.removeFirst(); - } - QStringList khangmanFiles = KGlobal::dirs()->findAllResources( "data", - QString( "kvtml/*.txt" ) ); - - // move khangman files into - while ( !khangmanFiles.isEmpty() ) { - KUrl fileUrl( KUrl::fromPath( khangmanFiles.first() ) ); - KUrl destDir = KUrl::fromPath(KStandardDirs::locateLocal("appdata", "khangman/data/")); - // do this better with KStandardDirs stuff - KIO::move( fileUrl, destDir); - khangmanFiles.removeFirst(); - } - - rescan(); + qCritical("FIXME: not methode sortDownloadedFiles"); +// QStringList unsortedFiles = KGlobal::dirs()->findAllResources( "data", +// QString( "kvtml/*.kvtml" ) ); +// +// +// QmVocDocument doc; +// +// while ( !unsortedFiles.isEmpty() ) { +// KUrl fileUrl( KUrl::fromPath( unsortedFiles.first() ) ); +// // find the file's locale +// // open the file +// doc.open( fileUrl ); +// +// if (doc.identifierCount() == 1) { +// QString locale = doc.identifier( 0 ).locale(); +// +// // make sure the locale sub-folder exists +// KUrl pathUrl( fileUrl ); +// pathUrl.setFileName( QString() ); +// pathUrl.addPath( locale ); +// KIO::mkdir( pathUrl ); +// +// // move the file into the locale sub-folder +// KIO::move( fileUrl, pathUrl ); +// } +// +// // take off the one we just did +// unsortedFiles.removeFirst(); +// } +// +// QStringList khangmanFiles = KGlobal::dirs()->findAllResources( "data", +// QString( "kvtml/*.txt" ) ); +// +// // move khangman files into +// while ( !khangmanFiles.isEmpty() ) { +// KUrl fileUrl( KUrl::fromPath( khangmanFiles.first() ) ); +// KUrl destDir = KUrl::fromPath(KStandardDirs::locateLocal("appdata", "khangman/data/")); +// // do this better with KStandardDirs stuff +// KIO::move( fileUrl, destDir); +// khangmanFiles.removeFirst(); +// } +// +// rescan(); } -- 2.47.3