1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/* This file is part of the KDE project
Copyright (C) 2004 Lucijan Busch <[email protected]>
Copyright (C) 2004-2006 Jaroslaw Staniek <[email protected]>
This library 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 library 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 library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kexiinternalpart.h"
#include "kexidialogbase.h"
#include "kexiviewbase.h"
#include "keximainwindow.h"
#include <tqasciidict.h>
#include <tqdialog.h>
#include <kdebug.h>
#include <klibloader.h>
#include <tdelocale.h>
#include <ktrader.h>
#include <tdeparts/componentfactory.h>
#include <kexidb/msghandler.h>
//! @internal
class KexiInternalPartManager
{
public:
KexiInternalPartManager()
: m_parts(101, false)
{
m_parts.setAutoDelete(false);
}
KexiInternalPart* findPart(KexiDB::MessageHandler *msgHdr, const char* partName)
{
KexiInternalPart *part = m_parts[partName];
if (!part) {
TQCString fullname("kexihandler_");
fullname += TQCString(partName).lower();
part = KParts::ComponentFactory::createInstanceFromLibrary<KexiInternalPart>(
fullname, 0, fullname);
if (!part) {
if (msgHdr)
msgHdr->showErrorMessage(i18n("Could not load \"%1\" plugin.").arg(partName));
}
else
m_parts.insert(partName, part);
}
return part;
}
private:
TQAsciiDict<KexiInternalPart> m_parts;
};
KexiInternalPartManager internalPartManager;
//----------------------------------------------
KexiInternalPart::KexiInternalPart(TQObject *parent, const char *name, const TQStringList &)
: TQObject(parent, name)
, m_uniqueDialog(true)
, m_cancelled(false)
{
}
KexiInternalPart::~KexiInternalPart()
{
}
//static
const KexiInternalPart *
KexiInternalPart::part(KexiDB::MessageHandler *msgHdr, const char* partName)
{
return internalPartManager.findPart(msgHdr, partName);
}
//static
TQWidget* KexiInternalPart::createWidgetInstance(const char* partName,
const char* widgetClass, KexiDB::MessageHandler *msgHdr, KexiMainWindow* mainWin,
TQWidget *parent, const char *objName, TQMap<TQString,TQString>* args)
{
KexiInternalPart *part = internalPartManager.findPart(msgHdr, partName);
if (!part)
return 0; //fatal!
return part->createWidget(widgetClass, mainWin, parent, objName ? objName : partName, args);
}
KexiDialogBase* KexiInternalPart::findOrCreateKexiDialog(
KexiMainWindow* mainWin, const char *objName)
{
if (m_uniqueDialog && !m_uniqueWidget.isNull())
return dynamic_cast<KexiDialogBase*>((TQWidget*)m_uniqueWidget);
// KexiDialogBase *dlg = createDialog(mainWin, objName);
KexiDialogBase * dlg = new KexiDialogBase(mainWin, "");
KexiViewBase *view = createView(mainWin, 0, objName);
if (!view)
return 0;
// dlg->show();
if (m_uniqueDialog)
m_uniqueWidget = dlg; //recall unique!
dlg->addView(view);
dlg->setCaption( view->caption() );
dlg->setTabCaption( view->caption() );
dlg->resize(view->sizeHint());
dlg->setMinimumSize(view->minimumSizeHint().width(),view->minimumSizeHint().height());
dlg->setId( mainWin->generatePrivateID() );
dlg->registerDialog();
return dlg;
}
//static
KexiDialogBase* KexiInternalPart::createKexiDialogInstance(
const char* partName,
KexiDB::MessageHandler *msgHdr, KexiMainWindow* mainWin, const char *objName)
{
KexiInternalPart *part = internalPartManager.findPart(msgHdr, partName);
if (!part) {
kdDebug() << "KexiInternalPart::createDialogInstance() !part" << endl;
return 0; //fatal!
}
return part->findOrCreateKexiDialog(mainWin, objName ? objName : partName);
}
//static
TQDialog* KexiInternalPart::createModalDialogInstance(const char* partName,
const char* dialogClass, KexiDB::MessageHandler *msgHdr, KexiMainWindow* mainWin,
const char *objName, TQMap<TQString,TQString>* args)
{
KexiInternalPart *part = internalPartManager.findPart(msgHdr, partName);
if (!part) {
kdDebug() << "KexiInternalPart::createDialogInstance() !part" << endl;
return 0; //fatal!
}
TQWidget *w;
if (part->uniqueDialog() && !part->m_uniqueWidget.isNull())
w = part->m_uniqueWidget;
else
w = part->createWidget(dialogClass, mainWin, mainWin, objName ? objName : partName, args);
if (dynamic_cast<TQDialog*>(w)) {
if (part->uniqueDialog())
part->m_uniqueWidget = w;
return dynamic_cast<TQDialog*>(w);
}
//sanity
if (! (part->uniqueDialog() && !part->m_uniqueWidget.isNull()))
delete w;
return 0;
}
//static
bool KexiInternalPart::executeCommand(const char* partName,
KexiMainWindow* mainWin, const char* commandName, TQMap<TQString,TQString>* args)
{
KexiInternalPart *part = internalPartManager.findPart(0, partName);
if (!part) {
kdDebug() << "KexiInternalPart::createDialogInstance() !part" << endl;
return 0; //fatal!
}
return part->executeCommand(mainWin, commandName, args);
}
TQWidget* KexiInternalPart::createWidget(const char* widgetClass, KexiMainWindow* mainWin,
TQWidget * parent, const char * objName, TQMap<TQString,TQString>* args)
{
Q_UNUSED(widgetClass);
Q_UNUSED(mainWin);
Q_UNUSED(parent);
Q_UNUSED(objName);
Q_UNUSED(args);
return 0;
}
KexiViewBase* KexiInternalPart::createView(KexiMainWindow* mainWin, TQWidget * parent,
const char * objName)
{
Q_UNUSED(mainWin);
Q_UNUSED(parent);
Q_UNUSED(objName);
return 0;
}
bool KexiInternalPart::executeCommand(KexiMainWindow* mainWin, const char* commandName,
TQMap<TQString,TQString>* args)
{
Q_UNUSED(mainWin);
Q_UNUSED(commandName);
Q_UNUSED(args);
return false;
}
#include "kexiinternalpart.moc"
|