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
23 The following source code is licensed by Id Software and subject to the terms of
24 its LIMITED USE SOFTWARE LICENSE AGREEMENT, a copy of which is included with
25 GtkRadiant. If you did not receive a LIMITED USE SOFTWARE LICENSE AGREEMENT,
26 please contact Id Software immediately at info@idsoftware.com.
29 #if !defined(INCLUDED_PREFERENCES_H)
30 #define INCLUDED_PREFERENCES_H
32 #include "libxml/parser.h"
37 void Widget_connectToggleDependency(GtkWidget* self, GtkWidget* toggleButton);
44 PreferencesPage(Dialog& dialog, GtkWidget* vbox) : m_dialog(dialog), m_vbox(vbox)
47 GtkWidget* appendCheckBox(const char* name, const char* flag, bool& data)
49 return m_dialog.addCheckBox(m_vbox, name, flag, data);
51 GtkWidget* appendCheckBox(const char* name, const char* flag, const BoolImportCallback& importCallback, const BoolExportCallback& exportCallback)
53 return m_dialog.addCheckBox(m_vbox, name, flag, importCallback, exportCallback);
55 void appendCombo(const char* name, StringArrayRange values, const IntImportCallback& importCallback, const IntExportCallback& exportCallback)
57 m_dialog.addCombo(m_vbox, name, values, importCallback, exportCallback);
59 void appendCombo(const char* name, int& data, StringArrayRange values)
61 m_dialog.addCombo(m_vbox, name, data, values);
63 void appendSlider(const char* name, int& data, gboolean draw_value, const char* low, const char* high, double value, double lower, double upper, double step_increment, double page_increment)
65 m_dialog.addSlider(m_vbox, name, data, draw_value, low, high, value, lower, upper, step_increment, page_increment);
67 void appendRadio(const char* name, StringArrayRange names, const IntImportCallback& importCallback, const IntExportCallback& exportCallback)
69 m_dialog.addRadio(m_vbox, name, names, importCallback, exportCallback);
71 void appendRadio(const char* name, int& data, StringArrayRange names)
73 m_dialog.addRadio(m_vbox, name, data, names);
75 void appendRadioIcons(const char* name, StringArrayRange icons, const IntImportCallback& importCallback, const IntExportCallback& exportCallback)
77 m_dialog.addRadioIcons(m_vbox, name, icons, importCallback, exportCallback);
79 void appendRadioIcons(const char* name, int& data, StringArrayRange icons)
81 m_dialog.addRadioIcons(m_vbox, name, data, icons);
83 GtkWidget* appendEntry(const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback)
85 return m_dialog.addIntEntry(m_vbox, name, importCallback, exportCallback);
87 GtkWidget* appendEntry(const char* name, int& data)
89 return m_dialog.addEntry(m_vbox, name, data);
91 GtkWidget* appendEntry(const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback)
93 return m_dialog.addSizeEntry(m_vbox, name, importCallback, exportCallback);
95 GtkWidget* appendEntry(const char* name, std::size_t& data)
97 return m_dialog.addEntry(m_vbox, name, data);
99 GtkWidget* appendEntry(const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback)
101 return m_dialog.addFloatEntry(m_vbox, name, importCallback, exportCallback);
103 GtkWidget* appendEntry(const char* name, float& data)
105 return m_dialog.addEntry(m_vbox, name, data);
107 GtkWidget* appendPathEntry(const char* name, bool browse_directory, const StringImportCallback& importCallback, const StringExportCallback& exportCallback)
109 return m_dialog.addPathEntry(m_vbox, name, browse_directory, importCallback, exportCallback);
111 GtkWidget* appendPathEntry(const char* name, CopiedString& data, bool directory)
113 return m_dialog.addPathEntry(m_vbox, name, data, directory);
115 GtkWidget* appendSpinner(const char* name, int& data, double value, double lower, double upper)
117 return m_dialog.addSpinner(m_vbox, name, data, value, lower, upper);
119 GtkWidget* appendSpinner(const char* name, double value, double lower, double upper, const IntImportCallback& importCallback, const IntExportCallback& exportCallback)
121 return m_dialog.addSpinner(m_vbox, name, value, lower, upper, importCallback, exportCallback);
123 GtkWidget* appendSpinner(const char* name, double value, double lower, double upper, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback)
125 return m_dialog.addSpinner(m_vbox, name, value, lower, upper, importCallback, exportCallback);
129 typedef Callback1<PreferencesPage&> PreferencesPageCallback;
131 class PreferenceGroup
134 virtual PreferencesPage createPage(const char* treeName, const char* frameName) = 0;
137 typedef Callback1<PreferenceGroup&> PreferenceGroupCallback;
139 void PreferencesDialog_addInterfacePreferences(const PreferencesPageCallback& callback);
140 void PreferencesDialog_addInterfacePage(const PreferenceGroupCallback& callback);
141 void PreferencesDialog_addDisplayPreferences(const PreferencesPageCallback& callback);
142 void PreferencesDialog_addDisplayPage(const PreferenceGroupCallback& callback);
143 void PreferencesDialog_addSettingsPreferences(const PreferencesPageCallback& callback);
144 void PreferencesDialog_addSettingsPage(const PreferenceGroupCallback& callback);
146 void PreferencesDialog_restartRequired(const char* staticName);
148 template<typename Value>
154 const char* m_description;
156 LatchedValue(Value value, const char* description) : m_latched(value), m_description(description)
163 void import(Value value)
166 if(m_latched != m_value)
168 PreferencesDialog_restartRequired(m_description);
173 typedef LatchedValue<bool> LatchedBool;
174 typedef MemberCaller1<LatchedBool, bool, &LatchedBool::import> LatchedBoolImportCaller;
176 typedef LatchedValue<int> LatchedInt;
177 typedef MemberCaller1<LatchedInt, int, &LatchedInt::import> LatchedIntImportCaller;
180 holds information for a given game
181 I'm a bit unclear on that still
182 it holds game specific configuration stuff
183 such as base names, engine names, some game specific features to activate in the various modules
184 it is not strictly a prefs thing since the user is not supposed to edit that (unless he is hacking
185 support for a new game)
187 what we do now is fully generate the information for this during the setup. We might want to
188 generate a piece that just says "the game pack is there", but put the rest of the config somwhere
189 else (i.e. not generated, copied over during setup .. for instance in the game tools directory)
191 class CGameDescription
193 typedef std::map<CopiedString, CopiedString> GameDescription;
196 CopiedString mGameFile; ///< the .game file that describes this game
197 GameDescription m_gameDescription;
199 CopiedString mGameToolsPath; ///< the explicit path to the game-dependent modules
200 CopiedString mGameType; ///< the type of the engine
202 const char* getKeyValue(const char* key) const
204 GameDescription::const_iterator i = m_gameDescription.find(key);
205 if(i != m_gameDescription.end())
207 return (*i).second.c_str();
211 const char* getRequiredKeyValue(const char* key) const
213 GameDescription::const_iterator i = m_gameDescription.find(key);
214 if(i != m_gameDescription.end())
216 return (*i).second.c_str();
218 ERROR_MESSAGE("game attribute " << makeQuoted(key) << " not found in " << makeQuoted(mGameFile.c_str()));
222 CGameDescription(xmlDocPtr pDoc, const CopiedString &GameFile);
227 extern CGameDescription *g_pGameDescription;
229 typedef struct _GtkWidget GtkWidget;
232 class PreferencesPage;
234 class StringOutputStream;
237 standalone dialog for games selection, and more generally global settings
239 class CGameDialog : public Dialog
243 mutable int m_nComboSelect; ///< intermediate int value for combo in dialog box
248 those settings are saved in the global prefs file
249 I'm too lazy to wrap behind protected access, not sure this needs to be public
250 NOTE: those are preference settings. if you change them it is likely that you would
251 have to restart the editor for them to take effect
255 what game has been selected
256 this is the name of the .game file
258 CopiedString m_sGameFile;
260 prompt which game to load on startup
264 log console to radiant.log
265 m_bForceLogConsole is an obscure forced latching situation
267 bool m_bForceLogConsole;
271 the list of game descriptions we scanned from the game/ dir
273 std::list<CGameDescription*> mGames;
278 m_bForceLogConsole(false)
281 virtual ~CGameDialog();
283 void AddPacksURL(StringOutputStream &s);
286 intialize the game dialog, called at CPrefsDlg::Init
287 will scan for games, load prefs, and do game selection dialog if needed
292 reset the global settings by removing the file
297 run the dialog UI for the list of games
303 this is only called when the dialog is built at startup for main engine select
305 GtkWindow* BuildDialog();
307 void GameFileImport(int value);
308 void GameFileExport(const IntImportCallback& importCallback) const;
311 construction of the dialog frame
312 this is the part to be re-used in prefs dialog
313 for the standalone dialog, we include this in a modal box
314 for prefs, we hook the frame in the main notebook
315 build the frame on-demand (only once)
317 void CreateGlobalFrame(PreferencesPage& page);
320 global preferences subsystem
321 XML-based this time, hopefully this will generalize to other prefs
322 LoadPrefs has hardcoded defaults
323 NOTE: it may not be strictly 'CGameDialog' to put the global prefs here
324 could have named the class differently I guess
327 void LoadPrefs(); ///< load from file into variables
328 void SavePrefs(); ///< save pref variables to file
333 scan for .game files, load them
338 inits g_Preferences.m_global_rc_path
340 void InitGlobalPrefPath();
343 uses m_nComboItem to find the right mGames
345 CGameDescription *GameDescriptionForComboItem();
349 this holds global level preferences
351 extern CGameDialog g_GamesDialog;
356 class PrefsDlg : public Dialog
360 std::list<CGameDescription *> mGames;
364 GtkWidget *m_notebook;
368 g_string_free (m_rc_path, true );
369 g_string_free (m_inipath, true );
373 path for global settings
375 linux: ~/.radiant/[version]/
377 GString *m_global_rc_path;
380 path to per-game settings
381 used for various game dependant storage
383 linux: ~/.radiant/[version]/[gamename]/
388 holds per-game settings
389 m_rc_path+"local.pref"
390 \todo FIXME at some point this should become XML property bag code too
394 // initialize the above paths
397 /*! Utility function for swapping notebook pages for tree list selections */
398 void showPrefPage(GtkWidget* prefpage);
403 GtkWindow* BuildDialog();
404 void PostModal (EMessageBoxReturn code);
407 extern PrefsDlg g_Preferences;
409 struct preferences_globals_t
411 // disabled all INI / registry read write .. used when shutting down after registry cleanup
413 preferences_globals_t() : disable_ini(false)
417 extern preferences_globals_t g_preferences_globals;
419 typedef struct _GtkWindow GtkWindow;
420 void PreferencesDialog_constructWindow(GtkWindow* main_window);
421 void PreferencesDialog_destroyWindow();
423 void PreferencesDialog_showDialog();
425 void GlobalPreferences_Init();
426 void Preferences_Init();
428 void Preferences_Load();
429 void Preferences_Save();
431 void Preferences_Reset();