Parent: [5ebcb0] (diff)

Child: [add9ba] (diff)

Download this file

main.cpp    145 lines (119 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef lint
static char rcsid[] = "@(#$Id: main.cpp,v 1.13 2005-11-06 15:07:09 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#include <unistd.h>
#include <qapplication.h>
#include <qtranslator.h>
#include <qtextcodec.h>
#include <qthread.h>
#include <qtimer.h>
#include <qmessagebox.h>
#include "rcldb.h"
using Rcl::AdvSearchData;
#include "rclconfig.h"
#include "pathut.h"
#include "recoll.h"
#include "smallut.h"
#include "wipedir.h"
#include "rclinit.h"
#include "recollmain.h"
RclConfig *rclconfig;
Rcl::Db *rcldb;
int recollNeedsExit;
string tmpdir;
void getQueryStemming(bool &dostem, std::string &stemlang)
{
string param;
if (rclconfig->getConfParam("querystemming", param))
dostem = ConfTree::stringToBool(param);
else
dostem = false;
if (!rclconfig->getConfParam("querystemminglanguage", stemlang))
stemlang = "english";
}
bool maybeOpenDb(string &reason)
{
if (!rcldb)
return false;
if (!rcldb->isopen()) {
string dbdir;
if (rclconfig->getConfParam(string("dbdir"), dbdir) == 0) {
reason = "No db directory in configuration";
return false;
}
dbdir = path_tildexpand(dbdir);
if (!rcldb->open(dbdir, Rcl::Db::DbRO)) {
reason = "Could not open database in " +
dbdir + " wait for indexing to complete?";
return false;
}
}
return true;
}
void recollCleanup()
{
stop_idxthread();
delete rcldb;
rcldb = 0;
delete rclconfig;
rclconfig = 0;
if (tmpdir.length()) {
wipedir(tmpdir);
rmdir(tmpdir.c_str());
tmpdir.erase();
}
}
static void sigcleanup(int)
{
// fprintf(stderr, "sigcleanup\n");
// Cant call exit from here, because the atexit cleanup does some
// thread stuff that we can't do from signal context.
// Just set a flag and let the watchdog timer do the work
recollNeedsExit = 1;
}
int main( int argc, char ** argv )
{
QApplication a(argc, argv);
QTranslator translator( 0 );
// QTextCodec::locale() return $LANG
translator.load( QString("recoll_") + QTextCodec::locale(), "." );
a.installTranslator( &translator );
RecollMain w;
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
QTimer *timer = new QTimer(&a);
w.connect(timer, SIGNAL(timeout()), &w, SLOT(periodic100()));
timer->start(100);
string reason;
rclconfig = recollinit(recollCleanup, sigcleanup, reason);
if (!rclconfig || !rclconfig->ok()) {
string msg = "Configuration problem: ";
msg += reason;
QMessageBox::critical(0, "Recoll",
QString(msg.c_str()));
exit(1);
}
string dbdir;
if (rclconfig->getConfParam(string("dbdir"), dbdir) == 0) {
// Note: this will have to be replaced by a call to a
// configuration buildin dialog for initial configuration
QMessageBox::critical(0, "Recoll",
QString("No db directory in configuration"));
exit(1);
}
if (!maketmpdir(tmpdir)) {
QMessageBox::critical(0, "Recoll",
QString("Cannot create temporary directory"));
exit(1);
}
dbdir = path_tildexpand(dbdir);
rcldb = new Rcl::Db;
if (!rcldb || !rcldb->open(dbdir, Rcl::Db::DbRO)) {
startindexing = 1;
QMessageBox::information(0, "Recoll",
QString("Could not open database in ") +
QString(dbdir) + ". Starting indexation");
}
start_idxthread(rclconfig);
return a.exec();
}