more refactoring

This commit is contained in:
dockes 2006-01-23 13:32:06 +00:00
parent 21346df77b
commit 34ab3a7fed
8 changed files with 178 additions and 185 deletions

View File

@ -1,5 +1,21 @@
#include <stdio.h>
#include <unistd.h>
/*
* 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 <qthread.h>

View File

@ -1,20 +1,41 @@
#ifndef lint
static char rcsid[] = "@(#$Id: main.cpp,v 1.33 2006-01-22 18:46:41 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: main.cpp,v 1.34 2006-01-23 13:32:05 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 <unistd.h>
#include <qapplication.h>
//#define WITH_KDE
#ifdef WITH_KDE
#include <kapplication.h>
#endif
#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 <qsettings.h>
#include <qcheckbox.h>
@ -28,10 +49,23 @@ using Rcl::AdvSearchData;
#include "smallut.h"
#include "rclinit.h"
#include "debuglog.h"
#include "rclversion.h"
#include "rclmain.h"
#include "guiutils.h"
static const char *recoll_datadir = RECOLL_DATADIR;
#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;
@ -40,52 +74,6 @@ static string dbdir;
static RclMainBase *mainWindow;
static string recollsharedir;
/////////////////////////
// Global variables for user preferences. These are set in the user preference
// dialog and saved restored to the appropriate place in the qt settings
bool prefs_showicons;
int prefs_respagesize = 8;
QString prefs_reslistfontfamily;
int prefs_reslistfontsize;
QString prefs_queryStemLang;
int prefs_mainwidth;
int prefs_mainheight;
bool prefs_ssall;
QString prefs_htmlBrowser;
#define SETTING_RW(var, nm, tp, def) \
if (writing) { \
settings.writeEntry(nm , var); \
} else { \
var = settings.read##tp##Entry(nm, def); \
}
static void rwSettings(bool writing)
{
if (writing) {
if (!mainWindow)
return;
prefs_mainwidth = mainWindow->width();
prefs_mainheight = mainWindow->height();
prefs_ssall = mainWindow->sSearch->allTermsCB->isChecked();
}
QSettings settings;
settings.setPath("Recoll.org", "Recoll");
SETTING_RW(prefs_mainwidth, "/Recoll/geometry/width", Num, 590);
SETTING_RW(prefs_mainheight, "/Recoll/geometry/height", Num, 810);
SETTING_RW(prefs_ssall, "/Recoll/prefs/simpleSearchAll", Bool, false);
SETTING_RW(prefs_showicons, "/Recoll/prefs/reslist/showicons", Bool, true);
SETTING_RW(prefs_respagesize, "/Recoll/prefs/reslist/pagelen", Num, 8);
SETTING_RW(prefs_reslistfontfamily, "/Recoll/prefs/reslist/fontFamily", ,
"");
SETTING_RW(prefs_reslistfontsize, "/Recoll/prefs/reslist/fontSize", Num,
0);
SETTING_RW(prefs_queryStemLang, "/Recoll/prefs/query/stemLang", ,
"english");
}
bool maybeOpenDb(string &reason)
{
if (!rcldb) {
@ -102,6 +90,11 @@ bool maybeOpenDb(string &reason)
static void recollCleanup()
{
if (mainWindow) {
prefs.mainwidth = mainWindow->width();
prefs.mainheight = mainWindow->height();
prefs.ssall = mainWindow->sSearch->allTermsCB->isChecked();
}
rwSettings(true);
stop_idxthread();
delete rcldb;
@ -119,19 +112,26 @@ static void sigcleanup(int)
recollNeedsExit = 1;
}
extern void qInitImages_recoll();
int main( int argc, char ** argv )
{
#ifdef WITH_KDE
KApplication a(argc, argv, "recoll");
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 a(argc, argv);
QApplication app(argc, argv);
#endif
// translation file for Qt
// Translation file for Qt
QTranslator qt( 0 );
qt.load( QString( "qt_" ) + QTextCodec::locale(), "." );
a.installTranslator( &qt );
app.installTranslator( &qt );
// Translations for Recoll
string translatdir = path_cat(recoll_datadir, "translations");
@ -139,32 +139,52 @@ int main( int argc, char ** argv )
// QTextCodec::locale() returns $LANG
translator.load( QString("recoll_") + QTextCodec::locale(),
translatdir.c_str() );
a.installTranslator( &translator );
app.installTranslator( &translator );
rwSettings(false);
string reason;
rclconfig = recollinit(recollCleanup, sigcleanup, reason);
if (!rclconfig || !rclconfig->ok()) {
QString msg = a.translate("Main", "Configuration problem: ");
QString msg = app.translate("Main", "Configuration problem: ");
msg += reason;
QMessageBox::critical(0, "Recoll", msg);
exit(1);
}
// 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;
QSize s(prefs_mainwidth, prefs_mainheight);
w.resize(s);
#endif
QSize s(prefs.mainwidth, prefs.mainheight);
mainWindow->resize(s);
w.sSearch->allTermsCB->setChecked(prefs_ssall);
mainWindow->sSearch->allTermsCB->setChecked(prefs.ssall);
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",
a.translate("Main",
app.translate("Main",
"No db directory in configuration"));
exit(1);
}
@ -173,18 +193,19 @@ int main( int argc, char ** argv )
rcldb = new Rcl::Db;
// Connect exit handlers etc..
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
QTimer *timer = new QTimer(&a);
w.connect(timer, SIGNAL(timeout()), &w, SLOT(periodic100()));
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
QTimer *timer = new QTimer(&app);
mainWindow->connect(timer, SIGNAL(timeout()),
mainWindow, SLOT(periodic100()));
timer->start(100);
if (!rcldb->open(dbdir, Rcl::Db::DbRO)) {
startindexing = 1;
switch (QMessageBox::
question(0, "Recoll",
a.translate("Main", "Could not open database in ")+
app.translate("Main", "Could not open database in ")+
QString(dbdir) +
a.translate("Main",
app.translate("Main",
".\n"
"Click Cancel if you want to edit the configuration file before indexation starts, or Ok to let it proceed."),
"Ok",
@ -196,75 +217,10 @@ int main( int argc, char ** argv )
}
}
mainWindow->show();
start_idxthread(*rclconfig);
// Let's go
w.show();
return a.exec();
return app.exec();
}
const static char *htmlbrowserlist =
"opera konqueror firefox mozilla netscape";
// Search for and launch an html browser for the documentation. If the
// user has set a preference, we use it directly instead of guessing.
bool startHelpBrowser(const string &iurl)
{
string url;
if (iurl.empty()) {
url = path_cat(recoll_datadir, "doc");
url = path_cat(url, "usermanual.html");
url = string("file://") + url;
} else
url = iurl;
// If the user set a preference with an absolute path then things are
// simple
if (!prefs_htmlBrowser.isEmpty() && prefs_htmlBrowser.find('/') != -1) {
if (access(prefs_htmlBrowser.ascii(), X_OK) != 0) {
LOGERR(("startHelpBrowser: %s not found or not executable\n",
prefs_htmlBrowser.ascii()));
}
string cmd = string(prefs_htmlBrowser.ascii()) + " " + url + "&";
if (system(cmd.c_str()) == 0)
return true;
else
return false;
}
string searched;
if (prefs_htmlBrowser.isEmpty()) {
searched = htmlbrowserlist;
} else {
searched = prefs_htmlBrowser.ascii();
}
list<string> blist;
stringToTokens(searched, blist, " ");
const char *path = getenv("PATH");
if (path == 0)
path = "/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin";
list<string> pathl;
stringToTokens(path, pathl, ":");
// For each browser name, search path and exec/stop if found
for (list<string>::const_iterator bit = blist.begin();
bit != blist.end(); bit++) {
for (list<string>::const_iterator pit = pathl.begin();
pit != pathl.end(); pit++) {
string exefile = path_cat(*pit, *bit);
LOGDEB1(("startHelpBrowser: trying %s\n", exefile.c_str()));
if (access(exefile.c_str(), X_OK) == 0) {
string cmd = exefile + " " + url + "&";
if (system(cmd.c_str()) == 0) {
return true;
}
}
}
}
LOGERR(("startHelpBrowser: no html browser found. Looked for: %s\n",
searched.c_str()));
return false;
}

View File

@ -1,6 +1,22 @@
#ifndef lint
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.7 2006-01-19 12:01:42 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.8 2006-01-23 13:32:05 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 <string>

View File

@ -1,14 +1,22 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#ifndef lint
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.6 2006-01-23 13:32:06 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 <stdlib.h>
#include <sys/types.h>
@ -49,6 +57,7 @@ using std::pair;
#include "rclversion.h"
#include "sortseq.h"
#include "uiprefs.h"
#include "guiutils.h"
#include "rclmain.h"
#include "moc_rclmain.cpp"
@ -72,8 +81,8 @@ void RclMain::init()
sSearch->queryText->setFocus();
// Set result list font according to user preferences.
if (prefs_reslistfontfamily.length()) {
QFont nfont(prefs_reslistfontfamily, prefs_reslistfontsize);
if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
resList->setFont(nfont);
}
string historyfile = path_cat(rclconfig->getConfDir(), "history");
@ -281,9 +290,9 @@ void RclMain::startAdvSearch(Rcl::AdvSearchData sdata)
resList->m_winfirst = -1;
if (!rcldb->setQuery(sdata, prefs_queryStemLang.length() > 0 ?
if (!rcldb->setQuery(sdata, prefs.queryStemLang.length() > 0 ?
Rcl::Db::QO_STEM : Rcl::Db::QO_NONE,
prefs_queryStemLang.ascii()))
prefs.queryStemLang.ascii()))
return;
curPreview = 0;
@ -516,22 +525,22 @@ void RclMain::setUIPrefs()
if (!uiprefs)
return;
LOGDEB(("Recollmain::setUIPrefs\n"));
prefs_showicons = uiprefs->useIconsCB->isChecked();
prefs_respagesize = uiprefs->pageLenSB->value();
prefs.showicons = uiprefs->useIconsCB->isChecked();
prefs.respagesize = uiprefs->pageLenSB->value();
prefs_reslistfontfamily = uiprefs->reslistFontFamily;
prefs_reslistfontsize = uiprefs->reslistFontSize;
if (prefs_reslistfontfamily.length()) {
QFont nfont(prefs_reslistfontfamily, prefs_reslistfontsize);
prefs.reslistfontfamily = uiprefs->reslistFontFamily;
prefs.reslistfontsize = uiprefs->reslistFontSize;
if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
resList->setFont(nfont);
} else {
resList->setFont(this->font());
}
if (uiprefs->stemLangCMB->currentItem() == 0) {
prefs_queryStemLang = "";
prefs.queryStemLang = "";
} else {
prefs_queryStemLang = uiprefs->stemLangCMB->currentText();
prefs.queryStemLang = uiprefs->stemLangCMB->currentText();
}
}

View File

@ -1,6 +1,6 @@
#ifndef _RECOLL_H_INCLUDED_
#define _RECOLL_H_INCLUDED_
/* @(#$Id: recoll.h,v 1.11 2006-01-20 14:58:57 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: recoll.h,v 1.12 2006-01-23 13:32:06 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include "rclconfig.h"
@ -9,17 +9,10 @@
// Misc declarations in need of sharing between the UI files
extern bool maybeOpenDb(std::string &reason);
extern bool startHelpBrowser(const string& url = "");
extern RclConfig *rclconfig;
extern Rcl::Db *rcldb;
extern int recollNeedsExit;
class QString;
extern bool prefs_showicons;
extern int prefs_respagesize;
extern QString prefs_reslistfontfamily;
extern int prefs_reslistfontsize;
extern QString prefs_queryStemLang;
extern const std::string recoll_datadir;
#endif /* _RECOLL_H_INCLUDED_ */

View File

@ -8,7 +8,8 @@ HEADERS += rclmain.h
SOURCES += main.cpp \
rclmain.cpp \
idxthread.cpp \
plaintorich.cpp
plaintorich.cpp \
guiutils.cpp
FORMS = reslistb.ui \
recollmain.ui \
@ -42,7 +43,7 @@ unix {
DEFINES += RECOLL_DATADIR=\"/usr/local/share\"
LIBS += ../lib/librcl.a ../bincimapmime/libmime.a \
$(BSTATIC) -L/usr/local/lib -lxapian -L/usr/local/lib -liconv $(BDYNAMIC) \
-lz
-lkdecore -lz
INCLUDEPATH += ../common ../index ../query ../unac ../utils
POST_TARGETDEPS = ../lib/librcl.a

View File

@ -16,6 +16,7 @@
#include "debuglog.h"
#include "recoll.h"
#include "guiutils.h"
#include "pathut.h"
#include "docseq.h"
@ -170,7 +171,7 @@ void ResListBase::resultPageBack()
{
if (m_winfirst <= 0)
return;
m_winfirst -= 2 * prefs_respagesize;
m_winfirst -= 2 * prefs.respagesize;
showResultPage();
}
@ -192,7 +193,7 @@ void ResListBase::showResultPage()
// If we are already on the last page, nothing to do:
if (m_winfirst >= 0 &&
(m_winfirst + prefs_respagesize > resCnt)) {
(m_winfirst + prefs.respagesize > resCnt)) {
emit nextPageAvailable(false);
return;
}
@ -202,13 +203,13 @@ void ResListBase::showResultPage()
emit prevPageAvailable(false);
} else {
emit prevPageAvailable(true);
m_winfirst += prefs_respagesize;
m_winfirst += prefs.respagesize;
}
bool gotone = false;
reslistTE->clear();
int last = MIN(resCnt-m_winfirst, prefs_respagesize);
int last = MIN(resCnt-m_winfirst, prefs.respagesize);
// Insert results if any in result list window. We have to send
@ -256,7 +257,7 @@ void ResListBase::showResultPage()
result = "<p>";
string img_name;
if (prefs_showicons) {
if (prefs.showicons) {
string iconpath;
string iconname = rclconfig->getMimeIconName(doc.mimetype,
&iconpath);
@ -310,7 +311,7 @@ void ResListBase::showResultPage()
/*"<img align=\"left\" source=\"myimage\">"*/
"<b>No results found</b>"
"<br>"));
m_winfirst -= prefs_respagesize;
m_winfirst -= prefs.respagesize;
if (m_winfirst < 0)
m_winfirst = -1;
}
@ -331,7 +332,7 @@ void ResListBase::showResultPage()
if (m_winfirst < 0 ||
(m_winfirst >= 0 &&
m_winfirst + prefs_respagesize >= resCnt)) {
m_winfirst + prefs.respagesize >= resCnt)) {
emit nextPageAvailable(false);
} else {
emit nextPageAvailable(true);

View File

@ -15,18 +15,19 @@
#include "qmessagebox.h"
#include "recoll.h"
#include "guiutils.h"
void UIPrefsDialog::init()
{
// Entries per result page spinbox
pageLenSB->setValue(prefs_respagesize);
pageLenSB->setValue(prefs.respagesize);
// Show icons checkbox
useIconsCB->setChecked(prefs_showicons);
useIconsCB->setChecked(prefs.showicons);
// Result list font family and size
reslistFontFamily = prefs_reslistfontfamily;
reslistFontSize = prefs_reslistfontsize;
reslistFontFamily = prefs.reslistfontfamily;
reslistFontSize = prefs.reslistfontsize;
QString s;
if (prefs_reslistfontfamily.length() == 0) {
if (prefs.reslistfontfamily.length() == 0) {
reslistFontPB->setText(this->font().family() + "-" +
s.setNum(this->font().pointSize()));
} else {
@ -57,7 +58,7 @@ void UIPrefsDialog::init()
insertItem(QString::fromAscii(it->c_str(), it->length()));
i++;
if (cur == -1) {
if (!strcmp(prefs_queryStemLang.ascii(), it->c_str()))
if (!strcmp(prefs.queryStemLang.ascii(), it->c_str()))
cur = i;
}
}
@ -79,9 +80,9 @@ void UIPrefsDialog::showFontDialog()
{
bool ok;
QFont font;
if (prefs_reslistfontfamily.length()) {
font.setFamily(prefs_reslistfontfamily);
font.setPointSize(prefs_reslistfontsize);
if (prefs.reslistfontfamily.length()) {
font.setFamily(prefs.reslistfontfamily);
font.setPointSize(prefs.reslistfontsize);
}
font = QFontDialog::getFont(&ok, font, this );