20#include "KexiStartupDialog.h"
21#include "KexiStartupDialogTemplatesPage.h"
23#include "KexiProjectSelector.h"
24#include "KexiOpenExistingFile.h"
25#include "KexiConnSelector.h"
26#include "KexiConnSelectorBase.h"
29#include <tqtabwidget.h>
30#include <tqcombobox.h>
31#include <tqcheckbox.h>
33#include <tqobjectlist.h>
34#include <tqvgroupbox.h>
35#include <tqapplication.h>
37#include <tqwidgetstack.h>
40#include <tdeinstance.h>
42#include <kpushbutton.h>
43#include <kjanuswidget.h>
44#include <tdeglobalsettings.h>
46#include <tdefileiconview.h>
47#include <tdefileitem.h>
48#include <tdemessagebox.h>
49#include <tdeapplication.h>
51#include <ktextbrowser.h>
54#ifdef KEXI_SHOW_UNIMPLEMENTED
55#define KEXI_STARTUP_SHOW_TEMPLATES
56#define KEXI_STARTUP_SHOW_RECENT
60class KexiStartupDialogPrivate {
62 KexiStartupDialogPrivate()
63 : pageTemplates(0), pageOpenExisting(0), pageOpenRecent(0)
65 , pageOpenExistingID(-1)
66 , pageOpenRecentID(-1)
69 TQString none, iconname;
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 );
76 openExistingConnWidget = 0;
78 templatesWidget_IconListBox = 0;
80 ~KexiStartupDialogPrivate()
83 int dialogType, dialogOptions;
85 TQFrame *pageTemplates, *pageOpenExisting, *pageOpenRecent;
87 int pageOpenExistingID, pageOpenRecentID;
88 int templatesSectionID_blank, templatesSectionID_import;
90 int templatesSectionID_templates;
92 TQCheckBox *chkDoNotShow;
95 KJanusWidget* templatesWidget;
96 TQObject *templatesWidget_IconListBox;
98 TQWidgetStack *viewBlankTempl;
99 KexiStartupDialogTemplatesPage *viewTemplates;
104 TQPixmap kexi_sqlite_icon, kexi_shortcut_icon;
110 KexiDBConnectionSet *connSet;
111 KexiStartupFileDialog *openExistingFileDlg;
112 KexiConnSelectorWidget *openExistingConnWidget;
113 TQString existingFileToOpen;
114 KexiDB::ConnectionData* selectedExistingConnection;
117 KexiProjectSet *recentProjects;
118 KexiProjectSelectorWidget* prj_selector;
124bool dlgSinglePage(
int type)
126 return (type==KexiStartupDialog::Templates)
127 || (type==KexiStartupDialog::OpenExisting)
128 || (type==KexiStartupDialog::OpenRecent);
131TQString captionForDialogType(
int type)
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");
140 return i18n(
"Choose Project");
152 int dialogType,
int dialogOptions,
154 TQWidget *parent,
const char *name )
156 dlgSinglePage(dialogType) ? Plain : Tabbed
157 ,captionForDialogType(dialogType)
158 ,Help | Ok | Cancel, Ok, parent, name )
159 , d(new KexiStartupDialogPrivate())
161 d->recentProjects = &recentProjects;
162 d->connSet = &connSet;
163 d->dialogType = dialogType;
164 d->dialogOptions = dialogOptions;
165 d->singlePage = dlgSinglePage(dialogType);
167 if (dialogType==OpenExisting) {
168 setIcon(DesktopIcon(
"document-open"));
170 setIcon(d->kexi_sqlite_icon);
173 setSizeGripEnabled(
true);
175 if (d->dialogType & Templates) {
176 setupPageTemplates();
177 d->pageTemplatesID =
id++;
178 d->templatesWidget->setFocus();
180 if (d->dialogType & OpenExisting) {
181 setupPageOpenExisting();
182 d->pageOpenExistingID =
id++;
184 d->openExistingConnWidget->setFocus();
186#ifdef KEXI_STARTUP_SHOW_RECENT
187 if (d->dialogType & OpenRecent) {
188 setupPageOpenRecent();
189 d->pageOpenRecentID =
id++;
191 d->prj_selector->setFocus();
195 if (!d->singlePage) {
196 connect(
this, TQ_SIGNAL(aboutToShowPage(TQWidget*)),
this, TQ_SLOT(
slotPageShown(TQWidget*)));
197 d->templatesWidget->setFocus();
203KexiStartupDialog::~KexiStartupDialog()
210 TDEGlobal::config()->setGroup(
"Startup");
211 return TDEGlobal::config()->readBoolEntry(
"ShowStartupDialog",
true);
218 d->existingFileToOpen=TQString();
221 KDialog::centerOnScreen(
this);
230void KexiStartupDialog::done(
int r)
238 if (r==TQDialog::Rejected) {
242 if (idx == d->pageTemplatesID) {
243 const int templateIdx = d->templatesWidget->activePageIndex();
244 if (templateIdx == d->templatesSectionID_blank)
247 else if (templateIdx == d->templatesSectionID_templates)
250 else if (templateIdx == d->templatesSectionID_import)
253 else if (idx == d->pageOpenExistingID) {
255 if (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased) {
256 if (!d->openExistingFileDlg->checkFileName())
258 d->existingFileToOpen = d->openExistingFileDlg->currentFileName();
260 d->selectedExistingConnection = 0;
262 d->existingFileToOpen = TQString();
263 d->selectedExistingConnection
264 = d->openExistingConnWidget->selectedConnectionData();
274 TDEGlobal::config()->setGroup(
"Startup");
275 if (d->openExistingConnWidget)
276 TDEGlobal::config()->writeEntry(
"OpenExistingType",
277 (d->openExistingConnWidget->selectedConnectionType() == KexiConnSelectorWidget::FileBased)
278 ?
"File" :
"Server");
280 TDEGlobal::config()->writeEntry(
"ShowStartupDialog",!d->chkDoNotShow->isChecked());
282 TDEGlobal::config()->sync();
284 KDialogBase::done(r);
287void KexiStartupDialog::reject()
290 KDialogBase::reject();
293void KexiStartupDialog::setupPageTemplates()
295 d->pageTemplates = addPage( i18n(
"&Create Project") );
296 TQVBoxLayout *lyr =
new TQVBoxLayout( d->pageTemplates, 0, KDialogBase::spacingHint() );
298 d->templatesWidget =
new KJanusWidget(
299 d->pageTemplates,
"templatesWidget", KJanusWidget::IconList);
301 d->templatesWidget_IconListBox = d->templatesWidget->child(0,
"TDEListBox");
302 if (d->templatesWidget_IconListBox)
303 d->templatesWidget_IconListBox->installEventFilter(
this);
305 lyr->addWidget(d->templatesWidget);
306 connect(d->templatesWidget, TQ_SIGNAL(aboutToShowPage(TQWidget*)),
this, TQ_SLOT(
slotPageShown(TQWidget*)));
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);
314 TQFrame *templPageFrame;
315 TQVBoxLayout *tmplyr;
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);
333 d->templatesSectionID_templates = itemID++;
335 TQString kexi_sqlite_icon_name
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 );
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&)));
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);
399 int idx = d->templatesWidget->pageIndex(page);
401 if (idx==d->templatesSectionID_blank) {
404 else if (idx==d->templatesSectionID_import) {
407 else if (idx==d->templatesSectionID_templates) {
408 d->viewTemplates->populate();
438void KexiStartupDialog::templateItemSelected(TQIconViewItem *)
443void KexiStartupDialog::templateItemExecuted(TQIconViewItem *item)
453void KexiStartupDialog::updateSelectedTemplateKeyInfo()
456 d->selectedTemplateKey=TQString();
459 TQIconViewItem *item;
460 if (d->templatesWidget->activePageIndex()==d->templatesSectionID_blank) {
461 d->selectedTemplateKey =
"blank";
463 else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_import) {
464 d->selectedTemplateKey =
"import";
467 else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_templates) {
468 item = d->viewTemplates->templates->currentItem();
470 d->selectedTemplateKey=TQString();
473 d->selectedTemplateKey=TQString(
"personal/")+
static_cast<TemplateItem*
>(item)->key;
494 if (w==d->pageOpenExisting) {
495 d->openExistingConnWidget->setFocus();
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;
514 if (w==d->pageTemplates) {
515 int t_id = d->templatesWidget->activePageIndex();
517 enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import
518 || (t_id==d->templatesSectionID_templates && !d->viewTemplates->selectedFileName().isEmpty()));
520 enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import);
523 else if (w==d->pageOpenExisting) {
526 (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased)
527 ? !d->openExistingFileDlg->currentFileName().isEmpty()
528 : (bool)d->openExistingConnWidget->selectedConnectionData();
530 else if (w==d->pageOpenRecent) {
531 enable = (d->prj_selector->selectedProjectData()!=0);
533 enableButton(Ok,enable);
541void KexiStartupDialog::setupPageOpenExisting()
544 d->pageOpenExisting = plainPage();
546 d->pageOpenExisting = addPage( i18n(
"Open &Existing Project") );
547 TQVBoxLayout *lyr =
new TQVBoxLayout( d->pageOpenExisting, 0, KDialogBase::spacingHint() );
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();
557 d->openExistingConnWidget->showSimpleConn();
558 d->openExistingConnWidget->showAdvancedConn();
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*)));
577 actionButton(KDialogBase::Ok)->setEnabled(item);
580void KexiStartupDialog::slotOk() {
583 if (d->openExistingFileDlg) {
584 if (d->openExistingFileDlg->okButton())
585 d->openExistingFileDlg->okButton()->animateClick();
589 KDialogBase::slotOk();
592void KexiStartupDialog::showSimpleConnForOpenExisting()
595 d->openExistingConnWidget->showSimpleConn();
598void KexiStartupDialog::showAdvancedConnForOpenExisting()
601 d->openExistingConnWidget->showAdvancedConn();
607 return d->existingFileToOpen;
609 return d->viewTemplates->selectedFileName();
616 return d->selectedExistingConnection;
619void KexiStartupDialog::existingFileSelected(
const TQString &f)
623 d->existingFileToOpen=f;
627void KexiStartupDialog::setupPageOpenRecent()
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*)),
642 return d->prj_selector->selectedProjectData();
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)
663 const int t_id = d->templatesWidget->activePageIndex();
664 if (t_id==d->templatesSectionID_blank || t_id==d->templatesSectionID_import) {
670 return KDialogBase::eventFilter(o,e);
676 if (!d->singlePage) {
678 return KDialogBase::activePageIndex();
680 kdDebug() <<
"int KexiStartupDialog::activePageIndex() == " << 0 << endl;
684void KexiStartupDialog::templateSelected(
const TQString& fileName)
686 if (!fileName.isEmpty())
693 TQValueList<KexiProjectData::ObjectInfo>();
695 return d->viewTemplates->autoopenObjectsForSelectedTemplate();
698#include "KexiStartupDialog.moc"
Database specific connection data, e.g. host, port.
static TQString defaultFileBasedDriverMimeType()
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)