kexi

keximacropart.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Sebastian Sauer <mail@dipe.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12 You should have received a copy of the GNU Library General Public License
13 along with this library; see the file COPYING.LIB. If not, write to
14 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
15 Boston, MA 02110-1301, USA.
16*/
17
18#include "keximacropart.h"
19
20#include "keximacroview.h"
21#include "keximacrodesignview.h"
22#include "keximacrotextview.h"
23
24//#include "kexiviewbase.h"
25//#include "keximainwindow.h"
26//#include "kexiproject.h"
27
28#include <tqdom.h>
29#include <tqstringlist.h>
30#include <kgenericfactory.h>
31#include <kexipartitem.h>
32//#include <kxmlguiclient.h>
33//#include <kexidialogbase.h>
34//#include <tdeconfig.h>
35//#include <kdebug.h>
36
37#include "../lib/manager.h"
38#include "../lib/macro.h"
39#include "../lib/macroitem.h"
40#include "../lib/action.h"
41
42#include "../kexiactions/openaction.h"
43#include "../kexiactions/executeaction.h"
44#include "../kexiactions/navigateaction.h"
45#include "../kexiactions/messageaction.h"
46#include "../kexiactions/datatableaction.h"
47
52class KexiMacroPart::Private
53{
54 public:
55};
56
57KexiMacroPart::KexiMacroPart(TQObject *parent, const char *name, const TQStringList &l)
58 : KexiPart::Part(parent, name, l)
59 , d( new Private() )
60{
61 //kdDebug() << "KexiMacroPart::KexiMacroPart() Ctor" << endl;
62
63 //registered ID
64 m_registeredPartID = (int)KexiPart::MacroObjectType;
65
66 //name of the instance.
67 m_names["instanceName"]
68 = i18n("Translate this word using only lowercase alphanumeric characters (a..z, 0..9). "
69 "Use '_' character instead of spaces. First character should be a..z character. "
70 "If you cannot use latin characters in your language, use english word.",
71 "macro");
72
73 //describing caption
74 m_names["instanceCaption"] = i18n("Macro");
75
76 //supported viewmodes
77 m_supportedViewModes = Kexi::DesignViewMode | Kexi::TextViewMode;
78}
79
81{
82 //kdDebug() << "KexiMacroPart::~KexiMacroPart() Dtor" << endl;
83 delete d;
84}
85
86bool KexiMacroPart::execute(KexiPart::Item* item, TQObject* sender)
87{
88 KexiDialogBase* dialog = new KexiDialogBase(m_mainWin);
89 dialog->setId( item->identifier() );
90 KexiMacroView* view = dynamic_cast<KexiMacroView*>( createView(dialog, dialog, *item, Kexi::DataViewMode) );
91 if(! view) {
92 kdWarning() << "KexiMacroPart::execute() Failed to create a view." << endl;
93 return false;
94 }
95
96 if(! view->macro().data()) {
97 kdWarning() << "KexiMacroPart::execute() No such item " << item->name() << endl;
98 return false;
99 }
100
101 kdDebug() << "KexiMacroPart::execute() itemname=" << item->name() << endl;
102 view->loadData();
103 view->execute(sender);
104 view->deleteLater();
105 return true;
106}
107
109{
110 //kdDebug() << "KexiMacroPart::initPartActions()" << endl;
111
112 KoMacro::Manager::init(m_mainWin);
118}
119
121{
122 //kdDebug() << "KexiMacroPart::initInstanceActions()" << endl;
123 //createSharedAction(Kexi::DesignViewMode, i18n("Execute Macro"), "application-x-executable", 0, "data_execute");
124}
125
126KexiViewBase* KexiMacroPart::createView(TQWidget* parent, KexiDialogBase* dialog, KexiPart::Item& item, int viewMode, TQMap<TQString,TQString>*)
127{
128 const TQString itemname = item.name();
129 //kdDebug() << "KexiMacroPart::createView() itemname=" << itemname << endl;
130
131 if(! itemname.isNull()) {
132 TDESharedPtr<KoMacro::Macro> macro = ::KoMacro::Manager::self()->getMacro(itemname);
133 if(! macro) {
134 // If we don't have a macro with that name yet, create one.
135 macro = ::KoMacro::Manager::self()->createMacro(itemname);
136 // and remember the new macro for later usage.
137 ::KoMacro::Manager::self()->addMacro(itemname, macro);
138 }
139
140 KexiMainWindow *win = dialog->mainWin();
141 if(win && win->project() && win->project()->dbConnection()) {
142 if(viewMode == Kexi::DesignViewMode) {
143 return new KexiMacroDesignView(win, parent, macro);
144 }
145 if(viewMode == Kexi::TextViewMode) {
146 return new KexiMacroTextView(win, parent, macro);
147 }
148 if(viewMode == Kexi::DataViewMode) {
149 // Called if the macro should be executed.
150 return new KexiMacroView(win, parent, macro);
151 }
152 }
153 }
154
155 //kdDebug() << "KexiMacroPart::createView() No view available." << endl;
156 return 0;
157}
158
159TQString KexiMacroPart::i18nMessage(const TQCString& englishMessage) const
160{
161 if(englishMessage=="Design of object \"%1\" has been modified.") {
162 return i18n("Design of macro \"%1\" has been modified.");
163 }
164 if(englishMessage=="Object \"%1\" already exists.") {
165 return i18n("Macro \"%1\" already exists.");
166 }
167 return englishMessage;
168}
169
170K_EXPORT_COMPONENT_FACTORY( kexihandler_macro, KGenericFactory<KexiMacroPart>("kexihandler_macro") )
171
172#include "keximacropart.moc"
Base class for child window of Kexi's main application window.
void setId(int id)
The KexiScriptDesignView implements KexiMacroView to provide a GUI-Editor to edit a Macro.
KexiMacroPart(TQObject *parent, const char *name, const TQStringList &args)
Constructor.
virtual bool execute(KexiPart::Item *item, TQObject *sender=0)
Implementation of the KexiPart::Part::action method used to provide scripts as TDEAction's to the out...
virtual ~KexiMacroPart()
Destructor.
virtual KexiViewBase * createView(TQWidget *parent, KexiDialogBase *dialog, KexiPart::Item &item, int viewMode=Kexi::DesignViewMode, TQMap< TQString, TQString > *staticObjectArgs=0)
Create a new view.
virtual void initInstanceActions()
Initialize the instance actions.
virtual void initPartActions()
Initialize the part's actions.
virtual TQString i18nMessage(const TQCString &englishMessage) const
The KexiMacroTextView implements KexiMacroView to provide a simple texteditor to edit the XML documen...
The KexiMacroView implements KexiViewBase to provide a base KexiView instance for Macros.
void execute(TQObject *sender=0)
This slot will be invoked if Kexi's menuitem Data=>Execute got activated and will execute the Macro.
TDESharedPtr< KoMacro::Macro > macro() const
virtual bool loadData()
Load the data from XML source and fill the internally used KoMacro::Macro instance.
The DataTableAction class implements a KoMacro::Action to provide functionality to import or export a...
The ExecuteAction class implements a KoMacro::Action to provide functionality to execute an object li...
The ExecuteObject class implements a KoMacro::Action to provide functionality to execute an object li...
The NavigateAction class implements a KoMacro::Action to provide functionality to execute an object l...
The OpenAction class implements a KoMacro::Action to provide functionality to open any kind of Kexi o...
Definition openaction.h:40
virtual KexiProject * project()=0
Project data of currently opened project or NULL if no project here yet.
Information about a single object that can be instantiated using Kexi Part.
int m_supportedViewModes
Definition kexipart.h:301
int m_registeredPartID
Definition kexipart.h:318
Part(TQObject *parent, const char *name, const TQStringList &)
Definition kexipart.cpp:90
TQMap< TQString, TQString > m_names
Definition kexipart.h:297
KexiDB::Connection * dbConnection() const
Base class for single view embeddable of in KexiDialogBase.
TDESharedPtr< Macro > createMacro(const TQString &macroname)
Factory function to create a new Macro instances.
Definition manager.cpp:126
static void init(KXMLGUIClient *xmlguiclient)
Initialize this Manager singleton.
Definition manager.cpp:65
static Manager * self()
Definition manager.cpp:76
void addMacro(const TQString &macroname, TDESharedPtr< Macro > macro)
Add a new Macro to the list of known macros.
Definition manager.cpp:116
TDESharedPtr< Macro > getMacro(const TQString &macroname)
Definition manager.cpp:111
@ TextViewMode
Also known as SQL View Mode.
Definition kexi.h:48