diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 3eae8274..2dd1c8a7 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -316,12 +316,8 @@ int main(int argc, char **argv) mainWindow->resize(s); } - mainWindow->sSearch->searchTypCMB->setCurrentItem(prefs.ssearchTyp); - mainWindow->sSearch->searchTypeChanged(prefs.ssearchTyp); string dbdir = rclconfig->getDbDir(); if (dbdir.empty()) { - // Note: this will have to be replaced by a call to a - // configuration buildin dialog for initial configuration QMessageBox::critical(0, "Recoll", app.translate("Main", "No db directory in configuration")); @@ -330,47 +326,11 @@ int main(int argc, char **argv) rcldb = new Rcl::Db(rclconfig); - bool needindexconfig = false; - if (!maybeOpenDb(reason)) { - - switch (QMessageBox:: -#if (QT_VERSION >= 0x030200) - question -#else - information -#endif - (0, "Recoll", - app.translate("Main", "Could not open database in ") + - QString::fromLocal8Bit(dbdir.c_str()) + - app.translate("Main", - ".\n" - "Click Cancel if you want to edit the configuration file before indexation starts, or Ok to let it proceed."), - "Ok", "Cancel", 0, 0)) { - - case 0: // Ok: indexing is going to start. - start_indexing(true); - break; - - case 1: // Cancel - needindexconfig = true; - break; - } - } - mainWindow->show(); - if (needindexconfig) { - startIndexingAfterConfig = 1; - mainWindow->showIndexConfig(); - } else { - if (prefs.startWithAdvSearchOpen) - mainWindow->showAdvSearchDialog(); - if (prefs.startWithSortToolOpen) - mainWindow->showSortDialog(); - } + QTimer::singleShot(0, mainWindow, SLOT(initDbOpen())); // Connect exit handlers etc.. Beware, apparently this must come - // after mainWindow->show() , else the QMessageBox above never - // returns. + // after mainWindow->show()? app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); app.connect(&app, SIGNAL(aboutToQuit()), mainWindow, SLOT(close())); @@ -378,6 +338,8 @@ int main(int argc, char **argv) // something to do. start_idxthread(*rclconfig); + mainWindow->sSearch->searchTypCMB->setCurrentItem(prefs.ssearchTyp); + mainWindow->sSearch->searchTypeChanged(prefs.ssearchTyp); if (op_flags & OPT_q) { SSearch::SSearchType stype; if (op_flags & OPT_o) { @@ -392,10 +354,7 @@ int main(int argc, char **argv) mainWindow->sSearch->searchTypCMB->setCurrentItem(int(stype)); mainWindow-> sSearch->setSearchString(QString::fromLocal8Bit(question.c_str())); - QTimer::singleShot(0, mainWindow->sSearch, SLOT(startSimpleSearch())); } - // fprintf(stderr, "Go\n"); - // Let's go return app.exec(); } diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index bbe05234..17f96cd6 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -302,6 +302,54 @@ void RclMain::init() } } +// This is called by a timer right after we come up. Try to open +// the database and talk to the user if we can't +void RclMain::initDbOpen() +{ + bool needindexconfig = false; + bool nodb = false; + string reason; + if (!maybeOpenDb(reason)) { + nodb = true; + switch (QMessageBox:: +#if (QT_VERSION >= 0x030200) + question +#else + information +#endif + (this, "Recoll", + qApp->translate("Main", "Could not open database in ") + + QString::fromLocal8Bit(rclconfig->getDbDir().c_str()) + + qApp->translate("Main", + ".\n" + "Click Cancel if you want to edit the configuration file before indexation starts, or Ok to let it proceed."), + "Ok", "Cancel", 0, 0)) { + + case 0: // Ok: indexing is going to start. + start_indexing(true); + break; + + case 1: // Cancel + needindexconfig = true; + break; + } + } + + if (needindexconfig) { + startIndexingAfterConfig = 1; + showIndexConfig(); + } else { + if (prefs.startWithAdvSearchOpen) + showAdvSearchDialog(); + if (prefs.startWithSortToolOpen) + showSortDialog(); + // If we have something in the search entry, it comes from a + // command line argument + if (!nodb && sSearch->hasSearchString()) + QTimer::singleShot(0, sSearch, SLOT(startSimpleSearch())); + } +} + void RclMain::setStemLang(int id) { LOGDEB(("RclMain::setStemLang(%d)\n", id)); diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index 04587c9e..14121823 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -110,6 +110,7 @@ public slots: // Prefs menu about to show, set the checked lang entry virtual void adjustPrefsMenu(); virtual void catgFilter(int); + virtual void initDbOpen(); signals: void stemLangChanged(const QString& lang); diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index 24081d15..a0f24011 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -191,11 +191,17 @@ void SSearch::startSimpleSearch() RefCntr rsdata(sdata); emit startSearch(rsdata); } + void SSearch::setSearchString(const QString& txt) { queryText->setEditText(txt); } +bool SSearch::hasSearchString() +{ + return !queryText->lineEdit()->text().isEmpty(); +} + void SSearch::setAnyTermMode() { searchTypCMB->setCurrentItem(SST_ANY); diff --git a/src/qtgui/ssearch_w.h b/src/qtgui/ssearch_w.h index 2598caa7..3c723fb3 100644 --- a/src/qtgui/ssearch_w.h +++ b/src/qtgui/ssearch_w.h @@ -61,6 +61,7 @@ public: virtual void setAnyTermMode(); virtual void completion(); virtual bool eventFilter(QObject *target, QEvent *event); + virtual bool hasSearchString(); public slots: virtual void searchTextChanged(const QString & text);