allow setting stemlang from prefs menu

This commit is contained in:
dockes 2007-08-01 07:55:03 +00:00
parent aca8b72444
commit 4cffc83104
5 changed files with 134 additions and 9 deletions

View File

@ -82,18 +82,19 @@
<separator/>
<action name="fileExitAction"/>
</item>
<item text="&amp;Tools" name="Tools">
<item text="&amp;Tools" name="toolsMenu">
<action name="toolsDoc_HistoryAction"/>
<action name="toolsAdvanced_SearchAction"/>
<action name="toolsSort_parametersAction"/>
<action name="toolsSpellAction"/>
</item>
<item text="&amp;Preferences" name="Preferences">
<item text="&amp;Preferences" name="preferencesMenu">
<action name="preferencesQuery_PrefsAction"/>
<action name="extIdxAction"/>
<separator/>
</item>
<separator/>
<item text="&amp;Help" name="Help">
<item text="&amp;Help" name="helpMenu">
<action name="userManualAction"/>
<separator/>
<action name="helpAbout_RecollAction"/>

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.36 2007-07-20 14:32:55 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.37 2007-08-01 07:55:03 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -107,10 +107,42 @@ void RclMain::init()
resList->setFont(nfont);
}
// Stemming language menu
m_idNoStem = preferencesMenu->insertItem(tr("(no stemming)"));
m_stemLangToId[tr("(no stemming)")] = m_idNoStem;
LOGDEB(("idNoStem: %d\n", m_idNoStem));
// Can't get the stemming languages from the db at this stage as
// db not open yet (the case where it does not even exist makes
// things complicated). So get the languages from the config
// instead
string slangs;
list<string> langs;
if (rclconfig->getConfParam("indexstemminglanguages", slangs)) {
stringToStrings(slangs, langs);
} else {
QMessageBox::warning(0, "Recoll",
tr("error retrieving stemming languages"));
}
int curid = m_idNoStem, id; // Menu ids are negative integers
for (list<string>::const_iterator it = langs.begin();
it != langs.end(); it++) {
QString qlang = QString::fromAscii(it->c_str(), it->length());
id = preferencesMenu->insertItem(qlang);
m_stemLangToId[qlang] = id;
if (prefs.queryStemLang == qlang) {
curid = id;
}
}
preferencesMenu->setItemChecked(curid, true);
// Connections
connect(sSearch, SIGNAL(startSearch(RefCntr<Rcl::SearchData>)),
this, SLOT(startSearch(RefCntr<Rcl::SearchData>)));
connect(preferencesMenu, SIGNAL(activated(int)),
this, SLOT(setStemLang(int)));
connect(preferencesMenu, SIGNAL(aboutToShow()),
this, SLOT(adjustPrefsMenu()));
// signals and slots connections
connect(sSearch, SIGNAL(clearSearch()),
this, SLOT(resetSearch()));
@ -190,6 +222,68 @@ void RclMain::init()
}
}
void RclMain::setStemLang(int id)
{
LOGDEB(("RclMain::setStemLang(%d)\n", id));
// Check that the menu entry is for a stemming language change
// (might also be "show prefs" etc.
bool isLangId = false;
for (map<QString, int>::const_iterator it = m_stemLangToId.begin();
it != m_stemLangToId.end(); it++) {
if (id == it->second)
isLangId = true;
}
if (!isLangId)
return;
// Set the "checked" item state for lang entries
for (map<QString, int>::const_iterator it = m_stemLangToId.begin();
it != m_stemLangToId.end(); it++) {
preferencesMenu->setItemChecked(it->second, false);
}
preferencesMenu->setItemChecked(id, true);
// Retrieve language value (also handle special cases), set prefs,
// notify that we changed
QString lang;
if (id == m_idNoStem) {
lang = "";
} else {
lang = preferencesMenu->text(id);
}
prefs.queryStemLang = lang;
LOGDEB(("RclMain::setStemLang(%d): lang [%s]\n",
id, (const char *)prefs.queryStemLang.ascii()));
rwSettings(true);
emit stemLangChanged(lang);
}
// Set the checked stemming language item before showing the prefs menu
void RclMain::setStemLang(const QString& lang)
{
LOGDEB(("RclMain::setStemLang(%s)\n", (const char *)lang.ascii()));
int id;
if (lang == "") {
id = m_idNoStem;
} else {
map<QString, int>::iterator it = m_stemLangToId.find(lang);
if (it == m_stemLangToId.end())
return;
id = it->second;
}
for (map<QString, int>::const_iterator it = m_stemLangToId.begin();
it != m_stemLangToId.end(); it++) {
preferencesMenu->setItemChecked(it->second, false);
}
preferencesMenu->setItemChecked(id, true);
}
// Prefs menu about to show
void RclMain::adjustPrefsMenu()
{
setStemLang(prefs.queryStemLang);
}
void RclMain::closeEvent( QCloseEvent * )
{
fileExit();
@ -393,6 +487,8 @@ void RclMain::showUIPrefs()
if (uiprefs == 0) {
uiprefs = new UIPrefsDialog(0);
connect(uiprefs, SIGNAL(uiprefsDone()), this, SLOT(setUIPrefs()));
connect(this, SIGNAL(stemLangChanged(const QString&)),
uiprefs, SLOT(setStemLang(const QString&)));
} else {
// Close and reopen, in hope that makes us visible...
uiprefs->close();

View File

@ -67,7 +67,6 @@ public:
}
~RclMain() {}
public slots:
virtual bool close();
virtual void fileExit();
@ -99,6 +98,14 @@ public slots:
virtual void previewExposed(Preview *, int sid, int docnum);
virtual void resetSearch();
virtual void eraseDocHistory();
// Callback for setting the stemming language through the prefs menu
virtual void setStemLang(int id);
// Prefs menu about to show, set the checked lang entry
virtual void adjustPrefsMenu();
signals:
void stemLangChanged(const QString& lang);
protected:
virtual void closeEvent( QCloseEvent * );
@ -117,9 +124,13 @@ private:
// Serial number of current search for this process.
// Used to match to preview windows
int m_searchId;
map<QString, int> m_stemLangToId;
int m_idNoStem;
virtual void init();
virtual void previewPrevOrNextInTab(Preview *, int sid, int docnum,
bool next);
virtual void setStemLang(const QString& lang);
};
#endif // RCLMAIN_W_H

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.19 2007-07-12 10:13:37 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: uiprefs_w.cpp,v 1.20 2007-08-01 07:55:03 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -233,6 +233,22 @@ void UIPrefsDialog::reject()
QDialog::reject();
}
void UIPrefsDialog::setStemLang(const QString& lang)
{
int cur = 0;
if (lang == "") {
cur = 0;
} else {
for (int i = 1; i < stemLangCMB->count(); i++) {
if (lang == stemLangCMB->text(i)) {
cur = i;
break;
}
}
}
stemLangCMB->setCurrentItem(cur);
}
void UIPrefsDialog::showFontDialog()
{
bool ok;

View File

@ -1,4 +1,4 @@
/* @(#$Id: uiprefs_w.h,v 1.8 2007-02-08 09:03:29 dockes Exp $ (C) 2006 J.F.Dockes */
/* @(#$Id: uiprefs_w.h,v 1.9 2007-08-01 07:55:03 dockes Exp $ (C) 2006 J.F.Dockes */
/*
* 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
@ -17,7 +17,7 @@
*/
#ifndef _UIPREFS_W_H_INCLUDED_
#define _UIPREFS_W_H_INCLUDED_
/* @(#$Id: uiprefs_w.h,v 1.8 2007-02-08 09:03:29 dockes Exp $ (C) 2005 J.F.Dockes */
/* @(#$Id: uiprefs_w.h,v 1.9 2007-08-01 07:55:03 dockes Exp $ (C) 2005 J.F.Dockes */
#include <qvariant.h>
#include <qdialog.h>
@ -75,6 +75,7 @@ public slots:
virtual void togExtraDbPB_clicked();
virtual void actAllExtraDbPB_clicked();
virtual void unacAllExtraDbPB_clicked();
virtual void setStemLang(const QString& lang);
signals:
void uiprefsDone();