use normal text/html ext app for viewing help

This commit is contained in:
dockes 2009-01-23 09:30:27 +00:00
parent 27fbdc6a12
commit e9aad2d453
8 changed files with 46 additions and 134 deletions

View File

@ -43,74 +43,6 @@ bool getStemLangs(list<string>& langs)
return true;
}
static const 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(rclconfig->getDatadir(), "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;
}
// The global preferences structure
PrefsPack prefs;
@ -142,7 +74,6 @@ void rwSettings(bool writing)
SETTING_RW(prefs.pvwidth, "/Recoll/geometry/pvwidth", Num, 0);
SETTING_RW(prefs.pvheight, "/Recoll/geometry/pvheight", Num, 0);
SETTING_RW(prefs.ssearchTyp, "/Recoll/prefs/simpleSearchTyp", Num, 1);
SETTING_RW(prefs.htmlBrowser, "/Recoll/prefs/htmlBrowser", , "");
SETTING_RW(prefs.startWithAdvSearchOpen,
"/Recoll/prefs/startWithAdvSearchOpen", Bool, false);
SETTING_RW(prefs.startWithSortToolOpen,

View File

@ -74,7 +74,6 @@ class PrefsPack {
int pvwidth; // Preview window geom
int pvheight;
int ssearchTyp;
QString htmlBrowser;
bool useDesktopOpen; // typically xdg-open, instead of mimeview settings
bool keepSort; // remember sort status between invocations
bool sortActive; // Remembered sort state.

View File

@ -87,7 +87,7 @@ RclConfig* RclConfig::getMainConfig()
RclHistory *g_dynconf;
int recollNeedsExit;
int startIndexingAfterConfig;
static RclMain *mainWindow;
RclMain *mainWindow;
static string recollsharedir;
bool maybeOpenDb(string &reason, bool force)

View File

@ -827,13 +827,35 @@ void RclMain::saveDocToFile(int docnum)
}
}
/* Look for html browser. We make a special effort for html because it's
* used for reading help */
static bool lookForHtmlBrowser(string &exefile)
{
static const char *htmlbrowserlist =
"opera konqueror firefox mozilla netscape epiphany";
list<string> blist;
stringToTokens(htmlbrowserlist, blist, " ");
const char *path = getenv("PATH");
if (path == 0)
path = "/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin";
// Look for each browser
for (list<string>::const_iterator bit = blist.begin();
bit != blist.end(); bit++) {
if (ExecCmd::which(*bit, exefile, path))
return true;
}
exefile.clear();
return false;
}
void RclMain::startNativeViewer(int docnum)
{
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll",
tr("Cannot retrieve document info"
" from database"));
QMessageBox::warning(0, "Recoll", tr("Cannot retrieve document info"
" from database"));
return;
}
startNativeViewer(doc);
@ -868,7 +890,8 @@ void RclMain::startNativeViewer(Rcl::Doc doc)
string cmdpath;
if (prefs.useDesktopOpen) {
// Findfilter searches the recoll filters directory in
// addition to the path
// addition to the path. We store a copy of xdg-open there, to be
// used as last resort
cmdpath = rclconfig->findFilter(lcmd.front());
// Substitute path for cmd
if (!cmdpath.empty()) {
@ -880,6 +903,12 @@ void RclMain::startNativeViewer(Rcl::Doc doc)
ExecCmd::which(lcmd.front(), cmdpath);
}
// Specialcase text/html because of the help browser need
if (cmdpath.empty() && !doc.mimetype.compare("text/html")) {
if (lookForHtmlBrowser(cmdpath)) {
cmd = cmdpath + " %u";
}
}
if (cmdpath.empty()) {
QString mt = QString::fromAscii(doc.mimetype.c_str());
QString message = tr("The viewer specified in mimeconf for %1: %2"
@ -895,9 +924,9 @@ void RclMain::startNativeViewer(Rcl::Doc doc)
uiprefs->showViewAction(mt);
break;
case 1:
return;
break;
}
return;
}
// For files with an ipath, we do things differently depending if the
@ -953,11 +982,15 @@ void RclMain::startNativeViewer(Rcl::Doc doc)
void RclMain::startManual()
{
QString msg = tr("Starting help browser ");
if (prefs.htmlBrowser != QString(""))
msg += prefs.htmlBrowser;
QString msg = tr("Starting html help browser ");
statusBar()->message(msg, 3000);
startHelpBrowser();
Rcl::Doc doc;
doc.url = "file://";
doc.url = path_cat(doc.url, rclconfig->getDatadir());
doc.url = path_cat(doc.url, "doc");
doc.url = path_cat(doc.url, "usermanual.html");
doc.mimetype = "text/html";
startNativeViewer(doc);
}
// Search for document 'like' the selected one. We ask rcldb/xapian to find

View File

@ -29,6 +29,8 @@
// Open the database if needed. We now force a close/open by default
extern bool maybeOpenDb(std::string &reason, bool force = true);
class RclMain;
extern RclMain *mainWindow;
extern RclConfig *rclconfig;
extern Rcl::Db *rcldb;
extern int recollNeedsExit;

View File

@ -276,43 +276,6 @@
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout36</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1_3</cstring>
</property>
<property name="text">
<string>HTML help browser</string>
</property>
</widget>
<widget class="QLineEdit">
<property name="name">
<cstring>helpBrowserLE</cstring>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>helpBrowserPB</cstring>
</property>
<property name="text">
<string>Select file</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout37</cstring>

View File

@ -67,7 +67,6 @@ void UIPrefsDialog::init()
connect(viewActionPB, SIGNAL(clicked()), this, SLOT(showViewAction()));
connect(reslistFontPB, SIGNAL(clicked()), this, SLOT(showFontDialog()));
connect(helpBrowserPB, SIGNAL(clicked()), this, SLOT(showBrowserDialog()));
connect(resetFontPB, SIGNAL(clicked()), this, SLOT(resetReslistFont()));
connect(extraDbLE,SIGNAL(textChanged(const QString&)), this,
SLOT(extraDbTextChanged(const QString&)));
@ -123,7 +122,6 @@ void UIPrefsDialog::setFromPrefs()
s.setNum(reslistFontSize));
}
rlfTE->setText(prefs.reslistformat);
helpBrowserLE->setText(prefs.htmlBrowser);
// Stemming language combobox
stemLangCMB->clear();
@ -194,8 +192,6 @@ void UIPrefsDialog::accept()
}
prefs.creslistformat = (const char*)prefs.reslistformat.utf8();
prefs.htmlBrowser = helpBrowserLE->text();
if (stemLangCMB->currentItem() == 0) {
prefs.queryStemLang = "";
} else if (stemLangCMB->currentItem() == 1) {
@ -296,17 +292,6 @@ void UIPrefsDialog::resetReslistFont()
QString().setNum(this->font().pointSize()));
}
void UIPrefsDialog::showBrowserDialog()
{
QString s = QFileDialog::getOpenFileName("/usr",
"",
this,
"open file dialog",
"Choose a file");
if (!s.isEmpty())
helpBrowserLE->setText(s);
}
void UIPrefsDialog::showViewAction()
{
if (m_viewAction== 0) {

View File

@ -68,7 +68,6 @@ public slots:
virtual void showViewAction();
virtual void showViewAction(const QString& mt);
virtual void resetReslistFont();
virtual void showBrowserDialog();
virtual void extraDbTextChanged(const QString& text);
virtual void addExtraDbPB_clicked();
virtual void delExtraDbPB_clicked();