]> Git trees. - libqmvoc.git/commitdiff
added method to sort kns downloaded data into locale sub-folders
authorJeremy Paul Whiting <jpwhiting@kde.org>
Fri, 10 Aug 2007 13:33:40 +0000 (13:33 +0000)
committerJeremy Paul Whiting <jpwhiting@kde.org>
Fri, 10 Aug 2007 13:33:40 +0000 (13:33 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=698616

keduvocdocument/sharedkvtmlfiles.cpp
keduvocdocument/sharedkvtmlfiles.h

index b48c8f5baf9c0bc79526723bfebf2e00202a18ef..461eaa8d55370439e5cccc4c6145e9be9ef2bcee 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "keduvocdocument.h"
 
+#include <kio/copyjob.h>
+#include <kio/job.h>
 #include <klocale.h>
 #include <kstandarddirs.h>
 
@@ -103,6 +105,8 @@ void SharedKvtmlFilesPrivate::rescan()
         // add it's comment to the comment list
         this->m_commentList.append(doc->documentRemark());
     }
+       // plug a memory leak
+       delete doc;
 }
 
 void SharedKvtmlFiles::rescan()
@@ -165,3 +169,35 @@ QStringList SharedKvtmlFiles::comments(const QString &language)
 
        return retlist;
 }
+
+void SharedKvtmlFiles::sortDownloadedFiles()
+{
+       QStringList unsortedFiles = KGlobal::dirs()->findAllResources("data", 
+               QString("kvtml/*.kvtml"));
+       
+       KEduVocDocument *doc = new KEduVocDocument();
+
+       while (unsortedFiles.size() > 0)
+       {
+               KUrl fileUrl(KUrl::fromPath(unsortedFiles.first()));
+               // find the file's locale
+        // open the file
+        doc->open(fileUrl);
+
+               QString locale = doc->identifier(0);
+
+               // 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();
+       }
+       
+       rescan();
+}
index 2cc70ec626e3a02913858fd262534bd636e662fb..c9344b675caeae6178fd276ef1ee25a8ff639783 100644 (file)
@@ -51,6 +51,9 @@ namespace SharedKvtmlFiles
 
     /** rescan the shared kvtml locations */
     KEDUVOCDOCUMENT_EXPORT void rescan();
+       
+       /** sort files downloaded to kvtml top-level dir into locale sub-folders */
+       KEDUVOCDOCUMENT_EXPORT void sortDownloadedFiles();
 }
 
 #endif