]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/help.cpp
integrated x86_64 patch from LordHavoc
[xonotic/netradiant.git] / radiant / help.cpp
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 #include "help.h"
23
24 #include "debugging/debugging.h"
25
26 #include <vector>
27 #include <list>
28
29 #include "libxml/parser.h"
30 #include "generic/callback.h"
31 #include "gtkutil/menu.h"
32 #include "stream/stringstream.h"
33 #include "os/file.h"
34
35 #include "url.h"
36 #include "preferences.h"
37 #include "mainframe.h"
38
39 /*!
40 the urls to fire up in the game packs help menus
41 */
42 namespace
43 {
44   std::list<CopiedString> mHelpURLs;
45 }
46
47 /*!
48 needed for hooking in Gtk+
49 */
50 void HandleHelpCommand(CopiedString& str)
51 {
52   OpenURL(str.c_str());
53 }
54
55 void process_xlink(const char* filename, const char *menu_name, const char *base_url, GtkMenu *menu)
56 {
57   if(file_exists(filename))
58   {
59     xmlDocPtr pDoc = xmlParseFile(filename);
60     if (pDoc)
61     {
62       globalOutputStream() << "Processing .xlink file '" << filename << "'\n";
63       // create sub menu
64       GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic(menu, menu_name);
65       // start walking the nodes, find the 'links' one
66       xmlNodePtr pNode = pDoc->children;
67       while (pNode && strcmp((const char*)pNode->name, "links"))
68         pNode=pNode->next;
69       if (pNode)
70       {
71         pNode = pNode->children;
72         while(pNode)
73         {
74           if(!strcmp((const char*)pNode->name, "item"))
75           {
76             // process the URL
77             CopiedString url;
78             
79             xmlChar* prop = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>("url"));
80             ASSERT_NOTNULL(prop);
81             if(strstr(reinterpret_cast<const char*>(prop), "http://"))
82             {
83               // complete URL
84               url = reinterpret_cast<const char*>(prop);
85             }
86             else
87             {
88               // relative URL
89               StringOutputStream full(256);
90               full << base_url << reinterpret_cast<const char*>(prop);
91               url = full.c_str();
92             }
93
94             mHelpURLs.push_back(url);
95
96             xmlFree(prop);
97             
98             prop = xmlGetProp(pNode, reinterpret_cast<const xmlChar*>("name"));
99             ASSERT_NOTNULL(prop);
100             create_menu_item_with_mnemonic(menu_in_menu, reinterpret_cast<const char*>(prop), ReferenceCaller<CopiedString, HandleHelpCommand>(mHelpURLs.back()));
101             xmlFree(prop);
102           }
103           pNode=pNode->next;
104         }
105       }
106       xmlFreeDoc(pDoc);
107     }
108     else
109     {
110       globalOutputStream() << "'" << filename << "' parse failed\n";
111     }
112   }
113   else
114   {
115     globalOutputStream() << "'" << filename << "' not found\n";
116   }
117 }
118
119 void create_game_help_menu(GtkMenu *menu)
120 {
121   StringOutputStream filename(256);
122   filename << AppPath_get() << "global.xlink";
123   process_xlink(filename.c_str(), "General", AppPath_get(), menu);
124
125 #if 1
126   filename.clear();
127   filename << g_pGameDescription->mGameToolsPath.c_str() << "game.xlink";
128   process_xlink(filename.c_str(), g_pGameDescription->getRequiredKeyValue("name"), g_pGameDescription->mGameToolsPath.c_str(), menu);
129 #else
130   for(std::list<CGameDescription *>::iterator iGame = g_GamesDialog.mGames.begin(); iGame != g_GamesDialog.mGames.end(); ++iGame)
131   {
132     filename.clear();
133     filename << (*iGame)->mGameToolsPath.c_str() << "game.xlink";
134     process_xlink(filename.c_str(), (*iGame)->getRequiredKeyValue("name"), (*iGame)->mGameToolsPath.c_str(), menu);
135   }
136 #endif
137 }
138