29 # include <htmlhelp.h>
32 #include "gnc-help-utils.h"
37 parse_hhmap_file(
const gchar *chmfile)
39 gchar *mapfile = NULL, *dot;
40 GKeyFile *keyfile = NULL;
42 gchar **keys = NULL, **key;
44 GHashTable *ctxtmap = NULL;
46 g_return_val_if_fail(chmfile, NULL);
48 mapfile = g_new(gchar, strlen(chmfile) + 7);
49 strcpy(mapfile, chmfile);
50 dot = strrchr(mapfile,
'.');
52 strcpy(dot,
".hhmap");
54 strcat(mapfile,
".hhmap");
56 keyfile = g_key_file_new();
57 if (!g_key_file_load_from_file(keyfile, mapfile, G_KEY_FILE_NONE, &error))
60 if (NULL == (keys = g_key_file_get_keys(keyfile,
"Map", NULL, &error)))
63 ctxtmap = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
64 for (key = keys; *key; key++)
66 value = g_key_file_get_integer(keyfile,
"Map", *key, &error);
70 g_hash_table_insert(ctxtmap, g_strdup(*key), GINT_TO_POINTER(value));
76 g_warning(
"Could not load help map file: %s", error->message);
79 g_hash_table_destroy(ctxtmap);
85 g_key_file_free (keyfile);
93 gnc_show_htmlhelp(
const gchar *chmfile,
const gchar *anchor)
95 static GHashTable *chmfile_ctxtmap_map;
96 G_LOCK_DEFINE_STATIC(chmfile_ctxtmap_map);
98 gboolean create_map = FALSE;
102 g_return_if_fail(chmfile);
106 G_LOCK(chmfile_ctxtmap_map);
107 if (!chmfile_ctxtmap_map)
109 chmfile_ctxtmap_map = g_hash_table_new(g_str_hash, g_str_equal);
114 create_map = !g_hash_table_lookup_extended(
115 chmfile_ctxtmap_map, chmfile, NULL, (gpointer) & ctxtmap);
120 ctxtmap = parse_hhmap_file(chmfile);
121 g_hash_table_insert(chmfile_ctxtmap_map, g_strdup(chmfile), ctxtmap);
126 gpointer ptr = g_hash_table_lookup(ctxtmap, anchor);
128 id = GPOINTER_TO_INT(ptr);
130 G_UNLOCK(chmfile_ctxtmap_map);
133 g_warning(
"Could not find anchor '%s'", anchor);
136 wpath = g_utf8_to_utf16(chmfile, -1, NULL, NULL, NULL);
137 HtmlHelpW(GetDesktopWindow(), wpath, HH_HELP_CONTEXT,
id);
143 gnc_show_htmlhelp(
const gchar *chmfile,
const gchar *anchor)
147 g_return_if_fail(chmfile);
150 argv[1] = g_strdup(chmfile);
153 if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
154 NULL, NULL, NULL, NULL))
155 if (g_file_test(chmfile, G_FILE_TEST_IS_REGULAR))
156 g_warning(
"Found CHM help file, but could not spawn hh to open it");