kexi

keximacroerror.cpp

00001 /***************************************************************************
00002  * This file is part of the KDE project
00003  * copyright (C) 2006 by Tobi Krebs (tobi.krebs@gmail.com)
00004  * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
00005  * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
00006  * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this program; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  ***************************************************************************/
00021 
00022 #include "keximacroerror.h"
00023 
00024 #include <core/kexiproject.h>
00025 #include <core/keximainwindow.h>
00026 
00027 #include <qtimer.h>
00028 
00033 class KexiMacroError::Private
00034 {
00035     public:
00036         KexiMainWindow* const mainwin;
00037         KSharedPtr<KoMacro::Context> context;
00038 
00039         Private(KexiMainWindow* const m, KoMacro::Context* const c)
00040             : mainwin(m)
00041             , context(c)
00042         {
00043         }
00044 };
00045 
00046 KexiMacroError::KexiMacroError(KexiMainWindow* mainwin, KSharedPtr<KoMacro::Context> context)
00047     : KexiMacroErrorBase(mainwin, "KexiMacroError" , /*WFlags*/ Qt::WDestructiveClose)
00048     , d(new Private(mainwin, context))
00049 {
00050     //setText(i18n("Execution failed")); //caption
00051     //errortext, errorlist, continuebtn,cancelbtn, designerbtn
00052     
00053     KoMacro::Exception* exception = context->exception();
00054 
00055     iconlbl->setPixmap(KGlobal::instance()->iconLoader()->loadIcon("messagebox_critical", KIcon::Small, 32));
00056     errorlbl->setText(i18n("<qt>Failed to execute the macro \"%1\".<br>%2</qt>").arg( context->macro()->name() ).arg( exception->errorMessage() ));
00057 
00058     int i = 1;
00059     KoMacro::MacroItem::List items = context->macro()->items();
00060     for (KoMacro::MacroItem::List::ConstIterator mit = items.begin(); mit != items.end(); mit++)
00061     {
00062         KListViewItem* listviewitem = new KListViewItem(errorlist);
00063         listviewitem->setText(0,QString("%1").arg(i++));
00064         listviewitem->setText(1,i18n("Action"));
00065         KSharedPtr<KoMacro::MacroItem> macroitem = *mit;
00066 
00067         if (macroitem != 0 && macroitem->action() != 0)
00068         {
00069             listviewitem->setText(2,macroitem->action()->name());
00070         }
00071 
00072         if(macroitem == context->macroItem())
00073         {
00074             listviewitem->setOpen(true);
00075             listviewitem->setSelected(true);
00076             errorlist->setSelected(listviewitem, true);
00077             errorlist->ensureItemVisible(listviewitem);
00078         }
00079         
00080         KoMacro::Variable::Map variables = macroitem->variables();
00081         KoMacro::Variable::Map::ConstIterator vit;
00082         for ( vit = variables.begin(); vit != variables.end(); ++vit ) {
00083             KListViewItem* child = new KListViewItem(listviewitem);
00084             child->setText(1,vit.key());
00085             child->setText(2,vit.data()->toString());
00086         }
00087     }
00088     
00089     connect(designerbtn, SIGNAL(clicked()), this, SLOT(designbtnClicked()));
00090     connect(continuebtn, SIGNAL(clicked()), this, SLOT(continuebtnClicked()));
00091 }
00092 
00093 KexiMacroError::~KexiMacroError()
00094 {
00095     delete d;
00096 }
00097 
00098 void KexiMacroError::designbtnClicked()
00099 {
00100     if(! d->mainwin->project()) {
00101         kdWarning() << QString("KexiMacroError::designbtnClicked(): No project open.") << endl;
00102         return;
00103     }
00104 
00105     // We need to determinate the KexiPart::Item which should be opened.
00106     KSharedPtr<KoMacro::Macro> macro = d->context->macro();
00107     const QString name = macro->name();
00108     KexiPart::Item* item = d->mainwin->project()->itemForMimeType("kexi/macro", name);
00109     if(! item) {
00110         kdWarning() << QString("KexiMacroError::designbtnClicked(): No such macro \"%1\"").arg(name) << endl;
00111         return;
00112     }
00113 
00114     // Try to open the KexiPart::Item now.
00115     bool openingCancelled;
00116     if(! d->mainwin->openObject(item, Kexi::DesignViewMode, openingCancelled)) {
00117         if(! openingCancelled) {
00118             kdWarning() << QString("KexiMacroError::designbtnClicked(): Open macro \"%1\" in designview failed.").arg(name) << endl;
00119             return;
00120         }
00121     }
00122 
00123     close();
00124 }
00125 
00126 void KexiMacroError::continuebtnClicked()
00127 {   
00128     QTimer::singleShot(200, d->context, SLOT(activateNext()));
00129     close();
00130 }
KDE Home | KDE Accessibility Home | Description of Access Keys