wollocalemgr.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/wollocalemgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/19/02 2:25p $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "WOLLocaleMgr.h"
  36. #include "WOLLoginProfile.h"
  37. #include "WOLLogonMgr.h"
  38. #include "DlgMPWOLLocaleNag.h"
  39. #include "ComboBoxCtrl.h"
  40. #include "MPSettingsMgr.h"
  41. #include "String_IDs.h"
  42. #include "TranslateDB.h"
  43. //////////////////////////////////////////////////////////////////////
  44. // Local constants
  45. //////////////////////////////////////////////////////////////////////
  46. static const int LOC_STRING_ARRAY[] =
  47. {
  48. IDS_LOCALE_UNKNOWN,
  49. IDS_LOCALE_OTHER,
  50. IDS_LOCALE_USA,
  51. IDS_LOCALE_CANADA,
  52. IDS_LOCALE_UK,
  53. IDS_LOCALE_GERMANY,
  54. IDS_LOCALE_FRANCE,
  55. IDS_LOCALE_SPAIN,
  56. IDS_LOCALE_NETHERLANDS,
  57. IDS_LOCALE_BELGIUM,
  58. IDS_LOCALE_AUSTRIA,
  59. IDS_LOCALE_SWITZERLAND,
  60. IDS_LOCALE_ITALY,
  61. IDS_LOCALE_DENMARK,
  62. IDS_LOCALE_SWEDEN,
  63. IDS_LOCALE_NORWAY,
  64. IDS_LOCALE_FINLAND,
  65. IDS_LOCALE_ISRAEL,
  66. IDS_LOCALE_SOUTH_AFRICA,
  67. IDS_LOCALE_JAPAN,
  68. IDS_LOCALE_SOUTH_KOREA,
  69. IDS_LOCALE_CHINA,
  70. IDS_LOCALE_SINGAPORE,
  71. IDS_LOCALE_TAIWAN,
  72. IDS_LOCALE_MALAYSIA,
  73. IDS_LOCALE_AUSTRALIA,
  74. IDS_LOCALE_NEW_ZEALAND,
  75. IDS_LOCALE_BRAZIL,
  76. IDS_LOCALE_THAILAND,
  77. IDS_LOCALE_ARGENTINA,
  78. IDS_LOCALE_PHILIPPINES,
  79. IDS_LOCALE_GREECE,
  80. IDS_LOCALE_IRELAND,
  81. IDS_LOCALE_POLAND,
  82. IDS_LOCALE_PORTUGAL,
  83. IDS_LOCALE_MEXICO,
  84. IDS_LOCALE_RUSSIA,
  85. IDS_LOCALE_TURKEY
  86. };
  87. static const int LOC_COUNT = sizeof (LOC_STRING_ARRAY) / sizeof (LOC_STRING_ARRAY[0]);
  88. //////////////////////////////////////////////////////////////////////
  89. //
  90. // Get_Locale
  91. //
  92. //////////////////////////////////////////////////////////////////////
  93. WOL::Locale WolLocaleMgrClass::Get_Locale(const WCHAR *login_name)
  94. {
  95. WOL::Locale locale = WOL::LOC_UNKNOWN;
  96. // Get the login information for this name
  97. LoginProfile* profile = LoginProfile::Get(login_name, false);
  98. if (profile) {
  99. locale = profile->GetLocale();
  100. profile->Release_Ref();
  101. }
  102. return locale;
  103. }
  104. //////////////////////////////////////////////////////////////////////
  105. //
  106. // Set_Locale
  107. //
  108. //////////////////////////////////////////////////////////////////////
  109. void WolLocaleMgrClass::Set_Locale(const WCHAR *login_name, WOL::Locale locale)
  110. {
  111. if (WOL::LOC_UNKNOWN != locale) {
  112. LoginProfile* profile = LoginProfile::Get(login_name, false);
  113. if (profile) {
  114. profile->SetLocale(locale);
  115. profile->SaveSettings();
  116. profile->Release_Ref();
  117. }
  118. }
  119. }
  120. //////////////////////////////////////////////////////////////////////
  121. //
  122. // Get_Current_Locale
  123. //
  124. //////////////////////////////////////////////////////////////////////
  125. WOL::Locale WolLocaleMgrClass::Get_Current_Locale(void)
  126. {
  127. WideStringClass loginName(0, true);
  128. WOLLogonMgr::GetLoginName(loginName);
  129. return Get_Locale(loginName);
  130. }
  131. //////////////////////////////////////////////////////////////////////
  132. //
  133. // Set_Current_Locale
  134. //
  135. //////////////////////////////////////////////////////////////////////
  136. void WolLocaleMgrClass::Set_Current_Locale(WOL::Locale locale)
  137. {
  138. WideStringClass loginName(0, true);
  139. WOLLogonMgr::GetLoginName(loginName);
  140. Set_Locale(loginName, locale);
  141. }
  142. //////////////////////////////////////////////////////////////////////
  143. //
  144. // Get_Locale_String
  145. //
  146. //////////////////////////////////////////////////////////////////////
  147. const WCHAR* WolLocaleMgrClass::Get_Locale_String(WOL::Locale locale)
  148. {
  149. WWASSERT(locale < LOC_COUNT && "Invalid locale");
  150. return TRANSLATE(LOC_STRING_ARRAY[locale]);
  151. }
  152. //////////////////////////////////////////////////////////////////////
  153. //
  154. // Configure_Locale_Combobox
  155. //
  156. //////////////////////////////////////////////////////////////////////
  157. void WolLocaleMgrClass::Configure_Locale_Combobox(ComboBoxCtrlClass *ctrl)
  158. {
  159. if (ctrl) {
  160. ctrl->Reset_Content();
  161. // Add an entry for each locale to the combobox
  162. for (int index = 0; index < LOC_COUNT; ++index) {
  163. ctrl->Add_String(TRANSLATE(LOC_STRING_ARRAY[index]));
  164. }
  165. // Get the last login
  166. WideStringClass wide_nickname(64, true);
  167. const char* nickname = MPSettingsMgrClass::Get_Last_Login();
  168. wide_nickname.Convert_From(nickname);
  169. // Select this locale in the combobox
  170. int locale = Get_Locale(wide_nickname);
  171. ctrl->Set_Curr_Sel(locale);
  172. }
  173. }
  174. //////////////////////////////////////////////////////////////////////
  175. //
  176. // Display_Nag_Dialog
  177. //
  178. //////////////////////////////////////////////////////////////////////
  179. void WolLocaleMgrClass::Display_Nag_Dialog(void)
  180. {
  181. WOL::Locale locale = Get_Current_Locale();
  182. if (WOL::LOC_UNKNOWN == locale) {
  183. START_DIALOG(MPWolLocaleNagDialogClass);
  184. }
  185. }