1
/* This file is part of the KDE project
2
Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
3
Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org>
4
Copyright (C) 2004-2010 JarosÅaw Staniek <staniek@kde.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
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 library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
22
#include "kexitablepart.h"
24
#include <core/KexiMainWindowIface.h>
25
#include <core/kexiproject.h>
26
#include <core/kexipartinfo.h>
27
#include <widget/tableview/KexiDataTableView.h>
28
#include <widget/tableview/KexiDataTableScrollArea.h>
29
#include "kexitabledesignerview.h"
30
#include "kexitabledesigner_dataview.h"
31
#include "kexilookupcolumnpage.h"
32
#include <KexiWindow.h>
34
#include <KDbConnection>
36
#include <KMessageBox>
41
KEXI_PLUGIN_FACTORY(KexiTablePart, "kexi_tableplugin.json")
44
class KexiTablePart::Private
50
delete static_cast<KexiLookupColumnPage*>(lookupColumnPage);
52
QPointer<KexiLookupColumnPage> lookupColumnPage;
55
KexiTablePart::KexiTablePart(QObject *parent, const QVariantList& l)
56
: KexiPart::Part(parent,
57
xi18nc("Translate this word using only lowercase alphanumeric characters (a..z, 0..9). "
58
"Use '_' character instead of spaces. First character should be a..z character. "
59
"If you cannot use latin characters in your language, use english word.",
61
xi18nc("tooltip", "Create new table"),
62
xi18nc("what's this", "Creates new table."),
66
//! @todo js: also add Kexi::TextViewMode when we'll have SQL ALTER TABLE EDITOR!!!
69
KexiTablePart::~KexiTablePart()
74
void KexiTablePart::initPartActions()
78
void KexiTablePart::initInstanceActions()
82
KexiWindowData* KexiTablePart::createWindowData(KexiWindow* window)
84
return new KexiTablePartTempData(window);
87
KexiView* KexiTablePart::createView(QWidget *parent, KexiWindow* window,
88
KexiPart::Item *item, Kexi::ViewMode viewMode, QMap<QString, QVariant>*)
91
KexiMainWindowIface *win = KexiMainWindowIface::global();
92
if (!win || !win->project() || !win->project()->dbConnection())
96
KexiTablePartTempData *temp
97
= static_cast<KexiTablePartTempData*>(window->data());
99
temp->table = win->project()->dbConnection()->tableSchema(item->name());
100
qDebug() << "schema is " << temp->table;
103
if (viewMode == Kexi::DesignViewMode) {
104
KexiTableDesignerView *t = new KexiTableDesignerView(parent);
106
} else if (viewMode == Kexi::DataViewMode) {
108
return 0; //!< @todo message
110
//we're not setting table schema here -it will be forced to set
111
// in KexiTableDesigner_DataView::afterSwitchFrom()
112
KexiTableDesigner_DataView *t = new KexiTableDesigner_DataView(parent);
118
tristate KexiTablePart::remove(KexiPart::Item *item)
120
KexiProject *project = KexiMainWindowIface::global()->project();
121
if (!project || !project->dbConnection())
124
KDbConnection *conn = project->dbConnection();
125
KDbTableSchema *sch = conn->tableSchema(item->identifier());
128
tristate res = KexiTablePart::askForClosingObjectsUsingTableSchema(
129
KexiMainWindowIface::global()->thisWidget(), conn, sch,
130
xi18n("You are about to remove table <resource>%1</resource> but following objects using this table are opened:",
135
return conn->dropTable(sch);
137
//last chance: just remove item
138
return conn->removeObject(item->identifier());
141
tristate KexiTablePart::rename(KexiPart::Item *item, const QString& newName)
144
KDbConnection *conn = KexiMainWindowIface::global()->project()->dbConnection();
145
KDbTableSchema *schema = conn->tableSchema(item->identifier());
148
tristate res = KexiTablePart::askForClosingObjectsUsingTableSchema(
149
KexiMainWindowIface::global()->thisWidget(), conn, schema,
150
xi18n("You are about to rename table <resource>%1</resource> but following objects using this table are opened:",
155
return conn->alterTableName(schema, newName);
158
KDbObject* KexiTablePart::loadSchemaObject(KexiWindow *window, const KDbObject& object,
159
Kexi::ViewMode viewMode, bool *ownedByWindow)
164
*ownedByWindow = false;
165
return KexiMainWindowIface::global()->project()->dbConnection()->tableSchema(object.name());
169
tristate KexiTablePart::askForClosingObjectsUsingTableSchema(
170
QWidget *parent, KDbConnection *conn,
171
KDbTableSchema *table, const QString& msg)
175
QSet<KDbConnection::TableSchemaChangeListenerInterface*>* listeners
176
= conn->tableSchemaChangeListeners(table);
177
if (!listeners || listeners->isEmpty())
180
QString openedObjectsStr = "<list>";
181
foreach(KDbConnection::TableSchemaChangeListenerInterface* iface, *listeners) {
182
openedObjectsStr += QString("<item>%1</item>").arg(iface->listenerInfoString);
184
openedObjectsStr += "</list>";
185
int r = KMessageBox::questionYesNo(parent,
186
i18nc("@info", "<para>%1</para><para>%2</para>", msg, openedObjectsStr)
188
+ xi18n("Do you want to close all windows for these objects?")
190
QString(), KGuiItem(xi18nc("@action:button Close All Windows", "Close Windows"), koIconName("window-close")), KStandardGuiItem::cancel());
192
if (r == KMessageBox::Yes) {
193
//try to close every window
194
res = conn->closeAllTableSchemaChangeListeners(table);
195
if (res != true) //do not expose closing errors twice; just cancel
203
KLocalizedString KexiTablePart::i18nMessage(
204
const QString& englishMessage, KexiWindow* window) const
207
if (englishMessage == "Design of object <resource>%1</resource> has been modified.")
208
return kxi18nc(I18NC_NOOP("@info", "Design of table <resource>%1</resource> has been modified."));
210
if (englishMessage == "Object <resource>%1</resource> already exists.")
211
return kxi18nc(I18NC_NOOP("@info", "Table <resource>%1</resource> already exists."));
213
if (window->currentViewMode() == Kexi::DesignViewMode && !window->neverSaved()
214
&& englishMessage == ":additional message before saving design")
215
return kxi18nc(I18NC_NOOP("@info", "<warning>Any data in this table will be removed upon design's saving!</warning>"));
217
return Part::i18nMessage(englishMessage, window);
220
void KexiTablePart::setupCustomPropertyPanelTabs(QTabWidget *tab)
222
if (!d->lookupColumnPage) {
223
d->lookupColumnPage = new KexiLookupColumnPage(0);
224
connect(d->lookupColumnPage,
225
SIGNAL(jumpToObjectRequested(QString,QString)),
226
KexiMainWindowIface::global()->thisWidget(),
227
SLOT(highlightObject(QString,QString)));
229
//! @todo add "Table" tab
231
connect(d->dataSourcePage, SIGNAL(formDataSourceChanged(QCString,QCString)),
232
KFormDesigner::FormManager::self(), SLOT(setFormDataSource(QCString,QCString)));
233
connect(d->dataSourcePage, SIGNAL(dataSourceFieldOrExpressionChanged(QString,QString,KDbField::Type)),
234
KFormDesigner::FormManager::self(), SLOT(setDataSourceFieldOrExpression(QString,QString,KDbField::Type)));
235
connect(d->dataSourcePage, SIGNAL(insertAutoFields(QString,QString,QStringList)),
236
KFormDesigner::FormManager::self(), SLOT(insertAutoFields(QString,QString,QStringList)));*/
239
KexiProject *prj = KexiMainWindowIface::global()->project();
240
d->lookupColumnPage->setProject(prj);
242
//! @todo add lookup field icon
243
tab->addTab(d->lookupColumnPage, KexiIcon("combobox"), QString());
244
tab->setTabToolTip(tab->indexOf(d->lookupColumnPage), xi18n("Lookup column"));
247
KexiLookupColumnPage* KexiTablePart::lookupColumnPage() const
249
return d->lookupColumnPage;
254
KexiTablePartTempData::KexiTablePartTempData(QObject* parent)
255
: KexiWindowData(parent)
257
, tableSchemaChangedInPreviousView(true /*to force reloading on startup*/)
261
#include "kexitablepart.moc"