KexiStartupDialog.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2007 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 "KexiStartupDialog.h"
21#include "KexiStartupDialogTemplatesPage.h"
22#include "kexi.h"
23#include "KexiProjectSelector.h"
24#include "KexiOpenExistingFile.h"
25#include "KexiConnSelector.h"
26#include "KexiConnSelectorBase.h"
27
28#include <tqlayout.h>
29#include <tqtabwidget.h>
30#include <tqcombobox.h>
31#include <tqcheckbox.h>
32#include <tqpoint.h>
33#include <tqobjectlist.h>
34#include <tqvgroupbox.h>
35#include <tqapplication.h>
36#include <tqtooltip.h>
37#include <tqwidgetstack.h>
38
39#include <tdelocale.h>
40#include <tdeversion.h>
41#include <tdeinstance.h>
42#include <kdebug.h>
43#include <kpushbutton.h>
44#include <kjanuswidget.h>
45#include <tdeglobalsettings.h>
46#include <ktextedit.h>
47#include <tdefileiconview.h>
48#include <tdefileitem.h>
49#include <tdemessagebox.h>
50#include <tdeapplication.h>
51#include <kmimetype.h>
52#include <ktextbrowser.h>
53#include <tdeconfig.h>
54
55#ifdef KEXI_SHOW_UNIMPLEMENTED
56#define KEXI_STARTUP_SHOW_TEMPLATES
57#define KEXI_STARTUP_SHOW_RECENT
58#endif
59
61class KexiStartupDialogPrivate {
62public:
63 KexiStartupDialogPrivate()
64 : pageTemplates(0), pageOpenExisting(0), pageOpenRecent(0)
65 , pageTemplatesID(-1)
66 , pageOpenExistingID(-1)
67 , pageOpenRecentID(-1)
68 {
69 result = 0;
70 TQString none, iconname;
71 iconname = KMimeType::mimeType( KexiDB::Driver::defaultFileBasedDriverMimeType() )->icon(none,0);
72 kexi_sqlite_icon = TDEGlobal::iconLoader()->loadIcon( iconname, TDEIcon::Desktop );
73 iconname = KMimeType::mimeType("application/x-kexiproject-shortcut")->icon(none,0);
74 kexi_shortcut_icon = TDEGlobal::iconLoader()->loadIcon( iconname, TDEIcon::Desktop );
75 prj_selector = 0;
76 chkDoNotShow = 0;
77 openExistingConnWidget = 0;
78 templatesWidget = 0;
79 templatesWidget_IconListBox = 0;
80 }
81 ~KexiStartupDialogPrivate()
82 {}
83
84 int dialogType, dialogOptions;
85
86 TQFrame *pageTemplates, *pageOpenExisting, *pageOpenRecent;
87 int pageTemplatesID;
88 int pageOpenExistingID, pageOpenRecentID;
89 int templatesSectionID_blank, templatesSectionID_import;
90#ifdef DB_TEMPLATES
91 int templatesSectionID_templates; //, templatesSectionID_custom2;
92#endif
93 TQCheckBox *chkDoNotShow;
94
95 //widgets for template tab:
96 KJanusWidget* templatesWidget;
97 TQObject *templatesWidget_IconListBox;//helper
98
99 TQWidgetStack *viewBlankTempl;
100 KexiStartupDialogTemplatesPage *viewTemplates;
101 //TemplatesPage *viewBusinessTempl;
102
103 int result;
104
105 TQPixmap kexi_sqlite_icon, kexi_shortcut_icon;
106
107// //! Key string of selected database template. \sa selectedTemplateKey()
108// TQString selectedTemplateKey;
109
111 KexiDBConnectionSet *connSet;
112 KexiStartupFileDialog *openExistingFileDlg;
113 KexiConnSelectorWidget *openExistingConnWidget;
114 TQString existingFileToOpen;
115 KexiDB::ConnectionData* selectedExistingConnection;
116
119 KexiProjectSelectorWidget* prj_selector;
120
122 bool singlePage : 1;
123};
124
125bool dlgSinglePage(int type)
126{
127 return (type==KexiStartupDialog::Templates)
128 || (type==KexiStartupDialog::OpenExisting)
129 || (type==KexiStartupDialog::OpenRecent);
130}
131
132TQString captionForDialogType(int type)
133{
134 if (type==KexiStartupDialog::Templates)
135 return i18n("Create Project");
136 else if (type==KexiStartupDialog::OpenExisting)
137 return i18n("Open Existing Project");
138 else if (type==KexiStartupDialog::OpenRecent)
139 return i18n("Open Recent Project");
140
141 return i18n("Choose Project");
142}
143
144/*================================================================*/
145/*KexiStartupDialog::KexiStartupDialog(TQWidget *parent, const char *name, TDEInstance* global,
146 const TQCString &format, const TQString &nativePattern,
147 const TQString &nativeName, const DialogType &dialogType,
148 const TQCString& templateType) :
149 KDialogBase(parent, name, true, i18n("Open Document"), KDialogBase::Ok | KDialogBase::Cancel,
150 KDialogBase::Ok) {
151*/
153 int dialogType, int dialogOptions,
154 KexiDBConnectionSet& connSet, KexiProjectSet& recentProjects,
155 TQWidget *parent, const char *name )
156 : KDialogBase(
157 dlgSinglePage(dialogType) ? Plain : Tabbed
158 ,captionForDialogType(dialogType)
159 ,Help | Ok | Cancel, Ok, parent, name )
160 , d(new KexiStartupDialogPrivate())
161{
162 d->recentProjects = &recentProjects;
163 d->connSet = &connSet;
164 d->dialogType = dialogType;
165 d->dialogOptions = dialogOptions;
166 d->singlePage = dlgSinglePage(dialogType);
167
168 if (dialogType==OpenExisting) {//this dialog has "open" tab only!
169 setIcon(DesktopIcon("document-open"));
170 } else {
171 setIcon(d->kexi_sqlite_icon);
172 }
173
174 setSizeGripEnabled(true);
175 int id=0;
176 if (d->dialogType & Templates) {
177 setupPageTemplates();
178 d->pageTemplatesID = id++;
179 d->templatesWidget->setFocus();
180 }
181 if (d->dialogType & OpenExisting) {
182 setupPageOpenExisting();
183 d->pageOpenExistingID = id++;
184 if (d->singlePage)
185 d->openExistingConnWidget->setFocus();
186 }
187#ifdef KEXI_STARTUP_SHOW_RECENT
188 if (d->dialogType & OpenRecent) {
189 setupPageOpenRecent();
190 d->pageOpenRecentID = id++;
191 if (d->singlePage)
192 d->prj_selector->setFocus();
193 }
194#endif
195
196 if (!d->singlePage) {
197 connect(this, TQ_SIGNAL(aboutToShowPage(TQWidget*)), this, TQ_SLOT(slotPageShown(TQWidget*)));
198 d->templatesWidget->setFocus();
199 }
200 showPage(0);
201 adjustSize();
202}
203
204KexiStartupDialog::~KexiStartupDialog()
205{
206 delete d;
207}
208
210{
211 TDEGlobal::config()->setGroup("Startup");
212 return TDEGlobal::config()->readBoolEntry("ShowStartupDialog",true);
213}
214
216{
217 //just some cleanup
218// d->selectedTemplateKey=TQString();
219 d->existingFileToOpen=TQString();
220 d->result=-1;
221
222 KDialog::centerOnScreen(this);
223 KDialogBase::show();
224}
225
227{
228 return d->result;
229}
230
231void KexiStartupDialog::done(int r)
232{
233 if (d->result!=-1) //already done!
234 return;
235
236// kdDebug() << "KexiStartupDialog::done(" << r << ")" << endl;
237// updateSelectedTemplateKeyInfo();
238
239 if (r==TQDialog::Rejected) {
240 d->result = CancelResult;
241 } else {
242 const int idx = activePageIndex();
243 if (idx == d->pageTemplatesID) {
244 const int templateIdx = d->templatesWidget->activePageIndex();
245 if (templateIdx == d->templatesSectionID_blank)
246 d->result = CreateBlankResult;
247#ifdef DB_TEMPLATES
248 else if (templateIdx == d->templatesSectionID_templates)
249 d->result = CreateFromTemplateResult;
250#endif
251 else if (templateIdx == d->templatesSectionID_import)
252 d->result = ImportResult;
253 }
254 else if (idx == d->pageOpenExistingID) {
255 // return file or connection:
256 if (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased) {
257 if (!d->openExistingFileDlg->checkFileName())
258 return;
259 d->existingFileToOpen = d->openExistingFileDlg->currentFileName();
260// d->existingFileToOpen = d->openExistingFileDlg->currentURL().path();
261 d->selectedExistingConnection = 0;
262 } else {
263 d->existingFileToOpen = TQString();
264 d->selectedExistingConnection
265 = d->openExistingConnWidget->selectedConnectionData();
266 }
267 d->result = OpenExistingResult;
268 }
269 else {
270 d->result = OpenRecentResult;
271 }
272 }
273
274 //save settings
275 TDEGlobal::config()->setGroup("Startup");
276 if (d->openExistingConnWidget)
277 TDEGlobal::config()->writeEntry("OpenExistingType",
278 (d->openExistingConnWidget->selectedConnectionType() == KexiConnSelectorWidget::FileBased)
279 ? "File" : "Server");
280 if (d->chkDoNotShow)
281 TDEGlobal::config()->writeEntry("ShowStartupDialog",!d->chkDoNotShow->isChecked());
282
283 TDEGlobal::config()->sync();
284
285 KDialogBase::done(r);
286}
287
288void KexiStartupDialog::reject()
289{
290// d->result = CancelResult;
291 KDialogBase::reject();
292}
293
294void KexiStartupDialog::setupPageTemplates()
295{
296 d->pageTemplates = addPage( i18n("&Create Project") );
297 TQVBoxLayout *lyr = new TQVBoxLayout( d->pageTemplates, 0, KDialogBase::spacingHint() );
298
299 d->templatesWidget = new KJanusWidget(
300 d->pageTemplates, "templatesWidget", KJanusWidget::IconList);
301 {//aaa! dirty hack
302 d->templatesWidget_IconListBox = d->templatesWidget->child(0,"TDEListBox");
303 if (d->templatesWidget_IconListBox)
304 d->templatesWidget_IconListBox->installEventFilter(this);
305 }
306 lyr->addWidget(d->templatesWidget);
307 connect(d->templatesWidget, TQ_SIGNAL(aboutToShowPage(TQWidget*)), this, TQ_SLOT(slotPageShown(TQWidget*)));
308
309 if (d->dialogOptions & CheckBoxDoNotShowAgain) {
310 d->chkDoNotShow = new TQCheckBox(i18n("Don't show me this dialog again"), d->pageTemplates, "chkDoNotShow");
311 lyr->addWidget(d->chkDoNotShow);
312 }
313
314 //template groups:
315 TQFrame *templPageFrame;
316 TQVBoxLayout *tmplyr;
317 int itemID = 0; //used just to set up templatesSectionID_*
318
319 //- page "blank db"
320 d->templatesSectionID_blank = itemID++;
321 TQString clickMsg( "\n\n" + i18n("Click \"OK\" button to proceed.") );
322 templPageFrame = d->templatesWidget->addPage(
323 i18n("Blank Database"), i18n("New Blank Database Project"), DesktopIcon("application-x-zerosize") );
324 tmplyr = new TQVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
325 TQLabel *lbl_blank = new TQLabel(
326 i18n("Kexi will create a new blank database project.")+clickMsg, templPageFrame );
327 lbl_blank->setAlignment(TQt::AlignAuto|TQt::AlignTop|TQt::WordBreak);
328 lbl_blank->setMargin(0);
329 tmplyr->addWidget( lbl_blank );
330 tmplyr->addStretch(1);
331
332#ifdef DB_TEMPLATES
333 //- page "templates"
334 d->templatesSectionID_templates = itemID++;
335 TQString none;
336 TQString kexi_sqlite_icon_name
337 = KMimeType::mimeType( KexiDB::Driver::defaultFileBasedDriverMimeType() )->icon(none,0);
338 templPageFrame = d->templatesWidget->addPage (
339 i18n("Keep this text narrow: split to multiple rows if needed", "Create From\nTemplate"),
340 i18n("New Database Project From Template"), DesktopIcon(kexi_sqlite_icon_name) );
341 tmplyr = new TQVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
342 TQLabel *lbl_templ = new TQLabel(
343 i18n("Kexi will create a new database project using selected template.\n"
344 "Select template and click \"OK\" button to proceed."), templPageFrame );
345 lbl_templ->setAlignment(TQt::AlignAuto|TQt::AlignTop|TQt::WordBreak);
346 lbl_templ->setMargin(0);
347 tmplyr->addWidget( lbl_templ );
348
349 d->viewTemplates = new KexiStartupDialogTemplatesPage( templPageFrame );
350 tmplyr->addWidget( d->viewTemplates );
351 connect(d->viewTemplates,TQ_SIGNAL(selected(const TQString&)),
352 this,TQ_SLOT(templateSelected(const TQString&)));
353/* connect(d->viewTemplates->templates,TQ_SIGNAL(returnPressed(TQIconViewItem*)),
354 this,TQ_SLOT(templateItemExecuted(TQIconViewItem*)));
355 connect(d->viewTemplates->templates,TQ_SIGNAL(currentChanged(TQIconViewItem*)),
356 this,TQ_SLOT(templateItemSelected(TQIconViewItem*)));*/
357/*later
358 templPageFrame = d->templatesWidget->addPage (
359 i18n("Personal Databases"), i18n("New Personal Database Project Templates"), DesktopIcon("folder_home") );
360 tmplyr = new TQVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
361 d->viewPersonalTempl = new TemplatesPage(TQt::Vertical, templPageFrame, "personal_page" );
362 tmplyr->addWidget( d->viewPersonalTempl );
363 connect(d->viewPersonalTempl->templates,TQ_SIGNAL(doubleClicked(TQIconViewItem*)),this,TQ_SLOT(templateItemExecuted(TQIconViewItem*)));
364 connect(d->viewPersonalTempl->templates,TQ_SIGNAL(returnPressed(TQIconViewItem*)),this,TQ_SLOT(templateItemExecuted(TQIconViewItem*)));
365 connect(d->viewPersonalTempl->templates,TQ_SIGNAL(currentChanged(TQIconViewItem*)),this,TQ_SLOT(templateItemSelected(TQIconViewItem*)));
366*/
367
368 //- page "business db"
369/*later
370 d->templatesSectionID_custom2 = itemID++;
371 templPageFrame = d->templatesWidget->addPage (
372 i18n("Business Databases"), i18n("New Business Database Project Templates"),
373 DesktopIcon( "business_user" ));
374 tmplyr = new TQVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
375 d->viewBusinessTempl = new TemplatesPage(TQt::Vertical, templPageFrame, "business_page" );
376 tmplyr->addWidget( d->viewBusinessTempl );
377 connect(d->viewBusinessTempl->templates,TQ_SIGNAL(doubleClicked(TQIconViewItem*)),this,TQ_SLOT(templateItemExecuted(TQIconViewItem*)));
378 connect(d->viewBusinessTempl->templates,TQ_SIGNAL(returnPressed(TQIconViewItem*)),this,TQ_SLOT(templateItemExecuted(TQIconViewItem*)));
379 connect(d->viewBusinessTempl->templates,TQ_SIGNAL(currentChanged(TQIconViewItem*)),this,TQ_SLOT(templateItemSelected(TQIconViewItem*)));
380*/
381#endif //DB_TEMPLATES
382
383 //- page "import db"
384 d->templatesSectionID_import = itemID++;
385 templPageFrame = d->templatesWidget->addPage(
386 i18n("Import Existing\nDatabase"), i18n("Import Existing Database as New Database Project"),
387 DesktopIcon("database_import") );
388 tmplyr = new TQVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
389 TQLabel *lbl_import = new TQLabel(
390 i18n("Kexi will import the structure and data of an existing database as a new database project.")
391 +clickMsg, templPageFrame );
392 lbl_import->setAlignment(TQt::AlignAuto|TQt::AlignTop|TQt::WordBreak);
393 lbl_import->setMargin(0);
394 tmplyr->addWidget( lbl_import );
395 tmplyr->addStretch(1);
396}
397
399{
400 int idx = d->templatesWidget->pageIndex(page);
401// TDEIconView *templ = 0;
402 if (idx==d->templatesSectionID_blank) {//blank
403// kdDebug() << "blank" << endl;
404 }
405 else if (idx==d->templatesSectionID_import) {
406 }
407#ifdef DB_TEMPLATES
408 else if (idx==d->templatesSectionID_templates) {
409 d->viewTemplates->populate();
410 }
411/*later? TDEIconView *templ = d->viewTemplates->templates;
412 if (templ->count()==0) {
413 //add items (on demand):
414 d->viewTemplates->addItem("cd_catalog", i18n("CD Catalog"),
415 i18n("Easy-to-use database for storing information about your CD collection."),
416 DesktopIcon("media-optical-cdrom-unmounted"));
417 d->viewTemplates->addItem("expenses", i18n("Expenses"),
418 i18n("A database for managing your personal expenses."),
419 DesktopIcon("kcalc"));
420 d->viewTemplates->addItem("image_gallery", i18n("Image Gallery"),
421 i18n("A database for archiving your image collection in a form of gallery."),
422 DesktopIcon("icons"));
423 }
424 }
425 else if (idx==d->templatesSectionID_custom2) {//business
426 templ = d->viewBusinessTempl->templates;
427 if (templ->count()==0) {
428 //add items (on demand):
429 d->viewBusinessTempl->addItem("address_book", i18n("Address Book"),
430 i18n("A database that offers you a contact information"),
431 DesktopIcon("contents"));
432 }
433 }*/
434#endif
435 updateDialogOKButton(d->pageTemplates);
436}
437
438#if 0
439void KexiStartupDialog::templateItemSelected(TQIconViewItem *)
440{
441 updateDialogOKButton(d->pageTemplates);
442}
443
444void KexiStartupDialog::templateItemExecuted(TQIconViewItem *item)
445{
446 if (!item)
447 return;
448// updateSelectedTemplateKeyInfo();
449#ifdef DB_TEMPLATES
450 accept();
451#endif
452}
453
454void KexiStartupDialog::updateSelectedTemplateKeyInfo()
455{
456 if (activePageIndex()!=d->pageTemplatesID) {//not a 'new db' tab is selected
457 d->selectedTemplateKey=TQString();
458 return;
459 }
460 TQIconViewItem *item;
461 if (d->templatesWidget->activePageIndex()==d->templatesSectionID_blank) {
462 d->selectedTemplateKey = "blank";
463 }
464 else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_import) {
465 d->selectedTemplateKey = "import";
466 }
467#ifdef DB_TEMPLATES
468 else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_templates) {
469 item = d->viewTemplates->templates->currentItem();
470 if (!item) {
471 d->selectedTemplateKey=TQString();
472 return;
473 }
474 d->selectedTemplateKey=TQString("personal/")+static_cast<TemplateItem*>(item)->key;
475 }
476/*later?
477 else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_custom2) {
478 item = d->viewBusinessTempl->templates->currentItem();
479 if (!item) {
480 d->selectedTemplateKey=TQString();
481 return;
482 }
483 d->selectedTemplateKey=TQString("business/")+static_cast<TemplateItem*>(item)->key;
484 }*/
485#endif
486}
487#endif // 0
488
490{
491// kdDebug() << "KexiStartupDialog::tabShown " << (long)w << " "<< long(d->pageTemplates)<<endl;
492
494
495 if (w==d->pageOpenExisting) {
496 d->openExistingConnWidget->setFocus();
497 }
498}
499
501{
502 if (!w) {
503 int idx = activePageIndex();
504 if (idx==d->pageTemplatesID)
505 w = d->pageTemplates;
506 else if (idx==d->pageOpenExistingID)
507 w = d->pageOpenExisting;
508 else if (idx==d->pageOpenRecentID)
509 w = d->pageOpenRecent;
510
511 if (!w)
512 return;
513 }
514 bool enable = true;
515 if (w==d->pageTemplates) {
516 int t_id = d->templatesWidget->activePageIndex();
517#ifdef DB_TEMPLATES
518 enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import
519 || (t_id==d->templatesSectionID_templates && !d->viewTemplates->selectedFileName().isEmpty()));
520#else
521 enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import);
522#endif
523 }
524 else if (w==d->pageOpenExisting) {
525// enable = !d->openExistingFileDlg->currentURL().path().isEmpty();
526 enable =
527 (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased)
528 ? !d->openExistingFileDlg->currentFileName().isEmpty()
529 : (bool)d->openExistingConnWidget->selectedConnectionData();
530 }
531 else if (w==d->pageOpenRecent) {
532 enable = (d->prj_selector->selectedProjectData()!=0);
533 }
534 enableButton(Ok,enable);
535}
536
537/*TQString KexiStartupDialog::selectedTemplateKey() const
538{
539 return d->selectedTemplateKey;
540}*/
541
542void KexiStartupDialog::setupPageOpenExisting()
543{
544 if (d->singlePage)
545 d->pageOpenExisting = plainPage();
546 else
547 d->pageOpenExisting = addPage( i18n("Open &Existing Project") );
548 TQVBoxLayout *lyr = new TQVBoxLayout( d->pageOpenExisting, 0, KDialogBase::spacingHint() );
549
550 d->openExistingConnWidget = new KexiConnSelectorWidget(*d->connSet,
551 ":OpenExistingOrCreateNewProject",
552 d->pageOpenExisting, "KexiConnSelectorWidget");
553 d->openExistingConnWidget->hideConnectonIcon();
554 lyr->addWidget( d->openExistingConnWidget );
555 if (TDEGlobal::config()->readEntry("OpenExistingType","File")=="File")
556 d->openExistingConnWidget->showSimpleConn();
557 else {
558 d->openExistingConnWidget->showSimpleConn();
559 d->openExistingConnWidget->showAdvancedConn();
560 }
561 d->openExistingFileDlg = d->openExistingConnWidget->m_fileDlg;
562 connect(d->openExistingFileDlg,TQ_SIGNAL(accepted()),this,TQ_SLOT(accept()));
563 connect(d->openExistingConnWidget,TQ_SIGNAL(connectionItemExecuted(ConnectionDataLVItem*)),
564 this,TQ_SLOT(connectionItemForOpenExistingExecuted(ConnectionDataLVItem*)));
565 connect(d->openExistingConnWidget,TQ_SIGNAL(connectionItemHighlighted(ConnectionDataLVItem*)),
566 this,TQ_SLOT(connectionItemForOpenExistingHighlighted(ConnectionDataLVItem*)));
567}
568
569void KexiStartupDialog::connectionItemForOpenExistingExecuted(ConnectionDataLVItem *item)
570{
571 if (!item)
572 return;
573 accept();
574}
575
576void KexiStartupDialog::connectionItemForOpenExistingHighlighted(ConnectionDataLVItem *item)
577{
578 actionButton(KDialogBase::Ok)->setEnabled(item);
579}
580
581void KexiStartupDialog::slotOk() {
582// kdDebug()<<"KexiStartupDialog::slotOk()"<<endl;
583 if (activePageIndex()==d->pageOpenExistingID) {
584 if (d->openExistingFileDlg) {
585 if (d->openExistingFileDlg->okButton())
586 d->openExistingFileDlg->okButton()->animateClick();
587// return;
588 }
589 }
590 KDialogBase::slotOk();
591}
592
593void KexiStartupDialog::showSimpleConnForOpenExisting()
594{
595// kdDebug() << "simple" << endl;
596 d->openExistingConnWidget->showSimpleConn();
597}
598
599void KexiStartupDialog::showAdvancedConnForOpenExisting()
600{
601// kdDebug() << "adv" << endl;
602 d->openExistingConnWidget->showAdvancedConn();
603}
604
606{
607 if (d->result == OpenExistingResult)
608 return d->existingFileToOpen;
609 else if (d->result == CreateFromTemplateResult && d->viewTemplates)
610 return d->viewTemplates->selectedFileName();
611 else
612 return TQString();
613}
614
616{
617 return d->selectedExistingConnection;
618}
619
620void KexiStartupDialog::existingFileSelected(const TQString &f)
621{
622 if (f.isEmpty())
623 return;
624 d->existingFileToOpen=f;
625 updateDialogOKButton(d->openExistingFileDlg);
626}
627
628void KexiStartupDialog::setupPageOpenRecent()
629{
630#ifdef KEXI_STARTUP_SHOW_RECENT
631 d->pageOpenRecent = addPage( i18n("Open &Recent Project") );
632 TQVBoxLayout *lyr = new TQVBoxLayout( d->pageOpenRecent, 0, KDialogBase::spacingHint() );
633 lyr->addWidget( d->prj_selector = new KexiProjectSelectorWidget(
634 d->pageOpenRecent, "prj_selector", d->recentProjects ) );
635 connect(d->prj_selector,TQ_SIGNAL(projectExecuted(KexiProjectData*)),
637#endif
638}
639
641{
642 if (activePageIndex()==d->pageOpenRecentID) {
643 return d->prj_selector->selectedProjectData();
644 }
645 return 0;
646}
647
649{
650 updateDialogOKButton(d->pageOpenRecent);
651 if (!data)
652 return;
653 accept();
654}
655
657bool KexiStartupDialog::eventFilter( TQObject *o, TQEvent *e )
658{
659 if (o==d->templatesWidget_IconListBox && d->templatesWidget_IconListBox) {
660 if (e->type()==TQEvent::KeyPress
661 && (static_cast<TQKeyEvent*>(e)->key()==Key_Enter || static_cast<TQKeyEvent*>(e)->key()==Key_Return)
662 || e->type()==TQEvent::MouseButtonDblClick)
663 {
664 const int t_id = d->templatesWidget->activePageIndex();
665 if (t_id==d->templatesSectionID_blank || t_id==d->templatesSectionID_import) {
666
667 accept();
668 }
669 }
670 }
671 return KDialogBase::eventFilter(o,e);
672}
673
674// internal reimplementation
676{
677 if (!d->singlePage) {
678// kdDebug() << "int KexiStartupDialog::activePageIndex()" << KDialogBase::activePageIndex() << endl;
679 return KDialogBase::activePageIndex();
680 }
681 kdDebug() << "int KexiStartupDialog::activePageIndex() == " << 0 << endl;
682 return 0; //there is always "plain page" #0 selected
683}
684
685void KexiStartupDialog::templateSelected(const TQString& fileName)
686{
687 if (!fileName.isEmpty())
688 accept();
689}
690
691TQValueList<KexiProjectData::ObjectInfo> KexiStartupDialog::autoopenObjects() const
692{
693 if (d->result != CreateFromTemplateResult || !d->viewTemplates)
694 TQValueList<KexiProjectData::ObjectInfo>();
695
696 return d->viewTemplates->autoopenObjectsForSelectedTemplate();
697}
698
699#include "KexiStartupDialog.moc"
Database specific connection data, e.g. host, port.
static TQString defaultFileBasedDriverMimeType()
Definition driver.cpp:137
Kexi project core data member.
Stores information about multiple kexi project-data items.
void updateDialogOKButton(TQWidget *w)
helper: updates a state of dialog's OK button
TQString selectedFileName() const
void recentProjectItemExecuted(KexiProjectData *data)
helper
void slotPageShown(TQWidget *page)
slot activated when one of page in templates window is shown
int activePageIndex() const
internal reimplementation
KexiDB::ConnectionData * selectedExistingConnection() const
virtual bool eventFilter(TQObject *o, TQEvent *e)
used for accepting templates dialog with just return key press
void tabShown(TQWidget *w)
Any tab has been selected.
KexiProjectData * selectedProjectData() const
static bool shouldBeShown()
@ OpenExistingResult
The user has chosen an existing connection or db file.
@ OpenRecentResult
The user has selected one of recently used databases.
@ ImportResult
The user has chosen to import db.
@ CancelResult
The user has pressed 'Cancel'.
@ CreateFromTemplateResult
The user has selected a template to be used for creating a new db.
@ CreateBlankResult
The user has selected a template.
TQValueList< KexiProjectData::ObjectInfo > autoopenObjects() const
KexiStartupDialog(int dialogType, int dialogOptions, KexiDBConnectionSet &connSet, KexiProjectSet &recentProjects, TQWidget *parent=0, const char *name=0)
Widget for opening/saving files supported by Kexi.
KEXICORE_EXPORT KexiProjectSet & recentProjects()
A set avaiulable of project infos.
Definition kexi.cpp:86