• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.12
  • kdeedu
  • parley
  • plasmoid
  • engine
parley_engine.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
17 #include "parley_engine.h"
18 
19 #include <QStringList>
20 
21 #include <KDebug>
22 #include <KConfigGroup>
23 
24 #include <keduvocdocument.h>
25 #include <keduvoclesson.h>
26 #include <keduvocexpression.h>
27 
28 
29 #include "plasma/datacontainer.h"
30 
31 ParleyEngine::ParleyEngine(QObject* parent, const QVariantList& args)
32  : Plasma::DataEngine(parent)
33 {
34  Q_UNUSED(args)
35  KGlobal::locale()->insertCatalog("parley");
36  setMinimumPollingInterval(1000);
37  kDebug() << "ParleyEngine::ParleyEngine";
38 
39  m_random = new KRandomSequence( QDateTime::currentDateTime().toTime_t() );
40 }
41 
42 ParleyEngine::~ParleyEngine()
43 {
44  delete m_random;
45 }
46 
47 void ParleyEngine::openDocument(const QString& file)
48 {
49  kDebug() << "Open vocabulary file: '" << file << "'";
50  if (!file.isEmpty()) {
51  KEduVocDocument *doc = new KEduVocDocument(this);
52  doc->open(KUrl(file));
53 
54  // check that there is at least one identifier, otherwise this won't work...
55  if (doc->identifierCount() > 0) {
56  m_docs.insert(file, doc);
57  // vocabularyCount = doc->lesson()->entries(KEduVocContainer::Recursive).count();
58  } else {
59  delete doc;
60  }
61  }
62 }
63 
64 QStringList ParleyEngine::sources() const
65 {
66  return m_docs.keys();
67 }
68 
69 bool ParleyEngine::sourceRequestEvent(const QString &source)
70 {
71  if (!m_docs.contains(source)) {
72  kDebug() << "open file: " << source;
73  openDocument(source);
74  }
75 
76  if (!m_docs.contains(source)) {
77  kDebug() << "Could not open source file: " << source;
78  return false;
79  }
80  return updateSourceEvent(source);
81 }
82 
83 bool ParleyEngine::updateSourceEvent(const QString &source)
84 {
85  KEduVocDocument* doc = m_docs.value(source);
86  if (!doc) {
87  return false;
88  }
89 
90  int vocabularyCount = doc->lesson()->entries(KEduVocContainer::Recursive).count();
91  if (!vocabularyCount) {
92  setData(source, QVariant());
93  return false;
94  }
95 
96  ulong current = m_random->getLong(vocabularyCount);
97  KEduVocExpression *expression = doc->lesson()->entries(KEduVocContainer::Recursive).value(current);
98 
99  QHash<QString,QVariant> data;
100  for (int i = 0; i < doc->identifierCount(); i++) {
101  data[doc->identifier(i).name()] = expression->translation(i)->text();
102  }
103  setData(source, data);
104 
105  return true;
106 }
107 
108 #include "parley_engine.moc"
QObject
ParleyEngine::sources
QStringList sources() const
Definition: parley_engine.cpp:64
ParleyEngine::updateSourceEvent
bool updateSourceEvent(const QString &source)
Definition: parley_engine.cpp:83
parley_engine.h
ParleyEngine::sourceRequestEvent
bool sourceRequestEvent(const QString &name)
Definition: parley_engine.cpp:69
ParleyEngine::~ParleyEngine
~ParleyEngine()
Definition: parley_engine.cpp:42
ParleyEngine::ParleyEngine
ParleyEngine(QObject *parent, const QVariantList &args)
Definition: parley_engine.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal