moved initial db open and possible message boxes from main.cpp to rclmain_w.cpp first post-init job to avoid random crashes apparently related to the dialogs being created before app.exec(). Exact cause not certain, but crashes gone...

This commit is contained in:
dockes 2010-01-07 08:34:21 +00:00
parent 8ddea418aa
commit c09593f7db
5 changed files with 60 additions and 45 deletions

View File

@ -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();
}

View File

@ -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));

View File

@ -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);

View File

@ -191,11 +191,17 @@ void SSearch::startSimpleSearch()
RefCntr<Rcl::SearchData> 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);

View File

@ -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);