keximacroerror.cpp
1/***************************************************************************
2 * This file is part of the KDE project
3 * copyright (C) 2006 by Tobi Krebs (tobi.krebs@gmail.com)
4 * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
5 * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
6 * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 ***************************************************************************/
21
22#include "keximacroerror.h"
23
24#include <core/kexiproject.h>
25#include <core/keximainwindow.h>
26
27#include <tqtimer.h>
28
33class KexiMacroError::Private
34{
35 public:
36 KexiMainWindow* const mainwin;
37 TDESharedPtr<KoMacro::Context> context;
38
39 Private(KexiMainWindow* const m, KoMacro::Context* const c)
40 : mainwin(m)
41 , context(c)
42 {
43 }
44};
45
46KexiMacroError::KexiMacroError(KexiMainWindow* mainwin, TDESharedPtr<KoMacro::Context> context)
47 : KexiMacroErrorBase(mainwin, "KexiMacroError" , /*WFlags*/ TQt::WDestructiveClose)
48 , d(new Private(mainwin, context))
49{
50 //setText(i18n("Execution failed")); //caption
51 //errortext, errorlist, continuebtn,cancelbtn, designerbtn
52
53 KoMacro::Exception* exception = context->exception();
54
55 iconlbl->setPixmap(TDEGlobal::instance()->iconLoader()->loadIcon("messagebox_critical", TDEIcon::Small, 32));
56 errorlbl->setText(i18n("<qt>Failed to execute the macro \"%1\".<br>%2</qt>").arg( context->macro()->name() ).arg( exception->errorMessage() ));
57
58 int i = 1;
59 KoMacro::MacroItem::List items = context->macro()->items();
60 for (KoMacro::MacroItem::List::ConstIterator mit = items.begin(); mit != items.end(); mit++)
61 {
62 TDEListViewItem* listviewitem = new TDEListViewItem(errorlist);
63 listviewitem->setText(0,TQString("%1").arg(i++));
64 listviewitem->setText(1,i18n("Action"));
65 TDESharedPtr<KoMacro::MacroItem> macroitem = *mit;
66
67 if (macroitem != 0 && macroitem->action() != 0)
68 {
69 listviewitem->setText(2,macroitem->action()->name());
70 }
71
72 if(macroitem == context->macroItem())
73 {
74 listviewitem->setOpen(true);
75 listviewitem->setSelected(true);
76 errorlist->setSelected(listviewitem, true);
77 errorlist->ensureItemVisible(listviewitem);
78 }
79
80 KoMacro::Variable::Map variables = macroitem->variables();
81 KoMacro::Variable::Map::ConstIterator vit;
82 for ( vit = variables.begin(); vit != variables.end(); ++vit ) {
83 TDEListViewItem* child = new TDEListViewItem(listviewitem);
84 child->setText(1,vit.key());
85 child->setText(2,vit.data()->toString());
86 }
87 }
88
89 connect(designerbtn, TQ_SIGNAL(clicked()), this, TQ_SLOT(designbtnClicked()));
90 connect(continuebtn, TQ_SIGNAL(clicked()), this, TQ_SLOT(continuebtnClicked()));
91}
92
94{
95 delete d;
96}
97
98void KexiMacroError::designbtnClicked()
99{
100 if(! d->mainwin->project()) {
101 kdWarning() << TQString("KexiMacroError::designbtnClicked(): No project open.") << endl;
102 return;
103 }
104
105 // We need to determinate the KexiPart::Item which should be opened.
106 TDESharedPtr<KoMacro::Macro> macro = d->context->macro();
107 const TQString name = macro->name();
108 KexiPart::Item* item = d->mainwin->project()->itemForMimeType("kexi/macro", name);
109 if(! item) {
110 kdWarning() << TQString("KexiMacroError::designbtnClicked(): No such macro \"%1\"").arg(name) << endl;
111 return;
112 }
113
114 // Try to open the KexiPart::Item now.
115 bool openingCancelled;
116 if(! d->mainwin->openObject(item, Kexi::DesignViewMode, openingCancelled)) {
117 if(! openingCancelled) {
118 kdWarning() << TQString("KexiMacroError::designbtnClicked(): Open macro \"%1\" in designview failed.").arg(name) << endl;
119 return;
120 }
121 }
122
123 close();
124}
125
126void KexiMacroError::continuebtnClicked()
127{
128 TQTimer::singleShot(200, d->context, TQ_SLOT(activateNext()));
129 close();
130}
KexiMacroError(KexiMainWindow *mainwin, TDESharedPtr< KoMacro::Context > context)
Constructor.
virtual ~KexiMacroError()
Destructor.
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
Information about a single object that can be instantiated using Kexi Part.
The context of an execution.
Definition context.h:44
Base Exception class.
Definition exception.h:35
const TQString errorMessage() const
Definition exception.cpp:76
TQValueList< TDESharedPtr< MacroItem > > List
A list of MacroItem instances.
Definition macroitem.h:54
TQMap< TQString, TDESharedPtr< Variable > > Map
A map of variables.
Definition variable.h:66