kexi

KexiStartupDialog.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018   */
00019 
00020 #include "KexiStartupDialog.h"
00021 
00022 #include "kexi.h"
00023 #include "KexiProjectSelector.h"
00024 #include "KexiOpenExistingFile.h"
00025 #include "KexiConnSelector.h"
00026 #include "KexiConnSelectorBase.h"
00027 
00028 #include <qlayout.h>
00029 #include <qtabwidget.h>
00030 #include <qcombobox.h>
00031 #include <qcheckbox.h>
00032 #include <qpoint.h>
00033 #include <qobjectlist.h>
00034 #include <qvgroupbox.h>
00035 #include <qapplication.h>
00036 #include <qtooltip.h>
00037 #include <qwidgetstack.h>
00038 
00039 #include <klocale.h>
00040 #include <kdeversion.h>
00041 #include <kinstance.h>
00042 #include <kdebug.h>
00043 #include <kpushbutton.h>
00044 #include <kjanuswidget.h>
00045 #include <kglobalsettings.h>
00046 #include <ktextedit.h>
00047 #include <kfileiconview.h>
00048 #include <kfileitem.h>
00049 #include <kmessagebox.h>
00050 #include <kapplication.h>
00051 #include <kmimetype.h>
00052 #include <ktextbrowser.h>
00053 #include <kconfig.h>
00054 
00056 #define NO_DB_TEMPLATES
00057 
00058 #ifdef KEXI_SHOW_UNIMPLEMENTED
00059 #define KEXI_STARTUP_SHOW_TEMPLATES
00060 #define KEXI_STARTUP_SHOW_RECENT
00061 #endif
00062 
00063 class TemplateItem : public KIconViewItem
00064 {
00065     public:
00066         TemplateItem(KIconView* parent, const QString& name, const QPixmap& icon)
00067         : KIconViewItem(parent,name,icon)
00068         {}
00069         ~TemplateItem() {}
00070         QString key, name, description;
00071 };
00072 
00073 TemplatesPage::TemplatesPage( Orientation o, QWidget * parent, const char * name )
00074     : QSplitter(o, parent, name)
00075 {
00076     templates = new KIconView(this, "templates");
00077     templates->setItemsMovable(false);
00078     templates->setShowToolTips(false);
00079     info = new KTextBrowser(this,"info");
00080     setResizeMode(templates,KeepSize);
00081     setResizeMode(info,KeepSize);
00082 
00083     connect(templates,SIGNAL(selectionChanged(QIconViewItem*)),this,SLOT(itemClicked(QIconViewItem*)));
00084 }
00085 
00086 TemplatesPage::~TemplatesPage() {}
00087 
00088 void TemplatesPage::addItem(const QString& key, const QString& name,
00089     const QString& description, const QPixmap& icon)
00090 {
00091     TemplateItem *item = new TemplateItem(templates, name, icon);
00092     item->key=key;
00093     item->name=name;
00094     item->description=description;
00095 }
00096 
00097 void TemplatesPage::itemClicked(QIconViewItem *item) {
00098     if (!item) {
00099         info->setText("");
00100         return;
00101     }
00102     QString t = QString("<h2>%1</h2><p>%2</p>")
00103         .arg(static_cast<TemplateItem*>(item)->name)
00104         .arg(static_cast<TemplateItem*>(item)->description);
00105 #ifdef NO_DB_TEMPLATES
00106     t += QString("<p>") + i18n("We are sorry, templates are not yet available.") +"</p>";
00107 #endif
00108 
00109     info->setText( t );
00110 }
00111 
00112 /*================================================================*/
00113 
00115 class KexiStartupDialogPrivate {
00116 public:
00117     KexiStartupDialogPrivate()
00118         : pageTemplates(0), pageOpenExisting(0), pageOpenRecent(0)
00119         , pageTemplatesID(-1)
00120         , pageOpenExistingID(-1)
00121         , pageOpenRecentID(-1)
00122     {
00123         result = 0;
00124         QString none, iconname;
00125         iconname = KMimeType::mimeType( KexiDB::Driver::defaultFileBasedDriverMimeType() )->icon(none,0);
00126         kexi_sqlite_icon = KGlobal::iconLoader()->loadIcon( iconname, KIcon::Desktop );
00127         iconname = KMimeType::mimeType("application/x-kexiproject-shortcut")->icon(none,0);
00128         kexi_shortcut_icon = KGlobal::iconLoader()->loadIcon( iconname, KIcon::Desktop );
00129         prj_selector = 0;
00130         chkDoNotShow = 0;
00131         openExistingConnWidget = 0;
00132         templatesWidget = 0;
00133         templatesWidget_IconListBox = 0;
00134     }
00135     ~KexiStartupDialogPrivate()
00136     {}
00137 
00138     int dialogType, dialogOptions;
00139 
00140     QFrame *pageTemplates, *pageOpenExisting, *pageOpenRecent;
00141     int pageTemplatesID;
00142     int pageOpenExistingID, pageOpenRecentID;
00143     int templatesSectionID_blank, templatesSectionID_import;
00144 #ifdef NO_DB_TEMPLATES
00145     int templatesSectionID_custom1, templatesSectionID_custom2;
00146 #endif
00147     QCheckBox *chkDoNotShow;
00148 
00149     //widgets for template tab:
00150     KJanusWidget* templatesWidget;
00151     QObject *templatesWidget_IconListBox;//helper
00152 
00153     QWidgetStack *viewBlankTempl;
00154     TemplatesPage *viewPersonalTempl;
00155     TemplatesPage *viewBusinessTempl;
00156 
00157     int result;
00158 
00159     QPixmap kexi_sqlite_icon, kexi_shortcut_icon;
00160 
00162     QString selectedTemplateKey;
00163 
00165     KexiDBConnectionSet *connSet;
00166     KexiStartupFileDialog *openExistingFileDlg; 
00167     KexiConnSelectorWidget *openExistingConnWidget;
00168     QString existingFileToOpen; 
00169     KexiDB::ConnectionData* selectedExistingConnection; 
00170 
00172     KexiProjectSet *recentProjects;
00173     KexiProjectSelectorWidget* prj_selector;
00174 
00176     bool singlePage : 1;
00177 };
00178 
00179 bool dlgSinglePage(int type)
00180 {
00181     return (type==KexiStartupDialog::Templates)
00182     || (type==KexiStartupDialog::OpenExisting)
00183     || (type==KexiStartupDialog::OpenRecent);
00184 }
00185 
00186 QString captionForDialogType(int type)
00187 {
00188     if (type==KexiStartupDialog::Templates)
00189         return i18n("Create Project");
00190     else if (type==KexiStartupDialog::OpenExisting)
00191         return i18n("Open Existing Project");
00192     else if (type==KexiStartupDialog::OpenRecent)
00193         return i18n("Open Recent Project");
00194 
00195     return i18n("Choose Project");
00196 }
00197 
00198 /*================================================================*/
00199 /*KexiStartupDialog::KexiStartupDialog(QWidget *parent, const char *name, KInstance* global,
00200     const QCString &format, const QString &nativePattern,
00201     const QString &nativeName, const DialogType &dialogType,
00202     const QCString& templateType) :
00203     KDialogBase(parent, name, true, i18n("Open Document"), KDialogBase::Ok | KDialogBase::Cancel,
00204     KDialogBase::Ok) {
00205 */
00206 KexiStartupDialog::KexiStartupDialog(
00207     int dialogType, int dialogOptions,
00208     KexiDBConnectionSet& connSet, KexiProjectSet& recentProjects,
00209     QWidget *parent, const char *name )
00210  : KDialogBase(
00211     dlgSinglePage(dialogType) ? Plain : Tabbed
00212     ,captionForDialogType(dialogType)
00213     ,Help | Ok | Cancel, Ok, parent, name )
00214  , d(new KexiStartupDialogPrivate())
00215 {
00216     d->recentProjects = &recentProjects;
00217     d->connSet = &connSet;
00218     d->dialogType = dialogType;
00219     d->dialogOptions = dialogOptions;
00220     d->singlePage = dlgSinglePage(dialogType);
00221 
00222     if (dialogType==OpenExisting) {//this dialog has "open" tab only!
00223         setIcon(DesktopIcon("fileopen"));
00224     } else {
00225         setIcon(d->kexi_sqlite_icon);
00226     }
00227 
00228     setSizeGripEnabled(true);
00229     int id=0;
00230     if (d->dialogType & Templates) {
00231         setupPageTemplates();
00232         d->pageTemplatesID = id++;
00233         d->templatesWidget->setFocus();
00234     }
00235     if (d->dialogType & OpenExisting) {
00236         setupPageOpenExisting();
00237         d->pageOpenExistingID = id++;
00238         if (d->singlePage)
00239             d->openExistingConnWidget->setFocus();
00240     }
00241 #ifdef KEXI_STARTUP_SHOW_RECENT
00242     if (d->dialogType & OpenRecent) {
00243         setupPageOpenRecent();
00244         d->pageOpenRecentID = id++;
00245         if (d->singlePage)
00246             d->prj_selector->setFocus();
00247     }
00248 #endif
00249 
00250     if (!d->singlePage) {
00251         connect(this, SIGNAL(aboutToShowPage(QWidget*)), this, SLOT(tabShown(QWidget*)));
00252         d->templatesWidget->setFocus();
00253     }
00254     showPage(0);
00255     adjustSize();
00256 }
00257 
00258 KexiStartupDialog::~KexiStartupDialog()
00259 {
00260     delete d;
00261 }
00262 
00263 bool KexiStartupDialog::shouldBeShown()
00264 {
00265     KGlobal::config()->setGroup("Startup");
00266     return KGlobal::config()->readBoolEntry("ShowStartupDialog",true);
00267 }
00268 
00269 void KexiStartupDialog::show()
00270 {
00271     //just some cleanup
00272     d->selectedTemplateKey=QString::null;
00273     d->existingFileToOpen=QString::null;
00274     d->result=-1;
00275 
00276     KDialog::centerOnScreen(this);
00277     KDialogBase::show();
00278 }
00279 
00280 int KexiStartupDialog::result() const
00281 {
00282     return d->result;
00283 }
00284 
00285 void KexiStartupDialog::done(int r)
00286 {
00287     if (d->result!=-1) //already done!
00288         return;
00289 
00290 //  kdDebug() << "KexiStartupDialog::done(" << r << ")" << endl;
00291     updateSelectedTemplateKeyInfo();
00292 
00293     if (r==QDialog::Rejected) {
00294         d->result = CancelResult;
00295     } else {
00296         const int idx = activePageIndex();
00297         if (idx == d->pageTemplatesID) {
00298             d->result = TemplateResult;
00299         }
00300         else if (idx == d->pageOpenExistingID) {
00301             // return file or connection:
00302             if (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased) {
00303                 if (!d->openExistingFileDlg->checkFileName())
00304                     return;
00305                 d->existingFileToOpen = d->openExistingFileDlg->currentFileName();
00306 //              d->existingFileToOpen = d->openExistingFileDlg->currentURL().path();
00307                 d->selectedExistingConnection = 0;
00308             } else {
00309                 d->existingFileToOpen = QString::null;
00310                 d->selectedExistingConnection
00311                     = d->openExistingConnWidget->selectedConnectionData();
00312             }
00313             d->result = OpenExistingResult;
00314         }
00315         else {
00316             d->result = OpenRecentResult;
00317         }
00318     }
00319 
00320     //save settings
00321     KGlobal::config()->setGroup("Startup");
00322     if (d->openExistingConnWidget)
00323         KGlobal::config()->writeEntry("OpenExistingType", 
00324         (d->openExistingConnWidget->selectedConnectionType() == KexiConnSelectorWidget::FileBased) 
00325             ? "File" : "Server");
00326     if (d->chkDoNotShow)
00327         KGlobal::config()->writeEntry("ShowStartupDialog",!d->chkDoNotShow->isChecked());
00328 
00329     KGlobal::config()->sync();
00330 
00331     KDialogBase::done(r);
00332 }
00333 
00334 void KexiStartupDialog::reject()
00335 {
00336 //  d->result = CancelResult;
00337     KDialogBase::reject();
00338 }
00339 
00340 void KexiStartupDialog::setupPageTemplates()
00341 {
00342     d->pageTemplates = addPage( i18n("&Create Project") );
00343     QVBoxLayout *lyr = new QVBoxLayout( d->pageTemplates, 0, KDialogBase::spacingHint() );
00344 
00345     d->templatesWidget = new KJanusWidget(
00346         d->pageTemplates, "templatesWidget", KJanusWidget::IconList);
00347     {//aaa! dirty hack
00348         d->templatesWidget_IconListBox = d->templatesWidget->child(0,"KListBox");
00349         if (d->templatesWidget_IconListBox)
00350             d->templatesWidget_IconListBox->installEventFilter(this);
00351     }
00352     lyr->addWidget(d->templatesWidget);
00353     connect(d->templatesWidget, SIGNAL(aboutToShowPage(QWidget*)), this, SLOT(templatesPageShown(QWidget*)));
00354 
00355     if (d->dialogOptions & CheckBoxDoNotShowAgain) {
00356         d->chkDoNotShow = new QCheckBox(i18n("Don't show me this dialog again"), d->pageTemplates, "chkDoNotShow");
00357         lyr->addWidget(d->chkDoNotShow);
00358     }
00359 
00360     //template groups:
00361     QFrame *templPageFrame;
00362     QVBoxLayout *tmplyr;
00363     QLabel *lbl_blank;
00364     int itemID = 0; //used just to set up templatesSectionID_*
00365 
00366     //- page "blank db"
00367     d->templatesSectionID_blank = itemID++;
00368     QString clickMsg( "\n\n" + i18n("Click \"OK\" button to proceed.") );
00369     templPageFrame = d->templatesWidget->addPage(
00370         i18n("Blank Database"), i18n("New Blank Database Project"), DesktopIcon("empty") );
00371     tmplyr = new QVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
00372     lbl_blank = new QLabel( 
00373         i18n("Kexi will create a new blank database project.")+clickMsg, templPageFrame );
00374     lbl_blank->setAlignment(Qt::AlignAuto|Qt::AlignTop|Qt::WordBreak);
00375     lbl_blank->setMargin(0);
00376     tmplyr->addWidget( lbl_blank );
00377     tmplyr->addStretch(1);
00378 
00379     //- page "import db"
00380     d->templatesSectionID_import = itemID++;
00381     templPageFrame = d->templatesWidget->addPage(
00382         i18n("Import Existing\nDatabase"), i18n("Import Existing Database as New Database Project"), 
00383         DesktopIcon("database_import") );
00384     tmplyr = new QVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
00385     lbl_blank = new QLabel( 
00386         i18n("Kexi will import the structure and data of an existing database as a new database project.")
00387         +clickMsg, templPageFrame );
00388     lbl_blank->setAlignment(Qt::AlignAuto|Qt::AlignTop|Qt::WordBreak);
00389     lbl_blank->setMargin(0);
00390     tmplyr->addWidget( lbl_blank );
00391     tmplyr->addStretch(1);
00392 
00393 #ifdef KEXI_STARTUP_SHOW_TEMPLATES
00394     //- page "personal db"
00395     d->templatesSectionID_custom1 = itemID++;
00396 /*later
00397     templPageFrame = d->templatesWidget->addPage (
00398         i18n("Personal Databases"), i18n("New Personal Database Project Templates"), DesktopIcon("folder_home") );
00399     tmplyr = new QVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
00400     d->viewPersonalTempl = new TemplatesPage( Vertical, templPageFrame, "personal_page" );
00401     tmplyr->addWidget( d->viewPersonalTempl );
00402     connect(d->viewPersonalTempl->templates,SIGNAL(doubleClicked(QIconViewItem*)),this,SLOT(templateItemExecuted(QIconViewItem*)));
00403     connect(d->viewPersonalTempl->templates,SIGNAL(returnPressed(QIconViewItem*)),this,SLOT(templateItemExecuted(QIconViewItem*)));
00404     connect(d->viewPersonalTempl->templates,SIGNAL(currentChanged(QIconViewItem*)),this,SLOT(templateItemSelected(QIconViewItem*)));
00405 */
00406 
00407     //- page "business db"
00408     d->templatesSectionID_custom2 = itemID++;
00409 /*later
00410     templPageFrame = d->templatesWidget->addPage (
00411         i18n("Business Databases"), i18n("New Business Database Project Templates"),
00412         DesktopIcon( "business_user" ));
00413     tmplyr = new QVBoxLayout(templPageFrame, 0, KDialogBase::spacingHint());
00414     d->viewBusinessTempl = new TemplatesPage( Vertical, templPageFrame, "business_page" );
00415     tmplyr->addWidget( d->viewBusinessTempl );
00416     connect(d->viewBusinessTempl->templates,SIGNAL(doubleClicked(QIconViewItem*)),this,SLOT(templateItemExecuted(QIconViewItem*)));
00417     connect(d->viewBusinessTempl->templates,SIGNAL(returnPressed(QIconViewItem*)),this,SLOT(templateItemExecuted(QIconViewItem*)));
00418     connect(d->viewBusinessTempl->templates,SIGNAL(currentChanged(QIconViewItem*)),this,SLOT(templateItemSelected(QIconViewItem*)));
00419 */
00420 #endif //KEXI_STARTUP_SHOW_TEMPLATES
00421 }
00422 
00423 void KexiStartupDialog::templatesPageShown(QWidget *page)
00424 {
00425     int idx = d->templatesWidget->pageIndex(page);
00426 //  KIconView *templ = 0;
00427     if (idx==d->templatesSectionID_blank) {//blank
00428 //      kdDebug() << "blank" << endl;
00429     }
00430     else if (idx==d->templatesSectionID_import) {
00431     }
00432 #ifdef KEXI_STARTUP_SHOW_TEMPLATES
00433     else if (idx==d->templatesSectionID_custom1) {//personal
00434         templ = d->viewPersonalTempl->templates;
00435         if (templ->count()==0) {
00436             //add items (on demand):
00437             d->viewPersonalTempl->addItem("cd_catalog", i18n("CD Catalog"),
00438                 i18n("Easy-to-use database for storing information about your CD collection."),
00439                 DesktopIcon("cdrom_unmount"));
00440             d->viewPersonalTempl->addItem("expenses", i18n("Expenses"),
00441                 i18n("A database for managing your personal expenses."),
00442                 DesktopIcon("kcalc"));
00443             d->viewPersonalTempl->addItem("image_gallery", i18n("Image Gallery"),
00444                 i18n("A database for archiving your image collection in a form of gallery."),
00445                 DesktopIcon("icons"));
00446         }
00447     }
00448     else if (idx==d->templatesSectionID_custom2) {//business
00449         templ = d->viewBusinessTempl->templates;
00450         if (templ->count()==0) {
00451             //add items (on demand):
00452             d->viewBusinessTempl->addItem("address_book", i18n("Address Book"),
00453                 i18n("A database that offers you a contact information"),
00454                 DesktopIcon("contents"));
00455         }
00456     }
00457 #endif
00458     updateDialogOKButton(d->pageTemplates);
00459 }
00460 
00461 void KexiStartupDialog::templateItemSelected(QIconViewItem *)
00462 {
00463     updateDialogOKButton(d->pageTemplates);
00464 }
00465 
00466 void KexiStartupDialog::templateItemExecuted(QIconViewItem *item)
00467 {
00468     if (!item)
00469         return;
00470     updateSelectedTemplateKeyInfo();
00471 #ifndef NO_DB_TEMPLATES
00472     accept();
00473 #endif
00474 }
00475 
00476 void KexiStartupDialog::updateSelectedTemplateKeyInfo()
00477 {
00478     if (activePageIndex()!=d->pageTemplatesID) {//not a 'new db' tab is selected
00479         d->selectedTemplateKey=QString::null;
00480         return;
00481     }
00482     QIconViewItem *item;
00483     if (d->templatesWidget->activePageIndex()==d->templatesSectionID_blank) {
00484         d->selectedTemplateKey = "blank";
00485     }
00486     else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_import) {
00487         d->selectedTemplateKey = "import";
00488     }
00489 #ifdef NO_DB_TEMPLATES
00490     else if (d->templatesWidget->activePageIndex()==d->templatesSectionID_custom1) {
00491         item = d->viewPersonalTempl->templates->currentItem();
00492         if (!item) {
00493             d->selectedTemplateKey=QString::null;
00494             return;
00495         }
00496         d->selectedTemplateKey=QString("personal/")+static_cast<TemplateItem*>(item)->key;
00497     }
00498     else  if (d->templatesWidget->activePageIndex()==d->templatesSectionID_custom2) {
00499         item = d->viewBusinessTempl->templates->currentItem();
00500         if (!item) {
00501             d->selectedTemplateKey=QString::null;
00502             return;
00503         }
00504         d->selectedTemplateKey=QString("business/")+static_cast<TemplateItem*>(item)->key;
00505     }
00506 #endif
00507 }
00508 
00509 void KexiStartupDialog::tabShown(QWidget *w)
00510 {
00511 //  kdDebug() << "KexiStartupDialog::tabShown " << (long)w << " "<< long(d->pageTemplates)<<endl;
00512 
00513     updateDialogOKButton(w);
00514 
00515     if (w==d->pageOpenExisting) {
00516         d->openExistingConnWidget->setFocus();
00517     }
00518 }
00519 
00520 void KexiStartupDialog::updateDialogOKButton(QWidget *w)
00521 {
00522     if (!w) {
00523         int idx = activePageIndex();
00524         if (idx==d->pageTemplatesID)
00525             w = d->pageTemplates;
00526         else if (idx==d->pageOpenExistingID)
00527             w = d->pageOpenExisting;
00528         else if (idx==d->pageOpenRecentID)
00529             w = d->pageOpenRecent;
00530 
00531         if (!w)
00532             return;
00533     }
00534     bool enable = true;
00535     if (w==d->pageTemplates) {
00536         int t_id = d->templatesWidget->activePageIndex();
00537 #ifdef NO_DB_TEMPLATES
00538         enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import);
00539 #else
00540         enable = (t_id==d->templatesSectionID_blank || d->templatesSectionID_import
00541             || (t_id==d->templatesSectionID_custom1 && d->viewPersonalTempl->templates->currentItem()!=0) 
00542             || (t_id==d->templatesSectionID_custom1 && d->viewBusinessTempl->templates->currentItem()!=0));
00543 #endif
00544     }
00545     else if (w==d->pageOpenExisting) {
00546 //      enable = !d->openExistingFileDlg->currentURL().path().isEmpty();
00547         enable = 
00548             (d->openExistingConnWidget->selectedConnectionType()==KexiConnSelectorWidget::FileBased)
00549             ? !d->openExistingFileDlg->currentFileName().isEmpty()
00550             : (bool)d->openExistingConnWidget->selectedConnectionData();
00551     }
00552     else if (w==d->pageOpenRecent) {
00553         enable = (d->prj_selector->selectedProjectData()!=0);
00554     }
00555     enableButton(Ok,enable);
00556 }
00557 
00558 QString KexiStartupDialog::selectedTemplateKey() const
00559 {
00560     return d->selectedTemplateKey;
00561 }
00562 
00563 void KexiStartupDialog::setupPageOpenExisting()
00564 {
00565     if (d->singlePage)
00566         d->pageOpenExisting = plainPage();
00567     else
00568         d->pageOpenExisting = addPage( i18n("Open &Existing Project") );
00569     QVBoxLayout *lyr = new QVBoxLayout( d->pageOpenExisting, 0, KDialogBase::spacingHint() );
00570 
00571     d->openExistingConnWidget = new KexiConnSelectorWidget(*d->connSet, 
00572         ":OpenExistingOrCreateNewProject",
00573         d->pageOpenExisting, "KexiConnSelectorWidget");
00574     d->openExistingConnWidget->hideConnectonIcon();
00575     lyr->addWidget( d->openExistingConnWidget );
00576     if (KGlobal::config()->readEntry("OpenExistingType","File")=="File")
00577         d->openExistingConnWidget->showSimpleConn();
00578     else {
00579         d->openExistingConnWidget->showSimpleConn();
00580 #ifdef KEXI_SERVER_SUPPORT 
00581         d->openExistingConnWidget->showAdvancedConn();
00582 #endif
00583     }
00584     d->openExistingFileDlg = d->openExistingConnWidget->m_fileDlg;
00585     connect(d->openExistingFileDlg,SIGNAL(accepted()),this,SLOT(accept()));
00586     connect(d->openExistingConnWidget,SIGNAL(connectionItemExecuted(ConnectionDataLVItem*)),
00587         this,SLOT(connectionItemForOpenExistingExecuted(ConnectionDataLVItem*)));
00588     connect(d->openExistingConnWidget,SIGNAL(connectionItemHighlighted(ConnectionDataLVItem*)),
00589         this,SLOT(connectionItemForOpenExistingHighlighted(ConnectionDataLVItem*)));
00590 }
00591 
00592 void KexiStartupDialog::connectionItemForOpenExistingExecuted(ConnectionDataLVItem *item)
00593 {
00594     if (!item)
00595         return;
00596     accept();
00597 }
00598 
00599 void KexiStartupDialog::connectionItemForOpenExistingHighlighted(ConnectionDataLVItem *item)
00600 {
00601     actionButton(KDialogBase::Ok)->setEnabled(item);
00602 }
00603 
00604 void KexiStartupDialog::slotOk() {
00605 //  kdDebug()<<"KexiStartupDialog::slotOk()"<<endl;
00606     if (activePageIndex()==d->pageOpenExistingID) {
00607         if (d->openExistingFileDlg) {
00608             if (d->openExistingFileDlg->okButton())
00609                 d->openExistingFileDlg->okButton()->animateClick();
00610 //          return;
00611         }
00612     }
00613     KDialogBase::slotOk();
00614 }
00615 
00616 void KexiStartupDialog::showSimpleConnForOpenExisting()
00617 {
00618 //  kdDebug() << "simple" << endl;
00619     d->openExistingConnWidget->showSimpleConn();
00620 }
00621 
00622 void KexiStartupDialog::showAdvancedConnForOpenExisting()
00623 {
00624 //  kdDebug() << "adv" << endl;
00625     d->openExistingConnWidget->showAdvancedConn();
00626 }
00627 
00628 QString KexiStartupDialog::selectedExistingFile() const
00629 {
00630 //  kdDebug() << activePageIndex() << " " << d->openExistingFileDlg->isVisible()
00631 //      << ": " << d->existingFileToOpen << endl;
00632     return d->existingFileToOpen;
00633 }
00634 
00635 KexiDB::ConnectionData* KexiStartupDialog::selectedExistingConnection() const
00636 {
00637     return d->selectedExistingConnection;
00638 }
00639 
00640 void KexiStartupDialog::existingFileSelected(const QString &f)
00641 {
00642     if (f.isEmpty())
00643         return;
00644     d->existingFileToOpen=f;
00645     updateDialogOKButton(d->openExistingFileDlg);
00646 }
00647 
00648 void KexiStartupDialog::setupPageOpenRecent()
00649 {
00650 #ifdef KEXI_STARTUP_SHOW_RECENT
00651     d->pageOpenRecent = addPage( i18n("Open &Recent Project") );
00652     QVBoxLayout *lyr = new QVBoxLayout( d->pageOpenRecent, 0, KDialogBase::spacingHint() );
00653     lyr->addWidget( d->prj_selector = new KexiProjectSelectorWidget(
00654         d->pageOpenRecent, "prj_selector", d->recentProjects ) );
00655     connect(d->prj_selector,SIGNAL(projectExecuted(KexiProjectData*)),
00656         this,SLOT(recentProjectItemExecuted(KexiProjectData*)));
00657 #endif
00658 }
00659 
00660 KexiProjectData* KexiStartupDialog::selectedProjectData() const
00661 {
00662     if (activePageIndex()==d->pageOpenRecentID) {
00663         return d->prj_selector->selectedProjectData();
00664     }
00665     return 0;
00666 }
00667 
00668 void KexiStartupDialog::recentProjectItemExecuted(KexiProjectData *data)
00669 {
00670     updateDialogOKButton(d->pageOpenRecent);
00671     if (!data)
00672         return;
00673     accept();
00674 }
00675 
00677 bool KexiStartupDialog::eventFilter( QObject *o, QEvent *e )
00678 {
00679     if (o==d->templatesWidget_IconListBox && d->templatesWidget_IconListBox) {
00680         if (e->type()==QEvent::KeyPress 
00681             && (static_cast<QKeyEvent*>(e)->key()==Key_Enter || static_cast<QKeyEvent*>(e)->key()==Key_Return)
00682             || e->type()==QEvent::MouseButtonDblClick) 
00683         {
00684             const int t_id = d->templatesWidget->activePageIndex();
00685             if (t_id==d->templatesSectionID_blank || t_id==d->templatesSectionID_import) {
00686                 accept();
00687             }
00688         }
00689     }
00690     return KDialogBase::eventFilter(o,e);
00691 }
00692 
00693 // internal reimplementation
00694 int KexiStartupDialog::activePageIndex() const
00695 {
00696     if (!d->singlePage) {
00697 //      kdDebug() << "int KexiStartupDialog::activePageIndex()" << KDialogBase::activePageIndex() << endl;
00698         return KDialogBase::activePageIndex();
00699     }
00700     kdDebug() << "int KexiStartupDialog::activePageIndex() == " << 0 << endl;
00701     return 0; //there is always "plain page" #0 selected
00702 }
00703 
00704 #include "KexiStartupDialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys