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 /kexi/plugins/macros/kexiactions | |
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 'kexi/plugins/macros/kexiactions')
-rw-r--r-- | kexi/plugins/macros/kexiactions/Makefile.am | 27 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/datatableaction.cpp | 185 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/datatableaction.h | 76 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/executeaction.cpp | 96 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/executeaction.h | 78 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/kexiaction.cpp | 48 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/kexiaction.h | 75 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/kexivariable.h | 76 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/messageaction.cpp | 50 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/messageaction.h | 66 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/navigateaction.cpp | 158 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/navigateaction.h | 78 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/objectnamevariable.h | 76 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/objectvariable.h | 87 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/openaction.cpp | 154 | ||||
-rw-r--r-- | kexi/plugins/macros/kexiactions/openaction.h | 79 |
16 files changed, 1409 insertions, 0 deletions
diff --git a/kexi/plugins/macros/kexiactions/Makefile.am b/kexi/plugins/macros/kexiactions/Makefile.am new file mode 100644 index 00000000..4f42e5e9 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/Makefile.am @@ -0,0 +1,27 @@ +include $(top_srcdir)/kexi/Makefile.global + +noinst_LTLIBRARIES = libkeximacroactions.la + +libkeximacroactions_la_SOURCES = \ + kexiaction.cpp \ + openaction.cpp \ + executeaction.cpp \ + navigateaction.cpp \ + messageaction.cpp \ + datatableaction.cpp + +libkeximacroactions_la_CXXFLAGS = $(USE_EXCEPTIONS) + +libkeximacroactions_la_LDFLAGS = $(all_libraries) +libkeximacroactions_la_LIBADD = \ + $(top_builddir)/kexi/plugins/macros/lib/libkomacro.la \ + $(top_builddir)/kexi/core/libkexicore.la \ + $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) + +libkeximacroactions_la_METASOURCES = AUTO +SUBDIRS = . + +INCLUDES = \ + -I$(top_srcdir)/kexi/core \ + -I$(top_srcdir)/kexi \ + $(all_includes) diff --git a/kexi/plugins/macros/kexiactions/datatableaction.cpp b/kexi/plugins/macros/kexiactions/datatableaction.cpp new file mode 100644 index 00000000..90b13e4f --- /dev/null +++ b/kexi/plugins/macros/kexiactions/datatableaction.cpp @@ -0,0 +1,185 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * + * 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 "datatableaction.h" +//#include "objectvariable.h" + +#include <core/kexi.h> +#include <core/kexiproject.h> +#include <core/kexipartmanager.h> +#include <core/kexipartinfo.h> +#include <core/kexipart.h> +#include <core/keximainwindow.h> +#include <core/kexiinternalpart.h> + +#include <klocale.h> + +using namespace KexiMacro; + +namespace KexiMacro { + + //static const QString OBJECT = "method"; + //static const QString OBJECT = "type"; + //static const QString OBJECT = "partitem"; + + template<class ACTIONIMPL> + class MethodVariable : public KexiVariable<ACTIONIMPL> + { + public: + MethodVariable(ACTIONIMPL* actionimpl) + : KexiVariable<ACTIONIMPL>(actionimpl, "method", i18n("Method")) + { + QStringList list; + list << "import" << "export"; + this->appendChild( KSharedPtr<KoMacro::Variable>( new KoMacro::Variable(list, "@list") ) ); + + this->setVariant( list[0] ); + } + }; + + template<class ACTIONIMPL> + class TypeVariable : public KexiVariable<ACTIONIMPL> + { + public: + TypeVariable(ACTIONIMPL* actionimpl) + : KexiVariable<ACTIONIMPL>(actionimpl, "type", i18n("Type")) + { + QStringList list; + list << "file" << "clipboard"; + this->appendChild( KSharedPtr<KoMacro::Variable>( new KoMacro::Variable(list, "@list") ) ); + + this->setVariant( list[0] ); + } + }; + + template<class ACTIONIMPL> + class PartItemVariable : public KexiVariable<ACTIONIMPL> + { + public: + PartItemVariable(ACTIONIMPL* actionimpl, const QString& partitem = QString::null) + : KexiVariable<ACTIONIMPL>(actionimpl, "partitem", i18n("Item")) + { + QStringList namelist; + if(actionimpl->mainWin()->project()) { + KexiPart::PartInfoList* parts = Kexi::partManager().partInfoList(); + for(KexiPart::PartInfoListIterator it(*parts); it.current(); ++it) { + KexiPart::Info* info = it.current(); + if(! info->isDataExportSupported()) + continue; + KexiPart::ItemDict* items = actionimpl->mainWin()->project()->items(info); + if(items) + for(KexiPart::ItemDictIterator item_it = *items; item_it.current(); ++item_it) + namelist << info->objectName() + "." + item_it.current()->name(); + } + for(QStringList::Iterator it = namelist.begin(); it != namelist.end(); ++it) + this->appendChild( KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(*it)) ); + + //const QString name = info->objectName(); //info->groupName(); + //this->appendChild( KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(name)) ); + } + const QString n = + namelist.contains(partitem) + ? partitem + : namelist.count() > 0 ? namelist[0] : ""; + this->setVariant(n); + kdDebug()<<"##################### KexiActions::ObjectVariable() variant="<<this->variant()<<endl; + } + }; + +} + +DataTableAction::DataTableAction() + : KexiAction("datatable", i18n("Data Table")) +{ + setVariable(KSharedPtr<KoMacro::Variable>( new MethodVariable<DataTableAction>(this) )); + setVariable(KSharedPtr<KoMacro::Variable>( new TypeVariable<DataTableAction>(this) )); + setVariable(KSharedPtr<KoMacro::Variable>( new PartItemVariable<DataTableAction>(this) )); +} + +DataTableAction::~DataTableAction() +{ +} + +bool DataTableAction::notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name) +{ + kdDebug()<<"DataTableAction::notifyUpdated() name="<<name<<" macroitem.action="<<(macroitem->action() ? macroitem->action()->name() : "NOACTION")<<endl; + /* + KSharedPtr<KoMacro::Variable> variable = macroitem->variable(name, false); + if(! variable) { + kdWarning()<<"DataTableAction::notifyUpdated() No such variable="<<name<<" in macroitem."<<endl; + return false; + } + variable->clearChildren(); + if(name == "method") { + const int partitem = macroitem->variant(OBJECT, true).toString(); + macroitem->variable(OBJECT, true)->setChildren( + KoMacro::Variable::List() << KSharedPtr<KoMacro::Variable>(new ObjectVariable<ExecuteAction>(this, partitem)) ); + } + */ + return true; +} + +void DataTableAction::activate(KSharedPtr<KoMacro::Context> context) +{ + if(! mainWin()->project()) { + kdWarning() << "ExecuteAction::activate(KSharedPtr<KoMacro::Context>) Invalid project" << endl; + return; + } + + const QString method = context->variable("method")->variant().toString(); + const QString type = context->variable("type")->variant().toString(); + + const QString partitem = context->variable("partitem")->variant().toString(); + QString identifier; + if(! partitem.isEmpty()) { + QStringList parts = QStringList::split(".", partitem); + KexiPart::Part* part = Kexi::partManager().partForMimeType( QString("kexi/%1").arg(parts[0]) ); + KexiPart::Item* item = part ? mainWin()->project()->item(part->info(), parts[1]) : 0; + if(! item) + throw KoMacro::Exception(i18n("No such item \"%1\"").arg(partitem)); + identifier = QString::number(item->identifier()); + } + + QMap<QString,QString> args; + if(! identifier.isNull()) + args.insert("itemId", identifier); + + if(method == "import") { + args.insert("sourceType", type); + QDialog *dlg = KexiInternalPart::createModalDialogInstance( + "csv_importexport", "KexiCSVImportDialog", 0, mainWin(), 0, &args); + if (!dlg) + return; //error msg has been shown by KexiInternalPart + dlg->exec(); + delete dlg; + } + else if(method == "export") { + args.insert("destinationType", type); + QDialog *dlg = KexiInternalPart::createModalDialogInstance( + "csv_importexport", "KexiCSVExportWizard", 0, mainWin(), 0, &args); + if (!dlg) + return; //error msg has been shown by KexiInternalPart + dlg->exec(); + delete dlg; + } + else { + throw KoMacro::Exception(i18n("No such method \"%1\"").arg(method)); + } +} + +//#include "executeaction.moc" diff --git a/kexi/plugins/macros/kexiactions/datatableaction.h b/kexi/plugins/macros/kexiactions/datatableaction.h new file mode 100644 index 00000000..3b5b32c0 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/datatableaction.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_DATATABLEACTION_H +#define KEXIMACRO_DATATABLEACTION_H + +#include "kexiaction.h" + +class KexiMainWindow; + +namespace KoMacro { + class Context; +} + +namespace KexiMacro { + + /** + * The DataTableAction class implements a @a KoMacro::Action + * to provide functionality to import or export a datatable. + * The datatable is used to deal with comma separated values. + */ + class DataTableAction : public KexiAction + { + Q_OBJECT + public: + + /** + * Constructor. + */ + DataTableAction(); + + /** + * Destructor. + */ + virtual ~DataTableAction(); + + /** + * This function is called, when the @a KoMacro::Variable + * with name @p name used within the @a KoMacro::MacroItem + * @p macroitem got changed. + * + * @param macroitem The @a KoMacro::MacroItem instance where + * the variable defined with @p name is located in. + * @param name The name the @a KoMacro::Variable has. + * @return true if the update was successfully else false + * is returned. + */ + virtual bool notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name); + + public slots: + + /** + * Called if the @a Action should be executed within the + * defined @p context . + */ + virtual void activate(KSharedPtr<KoMacro::Context> context); + + }; +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/executeaction.cpp b/kexi/plugins/macros/kexiactions/executeaction.cpp new file mode 100644 index 00000000..1e7f24a2 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/executeaction.cpp @@ -0,0 +1,96 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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 "executeaction.h" + +#include <core/kexi.h> +#include <core/kexiproject.h> +#include <core/kexipartmanager.h> +#include <core/kexipartinfo.h> +#include <core/kexipart.h> +#include <core/keximainwindow.h> + +#include <klocale.h> + +using namespace KexiMacro; + +namespace KexiMacro { + static const QString OBJECT = "object"; + static const QString NAME = "name"; +} + +ExecuteAction::ExecuteAction() + : KexiAction("execute", i18n("Execute")) +{ + int conditions = ObjectVariable<ExecuteAction>::VisibleInNav | ObjectVariable<ExecuteAction>::Executable; + KSharedPtr<KoMacro::Variable> objvar = new ObjectVariable<ExecuteAction>(this, conditions); + setVariable(objvar); + + setVariable(KSharedPtr<KoMacro::Variable>( new ObjectNameVariable<ExecuteAction>(this, objvar->variant().toString()) )); +} + +ExecuteAction::~ExecuteAction() +{ +} + +bool ExecuteAction::notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name) +{ + kdDebug()<<"ExecuteAction::notifyUpdated() name="<<name<<" macroitem.action="<<(macroitem->action() ? macroitem->action()->name() : "NOACTION")<<endl; + KSharedPtr<KoMacro::Variable> variable = macroitem->variable(name, false); + if(! variable) { + kdWarning()<<"ExecuteAction::notifyUpdated() No such variable="<<name<<" in macroitem."<<endl; + return false; + } + + variable->clearChildren(); + if(name == OBJECT) { + const QString objectvalue = macroitem->variant(OBJECT, true).toString(); // e.g. "macro" or "script" + const QString objectname = macroitem->variant(NAME, true).toString(); // e.g. "macro1" or "macro2" if objectvalue above is "macro" + macroitem->variable(NAME, true)->setChildren( + KoMacro::Variable::List() << KSharedPtr<KoMacro::Variable>(new ObjectNameVariable<ExecuteAction>(this, objectvalue, objectname)) ); + } + + return true; +} + +void ExecuteAction::activate(KSharedPtr<KoMacro::Context> context) +{ + if(! mainWin()->project()) { + kdWarning() << "ExecuteAction::activate(KSharedPtr<KoMacro::Context>) Invalid project" << endl; + return; + } + + const QString mimetype = QString("kexi/%1").arg( context->variable("object")->variant().toString() ); + const QString name = context->variable("name")->variant().toString(); + + KexiPart::Part* part = Kexi::partManager().partForMimeType(mimetype); + if(! part) { + throw KoMacro::Exception(i18n("No such mimetype \"%1\"").arg(mimetype)); + } + + KexiPart::Item* item = mainWin()->project()->item(part->info(), name); + if(! item) { + throw KoMacro::Exception(i18n("Failed to open part \"%1\" for mimetype \"%2\"").arg(name).arg(mimetype)); + } + + part->execute(item); +} + +//#include "executeaction.moc" diff --git a/kexi/plugins/macros/kexiactions/executeaction.h b/kexi/plugins/macros/kexiactions/executeaction.h new file mode 100644 index 00000000..17a8ca88 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/executeaction.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_EXECUTEACTION_H +#define KEXIMACRO_EXECUTEACTION_H + +#include "kexiaction.h" + +class KexiMainWindow; + +namespace KoMacro { + class Context; +} + +namespace KexiMacro { + + /** + * The ExecuteAction class implements a @a KoMacro::Action + * to provide functionality to execute an object like + * e.g. a script or a macro. + */ + class ExecuteAction : public KexiAction + { + Q_OBJECT + public: + + /** + * Constructor. + */ + ExecuteAction(); + + /** + * Destructor. + */ + virtual ~ExecuteAction(); + + /** + * This function is called, when the @a KoMacro::Variable + * with name @p name used within the @a KoMacro::MacroItem + * @p macroitem got changed. + * + * @param macroitem The @a KoMacro::MacroItem instance where + * the variable defined with @p name is located in. + * @param name The name the @a KoMacro::Variable has. + * @return true if the update was successfully else false + * is returned. + */ + virtual bool notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name); + + public slots: + + /** + * Called if the @a Action should be executed within the + * defined @p context . + */ + virtual void activate(KSharedPtr<KoMacro::Context> context); + + }; +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/kexiaction.cpp b/kexi/plugins/macros/kexiactions/kexiaction.cpp new file mode 100644 index 00000000..521f8cfc --- /dev/null +++ b/kexi/plugins/macros/kexiactions/kexiaction.cpp @@ -0,0 +1,48 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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 "kexiaction.h" +#include "../lib/exception.h" + +#include <ksharedptr.h> + +using namespace KexiMacro; + +KexiAction::KexiAction(const QString& name, const QString& text) + : KoMacro::Action(name) +{ + m_mainwin = dynamic_cast< KexiMainWindow* >( KoMacro::Manager::self()->guiClient() ); + + if(! m_mainwin) { + throw KoMacro::Exception("Invalid KexiMainWindow instance."); + } + + // Set the caption this action has. + setText(text); +} + +KexiAction::~KexiAction() +{ +} + +KexiMainWindow* KexiAction::mainWin() const +{ + return m_mainwin; +} diff --git a/kexi/plugins/macros/kexiactions/kexiaction.h b/kexi/plugins/macros/kexiactions/kexiaction.h new file mode 100644 index 00000000..a61e2bc1 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/kexiaction.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_KEXIACTION_H +#define KEXIMACRO_KEXIACTION_H + +#include "../lib/action.h" +#include "../lib/variable.h" +#include "../lib/macroitem.h" +#include "../lib/context.h" + +#include "objectvariable.h" +#include "objectnamevariable.h" + +#include <core/keximainwindow.h> + +namespace KexiMacro { + + /** + * Template class to offer common functionality needed by all + * @a KoMacro::Action implementations Kexi provides. + * + * All the actions Kexi provides are inherited from this + * template class. + */ + class KexiAction : public KoMacro::Action + { + public: + + /** + * Constructor. + * + * @param name The unique name the @a KoMacro::Action has. This + * name will be used to identify the action. + * @param text The i18n-caption text used for display purposes. + */ + KexiAction(const QString& name, const QString& text); + + /** + * Destructor. + */ + virtual ~KexiAction(); + + /** + * @return the @a KexiMainWindow instance we are + * running in. + */ + KexiMainWindow* mainWin() const; + + private: + + /// The @a KexiMainWindow instance. + KexiMainWindow* m_mainwin; + + }; +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/kexivariable.h b/kexi/plugins/macros/kexiactions/kexivariable.h new file mode 100644 index 00000000..27dcc0ef --- /dev/null +++ b/kexi/plugins/macros/kexiactions/kexivariable.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_KEXIVARIABLE_H +#define KEXIMACRO_KEXIVARIABLE_H + +#include "../lib/manager.h" +#include "../lib/exception.h" +#include "../lib/action.h" +#include "../lib/variable.h" + +#include <ksharedptr.h> + +class KexiMainWindow; + +namespace KoMacro { + class Context; +} + +namespace KexiMacro { + + /** + * Template class to offer common functionality needed by all + * @a KoMacro::Variable implementations Kexi provides. + */ + template<class ACTIONIMPL> + class KexiVariable : public KoMacro::Variable + { + public: + + /** + * Constructor. + */ + KexiVariable(ACTIONIMPL* actionimpl, const QString& name, const QString& caption) + : KoMacro::Variable() + , m_actionimpl(actionimpl) + { + setName(name); + setText(caption); + } + + protected: + + /** + * @return the @a KexiAction implementation this @a KexiVariable + * is a child of. + */ + ACTIONIMPL* actionImpl() const + { + return m_actionimpl; + } + + private: + /// The parent @a KexiAction implementation. + ACTIONIMPL* m_actionimpl; + }; +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/messageaction.cpp b/kexi/plugins/macros/kexiactions/messageaction.cpp new file mode 100644 index 00000000..1a4605cb --- /dev/null +++ b/kexi/plugins/macros/kexiactions/messageaction.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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 "messageaction.h" + +#include <core/keximainwindow.h> + +#include <klocale.h> +#include <kmessagebox.h> +#include <kdebug.h> + +using namespace KexiMacro; + +MessageAction::MessageAction() + : KexiAction("message", i18n("Message")) +{ + setVariable("caption", i18n("Caption"), QString("")); + setVariable("message", i18n("Message"), QString("")); +} + +MessageAction::~MessageAction() +{ +} + +void MessageAction::activate(KSharedPtr<KoMacro::Context> context) +{ + kdDebug() << "MessageAction::activate(KSharedPtr<Context>)" << endl; + const QString caption = context->variable("caption")->variant().toString(); + const QString message = context->variable("message")->variant().toString(); + KMessageBox::information(mainWin(), message, caption); +} + +//#include "messageaction.moc" diff --git a/kexi/plugins/macros/kexiactions/messageaction.h b/kexi/plugins/macros/kexiactions/messageaction.h new file mode 100644 index 00000000..543674bd --- /dev/null +++ b/kexi/plugins/macros/kexiactions/messageaction.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_MESSAGEACTION_H +#define KEXIMACRO_MESSAGEACTION_H + + +#include "kexiaction.h" + +class KexiMainWindow; + +namespace KoMacro { + class Context; +} + +namespace KexiMacro { + + /** + * The ExecuteObject class implements a @a KoMacro::Action + * to provide functionality to execute an object like + * e.g. a script or a macro. + */ + class MessageAction : public KexiAction + { + Q_OBJECT + public: + + /** + * Constructor. + */ + MessageAction(); + + /** + * Destructor. + */ + virtual ~MessageAction(); + + public slots: + + /** + * Called if the @a Action should be executed within the + * defined @param context . + */ + virtual void activate(KSharedPtr<KoMacro::Context> context); + + }; +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/navigateaction.cpp b/kexi/plugins/macros/kexiactions/navigateaction.cpp new file mode 100644 index 00000000..d3fe551c --- /dev/null +++ b/kexi/plugins/macros/kexiactions/navigateaction.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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 "navigateaction.h" + +#include <core/kexi.h> +#include <core/kexiproject.h> +#include <core/kexipartmanager.h> +#include <core/kexipartinfo.h> +#include <core/kexipart.h> +#include <core/keximainwindow.h> +#include <core/kexidialogbase.h> + +#include <widget/kexidataawareview.h> +#include <widget/tableview/kexidataawareobjectiface.h> + +#include <klocale.h> +#include <kdebug.h> + +using namespace KexiMacro; + +namespace KexiMacro { + + template<class ACTIONIMPL> + class NavigateVariable : public KexiVariable<ACTIONIMPL> + { + public: + NavigateVariable(ACTIONIMPL* actionimpl) + : KexiVariable<ACTIONIMPL>(actionimpl, "record", i18n("Record")) + { + QStringList list; + list << "first" << "previous" << "next" << "last" << "goto"; + this->appendChild( KSharedPtr<KoMacro::Variable>( new KoMacro::Variable(list, "@list") ) ); + + /*TODO should this actions belong to navigate? maybe it would be more wise to have + such kind of functionality in an own e.g. "Modify" action to outline, that + we are manipulating the database that way... */ + //"add" << "save" << "delete" << "query" << "execute" << "cancel" << "reload" + + this->setVariant( list[0] ); + } + }; + +} + +NavigateAction::NavigateAction() + : KexiAction("navigate", i18n("Navigate")) +{ + KoMacro::Variable* navvar = new NavigateVariable<NavigateAction>(this); + setVariable(KSharedPtr<KoMacro::Variable>( navvar )); + + KoMacro::Variable* rowvar = new KexiVariable<NavigateAction>(this, "rownr", i18n("Row")); + rowvar->setVariant(0); + setVariable(KSharedPtr<KoMacro::Variable>(rowvar)); + + KoMacro::Variable* colvar = new KexiVariable<NavigateAction>(this, "colnr", i18n("Column")); + colvar->setVariant(0); + setVariable(KSharedPtr<KoMacro::Variable>(colvar)); +} + +NavigateAction::~NavigateAction() +{ +} + +bool NavigateAction::notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name) +{ + kdDebug()<<"NavigateAction::notifyUpdated() name="<<name<<" macroitem.action="<<(macroitem->action() ? macroitem->action()->name() : "NOACTION")<<endl; + KSharedPtr<KoMacro::Variable> variable = macroitem->variable(name, false); + if(! variable) { + kdWarning()<<"NavigateAction::notifyUpdated() No such variable="<<name<<" in macroitem."<<endl; + return false; + } + + variable->clearChildren(); + if(name == "goto") { + const int rownr = macroitem->variant("rownr", true).toInt(); // e.g. "macro" or "script" + const int colnr = macroitem->variant("colnr", true).toInt(); // e.g. "macro1" or "macro2" if objectvalue above is "macro" + + macroitem->variable("rownr", true)->setChildren( + KoMacro::Variable::List() << KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(rownr)) ); + macroitem->variable("colnr", true)->setChildren( + KoMacro::Variable::List() << KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(colnr)) ); + } + + return true; +} + +void NavigateAction::activate(KSharedPtr<KoMacro::Context> context) +{ + KexiDialogBase* dialog = dynamic_cast<KexiDialogBase*>( mainWin()->activeWindow() ); + if(! dialog) { + throw KoMacro::Exception(i18n("No window active.")); + } + + KexiViewBase* view = dialog->selectedView(); + if(! view) { + throw KoMacro::Exception(i18n("No view selected for \"%1\".").arg(dialog->caption())); + } + + KexiDataAwareView* dbview = dynamic_cast<KexiDataAwareView*>( view ); + KexiDataAwareObjectInterface* dbobj = dbview ? dbview->dataAwareObject() : 0; + if(! dbview) { + throw KoMacro::Exception(i18n("The view for \"%1\" could not handle data.").arg(dialog->caption())); + } + + const QString record = context->variable("record")->variant().toString(); + if(record == "previous") { + dbobj->selectPrevRow(); + } + else if(record == "next") { + dbobj->selectNextRow(); + } + else if(record == "first") { + dbobj->selectFirstRow(); + } + else if(record == "last") { + dbobj->selectLastRow(); + } + else if(record == "goto") { + int rownr = context->variable("rownr")->variant().toInt() - 1; + int colnr = context->variable("colnr")->variant().toInt() - 1; + dbobj->setCursorPosition(rownr >= 0 ? rownr : dbobj->currentRow(), colnr >= 0 ? colnr : dbobj->currentColumn()); + } + else { + /* + virtual void selectNextPage(); //!< page down action + virtual void selectPrevPage(); //!< page up action + void deleteAllRows(); + void deleteCurrentRow(); + void deleteAndStartEditCurrentCell(); + void startEditOrToggleValue(); + bool acceptRowEdit(); + void cancelRowEdit(); + void sortAscending(); + void sortDescending(); + */ + throw KoMacro::Exception(i18n("Unknown record \"%1\" in view for \"%2\".").arg(record).arg(dialog->caption())); + } +} + +//#include "navigateaction.moc" diff --git a/kexi/plugins/macros/kexiactions/navigateaction.h b/kexi/plugins/macros/kexiactions/navigateaction.h new file mode 100644 index 00000000..f7f74f86 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/navigateaction.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_NAVIGATEACTION_H +#define KEXIMACRO_NAVIGATEACTION_H + +#include "kexiaction.h" + +class KexiMainWindow; + +namespace KoMacro { + class Context; +} + +namespace KexiMacro { + + /** + * The NavigateAction class implements a @a KoMacro::Action + * to provide functionality to execute an object like + * e.g. a script or a macro. + */ + class NavigateAction : public KexiAction + { + Q_OBJECT + public: + + /** + * Constructor. + */ + NavigateAction(); + + /** + * Destructor. + */ + virtual ~NavigateAction(); + + /** + * This function is called, when the @a KoMacro::Variable + * with name @p name used within the @a KoMacro::MacroItem + * @p macroitem got changed. + * + * @param macroitem The @a KoMacro::MacroItem instance where + * the variable defined with @p name is located in. + * @param name The name the @a KoMacro::Variable has. + * @return true if the update was successfully else false + * is returned. + */ + virtual bool notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name); + + public slots: + + /** + * Called if the @a Action should be executed within the + * defined @p context . + */ + virtual void activate(KSharedPtr<KoMacro::Context> context); + + }; +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/objectnamevariable.h b/kexi/plugins/macros/kexiactions/objectnamevariable.h new file mode 100644 index 00000000..eeaabe04 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/objectnamevariable.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_OBJECTNAMEVARIABLE_H +#define KEXIMACRO_OBJECTNAMEVARIABLE_H + +#include "../lib/variable.h" + +#include "kexivariable.h" + +#include <core/kexi.h> +#include <core/kexiproject.h> +#include <core/kexipartmanager.h> +#include <core/kexipartinfo.h> + +#include <klocale.h> + +namespace KexiMacro { + + /** + * The ViewVariable class provide a list of KexiPart::PartItem's + * supported by a KexiPart::Part as @a KoMacro::Variable . + */ + template<class ACTIONIMPL> + class ObjectNameVariable : public KexiVariable<ACTIONIMPL> + { + public: + ObjectNameVariable(ACTIONIMPL* actionimpl, const QString& objectname = QString::null, const QString& name = QString::null) + : KexiVariable<ACTIONIMPL>(actionimpl, "name", i18n("Name")) + { + if(! actionimpl->mainWin()->project()) + return; + + QStringList namelist; + KexiPart::Info* info = Kexi::partManager().infoForMimeType( QString("kexi/%1").arg(objectname) ); + if(info) { + KexiPart::ItemDict* items = actionimpl->mainWin()->project()->items(info); + if(items) + for(KexiPart::ItemDictIterator item_it = *items; item_it.current(); ++item_it) + namelist << item_it.current()->name(); + } + + if(namelist.count() <= 0) + namelist << ""; + + for(QStringList::Iterator it = namelist.begin(); it != namelist.end(); ++it) + this->appendChild( KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(*it)) ); + + this->setVariant( (name.isNull() || ! namelist.contains(name)) ? namelist[0] : name ); + + kdDebug()<<"##################### KexiActions::ObjectNameVariable() objectname="<<objectname<<" name="<<name<<" value="<<this->variant()<<" children="<<namelist<<endl; + } + + virtual ~ObjectNameVariable() {} + }; + +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/objectvariable.h b/kexi/plugins/macros/kexiactions/objectvariable.h new file mode 100644 index 00000000..b61f24e3 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/objectvariable.h @@ -0,0 +1,87 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_OBJECTVARIABLE_H +#define KEXIMACRO_OBJECTVARIABLE_H + +#include "../lib/action.h" +#include "../lib/variable.h" + +#include "kexivariable.h" + +#include <core/kexi.h> +#include <core/kexiproject.h> +#include <core/kexipartmanager.h> +#include <core/kexipartinfo.h> + +#include <klocale.h> +#include <kdebug.h> + +namespace KexiMacro { + + /** + * The ObjectVariable class implements @a KoMacro::Variable to + * provide a variable list of Kexi-objects. Those Kexi-objects + * are KexiPart's like e.g. table, query, form or script. + */ + template<class ACTIONIMPL> + class ObjectVariable : public KexiVariable<ACTIONIMPL> + { + public: + + enum Conditions { + VisibleInNav = 1, + Executable = 2, + DataExport = 4 + }; + + ObjectVariable(ACTIONIMPL* actionimpl, int conditions = VisibleInNav, const QString& objectname = QString::null) + : KexiVariable<ACTIONIMPL>(actionimpl, "object", i18n("Object")) + { + KexiPart::PartInfoList* parts = Kexi::partManager().partInfoList(); + for(KexiPart::PartInfoListIterator it(*parts); it.current(); ++it) { + KexiPart::Info* info = it.current(); + + if(conditions & VisibleInNav && ! info->isVisibleInNavigator()) + continue; + if(conditions & Executable && ! info->isExecuteSupported()) + continue; + if(conditions & DataExport && ! info->isDataExportSupported()) + continue; + + const QString name = info->objectName(); //info->groupName(); + this->appendChild( KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(name)) ); + } + + if(! objectname.isNull()) + this->setVariant( objectname ); + else if(this->children().count() > 0) + this->setVariant( this->children()[0]->variant() ); + else + this->setVariant( QString::null ); + + kdDebug()<<"##################### KexiActions::ObjectVariable() variant="<<this->variant()<<endl; + } + + }; + +} + +#endif diff --git a/kexi/plugins/macros/kexiactions/openaction.cpp b/kexi/plugins/macros/kexiactions/openaction.cpp new file mode 100644 index 00000000..b67041bb --- /dev/null +++ b/kexi/plugins/macros/kexiactions/openaction.cpp @@ -0,0 +1,154 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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 "openaction.h" + +#include <core/kexi.h> +#include <core/kexiproject.h> +#include <core/kexipartmanager.h> +#include <core/kexipartinfo.h> +#include <core/kexipart.h> +#include <core/keximainwindow.h> + +#include <klocale.h> + +using namespace KexiMacro; + +namespace KexiMacro { + + static const QString DATAVIEW = "data"; + static const QString DESIGNVIEW = "design"; + static const QString TEXTVIEW = "text"; + + static const QString OBJECT = "object"; + static const QString NAME = "name"; + static const QString VIEW = "view"; + + /** + * The ViewVariable class provide a list of viewmodes supported + * by a KexiPart::Part as @a KoMacro::Variable . + */ + template<class ACTIONIMPL> + class ViewVariable : public KexiVariable<ACTIONIMPL> + { + public: + ViewVariable(ACTIONIMPL* actionimpl, const QString& objectname = QString::null, const QString& viewname = QString::null) + : KexiVariable<ACTIONIMPL>(actionimpl, VIEW, i18n("View")) + { + QStringList namelist; + KexiPart::Part* part = Kexi::partManager().partForMimeType( QString("kexi/%1").arg(objectname) ); + if(part) { + int viewmodes = part->supportedViewModes(); + if(viewmodes & Kexi::DataViewMode) + namelist << DATAVIEW; + if(viewmodes & Kexi::DesignViewMode) + namelist << DESIGNVIEW; + if(viewmodes & Kexi::TextViewMode) + namelist << TEXTVIEW; + for(QStringList::Iterator it = namelist.begin(); it != namelist.end(); ++it) + this->children().append( KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(*it)) ); + } + const QString n = + namelist.contains(viewname) + ? viewname + : namelist.count() > 0 ? namelist[0] : ""; + + this->setVariant(n); + } + }; + +} + +OpenAction::OpenAction() + : KexiAction("open", i18n("Open")) +{ + const int conditions = ObjectVariable<OpenAction>::VisibleInNav; + + KSharedPtr<KoMacro::Variable> objvar = new ObjectVariable<OpenAction>(this, conditions); + setVariable(objvar); + + setVariable(KSharedPtr<KoMacro::Variable>( new ObjectNameVariable<OpenAction>(this, objvar->variant().toString()) )); + setVariable(KSharedPtr<KoMacro::Variable>( new ViewVariable<OpenAction>(this, objvar->variant().toString()) )); +} + +OpenAction::~OpenAction() +{ +} + +bool OpenAction::notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name) +{ + kdDebug()<<"OpenAction::notifyUpdated() name="<<name<<" macroitem.action="<<(macroitem->action() ? macroitem->action()->name() : "NOACTION")<<endl; + KSharedPtr<KoMacro::Variable> variable = macroitem->variable(name, false); + if(! variable) { + kdWarning()<<"OpenAction::notifyUpdated() No such variable="<<name<<" in macroitem."<<endl; + return false; + } + + variable->clearChildren(); + if(name == OBJECT) { + const QString objectvalue = macroitem->variant(OBJECT, true).toString(); // e.g. "table" or "query" + const QString objectname = macroitem->variant(NAME, true).toString(); // e.g. "table1" or "table2" if objectvalue above is "table" + const QString viewname = macroitem->variant(VIEW, true).toString(); // "data", "design" or "text" + + macroitem->variable(NAME, true)->setChildren( + KoMacro::Variable::List() << KSharedPtr<KoMacro::Variable>(new ObjectNameVariable<OpenAction>(this, objectvalue, objectname)) ); + macroitem->variable(VIEW, true)->setChildren( + KoMacro::Variable::List() << KSharedPtr<KoMacro::Variable>(new ViewVariable<OpenAction>(this, objectvalue, viewname)) ); + } + + return true; +} + +void OpenAction::activate(KSharedPtr<KoMacro::Context> context) +{ + if(! mainWin()->project()) { + throw KoMacro::Exception(i18n("No project loaded.")); + } + + const QString objectname = context->variable(OBJECT)->variant().toString(); + const QString name = context->variable(NAME)->variant().toString(); + KexiPart::Item* item = mainWin()->project()->itemForMimeType( QString("kexi/%1").arg(objectname).latin1(), name ); + if(! item) { + throw KoMacro::Exception(i18n("No such object \"%1.%2\".").arg(objectname).arg(name)); + } + + // Determinate the viewmode. + const QString view = context->variable(VIEW)->variant().toString(); + int viewmode; + if(view == DATAVIEW) + viewmode = Kexi::DataViewMode; + else if(view == DESIGNVIEW) + viewmode = Kexi::DesignViewMode; + else if(view == TEXTVIEW) + viewmode = Kexi::TextViewMode; + else { + throw KoMacro::Exception(i18n("No such viewmode \"%1\" in object \"%2.%3\".").arg(view).arg(objectname).arg(name)); + } + + // Try to open the object now. + bool openingCancelled; + if(! mainWin()->openObject(item, viewmode, openingCancelled)) { + if(! openingCancelled) { + throw KoMacro::Exception(i18n("Failed to open object \"%1.%2\".").arg(objectname).arg(name)); + } + } +} + +//#include "openaction.moc" diff --git a/kexi/plugins/macros/kexiactions/openaction.h b/kexi/plugins/macros/kexiactions/openaction.h new file mode 100644 index 00000000..b49f1238 --- /dev/null +++ b/kexi/plugins/macros/kexiactions/openaction.h @@ -0,0 +1,79 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer ([email protected]) + * copyright (C) 2006 by Bernd Steindorff ([email protected]) + * copyright (C) 2006 by Sascha Kupper ([email protected]) + * + * 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. + ***************************************************************************/ + +#ifndef KEXIMACRO_OPENACTION_H +#define KEXIMACRO_OPENACTION_H + +#include "kexiaction.h" + +class KexiMainWindow; + +namespace KoMacro { + class Context; +} + +namespace KexiMacro { + + /** + * The OpenAction class implements a @a KoMacro::Action + * to provide functionality to open any kind of Kexi + * object (e.g. table, query, form, script, ...). + */ + class OpenAction : public KexiAction + { + Q_OBJECT + + public: + + /** + * Constructor. + */ + OpenAction(); + + /** + * Destructor. + */ + virtual ~OpenAction(); + + /** + * This function is called, when the @a KoMacro::Variable + * with name @p name used within the @a KoMacro::MacroItem + * @p macroitem got changed. + * + * @param macroitem The @a KoMacro::MacroItem instance where + * the variable defined with @p name is located in. + * @param name The name the @a KoMacro::Variable has. + * @return true if the update was successfully else false + * is returned. + */ + virtual bool notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name); + + public slots: + + /** + * Called if the @a Action should be executed within the + * defined @p context . + */ + virtual void activate(KSharedPtr<KoMacro::Context> context); + + }; +} + +#endif |