2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "debugging/debugging.h"
29 #include "libxml/parser.h"
30 #include "generic/callback.h"
31 #include "gtkutil/menu.h"
32 #include "stream/stringstream.h"
36 #include "preferences.h"
37 #include "mainframe.h"
40 the urls to fire up in the game packs help menus
43 std::list<CopiedString> mHelpURLs;
47 needed for hooking in Gtk+
49 void HandleHelpCommand(CopiedString &str)
54 void process_xlink(const char *filename, const char *menu_name, const char *base_url, ui::Menu menu)
56 if (file_exists(filename)) {
57 xmlDocPtr pDoc = xmlParseFile(filename);
59 globalOutputStream() << "Processing .xlink file '" << filename << "'\n";
61 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, menu_name);
62 if (g_Layout_enableDetachableMenus.m_value) {
63 menu_tearoff(menu_in_menu);
65 // start walking the nodes, find the 'links' one
66 xmlNodePtr pNode = pDoc->children;
67 while (pNode && strcmp((const char *) pNode->name, "links")) {
71 pNode = pNode->children;
73 if (!strcmp((const char *) pNode->name, "item")) {
77 xmlChar *prop = xmlGetProp(pNode, reinterpret_cast<const xmlChar *>( "url" ));
79 if (strstr(reinterpret_cast<const char *>( prop ), "http://") ||
80 strstr(reinterpret_cast<const char *>( prop ), "https://")) {
82 url = reinterpret_cast<const char *>( prop );
85 StringOutputStream full(256);
86 full << base_url << reinterpret_cast<const char *>( prop );
90 mHelpURLs.push_back(url);
94 prop = xmlGetProp(pNode, reinterpret_cast<const xmlChar *>( "name" ));
96 create_menu_item_with_mnemonic(menu_in_menu, reinterpret_cast<const char *>( prop ),
97 ReferenceCaller<CopiedString, void(), HandleHelpCommand>(
106 globalOutputStream() << "'" << filename << "' parse failed\n";
109 globalOutputStream() << "'" << filename << "' not found\n";
113 void create_game_help_menu(ui::Menu menu)
115 StringOutputStream filename(256);
116 filename << AppPath_get() << "global.xlink";
117 process_xlink(filename.c_str(), "General", AppPath_get(), menu);
121 filename << g_pGameDescription->mGameToolsPath.c_str() << "game.xlink";
122 process_xlink(filename.c_str(), g_pGameDescription->getRequiredKeyValue("name"),
123 g_pGameDescription->mGameToolsPath.c_str(), menu);
125 for ( std::list<CGameDescription *>::iterator iGame = g_GamesDialog.mGames.begin(); iGame != g_GamesDialog.mGames.end(); ++iGame )
128 filename << ( *iGame )->mGameToolsPath.c_str() << "game.xlink";
129 process_xlink( filename.c_str(), ( *iGame )->getRequiredKeyValue( "name" ), ( *iGame )->mGameToolsPath.c_str(), menu );