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 <tdeversion.h>
41#include <tdeinstance.h>
43#include <kpushbutton.h>
44#include <kjanuswidget.h>
45#include <tdeglobalsettings.h>
47#include <tdefileiconview.h>
48#include <tdefileitem.h>
49#include <tdemessagebox.h>
50#include <tdeapplication.h>
52#include <ktextbrowser.h>
55#ifdef KEXI_SHOW_UNIMPLEMENTED
56#define KEXI_STARTUP_SHOW_TEMPLATES
57#define KEXI_STARTUP_SHOW_RECENT
61class KexiStartupDialogPrivate {
63 KexiStartupDialogPrivate()
64 : pageTemplates(0), pageOpenExisting(0), pageOpenRecent(0)
66 , pageOpenExistingID(-1)
67 , pageOpenRecentID(-1)
70 TQString none, iconname;
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 );
77 openExistingConnWidget = 0;
79 templatesWidget_IconListBox = 0;
81 ~KexiStartupDialogPrivate()
84 int dialogType, dialogOptions;
86 TQFrame *pageTemplates, *pageOpenExisting, *pageOpenRecent;
88 int pageOpenExistingID, pageOpenRecentID;
89 int templatesSectionID_blank, templatesSectionID_import;
91 int templatesSectionID_templates;
93 TQCheckBox *chkDoNotShow;
96 KJanusWidget* templatesWidget;
97 TQObject *templatesWidget_IconListBox;
99 TQWidgetStack *viewBlankTempl;
105 TQPixmap kexi_sqlite_icon, kexi_shortcut_icon;
114 TQString existingFileToOpen;
125bool dlgSinglePage(
int type)
127 return (type==KexiStartupDialog::Templates)
128 || (type==KexiStartupDialog::OpenExisting)
129 || (type==KexiStartupDialog::OpenRecent);
132TQString captionForDialogType(
int type)
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");
141 return i18n(
"Choose Project");
153 int dialogType,
int dialogOptions,
155 TQWidget *parent,
const char *name )
157 dlgSinglePage(dialogType) ? Plain : Tabbed
158 ,captionForDialogType(dialogType)
159 ,Help | Ok | Cancel, Ok, parent, name )
160 , d(new KexiStartupDialogPrivate())
162 d->recentProjects = &recentProjects;
163 d->connSet = &connSet;
164 d->dialogType = dialogType;
165 d->dialogOptions = dialogOptions;
166 d->singlePage = dlgSinglePage(dialogType);
168 if (dialogType==OpenExisting) {
169 setIcon(DesktopIcon(
"document-open"));
171 setIcon(d->kexi_sqlite_icon);
174 setSizeGripEnabled(
true);
176 if (d->dialogType & Templates) {
177 setupPageTemplates();
178 d->pageTemplatesID =
id++;
179 d->templatesWidget->setFocus();
181 if (d->dialogType & OpenExisting) {
182 setupPageOpenExisting();
183 d->pageOpenExistingID =
id++;
185 d->openExistingConnWidget->setFocus();
187#ifdef KEXI_STARTUP_SHOW_RECENT
188 if (d->dialogType & OpenRecent) {
189 setupPageOpenRecent();
190 d->pageOpenRecentID =
id++;
192 d->prj_selector->setFocus();
196 if (!d->singlePage) {
197 connect(
this, TQ_SIGNAL(aboutToShowPage(TQWidget*)),
this, TQ_SLOT(
slotPageShown(TQWidget*)));
198 d->templatesWidget->setFocus();
204KexiStartupDialog::~KexiStartupDialog()
211 TDEGlobal::config()->setGroup(
"Startup");
212 return TDEGlobal::config()->readBoolEntry(
"ShowStartupDialog",
true);
219 d->existingFileToOpen=TQString();
222 KDialog::centerOnScreen(
this);
231void KexiStartupDialog::done(
int r)
239 if (r==TQDialog::Rejected) {
243 if (idx == d->pageTemplatesID) {
244 const int templateIdx = d->templatesWidget->activePageIndex();
245 if (templateIdx == d->templatesSectionID_blank)
248 else if (templateIdx == d->templatesSectionID_templates)
251 else if (templateIdx == d->templatesSectionID_import)
254 else if (idx == d->pageOpenExistingID) {
256 if (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased) {
257 if (!d->openExistingFileDlg->checkFileName())
259 d->existingFileToOpen = d->openExistingFileDlg->currentFileName();
261 d->selectedExistingConnection = 0;
263 d->existingFileToOpen = TQString();
264 d->selectedExistingConnection
265 = d->openExistingConnWidget->selectedConnectionData();
275 TDEGlobal::config()->setGroup(
"Startup");
276 if (d->openExistingConnWidget)
277 TDEGlobal::config()->writeEntry(
"OpenExistingType",
278 (d->openExistingConnWidget->selectedConnectionType() == KexiConnSelectorWidget::FileBased)
279 ?
"File" :
"Server");
281 TDEGlobal::config()->writeEntry(
"ShowStartupDialog",!d->chkDoNotShow->isChecked());
283 TDEGlobal::config()->sync();
285 KDialogBase::done(r);
288void KexiStartupDialog::reject()
291 KDialogBase::reject();
294void KexiStartupDialog::setupPageTemplates()
296 d->pageTemplates = addPage( i18n(
"&Create Project") );
297 TQVBoxLayout *lyr =
new TQVBoxLayout( d->pageTemplates, 0, KDialogBase::spacingHint() );
299 d->templatesWidget =
new KJanusWidget(
300 d->pageTemplates,
"templatesWidget", KJanusWidget::IconList);
302 d->templatesWidget_IconListBox = d->templatesWidget->child(0,
"TDEListBox");
303 if (d->templatesWidget_IconListBox)
304 d->templatesWidget_IconListBox->installEventFilter(
this);
306 lyr->addWidget(d->templatesWidget);
307 connect(d->templatesWidget, TQ_SIGNAL(aboutToShowPage(TQWidget*)),
this, TQ_SLOT(
slotPageShown(TQWidget*)));
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);
315 TQFrame *templPageFrame;
316 TQVBoxLayout *tmplyr;
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);
334 d->templatesSectionID_templates = itemID++;
336 TQString kexi_sqlite_icon_name
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 );
350 tmplyr->addWidget( d->viewTemplates );
351 connect(d->viewTemplates,TQ_SIGNAL(selected(
const TQString&)),
352 this,TQ_SLOT(templateSelected(
const TQString&)));
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);
400 int idx = d->templatesWidget->pageIndex(page);
402 if (idx==d->templatesSectionID_blank) {
405 else if (idx==d->templatesSectionID_import) {
408 else if (idx==d->templatesSectionID_templates) {
409 d->viewTemplates->populate();
439void KexiStartupDialog::templateItemSelected(TQIconViewItem *)
444void KexiStartupDialog::templateItemExecuted(TQIconViewItem *item)
454void KexiStartupDialog::updateSelectedTemplateKeyInfo()
457 d->selectedTemplateKey=TQString();
460 TQIconViewItem *item;
461 if (d->templatesWidget->activePageIndex()==d->templatesSectionID_blank) {
462 d->selectedTemplateKey =
"blank";
464 else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_import) {
465 d->selectedTemplateKey =
"import";
468 else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_templates) {
469 item = d->viewTemplates->templates->currentItem();
471 d->selectedTemplateKey=TQString();
474 d->selectedTemplateKey=TQString(
"personal/")+
static_cast<TemplateItem*
>(item)->key;
495 if (w==d->pageOpenExisting) {
496 d->openExistingConnWidget->setFocus();
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;
515 if (w==d->pageTemplates) {
516 int t_id = d->templatesWidget->activePageIndex();
518 enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import
519 || (t_id==d->templatesSectionID_templates && !d->viewTemplates->selectedFileName().isEmpty()));
521 enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import);
524 else if (w==d->pageOpenExisting) {
527 (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased)
528 ? !d->openExistingFileDlg->currentFileName().isEmpty()
529 : (bool)d->openExistingConnWidget->selectedConnectionData();
531 else if (w==d->pageOpenRecent) {
532 enable = (d->prj_selector->selectedProjectData()!=0);
534 enableButton(Ok,enable);
542void KexiStartupDialog::setupPageOpenExisting()
545 d->pageOpenExisting = plainPage();
547 d->pageOpenExisting = addPage( i18n(
"Open &Existing Project") );
548 TQVBoxLayout *lyr =
new TQVBoxLayout( d->pageOpenExisting, 0, KDialogBase::spacingHint() );
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();
558 d->openExistingConnWidget->showSimpleConn();
559 d->openExistingConnWidget->showAdvancedConn();
561 d->openExistingFileDlg = d->openExistingConnWidget->m_fileDlg;
562 connect(d->openExistingFileDlg,TQ_SIGNAL(accepted()),
this,TQ_SLOT(accept()));
578 actionButton(KDialogBase::Ok)->setEnabled(item);
581void KexiStartupDialog::slotOk() {
584 if (d->openExistingFileDlg) {
585 if (d->openExistingFileDlg->okButton())
586 d->openExistingFileDlg->okButton()->animateClick();
590 KDialogBase::slotOk();
593void KexiStartupDialog::showSimpleConnForOpenExisting()
596 d->openExistingConnWidget->showSimpleConn();
599void KexiStartupDialog::showAdvancedConnForOpenExisting()
602 d->openExistingConnWidget->showAdvancedConn();
608 return d->existingFileToOpen;
610 return d->viewTemplates->selectedFileName();
617 return d->selectedExistingConnection;
620void KexiStartupDialog::existingFileSelected(
const TQString &f)
624 d->existingFileToOpen=f;
628void KexiStartupDialog::setupPageOpenRecent()
630#ifdef KEXI_STARTUP_SHOW_RECENT
631 d->pageOpenRecent = addPage( i18n(
"Open &Recent Project") );
632 TQVBoxLayout *lyr =
new TQVBoxLayout( d->pageOpenRecent, 0, KDialogBase::spacingHint() );
634 d->pageOpenRecent,
"prj_selector", d->recentProjects ) );
643 return d->prj_selector->selectedProjectData();
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)
664 const int t_id = d->templatesWidget->activePageIndex();
665 if (t_id==d->templatesSectionID_blank || t_id==d->templatesSectionID_import) {
671 return KDialogBase::eventFilter(o,e);
677 if (!d->singlePage) {
679 return KDialogBase::activePageIndex();
681 kdDebug() <<
"int KexiStartupDialog::activePageIndex() == " << 0 << endl;
685void KexiStartupDialog::templateSelected(
const TQString& fileName)
687 if (!fileName.isEmpty())
694 TQValueList<KexiProjectData::ObjectInfo>();
696 return d->viewTemplates->autoopenObjectsForSelectedTemplate();
699#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)
Widget for opening/saving files supported by Kexi.
KEXICORE_EXPORT KexiProjectSet & recentProjects()
A set avaiulable of project infos.