Skip to content

Commit 31a7127

Browse files
author
gsherman
committed
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
1 parent 8961a03 commit 31a7127

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/helpviewer/qgshelpviewer.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <qfileinfo.h>
2626
#include <q3textbrowser.h>
2727
#include <sqlite3.h>
28+
#include <QTextCodec>
29+
#include <QTextStream>
30+
#include <QFile>
2831
#include "qgshelpviewer.h"
2932
QgsHelpViewer::QgsHelpViewer(const QString &contextId, QWidget *parent,
3033
Qt::WFlags fl)
@@ -49,7 +52,73 @@ void QgsHelpViewer::fileExit()
4952
{
5053
QApplication::exit();
5154
}
55+
/*
56+
* Read the help file and populate the viewer
57+
*/
5258
void QgsHelpViewer::loadContext(const QString &contextId)
59+
{
60+
if(contextId != QString::null)
61+
{
62+
// set up the path to the help file
63+
QString helpFilesPath =
64+
#ifdef Q_OS_MACX
65+
// remove bin/qgis_help.app/Contents/MacOS to get to share/qgis
66+
qApp->applicationDirPath() + "/../../../../share/qgis" +
67+
#elif WIN32
68+
qApp->applicationDirPath() + "/share/qgis"
69+
#else
70+
QString(PKGDATAPATH) +
71+
#endif
72+
"/resources/context_help/";
73+
/*
74+
* determine the locale and create the file name from
75+
* the context id
76+
*/
77+
QString lang(QTextCodec::locale());
78+
QString fullHelpPath = helpFilesPath + contextId + "_" + lang;
79+
// get the help content and title from the localized file
80+
QString helpContents;
81+
QFile file(fullHelpPath);
82+
// check to see if the localized version exists
83+
if(!file.exists())
84+
{
85+
// change the file name to the en_US version (default)
86+
fullHelpPath = helpFilesPath + contextId + "_en_US";
87+
file.setFileName(fullHelpPath);
88+
// Check for some sort of english locale and if not found, include
89+
// translate this for us message
90+
if(!lang.contains("en_"))
91+
{
92+
helpContents = "<i>This help file is not available in your language."
93+
" If you would like to translate it, please contact the QGIS development team.</i><hr>";
94+
}
95+
}
96+
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
97+
{
98+
helpContents = tr("This help file does not exist for your language")
99+
+":<p><b>"
100+
+ fullHelpPath
101+
+ "</b><p>"
102+
+ tr("Feel free to translate it and submit it to the QGIS development team");
103+
}
104+
else
105+
{
106+
QTextStream in(&file);
107+
while (!in.atEnd()) {
108+
QString line = in.readLine();
109+
helpContents += line;
110+
}
111+
}
112+
file.close();
113+
114+
// Set the browser text to the help contents
115+
txtBrowser->setText(helpContents);
116+
setCaption(tr("Quantum GIS Help"));
117+
118+
}
119+
}
120+
121+
void QgsHelpViewer::loadContextFromSqlite(const QString &contextId)
53122
{
54123
if(contextId != QString::null)
55124
{

src/helpviewer/qgshelpviewer.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public slots:
3333
void fileExit();
3434
private:
3535
void loadContext(const QString &contextId);
36+
void loadContextFromSqlite(const QString &contextId);
3637
int connectDb(const QString &helpDbPath);
3738
sqlite3 *db;
3839
};

0 commit comments

Comments
 (0)