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