set(kdeeducore_LIB_SRCS
keduvoccsvreader.cpp
+ keduvoccsvwriter.cpp
keduvocdocument.cpp
keduvocexpression.cpp
keduvocgrammar.cpp
install(FILES
libkdeedu_core_export.h
keduvoccsvreader.h
+ keduvoccsvwriter.h
keduvocdocument.h
keduvocexpression.h
keduvocgrammar.h
--- /dev/null
+/***************************************************************************
+ export a KEduVocDocument to a delimited text file
+ -----------------------------------------------------------------------
+ copyright : (C) 1999-2001 Ewald Arnold
+ (C) 2001 The KDE-EDU team
+ (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. *
+ * *
+ ***************************************************************************/
+
+#include <QTextStream>
+
+#include <KLocale>
+
+#include "keduvoccsvwriter.h"
+#include "keduvocdocument.h"
+#include "keduvocexpression.h"
+
+KEduVocCsvWriter::KEduVocCsvWriter(QFile *file)
+{
+ // the file must be already open
+ m_outputFile = file;
+}
+
+
+bool KEduVocCsvWriter::writeDoc(KEduVocDocument *doc, const QString &generator)
+{
+ Q_UNUSED(generator);
+
+ m_doc = doc;
+
+ QString separator = ",";
+
+ QTextStream outputStream;
+ outputStream.setDevice(m_outputFile);
+ outputStream.setCodec("UTF-8");
+
+ outputStream << i18n("! Title:") << separator << m_doc->title() << "\n";
+ outputStream << i18n("! Author:") << separator << m_doc->author() << "\n";
+
+ KEduVocExpression *expression;
+ int idCount = m_doc->identifierCount();
+ QString currentRow;
+
+ for (int e = 0; e < m_doc->entryCount(); e++)
+ {
+ expression = m_doc->entry(e);
+ currentRow = "";
+ bool sep = false;
+
+ for (int i = 0; i < idCount; i++) {
+ if (!sep)
+ sep = true;
+ else
+ currentRow += separator;
+
+ if (i == 0)
+ currentRow += expression->original();
+ else
+ currentRow += expression->translation(i);
+ }
+
+ if (!currentRow.isEmpty())
+ outputStream << currentRow << "\n";
+ }
+
+ return true;
+}
+
--- /dev/null
+/***************************************************************************
+ export a KEduVocDocument to a delimited text file
+ -----------------------------------------------------------------------
+ copyright : (C) 1999-2001 Ewald Arnold
+ (C) 2001 The KDE-EDU team
+ (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 KEDUVOCCSVWRITER_H
+#define KEDUVOCCSVWRITER_H
+
+#include <libkdeedu_core_export.h>
+
+#include <QFile>
+
+class KEduVocDocument;
+
+class KDEEDUCORE_EXPORT KEduVocCsvWriter
+{
+public:
+ KEduVocCsvWriter(QFile *file);
+
+ bool writeDoc(KEduVocDocument *doc, const QString &generator);
+
+private:
+ QFile *m_outputFile;
+ KEduVocDocument *m_doc;
+};
+
+#endif
#include "keduvockvtmlwriter.h"
#include "keduvoccsvreader.h"
+#include "keduvoccsvwriter.h"
#include "keduvockvtmlreader.h"
#include "keduvocwqlreader.h"
#include "keduvocpaukerreader.h"
bool KEduVocDocument::saveAs(QObject *parent, const KUrl & url, FileType ft, const QString & generator)
{
- connect( this, SIGNAL(progressChanged(KEduVocDocument*,int)), parent, SLOT(slotProgress(KEduVocDocument*,int)) );
+ connect(this, SIGNAL(progressChanged(KEduVocDocument*, int)), parent, SLOT(slotProgress(KEduVocDocument*, int)));
KUrl tmp (url);
}
bool saved = false;
+
while (!saved)
{
-
QFile f(tmp.path());
if (!f.open(QIODevice::WriteOnly))
break;
case csv: {
- QTextStream os( &f ); // serialize using f
- //TODO saved = saveToCsv(os, title);
+ KEduVocCsvWriter csvWriter(&f);
+ saved = csvWriter.writeDoc(this, generator);
}
break;
QApplication::restoreOverrideCursor();
if (!saved) {
- // TODO new writers provide an explicite error message
- // the two messages should be merged
QString msg = i18n("Could not save \"%1\"\nDo you want to try again?", tmp.path());
int result = KMessageBox::warningContinueCancel(0, msg, i18n("Error Saving File"), KGuiItem(i18n("&Retry")));
if (result == KMessageBox::Cancel)