| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /******************************************************************************
- *
- * FILE
- * $Archive: /Commando/Code/Commando/DlgWOLSettings.cpp $
- *
- * DESCRIPTION
- * Westwood Online Account Settings
- *
- * PROGRAMMER
- * Denzil E. Long, Jr.
- * $Author: Greg_h $
- *
- * VERSION INFO
- * $Revision: 43 $
- * $Modtime: 6/21/02 11:40a $
- *
- ******************************************************************************/
- #include "DlgWOLSettings.h"
- #include "UserOptions.h"
- #include "RenegadeDialogMgr.h"
- #include "MPSettingsMgr.h"
- #include "DlgMessageBox.h"
- #include "DlgWOLWait.h"
- #include "DlgWebPage.h"
- #include "WOLLoginProfile.h"
- #include "WOLLogonMgr.h"
- #include <WWOnline\WOLServer.h>
- #include <WWOnline\WOLLoginInfo.h>
- #include <WWOnline\PingProfile.h>
- #include <WWUI\ComboBoxCtrl.h>
- #include <WWUI\ShortcutBarCtrl.h>
- #include "bandwidthcheck.h"
- #include "Resource.h"
- #include "String_ids.h"
- #include <WWTranslateDB\TranslateDB.h>
- using namespace WWOnline;
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::DoDialog
- *
- * DESCRIPTION
- * Start Westwood Online settings dialog.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * True if dialog successfully started.
- *
- ******************************************************************************/
- bool DlgWOLSettings::DoDialog(void)
- {
- DlgWOLSettings* dialog = new DlgWOLSettings;
- if (dialog)
- {
- if (dialog->FinalizeCreate())
- {
- dialog->Start_Dialog();
- }
- dialog->Release_Ref();
- }
- return (dialog != NULL);
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::DlgWOLSettings
- *
- * DESCRIPTION
- * Constructor
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- DlgWOLSettings::DlgWOLSettings() :
- MenuDialogClass(IDD_WOL_SETTINGS),
- DetectingBandwidth(false),
- WaitingToExitDialog(false)
- {
- WWDEBUG_SAY(("DlgWOLSettings: Instantiated\n"));
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::~DlgWOLSettings
- *
- * DESCRIPTION
- * Destructor
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- DlgWOLSettings::~DlgWOLSettings()
- {
- WWDEBUG_SAY(("DlgWOLSettings: Destroyed\n"));
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::FinalizeCreate
- *
- * DESCRIPTION
- * Finalize the creation of this object (Initialize).
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * True if successful
- *
- ******************************************************************************/
- bool DlgWOLSettings::FinalizeCreate(void)
- {
- mWOLSession = Session::GetInstance(false);
- return mWOLSession.IsValid();
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::On_Init_Dialog
- *
- * DESCRIPTION
- * Initialize dialog for first time.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::On_Init_Dialog(void)
- {
- // Configure the shortcut bar
- ShortcutBarCtrlClass* bar = (ShortcutBarCtrlClass*)Get_Dlg_Item(IDC_SHORTCUT_BAR);
- if (bar)
- {
- bar->Add_Button(IDC_MP_SHORTCUT_INTERNET_OPTIONS, TRANSLATE(IDS_INTERNET_OPTIONS));
- #ifdef QUICKMATCH_OPTIONS
- bar->Add_Button(IDC_MP_SHORTCUT_QUICKMATCH_OPTIONS, TRANSLATE(IDS_MENU_TEXT364));
- #endif
- bar->Add_Button(IDC_MP_SHORTCUT_NEWS, TRANSLATE(IDS_MP_SHORTCUT_NEWS));
- bar->Add_Button(IDC_MP_SHORTCUT_CLANS, TRANSLATE(IDS_MP_SHORTCUT_CLANS));
- bar->Add_Button(IDC_MP_SHORTCUT_RANKINGS, TRANSLATE(IDS_MP_SHORTCUT_RANKINGS));
- bar->Add_Button(IDC_MP_SHORTCUT_NET_STATUS, TRANSLATE(IDS_MP_SHORTCUT_NET_STATUS));
- }
- // Initialize combos
- InitPersonaCombo();
- InitSideCombo();
- InitLocaleCombo();
- InitConnectionSpeedCombo();
- UpdateForPersona();
- // Initialize server combos
- const IRCServerList& servers = mWOLSession->GetIRCServerList();
- // If we already have a list of servers then use those. Otherwise
- // request a server list from WOL
- if (servers.size() > 0)
- {
- InitServersCombo(servers);
- }
- else
- {
- RefPtr<SerialWait> serverWait = SerialWait::Create();
- WWASSERT(serverWait.IsValid());
- if (BandwidthCheckerClass::Got_Bandwidth() == 0 && cUserOptions::Get_Bandwidth_Type() == BANDWIDTH_AUTO)
- {
- DetectingBandwidth = true;
- Add_Ref();
- RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
- serverWait->Add(bandwidth_wait);
- }
- // Request server list.
- WWDEBUG_SAY(("DlgWOLSettings: Requesting ServerList\n"));
- RefPtr<WaitCondition> listWait = mWOLSession->GetNewServerList();
- serverWait->Add(listWait);
- RefPtr<WaitCondition> pingWait = PingProfileWait::Create();
- serverWait->Add(pingWait);
- RefPtr<WaitCondition> wait(serverWait);
- DlgWOLWait::DoDialog(IDS_WOL_SERVERLISTFETCH, wait, this);
- }
- MenuDialogClass::On_Init_Dialog();
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::On_Destroy
- *
- * DESCRIPTION
- * Handle dialog shutdown.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::On_Destroy(void)
- {
- ClearPersonaCombo();
- MenuDialogClass::On_Destroy();
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::On_Command
- *
- * DESCRIPTION
- *
- * INPUTS
- * Ctrl - Control command is from.
- * Msg - Command message
- * Param - Command parameter
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::On_Command(int ctrl, int message, DWORD param)
- {
- switch (ctrl)
- {
- case IDOK:
- {
- ComboBoxCtrlClass* connectCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CONNECTION_SPEED_COMBO);
- if (connectCombo && BandwidthCheckerClass::Got_Bandwidth() == 0)
- {
- int sel = connectCombo->Get_Curr_Sel();
- if (sel >= 0)
- {
- BANDWIDTH_TYPE_ENUM bandwidth = min<BANDWIDTH_TYPE_ENUM>((BANDWIDTH_TYPE_ENUM)(sel + BANDWIDTH_FIRST), BANDWIDTH_LAST);
- if (bandwidth == BANDWIDTH_AUTO)
- {
- if (!DetectingBandwidth)
- {
- RefPtr<SerialWait> serverWait = SerialWait::Create();
- WWASSERT(serverWait.IsValid());
- DetectingBandwidth = true;
- Add_Ref();
- RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
- DlgWOLWait::DoDialog(TRANSLATE (IDS_MENU_DETECTING_BANDWIDTH), bandwidth_wait, this);
- WaitingToExitDialog = true;
- break;
- }
- }
- }
- }
- if (SaveSettings())
- {
- End_Dialog();
- }
- }
- return;
- break;
- case IDC_DELETE_ACCOUNT_BUTTON:
- DeleteSelectedPersona();
- break;
- case IDC_NEWPERSONA:
- DlgWebPage::DoDialog("Signup");
- break;
- case IDC_CHECK_BANDWIDTH:
- if (!DetectingBandwidth)
- {
- RefPtr<SerialWait> serverWait = SerialWait::Create();
- WWASSERT(serverWait.IsValid());
- DetectingBandwidth = true;
- Add_Ref();
- RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
- DlgWOLWait::DoDialog(TRANSLATE (IDS_MENU_DETECTING_BANDWIDTH), bandwidth_wait, this);
- }
- break;
- case IDC_AUTOLOGIN_CHECK:
- if (param && mWOLSession->IsAutoLoginAllowed())
- {
- // Get preferred login
- WideStringClass name(64, true);
- name = Get_Dlg_Item_Text(IDC_PERSONA_COMBO);
- // Save preferred login
- StringClass saveName(64, true);
- name.Convert_To(saveName);
- MPSettingsMgrClass::Set_Auto_Login(saveName);
- }
- else
- {
- MPSettingsMgrClass::Set_Auto_Login("");
- }
- break;
- case IDC_MENU_BACK_BUTTON:
- break;
- }
- MenuDialogClass::On_Command(ctrl, message, param);
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::SaveSettings
- *
- * DESCRIPTION
- * Save the users settings.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * True if save successful.
- *
- ******************************************************************************/
- bool DlgWOLSettings::SaveSettings(void)
- {
- WWDEBUG_SAY(("DlgWOLSettings: Saving settings\n"));
- // Save the settings for each login.
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
- if (combo)
- {
- int count = combo->Get_Item_Count();
- for (int index = 0; index < count; ++index)
- {
- LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(index);
- if (profile)
- {
- profile->SaveSettings();
- }
- }
- }
- // Save connection speed
- ComboBoxCtrlClass* connectCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CONNECTION_SPEED_COMBO);
- if (connectCombo)
- {
- int sel = connectCombo->Get_Curr_Sel();
- if (sel >= 0)
- {
- BANDWIDTH_TYPE_ENUM bandwidth = min<BANDWIDTH_TYPE_ENUM>((BANDWIDTH_TYPE_ENUM)(sel + BANDWIDTH_FIRST), BANDWIDTH_LAST);
- cUserOptions::Set_Bandwidth_Type(bandwidth);
- }
- }
- return true;
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::InitPersonaCombo
- *
- * DESCRIPTION
- * Initialize the preferred login combo box with the cached WWOnline
- * accounts.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::InitPersonaCombo(void)
- {
- ClearPersonaCombo();
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
- if (combo)
- {
- // Populate the persona combo box with the list of WWOnline logins.
- const LoginInfoList& logins = LoginInfo::GetList();
- const unsigned int count = logins.size();
- for (unsigned int index = 0; index < count; ++index)
- {
- RefPtr<LoginInfo> login = logins[index];
- WWASSERT(login.IsValid());
- if (login.IsValid())
- {
- const WideStringClass& name = login->GetNickname();
- int item = combo->Add_String(name);
- // Create a profile for each login
- if (item >= 0)
- {
- LoginProfile* profile = LoginProfile::Get(name, true);
- combo->Set_Item_Data(item, (uint32)profile);
- }
- }
- }
- combo->Set_Curr_Sel(0);
- // Select the last login
- WideStringClass loginName(64, true);
- loginName = MPSettingsMgrClass::Get_Last_Login();
- combo->Select_String(loginName);
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::ClearPersonaCombo
- *
- * DESCRIPTION
- * Release the personas.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::ClearPersonaCombo(void)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
- if (combo)
- {
- // Release the login profiles
- const int count = combo->Get_Item_Count();
- for (int index = 0; index < count; ++index)
- {
- LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(index);
- if (profile)
- {
- profile->Release_Ref();
- }
- }
- combo->Reset_Content();
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::DeleteSelectedPersona
- *
- * DESCRIPTION
- * Delete the currently selected persona.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::DeleteSelectedPersona(void)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
- if (combo)
- {
- int sel = combo->Get_Curr_Sel();
- if (sel >= 0)
- {
- const WCHAR* name = combo->Get_Text();
- // Delete this login from our local cache and purge it from disk.
- RefPtr<LoginInfo> login = LoginInfo::Find(name);
- if (login.IsValid())
- {
- login->Forget(true);
- }
- // Release the login profile
- LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(sel);
- if (profile)
- {
- profile->Release_Ref();
- }
- // Delete the persistent profile.
- LoginProfile::Delete(name);
- // Remove the persona from the combo box.
- combo->Delete_String(sel);
- // Refresh the dialog
- UpdateForPersona();
- }
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::UpdateForPersona
- *
- * DESCRIPTION
- * Update the dialog for the selected persona
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::UpdateForPersona(void)
- {
- int sel = -1;
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
- if (combo)
- {
- sel = combo->Get_Curr_Sel();
- if (sel >= 0)
- {
- // Update the dialog with settings from the persona's profile.
- WideStringClass newLogin(64, true);
- combo->Get_String(sel, newLogin);
- LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(sel);
- // Set dialog to reflect the profile settings
- if (profile)
- {
- SetServerCombo(profile->GetPreferredServer());
- SetSideCombo(profile->GetSidePreference());
- SetLocaleCombo(profile->GetLocale());
- }
- else
- {
- SetServerCombo("");
- SetSideCombo(-1);
- SetLocaleCombo(WOL::LOC_UNKNOWN);
- }
- ShowProfileRanking(this, profile);
- // Set the autologin checkbox appropriately for this persona.
- WideStringClass preferred(64, true);
- preferred = MPSettingsMgrClass::Get_Auto_Login();
- bool autoLogin = (mWOLSession->IsAutoLoginAllowed() && (newLogin.Compare_No_Case(preferred) == 0));
- Check_Dlg_Button(IDC_AUTOLOGIN_CHECK, autoLogin);
- // Set the selected login to the persona that is selected.
- StringClass loginName(64, true);
- newLogin.Convert_To(loginName);
- MPSettingsMgrClass::Set_Last_Login(loginName);
- }
- else
- {
- SetServerCombo("");
- SetSideCombo(-1);
- SetLocaleCombo(WOL::LOC_UNKNOWN);
- ShowProfileRanking(this, NULL);
- }
- }
- bool isValid = (sel >= 0);
- Enable_Dlg_Item(IDC_PERSONA_COMBO, isValid);
- Enable_Dlg_Item(IDC_GAMESERVER_COMBO, isValid);
- Enable_Dlg_Item(IDC_CHOOSESIDE_COMBO, isValid);
- Enable_Dlg_Item(IDC_LOCALE_COMBO, isValid);
- Enable_Dlg_Item(IDC_AUTOLOGIN_CHECK, isValid && mWOLSession->IsAutoLoginAllowed());
- Enable_Dlg_Item(IDC_DELETE_ACCOUNT_BUTTON, isValid);
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::InitServersCombo
- *
- * DESCRIPTION
- * Initialize server combo boxes
- *
- * INPUTS
- * Servers - List of servers to populate combo with.
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::InitServersCombo(const IRCServerList& servers)
- {
- ComboBoxCtrlClass* gameCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_GAMESERVER_COMBO);
- if (gameCombo)
- {
- // Remember current chat selection
- WideStringClass gameSelName(0, true);
- LoginProfile* profile = GetLoginProfile();
- if (profile)
- {
- gameSelName = profile->GetPreferredServer();
- }
- int gameSel = -1;
- gameCombo->Reset_Content();
- // convenience reference for list of ping servers
- const PingServerList& pingers = mWOLSession->GetPingServerList();
- int bestTime = INT_MAX;
- int tmpSel = -1;
- // walk the list of servers and add them to the combo box
- const unsigned int serverCount = servers.size();
- for (unsigned int index = 0; index < serverCount; ++index)
- {
- const RefPtr<IRCServerData>& server = servers[index];
- // Filter out servers that do not have a set of supported languages.
- if (server->HasLanguageCode())
- {
- WideStringClass serverName(0, true);
- serverName = server->GetName();
- int pos = gameCombo->Add_String(serverName);
- // Now, figure out which one to pick
- // they haven't picked a preferred server
- if (gameSelName.Is_Empty())
- {
- // lets pick a default server for them!
- if (server->MatchesLanguageCode())
- {
- float serverLong = server->GetLongitude();
- float serverLat = server->GetLattitude();
- // Find the ping server with the best time that matches this server's lat/long
- const unsigned int pingersCount = pingers.size();
- for (unsigned int pingindex = 0; pingindex < pingersCount; ++pingindex)
- {
- const RefPtr<PingServerData>& thisPing = pingers[pingindex];
- float pingLong = thisPing->GetLongitude();
- float pingLat = thisPing->GetLattitude();
- // make sure the ping server is associated with the chat server
- if (serverLong == pingLong && serverLat == pingLat)
- {
- int pingTime = thisPing->GetPingTime();
- // sanity check
- if (pingTime == -1)
- {
- pingTime = INT_MAX;
- }
- // here's our main test! Find the best ping time
- if (pingTime < bestTime)
- {
- bestTime = pingTime;
- tmpSel = pos;
- }
- }
- } // end for each ping server
- }
- }
- // If this is their preferred server
- else if ((gameSelName.Compare_No_Case(serverName) == 0) && (gameSel == -1))
- {
- gameSel = pos; // they picked one, and this is it!
- gameCombo->Set_Curr_Sel(pos);
- if (profile)
- {
- profile->SetPreferredServer(server->GetName());
- }
- }
- } // if server has a langcode - sanity check
- }
- if ((gameSel == -1) && (tmpSel != -1))
- {
- gameSel = tmpSel;
- gameCombo->Set_Curr_Sel(tmpSel);
- }
- } // if valid gameCombo box
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::SetServerCombo
- *
- * DESCRIPTION
- * Set the server combo to the specified server.
- *
- * INPUTS
- * Name - Server to set server combo to.
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::SetServerCombo(const char* serverName)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_GAMESERVER_COMBO);
- if (combo)
- {
- WWDEBUG_SAY(("ServerCombo = %s\n", serverName));
- WideStringClass name(64, true);
- name = serverName;
- int sel = combo->Select_String(name);
- if (sel == -1)
- {
- RefPtr<IRCServerData> defaultServer = WOLLogonMgr::GetDefaultServer();
- if (defaultServer.IsValid())
- {
- name = defaultServer->GetName();
- combo->Select_String(name);
- }
- else
- {
- combo->Set_Curr_Sel(0);
- }
- }
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::InitSideCombo
- *
- * DESCRIPTION
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::InitSideCombo(void)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CHOOSESIDE_COMBO);
- if (combo)
- {
- //(gth) Renegade day 120 Patch: re-translate these strings each time!
- struct {const wchar_t* TeamName; int TeamID;} _teams[] =
- {
- {TRANSLATE (IDS_MENU_RANDOM), -1},
- {TRANSLATE (IDS_MENU_TEXT933), 1},
- {TRANSLATE (IDS_MENU_TEXT934), 0},
- {NULL, -1},
- };
- int index = 0;
- while (_teams[index].TeamName != NULL)
- {
- int item = combo->Add_String(_teams[index].TeamName);
- if (item >= 0)
- {
- combo->Set_Item_Data(item, (uint32)_teams[index].TeamID);
- }
- ++index;
- }
- }
- // Selected current logins preference
- int side = -1;
- LoginProfile* profile = GetLoginProfile();
- if (profile)
- {
- side = profile->GetSidePreference();
- }
- SetSideCombo(side);
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::SetSideCombo
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::SetSideCombo(int side)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CHOOSESIDE_COMBO);
- if (combo)
- {
- const int count = combo->Get_Item_Count();
- for (int index = 0; index < count; ++index)
- {
- if (combo->Get_Item_Data(index) == (uint32)side)
- {
- combo->Set_Curr_Sel(index);
- break;
- }
- }
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::InitLocaleCombo
- *
- * DESCRIPTION
- * Update the locale combo box with the selectable WWOnline locales.
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::InitLocaleCombo(void)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_LOCALE_COMBO);
- if (combo)
- {
- combo->Reset_Content();
- std::vector<WideStringClass> localeNames;
- mWOLSession->GetLocaleStrings(localeNames);
- const unsigned int localeCount = localeNames.size();
- for (unsigned int index = 0; index < localeCount; ++index)
- {
- WideStringClass& locale = localeNames[index];
- combo->Add_String(locale);
- }
- int locale = WOL::LOC_UNKNOWN;
- LoginProfile* profile = GetLoginProfile();
- if (profile)
- {
- locale = profile->GetLocale();
- }
- combo->Set_Curr_Sel(locale);
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::SetLocaleCombo
- *
- * DESCRIPTION
- *
- * INPUTS
- * Name - Persona to set locale for.
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::SetLocaleCombo(WOL::Locale locale)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_LOCALE_COMBO);
- if (combo)
- {
- WWDEBUG_SAY(("LocaleCombo = %ld\n", locale));
- combo->Set_Curr_Sel((int)locale);
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::InitConnectionSpeedCombo
- *
- * DESCRIPTION
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::InitConnectionSpeedCombo(void)
- {
- // Configure the connection type combobox
- ComboBoxCtrlClass* connectCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CONNECTION_SPEED_COMBO);
- if (connectCombo)
- {
- connectCombo->Reset_Content();
- connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_288));
- connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_336));
- connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_56));
- connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_ISDN));
- connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_CABLE));
- connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_T1));
- WideStringClass auto_set_str(256, true);
- if (BandwidthCheckerClass::Get_Reported_Upstream_Bandwidth())
- {
- auto_set_str.Format(TRANSLATE (IDS_MENU_AUTO_FORMAT), BandwidthCheckerClass::Get_Bandwidth_As_String());
- }
- else
- {
- auto_set_str.Format(TRANSLATE (IDS_MENU_AUTO));
- }
- connectCombo->Add_String(auto_set_str);
- // Set the current selection
- connectCombo->Set_Curr_Sel(cUserOptions::Get_Bandwidth_Type() - BANDWIDTH_FIRST);
- connectCombo->Set_Dirty(true);
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::On_ComboBoxCtrl_Sel_Change
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::On_ComboBoxCtrl_Sel_Change(ComboBoxCtrlClass* combo, int ctrl,
- int oldSel, int newSel)
- {
- switch (ctrl)
- {
- case IDC_PERSONA_COMBO:
- UpdateForPersona();
- break;
- case IDC_GAMESERVER_COMBO:
- {
- LoginProfile* profile = GetLoginProfile();
- if (profile)
- {
- // Save selected game server
- WideStringClass name(64, true);
- combo->Get_String(newSel, name);
- StringClass saveName(64, true);
- name.Convert_To(saveName);
- profile->SetPreferredServer(saveName);
- }
- }
- break;
- case IDC_CHOOSESIDE_COMBO:
- {
- LoginProfile* profile = GetLoginProfile();
- if (profile)
- {
- int side = combo->Get_Item_Data(newSel);
- profile->SetSidePreference(side);
- }
- }
- break;
- case IDC_LOCALE_COMBO:
- {
- LoginProfile* profile = GetLoginProfile();
- if (profile)
- {
- profile->SetLocale((WOL::Locale)newSel);
- }
- }
- break;
- default:
- break;
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::HandleNotification(DlgWOLWaitEvent)
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void DlgWOLSettings::HandleNotification(DlgWOLWaitEvent& event)
- {
- if (WaitCondition::ConditionMet == event.Result())
- {
- if (DetectingBandwidth)
- {
- DetectingBandwidth = false;
- cUserOptions::Set_Bandwidth_Type(BANDWIDTH_AUTO);
- // Re-init the connection speed combo.
- InitConnectionSpeedCombo();
- Release_Ref();
- if (WaitingToExitDialog)
- {
- if (SaveSettings())
- {
- End_Dialog();
- return;
- }
- }
- }
- // Check if we got the server list.
- const IRCServerList& servers = mWOLSession->GetIRCServerList();
- if (servers.size())
- {
- InitServersCombo(servers);
- }
- }
- else if (DetectingBandwidth == false)
- {
- Enable_Dlg_Item(IDC_GAMESERVER_COMBO, false);
- }
- }
- /******************************************************************************
- *
- * NAME
- * DlgWOLSettings::GetLoginProfile
- *
- * DESCRIPTION
- *
- * INPUTS
- * NONE
- *
- * RESULT
- *
- ******************************************************************************/
- LoginProfile* DlgWOLSettings::GetLoginProfile(void)
- {
- ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
- if (combo)
- {
- int sel = combo->Get_Curr_Sel();
- if (sel >= 0)
- {
- return (LoginProfile*)combo->Get_Item_Data(sel);
- }
- }
- return NULL;
- }
|