########### next target ###############
set(kdeeducore_LIB_SRCS
+ keduvoccsvreader.cpp
keduvocdocument.cpp
keduvocexpression.cpp
keduvocgrammar.cpp
install(FILES
libkdeedu_core_export.h
+ keduvoccsvreader.h
keduvocdocument.h
keduvocexpression.h
keduvocgrammar.h
--- /dev/null
+/***************************************************************************
+
+ create a KEduVocDocument from a text file
+
+ -----------------------------------------------------------------------
+
+ begin : Sat Sep 06 11:00:53 MET 1999
+
+ copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
+ (C) 2001 The KDE-EDU team
+ (C) 2005, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
+
+ -----------------------------------------------------------------------
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 <QTextStream>
+
+#include <klocale.h>
+
+#include "keduvocdocument.h"
+#include "keduvoccsvreader.h"
+
+KEduVocCsvReader::KEduVocCsvReader(QIODevice *file)
+{
+ // the file must be already open
+ m_inputFile = file;
+ m_errorMessage = "";
+}
+
+
+bool KEduVocCsvReader::readDoc(KEduVocDocument *doc)
+{
+ m_doc = doc;
+
+ QString separator = QString(",");
+
+ QTextStream inputStream(m_inputFile);
+ inputStream.setCodec("UTF-8");
+ inputStream.setAutoDetectUnicode(true);
+ inputStream.seek(0);
+
+ int languageCount = 0;
+
+ while (!inputStream.atEnd()) {
+ QString s = inputStream.readLine();
+
+ if (!s.simplified().isEmpty()) {
+ KEduVocExpression expression(s, separator);
+ languageCount = qMax(languageCount, expression.numTranslations() + 1);
+ m_doc->appendEntry(&expression);
+ }
+ }
+
+ for (int j = 0; j < languageCount; j++)
+ if (j == 0)
+ m_doc->appendIdentifier(i18n("Original"));
+ else
+ m_doc->appendIdentifier(i18n("Translation %1", j));
+
+ return true;
+}
--- /dev/null
+/***************************************************************************
+ create a KEduVocDocument from a text file
+ -----------------------------------------------------------------------
+ copyright : (C) 2007 Peter Hedlund <peter.hedlund@kdemail.net>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 KEDUVOCCSVREADER_H
+#define KEDUVOCCSVREADER_H
+
+#include <libkdeedu_core_export.h>
+
+#include <QIODevice>
+
+class KEduVocDocument;
+
+class KDEEDUCORE_EXPORT KEduVocCsvReader : public QObject
+{
+public:
+ KEduVocCsvReader(QIODevice *file);
+
+ bool readDoc(KEduVocDocument *doc);
+
+ QString errorMessage() const {return m_errorMessage;};
+
+private:
+ QIODevice *m_inputFile;
+ KEduVocDocument *m_doc;
+ QString m_errorMessage;
+};
+
+#endif
#include <kfilterdev.h>
#include "keduvockvtmlwriter.h"
+#include "keduvoccsvreader.h"
#include "keduvockvtmlreader.h"
#include "keduvocwqlwriter.h"
#include "keduvocwqlreader.h"
KEduVocDocument::FileType KEduVocDocument::detectFileType(const QString &fileName)
{
QIODevice * f = KFilterDev::deviceForFile(fileName);
- //QFile f(fileName);
if (!f->open(QIODevice::ReadOnly))
return csv;
QString temporaryFile;
if (KIO::NetAccess::download(url, temporaryFile, 0))
{
- ///@todo We need to work with the QIODevice directly for the compressed Pauker files
QIODevice * f = KFilterDev::deviceForFile(temporaryFile);
- //QFile f(temporaryFile);
+
if (!f->open(QIODevice::ReadOnly))
{
KMessageBox::error(0, errorMessage);
case csv:
{
- //QTextStream is(&f);
- //TODO read = loadFromCsv(is);
+ KEduVocCsvReader csvReader(f);
+ read = csvReader.readDoc(this);
+ if (!read)
+ errorMessage = csvReader.errorMessage();
}
break;
return false;
}
+ m_doc->setAuthor("http://pauker.sf.net");
///Pauker does not provide any column titles
m_doc->appendIdentifier(i18n("Front Side"));
m_doc->appendIdentifier(i18n("Reverse Side"));