From: Carsten Niehaus Date: Fri, 29 Jun 2007 14:20:29 +0000 (+0000) Subject: * Adding a new engine: The chemical-data engine provides access to X-Git-Tag: v3.92.0~58 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=29b3838d0b1c5589dc80dc6d888fcaec7d4795e4;p=libqmvoc.git * Adding a new engine: The chemical-data engine provides access to * libscience. To be precise it gives access to the element.xml file svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=681594 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 39aa966..24fdc51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..6f86840 --- /dev/null +++ b/plasma/CMakeLists.txt @@ -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 index 0000000..43b14eb --- /dev/null +++ b/plasma/engines/CMakeLists.txt @@ -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 index 0000000..0d7e4dd --- /dev/null +++ b/plasma/engines/chemical-data/CMakeLists.txt @@ -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 index 0000000..f8e0c0d --- /dev/null +++ b/plasma/engines/chemical-data/chemicaldata.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007 Aaron Seigo + * Copyright (C) 2007 Sebastian Kuegler + * + * 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 +#include +#include + +#include "plasma/datasource.h" + +#include + +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 index 0000000..3cc6063 --- /dev/null +++ b/plasma/engines/chemical-data/chemicaldata.h @@ -0,0 +1,58 @@ +#ifndef CHEMICALDATA_H +#define CHEMICALDATA_H +/* + * Copyright (C) 2007 Carsten Niehaus + * + * 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 +#include + +/** + * 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 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 index 0000000..3c06129 --- /dev/null +++ b/plasma/engines/chemical-data/plasma-engine-chemicaldata.desktop @@ -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