Debian Codegraph @

src/af/xap/xp/xap_AppImpl.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 2004 Hubert Figuiere
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include "xap_AppImpl.h"
21 #include "ut_assert.h"
22 #include "ut_path.h"
23 #include "ut_string_class.h"
24 #include "xap_App.h"
25 #include "xap_Prefs.h"
26
27 /*!
28 Open a help URL
29
30 \param url the URL to open
31
32 This method opens a help page designated by URL. By default it does
33 the same as opening and URL, ie likely to be in the web browser.
34 Override it to open this in a different viewer like Help Viewer (MacOS X),
35 gnome-help (GNOME), etc.
36 It should check the protcol (file: vs http:)
37 */
38 bool XAP_AppImpl::openHelpURL(const char * url)
39 {
40 return openURL(url);
41 }
42
43
44 inline static void _catPath(UT_String& st, const char* st2)
45 {
46 if (st.size() > 0)
47 {
48 if (st[st.size() - 1] != '/')
49 st += '/';
50 }
51 else
52 st += '/';
53
54 st += st2;
55 }
56
57 /*!
58 Localize and URL for help.
59
60 \param pathBeforeLang the path for the help file that prefix
61 \param pathAfterLang the path inside the localized directory
62 \param remoteURLbase remote URL if help files are not found.
63
64 Override in subclasses if platform needs specific work
65 */
66 UT_String XAP_AppImpl::localizeHelpUrl (const char * pathBeforeLang,
67 const char * pathAfterLang,
68 const char * remoteURLbase)
69 {
70 XAP_App* pApp = XAP_App::getApp();
71
72 UT_return_val_if_fail(pApp, "");
73 XAP_Prefs* pPrefs = pApp->getPrefs();
74 UT_return_val_if_fail(pPrefs, "");
75
76 const char* abiSuiteLibDir = pApp->getAbiSuiteLibDir();
77 const gchar* abiSuiteLocString = NULL;
78 UT_String url;
79
80 // evil...
81 pPrefs->getPrefsValue((gchar*)"StringSet", &abiSuiteLocString);
82
83 // 1st try file on user's computer (local file), if not exist try remote help
84 UT_String path(abiSuiteLibDir);
85 _catPath(path, pathBeforeLang);
86
87 UT_String localized_path(path);
88 _catPath(localized_path, abiSuiteLocString);
89
90 if (UT_directoryExists(localized_path.c_str()))
91 {
92 // the localised help exists, so use it
93 path = localized_path;
94 }
95 else
96 {
97 // the localised help directory does not exist, so fall back to the
98 // en-US help location, which is the default lang, so usually available
99 localized_path = path;
100 _catPath(localized_path, "en-US");
101 }
102
103 _catPath(localized_path, pathAfterLang);
104 localized_path += ".html";
105
106 if (remoteURLbase && !UT_isRegularFile(localized_path.c_str()))
107 {
108 // not found, so build localized path for remote URL (but we can't verify remote URL)
109 url = remoteURLbase;
110
111 // HACK: Not all help files are localized.
112 // HACK: Hard code the available translations here instead of 404-ing.
113 if (!(
114 !strcmp(abiSuiteLocString, "en-US") ||
115 !strcmp(abiSuiteLocString, "fr-FR") ||
116 !strcmp(abiSuiteLocString, "pl-PL")
117 ))
118 _catPath(url, "en-US");
119 else
120 _catPath(url, abiSuiteLocString);
121 _catPath(url, pathAfterLang);
122 url += ".html";
123 }
124 else
125 {
126 url = "file://";
127 url += localized_path;
128 }
129
130 return url;
131 }