[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [parley/collection-class] src/collection: First draft of the new collection class.
From: Inge Wallin <inge () lysator ! liu ! se>
Date: 2014-11-01 1:28:13
Message-ID: E1XkNUD-0004WS-NE () scm ! kde ! org
[Download RAW message or body]
Git commit 8fd221841589cc590eb30b94486cdb9621edec7a by Inge Wallin.
Committed on 01/11/2014 at 00:12.
Pushed by ingwa into branch 'collection-class'.
First draft of the new collection class.
A +204 -0 src/collection/collection.cpp [License: Public Domain GPL (v2+)]
A +67 -0 src/collection/collection.h [License: GPL (v2+)]
http://commits.kde.org/parley/8fd221841589cc590eb30b94486cdb9621edec7a
diff --git a/src/collection/collection.cpp b/src/collection/collection.cpp
new file mode 100644
index 0000000..2f44837
--- /dev/null
+++ b/src/collection/collection.cpp
@@ -0,0 +1,204 @@
+/***************************************************************************
+
+ Copyright 2007-2008 Frederik Gladhorn <frederik.gladhorn@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 "collection.h"
+
+#include <QTimer>
+#include <QtGui/QPrinter>
+#include <QtGui/QPrintDialog>
+
+// KDE
+#include <KFileDialog>
+#include <KRecentFilesAction>
+#include <KStandardDirs>
+#include <knewstuff3/downloaddialog.h>
+#include <knewstuff3/uploaddialog.h>
+#include <KEMailSettings>
+#include <KMessageBox>
+#include <KProcess>
+#include <KTempDir>
+
+// KEduVocDocument library
+#include <keduvoclesson.h>
+#include <keduvocleitnerbox.h>
+#include <keduvocexpression.h>
+#include <keduvocwordtype.h>
+
+#ifdef HAVE_LIBXSLT
+#include "exportdialog.h"
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxslt/xslt.h>
+#include <libxslt/xsltInternals.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+#endif
+
+// Parley
+#include "../config-parley.h"
+#include "parleymainwindow.h"
+#include "editor/editor.h"
+#include "version.h"
+#include "prefs.h"
+
+#include "vocabularyview.h"
+#include "settings/documentproperties.h"
+#include "dashboard/dashboard.h"
+
+#include "settings/languageproperties.h"
+#include "settings/documentproperties.h"
+
+
+void fetchGrammar(KEduVocDocument* doc, int languageIndex)
+{
+ QString locale = doc->identifier(languageIndex).locale();
+
+ KUrl location(QString("http://edu.kde.org/parley/locale/") + locale + QString(".kvtml"));
+
+ KEduVocDocument grammarDoc;
+ if (grammarDoc.open(location) == KEduVocDocument::NoError) {
+ doc->identifier(languageIndex).setArticle(grammarDoc.identifier(0).article());
+ doc->identifier(languageIndex).setPersonalPronouns(grammarDoc.identifier(0).personalPronouns());
+ // @todo m_doc->identifier(index).setDeclension(grammarDoc.identifier(0).declension());
+ doc->identifier(languageIndex).setTenseList(grammarDoc.identifier(0).tenseList());
+ } else {
+ kDebug() << "Download of " << location.url() << " failed.";
+ }
+}
+
+Collection::Collection()
+ : m_backupTimer(0)
+ , m_doc(new KEduVocDocument(this))
+{
+}
+
+Collection::~Collection()
+{
+ close();
+
+ delete m_backupTimer;
+
+ m_doc->deleteLater();
+ emit documentChanged(0);
+}
+
+
+KEduVocDocument *Collection::eduVocDocument()
+{
+ // If there is no present vocabulary document, create an empty one.
+ if (!m_doc) {
+ m_doc = new KEduVocDocument();
+ }
+
+ return m_doc;
+}
+
+void Collection::setTitle(const QString& title)
+{
+ m_doc->setTitle(title);
+}
+
+
+
+void Collection::close()
+{
+ enableAutoBackup(false);
+ if (m_doc) {
+ emit documentChanged(0);
+ m_doc->deleteLater();
+ m_doc = 0;
+ }
+}
+
+
+void Collection::setDefaultDocumentProperties(KEduVocDocument *doc)
+{
+ KEMailSettings emailSettings;
+ emailSettings.setProfile(emailSettings.defaultProfileName());
+ doc->setAuthor(emailSettings.getSetting(KEMailSettings::RealName));
+ doc->setAuthorContact(emailSettings.getSetting(KEMailSettings::EmailAddress));
+
+ doc->setLicense(i18n("Public Domain"));
+ doc->setCategory(i18n("Languages"));
+
+ QString locale = KGlobal::locale()->language();
+
+ doc->appendIdentifier();
+ doc->appendIdentifier();
+ doc->identifier(0).setName(KGlobal::locale()->languageCodeToName(locale));
+ doc->identifier(0).setLocale(locale);
+ doc->identifier(1).setName(i18n("A Second Language"));
+ doc->identifier(1).setLocale(locale);
+
+ KEduVocLesson* lesson = new KEduVocLesson(i18n("Lesson 1"), doc->lesson());
+ doc->lesson()->appendChildContainer(lesson);
+
+ // add some entries
+ for (int i = 0; i < 15 ; i++) {
+ lesson->appendEntry(new KEduVocExpression());
+ }
+
+ doc->setModified(false);
+}
+
+void Collection::initializeDefaultGrammar(KEduVocDocument *doc)
+{
+ KEduVocWordType *root = doc->wordTypeContainer();
+ KEduVocWordType *noun = new KEduVocWordType(i18n("Noun"), root);
+ noun->setWordType(KEduVocWordFlag::Noun);
+ root->appendChildContainer(noun);
+
+ KEduVocWordType *nounChild = new KEduVocWordType(i18n("Masculine"), noun);
+ nounChild->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine);
+ noun->appendChildContainer(nounChild);
+ nounChild = new KEduVocWordType(i18n("Feminine"), noun);
+ nounChild->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine);
+ noun->appendChildContainer(nounChild);
+ nounChild = new KEduVocWordType(i18n("Neuter"), noun);
+ nounChild->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Neuter);
+ noun->appendChildContainer(nounChild);
+
+ KEduVocWordType *verb = new KEduVocWordType(i18n("Verb"), root);
+ verb->setWordType(KEduVocWordFlag::Verb);
+ root->appendChildContainer(verb);
+
+ KEduVocWordType *adjective = new KEduVocWordType(i18n("Adjective"), root);
+ adjective->setWordType(KEduVocWordFlag::Adjective);
+ root->appendChildContainer(adjective);
+
+ KEduVocWordType *adverb = new KEduVocWordType(i18n("Adverb"), root);
+ adverb->setWordType(KEduVocWordFlag::Adverb);
+ root->appendChildContainer(adverb);
+
+ KEduVocWordType *conjunction = new KEduVocWordType(i18n("Conjunction"), root);
+ conjunction->setWordType(KEduVocWordFlag::Conjunction);
+ root->appendChildContainer(conjunction);
+}
+
+
+void Collection::enableAutoBackup(bool enable)
+{
+ if (!enable) {
+ if (m_backupTimer) {
+ m_backupTimer->stop();
+ }
+ } else {
+ if (!m_backupTimer) {
+ m_backupTimer = new QTimer(this);
+ connect(m_backupTimer, SIGNAL(timeout()), this, SLOT(save()));
+ }
+ m_backupTimer->start(Prefs::backupTime() * 60 * 1000);
+ }
+}
diff --git a/src/collection/collection.h b/src/collection/collection.h
new file mode 100644
index 0000000..5be328a
--- /dev/null
+++ b/src/collection/collection.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+
+ Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
+ Copyright 2014 Inge Wallin <inge@lysator.liu.se>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 COLLECTION_H
+#define COLLECTION_H
+
+#include <keduvocdocument.h>
+#include <QObject>
+
+#include "../config-parley.h"
+
+class ParleyMainWindow;
+class QTimer;
+
+class Collection : public QObject
+{
+ Q_OBJECT
+public:
+ Collection();
+ ~Collection();
+
+
+ KEduVocDocument *eduVocDocument();
+
+ void setTitle(const QString& title);
+
+ /** Enable/disable the timed auto backup
+ */
+ void enableAutoBackup(bool enable);
+
+public slots:
+
+ /** close the document*/
+ void close();
+
+signals:
+ /** Emitted when the document pointer is changed.
+ @todo Stop using documentChanged(0) as a replacement for destoyed in editor classes.**/
+ void documentChanged(KEduVocDocument *newDocument);
+ void languagesChanged();
+ void statesNeedSaving();
+
+private:
+ void initializeDefaultGrammar(KEduVocDocument *doc);
+ void setDefaultDocumentProperties(KEduVocDocument *doc);
+
+ private:
+ // The contents of the document
+ KEduVocDocument *m_doc;
+
+ QTimer *m_backupTimer; // Timer for next autosave
+};
+
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic