kexi
keximacropart.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "keximacropart.h"
00019
00020 #include "keximacroview.h"
00021 #include "keximacrodesignview.h"
00022 #include "keximacrotextview.h"
00023
00024
00025
00026
00027
00028 #include <qdom.h>
00029 #include <qstringlist.h>
00030 #include <kgenericfactory.h>
00031 #include <kexipartitem.h>
00032
00033
00034
00035
00036
00037 #include "../lib/manager.h"
00038 #include "../lib/macro.h"
00039 #include "../lib/macroitem.h"
00040 #include "../lib/action.h"
00041
00042 #include "../kexiactions/openaction.h"
00043 #include "../kexiactions/executeaction.h"
00044 #include "../kexiactions/navigateaction.h"
00045 #include "../kexiactions/messageaction.h"
00046 #include "../kexiactions/datatableaction.h"
00047
00052 class KexiMacroPart::Private
00053 {
00054 public:
00055 };
00056
00057 KexiMacroPart::KexiMacroPart(QObject *parent, const char *name, const QStringList &l)
00058 : KexiPart::Part(parent, name, l)
00059 , d( new Private() )
00060 {
00061
00062
00063
00064 m_registeredPartID = (int)KexiPart::MacroObjectType;
00065
00066
00067 m_names["instanceName"]
00068 = i18n("Translate this word using only lowercase alphanumeric characters (a..z, 0..9). "
00069 "Use '_' character instead of spaces. First character should be a..z character. "
00070 "If you cannot use latin characters in your language, use english word.",
00071 "macro");
00072
00073
00074 m_names["instanceCaption"] = i18n("Macro");
00075
00076
00077 m_supportedViewModes = Kexi::DesignViewMode | Kexi::TextViewMode;
00078 }
00079
00080 KexiMacroPart::~KexiMacroPart()
00081 {
00082
00083 delete d;
00084 }
00085
00086 bool KexiMacroPart::execute(KexiPart::Item* item, QObject* sender)
00087 {
00088 KexiDialogBase* dialog = new KexiDialogBase(m_mainWin);
00089 dialog->setId( item->identifier() );
00090 KexiMacroView* view = dynamic_cast<KexiMacroView*>( createView(dialog, dialog, *item, Kexi::DataViewMode) );
00091 if(! view) {
00092 kdWarning() << "KexiMacroPart::execute() Failed to create a view." << endl;
00093 return false;
00094 }
00095
00096 if(! view->macro().data()) {
00097 kdWarning() << "KexiMacroPart::execute() No such item " << item->name() << endl;
00098 return false;
00099 }
00100
00101 kdDebug() << "KexiMacroPart::execute() itemname=" << item->name() << endl;
00102 view->loadData();
00103 view->execute(sender);
00104 view->deleteLater();
00105 return true;
00106 }
00107
00108 void KexiMacroPart::initPartActions()
00109 {
00110
00111
00112 KoMacro::Manager::init(m_mainWin);
00113 new KexiMacro::OpenAction;
00114 new KexiMacro::ExecuteAction;
00115 new KexiMacro::DataTableAction;
00116 new KexiMacro::NavigateAction;
00117 new KexiMacro::MessageAction;
00118 }
00119
00120 void KexiMacroPart::initInstanceActions()
00121 {
00122
00123
00124 }
00125
00126 KexiViewBase* KexiMacroPart::createView(QWidget* parent, KexiDialogBase* dialog, KexiPart::Item& item, int viewMode, QMap<QString,QString>*)
00127 {
00128 const QString itemname = item.name();
00129
00130
00131 if(! itemname.isNull()) {
00132 KSharedPtr<KoMacro::Macro> macro = ::KoMacro::Manager::self()->getMacro(itemname);
00133 if(! macro) {
00134
00135 macro = ::KoMacro::Manager::self()->createMacro(itemname);
00136
00137 ::KoMacro::Manager::self()->addMacro(itemname, macro);
00138 }
00139
00140 KexiMainWindow *win = dialog->mainWin();
00141 if(win && win->project() && win->project()->dbConnection()) {
00142 if(viewMode == Kexi::DesignViewMode) {
00143 return new KexiMacroDesignView(win, parent, macro);
00144 }
00145 if(viewMode == Kexi::TextViewMode) {
00146 return new KexiMacroTextView(win, parent, macro);
00147 }
00148 if(viewMode == Kexi::DataViewMode) {
00149
00150 return new KexiMacroView(win, parent, macro);
00151 }
00152 }
00153 }
00154
00155
00156 return 0;
00157 }
00158
00159 QString KexiMacroPart::i18nMessage(const QCString& englishMessage) const
00160 {
00161 if(englishMessage=="Design of object \"%1\" has been modified.") {
00162 return i18n("Design of macro \"%1\" has been modified.");
00163 }
00164 if(englishMessage=="Object \"%1\" already exists.") {
00165 return i18n("Macro \"%1\" already exists.");
00166 }
00167 return englishMessage;
00168 }
00169
00170 K_EXPORT_COMPONENT_FACTORY( kexihandler_macro, KGenericFactory<KexiMacroPart>("kexihandler_macro") )
00171
00172 #include "keximacropart.moc"
|