kexi
datatableaction.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "datatableaction.h"
00020
00021
00022 #include <core/kexi.h>
00023 #include <core/kexiproject.h>
00024 #include <core/kexipartmanager.h>
00025 #include <core/kexipartinfo.h>
00026 #include <core/kexipart.h>
00027 #include <core/keximainwindow.h>
00028 #include <core/kexiinternalpart.h>
00029
00030 #include <klocale.h>
00031
00032 using namespace KexiMacro;
00033
00034 namespace KexiMacro {
00035
00036
00037
00038
00039
00040 template<class ACTIONIMPL>
00041 class MethodVariable : public KexiVariable<ACTIONIMPL>
00042 {
00043 public:
00044 MethodVariable(ACTIONIMPL* actionimpl)
00045 : KexiVariable<ACTIONIMPL>(actionimpl, "method", i18n("Method"))
00046 {
00047 QStringList list;
00048 list << "import" << "export";
00049 this->appendChild( KSharedPtr<KoMacro::Variable>( new KoMacro::Variable(list, "@list") ) );
00050
00051 this->setVariant( list[0] );
00052 }
00053 };
00054
00055 template<class ACTIONIMPL>
00056 class TypeVariable : public KexiVariable<ACTIONIMPL>
00057 {
00058 public:
00059 TypeVariable(ACTIONIMPL* actionimpl)
00060 : KexiVariable<ACTIONIMPL>(actionimpl, "type", i18n("Type"))
00061 {
00062 QStringList list;
00063 list << "file" << "clipboard";
00064 this->appendChild( KSharedPtr<KoMacro::Variable>( new KoMacro::Variable(list, "@list") ) );
00065
00066 this->setVariant( list[0] );
00067 }
00068 };
00069
00070 template<class ACTIONIMPL>
00071 class PartItemVariable : public KexiVariable<ACTIONIMPL>
00072 {
00073 public:
00074 PartItemVariable(ACTIONIMPL* actionimpl, const QString& partitem = QString::null)
00075 : KexiVariable<ACTIONIMPL>(actionimpl, "partitem", i18n("Item"))
00076 {
00077 QStringList namelist;
00078 if(actionimpl->mainWin()->project()) {
00079 KexiPart::PartInfoList* parts = Kexi::partManager().partInfoList();
00080 for(KexiPart::PartInfoListIterator it(*parts); it.current(); ++it) {
00081 KexiPart::Info* info = it.current();
00082 if(! info->isDataExportSupported())
00083 continue;
00084 KexiPart::ItemDict* items = actionimpl->mainWin()->project()->items(info);
00085 if(items)
00086 for(KexiPart::ItemDictIterator item_it = *items; item_it.current(); ++item_it)
00087 namelist << info->objectName() + "." + item_it.current()->name();
00088 }
00089 for(QStringList::Iterator it = namelist.begin(); it != namelist.end(); ++it)
00090 this->appendChild( KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(*it)) );
00091
00092
00093
00094 }
00095 const QString n =
00096 namelist.contains(partitem)
00097 ? partitem
00098 : namelist.count() > 0 ? namelist[0] : "";
00099 this->setVariant(n);
00100 kdDebug()<<"##################### KexiActions::ObjectVariable() variant="<<this->variant()<<endl;
00101 }
00102 };
00103
00104 }
00105
00106 DataTableAction::DataTableAction()
00107 : KexiAction("datatable", i18n("Data Table"))
00108 {
00109 setVariable(KSharedPtr<KoMacro::Variable>( new MethodVariable<DataTableAction>(this) ));
00110 setVariable(KSharedPtr<KoMacro::Variable>( new TypeVariable<DataTableAction>(this) ));
00111 setVariable(KSharedPtr<KoMacro::Variable>( new PartItemVariable<DataTableAction>(this) ));
00112 }
00113
00114 DataTableAction::~DataTableAction()
00115 {
00116 }
00117
00118 bool DataTableAction::notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name)
00119 {
00120 kdDebug()<<"DataTableAction::notifyUpdated() name="<<name<<" macroitem.action="<<(macroitem->action() ? macroitem->action()->name() : "NOACTION")<<endl;
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 return true;
00135 }
00136
00137 void DataTableAction::activate(KSharedPtr<KoMacro::Context> context)
00138 {
00139 if(! mainWin()->project()) {
00140 kdWarning() << "ExecuteAction::activate(KSharedPtr<KoMacro::Context>) Invalid project" << endl;
00141 return;
00142 }
00143
00144 const QString method = context->variable("method")->variant().toString();
00145 const QString type = context->variable("type")->variant().toString();
00146
00147 const QString partitem = context->variable("partitem")->variant().toString();
00148 QString identifier;
00149 if(! partitem.isEmpty()) {
00150 QStringList parts = QStringList::split(".", partitem);
00151 KexiPart::Part* part = Kexi::partManager().partForMimeType( QString("kexi/%1").arg(parts[0]) );
00152 KexiPart::Item* item = part ? mainWin()->project()->item(part->info(), parts[1]) : 0;
00153 if(! item)
00154 throw KoMacro::Exception(i18n("No such item \"%1\"").arg(partitem));
00155 identifier = QString::number(item->identifier());
00156 }
00157
00158 QMap<QString,QString> args;
00159 if(! identifier.isNull())
00160 args.insert("itemId", identifier);
00161
00162 if(method == "import") {
00163 args.insert("sourceType", type);
00164 QDialog *dlg = KexiInternalPart::createModalDialogInstance(
00165 "csv_importexport", "KexiCSVImportDialog", 0, mainWin(), 0, &args);
00166 if (!dlg)
00167 return;
00168 dlg->exec();
00169 delete dlg;
00170 }
00171 else if(method == "export") {
00172 args.insert("destinationType", type);
00173 QDialog *dlg = KexiInternalPart::createModalDialogInstance(
00174 "csv_importexport", "KexiCSVExportWizard", 0, mainWin(), 0, &args);
00175 if (!dlg)
00176 return;
00177 dlg->exec();
00178 delete dlg;
00179 }
00180 else {
00181 throw KoMacro::Exception(i18n("No such method \"%1\"").arg(method));
00182 }
00183 }
00184
00185
|