kspread

scripting.cc

00001 /*
00002  * This file is part of the KSpread project
00003  *
00004  * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
00005  * Copyright (c) 2006 Isaac Clerencia <isaac@warp.es>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  */
00021 #include "scripting.h"
00022 
00023 #include <qapplication.h>
00024 
00025 #include <kdebug.h>
00026 #include <kgenericfactory.h>
00027 #include <kstandarddirs.h>
00028 
00029 #define KROSS_MAIN_EXPORT KDE_EXPORT
00030 #include <main/manager.h>
00031 #include <main/scriptguiclient.h>
00032 #include <main/wdgscriptsmanager.h>
00033 
00034 #include <kspread_doc.h>
00035 #include <kspread_view.h>
00036 
00037 typedef KGenericFactory<Scripting> KSpreadScriptingFactory;
00038 K_EXPORT_COMPONENT_FACTORY( kspreadscripting, KSpreadScriptingFactory( "kspreadscripting" ) )
00039 
00040 Scripting::Scripting(QObject *parent, const char *name, const QStringList &)
00041         : KParts::Plugin(parent, name)
00042 {
00043     setInstance(KSpreadScriptingFactory::instance());
00044 
00045     kdDebug() << "Scripting plugin. Class: "
00046           << metaObject()->className()
00047           << ", Parent: "
00048           << parent->metaObject()->className()
00049           << "\n";
00050 
00051     if ( parent->inherits("KSpread::View") )
00052     {
00053         setInstance(Scripting::instance());
00054         m_view = (KSpread::View*) parent;
00055         m_scriptguiclient = new Kross::Api::ScriptGUIClient( m_view, m_view );
00056 //         m_scriptguiclient ->setXMLFile(locate("data","kspreadplugins/scripting.rc"), true);
00057         kdDebug() << "Setup actions for scripting !" << endl;
00058 
00059         setXMLFile(locate("data","kspread/kpartplugins/scripting.rc"), true);
00060 
00061         new KAction(i18n("Execute Script File..."), 0, 0, m_scriptguiclient, SLOT(executeScriptFile()), actionCollection(), "executescriptfile");
00062         new KAction(i18n("Script Manager..."), 0, 0, m_scriptguiclient, SLOT(showScriptManager()), actionCollection(), "configurescripts");
00063 
00064         KAction* scriptmenuaction = m_scriptguiclient->action("installedscripts");
00065         actionCollection()->insert(scriptmenuaction);
00066 
00067         connect(m_scriptguiclient, SIGNAL(executionFinished( const Kross::Api::ScriptAction* )), this, SLOT(executionFinished(const Kross::Api::ScriptAction*)));
00068 
00069         Kross::Api::Manager::scriptManager()->addQObject(m_view->doc(), "KSpreadDocument");
00070         Kross::Api::Manager::scriptManager()->addQObject(m_view, "KSpreadView");
00071     }
00072 
00073 }
00074 
00075 Scripting::~Scripting()
00076 {
00077 }
00078 
00079 void Scripting::executionFinished(const Kross::Api::ScriptAction*)
00080 {
00081     QApplication::restoreOverrideCursor();
00082 }
00083 
00084 #include "scripting.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys