]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/preferences.cpp
* removed a lot of HACKs for several games by merging the enginepath_win32, enginepat...
[xonotic/netradiant.git] / radiant / preferences.cpp
1 /*
2 Copyright (C) 1999-2007 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 //
23 // User preferences
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "stdafx.h"
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <assert.h>
32 #if defined (__linux__) || defined (__APPLE__)
33 #include <sys/stat.h>
34 #include <sys/types.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <dirent.h>
38 #endif
39 #include "missing.h"
40 #include "gtkmisc.h"
41
42 #ifdef _WIN32
43 #include <io.h>
44 #define X_OK 0
45 #include <sys/stat.h>
46 #endif
47
48 #define PREF_SECTION            "Prefs"
49 #define INTERNAL_SECTION        "Internals"
50 #define MOUSE_KEY               "MouseButtons"
51 #define WINDOW_KEY              "QE4StyleWindows"
52 #define LAYOUT_KEY              "WindowLayout"
53 #define RUNQ2_KEY               "RunQuake2Run"
54 #define TLOCK_KEY               "TextureLock"
55 #define RLOCK_KEY               "RotateLock"
56 #define LOADLAST_KEY            "LoadLast"
57 #define LOADLASTMAP_KEY         "LoadLastMap"
58 #define LASTPROJ_KEY            "LastProject"
59 #define LASTPROJVER_KEY         "LastProjectKey"
60 #define LASTMAP_KEY             "LastMap"
61 #define FACE_KEY                "NewFaceGrab"
62 #define BSP_KEY                 "InternalBSP"
63 #define RCLICK_KEY              "NewRightClick"
64 #define VERTEX_KEY              "NewVertex"
65 #define AUTOSAVE_KEY            "Autosave"
66 #define AUTOSAVETIME_KEY        "AutosaveMinutes"
67 #define PAK_KEY                 "UsePAK"
68 #define NEWAPPLY_KEY            "ApplyDismissesSurface"
69 #define HACK_KEY                "Gatewayescapehack"
70 #define TEXTURE_KEY             "NewTextureWindowStuff"
71 #define TINYBRUSH_KEY           "CleanTinyBrushes"
72 #define TINYSIZE_KEY            "CleanTinyBrusheSize"
73 #define SNAPSHOT_KEY            "Snapshots"
74 #define MOVESPEED_KEY           "MoveSpeed"
75 #define ANGLESPEED_KEY          "AngleSpeed"
76 #define SETGAME_KEY             "UseSetGame"
77 #define CAMXYUPDATE_KEY         "CamXYUpdate"
78 #define CAMDRAGMULTISELECT_KEY  "CamDragMultiSelect"
79 #define CAMFREELOOK_KEY         "CamFreeLook"
80 #define CAMINVERSEMOUSE_KEY         "CamInverseMouse"
81 #define CAMDISCRETE_KEY         "CamDiscrete"
82 #define LIGHTDRAW_KEY           "NewLightStyle"
83 #define WHATGAME_KEY            "WhichGame"
84 #define CUBICCLIP_KEY           "CubicClipping"
85 #define CUBICSCALE_KEY          "CubicScale"
86 #define ALTEDGE_KEY             "ALTEdgeDrag"
87 #define FACECOLORS_KEY          "FaceColors"
88 #define SNAPT_KEY               "SnapT"
89 #define XZVIS_KEY               "XZVIS"
90 #define YZVIS_KEY               "YZVIS"
91 #define ZVIS_KEY                "ZVIS"
92 #define SIZEPAINT_KEY           "SizePainting"
93 #define DLLENTITIES_KEY         "DLLEntities"
94 #define DETACHABLEMENUS_KEY     "DetachableMenus"
95 #define PATCHTOOLBAR_KEY        "PatchToolBar"
96 #define WIDETOOLBAR_KEY         "WideToolBar"
97 #define PLUGINTOOLBAR_KEY "PluginToolBar"
98 #define NOCLAMP_KEY             "NoClamp"
99 #define PREFAB_KEY              "PrefabPath"
100 #define USERINI_KEY             "UserINIPath"
101 #define ROTATION_KEY            "Rotation"
102 #define BUGGYICD_KEY            "BuggyICD"
103 #define CHASEMOUSE_KEY          "ChaseMouse"
104 #define ENTITYSHOW_KEY          "EntityShow"
105 #define TEXTURESCALE_KEY        "TextureScale"
106 #define TEXTURESCROLLBAR_KEY    "TextureScrollbar"
107 #define DISPLAYLISTS_KEY        "UseDisplayLists"
108 #define ANTIALIASEDLINES_KEY    "UseAntialiasedPointsAndLines" // Fishman - Add antialiazed points and lines support. 09/03/00
109 #define NORMALIZECOLORS_KEY     "NormalizeColors"
110 #define SHADERS_KEY             "UseShaders"
111 #define SWITCHCLIP_KEY          "SwitchClipKey"
112 #define SELWHOLEENTS_KEY                    "SelectWholeEntitiesKey"
113 #define TEXTURESUBSET_KEY                 "UseTextureSubsetLoading"
114 #define TEXTUREQUALITY_KEY          "TextureQuality"
115 #define SHOWSHADERS_KEY               "ShowShaders"
116 #define SHADERTEST_KEY          "ShaderTest"
117 #define GLLIGHTING_KEY          "UseGLLighting"
118 #define LOADSHADERS_KEY         "LoadShaders"
119 #define NOSTIPPLE_KEY           "NoStipple"
120 #define UNDOLEVELS_KEY          "UndoLevels"
121 #define VERTEXMODE_KEY          "VertexSplit"
122 #define ENGINEPATH_KEY          "EnginePath"
123 #define ENGINE_KEY              "Engine"
124 #define LOGCONSOLE_KEY          "LogConsole"
125 #define SELECTCURVES_KEY        "SelectCurves"
126 #define SELECTMODELS_KEY        "SelectModels"
127 #define SHADERLISTONLY_KEY      "ShowShaderlistOnly"
128 #define WATCHBSP_KEY            "WatchBSP"
129 #define LEAKSTOP_KEY            "LeakStop"
130 #define DOSLEEP_KEY             "SleepMode"
131 #define SUBDIVISIONS_KEY        "Subdivisions"
132 #define CLIPCAULK_KEY           "ClipCaulk"
133 #define PATCHSHOWBOUNDS_KEY     "PatchShowBounds"
134 #define NATIVEGUI_KEY           "NativeGUI"
135 #define STARTONPRIMMON_KEY      "StartOnPrimMon"
136 #define NOSYSMENUPOPUPS_KEY     "NoSysMenuPopups"
137 #define SNAPTTOGRID_KEY         "SnapTToGrid"
138 #define FLOATINGZ_KEY           "FloatingZ"
139 #define TARGETFIX_KEY           "TargetFix"
140 #define GLPOINTWORKAROUND_KEY   "GlPointWorkaround"             // Gef: Workaround for broken Kyro * gl driver 25-aug-2001
141 #define WHEELINC_KEY            "WheelMouseInc"
142 #define PATCHBBOXSEL_KEY        "PatchBBoxSel"
143 #define LASTLIGHTINTENSITY_KEY  "LastLightIntensity"
144 #define CUSTOMSHADEREDITOR_KEY        "UseCustomShaderEditor"
145 #define CUSTOMSHADEREDITORCOMMAND_KEY "CustomShaderEditorCommand"
146 #define TEXTURECOMPRESSIONFORMAT_KEY "TextureCompressionFormat"
147 #define LIGHTRADIUS_KEY "LightRadiuses"
148 #define Q3MAP2TEX_KEY "Q3Map2Tex"
149 #define ATIHACK_KEY "ATIHack"
150
151 // window stuff
152 #define ENTITYSPLIT1_KEY  "EntitySplit1"
153 #define ENTITYSPLIT2_KEY  "EntitySplit2"
154 #define POSITIONX_KEY     "PositionX"
155 #define POSITIONY_KEY     "PositionY"
156 #define ENTITYWND_KEY     "EntityWnd"
157 #define MAPINFOWND_KEY    "MapInfoDlg"
158 #define CAMWND_KEY        "CamWnd"
159 #define ZWND_KEY          "ZWnd"
160 #define XYWND_KEY         "XYWnd"
161 #define XZWND_KEY         "XZWnd"
162 #define YZWND_KEY         "YZWnd"
163 #define PATCHWND_KEY      "PatchWnd"
164 #define SURFACEWND_KEY    "SurfaceWnd"
165 #define ENTITYINFOWND_KEY "EntityInfoDlg"
166 #define WIDTH_KEY         "Width"
167 #define HEIGHT_KEY        "Height"
168 #define ZWIDTH_KEY        "ZWidth"
169 #define XYHEIGHT_KEY      "XYHeight"
170 #define XYWIDTH_KEY       "XYWidth"
171 #define CAMWIDTH_KEY      "CamWidth"
172 #define CAMHEIGHT_KEY     "CamHeight"
173 #define ZFLOATWIDTH_KEY   "ZWidthFloating"
174 #define STATE_KEY         "State"
175
176 // menu stuff
177 #define COUNT_KEY         "Count"
178 #define FILE_KEY          "File"
179
180 //saved info
181 #define SI_TEXMENU_KEY          "SI_TexMenu"
182 #define SI_GAMMA_KEY            "SI_Gamma"
183 #define SI_COLORS_KEY           "SI_Colors"
184 #define SI_EXCLUDE_KEY          "SI_Exclude"
185 #define SI_INCLUDE_KEY          "SI_Include"
186 #define SI_SURFACE_TEXDEF_KEY   "SI_SurfaceTexdef"
187 #define SI_PATCH_TEXDEF_KEY     "SI_PatchTexdef"
188 #define SI_AXISCOLORS_KEY       "SI_AxisColors"
189 #define SI_SHOWNAMES_KEY        "SI_ShowNames"
190 #define SI_SHOWCOORDS_KEY       "SI_ShowCoords"
191 #define SI_SHOWANGLES_KEY       "SI_ShowAngles"
192 #define SI_SHOWOUTLINES_KEY     "SI_ShowOutlines"
193 #define SI_SHOWAXIS_KEY         "SI_ShowAxis"
194 #define SI_NOSELOUTLINES_KEY    "SI_NoSelectedOutlines"
195 #define SI_OUTLINESTYLE_KEY "SI_OutLineStyle"
196
197 //for texdefs
198 #define TD_SCALE1_KEY           "_Scale1"
199 #define TD_SCALE2_KEY           "_Scale2"
200 #define TD_SHIFT1_KEY           "_Shift1"
201 #define TD_SHIFT2_KEY           "_Shift2"
202 #define TD_ROTATE_KEY           "_Rotate"
203
204 #define MOUSE_DEF 1
205 #define WINDOW_DEF 0
206 #define RUNQ2_DEF 0
207 #define WATCHBSP_DEF 1
208 #define TLOCK_DEF 1
209 #define LOADLAST_DEF 1
210 #define RUN_DEF 0
211 #define SUBDIVISIONS_DEF 4
212
213 void WindowPosition_Parse(window_position_t& m_value, const CString& value)
214 {
215   if(sscanf(value.GetBuffer(), "%d %d %d %d", &m_value.x, &m_value.y, &m_value.w, &m_value.h) != 4)
216     m_value.x = m_value.y = m_value.w = m_value.h = -1;
217 }
218
219 void WindowPosition_Write(const window_position_t& m_value, CString& value)
220 {
221   char buffer[64];
222   sprintf(buffer, "%d %d %d %d", m_value.x, m_value.y, m_value.w, m_value.h);
223   value = buffer;
224 }
225
226
227 CXMLPropertyBag::CXMLPropertyBag() {
228   mStrFilename = "";
229   mpDoc = NULL;
230   mbEmpty = false;
231 }
232
233 // generic preference functions
234
235 void CXMLPropertyBag::PushAssignment(const char *name, PrefTypes_t type, void *pV)
236 {
237   list<CPrefAssignment>::iterator iAssign;
238   for(iAssign=mPrefAssignments.begin(); iAssign!=mPrefAssignments.end(); iAssign++)
239   {
240     if ((*iAssign).mName == name)
241     {
242       // we have it already, check anyway
243       if (pV != (*iAssign).mVal)
244       {
245         Sys_FPrintf(SYS_ERR, "PushAssignment, '%s' has different mVal\n", name);
246         return;
247       }
248     }
249   }
250   // ok, it's not in our list yet
251   mPrefAssignments.push_front(CPrefAssignment(name, type, pV));
252 }
253
254 xmlNodePtr CXMLPropertyBag::EpairForName(const char *name)
255 {
256   xmlNodePtr ret = NULL;
257
258   xmlNodePtr pNode = mpDocNode->children;
259   while (pNode != NULL)
260   {
261     if(pNode->type == XML_ELEMENT_NODE)
262     {
263       xmlAttrPtr tmp_attr_ptr = xmlHasProp(pNode, (xmlChar *)"name");
264       if (tmp_attr_ptr != NULL && !strcmp(name, (char *)tmp_attr_ptr->children->content))
265       {
266         if ( ret ) {
267           Sys_FPrintf( SYS_WRN, "WARNING: dupe property in CXMLPropertyBag::EpairForName '%s'\n", name );
268         } else {
269           ret = pNode;
270         }
271       }
272     }
273     pNode = pNode->next;
274   }
275   return ret;
276 }
277
278 void CXMLPropertyBag::GetPref(const char *name, Str *pV, const char *V)
279 {
280   xmlNodePtr pNode = EpairForName( name );
281   if ( pNode )
282   {
283     if ( pNode->children && pNode->children->content ) {
284       *pV = pNode->children->content;
285     } else {
286       // means the pref exists, and that the value is ""
287       *pV = "";
288     }
289   }
290   else
291   {
292     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)V);
293     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
294   }
295   // push the pref assignment if needed
296   PushAssignment(name, PREF_STR, pV);
297 }
298
299 void CXMLPropertyBag::GetPref(const char *name, int *pV, int V)
300 {
301   xmlNodePtr pNode;
302   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
303   {
304     *pV = atoi((char *)pNode->children->content);
305   }
306   else
307   {
308     char s[10];
309     sprintf(s, "%d", V);
310     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
311     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
312     *pV=V;
313   }
314   // push the pref assignment if needed
315   PushAssignment(name, PREF_INT, pV);
316 }
317
318 void CXMLPropertyBag::GetPref(const char *name, bool *pV, bool V)
319 {
320   xmlNodePtr pNode;
321   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
322   {
323     if (!strcmp((char *)pNode->children->content, "true"))
324     {
325       *pV = true;
326     }
327     else
328     {
329       *pV = false;
330     }
331   }
332   else
333   {
334     char s[10];
335     V ? strcpy(s, "true") : strcpy(s, "false");
336     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
337     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
338     *pV=V;
339   }
340   // push the pref assignment
341   PushAssignment(name, PREF_BOOL, pV);
342 }
343
344 void CXMLPropertyBag::GetPref(const char *name, float *pV, float V)
345 {
346   xmlNodePtr pNode;
347   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
348   {
349     *pV = atof((char *)pNode->children->content);
350   }
351   else
352   {
353     char s[10];
354     sprintf(s, "%f", V);
355     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
356     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
357     *pV=V;
358   }
359   // push the pref assignment if needed
360   PushAssignment(name, PREF_FLOAT, pV);
361 }
362
363 void CXMLPropertyBag::GetPref(const char *name, float* pV, float* V)
364 {
365   xmlNodePtr pNode;
366   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
367   {
368     sscanf((char *)pNode->children->content, "%f %f %f", &pV[0], &pV[1], &pV[2]);
369   }
370   else
371   {
372     char s[128];
373     sprintf(s, "%f %f %f", V[0], V[1], V[2]);
374     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
375     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
376     pV[0] = V[0];
377     pV[1] = V[1];
378     pV[2] = V[2];
379   }
380   // push the pref assignment if needed
381   PushAssignment(name, PREF_VEC3, pV);
382 }
383
384 void CXMLPropertyBag::GetPref(const char *name, window_position_t* pV, window_position_t V)
385 {
386   xmlNodePtr pNode;
387   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
388   {
389     WindowPosition_Parse(*pV, CString((xmlChar *)pNode->children->content));
390   }
391   else
392   {
393     CString str;
394     WindowPosition_Write(V, str);
395     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)str.GetBuffer());
396     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
397     *pV = V;
398   }
399   // push the pref assignment if needed
400   PushAssignment(name, PREF_WNDPOS, pV);
401 }
402
403 void CXMLPropertyBag::UpdatePrefTree()
404 {
405   // read the assignments and update the tree
406   list<CPrefAssignment>::iterator iPref;
407   for(iPref = mPrefAssignments.begin(); iPref != mPrefAssignments.end(); iPref++)
408   {
409     CPrefAssignment *pPref = &(*iPref);
410     // look for the node
411     xmlNodePtr pNode;
412     char s[64];
413
414     pNode = EpairForName(pPref->mName.GetBuffer());
415     // we never expect that the node could not be found, because this is supposed to happen
416     // after the tree was built with GetPref calls, never on a blank tree
417     if (!pNode)
418     {
419       Sys_FPrintf(SYS_ERR, "Unexpected EpairForName '%s' not found in UpdatePrefTree\n", pPref->mName.GetBuffer());
420       return;
421     }
422     switch ((*iPref).mType)
423     {
424     case PREF_STR:
425       xmlNodeSetContent(pNode, (const xmlChar *)((Str *)pPref->mVal)->GetBuffer());
426       break;
427     case PREF_INT:
428       sprintf(s, "%d", *(int *)pPref->mVal);
429       xmlNodeSetContent(pNode, (xmlChar *)s);
430       break;
431     case PREF_FLOAT:
432       sprintf(s, "%f", *(float *)pPref->mVal);
433       xmlNodeSetContent(pNode, (xmlChar *)s);
434       break;
435     case PREF_BOOL:
436       *(bool *)pPref->mVal ? strcpy(s, "true") : strcpy(s, "false");
437       xmlNodeSetContent(pNode, (xmlChar *)s);
438       break;
439     case PREF_VEC3:
440       {
441         float* v = (float*)pPref->mVal;
442         sprintf(s, "%f %f %f", v[0], v[1], v[2]);
443         xmlNodeSetContent(pNode, (xmlChar *)s);
444       }
445       break;
446     case PREF_WNDPOS:
447       {
448         CString str;
449         WindowPosition_Write(*(window_position_t*)pPref->mVal, str);
450         xmlNodeSetContent(pNode, (xmlChar*)str.GetBuffer());
451       }
452       break;
453     }
454   }
455 }
456
457 void CXMLPropertyBag::Clear()
458 {
459   if(!InUse())
460     return;
461
462   xmlFreeDoc(mpDoc);
463   mpDoc = NULL;
464   mpDocNode = NULL;
465   mbEmpty = false;
466 }
467
468 void CXMLPropertyBag::ReadXMLFile(const char* pFilename)
469 {
470   mpDoc = xmlParseFile(pFilename);
471
472   // basic checks
473   if (mpDoc)
474   {
475     mpDocNode = mpDoc->children;
476     xmlAttrPtr tmp_attr_ptr = xmlHasProp(mpDocNode, (xmlChar *)"version");
477     if (strcmp((char *)mpDocNode->name, "qpref"))
478     {
479       Sys_FPrintf(SYS_ERR, "Unrecognized node '%s' in '%s'\n", mpDocNode->name, mpDoc->URL);
480       xmlFreeDoc(mpDoc);
481       mpDoc = NULL;
482     }
483     else if (tmp_attr_ptr != NULL && strcmp((char*)tmp_attr_ptr->children->content, "1"))
484     {
485       Sys_FPrintf(SYS_ERR, "Wrong version '%s' in <qpref> node for '%s'\n", (char*)tmp_attr_ptr->children->content, mpDoc->URL);
486       xmlFreeDoc(mpDoc);
487       mpDoc = NULL;
488     }
489     Sys_Printf("Opened XML property file: '%s'\n", pFilename);
490   }
491
492   if (!mpDoc)
493   {
494     mbEmpty = true;
495     // no document, create one
496     mpDoc = xmlNewDoc((xmlChar *)"1.0");
497     mpDocNode = xmlNewDocNode(mpDoc, NULL, (xmlChar *)"qpref", NULL);
498     xmlDocSetRootElement(mpDoc, mpDocNode);
499     xmlSetProp(mpDocNode, (xmlChar *)"version", (xmlChar *)"1");
500     Sys_Printf("XML property file '%s' invalid/not found, creating blank properties tree\n", pFilename);
501   }
502 }
503
504 qboolean CXMLPropertyBag::WriteXMLFile(const char* pFilename)
505 {
506   int res = xmlSaveFormatFile(pFilename, mpDoc, 1);
507
508   if(res == -1)
509     return false;
510
511   Sys_Printf("Wrote XML property file '%s'\n", pFilename);
512   return true;
513 }
514
515 // =============================================================================
516 // Widget callbacks for PrefsDlg
517
518 #if !defined(WIN32)
519 // browse for custom editor executable
520 static void OnBtnBrowseEditor (GtkWidget *widget, gpointer data)
521 {
522   PrefsDlg *dlg = (PrefsDlg*)data;
523
524   const char *filename = file_dialog(g_PrefsDlg.GetWidget(), TRUE, _("Executable for Custom Editor"));
525
526   if(filename != NULL)
527   {
528     dlg->m_strEditorCommand = filename;
529     dlg->UpdateData(FALSE);
530   }
531 }
532 #endif
533
534 static void OnBtnBrowseprefab (GtkWidget *widget, gpointer data)
535 {
536   PrefsDlg *dlg = (PrefsDlg*)data;
537   char *path = dlg->m_strPrefabPath;
538   if (strlen (path) == 0)
539     path = g_strGameToolsPath;
540   char *dir = dir_dialog (g_PrefsDlg.GetWidget (), _("Set prefab path"), path);
541   dlg->UpdateData(TRUE);
542
543   if (dir != NULL)
544   {
545     CString strPath;
546     strPath = dir;
547     AddSlash(strPath);
548     dlg->m_strPrefabPath = strPath;
549     dlg->UpdateData(FALSE);
550     free (dir);
551   }
552 }
553
554 static void OnBtnBrowseuserini (GtkWidget *widget, gpointer data)
555 {
556   PrefsDlg *dlg = (PrefsDlg*)data;
557   char *path = dlg->m_strUserPath;
558   if (strlen (path) == 0)
559     path = g_strGameToolsPath;
560   // TODO: INI filter?
561   const char *filename = file_dialog (g_PrefsDlg.GetWidget(), TRUE, _("Find INI file"), path);
562
563   if (filename != NULL)
564   {
565     dlg->UpdateData(TRUE);
566     dlg->m_strUserPath = filename;
567     dlg->UpdateData(FALSE);
568   }
569 }
570
571 static void OnButtonClean (GtkWidget *widget, gpointer data)
572 {
573   // make sure this is what the user wants
574   if (gtk_MessageBox (g_PrefsDlg.GetWidget (), _("This will close Radiant and clean the corresponding registry entries.\n"
575                   "Next time you start Radiant it will be good as new. Do you wish to continue?"),
576                   _("Reset Registry"), MB_YESNO) == IDYES)
577   {
578     PrefsDlg *dlg = (PrefsDlg*)data;
579     dlg->EndModal (IDCANCEL);
580
581     g_qeglobals.disable_ini = true;
582     remove (dlg->m_inipath->str);
583     char buf[PATH_MAX];
584     sprintf(buf, "%sSavedInfo.bin", dlg->m_rc_path->str);
585     remove(buf);
586     HandleCommand (NULL, GINT_TO_POINTER (ID_FILE_EXIT));
587     _exit (0);
588   }
589 }
590
591 // =============================================================================
592 // PrefsDlg class
593
594 // IMPORTANT NOTE: the values here don't matter very much
595 // the actual intialization if you start with an empty .ini is done when loading the prefs for the first time
596 // profile_load_int takes an argument to use if the value is not found
597 PrefsDlg::PrefsDlg ()
598 {
599   m_bWarn = TRUE;
600   m_nMouse = 1;
601   m_nView = MainFrame::eRegular;
602   m_bLoadLast = FALSE;
603   m_bInternalBSP = FALSE;
604   m_bRightClick = FALSE;
605   m_bSetGame = FALSE;
606   m_bAutoSave = TRUE;
607   m_nAutoSave = 5;
608   m_bLoadLastMap = FALSE;
609   m_bTextureWindow = FALSE;
610   m_bSnapShots = FALSE;
611   m_fTinySize = 0.5;
612   m_bCleanTiny = FALSE;
613   m_bCamXYUpdate = TRUE;
614   m_bCamDragMultiSelect = FALSE;
615   m_bCamFreeLook = TRUE;
616   m_bCamFreeLookStrafe = FALSE;
617   m_bCamInverseMouse = FALSE;
618   m_bCamDiscrete = TRUE;
619   m_bNewLightDraw = FALSE;
620   m_strPrefabPath = "";
621   m_nWhatGame = 0;
622   m_bALTEdge = FALSE;
623   m_bFaceColors = FALSE;
624   m_bXZVis = FALSE;
625   m_bYZVis = FALSE;
626   m_bZVis = FALSE;
627   m_bSizePaint = FALSE;
628   m_bDLLEntities = FALSE;
629 #ifdef _WIN32
630   m_bDetachableMenus = FALSE;   // Most win32 users will find detachable menus annoying
631 #else
632   m_bDetachableMenus = TRUE;    // Linux/Apple users are used to them...
633 #endif
634   m_bPatchToolbar = TRUE;
635   m_bWideToolbar = TRUE;
636   m_bPluginToolbar = TRUE;
637   m_bNoClamp = FALSE;
638   m_strUserPath = "";
639   m_nRotation = 0;
640   m_bChaseMouse = FALSE;
641   m_bTextureScrollbar = TRUE;
642   m_bDisplayLists = TRUE;
643   m_bAntialiasedPointsAndLines = FALSE; // Fishman - Add antialiazed points and lines support. 09/03/00
644   m_bShowShaders = FALSE;
645   m_nShader = -1;
646   m_bNoStipple = FALSE;
647   m_bVertexSplit = FALSE;
648   m_bSelectCurves = TRUE;
649   m_bSelectModels = TRUE;
650   m_nEntityShowState = ENTITY_SKINNED_BOXED;
651   m_nTextureScale = 2;
652   m_bSwitchClip = FALSE;
653   m_bSelectWholeEntities = TRUE;
654   m_nTextureQuality = 3;
655   m_bShowShaders = TRUE;
656   m_bGLLighting = FALSE;
657   m_nShader = 0;
658   m_nUndoLevels = 30;
659   m_bTexturesShaderlistOnly = FALSE;
660   // paths to ini files
661   m_rc_path = NULL;
662   m_inipath = NULL;
663   m_bWatchBSP = TRUE;
664   m_bLeakStop = TRUE;
665   m_iTimeout = 15;
666   m_bRunQuake = TRUE;
667   m_bDoSleep = FALSE;
668   m_nSubdivisions = 4;
669   // not prefs
670   m_bFloatingZ = FALSE;
671   m_bGlPtWorkaround = FALSE;    // Gef: Kyro/GL_POINTS workaround 25-aug-2001
672 #ifdef _WIN32
673   m_bNativeGUI = FALSE;
674   m_bStartOnPrimMon = FALSE;
675 #endif
676   m_global_rc_path = NULL;
677 #ifdef _WIN32
678   m_bUseWin32Editor = TRUE;
679 #else
680   // custom shader editor options
681   m_bUseCustomEditor = FALSE;
682   m_strEditorCommand = "";
683 #endif
684   m_nLightRadiuses = 1;
685   m_bQ3Map2Texturing = TRUE;
686 #ifdef ATIHACK_812
687         m_bGlATIHack = FALSE;
688 #endif
689 }
690
691 /*!
692 =========================================================
693 Games selection dialog
694 =========================================================
695 */
696
697 #if defined(WIN32)
698 #define ENGINE_ATTRIBUTE "engine_win32"
699 #define MP_ENGINE_ATTRIBUTE "mp_engine_win32"
700 #elif defined(__linux__) || defined (__FreeBSD__)
701 #define ENGINE_ATTRIBUTE "engine_linux"
702 #define MP_ENGINE_ATTRIBUTE "mp_engine_linux"
703 #elif defined(__APPLE__)
704 #define ENGINE_ATTRIBUTE "engine_macos"
705 #define MP_ENGINE_ATTRIBUTE "mp_engine_macos"
706 #else
707 #error "unsupported platform"
708 #endif
709
710
711 #if defined(WIN32)
712 #define ENGINEPATH_ATTRIBUTE "enginepath_win32"
713 #elif defined(__linux__) || defined (__FreeBSD__)
714 #define ENGINEPATH_ATTRIBUTE "enginepath_linux"
715 #elif defined(__APPLE__)
716 #define ENGINEPATH_ATTRIBUTE "enginepath_macos"
717 #else
718 #error "unknown platform"
719 #endif
720
721
722 CGameDescription::CGameDescription(xmlDocPtr pDoc, const Str &GameFile)
723 {
724   char *p, *prop;
725   mpDoc = pDoc;
726   // read the user-friendly game name
727   xmlNodePtr pNode = mpDoc->children;
728
729   while (strcmp((const char*)pNode->name, "game") && pNode != NULL) pNode=pNode->next;
730   if (!pNode)
731   {
732     ///< \todo add the file name (this node and gametools should all be part of CGameDescription anyway)
733     Error("Didn't find 'game' node in the game description file '%s'\n", pDoc->URL);
734   }
735   // on win32, game tools path can now be specified relative to the exe's cwd
736   prop = (char*)xmlGetProp( pNode, (xmlChar*)"gametools" );
737   if ( prop == NULL ) {
738         Error( "Didn't find 'gametools' node in the game description file '%s'\n", pDoc->URL );
739   }
740   {
741         char full[PATH_MAX];
742 #ifdef _WIN32
743         _fullpath( full, prop, PATH_MAX );
744 #else
745     strncpy( full, prop, PATH_MAX );
746 #endif
747     xmlFree( prop );
748     prop = NULL;
749     for ( p = full; *p != '\0'; p++ ) {
750           if ( *p == '\\' ) {
751             *p = '/';
752           }
753           mGameToolsPath = full;
754           if ( p != full && *(p-1) != '/' ) {
755             mGameToolsPath += "/";
756           }
757     }
758   }
759
760   prop = (char*)xmlGetProp(pNode, (xmlChar*)"name");
761   if (prop == NULL)
762   {
763     Sys_FPrintf(SYS_WRN, "Warning, 'name' attribute not found in '%s'\n", pDoc->URL);
764     mGameName = pDoc->URL;
765   }
766   else
767   {
768     mGameName = prop;
769     xmlFree(prop);
770   }
771
772   mGameFile = GameFile;
773
774   prop = (char*)xmlGetProp(pNode, (xmlChar*)"quake2");
775   if (prop == NULL)
776   {
777     // default
778     quake2 = false;
779   }
780   else
781   {
782     quake2 = true;
783     xmlFree(prop);
784   }
785
786   // if this is set, the open maps dialoge will open the engine path not the
787   // home dir for map loading and saving
788   prop = (char*)xmlGetProp(pNode, (xmlChar*)"no_maps_in_home");
789   if (prop == NULL)
790   {
791     // default
792     noMapsInHome = false;
793   }
794   else
795   {
796     noMapsInHome = true;
797     xmlFree(prop);
798   }
799
800   prop = (char*)xmlGetProp(pNode, (xmlChar*)"basegame");
801   if (prop == NULL)
802   {
803     // default
804     mBaseGame = "baseq3";
805   }
806   else
807   {
808     mBaseGame = prop;
809     xmlFree(prop);
810   }
811
812
813         prop = (char*)xmlGetProp(pNode, (const xmlChar*)ENGINE_ATTRIBUTE);
814         if (prop == NULL)
815         {
816 #ifdef _WIN32
817                 mEngine = "quake3.exe";
818 #elif __linux__
819                 mEngine = "quake3";
820 #elif __APPLE__
821                 mEngine = "Quake3.app";
822 #endif
823         }
824         else
825         {
826                 mEngine = prop;
827                 xmlFree(prop);
828         }
829
830         prop = (char*)xmlGetProp(pNode, (const xmlChar*)MP_ENGINE_ATTRIBUTE);
831         if (prop == NULL)
832         {
833 #ifdef _WIN32
834                 mMultiplayerEngine = "quake3.exe";
835 #elif __linux__
836                 mMultiplayerEngine = "quake3";
837 #elif __APPLE__
838                 mMultiplayerEngine = "Quake3.app";
839 #endif
840         }
841         else
842         {
843                 mMultiplayerEngine = prop;
844                 xmlFree(prop);
845         }
846
847         {
848                 // on win32, engine path can now be specified relative to the exe's cwd
849                 prop = (char*)xmlGetProp(pNode, (const xmlChar *)ENGINEPATH_ATTRIBUTE);
850                 if ( prop != NULL ) {
851                         char full[PATH_MAX];
852                 #ifdef _WIN32
853                         _fullpath( full, prop, PATH_MAX );
854                 #else
855                         strncpy( full, prop, PATH_MAX );
856                 #endif
857                         xmlFree( prop );
858                         prop = NULL;
859                         // process seperators
860                         for ( p = full; *p != '\0'; p++ ) {
861                                 if ( *p == '\\' ) {
862                                         *p = '/';
863                                 }
864                         }
865                         mEnginePath = full;
866                         if ( p != full && *(p-1) != '/' ) {
867                                 mEnginePath += "/";
868                         }
869                 }
870                 else
871                 {
872                         // if engine path was not specified in the .game, it implies we can guess it from the gametools path
873                         // on win32, and for most game package, the gametools are installed with the game
874                         char aux_path[PATH_MAX]; // aux
875                         strcpy( aux_path, mGameToolsPath.GetBuffer() );
876                         if ( ( aux_path[ strlen(aux_path)-1 ] == '/' ) || ( aux_path[ strlen(aux_path)-1 ] == '\\' ) ) {
877                                 aux_path[strlen(aux_path)-1] = '\0'; // strip ending '/' if any
878                         }
879                         char up_path[PATH_MAX]; // up one level
880                         ExtractFilePath( aux_path, up_path );
881                         mEnginePath = up_path;
882                 }
883         }
884
885 #if defined (__linux__) || defined (__APPLE__)
886   // *nix specific
887   prop = (char*)xmlGetProp(pNode, (const xmlChar *)"prefix");
888   if(prop != NULL)
889   {
890     mUserPathPrefix = prop;
891     xmlFree(prop);
892   }
893 #endif
894   mShaderPath = xmlGetProp(pNode, (const xmlChar *)"shaderpath");
895   if (!mShaderPath.GetLength())
896   {
897     mShaderPath = "scripts/";
898     mShaderlist = "scripts/shaderlist.txt";
899   }
900   else
901   {
902     AddSlash(mShaderPath);
903     mShaderlist = mShaderPath;
904     mShaderlist += "shaderlist.txt";
905   }
906   xmlChar* default_scale = xmlGetProp(pNode, (const xmlChar *)"default_scale");
907   if (default_scale)
908   {
909     mTextureDefaultScale = atof((const char *)default_scale);
910     xmlFree(default_scale);
911   }
912   else
913     mTextureDefaultScale = 0.5f;
914   xmlChar* eclass_singleload = xmlGetProp(pNode, (const xmlChar*)"eclass_singleload");
915   if (eclass_singleload)
916   {
917     mEClassSingleLoad = true;
918     xmlFree(eclass_singleload);
919   }
920   else
921     mEClassSingleLoad = false;
922   xmlChar* no_patch = xmlGetProp(pNode, (const xmlChar *)"no_patch");
923   if (no_patch)
924   {
925     mNoPatch = true;
926     xmlFree(no_patch);
927   }
928   else
929     mNoPatch = false;
930   xmlChar* caulk_shader = xmlGetProp(pNode, (const xmlChar *)"caulk_shader");
931   if (caulk_shader)
932   {
933     mCaulkShader = caulk_shader;
934     xmlFree(caulk_shader);
935   }
936   else
937     mCaulkShader = "textures/common/caulk";
938 }
939
940 void CGameDescription::Dump()
941 {
942 #ifdef _WIN32
943   if (CGameDialog::GetNetrun())
944     Sys_Printf("Running in network mode, prefs path set to '%s'\n", g_strTempPath.GetBuffer());
945 #endif
946   Sys_Printf("game name            : '%s'\n", mGameName.GetBuffer());
947   Sys_Printf("game file            : '%s'\n", mGameFile.GetBuffer());
948   Sys_Printf("game path            : '%s'\n", mGameToolsPath.GetBuffer());
949   Sys_Printf("base game            : '%s'\n", mBaseGame.GetBuffer());
950   Sys_Printf("engine path          : '%s'\n", mEnginePath.GetBuffer());
951   Sys_Printf("engine               : '%s'\n", mEngine.GetBuffer());
952   Sys_Printf("shaderlist           : '%s'\n", mShaderlist.GetBuffer());
953   Sys_Printf("caulk shader: '%s'\n", mCaulkShader.GetBuffer());
954 #if defined (__linux__) || defined (__APPLE__)
955   Sys_Printf("prefix               : '%s'\n", mUserPathPrefix.GetBuffer());
956 #endif
957   Sys_Printf("default texture scale: %g\n", mTextureDefaultScale);
958   Sys_Printf("single eclass load   : %s\n", mEClassSingleLoad ? "Yes" : "No");
959   Sys_Printf("patches supported    : %s\n", mNoPatch ? "No" : "Yes");
960 }
961
962 CPrefAssignment& CPrefAssignment::operator = (const CPrefAssignment& ass)
963 {
964   if (&ass != this)
965   {
966     mName = ass.mName;
967     mType = ass.mType;
968     mVal = ass.mVal;
969   }
970   return *this;
971 }
972
973 CPrefAssignment::CPrefAssignment(const CPrefAssignment& ass)
974 {
975   *this = ass;
976 }
977
978 void CGameDialog::LoadPrefs()
979 {
980   // if we already have a document loaded, we will free and reload from file
981   if (mGlobalPrefs.InUse())
982   {
983     Sys_Printf("Reloading global prefs from file\n");
984     mGlobalPrefs.Clear();
985   }
986
987   // load global .pref file
988   CString strGlobalPref = g_PrefsDlg.m_global_rc_path->str;
989   strGlobalPref += "global.pref";
990
991   mGlobalPrefs.ReadXMLFile(strGlobalPref.GetBuffer());
992
993   mGlobalPrefs.GetPref("gamefile", &m_sGameFile, ""); // NOTE: there's no default, user HAS to select something
994   mGlobalPrefs.GetPref("autoload", &m_bAutoLoadGame, false);
995   mGlobalPrefs.GetPref("log console", &m_bLogConsole, false);
996   // in a very particular post-.pid startup
997   // we may have the console turned on and want to keep it that way
998   // so we use a latching system
999   if (m_bForceLogConsole)
1000   {
1001     m_bLogConsole = true;
1002     Sys_Printf("console logging has been latched on, saving prefs\n");
1003     SavePrefs();
1004     m_bForceLogConsole = false;
1005   }
1006
1007   // console logging: call Sys_LogConsole to check console logging status
1008   // it is important that we would log console as early as possible to make it useful
1009   Sys_LogFile();
1010
1011   if (mGlobalPrefs.mbEmpty)
1012   {
1013     Sys_Printf("Saving global.pref with default pref values\n");
1014     SavePrefs();
1015   }
1016 }
1017
1018 void CGameDialog::SavePrefs()
1019 {
1020   // update the tree and save it
1021   mGlobalPrefs.UpdatePrefTree();
1022
1023   CString strGlobalPref = g_PrefsDlg.m_global_rc_path->str;
1024   strGlobalPref += "global.pref";
1025
1026   if ( !mGlobalPrefs.WriteXMLFile( strGlobalPref.GetBuffer() ) ) {
1027     Sys_FPrintf(SYS_ERR, "Error occured while saving global prefs file '%s'\n", strGlobalPref.GetBuffer());
1028   }
1029 }
1030
1031 void CGameDialog::DoGameInstall() {
1032         // make sure console logging is on whenever we enter the installation loop
1033     g_PrefsDlg.mGamesDialog.m_bLogConsole = true;
1034         Sys_LogFile();
1035         mGameInstall.Run();
1036 }
1037
1038 void CGameDialog::DoGameDialog() {
1039         // allow looping the game selection dialog with calls to the game configure dialog in between
1040         while ( m_bDoGameInstall ) {
1041
1042                 m_bDoGameInstall = false;
1043
1044                 if ( DoModal() == IDCANCEL ) {
1045                         Error( "game selection dialog canceled, cannot continue" );
1046                         return;
1047                 }
1048
1049                 if ( m_bDoGameInstall ) {
1050                         DoGameInstall();
1051                         ScanForGames();
1052                         // and we will loop to do another DoModal dialog
1053                 }
1054         }
1055
1056         // unhook so we can use in other places
1057         // we manually incref'ed it when creating, it won't be freed (destructor)
1058         gtk_container_remove( GTK_CONTAINER( mTopBox ), GetGlobalFrame() );
1059
1060         // we save the prefs file
1061         SavePrefs();
1062 }
1063
1064 GtkWidget* CGameDialog::GetGlobalFrame()
1065 {
1066   GtkWidget *vbox, *text, *combo, *check;
1067
1068   if ( mFrame != NULL ) {
1069           return mFrame;
1070   }
1071
1072   mFrame = gtk_frame_new( NULL );
1073   gtk_container_set_border_width( GTK_CONTAINER( mFrame ), 5 );
1074   gtk_widget_show( mFrame );
1075
1076   vbox = gtk_vbox_new( FALSE, 6 );
1077   gtk_widget_show( vbox );
1078   gtk_container_add( GTK_CONTAINER( mFrame ), vbox );
1079   gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
1080
1081   text = gtk_label_new( _("Select the game:") );
1082   gtk_widget_show( text );
1083   gtk_box_pack_start( GTK_BOX( vbox ), text, FALSE, FALSE, 0 );
1084
1085   combo = gtk_combo_box_new_text();
1086   gtk_widget_show( combo );
1087   gtk_box_pack_start( GTK_BOX( vbox ), combo, FALSE, FALSE, 0 );
1088   AddDialogData( combo, &m_nComboSelect, DLG_COMBO_BOX_INT );
1089   mGameCombo = GTK_COMBO_BOX( combo );
1090
1091   UpdateGameCombo();
1092
1093   check = gtk_check_button_new_with_label( _("Auto load selected game on startup") );
1094   gtk_widget_show(check);
1095   gtk_box_pack_start (GTK_BOX(vbox), check, FALSE, FALSE, 0);
1096   AddDialogData (check, &m_bAutoLoadGame, DLG_CHECK_BOOL);
1097
1098   text = gtk_label_new(_("(this frame is available in the prefs menu if you set auto-select)"));
1099   gtk_widget_show(text);
1100   gtk_box_pack_start (GTK_BOX(vbox), text, FALSE, FALSE, 0);
1101
1102 #ifdef _WIN32
1103   check = gtk_check_button_new_with_label( _("Networked install - per-user settings") );
1104   gtk_widget_show( check );
1105   gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 );
1106   AddDialogData( check, &m_bNetRun, DLG_CHECK_BOOL );
1107 #endif
1108
1109   check = gtk_check_button_new_with_label( _("Log the console to radiant.log") );
1110   gtk_widget_show( check );
1111   gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 );
1112   AddDialogData( check, &m_bLogConsole, DLG_CHECK_BOOL );
1113
1114   // incref it so we can pass it around
1115   gtk_widget_ref( GTK_WIDGET( mFrame ) );
1116
1117   return mFrame;
1118 }
1119
1120 void CGameDialog::UpdateData( bool retrieve ) {
1121   if (!retrieve)
1122   {
1123     // use m_sGameFile to set m_nComboSelect
1124     list<CGameDescription *>::iterator iGame;
1125     int i = 0;
1126     for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1127     {
1128       if ((*iGame)->mGameFile == m_sGameFile)
1129       {
1130         m_nComboSelect = i;
1131         break;
1132       }
1133       i++;
1134     }
1135 #ifdef _WIN32
1136     UpdateNetrun(false);
1137 #endif
1138   }
1139   Dialog::UpdateData(retrieve);
1140   if (retrieve)
1141   {
1142     // use m_nComboSelect to set m_sGameFile
1143     list<CGameDescription *>::iterator iGame = mGames.begin();
1144     int i;
1145     for(i=0; i<m_nComboSelect; i++)
1146     {
1147       iGame++;
1148     }
1149     m_sGameFile = (*iGame)->mGameFile;
1150 #ifdef _WIN32
1151     UpdateNetrun(true);
1152 #endif
1153   }
1154 }
1155
1156 void CGameDialog::SInstallCallback( GtkWidget *widget, gpointer data ) {
1157         CGameDialog *d = static_cast< CGameDialog* >( data );
1158         d->m_bDoGameInstall = true;
1159         d->EndModal( 0 );
1160 }
1161
1162 void CGameDialog::BuildDialog() {
1163         GtkWidget *dlg, *vbox1, *button, *setup_button;
1164
1165         dlg = m_pWidget;
1166         gtk_window_set_title( GTK_WINDOW( dlg ), _("Select Game") );
1167
1168         vbox1 = gtk_vbox_new( FALSE, 0 );
1169         gtk_widget_show( vbox1 );
1170         gtk_container_add( GTK_CONTAINER( dlg ), vbox1 );
1171
1172         gtk_container_add( GTK_CONTAINER( vbox1 ), GetGlobalFrame() );
1173         mTopBox = vbox1;
1174
1175         setup_button = gtk_button_new_with_label( _("Configure more games") );
1176         gtk_widget_show( setup_button );
1177         gtk_box_pack_start( GTK_BOX( vbox1 ), setup_button, FALSE, FALSE, 0 );
1178         gtk_signal_connect( GTK_OBJECT( setup_button ), "clicked",
1179                                                 GTK_SIGNAL_FUNC( SInstallCallback ), this );
1180
1181         button = gtk_button_new_with_label( _("OK") );
1182         gtk_widget_show( button );
1183         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
1184         AddModalButton( button, IDOK );
1185
1186         button = gtk_button_new_with_label( _("Cancel") );
1187         gtk_widget_show( button );
1188         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
1189         AddModalButton( button, IDCANCEL );
1190
1191         gtk_widget_set_usize( button, 60, -2 );
1192 }
1193
1194 void CGameDialog::UpdateGameCombo() {
1195   // fill in with the game descriptions
1196   list<CGameDescription *>::iterator iGame;
1197
1198   if ( mGameCombo == NULL ) {
1199           Sys_Printf( "mGameCombo == NULL\n" );
1200           return;
1201   }
1202
1203   // clear whatever is in - wtf no way to know how many text entries?
1204   // use set/get active to track
1205   gtk_combo_box_set_active( mGameCombo, 0 );
1206   while ( gtk_combo_box_get_active( mGameCombo ) == 0 ) {
1207           gtk_combo_box_remove_text( mGameCombo, 0 );
1208           gtk_combo_box_set_active( mGameCombo, 0 );
1209   }
1210
1211   for ( iGame = mGames.begin(); iGame != mGames.end(); iGame++ ) {
1212           gtk_combo_box_append_text( mGameCombo, (*iGame)->mGameName.GetBuffer() );
1213   }
1214   gtk_combo_box_set_active( mGameCombo, 0 );
1215 }
1216
1217 void CGameDialog::ScanForGames()
1218 {
1219   CString strPath;
1220   char *dirlist;
1221   GDir *dir;
1222   CString strGamesPath = g_strAppPath.GetBuffer();
1223   strGamesPath += "games";
1224   const char *path = strGamesPath.GetBuffer();
1225
1226   if ( !mGames.empty() ) {
1227           Sys_Printf( "Clearing game list\n" );
1228           list<CGameDescription*>::iterator iGame;
1229           for ( iGame = mGames.begin(); iGame != mGames.end(); iGame++ ) {
1230                   delete (*iGame);
1231           }
1232           mGames.clear();
1233   }
1234
1235   Sys_Printf( "Scanning for game description files: %s\n", path );
1236
1237   /*!
1238   \todo FIXME LINUX:
1239   do we put game description files below g_strAppPath, or in ~/.radiant
1240   i.e. read only or read/write?
1241   my guess .. readonly cause it's an install
1242   we will probably want to add ~/.radiant/<version>/games/ scanning on top of that for developers
1243   (if that's really needed)
1244   */
1245
1246   // FIXME need to catch the 'no game description' situation and exit with a clean error
1247
1248   dir = g_dir_open(path, 0, NULL);
1249
1250   if (dir != NULL)
1251   {
1252     while (1)
1253     {
1254       const gchar* name = g_dir_read_name(dir);
1255       if(name == NULL)
1256         break;
1257
1258       dirlist = g_strdup(name);
1259 #ifdef _WIN32
1260       strlwr (dirlist);
1261 #endif
1262       char *ext = strrchr (dirlist, '.');
1263       if ((ext == NULL) || (strcmp (ext, ".game") != 0))
1264         continue;
1265       strPath.Format("%s/%s", path, dirlist);
1266       Sys_Printf("%s\n", strPath.GetBuffer());
1267       // got one, load it
1268       xmlDocPtr pDoc = xmlParseFile(strPath.GetBuffer());
1269       if (pDoc)
1270       {
1271         mGames.push_front( new CGameDescription( pDoc, dirlist ) );
1272       }
1273       else
1274       {
1275         Sys_FPrintf(SYS_ERR, "XML parser failed on '%s'\n", strPath.GetBuffer());
1276       }
1277
1278       g_free( dirlist );
1279     }
1280     g_dir_close( dir );
1281   }
1282
1283   // entries in the combo need to be updated
1284   UpdateGameCombo();
1285 }
1286
1287 CGameDescription* CGameDialog::GameDescriptionForComboItem()
1288 {
1289   list<CGameDescription *>::iterator iGame;
1290   int i=0;
1291   for( iGame = mGames.begin(); iGame != mGames.end(); iGame++,i++ ) {
1292     if ( i == m_nComboSelect ) {
1293       return (*iGame);
1294     }
1295   }
1296   return NULL; // not found
1297 }
1298
1299 void CGameDialog::InitGlobalPrefPath()
1300 {
1301   GString *global_rc_path;
1302   // configure m_global_rc_path
1303   // this is the g_strTempPath, and it has already been mkdir'ed
1304   global_rc_path = g_string_new(g_strTempPath.GetBuffer());
1305   g_PrefsDlg.m_global_rc_path = global_rc_path;
1306 }
1307
1308 void CGameDialog::Reset()
1309 {
1310   if (!g_PrefsDlg.m_global_rc_path)
1311     InitGlobalPrefPath();
1312   CString strGlobalPref = g_PrefsDlg.m_global_rc_path->str;
1313   strGlobalPref += "global.pref";
1314   remove(strGlobalPref.GetBuffer());
1315 }
1316
1317 void CGameDialog::Init()
1318 {
1319   InitGlobalPrefPath();
1320   ScanForGames();
1321   if ( mGames.empty() ) {
1322           DoGameInstall();
1323           ScanForGames();
1324           if ( mGames.empty() ) {
1325                   Error( "No games setup, aborting\n" );
1326           }
1327   }
1328   LoadPrefs();
1329   if ( m_bAutoLoadGame ) {
1330     // search by .game name
1331     list<CGameDescription *>::iterator iGame;
1332     for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1333     {
1334       if ((*iGame)->mGameFile == m_sGameFile)
1335       {
1336         m_pCurrentGameDescription = (*iGame);
1337         break;
1338       }
1339     }
1340   }
1341   if ( !m_bAutoLoadGame || !m_pCurrentGameDescription ) {
1342     DoGameDialog();
1343     // use m_nComboSelect to identify the game to run as and set the globals
1344     m_pCurrentGameDescription = GameDescriptionForComboItem();
1345     if ( !m_pCurrentGameDescription ) {
1346                 Error("Lookup of game description object failed, can't continue\n");
1347         }
1348   }
1349   g_pGameDescription = m_pCurrentGameDescription;
1350
1351   g_strGameToolsPath = g_pGameDescription->mGameToolsPath;
1352
1353         // NOTE TTimo: this is moved from QE_LoadProject in 1.2
1354         // (probably broken)
1355   // NOTE Hydra: was broken for win32, we don't use m_strHomeGame or m_strFSBasePath
1356 #if defined (__linux__) || defined (__APPLE__)
1357   g_qeglobals.m_strHomeGame = g_get_home_dir();
1358   g_qeglobals.m_strHomeGame += "/";
1359   g_qeglobals.m_strHomeGame += m_pCurrentGameDescription->mUserPathPrefix.GetBuffer();
1360   g_qeglobals.m_strHomeGame += "/";
1361 #else
1362   g_qeglobals.m_strHomeGame = g_pGameDescription->mEnginePath.GetBuffer();
1363 #endif
1364
1365   g_pGameDescription->Dump();
1366 }
1367
1368 CGameDialog::~CGameDialog()
1369 {
1370   if (mFrame)
1371   {
1372     // NOTE I'm not too sure how reliable this is
1373     gtk_widget_unref(GTK_WIDGET(mFrame));
1374   }
1375   // free all the game descriptions
1376   list<CGameDescription *>::iterator iGame;
1377   for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1378   {
1379     delete (*iGame);
1380     *iGame = NULL;
1381   }
1382 }
1383
1384 void CGameDialog::AddPacksURL(Str &URL)
1385 {
1386   // add the URLs for the list of game packs installed
1387   // FIXME: this is kinda hardcoded for now..
1388   list<CGameDescription *>::iterator iGame;
1389   for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1390   {
1391     if ((*iGame)->mGameFile == "q3.game")
1392       URL += "&Games_dlup%5B%5D=1";
1393     else if ((*iGame)->mGameFile == "wolf.game")
1394       URL += "&Games_dlup%5B%5D=2";
1395         // FIXME: double entry
1396     else if ((*iGame)->mGameFile == "wolf.game")
1397       URL += "&Games_dlup%5B%5D=3";
1398     else if ((*iGame)->mGameFile == "jk2.game")
1399       URL += "&Games_dlup%5B%5D=4";
1400     else if ((*iGame)->mGameFile == "stvef.game")
1401       URL += "&Games_dlup%5B%5D=5";
1402     else if ((*iGame)->mGameFile == "sof2.game")
1403       URL += "&Games_dlup%5B%5D=6";
1404     else if ((*iGame)->mGameFile == "ja.game")
1405       URL += "&Games_dlup%5B%5D=7";
1406   }
1407 }
1408
1409 #ifdef _WIN32
1410
1411 #define NETRUN_FILENAME "netrun.conf"
1412
1413 bool CGameDialog::m_bNetRun;
1414
1415 void CGameDialog::UpdateNetrun(bool retrieve)
1416 {
1417   FILE *f_netrun;
1418   CString strNetrun;
1419   strNetrun = g_strAppPath; strNetrun += NETRUN_FILENAME;
1420   if (!retrieve)
1421   {
1422     // now check if we are running from a network installation
1423     // use a dummy file as the flag
1424     f_netrun = fopen(strNetrun.GetBuffer(), "r");
1425     if (f_netrun)
1426     {
1427       fclose(f_netrun);
1428       m_bNetRun = true;
1429     }
1430     else
1431       m_bNetRun = false;
1432   }
1433   else
1434   {
1435     if (m_bNetRun)
1436     {
1437       f_netrun = fopen(strNetrun.GetBuffer(), "w");
1438       if (!f_netrun)
1439       {
1440         Sys_FPrintf(SYS_ERR, "ERROR: Failed to create netrun file '%s'\n", strNetrun.GetBuffer());
1441         m_bNetRun = false;
1442       }
1443       else
1444       {
1445         fclose(f_netrun);
1446         Sys_Printf("Created/Checked '%s'\n", strNetrun.GetBuffer());
1447       }
1448     }
1449     else
1450     {
1451       if (remove(strNetrun.GetBuffer()) == -1)
1452       {
1453         if (errno != ENOENT)
1454           Sys_FPrintf(SYS_ERR, "Failed to remove netrun file '%s'\n", strNetrun.GetBuffer());
1455         m_bNetRun = true;
1456       }
1457       else
1458       {
1459         Sys_Printf("Netrun mode is disabled\n");
1460       }
1461     }
1462   }
1463 }
1464
1465 bool CGameDialog::GetNetrun()
1466 {
1467   return m_bNetRun;
1468 }
1469 #endif
1470
1471 /*
1472 ========
1473
1474 very first prefs init deals with selecting the game and the game tools path
1475 then we can load .ini stuff
1476
1477 using prefs / ini settings:
1478 those are per-game
1479
1480 win32:
1481 look in g_strGameToolsPath for .ini
1482
1483 linux:
1484 look in ~/.radiant/<version>/gamename
1485 ========
1486 */
1487
1488 #define PREFS_LOCAL_FILENAME "local.pref"
1489
1490 void PrefsDlg::Init()
1491 {
1492   mGamesDialog.Init();
1493
1494   // m_global_rc_path has been set above, do m_rc_path with game specific stuff now
1495   // the win32 and linux versions have been unified for network mode
1496 #ifdef _WIN32
1497   if (!CGameDialog::GetNetrun())
1498   {
1499     // legacy prefs settings, this goes where the game pack is installed
1500     m_rc_path = g_string_new (g_strGameToolsPath.GetBuffer() );
1501     m_inipath = g_string_new (m_rc_path->str);
1502     g_string_append (m_inipath, PREFS_LOCAL_FILENAME);
1503     return;
1504   }
1505 #endif
1506   // this is common to win32 and Linux init now
1507   m_rc_path = g_string_new (m_global_rc_path->str);
1508
1509   // game sub-dir
1510   g_string_append (m_rc_path, g_pGameDescription->mGameFile.GetBuffer());
1511   g_string_append (m_rc_path, "/");
1512   Q_mkdir (m_rc_path->str, 0775);
1513
1514   // then the ini file
1515   m_inipath = g_string_new (m_rc_path->str);
1516   g_string_append (m_inipath, PREFS_LOCAL_FILENAME);
1517
1518 }
1519
1520 void PrefsDlg::UpdateData (bool retrieve)
1521 {
1522   // leo: the "changed" signal confuses the update function
1523   if (m_pWidget == NULL)
1524     return;
1525   mGamesDialog.UpdateData (retrieve);
1526   Dialog::UpdateData (retrieve);
1527 }
1528
1529 #ifdef _WIN32
1530 #define PREFSHSPACE 5
1531 #else
1532 #define PREFSHSPACE 0
1533 #endif
1534
1535 static void UpdateSensitivity( GtkWidget *widget, gpointer data )
1536 {
1537   PrefsDlg *dlg = (PrefsDlg*)data;
1538   dlg->DoSensitivity();
1539 }
1540
1541 static void UpdateEditorSensitivity(GtkWidget *widget, gpointer data)
1542 {
1543   PrefsDlg *dlg = (PrefsDlg*)data;
1544   dlg->DoEditorSensitivity();
1545 }
1546
1547 // start new prefs dialog
1548
1549 /*! Utility function for swapping notebook pages for tree list selections */
1550 void PrefsDlg::showPrefPage(int prefpage)
1551 {
1552   if(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)) != prefpage)
1553     gtk_notebook_set_page(GTK_NOTEBOOK(notebook), prefpage);
1554
1555   return;
1556 }
1557
1558 static void treeSelection(GtkTreeSelection* selection, gpointer data)
1559 {
1560   PrefsDlg *dlg = (PrefsDlg*)data;
1561
1562   GtkTreeModel* model;
1563   GtkTreeIter selected;
1564   if(gtk_tree_selection_get_selected(selection, &model, &selected))
1565   {
1566     int prefpage;
1567     gtk_tree_model_get(model, &selected, 1, (gpointer*)&prefpage, -1);
1568     dlg->showPrefPage(prefpage);
1569   }
1570 }
1571
1572 void PrefsDlg::BuildDialog ()
1573 {
1574   // Main Preferences dialog
1575   GtkWidget *dialog, *mainvbox, *hbox, *sc_win, *preflabel;
1576
1577   // Widgets on notebook pages
1578   GtkWidget *check, *label, *scale, *hbox2, *combo,
1579             *table, *spin,  *entry, *pixmap,
1580             *radio, *button, *pageframe, *vbox;
1581
1582   GList *combo_list = (GList*)NULL;
1583
1584   GtkObject *adj;
1585
1586   dialog = m_pWidget;
1587   gtk_window_set_title(GTK_WINDOW(dialog), _("GtkRadiant Preferences"));
1588   gtk_widget_realize(dialog);
1589
1590   mainvbox = gtk_vbox_new(FALSE, 5);
1591   gtk_container_add(GTK_CONTAINER(dialog), mainvbox);
1592   gtk_container_set_border_width(GTK_CONTAINER(mainvbox), 5);
1593   gtk_widget_show(mainvbox);
1594
1595   hbox = gtk_hbox_new(FALSE, 5);
1596   gtk_widget_show(hbox);
1597   gtk_box_pack_end(GTK_BOX(mainvbox), hbox, FALSE, TRUE, 0);
1598
1599   button = gtk_button_new_with_label(_("OK"));
1600   gtk_widget_show(button);
1601   gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1602   gtk_widget_set_usize(button, 60, -2);
1603   AddModalButton(button, IDOK);
1604
1605   button = gtk_button_new_with_label(_("Cancel"));
1606   gtk_widget_show(button);
1607   gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1608   gtk_widget_set_usize(button, 60, -2);
1609   AddModalButton(button, IDCANCEL);
1610
1611   button = gtk_button_new_with_label (_("Clean"));
1612   gtk_widget_show(button);
1613   gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(OnButtonClean), this);
1614   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1615   gtk_widget_set_usize (button, 60, -2);
1616
1617   hbox = gtk_hbox_new(FALSE, 5);
1618   gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 0);
1619   gtk_widget_show(hbox);
1620
1621   sc_win = gtk_scrolled_window_new(NULL, NULL);
1622   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sc_win), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1623   gtk_box_pack_start(GTK_BOX(hbox), sc_win, FALSE, FALSE, 0);
1624   gtk_widget_show(sc_win);
1625
1626   // prefs pages notebook
1627   notebook = gtk_notebook_new();
1628   // hide the notebook tabs since its not supposed to look like a notebook
1629   gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
1630   gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 0);
1631   gtk_widget_show(notebook);
1632
1633   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sc_win), GTK_SHADOW_IN);
1634
1635   {
1636     GtkTreeStore* store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
1637
1638     GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1639     gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
1640
1641     {
1642       GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1643       GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(_("Preferences"), renderer, "text", 0, NULL);
1644       gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1645     }
1646
1647     {
1648       GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1649       g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(treeSelection), this);
1650     }
1651
1652     gtk_widget_show(view);
1653
1654     gtk_container_add(GTK_CONTAINER (sc_win), view);
1655
1656     {
1657       /********************************************************************/
1658       /* Add preference tree options                                      */
1659       /********************************************************************/
1660       {
1661         GtkTreeIter group;
1662         gtk_tree_store_append(store, &group, NULL);
1663         gtk_tree_store_set(store, &group, 0, _("Globals"), 1, PTAB_FRONT, -1);
1664         {
1665           GtkTreeIter tab;
1666           gtk_tree_store_append(store, &tab, &group);
1667           gtk_tree_store_set(store, &tab, 0, _("Game settings"), 1, (gpointer)PTAB_GAME_SETTINGS, -1);
1668         }
1669       }
1670
1671       {
1672         GtkTreeIter group;
1673         gtk_tree_store_append(store, &group, NULL);
1674         gtk_tree_store_set(store, &group, 0, _("Display"), 1, PTAB_FRONT, -1);
1675         {
1676           GtkTreeIter tab;
1677           gtk_tree_store_append(store, &tab, &group);
1678           gtk_tree_store_set(store, &tab, 0, _("2D Display/Rendering"), 1, (gpointer)PTAB_2D, -1);
1679         }
1680         {
1681           GtkTreeIter tab;
1682           gtk_tree_store_append(store, &tab, &group);
1683           gtk_tree_store_set(store, &tab, 0, _("3D View"), 1, (gpointer)PTAB_CAMERA, -1);
1684         }
1685         {
1686           GtkTreeIter tab;
1687           gtk_tree_store_append(store, &tab, &group);
1688           gtk_tree_store_set(store, &tab, 0, _("Texture Settings"), 1, (gpointer)PTAB_TEXTURE, -1);
1689         }
1690       }
1691
1692       {
1693         GtkTreeIter group;
1694         gtk_tree_store_append(store, &group, NULL);
1695         gtk_tree_store_set(store, &group, 0, _("Interface"), 1, PTAB_FRONT, -1);
1696         {
1697           GtkTreeIter tab;
1698           gtk_tree_store_append(store, &tab, &group);
1699           gtk_tree_store_set(store, &tab, 0, _("Layout"), 1, (gpointer)PTAB_LAYOUT, -1);
1700         }
1701         {
1702           GtkTreeIter tab;
1703           gtk_tree_store_append(store, &tab, &group);
1704           gtk_tree_store_set(store, &tab, 0, _("Mouse"), 1, (gpointer)PTAB_MOUSE, -1);
1705         }
1706         {
1707           GtkTreeIter tab;
1708           gtk_tree_store_append(store, &tab, &group);
1709           gtk_tree_store_set(store, &tab, 0, _("Editing"), 1, (gpointer)PTAB_EDITING, -1);
1710         }
1711       }
1712
1713       {
1714         GtkTreeIter group;
1715         gtk_tree_store_append(store, &group, NULL);
1716         gtk_tree_store_set(store, &group, 0, _("Other"), 1, PTAB_FRONT, -1);
1717         {
1718           GtkTreeIter tab;
1719           gtk_tree_store_append(store, &tab, &group);
1720           gtk_tree_store_set(store, &tab, 0, _("Startup/Auto save"), 1, (gpointer)PTAB_STARTUP, -1);
1721         }
1722         {
1723           GtkTreeIter tab;
1724           gtk_tree_store_append(store, &tab, &group);
1725           gtk_tree_store_set(store, &tab, 0, _("Paths"), 1, (gpointer)PTAB_PATHS, -1);
1726         }
1727         {
1728           GtkTreeIter tab;
1729           gtk_tree_store_append(store, &tab, &group);
1730           gtk_tree_store_set(store, &tab, 0, _("Misc"), 1, (gpointer)PTAB_MISC, -1);
1731         }
1732         if (!g_qeglobals.bBSPFrontendPlugin)
1733         {
1734           GtkTreeIter tab;
1735           gtk_tree_store_append(store, &tab, &group);
1736           gtk_tree_store_set(store, &tab, 0, _("BSP Monitoring"), 1, (gpointer)PTAB_BSPMONITOR, -1);
1737         }
1738       }
1739     }
1740
1741     gtk_tree_view_expand_all(GTK_TREE_VIEW(view));
1742
1743     g_object_unref(G_OBJECT(store));
1744   }
1745
1746   /**********************************************************************/
1747   /* build the prefs pages                                              */
1748   /**********************************************************************/
1749
1750   // Front page...
1751   // todo : add something interesting here
1752   // NOTE TTimo: tip of the day? or a logo?
1753   preflabel = gtk_label_new(_("Front Page"));
1754   gtk_widget_show(preflabel);
1755   pageframe = gtk_frame_new(NULL);
1756   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1757   gtk_widget_show(pageframe);
1758   vbox = gtk_vbox_new(FALSE, 5);
1759   gtk_widget_show(vbox);
1760   gtk_widget_set_usize(GTK_WIDGET(vbox), 350, -2);
1761   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1762   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1763
1764   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1765
1766   /******** global preferences group ****************************/
1767   preflabel = gtk_label_new(_("Globals"));
1768   gtk_widget_show(preflabel);
1769
1770   pageframe = mGamesDialog.GetGlobalFrame();
1771   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1772
1773   /******** 2D prefs group (xy views/rendering options) *********/
1774   preflabel = gtk_label_new(_("2D Display"));
1775   gtk_widget_show(preflabel);
1776   pageframe = gtk_frame_new(_("2D Display"));
1777   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1778   gtk_widget_show(pageframe);
1779   vbox = gtk_vbox_new(FALSE, 5);
1780   gtk_widget_show(vbox);
1781   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1782   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1783
1784   // OpenGL Display Lists
1785   check = gtk_check_button_new_with_label(_("OpenGL Display Lists"));
1786   gtk_widget_show(check);
1787   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1788   AddDialogData(check, &m_bDisplayLists, DLG_CHECK_BOOL);
1789
1790   // Antialiased points & lines
1791   // Fishman - Add antialiazed points and lines support. 09/03/00
1792   check = gtk_check_button_new_with_label (_("OpenGL antialiased points and lines"));
1793   gtk_widget_show (check);
1794   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1795   AddDialogData (check, &m_bAntialiasedPointsAndLines, DLG_CHECK_BOOL);
1796
1797   // Solid selection boxes
1798   check = gtk_check_button_new_with_label (_("Solid selection boxes"));
1799   gtk_widget_show (check);
1800   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1801   AddDialogData (check, &m_bNoStipple, DLG_CHECK_BOOL);
1802
1803   // Display size info
1804   check = gtk_check_button_new_with_label (_("Display size info"));
1805   gtk_widget_show (check);
1806   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1807   AddDialogData (check, &m_bSizePaint, DLG_CHECK_BOOL);
1808
1809   // Alternate vertex/edge handles
1810   // Gef: Kyro GL_POINT work around 25-aug-2001
1811   check = gtk_check_button_new_with_label (_("Alternate vertex/edge handles"));
1812   gtk_widget_show(check);
1813   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1814   AddDialogData(check, &m_bGlPtWorkaround, DLG_CHECK_BOOL);
1815
1816   g_list_free (combo_list);
1817
1818 #ifdef ATIHACK_812
1819         // ATI bugs
1820         check = gtk_check_button_new_with_label (_("ATI cards with broken drivers - bug #802"));
1821         gtk_widget_show(check);
1822         gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1823         AddDialogData(check, &m_bGlATIHack, DLG_CHECK_BOOL);
1824 #endif
1825
1826   // Add the page to the notebook
1827   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1828
1829   /******** 3D Camera view group *********/
1830   preflabel = gtk_label_new(_("3D View"));
1831   gtk_widget_show(preflabel);
1832   pageframe = gtk_frame_new(_("3D View"));
1833   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1834   gtk_widget_show(pageframe);
1835   vbox = gtk_vbox_new(FALSE, 5);
1836   gtk_widget_show(vbox);
1837   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1838   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1839
1840   // Directional velocity (Movement Velocity)
1841   // label container
1842   hbox2 = gtk_hbox_new (FALSE, 0);
1843   gtk_widget_show (hbox2);
1844   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
1845
1846   // label
1847   label = gtk_label_new(_("Movement Velocity"));
1848   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1849   gtk_widget_show(label);
1850   gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1851
1852   // adjustment
1853   adj = gtk_adjustment_new(100, 50, 300, 1, 10, 10);
1854   AddDialogData(adj, &m_nMoveSpeed, DLG_ADJ_INT);
1855
1856   // scale
1857   scale = gtk_hscale_new(GTK_ADJUSTMENT(adj));
1858   gtk_widget_show(scale);
1859   gtk_box_pack_start(GTK_BOX (vbox), scale, FALSE, TRUE, 2);
1860
1861   gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
1862
1863   // Angular velocity (Rotational Velocity)
1864   // label container
1865   hbox2 = gtk_hbox_new (FALSE, 0);
1866   gtk_widget_show (hbox2);
1867   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
1868
1869   // label
1870   label = gtk_label_new (_("Rotational Velocity"));
1871   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1872   gtk_widget_show (label);
1873   gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1874
1875   // adjustment
1876   adj = gtk_adjustment_new (3, 1, 180, 1, 10, 10); // value, low, high, step, page_step, page_size
1877   AddDialogData (adj, &m_nAngleSpeed, DLG_ADJ_INT);
1878
1879   // scale
1880   scale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
1881   gtk_widget_show (scale);
1882   gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, TRUE, 2);
1883   gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
1884
1885   // Text under the velocity sliders
1886   // container
1887   hbox2 = gtk_hbox_new (FALSE, 0);
1888   gtk_widget_show (hbox2);
1889   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
1890
1891   // label
1892   label = gtk_label_new (_("slow"));
1893   gtk_widget_show (label);
1894   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
1895
1896   // label
1897   label = gtk_label_new (_("fast"));
1898   gtk_widget_show (label);
1899   gtk_box_pack_end (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
1900
1901   // Allow drag to select multiple faces/brushes
1902   // container
1903   table = gtk_table_new(2, 1, FALSE);
1904   gtk_widget_show(table);
1905   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
1906   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
1907   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
1908
1909   label = gtk_label_new (_("Use paint-select in camera view:"));
1910   gtk_widget_show (label);
1911   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1912   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
1913                   (GtkAttachOptions) (0),
1914                   (GtkAttachOptions) (0), 0, 0);
1915
1916   combo_list = NULL;
1917   combo_list = g_list_append (combo_list, (void *)_("No"));
1918   combo_list = g_list_append (combo_list, (void *)_("Yes"));
1919   combo_list = g_list_append (combo_list, (void *)_("Yes (Classic Key Setup)"));
1920
1921   combo = gtk_combo_new ();
1922   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
1923   gtk_widget_show (combo);
1924   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
1925                   (GtkAttachOptions) (GTK_FILL),
1926                   (GtkAttachOptions) (0), 0, 0);
1927   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
1928   AddDialogData (combo, &m_nCamDragMultiSelect, DLG_COMBO_INT);
1929
1930   // Freelook in Camera view
1931   check = gtk_check_button_new_with_label (_("Freelook in Camera view"));
1932   gtk_widget_show (check);
1933   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1934   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1935   AddDialogData (check, &m_bCamFreeLook, DLG_CHECK_BOOL);
1936
1937   // Freelook in Camera view w/ forward & back strafing instead of up and down looking
1938   check = gtk_check_button_new_with_label (_("Freelook strafes Forward and Back"));
1939   gtk_widget_show (check);
1940   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1941   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1942   AddDialogData (check, &m_bCamFreeLookStrafe, DLG_CHECK_BOOL);
1943
1944   // Invert mouse in freelook
1945   check = gtk_check_button_new_with_label (_("Invert mouse in freelook"));
1946   gtk_widget_show (check);
1947   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1948   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1949   AddDialogData (check, &m_bCamInverseMouse, DLG_CHECK_BOOL);
1950
1951   // Discrete movement
1952   check = gtk_check_button_new_with_label (_("Discrete movement"));
1953   gtk_widget_show (check);
1954   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1955   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1956   AddDialogData (check, &m_bCamDiscrete, DLG_CHECK_BOOL);
1957
1958   // Update XY views on camera move
1959   check = gtk_check_button_new_with_label (_("Update XY views on camera move"));
1960   gtk_widget_show (check);
1961   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1962   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1963   AddDialogData (check, &m_bCamXYUpdate, DLG_CHECK_BOOL);
1964
1965   // Add the page to the notebook
1966   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1967
1968   /******** Texture group *********/
1969   preflabel = gtk_label_new(_("Textures"));
1970   gtk_widget_show(preflabel);
1971   pageframe = gtk_frame_new(_("Textures"));
1972   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1973   gtk_widget_show(pageframe);
1974   vbox = gtk_vbox_new(FALSE, 6);
1975   gtk_widget_show(vbox);
1976   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1977   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1978
1979   // Texture quality slider
1980   // label
1981   label = gtk_label_new (_("Texture quality"));
1982   gtk_widget_show (label);
1983   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
1984   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1985   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1986
1987   // adjustment
1988   adj = gtk_adjustment_new (0, 0, 4, 1, 1, 1);
1989   AddDialogData (adj, &m_nLatchedTextureQuality, DLG_ADJ_INT);
1990
1991   // scale
1992   scale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
1993   gtk_widget_show (scale);
1994   gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
1995   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
1996
1997   // text under the texture slider
1998   hbox2 = gtk_hbox_new (FALSE, 0);
1999   gtk_widget_show (hbox2);
2000   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
2001   label = gtk_label_new (_("low"));
2002   gtk_widget_show (label);
2003   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2004   label = gtk_label_new (_("high"));
2005   gtk_widget_show (label);
2006   gtk_box_pack_end (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2007
2008   // texture subsets
2009   check = gtk_check_button_new_with_label (_("Texture subsets"));
2010   gtk_widget_show (check);
2011   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2012   AddDialogData (check, &m_bTextureWindow, DLG_CHECK_BOOL);
2013
2014   // texture scrollbar
2015   check = gtk_check_button_new_with_label (_("Texture scrollbar"));
2016   gtk_widget_show (check);
2017   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2018   AddDialogData (check, &m_bTextureScrollbar, DLG_CHECK_BOOL);
2019
2020   // texture increment matches grid
2021   check = gtk_check_button_new_with_label (_("Tex increment matches grid"));
2022   gtk_widget_show (check);
2023   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2024   AddDialogData (check, &m_bSnapTToGrid, DLG_CHECK_BOOL);
2025
2026   // RIANT
2027   // Texture compression choice label
2028   // container
2029   table = gtk_table_new(2, 1, FALSE);
2030   gtk_widget_show(table);
2031   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2032   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2033   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2034
2035   label = gtk_label_new (_("Texture Compression (if available):"));
2036   gtk_widget_show (label);
2037   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
2038   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2039                   (GtkAttachOptions) (0),
2040                   (GtkAttachOptions) (0), 0, 0);
2041   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
2042
2043   // Texture compression choice label
2044   combo_list = NULL;
2045   // NONE will always be in pos 0
2046   combo_list = g_list_append (combo_list, (void *)_("None"));
2047
2048   // if OpenGL compression is enabled it will always be
2049   // in pos 1
2050   if (g_qeglobals.m_bOpenGLCompressionSupported)
2051   {
2052     combo_list = g_list_append (combo_list, (void *)_("OpenGL ARB"));
2053   }
2054
2055   // If S3 is enabled offer all 3 valid compression schemes in RGBA
2056   if (g_qeglobals.m_bS3CompressionSupported)
2057   {
2058     combo_list = g_list_append (combo_list, (void *)_("S3TC DXT1"));
2059     combo_list = g_list_append (combo_list, (void *)_("S3TC DXT3"));
2060     combo_list = g_list_append (combo_list, (void *)_("S3TC DXT5"));
2061   }
2062
2063   combo = gtk_combo_new ();
2064   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
2065   gtk_widget_show (combo);
2066   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
2067                   (GtkAttachOptions) (GTK_FILL),
2068                   (GtkAttachOptions) (0), 0, 0);
2069   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
2070   AddDialogData (combo, &m_nTextureCompressionFormat, DLG_COMBO_INT);
2071   g_list_free (combo_list);
2072
2073   // container
2074   table = gtk_table_new(2, 1, FALSE);
2075   gtk_widget_show(table);
2076   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2077   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2078   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2079
2080   // Startup shaders
2081   // label
2082   label = gtk_label_new (_("Startup Shaders:"));
2083   gtk_widget_show (label);
2084   gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
2085   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2086                   (GtkAttachOptions) (0),
2087                   (GtkAttachOptions) (0), 0, 0);
2088   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
2089
2090   // combo list
2091   combo_list = NULL;
2092   combo_list = g_list_append (combo_list, (void *)_("None"));
2093   if (g_pGameDescription->mGameFile == "jk2.game" || g_pGameDescription->mGameFile == "ja.game")
2094     combo_list = g_list_append (combo_list, (void *)_("System"));
2095   else if (g_pGameDescription->mGameFile == "sof2.game")
2096     combo_list = g_list_append (combo_list, (void *)("Tools"));
2097   else
2098     combo_list = g_list_append (combo_list, (void *)_("Common"));
2099   combo_list = g_list_append (combo_list, (void *)_("All"));
2100   combo = gtk_combo_new ();
2101   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
2102   gtk_widget_show (combo);
2103   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
2104                   (GtkAttachOptions) (GTK_FILL),
2105                   (GtkAttachOptions) (0), 0, 0);
2106   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
2107   AddDialogData (combo, &m_nLatchedShader, DLG_COMBO_INT);
2108   g_list_free (combo_list);
2109
2110   // Add the page to the notebook
2111   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2112
2113   /******** Layout group *********/
2114   preflabel = gtk_label_new(_("Layout"));
2115   gtk_widget_show(preflabel);
2116   pageframe = gtk_frame_new(_("Layout"));
2117   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2118   gtk_widget_show(pageframe);
2119   vbox = gtk_vbox_new(FALSE, 5);
2120   gtk_widget_show(vbox);
2121   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2122   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2123
2124   // View types
2125   // table
2126   table = gtk_table_new (2, 4, FALSE);
2127   gtk_widget_show (table);
2128   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2129   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2130   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2131
2132   // view type 1
2133   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window1.bmp");
2134   gtk_widget_show (pixmap);
2135   gtk_table_attach (GTK_TABLE (table), pixmap, 0, 1, 0, 1,
2136                     (GtkAttachOptions) (0),
2137                     (GtkAttachOptions) (0), 0, 0);
2138
2139   // view type 2
2140   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window2.bmp");
2141   gtk_widget_show (pixmap);
2142   gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
2143                     (GtkAttachOptions) (0),
2144                     (GtkAttachOptions) (0), 0, 0);
2145
2146   // view type 3
2147   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window3.bmp");
2148   gtk_widget_show (pixmap);
2149   gtk_table_attach (GTK_TABLE (table), pixmap, 2, 3, 0, 1,
2150                     (GtkAttachOptions) (0),
2151                     (GtkAttachOptions) (0), 0, 0);
2152
2153   // view type 4
2154   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window4.bmp");
2155   gtk_widget_show (pixmap);
2156   gtk_table_attach (GTK_TABLE (table), pixmap, 3, 4, 0, 1,
2157                     (GtkAttachOptions) (0),
2158                     (GtkAttachOptions) (0), 0, 0);
2159
2160   // view type 1 selector
2161   radio = gtk_radio_button_new (NULL);
2162   gtk_widget_show (radio);
2163   gtk_table_attach (GTK_TABLE (table), radio, 0, 1, 1, 2,
2164                     (GtkAttachOptions) (0),
2165                     (GtkAttachOptions) (0), 0, 0);
2166
2167   // view type 2 selector
2168   radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio));
2169   gtk_widget_show (radio);
2170   gtk_table_attach (GTK_TABLE (table), radio, 1, 2, 1, 2,
2171                     (GtkAttachOptions) (0),
2172                     (GtkAttachOptions) (0), 0, 0);
2173
2174   // view type 3 selector
2175   radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio));
2176   gtk_widget_show (radio);
2177   gtk_table_attach (GTK_TABLE (table), radio, 2, 3, 1, 2,
2178                     (GtkAttachOptions) (0),
2179                     (GtkAttachOptions) (0), 0, 0);
2180
2181   // view type 4 selector
2182   radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio));
2183   gtk_widget_show (radio);
2184   gtk_table_attach (GTK_TABLE (table), radio, 3, 4, 1, 2,
2185                     (GtkAttachOptions) (0),
2186                     (GtkAttachOptions) (0), 0, 0);
2187   AddDialogData (radio, &m_nLatchedView, DLG_RADIO_INT);
2188
2189   // Floating Z window
2190   check = gtk_check_button_new_with_label (_("Floating Z Window"));
2191   gtk_widget_show (check);
2192   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2193   AddDialogData (check, &m_bLatchedFloatingZ, DLG_CHECK_BOOL);
2194
2195   // show menu tear-off seperators
2196   check = gtk_check_button_new_with_label (_("Detachable Menus"));
2197   gtk_widget_show (check);
2198   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2199   AddDialogData (check, &m_bLatchedDetachableMenus, DLG_CHECK_BOOL);
2200
2201   if (!g_pGameDescription->mNoPatch)
2202   {
2203     // show patch toolbar
2204     check = gtk_check_button_new_with_label (_("Patch Toolbar"));
2205     gtk_widget_show (check);
2206     gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2207     g_object_set_data (G_OBJECT (dialog), "check_patchtoolbar", check); // Allow to be disabled for Q1/Q2
2208     AddDialogData (check, &m_bLatchedPatchToolbar, DLG_CHECK_BOOL);
2209   }
2210
2211   // use wide toolbar
2212   check = gtk_check_button_new_with_label (_("Wide Toolbar"));
2213   gtk_widget_show (check);
2214   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2215   AddDialogData (check, &m_bLatchedWideToolbar, DLG_CHECK_BOOL);
2216
2217   // use plugin toolbar
2218   check = gtk_check_button_new_with_label (_("Plugin Toolbar"));
2219   gtk_widget_show (check);
2220   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2221   AddDialogData (check, &m_bLatchedPluginToolbar, DLG_CHECK_BOOL);
2222
2223 #ifdef _WIN32
2224   // win32 file dialog
2225   check = gtk_check_button_new_with_label (_("Use win32 file load dialog"));
2226   gtk_widget_show (check);
2227   // gtk_container_add (GTK_CONTAINER (vbox), check);
2228   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2229   AddDialogData (check, &m_bNativeGUI, DLG_CHECK_BOOL);
2230
2231   // position on primary monitor
2232   check = gtk_check_button_new_with_label (_("Start on Primary Monitor"));
2233   gtk_widget_show (check);
2234   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2235   g_object_set_data (G_OBJECT (dialog), "check_startonprimary", check);
2236   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateSensitivity), this );
2237   AddDialogData (check, &m_bStartOnPrimMon, DLG_CHECK_BOOL);
2238 #endif
2239
2240   // Add the page to the notebook
2241   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2242
2243   /******** Mouse group *********/
2244   preflabel = gtk_label_new(_("Mouse"));
2245   gtk_widget_show(preflabel);
2246   pageframe = gtk_frame_new(_("Mouse"));
2247   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2248   gtk_widget_show(pageframe);
2249   vbox = gtk_vbox_new(FALSE, 5);
2250   gtk_widget_show(vbox);
2251   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2252   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2253
2254   // Buttons
2255   // container
2256   hbox2 = gtk_hbox_new (FALSE, 5);
2257   gtk_widget_show (hbox2);
2258   gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
2259
2260   // 2 button radio
2261   radio = gtk_radio_button_new_with_label (NULL, _("2 button"));
2262   gtk_widget_show (radio);
2263   gtk_box_pack_start (GTK_BOX (hbox2), radio, FALSE, FALSE, 0);
2264
2265   // 3 button radio
2266   radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("3 button"));
2267   gtk_widget_show (radio);
2268   gtk_box_pack_start (GTK_BOX (hbox2), radio, FALSE, FALSE, 0);
2269   AddDialogData (radio, &m_nMouse, DLG_RADIO_INT);
2270
2271   // right click to drop entity
2272   check = gtk_check_button_new_with_label (_("Right click to drop entities"));
2273   gtk_widget_show (check);
2274   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2275   AddDialogData (check, &m_bRightClick, DLG_CHECK_BOOL);
2276
2277   // Mouse chaser (and this does what?)
2278   check = gtk_check_button_new_with_label (_("Mouse chaser"));
2279   gtk_widget_show (check);
2280   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2281   AddDialogData (check, &m_bChaseMouse, DLG_CHECK_BOOL);
2282
2283   // Alt + multi-drag
2284   check = gtk_check_button_new_with_label (_("ALT + multi-drag"));
2285   gtk_widget_show (check);
2286   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2287   AddDialogData (check, &m_bALTEdge, DLG_CHECK_BOOL);
2288
2289   // Mouse wheel increments
2290   // container
2291   hbox2 = gtk_hbox_new (FALSE, 5);
2292   gtk_widget_show (hbox2);
2293   gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
2294
2295   // label
2296   label = gtk_label_new (_("Wheel Mouse inc:"));
2297   gtk_widget_show (label);
2298   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2299
2300   // entry
2301   entry = gtk_entry_new ();
2302   gtk_widget_show (entry);
2303   gtk_widget_set_usize (entry, 40, -2);
2304   gtk_box_pack_start (GTK_BOX (hbox2), entry, FALSE, FALSE, 0);
2305   AddDialogData (entry, &m_nWheelInc, DLG_ENTRY_INT);
2306
2307   // Add the page to the notebook
2308   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2309
2310   /******** Editing group *********/
2311   preflabel = gtk_label_new(_("Editing"));
2312   gtk_widget_show(preflabel);
2313   pageframe = gtk_frame_new(_("Editing"));
2314   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2315   gtk_widget_show(pageframe);
2316   vbox = gtk_vbox_new(FALSE, 5);
2317   gtk_widget_show(vbox);
2318   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2319   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2320
2321   // Vertex editing splits faces
2322   check = gtk_check_button_new_with_label (_("Vertex editing splits face"));
2323   gtk_widget_show (check);
2324   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2325   AddDialogData (check, &m_bVertexSplit, DLG_CHECK_BOOL);
2326
2327   // Fix target/targetname collisions
2328   check = gtk_check_button_new_with_label (_("Fix target/targetname collisions"));
2329   gtk_widget_show (check);
2330   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2331   AddDialogData (check, &m_bDoTargetFix, DLG_CHECK_BOOL);
2332
2333   // Clipper tool uses caulk
2334   check = gtk_check_button_new_with_label (_("Clipper tool uses caulk"));
2335   gtk_widget_show (check);
2336   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2337   AddDialogData (check, &m_bClipCaulk, DLG_CHECK_BOOL);
2338
2339   // Don't clamp plane points
2340   check = gtk_check_button_new_with_label (_("Don't clamp plane points"));
2341   gtk_widget_show (check);
2342   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2343   AddDialogData (check, &m_bNoClamp, DLG_CHECK_BOOL);
2344
2345   // Select patch by bounding box
2346   check = gtk_check_button_new_with_label (_("Select patches by bounding box"));
2347   gtk_widget_show (check);
2348   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2349   AddDialogData (check, &m_bPatchBBoxSelect, DLG_CHECK_BOOL);
2350
2351   // Rotation increment
2352   // container
2353   table = gtk_table_new (2, 3, FALSE);
2354   gtk_widget_show (table);
2355   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2356   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2357   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2358
2359   // label
2360   label = gtk_label_new (_("Rotation increment:"));
2361   gtk_widget_show (label);
2362   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
2363                    (GtkAttachOptions) (0),
2364                    (GtkAttachOptions) (0), 0, 0);
2365
2366   // entry
2367   entry = gtk_entry_new ();
2368   gtk_widget_show (entry);
2369   gtk_widget_set_usize (entry, 60, -2);
2370   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
2371                    (GtkAttachOptions) (GTK_FILL),
2372                    (GtkAttachOptions) (0), 0, 0);
2373   AddDialogData (entry, &m_nRotation, DLG_ENTRY_INT);
2374
2375   // Undo levels
2376   // label
2377   label = gtk_label_new (_("Undo Levels:"));
2378   gtk_widget_show (label);
2379   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
2380                    (GtkAttachOptions) (0),
2381                    (GtkAttachOptions) (0), 0, 0);
2382
2383   // spinner (allows undo levels to be set to zero)
2384   spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1, 0, 64, 1, 10, 10)), 1, 0);
2385   gtk_widget_show (spin);
2386   gtk_table_attach (GTK_TABLE (table), spin, 1, 2, 1, 2,
2387                    (GtkAttachOptions) (GTK_FILL),
2388                    (GtkAttachOptions) (0), 0, 0);
2389   gtk_widget_set_usize (spin, 60, -2);
2390   AddDialogData (spin, &m_nUndoLevels, DLG_SPIN_INT);
2391
2392   // Patch subdivisions
2393   // label
2394   label = gtk_label_new (_("Patch subdivisions:"));
2395   gtk_widget_show (label);
2396   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
2397                    (GtkAttachOptions) (0),
2398                    (GtkAttachOptions) (0), 0, 0);
2399
2400   // entry (spinner perhaps? [2-16])
2401   entry = gtk_entry_new ();
2402   gtk_widget_show (entry);
2403   gtk_widget_set_usize (entry, 60, -2);
2404   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 2, 3,
2405                    (GtkAttachOptions) (GTK_FILL),
2406                    (GtkAttachOptions) (0), 0, 0);
2407   AddDialogData (entry, &m_nSubdivisions, DLG_ENTRY_INT);
2408
2409   // Add the page to the notebook
2410   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2411
2412   /******** Save/Load group *********/
2413   preflabel = gtk_label_new(_("Startup/Auto save"));
2414   gtk_widget_show(preflabel);
2415   pageframe = gtk_frame_new(_("Startup/Auto save"));
2416   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2417   gtk_widget_show(pageframe);
2418   vbox = gtk_vbox_new(FALSE, 5);
2419   gtk_widget_show(vbox);
2420   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2421   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2422
2423   // Snapshots
2424   check = gtk_check_button_new_with_label (_("Snapshots"));
2425   gtk_widget_show (check);
2426   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2427   AddDialogData (check, &m_bSnapShots, DLG_CHECK_BOOL);
2428
2429   // load last project on open
2430   check = gtk_check_button_new_with_label (_("Load last project on open"));
2431   gtk_widget_show (check);
2432   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2433   AddDialogData (check, &m_bLoadLast, DLG_CHECK_BOOL);
2434
2435   // load last map on open
2436   check = gtk_check_button_new_with_label (_("Load last map on open"));
2437   gtk_widget_show (check);
2438   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2439   AddDialogData (check, &m_bLoadLastMap, DLG_CHECK_BOOL);
2440
2441   // Auto save..
2442   // container
2443   hbox2 = gtk_hbox_new (FALSE, 5);
2444   gtk_widget_show (hbox2);
2445   gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
2446   gtk_container_set_border_width (GTK_CONTAINER (hbox2), 0);
2447
2448   // label
2449   check = gtk_check_button_new_with_label (_("Auto save every"));
2450   gtk_widget_show (check);
2451   gtk_box_pack_start (GTK_BOX (hbox2), check, FALSE, FALSE, 0);
2452   AddDialogData (check, &m_bAutoSave, DLG_CHECK_BOOL);
2453
2454   // spinner
2455   spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1, 1, 60, 1, 10, 10)), 1, 0);
2456   gtk_widget_show (spin);
2457   gtk_box_pack_start (GTK_BOX (hbox2), spin, FALSE, FALSE, 0);
2458   gtk_widget_set_usize (spin, 60, -2);
2459   AddDialogData (spin, &m_nAutoSave, DLG_SPIN_INT);
2460
2461   // label
2462   label = gtk_label_new (_("minutes"));
2463   gtk_widget_show (label);
2464   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2465
2466   // Add the page to the notebook
2467   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2468
2469   /******** Paths group *********/
2470   preflabel = gtk_label_new(_("Paths"));
2471   gtk_widget_show(preflabel);
2472   pageframe = gtk_frame_new(_("Paths"));
2473   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2474   gtk_widget_show(pageframe);
2475   vbox = gtk_vbox_new(FALSE, 5);
2476   gtk_widget_show(vbox);
2477   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2478   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2479
2480   // prefab path
2481   // table
2482   table = gtk_table_new (3, 3, FALSE);
2483   gtk_widget_show (table);
2484   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2485   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2486   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2487
2488   // label
2489   label = gtk_label_new (_("Prefab path:"));
2490   gtk_widget_show (label);
2491   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
2492                    (GtkAttachOptions) (0),
2493                    (GtkAttachOptions) (0), 0, 0);
2494   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
2495
2496   // path entry
2497   entry = gtk_entry_new ();
2498   gtk_widget_show (entry);
2499   gtk_widget_set_usize(GTK_WIDGET(entry), 240, -2);
2500   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
2501                    (GtkAttachOptions) (GTK_FILL),
2502                    (GtkAttachOptions) (0), 1, 0);
2503   AddDialogData (entry, &m_strPrefabPath, DLG_ENTRY_TEXT);
2504
2505 #if 0
2506   // browse button
2507   button = gtk_button_new_with_label ("...");
2508   gtk_widget_show (button);
2509   gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (OnBtnBrowseprefab), this);
2510   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
2511                    (GtkAttachOptions) (0),
2512                    (GtkAttachOptions) (0), 0, 0);
2513 #endif
2514
2515   // User ini path
2516   // label
2517   label = gtk_label_new (_("User INI path:"));
2518   gtk_widget_show (label);
2519   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
2520                    (GtkAttachOptions) (0),
2521                    (GtkAttachOptions) (0), 0, 0);
2522   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
2523
2524   // user ini path entry
2525   entry = gtk_entry_new ();
2526   gtk_widget_show (entry);
2527   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2,
2528                    (GtkAttachOptions) (GTK_FILL),
2529                    (GtkAttachOptions) (0), 1, 0);
2530   AddDialogData (entry, &m_strUserPath, DLG_ENTRY_TEXT);
2531
2532   // user ini browse button
2533   button = gtk_button_new_with_label ("...");
2534   gtk_widget_show (button);
2535   gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (OnBtnBrowseuserini), this);
2536   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
2537                    (GtkAttachOptions) (0),
2538                    (GtkAttachOptions) (0), 0, 0);
2539
2540   // Add the page to the notebook
2541   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2542
2543   /******** Misc group *********/
2544   preflabel = gtk_label_new(_("Misc"));
2545   gtk_widget_show(preflabel);
2546   pageframe = gtk_frame_new(_("Misc"));
2547   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2548   gtk_widget_show(pageframe);
2549   vbox = gtk_vbox_new(FALSE, 5);
2550   gtk_widget_show(vbox);
2551   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2552   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2553
2554   // Light drawing
2555   check = gtk_check_button_new_with_label (_("Light drawing"));
2556   gtk_widget_show (check);
2557   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2558   AddDialogData (check, &m_bNewLightDraw, DLG_CHECK_BOOL);
2559
2560   // Light radiuses
2561   // container
2562   table = gtk_table_new(2, 1, FALSE);
2563   gtk_widget_show(table);
2564   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2565   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2566   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2567
2568   label = gtk_label_new (_("Light radiuses:"));
2569   gtk_widget_show (label);
2570   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
2571   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2572                   (GtkAttachOptions) (0),
2573                   (GtkAttachOptions) (0), 0, 0);
2574
2575   combo_list = NULL;
2576   combo_list = g_list_append (combo_list, (void *)_("Disabled"));
2577   combo_list = g_list_append (combo_list, (void *)_("True Q3Map2 Style"));
2578   combo_list = g_list_append (combo_list, (void *)_("Classic Style"));
2579
2580   combo = gtk_combo_new ();
2581   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
2582   gtk_widget_show (combo);
2583   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
2584                   (GtkAttachOptions) (GTK_FILL),
2585                   (GtkAttachOptions) (0), 0, 0);
2586   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
2587   AddDialogData (combo, &m_nLightRadiuses, DLG_COMBO_INT);
2588
2589 #ifdef _WIN32
2590   check = gtk_check_button_new_with_label (_("Use win32 file associations to open text files instead of builtin editor"));
2591   gtk_widget_show(check);
2592   gtk_box_pack_start(GTK_BOX (vbox), check, FALSE, FALSE, 0);
2593   AddDialogData (check, &g_PrefsDlg.m_bUseWin32Editor, DLG_CHECK_BOOL);
2594 #else
2595   // use custom shader editor
2596   check = gtk_check_button_new_with_label (_("Use Custom Shader Editor"));
2597   gtk_widget_show(check);
2598   gtk_box_pack_start(GTK_BOX (vbox), check, FALSE, FALSE, 0);
2599   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateEditorSensitivity), this);
2600   g_object_set_data (G_OBJECT(dialog), "check_customeditor", check);
2601   AddDialogData (check, &g_PrefsDlg.m_bUseCustomEditor, DLG_CHECK_BOOL);
2602
2603   // custom shader editor executable
2604   // table
2605   table = gtk_table_new (3, 1, FALSE);
2606   gtk_widget_show (table);
2607   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2608   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2609   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2610
2611   // label
2612   label = gtk_label_new(_("Custom Editor Command"));
2613   gtk_widget_show(label);
2614   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
2615                    (GtkAttachOptions) (0),
2616                    (GtkAttachOptions) (0), 0, 0);
2617   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
2618   g_object_set_data (G_OBJECT(dialog), "label_customeditor", label);
2619   gtk_widget_set_sensitive (label, g_PrefsDlg.m_bUseCustomEditor);
2620
2621   // custom editor command entry
2622   entry = gtk_entry_new ();
2623   gtk_widget_show (entry);
2624   gtk_widget_set_usize(GTK_WIDGET(entry), 240, -2);
2625   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
2626                    (GtkAttachOptions) (GTK_FILL),
2627                    (GtkAttachOptions) (0), 1, 0);
2628   AddDialogData (entry, &m_strEditorCommand, DLG_ENTRY_TEXT);
2629   gtk_widget_set_sensitive (entry, g_PrefsDlg.m_bUseCustomEditor);
2630   g_object_set_data (G_OBJECT(dialog), "entry_customeditor", entry);
2631
2632   // browse button
2633   button = gtk_button_new_with_label (_("..."));
2634   gtk_widget_show (button);
2635   gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (OnBtnBrowseEditor), this);
2636   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
2637                    (GtkAttachOptions) (0),
2638                    (GtkAttachOptions) (0), 0, 0);
2639   g_object_set_data (G_OBJECT(dialog), "button_customeditor", button);
2640   gtk_widget_set_sensitive (button, g_PrefsDlg.m_bUseCustomEditor);
2641 #endif
2642
2643   // Add the page to the notebook
2644   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2645
2646   /******** BSP Monitoring group *********/
2647   // this is never displayed if the plugin isn't available
2648   preflabel = gtk_label_new(_("BSP Monitoring"));
2649   gtk_widget_show(preflabel);
2650   pageframe = gtk_frame_new(_("BSP Monitoring"));
2651   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2652   gtk_widget_show(pageframe);
2653   vbox = gtk_vbox_new(FALSE, 5);
2654   gtk_widget_show(vbox);
2655   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2656   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2657
2658   // Enable BSP process monitoring
2659   check = gtk_check_button_new_with_label (_("Enable BSP process monitoring"));
2660   gtk_widget_show (check);
2661   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2662   g_object_set_data (G_OBJECT (dialog), "check_monitorbsp", check);
2663   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateSensitivity), this );
2664   AddDialogData (check, &g_PrefsDlg.m_bWatchBSP, DLG_CHECK_BOOL);
2665
2666   // Stop on leak
2667   check = gtk_check_button_new_with_label (_("Stop compilation on leak"));
2668   gtk_widget_show (check);
2669   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2670   g_object_set_data (G_OBJECT (dialog), "check_leakstop", check);
2671   AddDialogData (check, &g_PrefsDlg.m_bLeakStop, DLG_CHECK_BOOL);
2672
2673   // engine after compile
2674   check = gtk_check_button_new_with_label (_("Run engine after compile"));
2675   gtk_widget_show (check);
2676   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2677   g_object_set_data (G_OBJECT (dialog), "check_runengine", check);
2678   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateSensitivity), this );
2679   AddDialogData( check, &g_PrefsDlg.m_bRunQuake, DLG_CHECK_BOOL );
2680
2681   // sleep mode when running engine
2682   check = gtk_check_button_new_with_label (_("Activate sleep mode when running the engine"));
2683   gtk_widget_show (check);
2684   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2685   g_object_set_data (G_OBJECT (dialog), "check_sleep", check);
2686   AddDialogData( check, &g_PrefsDlg.m_bDoSleep, DLG_CHECK_BOOL );
2687
2688   // use q3map2's texture projection
2689   check = gtk_check_button_new_with_label (_("Texturing compatible with q3map2"));
2690   gtk_widget_show (check);
2691   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2692   g_object_set_data (G_OBJECT (dialog), "check_q3map2", check);
2693   AddDialogData( check, &g_PrefsDlg.m_bQ3Map2Texturing, DLG_CHECK_BOOL );
2694
2695   // Add the page to the notebook
2696   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2697
2698   gtk_notebook_set_page(GTK_NOTEBOOK(notebook), PTAB_FRONT);
2699
2700   return;
2701 }
2702
2703 // end new prefs dialog
2704
2705 void PrefsDlg::LoadTexdefPref(texdef_t* pTexdef, char* pName)
2706 {
2707   char buffer[256];
2708
2709   memset(pTexdef, 0, sizeof(texdef_t));
2710
2711   sprintf(buffer, "%s%s", pName, TD_SCALE1_KEY);
2712   mLocalPrefs.GetPref(buffer, &pTexdef->scale[0],   0.5f);
2713
2714   sprintf(buffer, "%s%s", pName, TD_SCALE2_KEY);
2715   mLocalPrefs.GetPref(buffer, &pTexdef->scale[1],   0.5f);
2716
2717   sprintf(buffer, "%s%s", pName, TD_SHIFT1_KEY);
2718   mLocalPrefs.GetPref(buffer, &pTexdef->shift[0],   8.f);
2719
2720   sprintf(buffer, "%s%s", pName, TD_SHIFT2_KEY);
2721   mLocalPrefs.GetPref(buffer, &pTexdef->shift[1],   8.f);
2722
2723   sprintf(buffer, "%s%s", pName, TD_ROTATE_KEY);
2724   mLocalPrefs.GetPref(buffer, &pTexdef->rotate,     45);
2725 }
2726
2727 void PrefsDlg::UpdateTextureCompression()
2728 {
2729   // if OpenGL is not ready yet, don't do anything
2730   if (!g_qeglobals.m_bOpenGLReady) {
2731     Sys_Printf("OpenGL not ready - postpone texture compression capability check\n");
2732     return;
2733   }
2734
2735   if (g_qeglobals.bTextureCompressionSupported)
2736   {
2737     if (m_nTextureCompressionFormat >= 2 && !g_qeglobals.m_bS3CompressionSupported)
2738     {
2739       Sys_Printf("Inconsistant pref setting for texture compression (%d), rolling back\n", m_nTextureCompressionFormat);
2740       m_nTextureCompressionFormat = 1; // if this is not supported either, see below
2741     }
2742     if (m_nTextureCompressionFormat == 1 && !g_qeglobals.m_bOpenGLCompressionSupported)
2743     {
2744       Sys_Printf("Inconsistant pref setting for texture compression (GL_COMPRESSED_RGBA), rolling back\n");
2745       m_nTextureCompressionFormat = 0;
2746     }
2747     switch (m_nTextureCompressionFormat)
2748     {
2749     case (0):
2750       {
2751         g_qeglobals.texture_components = GL_RGBA;
2752         Sys_Printf("texture compression disabled by preferences settings\n");
2753         break;
2754       }
2755     case (1):
2756       {
2757         g_qeglobals.texture_components = GL_COMPRESSED_RGBA;
2758         Sys_Printf("OpenGL texture compression enabled\n");
2759         break;
2760       }
2761     case (2):
2762       {
2763         g_qeglobals.texture_components = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
2764         Sys_Printf("S3TC DXT1 texture compression enabled\n");
2765         break;
2766       }
2767     case (3):
2768       {
2769         g_qeglobals.texture_components = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
2770         Sys_Printf("S3TC DXT3 texture compression enabled\n");
2771         break;
2772       }
2773     case (4):
2774       {
2775         g_qeglobals.texture_components = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
2776         Sys_Printf("S3TC DXT5 texture compression enabled\n");
2777         break;
2778       }
2779     }
2780   }
2781   else
2782   {
2783     Sys_Printf("texture compression is not supported by your current graphic card/drivers\n");
2784     g_qeglobals.texture_components = GL_RGBA;
2785     m_nTextureCompressionFormat = 0;
2786   }
2787 }
2788
2789 #ifdef ATIHACK_812
2790 void PrefsDlg::UpdateATIHack() {
2791   // if OpenGL is not ready yet, don't do anything
2792   if (!g_qeglobals.m_bOpenGLReady) {
2793     Sys_Printf("OpenGL not ready - postpone ATI bug workaround setup\n");
2794     return;
2795   }
2796
2797   if (m_bGlATIHack) {
2798     qglCullFace = &qglCullFace_ATIHack;
2799     qglDisable = &qglDisable_ATIHack;
2800     qglEnable = &qglEnable_ATIHack;
2801     qglPolygonMode = &qglPolygonMode_ATIHack;
2802     Sys_Printf("ATI bug workaround enabled\n");
2803   } else {
2804     qglCullFace = qglCullFace_real;
2805     qglDisable = qglDisable_real;
2806     qglEnable = qglEnable_real;
2807     qglPolygonMode = qglPolygonMode_real;
2808     Sys_Printf("ATI bug workaround disabled\n");
2809   }
2810 }
2811 #endif
2812
2813 // TTimo: m_strEnginePath has a special status, if not found in registry we need to
2814 // initiliaze it for sure. It is not totally failsafe but we can use the same
2815 // code than in q3map, expecting to find some "quake" above us. If not, we prompt
2816 // for the engine executable path
2817 void PrefsDlg::LoadPrefs ()
2818 {
2819   int i;
2820
2821   // first things first, load prefs from global prefs
2822   mGamesDialog.LoadPrefs();
2823
2824   // if we already have a document loaded, we will free and reload from file
2825   if (mLocalPrefs.InUse()) {
2826     mLocalPrefs.Clear();
2827   }
2828
2829   // load local.pref file
2830   mLocalPrefs.ReadXMLFile(m_inipath->str);
2831
2832   mLocalPrefs.GetPref(PATCHSHOWBOUNDS_KEY,  &g_bPatchShowBounds,  FALSE);
2833   mLocalPrefs.GetPref(MOUSE_KEY,            &m_nMouse,            MOUSE_DEF);
2834   m_nMouseButtons = m_nMouse ? 3 : 2;
2835
2836         // project file
2837         // if it's not found here, mainframe.cpp will take care of finding one
2838   mLocalPrefs.GetPref(LASTPROJ_KEY, &m_strLastProject, "");
2839   mLocalPrefs.GetPref(LASTPROJVER_KEY, &m_nLastProjectVer, -1);
2840
2841         // prefab path
2842   // NOTE TTimo: I'm not sure why this is in prefs
2843   // should probably be a project setting
2844   // and I'm not sure that we really have a way to set this reliably either
2845   CString strPrefab;
2846   strPrefab = g_qeglobals.m_strHomeGame.GetBuffer();
2847   strPrefab += g_pGameDescription->mBaseGame.GetBuffer();
2848   strPrefab += "/prefabs/";
2849   mLocalPrefs.GetPref(PREFAB_KEY, &m_strPrefabPath, strPrefab);
2850
2851   mLocalPrefs.GetPref(LASTLIGHTINTENSITY_KEY, &m_iLastLightIntensity, 300);
2852   mLocalPrefs.GetPref(TLOCK_KEY,              &m_bTextureLock,        TLOCK_DEF);
2853   mLocalPrefs.GetPref(RLOCK_KEY,              &m_bRotateLock,         TLOCK_DEF);
2854   mLocalPrefs.GetPref(LASTMAP_KEY,            &m_strLastMap,          "");
2855   mLocalPrefs.GetPref(LOADLAST_KEY,           &m_bLoadLast,           LOADLAST_DEF);
2856   mLocalPrefs.GetPref(BSP_KEY,                &m_bInternalBSP,        FALSE);
2857   mLocalPrefs.GetPref(RCLICK_KEY,             &m_bRightClick,         TRUE);
2858   mLocalPrefs.GetPref(AUTOSAVE_KEY,           &m_bAutoSave,           TRUE);
2859   mLocalPrefs.GetPref(LOADLASTMAP_KEY,        &m_bLoadLastMap,        FALSE);
2860   mLocalPrefs.GetPref(TINYBRUSH_KEY,          &m_bCleanTiny,          FALSE);
2861   mLocalPrefs.GetPref(TINYSIZE_KEY,           &m_fTinySize,           0.5f);
2862   mLocalPrefs.GetPref(AUTOSAVETIME_KEY,       &m_nAutoSave,           5);
2863   mLocalPrefs.GetPref(SNAPSHOT_KEY,           &m_bSnapShots,          FALSE);
2864   mLocalPrefs.GetPref(MOVESPEED_KEY,          &m_nMoveSpeed,          100);
2865   mLocalPrefs.GetPref(ANGLESPEED_KEY,         &m_nAngleSpeed,         3);
2866   mLocalPrefs.GetPref(SETGAME_KEY,            &m_bSetGame,            FALSE);
2867   mLocalPrefs.GetPref(CAMXYUPDATE_KEY,        &m_bCamXYUpdate,        TRUE);
2868   mLocalPrefs.GetPref(CAMDRAGMULTISELECT_KEY, &m_nCamDragMultiSelect, TRUE);
2869   mLocalPrefs.GetPref(CAMFREELOOK_KEY,        &m_bCamFreeLook,        TRUE);
2870   mLocalPrefs.GetPref(CAMINVERSEMOUSE_KEY,    &m_bCamInverseMouse,    FALSE);
2871   mLocalPrefs.GetPref(CAMDISCRETE_KEY,        &m_bCamDiscrete,        TRUE);
2872   mLocalPrefs.GetPref(LIGHTDRAW_KEY,          &m_bNewLightDraw,       TRUE);
2873   mLocalPrefs.GetPref(CUBICCLIP_KEY,          &m_bCubicClipping,      TRUE);
2874   mLocalPrefs.GetPref(CUBICSCALE_KEY,         &m_nCubicScale,         13);
2875   mLocalPrefs.GetPref(ALTEDGE_KEY,            &m_bALTEdge,            FALSE);
2876   mLocalPrefs.GetPref(FACECOLORS_KEY,         &m_bFaceColors,         FALSE);
2877   mLocalPrefs.GetPref(XZVIS_KEY,              &m_bXZVis,              FALSE);
2878   mLocalPrefs.GetPref(YZVIS_KEY,              &m_bYZVis,              FALSE);
2879   mLocalPrefs.GetPref(ZVIS_KEY,               &m_bZVis,               FALSE);
2880   mLocalPrefs.GetPref(SIZEPAINT_KEY,          &m_bSizePaint,                  FALSE);
2881   mLocalPrefs.GetPref(DLLENTITIES_KEY,        &m_bDLLEntities,                FALSE);
2882
2883   mLocalPrefs.GetPref(DETACHABLEMENUS_KEY,    &m_bLatchedDetachableMenus,            TRUE);
2884   m_bDetachableMenus = m_bLatchedDetachableMenus;
2885
2886   if (g_pGameDescription->mNoPatch)
2887   {
2888     m_bPatchToolbar = false;
2889   }
2890   else
2891   {
2892     mLocalPrefs.GetPref(PATCHTOOLBAR_KEY,       &m_bLatchedPatchToolbar,               TRUE);
2893     m_bPatchToolbar = m_bLatchedPatchToolbar;
2894   }
2895
2896   mLocalPrefs.GetPref(WIDETOOLBAR_KEY,        &m_bLatchedWideToolbar,                TRUE);
2897   m_bWideToolbar = m_bLatchedWideToolbar;
2898
2899   mLocalPrefs.GetPref(PLUGINTOOLBAR_KEY, &m_bLatchedPluginToolbar, TRUE);
2900   m_bPluginToolbar = m_bLatchedPluginToolbar;
2901
2902   mLocalPrefs.GetPref(WINDOW_KEY,             (int*)&m_nLatchedView,  WINDOW_DEF);
2903   m_nView = m_nLatchedView;
2904
2905   mLocalPrefs.GetPref(FLOATINGZ_KEY,          &m_bLatchedFloatingZ,           FALSE);
2906   m_bFloatingZ = m_bLatchedFloatingZ;
2907
2908   mLocalPrefs.GetPref(TEXTUREQUALITY_KEY,     &m_nLatchedTextureQuality,             3);
2909   m_nTextureQuality = m_nLatchedTextureQuality;
2910
2911   mLocalPrefs.GetPref(LOADSHADERS_KEY,        &m_nLatchedShader,                     0);
2912   m_nShader = m_nLatchedShader;
2913
2914   mLocalPrefs.GetPref(NOCLAMP_KEY,            &m_bNoClamp,                    FALSE);
2915   mLocalPrefs.GetPref(USERINI_KEY,            &m_strUserPath,                 "");
2916   mLocalPrefs.GetPref(ROTATION_KEY,           &m_nRotation,                   45);
2917   mLocalPrefs.GetPref(CHASEMOUSE_KEY,         &m_bChaseMouse,                 TRUE);
2918   mLocalPrefs.GetPref(ENTITYSHOW_KEY,         &m_nEntityShowState,            ENTITY_SKINNED_BOXED);
2919
2920   // this will probably need to be 75 or 100 for Q1.
2921   mLocalPrefs.GetPref(TEXTURESCALE_KEY,       &m_nTextureScale,               50);
2922
2923   // FIXME: Hydra - actually, this stuff is Q1,Q2 and HL specific.
2924   if ( (g_pGameDescription->mGameFile == "hl.game") )
2925   {
2926     // No BSP monitoring in the default compiler tools for Half-life (yet)
2927     mLocalPrefs.GetPref(WATCHBSP_KEY,           &m_bWatchBSP,                   FALSE);
2928
2929     // Texture subset on by default (HL specific really, because of halflife.wad's size)
2930     mLocalPrefs.GetPref(TEXTURE_KEY,            &m_bTextureWindow,              TRUE);
2931   }
2932   else if (g_pGameDescription->quake2)
2933   {
2934     // BSP monitoring is implemented in Quake2 and Heretic2 tools
2935     mLocalPrefs.GetPref(WATCHBSP_KEY,           &m_bWatchBSP,                   TRUE);
2936
2937     // Texture subset on by default (HL specific really, because of halflife.wad's size)
2938     mLocalPrefs.GetPref(TEXTURE_KEY,            &m_bTextureWindow,              TRUE);
2939   }
2940   else
2941   {
2942     mLocalPrefs.GetPref(WATCHBSP_KEY,           &m_bWatchBSP,                   WATCHBSP_DEF);
2943     mLocalPrefs.GetPref(TEXTURE_KEY,            &m_bTextureWindow,              FALSE);
2944   }
2945
2946
2947   mLocalPrefs.GetPref(TEXTURESCROLLBAR_KEY,   &m_bTextureScrollbar,           TRUE);
2948   mLocalPrefs.GetPref(DISPLAYLISTS_KEY,       &m_bDisplayLists,               TRUE);
2949   mLocalPrefs.GetPref(ANTIALIASEDLINES_KEY,   &m_bAntialiasedPointsAndLines,  FALSE);
2950   mLocalPrefs.GetPref(SWITCHCLIP_KEY,         &m_bSwitchClip,                 TRUE);
2951   mLocalPrefs.GetPref(SELWHOLEENTS_KEY,       &m_bSelectWholeEntities,        TRUE);
2952   mLocalPrefs.GetPref(SHOWSHADERS_KEY,        &m_bShowShaders,                TRUE);
2953   mLocalPrefs.GetPref(GLLIGHTING_KEY,         &m_bGLLighting,                 FALSE);
2954   mLocalPrefs.GetPref(NOSTIPPLE_KEY,          &m_bNoStipple,                  FALSE);
2955   mLocalPrefs.GetPref(UNDOLEVELS_KEY,         &m_nUndoLevels,                 30);
2956   mLocalPrefs.GetPref(VERTEXMODE_KEY,         &m_bVertexSplit,                TRUE);
2957   mLocalPrefs.GetPref(RUNQ2_KEY,              &m_bRunQuake,                   RUNQ2_DEF);
2958   mLocalPrefs.GetPref(LEAKSTOP_KEY,           &m_bLeakStop,                   TRUE);
2959   mLocalPrefs.GetPref(DOSLEEP_KEY,            &m_bDoSleep,                    FALSE);
2960   mLocalPrefs.GetPref(SELECTCURVES_KEY,       &m_bSelectCurves,               TRUE);
2961   mLocalPrefs.GetPref(SELECTMODELS_KEY,       &m_bSelectModels,               TRUE);
2962   mLocalPrefs.GetPref(SHADERLISTONLY_KEY,     &m_bTexturesShaderlistOnly,     FALSE);
2963   mLocalPrefs.GetPref(SUBDIVISIONS_KEY,       &m_nSubdivisions,               SUBDIVISIONS_DEF);
2964   mLocalPrefs.GetPref(CLIPCAULK_KEY,          &m_bClipCaulk,                  FALSE);
2965   mLocalPrefs.GetPref(SNAPTTOGRID_KEY,        &m_bSnapTToGrid,                FALSE);
2966   mLocalPrefs.GetPref(TARGETFIX_KEY,          &m_bDoTargetFix,                TRUE);
2967   mLocalPrefs.GetPref(WHEELINC_KEY,           &m_nWheelInc,                   64);
2968   mLocalPrefs.GetPref(PATCHBBOXSEL_KEY,       &m_bPatchBBoxSelect,            FALSE);
2969
2970   // Gef: Kyro GL_POINT workaround
2971   mLocalPrefs.GetPref(GLPOINTWORKAROUND_KEY,  &m_bGlPtWorkaround,             FALSE);
2972
2973   // window positioning
2974   mLocalPrefs.GetPref(ENTITYSPLIT1_KEY,       &mWindowInfo.nEntitySplit1,     -1);
2975   mLocalPrefs.GetPref(ENTITYSPLIT2_KEY,       &mWindowInfo.nEntitySplit2,     -1);
2976
2977   mLocalPrefs.GetPref(POSITIONX_KEY,          &mWindowInfo.position.x,        -1);
2978   mLocalPrefs.GetPref(POSITIONY_KEY,          &mWindowInfo.position.y,        -1);
2979   mLocalPrefs.GetPref(WIDTH_KEY,              &mWindowInfo.position.w,        -1);
2980   mLocalPrefs.GetPref(HEIGHT_KEY,             &mWindowInfo.position.h,        450);
2981
2982   const window_position_t default_window_pos = { 0, 0, 200, 200, };
2983
2984   mLocalPrefs.GetPref(ENTITYWND_KEY,          &mWindowInfo.posEntityWnd,      default_window_pos);
2985   mLocalPrefs.GetPref(MAPINFOWND_KEY,         &mWindowInfo.posMapInfoWnd,     default_window_pos);
2986   mLocalPrefs.GetPref(CAMWND_KEY,             &mWindowInfo.posCamWnd,         default_window_pos);
2987   mLocalPrefs.GetPref(ZWND_KEY,               &mWindowInfo.posZWnd,           default_window_pos);
2988   mLocalPrefs.GetPref(XYWND_KEY,              &mWindowInfo.posXYWnd,          default_window_pos);
2989   mLocalPrefs.GetPref(YZWND_KEY,              &mWindowInfo.posYZWnd,          default_window_pos);
2990   mLocalPrefs.GetPref(XZWND_KEY,              &mWindowInfo.posXZWnd,          default_window_pos);
2991   mLocalPrefs.GetPref(PATCHWND_KEY,           &mWindowInfo.posPatchWnd,       default_window_pos);
2992   mLocalPrefs.GetPref(SURFACEWND_KEY,         &mWindowInfo.posSurfaceWnd,     default_window_pos);
2993   mLocalPrefs.GetPref(ENTITYINFOWND_KEY,      &mWindowInfo.posEntityInfoWnd,  default_window_pos);
2994
2995   mLocalPrefs.GetPref(ZWIDTH_KEY,             &mWindowInfo.nZWidth,           30);
2996   mLocalPrefs.GetPref(XYHEIGHT_KEY,           &mWindowInfo.nXYHeight,         300);
2997   mLocalPrefs.GetPref(XYWIDTH_KEY,            &mWindowInfo.nXYWidth,          300);
2998   mLocalPrefs.GetPref(CAMWIDTH_KEY,           &mWindowInfo.nCamWidth,         200);
2999   mLocalPrefs.GetPref(CAMHEIGHT_KEY,          &mWindowInfo.nCamHeight,        200);
3000   mLocalPrefs.GetPref(ZFLOATWIDTH_KEY,        &mWindowInfo.nZFloatWidth,      300);
3001 #ifdef _WIN32
3002   mLocalPrefs.GetPref(STATE_KEY,              &mWindowInfo.nState,            SW_SHOW);
3003 #endif
3004
3005   // menu stuff
3006   mLocalPrefs.GetPref(COUNT_KEY,              &m_nMRUCount,                   0);
3007   for(i = 0; i < 4; i++)
3008   {
3009     char buf[64];
3010     sprintf (buf, "%s%d", FILE_KEY, i);
3011     mLocalPrefs.GetPref(buf,                  &m_strMRUFiles[i],              "");
3012   }
3013
3014   // some platform specific prefs
3015 #ifdef _WIN32
3016   mLocalPrefs.GetPref(NATIVEGUI_KEY,          &m_bNativeGUI,                  TRUE);
3017   mLocalPrefs.GetPref(STARTONPRIMMON_KEY,     &m_bStartOnPrimMon,             FALSE);
3018 #endif
3019
3020   mLocalPrefs.GetPref(SI_TEXMENU_KEY,         &g_qeglobals.d_savedinfo.iTexMenu,                ID_VIEW_BILINEARMIPMAP);
3021   mLocalPrefs.GetPref(SI_GAMMA_KEY,           &g_qeglobals.d_savedinfo.fGamma,                  1.0f);
3022   mLocalPrefs.GetPref(SI_EXCLUDE_KEY,         &g_qeglobals.d_savedinfo.exclude,                 0); // nothing filtered by default
3023   mLocalPrefs.GetPref(SI_INCLUDE_KEY,         &g_qeglobals.d_savedinfo.include,                 INCLUDE_NAMES | INCLUDE_COORDS | INCLUDE_ANGLES | INCLUDE_CAMERATINT);
3024   mLocalPrefs.GetPref(SI_SHOWNAMES_KEY,       &g_qeglobals.d_savedinfo.show_names,              FALSE);
3025   mLocalPrefs.GetPref(SI_SHOWCOORDS_KEY,      &g_qeglobals.d_savedinfo.show_coordinates,        TRUE);
3026   mLocalPrefs.GetPref(SI_SHOWANGLES_KEY,      &g_qeglobals.d_savedinfo.show_angles,             TRUE);
3027   mLocalPrefs.GetPref(SI_SHOWOUTLINES_KEY,    &g_qeglobals.d_savedinfo.show_outline,            FALSE);
3028   mLocalPrefs.GetPref(SI_SHOWAXIS_KEY,        &g_qeglobals.d_savedinfo.show_axis,               TRUE);
3029   mLocalPrefs.GetPref(SI_NOSELOUTLINES_KEY,   &g_qeglobals.d_savedinfo.bNoSelectedOutlines,     FALSE);
3030
3031   mLocalPrefs.GetPref(SI_OUTLINESTYLE_KEY,   &g_qeglobals.d_savedinfo.iSelectedOutlinesStyle,  OUTLINE_ZBUF|OUTLINE_BSEL);
3032
3033   LoadTexdefPref(&g_qeglobals.d_savedinfo.m_SIIncrement, SI_SURFACE_TEXDEF_KEY);
3034   LoadTexdefPref(&g_qeglobals.d_savedinfo.m_PIIncrement, SI_PATCH_TEXDEF_KEY);
3035
3036   // text editor binding
3037 #ifdef _WIN32
3038   mLocalPrefs.GetPref(CUSTOMSHADEREDITOR_KEY, &m_bUseWin32Editor, TRUE);
3039 #else
3040   mLocalPrefs.GetPref(CUSTOMSHADEREDITOR_KEY, &m_bUseCustomEditor, FALSE);
3041   mLocalPrefs.GetPref(CUSTOMSHADEREDITORCOMMAND_KEY, &m_strEditorCommand, "");
3042 #endif
3043
3044
3045   vec3_t vDefaultAxisColours[3] = {
3046     {0.f, 0.5f, 0.f},
3047     {0.f, 0.f, 1.f},
3048     {1.f, 0.f, 0.f},
3049   };
3050
3051   for(i = 0; i < 3; i++) {
3052     char buf[64];
3053     sprintf(buf, "%s%d", SI_AXISCOLORS_KEY, i);
3054     mLocalPrefs.GetPref(buf,   g_qeglobals.d_savedinfo.AxisColors[i], vDefaultAxisColours[i]);
3055   }
3056
3057   vec3_t vDefaultColours[COLOR_LAST] = {
3058     {0.25f, 0.25f,  0.25f},
3059     {1.f,   1.f,    1.f},
3060     {0.75f, 0.75f,  0.75f},
3061     {0.5f,  0.5f,   0.5f},
3062     {0.25f, 0.25f,  0.25f},
3063     {0.0f,  0.0f,   0.0f},
3064     {0.f,   0.f,    1.f},
3065     {0.f,   0.f,    0.f},
3066     {0.f,   0.f,    0.f},
3067     {1.f,   0.f,    0.f},
3068     {0.f,   0.f,    1.f},
3069     {0.5f,  0.f,    0.75f},
3070     {1.0f,  0.f,    0.f},
3071     {0.f,   0.f,    0.f},
3072     {0.f,   0.f,    0.f},
3073   };
3074
3075   for(i = 0; i < COLOR_LAST; i++) {
3076     char buf[64];
3077     sprintf(buf, "%s%d", SI_COLORS_KEY, i);
3078     mLocalPrefs.GetPref(buf,   g_qeglobals.d_savedinfo.colors[i], vDefaultColours[i]);
3079   }
3080
3081   mLocalPrefs.GetPref(TEXTURECOMPRESSIONFORMAT_KEY, &m_nTextureCompressionFormat, 1);
3082
3083   mLocalPrefs.GetPref(LIGHTRADIUS_KEY, &m_nLightRadiuses, TRUE);
3084
3085   mLocalPrefs.GetPref(Q3MAP2TEX_KEY, &m_bQ3Map2Texturing, TRUE);
3086
3087 #ifdef ATIHACK_812
3088         mLocalPrefs.GetPref(ATIHACK_KEY, &m_bGlATIHack, FALSE);
3089 #endif
3090
3091   Undo_SetMaxSize(m_nUndoLevels); // set it internally as well / FIXME: why not just have one global value?
3092
3093   UpdateTextureCompression();
3094
3095 #ifdef ATIHACK_812
3096   UpdateATIHack();
3097 #endif
3098
3099   if (mLocalPrefs.mbEmpty)
3100   {
3101     mLocalPrefs.mbEmpty = false;
3102     Sys_Printf("Saving local.pref with default pref values\n");
3103     SavePrefs();
3104   }
3105 }
3106
3107 void PrefsDlg::SavePrefs ()
3108 {
3109   if (g_qeglobals.disable_ini)
3110     return;
3111
3112 #ifdef _DEBUG
3113   Sys_Printf("PrefsDlg::SavePrefs\n");
3114 #endif
3115
3116   // this will take care of copying back from the dialog to the variables
3117   // NOTE: it may be overkill to call systematically before a SavePrefs, but it's safer
3118   // this will also cause an UpdateData for the mGamesDialog
3119   UpdateData(TRUE);
3120
3121   mGamesDialog.SavePrefs();
3122
3123   // update the tree and save it
3124   mLocalPrefs.UpdatePrefTree();
3125   if (!mLocalPrefs.WriteXMLFile(m_inipath->str))
3126     Sys_FPrintf(SYS_ERR, "Error occured while saving local prefs file '%s'\n", m_inipath->str);
3127
3128   if ( m_nMouse == 0 ) {
3129           m_nMouseButtons = 2;
3130   } else {
3131           m_nMouseButtons = 3;
3132   }
3133
3134 }
3135
3136 void PrefsDlg::PostModal (int code)
3137 {
3138   if (code == IDOK)
3139   {
3140     SavePrefs();
3141     // make sure the logfile is ok
3142     Sys_LogFile();
3143     #ifdef ATIHACK_812
3144       UpdateATIHack();
3145     #endif
3146     if (g_pParentWnd)
3147       g_pParentWnd->SetGridStatus();
3148     Sys_UpdateWindows(W_ALL);
3149     if (m_nUndoLevels != 0)
3150                 Undo_SetMaxSize(m_nUndoLevels);
3151   }
3152 }
3153
3154 void PrefsDlg::DoEditorSensitivity()
3155 {
3156   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data (G_OBJECT(m_pWidget), "check_customeditor"))))
3157   {
3158     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "label_customeditor")), TRUE);
3159     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "entry_customeditor")), TRUE);
3160     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "button_customeditor")), TRUE);
3161   }
3162   else
3163   {
3164     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "label_customeditor")), FALSE);
3165     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "entry_customeditor")), FALSE);
3166     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "button_customeditor")), FALSE);
3167   }
3168 }
3169
3170 void PrefsDlg::DoSensitivity()
3171 {
3172 #if 0
3173   // first, look at the project file version ... will monitoring work?
3174   // project files now XML, guaranteed to be at least version 2
3175   if (0)//IntForKey( g_qeglobals.d_project_entity, "version" ) < 2)
3176   {
3177     if (m_bWarn)
3178     {
3179       Str Msg;
3180       Msg = "The current project file (";
3181       Msg += g_PrefsDlg.m_strLastProject;
3182       Msg += ") is not at least version 2.\nI need version 2 or above to setup BSP monitoring correctly.";
3183       gtk_MessageBox(m_pWidget, Msg.GetBuffer(), MB_OK );
3184
3185       m_bWarn = false;
3186     }
3187
3188     // go ahead, disable everybuddy
3189     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_leakstop" )), FALSE );
3190     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_monitorbsp" )), FALSE );
3191     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" )), FALSE );
3192     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), FALSE );
3193   }
3194   else
3195   {
3196 #endif
3197 //    m_bWarn = true;
3198
3199     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_leakstop" )), TRUE );
3200     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_monitorbsp" )), TRUE );
3201     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" )), TRUE );
3202     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), TRUE );
3203
3204     if ( ! gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_object_get_data( G_OBJECT(m_pWidget), "check_monitorbsp" ) ) ) )
3205     {
3206       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_leakstop" )), FALSE );
3207       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" )), FALSE );
3208       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), FALSE );
3209     } else if (! gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" ) ) ) )
3210     {
3211       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), FALSE );
3212     }
3213 }
3214
3215 /*
3216 ============================================================
3217 CGameInstall
3218 ============================================================
3219 */
3220
3221 CGameInstall::CGameInstall() {
3222         memset( m_availGames, 0, sizeof( m_availGames ) );
3223 }
3224
3225 void CGameInstall::OnBtnBrowseEngine( GtkWidget *widget, gpointer data ) {
3226         Sys_Printf( "OnBtnBrowseEngine\n" );
3227
3228         CGameInstall* i = static_cast<CGameInstall*>( data );
3229         char *dir = dir_dialog( widget, _("Select game directory"), NULL );
3230
3231         i->UpdateData( TRUE );
3232
3233         if ( dir != NULL ) {
3234                 i->m_strEngine = dir;
3235                 i->UpdateData( FALSE );
3236                 free( dir );
3237         }
3238 }
3239
3240 void CGameInstall::OnGameSelectChanged( GtkWidget *widget, gpointer data ) {
3241         Sys_Printf( "OnGameSelectChanged\n" );
3242
3243         CGameInstall* i = static_cast<CGameInstall*>( data );
3244         i->UpdateData( TRUE );
3245         i->m_strName = gtk_combo_box_get_active_text( GTK_COMBO_BOX( widget ) );
3246         i->UpdateData( FALSE );
3247 }
3248
3249 void CGameInstall::BuildDialog() {
3250         GtkWidget *dlg, *vbox1, *button, *text, *combo, *entry, *hbox;
3251
3252         dlg = m_pWidget;
3253         gtk_window_set_title( GTK_WINDOW( dlg ), _("Configure games") );
3254
3255         vbox1 = gtk_vbox_new( FALSE, 0 );
3256         gtk_widget_show( vbox1 );
3257         gtk_container_add( GTK_CONTAINER( dlg ), vbox1 );
3258
3259         text = gtk_label_new( _("Select the game to configure") );
3260         gtk_widget_show( text );
3261         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3262
3263         combo = gtk_combo_box_new_text();
3264         gtk_widget_show( combo );
3265         gtk_box_pack_start( GTK_BOX( vbox1 ), combo, FALSE, FALSE, 0 );
3266
3267         //      GList *combo_list = NULL;
3268         int iGame = 0;
3269         while ( m_availGames[ iGame ] != GAME_NONE ) {
3270                 switch ( m_availGames[ iGame ] ) {
3271                 case GAME_Q2:
3272                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Quake II") );
3273                         break;
3274                 case GAME_Q3:
3275                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Quake III Arena and mods") );
3276                         break;
3277                 case GAME_URT:
3278                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Urban Terror (standalone)") );
3279                         break;
3280                 case GAME_UFOAI:
3281                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("UFO: Alien Invasion") );
3282                         break;
3283                 case GAME_Q2W:
3284                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Quake2World") );
3285                         break;
3286                 case GAME_WARSOW:
3287                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Warsow") );
3288                         break;
3289                 case GAME_NEXUIZ:
3290                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Nexuiz") );
3291                         break;
3292                 case GAME_TREMULOUS:
3293                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Tremulous") );
3294                         break;
3295                 }
3296                 iGame++;
3297         }
3298         AddDialogData( combo, &m_nComboSelect, DLG_COMBO_BOX_INT );
3299         gtk_signal_connect( GTK_OBJECT( combo ), "changed", G_CALLBACK( OnGameSelectChanged ), this );
3300         gtk_combo_box_set_active( GTK_COMBO_BOX( combo ), 0 );  // NOTE: will trigger signal
3301
3302         text = gtk_label_new( _("Name:") );
3303         gtk_widget_show( text );
3304         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3305
3306         entry = gtk_entry_new();
3307         gtk_widget_show( entry );
3308         gtk_box_pack_start( GTK_BOX( vbox1 ), entry, FALSE, FALSE, 0 );
3309         AddDialogData( entry, &m_strName, DLG_ENTRY_TEXT );
3310
3311         text = gtk_label_new( _("Engine directory:") );
3312         gtk_widget_show( text );
3313         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3314
3315         hbox = gtk_hbox_new( FALSE, 0 );
3316         gtk_widget_show( hbox );
3317         gtk_box_pack_start( GTK_BOX( vbox1 ), hbox, FALSE, FALSE, 0 );
3318
3319         entry = gtk_entry_new();
3320         gtk_widget_show( entry );
3321         gtk_box_pack_start( GTK_BOX( hbox ), entry, FALSE, FALSE, 0 );
3322         AddDialogData( entry, &m_strEngine, DLG_ENTRY_TEXT );
3323
3324         button = gtk_button_new_with_label (_("..."));
3325         gtk_widget_show( button );
3326         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnBtnBrowseEngine ), this );
3327         gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
3328
3329         // this gets done in the project stuff atm
3330 #if 0
3331         text = gtk_label_new( _("Mod subdirectory:") );
3332         gtk_widget_show( text );
3333         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3334
3335         entry = gtk_entry_new();
3336         gtk_widget_show( entry );
3337         gtk_box_pack_start( GTK_BOX( vbox1 ), entry, FALSE, FALSE, 0 );
3338         AddDialogData( entry, &m_strMod, DLG_ENTRY_TEXT );
3339 #endif
3340
3341         button = gtk_button_new_with_label( _("OK") );
3342         gtk_widget_show( button );
3343         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
3344         AddModalButton( button, IDOK );
3345
3346         button = gtk_button_new_with_label( _("Cancel") );
3347         gtk_widget_show( button );
3348         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
3349         AddModalButton( button, IDCANCEL );
3350
3351         gtk_widget_set_usize( button, 60, -2 );
3352 }
3353
3354 void CGameInstall::Run() {
3355         ScanGames();
3356         if ( DoModal() == IDCANCEL ) {
3357                 Sys_Printf( "game dialog cancelled\n" );
3358                 return;
3359         }
3360         Sys_Printf( "combo: %d name: %s engine: %s mod: %s\n", m_nComboSelect, m_strName.GetBuffer(), m_strEngine.GetBuffer(), m_strMod.GetBuffer() );
3361
3362         // write out the game file
3363         Str gameFilePath = g_strAppPath.GetBuffer();
3364         gameFilePath += "games/";
3365         gameFilePath += m_strName.GetBuffer();
3366         gameFilePath += ".game";
3367         Sys_Printf( "game file: %s\n", gameFilePath.GetBuffer() );
3368
3369         FILE *fg = fopen( gameFilePath.GetBuffer(), "w" );
3370         if ( fg == NULL ) {
3371                 Error( "Failed to open %s for writing\n", gameFilePath.GetBuffer() );
3372         }
3373         fprintf( fg, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"yes\"?>\n<game\n" );
3374         fprintf( fg, "  name=\"%s\"\n", m_strName.GetBuffer() );
3375         fprintf( fg, "  "ENGINEPATH_ATTRIBUTE"=\"%s\"\n", m_strEngine.GetBuffer() );
3376         switch ( m_availGames[ m_nComboSelect ] ) {
3377         case GAME_Q2: {
3378                 fprintf( fg, "  gametools=\"%sinstalls/Quake2Pack/game\"\n", g_strAppPath.GetBuffer() );
3379                 fprintf( fg, "  prefix=\".quake2\"\n" );
3380                 Str source = g_strAppPath.GetBuffer();
3381                 source += "installs/";
3382                 source += Q2_PACK;
3383                 source += "/install/";
3384                 Str dest = m_strEngine.GetBuffer();
3385                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3386                 fprintf( fg, "  basegame=\"baseq2\"\n" );
3387                 break;
3388         }
3389         case GAME_Q3: {
3390                 fprintf( fg, "  gametools=\"%sinstalls/Q3Pack/game\"\n", g_strAppPath.GetBuffer() );
3391                 fprintf( fg, "  prefix=\".q3a\"\n" );
3392                 Str source = g_strAppPath.GetBuffer();
3393                 source += "installs/";
3394                 source += Q3_PACK;
3395                 source += "/install/";
3396                 Str dest = m_strEngine.GetBuffer();
3397                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3398                 fprintf( fg, "  basegame=\"baseq3\"\n" );
3399                 break;
3400         }
3401         case GAME_URT: {
3402                 fprintf( fg, "  gametools=\"%sinstalls/UrTPack/game\"\n", g_strAppPath.GetBuffer() );
3403                 fprintf( fg, "  prefix=\".q3a\"\n" );
3404                 Str source = g_strAppPath.GetBuffer();
3405                 source += "installs/";
3406                 source += URT_PACK;
3407                 source += "/install/";
3408                 Str dest = m_strEngine.GetBuffer();
3409                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3410                 fprintf( fg, "  basegame=\"q3ut4\"\n" );
3411                 break;
3412         }
3413         case GAME_UFOAI: {
3414                 fprintf( fg, "  gametools=\"%sinstalls/UFOAIPack/game\"\n", g_strAppPath.GetBuffer() );
3415                 fprintf( fg, "  prefix=\".ufoai\"\n" );
3416                 Str source = g_strAppPath.GetBuffer();
3417                 source += "installs/";
3418                 source += UFOAI_PACK;
3419                 source += "/install/";
3420                 Str dest = m_strEngine.GetBuffer();
3421                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3422                 fprintf( fg, "  basegame=\"base\"\n" );
3423                 break;
3424         }
3425         case GAME_Q2W: {
3426                 fprintf( fg, "  gametools=\"%sinstalls/Q2WPack/game\"\n", g_strAppPath.GetBuffer() );
3427                 fprintf( fg, "  prefix=\".quake2world\"\n" );
3428                 Str source = g_strAppPath.GetBuffer();
3429                 source += "installs/";
3430                 source += Q2W_PACK;
3431                 source += "/install/";
3432                 Str dest = m_strEngine.GetBuffer();
3433                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3434                 fprintf( fg, "  basegame=\"default\"\n" );
3435                 break;
3436         }
3437         case GAME_WARSOW: {
3438                 fprintf( fg, "  gametools=\"%sinstalls/WarsowPack/game\"\n", g_strAppPath.GetBuffer() );
3439                 fprintf( fg, "  prefix=\".warsow\"\n" );
3440                 Str source = g_strAppPath.GetBuffer();
3441                 source += "installs/";
3442                 source += WARSOW_PACK;
3443                 source += "/install/";
3444                 Str dest = m_strEngine.GetBuffer();
3445                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3446                 fprintf( fg, "  basegame=\"basewsw\"\n" );
3447                 break;
3448         }
3449         case GAME_NEXUIZ: {
3450                 fprintf( fg, "  gametools=\"%sinstalls/NexuizPack/game\"\n", g_strAppPath.GetBuffer() );
3451                 fprintf( fg, "  prefix=\".nexuiz\"\n" );
3452                 Str source = g_strAppPath.GetBuffer();
3453                 source += "installs/";
3454                 source += NEXUIZ_PACK;
3455                 source += "/install/";
3456                 Str dest = m_strEngine.GetBuffer();
3457                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3458                 fprintf( fg, "  basegame=\"data\"\n" );
3459                 break;
3460         }
3461         case GAME_TREMULOUS: {
3462                 fprintf( fg, "  gametools=\"%sinstalls/TremulousPack/game\"\n", g_strAppPath.GetBuffer() );
3463                 fprintf( fg, "  prefix=\".tremulous\"\n" );
3464                 Str source = g_strAppPath.GetBuffer();
3465                 source += "installs/";
3466                 source += TREMULOUS_PACK;
3467                 source += "/install/";
3468                 Str dest = m_strEngine.GetBuffer();
3469                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3470                 fprintf( fg, "  basegame=\"base\"\n" );
3471                 break;
3472         }
3473         }
3474         fprintf( fg, "/>\n" );
3475         fclose( fg );
3476 }
3477
3478 /*
3479 ===============
3480 CGameInstall::ScanGames
3481 scan for active games that can be installed, based on the presence
3482 ===============
3483 */
3484 void CGameInstall::ScanGames() {
3485         Str                             pakPaths = g_strAppPath.GetBuffer();
3486         int                             iGame = 0;
3487         const char              *dirname;
3488
3489         pakPaths +=     "installs/";
3490         FindFiles fileScan( pakPaths.GetBuffer() );
3491         while ( ( dirname = fileScan.NextFile() ) != NULL ) {
3492                 if ( stricmp( dirname, Q3_PACK ) == 0 ) {
3493                         m_availGames[ iGame++ ] = GAME_Q3;
3494                 }
3495                 if ( stricmp( dirname, URT_PACK ) == 0 ) {
3496                         m_availGames[ iGame++ ] = GAME_URT;
3497                 }
3498                 if ( stricmp( dirname, UFOAI_PACK ) == 0 ) {
3499                         m_availGames[ iGame++ ] = GAME_UFOAI;
3500                 }
3501                 if ( stricmp( dirname, Q2W_PACK ) == 0 ) {
3502                         m_availGames[ iGame++ ] = GAME_Q2W;
3503                 }
3504                 if ( stricmp( dirname, WARSOW_PACK ) == 0 ) {
3505                         m_availGames[ iGame++ ] = GAME_WARSOW;
3506                 }
3507                 if ( stricmp( dirname, NEXUIZ_PACK ) == 0 ) {
3508                         m_availGames[ iGame++ ] = GAME_NEXUIZ;
3509                 }
3510                 if ( stricmp( dirname, Q2_PACK ) == 0 ) {
3511                         m_availGames[ iGame++ ] = GAME_Q2;
3512                 }
3513                 if ( stricmp( dirname, TREMULOUS_PACK ) == 0 ) {
3514                         m_availGames[ iGame++ ] = GAME_TREMULOUS;
3515                 }
3516         }
3517 }
3518