kexi

objectnamevariable.h

00001 /***************************************************************************
00002  * This file is part of the KDE project
00003  * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
00004  * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
00005  * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this program; see the file COPYING.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  ***************************************************************************/
00020 
00021 #ifndef KEXIMACRO_OBJECTNAMEVARIABLE_H
00022 #define KEXIMACRO_OBJECTNAMEVARIABLE_H
00023 
00024 #include "../lib/variable.h"
00025 
00026 #include "kexivariable.h"
00027 
00028 #include <core/kexi.h>
00029 #include <core/kexiproject.h>
00030 #include <core/kexipartmanager.h>
00031 #include <core/kexipartinfo.h>
00032 
00033 #include <klocale.h>
00034 
00035 namespace KexiMacro {
00036 
00041     template<class ACTIONIMPL>
00042     class ObjectNameVariable : public KexiVariable<ACTIONIMPL>
00043     {
00044         public:
00045             ObjectNameVariable(ACTIONIMPL* actionimpl, const QString& objectname = QString::null, const QString& name = QString::null)
00046                 : KexiVariable<ACTIONIMPL>(actionimpl, "name", i18n("Name"))
00047             {
00048                 if(! actionimpl->mainWin()->project())
00049                     return;
00050 
00051                 QStringList namelist;
00052                 KexiPart::Info* info = Kexi::partManager().infoForMimeType( QString("kexi/%1").arg(objectname) );
00053                 if(info) {
00054                     KexiPart::ItemDict* items = actionimpl->mainWin()->project()->items(info);
00055                     if(items)
00056                         for(KexiPart::ItemDictIterator item_it = *items; item_it.current(); ++item_it)
00057                             namelist << item_it.current()->name();
00058                 }
00059 
00060                 if(namelist.count() <= 0)
00061                     namelist << "";
00062 
00063                 for(QStringList::Iterator it = namelist.begin(); it != namelist.end(); ++it)
00064                     this->appendChild( KSharedPtr<KoMacro::Variable>(new KoMacro::Variable(*it)) );
00065 
00066                 this->setVariant( (name.isNull() || ! namelist.contains(name)) ? namelist[0] : name );
00067 
00068                 kdDebug()<<"##################### KexiActions::ObjectNameVariable() objectname="<<objectname<<" name="<<name<<" value="<<this->variant()<<" children="<<namelist<<endl;
00069             }
00070 
00071             virtual ~ObjectNameVariable() {}
00072     };
00073 
00074 }
00075 
00076 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys