From 31a71272d0caa74ba94c5c7af70c7e13a995e829 Mon Sep 17 00:00:00 2001 From: gsherman Date: Thu, 16 Nov 2006 03:39:30 +0000 Subject: [PATCH] changes to helpviewer to use context help files installed in ./share/qgis/resources/context_help git-svn-id: http://svn.osgeo.org/qgis/trunk@6091 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/helpviewer/qgshelpviewer.cpp | 69 ++++++++++++++++++++++++++++++++ src/helpviewer/qgshelpviewer.h | 1 + 2 files changed, 70 insertions(+) diff --git a/src/helpviewer/qgshelpviewer.cpp b/src/helpviewer/qgshelpviewer.cpp index a2ba1fc8f35..f404945704c 100644 --- a/src/helpviewer/qgshelpviewer.cpp +++ b/src/helpviewer/qgshelpviewer.cpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include "qgshelpviewer.h" QgsHelpViewer::QgsHelpViewer(const QString &contextId, QWidget *parent, Qt::WFlags fl) @@ -49,7 +52,73 @@ void QgsHelpViewer::fileExit() { QApplication::exit(); } +/* + * Read the help file and populate the viewer + */ void QgsHelpViewer::loadContext(const QString &contextId) +{ + if(contextId != QString::null) + { + // set up the path to the help file + QString helpFilesPath = +#ifdef Q_OS_MACX + // remove bin/qgis_help.app/Contents/MacOS to get to share/qgis + qApp->applicationDirPath() + "/../../../../share/qgis" + +#elif WIN32 + qApp->applicationDirPath() + "/share/qgis" +#else + QString(PKGDATAPATH) + +#endif + "/resources/context_help/"; + /* + * determine the locale and create the file name from + * the context id + */ + QString lang(QTextCodec::locale()); + QString fullHelpPath = helpFilesPath + contextId + "_" + lang; + // get the help content and title from the localized file + QString helpContents; + QFile file(fullHelpPath); + // check to see if the localized version exists + if(!file.exists()) + { + // change the file name to the en_US version (default) + fullHelpPath = helpFilesPath + contextId + "_en_US"; + file.setFileName(fullHelpPath); + // Check for some sort of english locale and if not found, include + // translate this for us message + if(!lang.contains("en_")) + { + helpContents = "This help file is not available in your language." + " If you would like to translate it, please contact the QGIS development team.
"; + } + } + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + helpContents = tr("This help file does not exist for your language") + +":

" + + fullHelpPath + + "

" + + tr("Feel free to translate it and submit it to the QGIS development team"); + } + else + { + QTextStream in(&file); + while (!in.atEnd()) { + QString line = in.readLine(); + helpContents += line; + } + } + file.close(); + + // Set the browser text to the help contents + txtBrowser->setText(helpContents); + setCaption(tr("Quantum GIS Help")); + + } + } + +void QgsHelpViewer::loadContextFromSqlite(const QString &contextId) { if(contextId != QString::null) { diff --git a/src/helpviewer/qgshelpviewer.h b/src/helpviewer/qgshelpviewer.h index 46f1feb8f34..884a31f5422 100644 --- a/src/helpviewer/qgshelpviewer.h +++ b/src/helpviewer/qgshelpviewer.h @@ -33,6 +33,7 @@ public slots: void fileExit(); private: void loadContext(const QString &contextId); + void loadContextFromSqlite(const QString &contextId); int connectDb(const QString &helpDbPath); sqlite3 *db; };