/*************************************************************************** * This file is part of the KDE project * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org) * * 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 #include #include #include #include #include #include #include using namespace KexiMacro; namespace KexiMacro { //static const TQString OBJECT = "method"; //static const TQString OBJECT = "type"; //static const TQString OBJECT = "partitem"; template class MethodVariable : public KexiVariable { public: MethodVariable(ACTIONIMPL* actionimpl) : KexiVariable(actionimpl, "method", i18n("Method")) { TQStringList list; list << "import" << "export"; this->appendChild( KSharedPtr( new KoMacro::Variable(list, "@list") ) ); this->setVariant( list[0] ); } }; template class TypeVariable : public KexiVariable { public: TypeVariable(ACTIONIMPL* actionimpl) : KexiVariable(actionimpl, "type", i18n("Type")) { TQStringList list; list << "file" << "clipboard"; this->appendChild( KSharedPtr( new KoMacro::Variable(list, "@list") ) ); this->setVariant( list[0] ); } }; template class PartItemVariable : public KexiVariable { public: PartItemVariable(ACTIONIMPL* actionimpl, const TQString& partitem = TQString()) : KexiVariable(actionimpl, "partitem", i18n("Item")) { TQStringList 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(TQStringList::Iterator it = namelist.begin(); it != namelist.end(); ++it) this->appendChild( KSharedPtr(new KoMacro::Variable(*it)) ); //const TQString name = info->objectName(); //info->groupName(); //this->appendChild( KSharedPtr(new KoMacro::Variable(name)) ); } const TQString n = namelist.contains(partitem) ? partitem : namelist.count() > 0 ? namelist[0] : ""; this->setVariant(n); kdDebug()<<"##################### KexiActions::ObjectVariable() variant="<variant()<( new MethodVariable(this) )); setVariable(KSharedPtr( new TypeVariable(this) )); setVariable(KSharedPtr( new PartItemVariable(this) )); } DataTableAction::~DataTableAction() { } bool DataTableAction::notifyUpdated(KSharedPtr macroitem, const TQString& name) { kdDebug()<<"DataTableAction::notifyUpdated() name="< variable = macroitem->variable(name, false); if(! variable) { kdWarning()<<"DataTableAction::notifyUpdated() No such variable="<clearChildren(); if(name == "method") { const int partitem = macroitem->variant(OBJECT, true).toString(); macroitem->variable(OBJECT, true)->setChildren( KoMacro::Variable::List() << KSharedPtr(new ObjectVariable(this, partitem)) ); } */ return true; } void DataTableAction::activate(KSharedPtr context) { if(! mainWin()->project()) { kdWarning() << "ExecuteAction::activate(KSharedPtr) Invalid project" << endl; return; } const TQString method = context->variable("method")->variant().toString(); const TQString type = context->variable("type")->variant().toString(); const TQString partitem = context->variable("partitem")->variant().toString(); TQString identifier; if(! partitem.isEmpty()) { TQStringList parts = TQStringList::split(".", partitem); KexiPart::Part* part = Kexi::partManager().partForMimeType( TQString("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 = TQString::number(item->identifier()); } TQMap args; if(! identifier.isNull()) args.insert("itemId", identifier); if(method == "import") { args.insert("sourceType", type); TQDialog *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); TQDialog *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"