]> Git trees. - libqmvoc.git/commitdiff
* Adding a new engine: The chemical-data engine provides access to
authorCarsten Niehaus <cniehaus@gmx.de>
Fri, 29 Jun 2007 14:20:29 +0000 (14:20 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Fri, 29 Jun 2007 14:20:29 +0000 (14:20 +0000)
* libscience. To be precise it gives access to the element.xml file

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=681594

CMakeLists.txt
plasma/CMakeLists.txt [new file with mode: 0644]
plasma/engines/CMakeLists.txt [new file with mode: 0644]
plasma/engines/chemical-data/CMakeLists.txt [new file with mode: 0644]
plasma/engines/chemical-data/chemicaldata.cpp [new file with mode: 0644]
plasma/engines/chemical-data/chemicaldata.h [new file with mode: 0644]
plasma/engines/chemical-data/plasma-engine-chemicaldata.desktop [new file with mode: 0644]

index 39aa96697d5cff1f42e611ff813f34327501d804..24fdc51a246cedeb2e3ee428f76055015b730fbd 100644 (file)
@@ -4,4 +4,4 @@ add_subdirectory(kdeeducore)
 add_subdirectory(kdeeduui)
 add_subdirectory(extdate)
 add_subdirectory(libscience)
-add_subdirectory(widgets)
+add_subdirectory(plasma)
diff --git a/plasma/CMakeLists.txt b/plasma/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6f86840
--- /dev/null
@@ -0,0 +1,3 @@
+find_package(Plasma REQUIRED)
+include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
+add_subdirectory(engines)
diff --git a/plasma/engines/CMakeLists.txt b/plasma/engines/CMakeLists.txt
new file mode 100644 (file)
index 0000000..43b14eb
--- /dev/null
@@ -0,0 +1 @@
+add_subdirectory(chemical-data)
diff --git a/plasma/engines/chemical-data/CMakeLists.txt b/plasma/engines/chemical-data/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0d7e4dd
--- /dev/null
@@ -0,0 +1,16 @@
+include_directories(
+   ${CMAKE_SOURCE_DIR}/libkdeedu/libscience/
+   ${CMAKE_CURRENT_BINARY_DIR}/..
+)
+
+set(chemicaldata_engine_SRCS
+       chemicaldata.cpp
+       )
+
+kde4_automoc(${chemicaldata_engine_SRCS})
+kde4_add_plugin(plasma_engine_chemicaldata ${chemicaldata_engine_SRCS})
+target_link_libraries(plasma_engine_chemicaldata ${KDE4_KDECORE_LIBS} ${PLASMA_LIBRARIES}  ${QT_QTXML_LIBRARY} science )
+
+install(TARGETS plasma_engine_chemicaldata DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES plasma-engine-chemicaldata.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
+
diff --git a/plasma/engines/chemical-data/chemicaldata.cpp b/plasma/engines/chemical-data/chemicaldata.cpp
new file mode 100644 (file)
index 0000000..f8e0c0d
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *   Copyright (C) 2007 Aaron Seigo <aseigo@kde.org>
+ *   Copyright (C) 2007 Sebastian Kuegler <sebas@kde.org>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License version 2 as
+ *   published by the Free Software Foundation
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "chemicaldata.h"
+#include "element.h"
+#include "elementparser.h"
+
+//solid specific includes
+#include <KDebug>
+#include <KLocale>
+#include <kstandarddirs.h>
+
+#include "plasma/datasource.h"
+
+#include <QFile>
+
+ChemicalDataEngine::ChemicalDataEngine(QObject* parent, const QStringList& args)
+        : Plasma::DataEngine(parent)
+{
+    Q_UNUSED(args)
+    ElementSaxParser * parser = new ElementSaxParser();
+    QFile xmlFile( KStandardDirs::locate( "data", "libkdeedu/data/elements.xml" ) );
+    QXmlInputSource source(&xmlFile);
+    QXmlSimpleReader reader;
+
+    reader.setContentHandler(parser);
+    reader.parse(source);
+
+    m_elements = parser->getElements();
+}
+
+ChemicalDataEngine::~ChemicalDataEngine()
+{}
+
+void ChemicalDataEngine::init()
+{}
+
+bool ChemicalDataEngine::sourceRequested(const QString &name)
+{
+    kDebug() << "ChemicalDataEngine::sourceRequested()" << endl;
+    int num = name.toInt(); num -= 1;
+    QString e_name   = m_elements.at(num)->dataAsString( ChemicalDataObject::name );
+    QString e_symbol = m_elements.at(num)->dataAsString( ChemicalDataObject::symbol );
+    QString e_weight = m_elements.at(num)->dataAsString( ChemicalDataObject::mass );
+    setData( e_name, "Symbol", e_symbol );
+    setData( e_name, "Mass", e_weight );
+
+    checkForUpdates( );
+    
+    return true;
+}
+
+#include "chemicaldata.moc"
diff --git a/plasma/engines/chemical-data/chemicaldata.h b/plasma/engines/chemical-data/chemicaldata.h
new file mode 100644 (file)
index 0000000..3cc6063
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef CHEMICALDATA_H
+#define CHEMICALDATA_H
+/*
+ *   Copyright (C) 2007 Carsten Niehaus <cniehaus@kde.org>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License version 2 as
+ *   published by the Free Software Foundation
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+
+#include "plasma/dataengine.h"
+#include "element.h"
+#include "chemicaldataobject.h"
+
+#include <QtXml/qxml.h>
+#include <QList>
+
+/**
+ * This class provides runtime information about the battery and AC status
+ * for use in a simple batter monitor application.
+ */
+class ChemicalDataEngine : public Plasma::DataEngine
+{
+    Q_OBJECT
+
+public:
+    ChemicalDataEngine( QObject* parent, const QStringList& args );
+    ~ChemicalDataEngine();
+
+protected:
+    bool sourceRequested(const QString &name);
+    void init();
+
+private:
+    /**
+     * Set the Element
+     * @param number The number of the Element (1 == H and so on)
+     */
+    void setElement( int number );
+
+    QList<Element*> m_elements; 
+};
+
+
+K_EXPORT_PLASMA_DATAENGINE(chemicaldata, ChemicalDataEngine)
+
+#endif // CHEMICALDATA_H
diff --git a/plasma/engines/chemical-data/plasma-engine-chemicaldata.desktop b/plasma/engines/chemical-data/plasma-engine-chemicaldata.desktop
new file mode 100644 (file)
index 0000000..3c06129
--- /dev/null
@@ -0,0 +1,7 @@
+[Desktop Entry]
+Name=Chemical Data Engine
+ServiceTypes=Plasma/DataEngine
+Type=Service
+Icon=kalzium
+X-KDE-Library=plasma_engine_chemicaldata
+X-EngineName=chemicaldata