kexiformeventhandler.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexiformeventhandler.h"
21
22#include <tqwidget.h>
23#include <tqobjectlist.h>
24
25#include <kdebug.h>
26#include <tdelocale.h>
27
28#include <tableview/kexitableitem.h>
29#include <tableview/kexitableviewdata.h>
30#include <kexidb/queryschema.h>
31#include <keximainwindow.h>
32#include <kexidialogbase.h>
33#include <kexipart.h>
34#include <kexipartinfo.h>
35#include <kexipartitem.h>
36
37KexiFormEventAction::ActionData::ActionData()
38{
39}
40
42{
43 return string.isEmpty();
44}
45
47 TQString& actionType, TQString& actionArg, bool& ok) const
48{
49 const int idx = string.find(':');
50 ok = false;
51 if (idx==-1)
52 return 0;
53 const TQString _actionType = string.left(idx);
54 const TQString _actionArg = string.mid(idx+1);
55 if (_actionType.isEmpty() || _actionArg.isEmpty())
56 return 0;
57 KexiPart::Info *info = 0;
58 if (_actionType!="tdeaction" && _actionType!="currentForm") {
59 info = Kexi::partManager().infoForMimeType( TQString("kexi/%1").arg(_actionType) );
60 if (!info)
61 return 0;
62 }
63 actionType = _actionType;
64 actionArg = _actionArg;
65 ok = true;
66 return info;
67}
68
69//-------------------------------------
70
71KexiFormEventAction::KexiFormEventAction(KexiMainWindow *mainWin, TQObject* parent,
72 const TQString& actionName, const TQString& objectName, const TQString& actionOption)
73 : TDEAction(parent), m_mainWin(mainWin), m_actionName(actionName), m_objectName(objectName)
74 , m_actionOption(actionOption)
75{
76}
77
78KexiFormEventAction::~KexiFormEventAction()
79{
80}
81
82void KexiFormEventAction::activate()
83{
84 KexiProject* project = m_mainWin->project();
85 if (!project)
86 return;
88 TQString("kexi/%1").arg(m_actionName) );
89 if (!part)
90 return;
91 KexiPart::Item* item = project->item( part->info(), m_objectName );
92 if (!item)
93 return;
94 bool actionCancelled = false;
95 if (m_actionOption.isEmpty()) { // backward compatibility (good defaults)
96 if (part->info()->isExecuteSupported())
97 part->execute(item, parent());
98 else
99 m_mainWin->openObject(item, Kexi::DataViewMode, actionCancelled);
100 }
101 else {
103 if (m_actionOption == "open")
104 m_mainWin->openObject(item, Kexi::DataViewMode, actionCancelled);
105 else if (m_actionOption == "execute")
106 part->execute(item, parent());
107 else if (m_actionOption == "print") {
108 if (part->info()->isPrintingSupported())
109 m_mainWin->printItem(item);
110 }
111 else if (m_actionOption == "printPreview") {
112 if (part->info()->isPrintingSupported())
113 m_mainWin->printPreviewForItem(item);
114 }
115 else if (m_actionOption == "pageSetup") {
116 if (part->info()->isPrintingSupported())
117 m_mainWin->showPageSetupForItem(item);
118 }
119 else if (m_actionOption == "exportToCSV"
120 || m_actionOption == "copyToClipboardAsCSV")
121 {
122 if (part->info()->isDataExportSupported())
123 m_mainWin->executeCustomActionForObject(item, m_actionOption);
124 }
125 else if (m_actionOption == "new")
126 m_mainWin->newObject( part->info(), actionCancelled );
127 else if (m_actionOption == "design")
128 m_mainWin->openObject(item, Kexi::DesignViewMode, actionCancelled);
129 else if (m_actionOption == "editText")
130 m_mainWin->openObject(item, Kexi::TextViewMode, actionCancelled);
131 else if (m_actionOption == "close") {
132 tristate res = m_mainWin->closeObject(item);
133 if (~res)
134 actionCancelled = true;
135 }
136 }
137}
138
139//------------------------------------------
140
141KexiFormEventHandler::KexiFormEventHandler()
142 : m_mainWidget(0)
143{
144}
145
146KexiFormEventHandler::~KexiFormEventHandler()
147{
148}
149
151{
152 m_mainWidget = mainWidget;
153 if (!m_mainWidget)
154 return;
155
156 //find widgets whose will work as data items
158 TQObjectList *l = m_mainWidget->queryList( "KexiPushButton" );
159 TQObjectListIt it( *l );
160 TQObject *obj;
161 for ( ; (obj = it.current()) != 0; ++it ) {
162 bool ok;
164 data.string = obj->property("onClickAction").toString();
165 data.option = obj->property("onClickActionOption").toString();
166 if (data.isEmpty())
167 continue;
168
169 TQString actionType, actionArg;
170 KexiPart::Info* partInfo = data.decodeString(actionType, actionArg, ok);
171 if (!ok)
172 continue;
173 if (actionType=="tdeaction" || actionType=="currentForm") {
174 TDEAction *action = mainWin->actionCollection()->action( actionArg.latin1() );
175 if (!action)
176 continue;
177 TQObject::disconnect( obj, TQ_SIGNAL(clicked()), action, TQ_SLOT(activate()) ); //safety
178 TQObject::connect( obj, TQ_SIGNAL(clicked()), action, TQ_SLOT(activate()) );
179 }
180 else if (partInfo) { //'open or execute' action
181 KexiFormEventAction* action = new KexiFormEventAction(mainWin, obj, actionType, actionArg,
182 data.option);
183 TQObject::disconnect( obj, TQ_SIGNAL(clicked()), action, TQ_SLOT(activate()) );
184 TQObject::connect( obj, TQ_SIGNAL(clicked()), action, TQ_SLOT(activate()) );
185 }
186 }
187 delete l;
188}
A structure used in currentActionName()
KexiPart::Info * decodeString(TQString &actionType, TQString &actionArg, bool &ok) const
TQString option
option used when name is "table/query/etc.:<objectName>" is set;
TQString string
action string with prefix, like "tdeaction:edit_copy" or "table:<tableName>"
void setMainWidgetForEventHandling(KexiMainWindow *mainWin, TQWidget *mainWidget)
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
Information about a Kexi Part (plugin).
bool isDataExportSupported() const
bool isPrintingSupported() const
bool isExecuteSupported() const
Information about a single object that can be instantiated using Kexi Part.
Part * partForMimeType(const TQString &mimeTypt)
Info * infoForMimeType(const TQString &mimeType)
The main class for kexi frontend parts like tables, queries, forms and reports.
Definition kexipart.h:66
virtual bool execute(KexiPart::Item *item, TQObject *sender=0)
Definition kexipart.h:85
A project's main controller.
Definition kexiproject.h:68
KexiPart::Item * item(KexiPart::Info *i, const TQString &name)
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition tristate.h:100
KEXICORE_EXPORT KexiPart::Manager & partManager()
shared part manager
Definition kexi.cpp:97
@ TextViewMode
Also known as SQL View Mode.
Definition kexi.h:48