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