kexi

kexiinternalpart.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Lucijan Busch <lucijan@kde.org>
3 Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "kexiinternalpart.h"
22
23#include "kexidialogbase.h"
24#include "kexiviewbase.h"
25#include "keximainwindow.h"
26
27#include <tqasciidict.h>
28#include <tqdialog.h>
29
30#include <kdebug.h>
31#include <klibloader.h>
32#include <tdelocale.h>
33#include <ktrader.h>
34#include <tdeparts/componentfactory.h>
35#include <kexidb/msghandler.h>
36
38class KexiInternalPartManager
39{
40 public:
41 KexiInternalPartManager()
42 : m_parts(101, false)
43 {
44 m_parts.setAutoDelete(false);
45 }
46
47 KexiInternalPart* findPart(KexiDB::MessageHandler *msgHdr, const char* partName)
48 {
49 KexiInternalPart *part = m_parts[partName];
50 if (!part) {
51 TQCString fullname("kexihandler_");
52 fullname += TQCString(partName).lower();
53 part = KParts::ComponentFactory::createInstanceFromLibrary<KexiInternalPart>(
54 fullname, 0, fullname);
55 if (!part) {
56 if (msgHdr)
57 msgHdr->showErrorMessage(i18n("Could not load \"%1\" plugin.").arg(partName));
58 }
59 else
60 m_parts.insert(partName, part);
61 }
62 return part;
63 }
64
65 private:
66
67 TQAsciiDict<KexiInternalPart> m_parts;
68};
69
70KexiInternalPartManager internalPartManager;
71
72//----------------------------------------------
73
74KexiInternalPart::KexiInternalPart(TQObject *parent, const char *name, const TQStringList &)
75 : TQObject(parent, name)
76 , m_uniqueDialog(true)
77 , m_cancelled(false)
78{
79}
80
81KexiInternalPart::~KexiInternalPart()
82{
83}
84
85//static
86const KexiInternalPart *
87KexiInternalPart::part(KexiDB::MessageHandler *msgHdr, const char* partName)
88{
89 return internalPartManager.findPart(msgHdr, partName);
90}
91
92//static
93TQWidget* KexiInternalPart::createWidgetInstance(const char* partName,
94 const char* widgetClass, KexiDB::MessageHandler *msgHdr, KexiMainWindow* mainWin,
95 TQWidget *parent, const char *objName, TQMap<TQString,TQString>* args)
96{
97 KexiInternalPart *part = internalPartManager.findPart(msgHdr, partName);
98 if (!part)
99 return 0; //fatal!
100 return part->createWidget(widgetClass, mainWin, parent, objName ? objName : partName, args);
101}
102
104 KexiMainWindow* mainWin, const char *objName)
105{
106 if (m_uniqueDialog && !m_uniqueWidget.isNull())
107 return dynamic_cast<KexiDialogBase*>((TQWidget*)m_uniqueWidget);
108// KexiDialogBase *dlg = createDialog(mainWin, objName);
109 KexiDialogBase * dlg = new KexiDialogBase(mainWin, "");
110 KexiViewBase *view = createView(mainWin, 0, objName);
111 if (!view)
112 return 0;
113
114// dlg->show();
115
116 if (m_uniqueDialog)
117 m_uniqueWidget = dlg; //recall unique!
118 dlg->addView(view);
119 dlg->setCaption( view->caption() );
120 dlg->setTabCaption( view->caption() );
121 dlg->resize(view->sizeHint());
122 dlg->setMinimumSize(view->minimumSizeHint().width(),view->minimumSizeHint().height());
123 dlg->setId( mainWin->generatePrivateID() );
124 dlg->registerDialog();
125 return dlg;
126}
127
128//static
130 const char* partName,
131 KexiDB::MessageHandler *msgHdr, KexiMainWindow* mainWin, const char *objName)
132{
133 KexiInternalPart *part = internalPartManager.findPart(msgHdr, partName);
134 if (!part) {
135 kdDebug() << "KexiInternalPart::createDialogInstance() !part" << endl;
136 return 0; //fatal!
137 }
138 return part->findOrCreateKexiDialog(mainWin, objName ? objName : partName);
139}
140
141//static
142TQDialog* KexiInternalPart::createModalDialogInstance(const char* partName,
143 const char* dialogClass, KexiDB::MessageHandler *msgHdr, KexiMainWindow* mainWin,
144 const char *objName, TQMap<TQString,TQString>* args)
145{
146 KexiInternalPart *part = internalPartManager.findPart(msgHdr, partName);
147 if (!part) {
148 kdDebug() << "KexiInternalPart::createDialogInstance() !part" << endl;
149 return 0; //fatal!
150 }
151 TQWidget *w;
152 if (part->uniqueDialog() && !part->m_uniqueWidget.isNull())
153 w = part->m_uniqueWidget;
154 else
155 w = part->createWidget(dialogClass, mainWin, mainWin, objName ? objName : partName, args);
156
157 if (dynamic_cast<TQDialog*>(w)) {
158 if (part->uniqueDialog())
159 part->m_uniqueWidget = w;
160 return dynamic_cast<TQDialog*>(w);
161 }
162 //sanity
163 if (! (part->uniqueDialog() && !part->m_uniqueWidget.isNull()))
164 delete w;
165 return 0;
166}
167
168//static
169bool KexiInternalPart::executeCommand(const char* partName,
170 KexiMainWindow* mainWin, const char* commandName, TQMap<TQString,TQString>* args)
171{
172 KexiInternalPart *part = internalPartManager.findPart(0, partName);
173 if (!part) {
174 kdDebug() << "KexiInternalPart::createDialogInstance() !part" << endl;
175 return 0; //fatal!
176 }
177 return part->executeCommand(mainWin, commandName, args);
178}
179
180TQWidget* KexiInternalPart::createWidget(const char* widgetClass, KexiMainWindow* mainWin,
181 TQWidget * parent, const char * objName, TQMap<TQString,TQString>* args)
182{
183 Q_UNUSED(widgetClass);
184 Q_UNUSED(mainWin);
185 Q_UNUSED(parent);
186 Q_UNUSED(objName);
187 Q_UNUSED(args);
188 return 0;
189}
190
192 const char * objName)
193{
194 Q_UNUSED(mainWin);
195 Q_UNUSED(parent);
196 Q_UNUSED(objName);
197 return 0;
198}
199
200bool KexiInternalPart::executeCommand(KexiMainWindow* mainWin, const char* commandName,
201 TQMap<TQString,TQString>* args)
202{
203 Q_UNUSED(mainWin);
204 Q_UNUSED(commandName);
205 Q_UNUSED(args);
206 return false;
207}
208
209#include "kexiinternalpart.moc"
virtual void showErrorMessage(const TQString &title, const TQString &details=TQString())=0
Base class for child window of Kexi's main application window.
void setId(int id)
void addView(KexiViewBase *view)
Adds view for the dialog. It will be the only view (of unspecified mode) for the dialog.
A prototype for Kexi Internal Parts (plugins) implementation.
static const KexiInternalPart * part(KexiDB::MessageHandler *msgHdr, const char *partName)
bool uniqueDialog() const
static TQWidget * createWidgetInstance(const char *partName, const char *widgetClass, KexiDB::MessageHandler *msgHdr, KexiMainWindow *mainWin, TQWidget *parent, const char *objName=0, TQMap< TQString, TQString > *args=0)
virtual KexiViewBase * createView(KexiMainWindow *mainWin, TQWidget *parent, const char *objName=0)
TQGuardedPtr< TQWidget > m_uniqueWidget
Unique dialog - we're using guarded ptr for the dialog so can know if it has been closed.
virtual TQWidget * createWidget(const char *widgetClass, KexiMainWindow *mainWin, TQWidget *parent, const char *objName=0, TQMap< TQString, TQString > *args=0)
bool m_uniqueDialog
true if createDialogInstance() should return only one dialog
static bool executeCommand(const char *partName, KexiMainWindow *mainWin, const char *commandName, TQMap< TQString, TQString > *args=0)
static KexiDialogBase * createKexiDialogInstance(const char *partName, KexiDB::MessageHandler *msgHdr, KexiMainWindow *mainWin, const char *objName=0)
static TQDialog * createModalDialogInstance(const char *partName, const char *dialogClass, KexiDB::MessageHandler *msgHdr, KexiMainWindow *mainWin, const char *objName=0, TQMap< TQString, TQString > *args=0)
KexiDialogBase * findOrCreateKexiDialog(KexiMainWindow *mainWin, const char *objName)
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
virtual int generatePrivateID()=0
Base class for single view embeddable of in KexiDialogBase.