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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
/* This file is part of the KDE project
Copyright (C) 2003 Jaroslaw Staniek <[email protected]>
This program 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 program 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 program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KexiProjectSelector.h"
#include <kexidb/drivermanager.h>
#include <kexidb/connectiondata.h>
#include "core/kexi.h"
#include <tdeapplication.h>
#include <kiconloader.h>
#include <kmimetype.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqlayout.h>
#include <tqlistview.h>
#include <assert.h>
//! @internal
class KexiProjectSelectorWidgetPrivate
{
public:
KexiProjectSelectorWidgetPrivate()
{
selectable = true;
}
TQPixmap fileicon, dbicon;
bool showProjectNameColumn : 1;
bool showConnectionColumns : 1;
bool selectable : 1;
};
/*================================================================*/
//! helper class
class ProjectDataLVItem : public TQListViewItem
{
public:
ProjectDataLVItem(KexiProjectData *d,
const KexiDB::Driver::Info& info, KexiProjectSelectorWidget *selector )
: TQListViewItem(selector->list)
, data(d)
{
int colnum = 0;
const KexiDB::ConnectionData *cdata = data->constConnectionData();
if (selector->d->showProjectNameColumn)
setText(colnum++, data->caption()+" ");
setText(colnum++, data->databaseName()+" ");
if (selector->d->showConnectionColumns) {
TQString drvname = info.caption.isEmpty() ? cdata->driverName : info.caption;
if (info.fileBased) {
setText(colnum++, i18n("File") + " ("+drvname+") " );
} else {
setText(colnum++, drvname+" " );
}
TQString conn;
if (!cdata->caption.isEmpty())
conn = cdata->caption + ": ";
conn += cdata->serverInfoString();
setText(3, conn + " ");
}
}
~ProjectDataLVItem() {}
KexiProjectData *data;
};
/*================================================================*/
/*!
* Constructs a KexiProjectSelector which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
KexiProjectSelectorWidget::KexiProjectSelectorWidget(
TQWidget* parent, const char* name,
KexiProjectSet* prj_set, bool showProjectNameColumn,
bool showConnectionColumns )
: KexiProjectSelectorBase( parent, name )
,m_prj_set(prj_set)
,d(new KexiProjectSelectorWidgetPrivate())
{
d->showProjectNameColumn = showProjectNameColumn;
d->showConnectionColumns = showConnectionColumns;
TQString none, iconname = KMimeType::mimeType( KexiDB::Driver::defaultFileBasedDriverMimeType() )->icon(none,0);
d->fileicon = TDEGlobal::iconLoader()->loadIcon( iconname, TDEIcon::Desktop );
setIcon( d->fileicon );
d->dbicon = SmallIcon("application-vnd.oasis.opendocument.database");
// list->setHScrollBarMode( TQScrollView::AlwaysOn );
if (!d->showConnectionColumns) {
list->removeColumn(2);
list->removeColumn(2);
}
if (!d->showProjectNameColumn) {
list->removeColumn(0);
}
setFocusProxy(list);
//show projects
setProjectSet( m_prj_set );
connect(list,TQT_SIGNAL(doubleClicked(TQListViewItem*)),this,TQT_SLOT(slotItemExecuted(TQListViewItem*)));
connect(list,TQT_SIGNAL(returnPressed(TQListViewItem*)),this,TQT_SLOT(slotItemExecuted(TQListViewItem*)));
connect(list,TQT_SIGNAL(selectionChanged()),this,TQT_SLOT(slotItemSelected()));
}
/*!
* Destroys the object and frees any allocated resources
*/
KexiProjectSelectorWidget::~KexiProjectSelectorWidget()
{
delete d;
}
KexiProjectData* KexiProjectSelectorWidget::selectedProjectData() const
{
ProjectDataLVItem *item = static_cast<ProjectDataLVItem*>(list->selectedItem());
if (item)
return item->data;
return 0;
}
void KexiProjectSelectorWidget::slotItemExecuted(TQListViewItem *item)
{
if (!d->selectable)
return;
ProjectDataLVItem *ditem = static_cast<ProjectDataLVItem*>(item);
if (ditem)
emit projectExecuted( ditem->data );
}
void KexiProjectSelectorWidget::slotItemSelected()
{
if (!d->selectable)
return;
ProjectDataLVItem *ditem = static_cast<ProjectDataLVItem*>(list->selectedItem());
emit selectionChanged( ditem ? ditem->data : 0 );
}
void KexiProjectSelectorWidget::setProjectSet( KexiProjectSet* prj_set )
{
if (prj_set) {
//old list
list->clear();
}
m_prj_set = prj_set;
if (!m_prj_set)
return;
//TODO: what with project set's ownership?
if (m_prj_set->error()) {
kdDebug() << "KexiProjectSelectorWidget::setProjectSet() : m_prj_set->error() !"<<endl;
return;
}
KexiDB::DriverManager manager;
KexiProjectData::List prjlist = m_prj_set->list();
KexiProjectData *data = prjlist.first();
while (data) {
KexiDB::Driver::Info info = manager.driverInfo(data->constConnectionData()->driverName);
if (!info.name.isEmpty()) {
ProjectDataLVItem *item = new ProjectDataLVItem(data, info, this);
if (!d->selectable)
item->setSelectable(false);
if (info.fileBased)
item->setPixmap( 0, d->fileicon );
else
item->setPixmap( 0, d->dbicon );
}
else {
kdWarning() << "KexiProjectSelector::KexiProjectSelector(): no driver found for '"
<< data->constConnectionData()->driverName << "'!" << endl;
}
data=prjlist.next();
}
if (list->firstChild()) {
list->setSelected(list->firstChild(),true);
}
}
void KexiProjectSelectorWidget::setSelectable(bool set)
{
if (d->selectable == set)
return;
d->selectable = set;
//update items' state
TQListViewItemIterator it( list );
while ( it.current() ) {
it.current()->setSelectable( d->selectable );
}
}
bool KexiProjectSelectorWidget::isSelectable() const
{
return d->selectable;
}
/*================================================================*/
KexiProjectSelectorDialog::KexiProjectSelectorDialog( TQWidget *parent, const char *name,
KexiProjectSet* prj_set, bool showProjectNameColumn, bool showConnectionColumns)
: KDialogBase( Plain, i18n("Open Recent Project"),
#ifndef KEXI_NO_UNFINISHED
//! @todo re-add Help when doc is available
Help |
#endif
Ok | Cancel, Ok, parent, name )
{
init(prj_set, showProjectNameColumn, showConnectionColumns);
}
KexiProjectSelectorDialog::KexiProjectSelectorDialog( TQWidget *parent, const char *name,
KexiDB::ConnectionData* cdata,
bool showProjectNameColumn, bool showConnectionColumns)
: KDialogBase(
Plain, i18n("Open Project"),
#ifndef KEXI_NO_UNFINISHED
//! @todo re-add Help when doc is available
Help |
#endif
Ok | Cancel, Ok, parent, name, true/*modal*/, false/*sep*/ )
{
setButtonGuiItem(Ok, KGuiItem(i18n("&Open"), "document-open", i18n("Open Database Connection")));
assert(cdata);
if (!cdata)
return;
KexiProjectSet *prj_set = new KexiProjectSet( *cdata );
init(prj_set, showProjectNameColumn, showConnectionColumns);
m_sel->label->setText( i18n("Select a project on <b>%1</b> database server to open:")
.arg(cdata->serverInfoString(false)) );
}
KexiProjectSelectorDialog::~KexiProjectSelectorDialog()
{
}
void KexiProjectSelectorDialog::init(KexiProjectSet* prj_set, bool showProjectNameColumn,
bool showConnectionColumns)
{
setSizeGripEnabled(true);
TQVBoxLayout *lyr = new TQVBoxLayout(plainPage(), 0, KDialogBase::spacingHint(), "lyr");
m_sel = new KexiProjectSelectorWidget(plainPage(), "sel",
prj_set, showProjectNameColumn, showConnectionColumns);
lyr->addWidget(m_sel);
setIcon(*m_sel->icon());
m_sel->setFocus();
connect(m_sel,TQT_SIGNAL(projectExecuted(KexiProjectData*)),
this,TQT_SLOT(slotProjectExecuted(KexiProjectData*)));
connect(m_sel,TQT_SIGNAL(selectionChanged(KexiProjectData*)),
this,TQT_SLOT(slotProjectSelectionChanged(KexiProjectData*)));
}
KexiProjectData* KexiProjectSelectorDialog::selectedProjectData() const
{
return m_sel->selectedProjectData();
}
void KexiProjectSelectorDialog::slotProjectExecuted(KexiProjectData*)
{
accept();
}
void KexiProjectSelectorDialog::slotProjectSelectionChanged(KexiProjectData* pdata)
{
enableButtonOK(pdata);
}
void KexiProjectSelectorDialog::show()
{
KDialogBase::show();
KDialog::centerOnScreen(this);
}
#include "KexiProjectSelector.moc"
|