diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kross/api/interpreter.cpp | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kross/api/interpreter.cpp')
-rw-r--r-- | lib/kross/api/interpreter.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/lib/kross/api/interpreter.cpp b/lib/kross/api/interpreter.cpp new file mode 100644 index 00000000..439063cd --- /dev/null +++ b/lib/kross/api/interpreter.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** + * interpreter.cpp + * This file is part of the KDE project + * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * 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 + * Library General Public License for more details. + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ***************************************************************************/ + +#include "interpreter.h" +#include "script.h" +#include "../main/manager.h" +#include "../main/scriptcontainer.h" + +#include <klibloader.h> + +extern "C" +{ + typedef int (*def_interpreter_func)(Kross::Api::InterpreterInfo*); +} + +using namespace Kross::Api; + +/************************************************************************* + * InterpreterInfo + */ + +InterpreterInfo::InterpreterInfo(const QString& interpretername, const QString& library, const QString& wildcard, QStringList mimetypes, Option::Map options) + : m_interpretername(interpretername) + , m_library(library) + , m_wildcard(wildcard) + , m_mimetypes(mimetypes) + , m_options(options) + , m_interpreter(0) +{ +} + +InterpreterInfo::~InterpreterInfo() +{ + for(Option::Map::Iterator it = m_options.begin(); it != m_options.end(); ++it) + delete it.data(); + + delete m_interpreter; + m_interpreter = 0; +} + +const QString InterpreterInfo::getInterpretername() +{ + return m_interpretername; +} + +const QString InterpreterInfo::getWildcard() +{ + return m_wildcard; +} + +const QStringList InterpreterInfo::getMimeTypes() +{ + return m_mimetypes; +} + +bool InterpreterInfo::hasOption(const QString& key) +{ + return m_options.contains(key); +} + +InterpreterInfo::Option* InterpreterInfo::getOption(const QString name) +{ + return m_options[name]; +} + +const QVariant InterpreterInfo::getOptionValue(const QString name, QVariant defaultvalue) +{ + Option* o = m_options[name]; + return o ? o->value : defaultvalue; +} + +InterpreterInfo::Option::Map InterpreterInfo::getOptions() +{ + return m_options; +} + +Interpreter* InterpreterInfo::getInterpreter() +{ + if(m_interpreter) // buffered + return m_interpreter; + + krossdebug( QString("Loading the interpreter library for %1").arg(m_interpretername) ); + + // Load the krosspython library. + KLibLoader *libloader = KLibLoader::self(); + + KLibrary* library = libloader->globalLibrary( m_library.latin1() ); + if(! library) { + /* + setException( + new Exception( QString("Could not load library \"%1\" for the \"%2\" interpreter.").arg(m_library).arg(m_interpretername) ) + ); + */ + krosswarning( QString("Could not load library \"%1\" for the \"%2\" interpreter.").arg(m_library).arg(m_interpretername) ); + return 0; + } + + // Get the extern "C" krosspython_instance function. + def_interpreter_func interpreter_func; + interpreter_func = (def_interpreter_func) library->symbol("krossinterpreter"); + if(! interpreter_func) { + //setException( new Exception("Failed to load symbol in krosspython library.") ); + krosswarning("Failed to load the 'krossinterpreter' symbol from the library."); + } + else { + // and execute the extern krosspython_instance function. + m_interpreter = (Interpreter*) (interpreter_func)(this); + if(! m_interpreter) { + krosswarning("Failed to load the Interpreter instance from library."); + } + else { + // Job done. The library is loaded and our Interpreter* points + // to the external Kross::Python::Interpreter* instance. + krossdebug("Successfully loaded Interpreter instance from library."); + } + } + + // finally unload the library. + library->unload(); + + return m_interpreter; +} + +/************************************************************************* + * Interpreter + */ + +Interpreter::Interpreter(InterpreterInfo* info) + : m_interpreterinfo(info) +{ +} + +Interpreter::~Interpreter() +{ +} |