25
25
#include < qfileinfo.h>
26
26
#include < q3textbrowser.h>
27
27
#include < sqlite3.h>
28
+ #include < QTextCodec>
29
+ #include < QTextStream>
30
+ #include < QFile>
28
31
#include " qgshelpviewer.h"
29
32
QgsHelpViewer::QgsHelpViewer (const QString &contextId, QWidget *parent,
30
33
Qt::WFlags fl)
@@ -49,7 +52,73 @@ void QgsHelpViewer::fileExit()
49
52
{
50
53
QApplication::exit ();
51
54
}
55
+ /*
56
+ * Read the help file and populate the viewer
57
+ */
52
58
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)
53
122
{
54
123
if (contextId != QString::null)
55
124
{
0 commit comments