From e9aad2d453510834f70c1917ec6207962587e71a Mon Sep 17 00:00:00 2001 From: dockes Date: Fri, 23 Jan 2009 09:30:27 +0000 Subject: [PATCH] use normal text/html ext app for viewing help --- src/qtgui/guiutils.cpp | 69 ----------------------------------------- src/qtgui/guiutils.h | 1 - src/qtgui/main.cpp | 2 +- src/qtgui/rclmain_w.cpp | 53 +++++++++++++++++++++++++------ src/qtgui/recoll.h | 2 ++ src/qtgui/uiprefs.ui | 37 ---------------------- src/qtgui/uiprefs_w.cpp | 15 --------- src/qtgui/uiprefs_w.h | 1 - 8 files changed, 46 insertions(+), 134 deletions(-) diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index 7bd7fb73..965ada71 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -43,74 +43,6 @@ bool getStemLangs(list& 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 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 pathl; - stringToTokens(path, pathl, ":"); - - // For each browser name, search path and exec/stop if found - for (list::const_iterator bit = blist.begin(); - bit != blist.end(); bit++) { - for (list::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, diff --git a/src/qtgui/guiutils.h b/src/qtgui/guiutils.h index 0506052e..e8e90d6e 100644 --- a/src/qtgui/guiutils.h +++ b/src/qtgui/guiutils.h @@ -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. diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 6d1cb7c3..647c632f 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -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) diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index b0e1207d..3910a804 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -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 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::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 diff --git a/src/qtgui/recoll.h b/src/qtgui/recoll.h index fcd9166f..dec0dde1 100644 --- a/src/qtgui/recoll.h +++ b/src/qtgui/recoll.h @@ -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; diff --git a/src/qtgui/uiprefs.ui b/src/qtgui/uiprefs.ui index bb0af112..2aa7bcd9 100644 --- a/src/qtgui/uiprefs.ui +++ b/src/qtgui/uiprefs.ui @@ -276,43 +276,6 @@ - - - layout36 - - - - unnamed - - - - textLabel1_3 - - - HTML help browser - - - - - helpBrowserLE - - - - 200 - 0 - - - - - - helpBrowserPB - - - Select file - - - - layout37 diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index d54daf2b..c281e208 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -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) { diff --git a/src/qtgui/uiprefs_w.h b/src/qtgui/uiprefs_w.h index efde0bf4..b3b374e7 100644 --- a/src/qtgui/uiprefs_w.h +++ b/src/qtgui/uiprefs_w.h @@ -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();