Parent: [8f1f2c] (diff)

Child: [a5efd7] (diff)

Download this file

main.cpp    331 lines (287 with data), 8.8 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#ifndef lint
static char rcsid[] = "@(#$Id: main.cpp,v 1.58 2007-01-08 15:21:32 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include <unistd.h>
//#define WITH_KDE
#ifdef WITH_KDE
#include <kapplication.h>
#include <kmainwindow.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#else
#include <qapplication.h>
#include <qtranslator.h>
#endif
#include <qtextcodec.h>
#include <qthread.h>
#include <qtimer.h>
#include <qmessagebox.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include "rcldb.h"
#include "rclconfig.h"
#include "pathut.h"
#include "recoll.h"
#include "smallut.h"
#include "rclinit.h"
#include "debuglog.h"
#ifdef WITH_KDE
#include "rclversion.h"
#endif
#include "rclmain_w.h"
#include "ssearch_w.h"
#include "guiutils.h"
#ifdef RCL_USE_ASPELL
#include "rclaspell.h"
#endif
#ifdef WITH_KDE
static const char description[] =
I18N_NOOP("A KDE fulltext search application");
static KCmdLineOptions options[] =
{
// { "+[URL]", I18N_NOOP( "Document to open" ), 0 },
KCmdLineLastOption
};
#endif
const string recoll_datadir = RECOLL_DATADIR;
RclConfig *rclconfig;
Rcl::Db *rcldb;
#ifdef RCL_USE_ASPELL
Aspell *aspell;
#endif
RclHistory *g_dynconf;
int recollNeedsExit;
static string dbdir;
static RclMain *mainWindow;
static string recollsharedir;
bool maybeOpenDb(string &reason, bool force)
{
if (!rcldb) {
reason = "Internal error: db not created";
return false;
}
int qopts = Rcl::Db::QO_NONE;
if (prefs.queryStemLang.length() > 0)
qopts |= Rcl::Db::QO_STEM;
if (force)
rcldb->close();
rcldb->rmQueryDb("");
for (list<string>::const_iterator it = prefs.activeExtraDbs.begin();
it != prefs.activeExtraDbs.end(); it++) {
LOGDEB(("main: adding [%s]\n", it->c_str()));
rcldb->addQueryDb(*it);
}
if (!rcldb->isopen() && !rcldb->open(dbdir, Rcl::Db::DbRO, qopts)) {
reason = "Could not open database in " +
dbdir + " wait for indexing to complete?";
return false;
}
rcldb->setAbstractParams(-1, prefs.syntAbsLen, prefs.syntAbsCtx);
return true;
}
static void recollCleanup()
{
LOGDEB(("recollCleanup: writing settings\n"));
rwSettings(true);
LOGDEB2(("recollCleanup: stopping idx thread\n"));
stop_idxthread();
LOGDEB2(("recollCleanup: closing database\n"));
delete rcldb;
rcldb = 0;
delete rclconfig;
rclconfig = 0;
#ifdef RCL_USE_ASPELL
delete aspell;
aspell = 0;
#endif
LOGDEB2(("recollCleanup: done\n"));
}
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;
}
extern void qInitImages_recoll();
static const char *thisprog;
static int op_flags;
#define OPT_MOINS 0x1
#define OPT_h 0x4
#define OPT_c 0x20
static const char usage [] =
"\n"
"recoll [-h] [-c <configdir>]\n"
" -h : Print help and exit\n"
" -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
;
static void
Usage(void)
{
FILE *fp = (op_flags & OPT_h) ? stdout : stderr;
fprintf(fp, "%s: Usage: %s", thisprog, usage);
exit((op_flags & OPT_h)==0);
}
int main(int argc, char **argv)
{
#ifdef WITH_KDE
KAboutData about("recoll", I18N_NOOP("Recoll"), rclversion, description,
KAboutData::License_GPL, "(C) 2006 Jean-Francois Dockes", 0, 0, "jean-francois.dockes@wanadoo.fr");
about.addAuthor( "Jean-Francois Dockes", 0,
"jean-francois.dockes@wanadoo.fr" );
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions( options );
KApplication app;
#else
QApplication app(argc, argv);
#endif
// fprintf(stderr, "Application created\n");
string a_config;
thisprog = argv[0];
argc--; argv++;
while (argc > 0 && **argv == '-') {
(*argv)++;
if (!(**argv))
Usage();
while (**argv)
switch (*(*argv)++) {
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
a_config = *(++argv);
argc--; goto b1;
case 'h': op_flags |= OPT_h; Usage();break;
}
b1: argc--; argv++;
}
// Translation file for Qt
QTranslator qt( 0 );
qt.load( QString( "qt_" ) + QTextCodec::locale(), "." );
app.installTranslator( &qt );
// Translations for Recoll
string translatdir = path_cat(recoll_datadir, "translations");
QTranslator translator( 0 );
// QTextCodec::locale() returns $LANG
translator.load( QString("recoll_") + QTextCodec::locale(),
translatdir.c_str() );
app.installTranslator( &translator );
// fprintf(stderr, "Translations installed\n");
string reason;
rclconfig = recollinit(recollCleanup, sigcleanup, reason, &a_config);
if (!rclconfig || !rclconfig->ok()) {
QString msg = app.translate("Main", "Configuration problem: ");
msg += QString::fromUtf8(reason.c_str());
QMessageBox::critical(0, "Recoll", msg);
exit(1);
}
// fprintf(stderr, "recollinit done\n");
#ifdef RCL_USE_ASPELL
aspell = new Aspell(rclconfig);
aspell->init(reason);
if (!aspell || !aspell->ok()) {
LOGDEB(("Aspell speller creation failed %s\n", reason.c_str()));
aspell = 0;
}
#endif
string historyfile = path_cat(rclconfig->getConfDir(), "history");
g_dynconf = new RclHistory(historyfile);
if (!g_dynconf || !g_dynconf->ok()) {
QString msg = app.translate("Main", "Configuration problem (dynconf");
QMessageBox::critical(0, "Recoll", msg);
exit(1);
}
// fprintf(stderr, "History done\n");
rwSettings(false);
// fprintf(stderr, "Settings done\n");
// Create main window and set its size to previous session's
#ifdef WITH_KDE
#if 0
if (app.isRestored()) {
RESTORE(RclMain);
} else {
#endif
// no session.. just start up normally
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
/// @todo do something with the command line args here
qInitImages_recoll();
mainWindow = new RclMain;
app.setMainWidget( mainWindow );
mainWindow->show();
args->clear();
// }
#else
RclMain w;
mainWindow = &w;
#endif
if (prefs.mainwidth > 100) {
QSize s(prefs.mainwidth, prefs.mainheight);
mainWindow->resize(s);
}
mainWindow->sSearch->searchTypCMB->setCurrentItem(prefs.ssearchTyp);
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"));
exit(1);
}
rcldb = new Rcl::Db;
if (!maybeOpenDb(reason)) {
startindexing = 1;
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
break;
case 1: // Cancel
exit(0);
}
}
mainWindow->show();
if (prefs.startWithAdvSearchOpen)
mainWindow->showAdvSearchDialog();
if (prefs.startWithSortToolOpen)
mainWindow->showSortDialog();
// Connect exit handlers etc.. Beware, apparently this must come
// after mainWindow->show() , else the QMessageBox above never
// returns.
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
QTimer *timer = new QTimer(&app);
mainWindow->connect(timer, SIGNAL(timeout()),
mainWindow, SLOT(periodic100()));
timer->start(100);
app.connect(&app, SIGNAL(aboutToQuit()), mainWindow, SLOT(close()));
start_idxthread(*rclconfig);
// fprintf(stderr, "Go\n");
// Let's go
return app.exec();
}