KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

KexiStartupDialog.cpp 22KB

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