--- /dev/null
+/***************************************************************************
+ scan a group of KVTML documents to get information from them
+ -----------------------------------------------------------------------
+ copyright : (C) 2007 Jeremy Whiting <jeremy@scitools.com>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "sharedkvtmlfiles.h"
+
+#include "keduvocdocument.h"
+
+#include <klocale.h>
+#include <kstandarddirs.h>
+
+#include <QList>
+
+#include <kglobal.h>
+
+class SharedKvtmlFilesPrivate
+{
+ public:
+ /** default constructor calls rescan*/
+ SharedKvtmlFilesPrivate()
+ {
+ rescan();
+ }
+
+ /** default destructor */
+ ~SharedKvtmlFilesPrivate()
+ {
+ }
+
+ SharedKvtmlFiles instance;
+
+ /** scan the folder for documents, and record what is found */
+ void rescan();
+
+ /** list of all files found */
+ QStringList m_fileList;
+
+ /** list of all files titles found */
+ QStringList m_titleList;
+
+ /** list of file comments */
+ QStringList m_commentList;
+
+ /** map of files by language key */
+ QMap<QString, QStringList> m_filesByLang;
+};
+
+K_GLOBAL_STATIC(SharedKvtmlFilesPrivate, sharedKvtmlFilesPrivate)
+
+SharedKvtmlFiles *SharedKvtmlFiles::self()
+{
+ // returns the singleton; automatically creates a new instance if that has not happened yet.
+ return &sharedKvtmlFilesPrivate->instance;
+}
+
+SharedKvtmlFiles::SharedKvtmlFiles()
+{
+}
+
+SharedKvtmlFiles::~SharedKvtmlFiles()
+{
+}
+
+void SharedKvtmlFilesPrivate::rescan()
+{
+ this->m_titleList.clear();
+ this->m_commentList.clear();
+ this->m_filesByLang.clear();
+ this->m_fileList = KGlobal::dirs()->findAllResources("data", "kvtml/*.kvtml");
+
+ 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->documentRemark());
+
+ // then add it under its main language in the map
+ QString language = doc->originalIdentifier();
+ if (language.isEmpty())
+ {
+ language = I18N_NOOP("none");
+ }
+ if (this->m_filesByLang.contains(language))
+ {
+ this->m_filesByLang[language].append(this->m_fileList[i]);
+ }
+ else
+ {
+ QStringList list;
+ list.append(this->m_fileList[i]);
+ this->m_filesByLang.insert(language, list);
+ }
+ }
+}
+
+void SharedKvtmlFiles::rescan()
+{
+ sharedKvtmlFilesPrivate->rescan();
+}
+
+QStringList SharedKvtmlFiles::languages()
+{
+ return sharedKvtmlFilesPrivate->m_filesByLang.keys();
+}
+
+QStringList SharedKvtmlFiles::fileNames(const QString &language)
+{
+ // return files by language for given language if it's not empty
+ // otherwise return all filenames
+ return language.isEmpty() ? sharedKvtmlFilesPrivate->m_fileList : sharedKvtmlFilesPrivate->m_filesByLang.value(language);
+}
+
+/** get the list of document titles found of a given language
+ *@param language requested language
+ *@return a list of document titles with words in language
+ */
+QStringList SharedKvtmlFiles::titles(const QString &language)
+{
+ QStringList retlist;
+
+ if (language.isEmpty())
+ {
+ retlist = sharedKvtmlFilesPrivate->m_titleList;
+ }
+ else
+ {
+ QStringList filenames = sharedKvtmlFilesPrivate->m_filesByLang.value(language);
+ for (int i = 0; i < filenames.size(); ++i)
+ {
+ retlist.append(sharedKvtmlFilesPrivate->m_titleList[sharedKvtmlFilesPrivate->m_fileList.indexOf(filenames[i])]);
+ }
+ }
+
+ return retlist;
+}
+
+QStringList SharedKvtmlFiles::comments(const QString &language)
+{
+ QStringList retlist;
+
+ if (language.isEmpty())
+ {
+ retlist = sharedKvtmlFilesPrivate->m_commentList;
+ }
+ else
+ {
+ QStringList filenames = sharedKvtmlFilesPrivate->m_filesByLang.value(language);
+ for (int i = 0; i < filenames.size(); ++i)
+ {
+ retlist.append(sharedKvtmlFilesPrivate->m_commentList[sharedKvtmlFilesPrivate->m_fileList.indexOf(filenames[i])]);
+ }
+ }
+
+ return retlist;
+}
--- /dev/null
+/***************************************************************************
+ scan a group of KVTML documents to get information from them
+ -----------------------------------------------------------------------
+ copyright : (C) 2007 Jeremy Whiting <jeremy@scitools.com>
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef SHAREDKVTMLFILES_H
+#define SHAREDKVTMLFILES_H
+
+#include "libkdeedu_core_export.h"
+
+#include <QtXml/QDomDocument>
+#include <QMap>
+#include <QStringList>
+
+#include <kglobal.h>
+
+#include "kvtmldefs.h"
+
+class QIODevice;
+class SharedKvtmlFilesPrivate;
+
+/**
+ *namespace and singleton class to scan groups of kvtml files
+ *from shared kvtml location, and give information
+ *about files found there
+ *@author Jeremy Whiting
+ */
+class KDEEDUCORE_EXPORT SharedKvtmlFiles
+{
+ friend class SharedKvtmlFilesPrivate;
+ public:
+ /** singleton accessor */
+ static SharedKvtmlFiles *self();
+
+ /** get list of all languages found in any files */
+ QStringList languages();
+
+ /** get list of filenames found of given language
+ *@param language language requested QString() for all languages
+ *@return a list of filenames with words in language
+ */
+ QStringList fileNames(const QString &language = QString());
+
+ /** get the list of document titles found of a given language
+ *@param language requested language QString() for all titles
+ *@return a list of document titles with words in language
+ */
+ QStringList titles(const QString &language = QString());
+
+ /** get the list of document remarts found of a given language
+ *@param language requested language QString() for all comments
+ *@return a list of document remarks with words in language
+ */
+ QStringList comments(const QString &language = QString());
+
+ /** rescan the shared kvtml locations */
+ void rescan();
+
+ private:
+ /** default contstuctor */
+ SharedKvtmlFiles();
+
+ /** default destructor */
+ ~SharedKvtmlFiles();
+};
+
+#endif
+