From: Reto Zingg Date: Sat, 13 Mar 2010 15:10:17 +0000 (+0200) Subject: sharedkvtmlfiles files deKDEfied X-Git-Tag: version-0.0.1~1 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=afcbc811c049ad1b8161ab6b20c047cd40fcf126;p=qtvoc.git sharedkvtmlfiles files deKDEfied --- diff --git a/lib/sharedkvtmlfiles.cpp b/lib/sharedkvtmlfiles.cpp index a5f45a2..62bdff1 100644 --- a/lib/sharedkvtmlfiles.cpp +++ b/lib/sharedkvtmlfiles.cpp @@ -17,16 +17,16 @@ #include "keduvocdocument.h" -#include -#include -#include -#include +// #include +// #include +// #include +// #include #include #include #include -#include +// #include class SharedKvtmlFilesPrivate { @@ -61,47 +61,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] ); +// } +// } +// +// KEduVocDocument *doc = new KEduVocDocument(); +// 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 +159,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" ) ); +// +// +// 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(); } diff --git a/lib/sharedkvtmlfiles.h b/lib/sharedkvtmlfiles.h index 402eff8..26198a4 100644 --- a/lib/sharedkvtmlfiles.h +++ b/lib/sharedkvtmlfiles.h @@ -20,6 +20,69 @@ #include +typedef void (*KdeCleanUpFunction)(); + +class KCleanUpGlobalStatic +{ + public: + KdeCleanUpFunction func; + + inline ~KCleanUpGlobalStatic() { func(); } +}; + + +#ifdef Q_CC_MSVC +# define K_GLOBAL_STATIC_STRUCT_NAME(NAME) _k_##NAME##__LINE__ +#else +# define K_GLOBAL_STATIC_STRUCT_NAME(NAME) +#endif + +#define K_GLOBAL_STATIC(TYPE, NAME) K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ()) + +#define K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ +static QBasicAtomicPointer _k_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0); \ +static bool _k_static_##NAME##_destroyed; \ +static struct K_GLOBAL_STATIC_STRUCT_NAME(NAME) \ +{ \ + bool isDestroyed() \ + { \ + return _k_static_##NAME##_destroyed; \ + } \ + inline operator TYPE*() \ + { \ + return operator->(); \ + } \ + inline TYPE *operator->() \ + { \ + if (!_k_static_##NAME) { \ + if (isDestroyed()) { \ + qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \ + "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \ + } \ + TYPE *x = new TYPE ARGS; \ + if (!_k_static_##NAME.testAndSetOrdered(0, x) \ + && _k_static_##NAME != x ) { \ + delete x; \ + } else { \ + static KCleanUpGlobalStatic cleanUpObject = { destroy }; \ + } \ + } \ + return _k_static_##NAME; \ + } \ + inline TYPE &operator*() \ + { \ + return *operator->(); \ + } \ + static void destroy() \ + { \ + _k_static_##NAME##_destroyed = true; \ + TYPE *x = _k_static_##NAME; \ + _k_static_##NAME = 0; \ + delete x; \ + } \ +} NAME; + + /** *namespace and singleton class to scan groups of kvtml files *from shared kvtml location, and give information