kexi

keximacropart.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Sebastian Sauer <mail@dipe.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012    You should have received a copy of the GNU Library General Public License
00013    along with this library; see the file COPYING.LIB.  If not, write to
00014    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00015    Boston, MA 02110-1301, USA.
00016 */
00017 
00018 #include "keximacropart.h"
00019 
00020 #include "keximacroview.h"
00021 #include "keximacrodesignview.h"
00022 #include "keximacrotextview.h"
00023 
00024 //#include "kexiviewbase.h"
00025 //#include "keximainwindow.h"
00026 //#include "kexiproject.h"
00027 
00028 #include <qdom.h>
00029 #include <qstringlist.h>
00030 #include <kgenericfactory.h>
00031 #include <kexipartitem.h>
00032 //#include <kxmlguiclient.h>
00033 //#include <kexidialogbase.h>
00034 //#include <kconfig.h>
00035 //#include <kdebug.h>
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     //kdDebug() << "KexiMacroPart::KexiMacroPart() Ctor" << endl;
00062 
00063     //registered ID
00064     m_registeredPartID = (int)KexiPart::MacroObjectType;
00065 
00066     //name of the instance.
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     //describing caption
00074     m_names["instanceCaption"] = i18n("Macro");
00075 
00076     //supported viewmodes
00077     m_supportedViewModes = Kexi::DesignViewMode | Kexi::TextViewMode;
00078 }
00079 
00080 KexiMacroPart::~KexiMacroPart()
00081 {
00082     //kdDebug() << "KexiMacroPart::~KexiMacroPart() Dtor" << endl;
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     //kdDebug() << "KexiMacroPart::initPartActions()" << endl;
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     //kdDebug() << "KexiMacroPart::initInstanceActions()" << endl;
00123     //createSharedAction(Kexi::DesignViewMode, i18n("Execute Macro"), "exec", 0, "data_execute");
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     //kdDebug() << "KexiMacroPart::createView() itemname=" << itemname << endl;
00130 
00131     if(! itemname.isNull()) {
00132         KSharedPtr<KoMacro::Macro> macro = ::KoMacro::Manager::self()->getMacro(itemname);
00133         if(! macro) {
00134             // If we don't have a macro with that name yet, create one.
00135             macro = ::KoMacro::Manager::self()->createMacro(itemname);
00136             // and remember the new macro for later usage.
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                 // Called if the macro should be executed.
00150                 return new KexiMacroView(win, parent, macro);
00151             }
00152         }
00153     }
00154 
00155     //kdDebug() << "KexiMacroPart::createView() No view available." << endl;
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"
KDE Home | KDE Accessibility Home | Description of Access Keys