kexi

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