Login.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <ScpMain.h>
  5. #include <Common.h>
  6. #include <TextsWin.h>
  7. #include <VCLCommon.h>
  8. #include "Login.h"
  9. #include "WinInterface.h"
  10. #include "GUITools.h"
  11. #include "Tools.h"
  12. #include "CustomWinConfiguration.h"
  13. //---------------------------------------------------------------------
  14. #pragma link "ComboEdit"
  15. #pragma link "LogSettings"
  16. #pragma link "GeneralSettings"
  17. #pragma link "UpDownEdit"
  18. #pragma link "XPGroupBox"
  19. #pragma link "PasswordEdit"
  20. #pragma resource "*.dfm"
  21. //---------------------------------------------------------------------------
  22. bool __fastcall DoLoginDialog(TStoredSessionList *SessionList,
  23. TSessionData * Data, int Options)
  24. {
  25. assert(Data);
  26. TLoginDialog *LoginDialog = new TLoginDialog(Application);
  27. bool Result;
  28. try
  29. {
  30. LoginDialog->StoredSessions = SessionList;
  31. LoginDialog->SessionData = Data;
  32. LoginDialog->Options = Options;
  33. Result = LoginDialog->Execute();
  34. if (Result)
  35. {
  36. Data->Assign(LoginDialog->SessionData);
  37. };
  38. }
  39. __finally
  40. {
  41. delete LoginDialog;
  42. }
  43. return Result;
  44. }
  45. //---------------------------------------------------------------------
  46. __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
  47. : TForm(AOwner)
  48. {
  49. FSessionData = new TSessionData("");
  50. NoUpdate = 0;
  51. FLanguagesPopupMenu = NULL;
  52. FInitialized = false;
  53. FSavedTab = NULL;
  54. FSavedSession = -1;
  55. FOptions = loStartup;
  56. FLocaleChanging = false;
  57. InitControls();
  58. }
  59. //---------------------------------------------------------------------
  60. __fastcall TLoginDialog::~TLoginDialog()
  61. {
  62. LoggingFrame->OnGetDefaultLogFileName = NULL;
  63. // SelectItem event is called after destructor! Why?
  64. SessionListView->Selected = NULL;
  65. delete FSystemSettings;
  66. FSystemSettings = NULL;
  67. delete FSessionData;
  68. delete FLanguagesPopupMenu;
  69. }
  70. //---------------------------------------------------------------------
  71. void __fastcall TLoginDialog::ShowTabs(bool Show)
  72. {
  73. for (int Index = 0; Index < PageControl->PageCount; Index++)
  74. {
  75. PageControl->Pages[Index]->TabVisible = Show;
  76. }
  77. // change form height by height of hidden tabs
  78. ClientHeight += (Show ? 1 : -1) * 50;
  79. }
  80. //---------------------------------------------------------------------
  81. void __fastcall TLoginDialog::InitControls()
  82. {
  83. InitializeBugsCombo(BugIgnore1Combo);
  84. InitializeBugsCombo(BugPlainPW1Combo);
  85. InitializeBugsCombo(BugRSA1Combo);
  86. InitializeBugsCombo(BugHMAC2Combo);
  87. InitializeBugsCombo(BugDeriveKey2Combo);
  88. InitializeBugsCombo(BugRSAPad2Combo);
  89. InitializeBugsCombo(BugDHGEx2Combo);
  90. InitializeBugsCombo(BugPKSessID2Combo);
  91. }
  92. //---------------------------------------------------------------------
  93. void __fastcall TLoginDialog::Init()
  94. {
  95. LoggingFrame->OnGetDefaultLogFileName = LoggingGetDefaultLogFileName;
  96. UseSystemSettings(this, &FSystemSettings);
  97. Caption = FORMAT("%s %s", (AppName, Caption));
  98. InitControls();
  99. PrepareNavigationTree(SimpleNavigationTree);
  100. PrepareNavigationTree(AdvancedNavigationTree);
  101. if ((Options & loLocalDirectory) == 0)
  102. {
  103. LocalDirectoryLabel->Visible = false;
  104. LocalDirectoryEdit->Visible = false;
  105. LocalDirectoryDescLabel->Visible = false;
  106. DirectoriesGroup->Height = RemoteDirectoryEdit->Top + RemoteDirectoryEdit->Height + 12;
  107. }
  108. ShowTabs(false);
  109. if (StoredSessions && StoredSessions->Count &&
  110. (FSessionData->Name == StoredSessions->DefaultSettings->Name))
  111. {
  112. ChangePage(SessionListSheet);
  113. SessionListView->SetFocus();
  114. }
  115. else
  116. {
  117. ChangePage(BasicSheet);
  118. HostNameEdit->SetFocus();
  119. }
  120. UpdateControls();
  121. }
  122. //---------------------------------------------------------------------
  123. void __fastcall TLoginDialog::InitializeBugsCombo(TComboBox * BugsCombo)
  124. {
  125. int PrevIndex = BugsCombo->ItemIndex;
  126. BugsCombo->Clear();
  127. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_AUTO));
  128. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_OFF));
  129. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_ON));
  130. assert(PrevIndex < BugsCombo->Items->Count);
  131. BugsCombo->ItemIndex = PrevIndex;
  132. }
  133. //---------------------------------------------------------------------
  134. void __fastcall TLoginDialog::LoadSessions()
  135. {
  136. SessionListView->Items->BeginUpdate();
  137. try
  138. {
  139. SessionListView->Items->Clear();
  140. if (StoredSessions)
  141. {
  142. for (int Index = 0; Index < StoredSessions->Count; Index++)
  143. {
  144. TListItem *Item;
  145. Item = SessionListView->Items->Add();
  146. LoadSessionItem(Item);
  147. }
  148. }
  149. }
  150. __finally
  151. {
  152. SessionListView->Items->EndUpdate();
  153. }
  154. SelectedSession = StoredSessions->Count > 0 ?
  155. dynamic_cast<TSessionData*>(StoredSessions->AtObject(0)) : NULL;
  156. UpdateControls();
  157. }
  158. //---------------------------------------------------------------------------
  159. void __fastcall TLoginDialog::Default()
  160. {
  161. if (StoredSessions)
  162. {
  163. FSessionData->Assign(StoredSessions->DefaultSettings);
  164. }
  165. else
  166. {
  167. FSessionData->Default();
  168. }
  169. LoadSession(FSessionData);
  170. FCurrentSessionName = "";
  171. }
  172. //---------------------------------------------------------------------
  173. void __fastcall TLoginDialog::LoadSession(TSessionData * aSessionData)
  174. {
  175. NoUpdate++;
  176. try
  177. {
  178. // Basic tab
  179. UserNameEdit->Text = aSessionData->UserName;
  180. PortNumberEdit->AsInteger = aSessionData->PortNumber;
  181. HostNameEdit->Text = aSessionData->HostName;
  182. PasswordEdit->Text = aSessionData->Password;
  183. PrivateKeyEdit->Text = aSessionData->PublicKeyFile;
  184. switch (aSessionData->FSProtocol) {
  185. case fsSCPonly: SCPonlyButton->Checked = true; break;
  186. case fsSFTP: SFTPButton->Checked = true; break;
  187. case fsSFTPonly:
  188. default: SFTPonlyButton->Checked = true; break;
  189. }
  190. // Directories tab
  191. LocalDirectoryEdit->Text = aSessionData->LocalDirectory;
  192. RemoteDirectoryEdit->Text = aSessionData->RemoteDirectory;
  193. UpdateDirectoriesCheck->Checked = aSessionData->UpdateDirectories;
  194. CacheDirectoriesCheck->Checked = aSessionData->CacheDirectories;
  195. CacheDirectoryChangesCheck->Checked = aSessionData->CacheDirectoryChanges;
  196. PreserveDirectoryChangesCheck->Checked = aSessionData->PreserveDirectoryChanges;
  197. ResolveSymlinksCheck->Checked = aSessionData->ResolveSymlinks;
  198. // Environment tab
  199. ConsiderDSTOnCheck->Checked = aSessionData->ConsiderDST;
  200. ConsiderDSTOffCheck->Checked = !aSessionData->ConsiderDST;
  201. if (aSessionData->EOLType == eolLF)
  202. {
  203. EOLTypeLFButton->Checked = true;
  204. }
  205. else
  206. {
  207. EOLTypeCRLFButton->Checked = true;
  208. }
  209. // Authentication tab
  210. AuthTISCheck->Checked = aSessionData->AuthTIS;
  211. AuthKICheck->Checked = aSessionData->AuthKI;
  212. AuthKIPasswordCheck->Checked = aSessionData->AuthKIPassword;
  213. AuthGSSAPICheck->Checked = aSessionData->AuthGSSAPI;
  214. AgentFwdCheck->Checked = aSessionData->AgentFwd;
  215. // SSH tab
  216. Ssh2LegacyDESCheck->Checked = aSessionData->Ssh2DES;
  217. CompressionCheck->Checked = aSessionData->Compression;
  218. switch (aSessionData->SshProt) {
  219. case ssh1only: SshProt1onlyButton->Checked = true; break;
  220. case ssh1: SshProt1Button->Checked = true; break;
  221. case ssh2: SshProt2Button->Checked = true; break;
  222. case ssh2only: SshProt2onlyButton->Checked = true; break;
  223. }
  224. CipherListBox->Items->Clear();
  225. assert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_DES);
  226. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  227. {
  228. CipherListBox->Items->AddObject(
  229. LoadStr(CIPHER_NAME_WARN+aSessionData->Cipher[Index]),
  230. (TObject*)aSessionData->Cipher[Index]);
  231. }
  232. // Connection tab
  233. switch (aSessionData->PingType)
  234. {
  235. case ptNullPacket:
  236. PingNullPacketButton->Checked = true;
  237. break;
  238. case ptDummyCommand:
  239. PingDummyCommandButton->Checked = true;
  240. break;
  241. default:
  242. PingOffButton->Checked = true;
  243. break;
  244. }
  245. PingIntervalSecEdit->AsInteger = aSessionData->PingInterval;
  246. TimeoutEdit->AsInteger = aSessionData->Timeout;
  247. // Shell tab
  248. if (aSessionData->DefaultShell)
  249. DefaultShellButton->Checked = true;
  250. else
  251. ShellEnterButton->Checked = true;
  252. ShellEdit->Text = aSessionData->Shell;
  253. if (aSessionData->DetectReturnVar)
  254. ReturnVarAutodetectButton->Checked = true;
  255. else
  256. ReturnVarEnterButton->Checked = true;
  257. ReturnVarEdit->Text = aSessionData->ReturnVar;
  258. LookupUserGroupsCheck->Checked = aSessionData->LookupUserGroups;
  259. ClearAliasesCheck->Checked = aSessionData->ClearAliases;
  260. IgnoreLsWarningsCheck->Checked = aSessionData->IgnoreLsWarnings;
  261. Scp1CompatibilityCheck->Checked = aSessionData->Scp1Compatibility;
  262. UnsetNationalVarsCheck->Checked = aSessionData->UnsetNationalVars;
  263. AliasGroupListCheck->Checked = aSessionData->AliasGroupList;
  264. int TimeDifferenceMin = DateTimeToTimeStamp(aSessionData->TimeDifference).Time / 60000;
  265. if (double(aSessionData->TimeDifference) < 0)
  266. {
  267. TimeDifferenceMin = -TimeDifferenceMin;
  268. }
  269. TimeDifferenceEdit->AsInteger = TimeDifferenceMin / 60;
  270. TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % 60;
  271. // Proxy tab
  272. switch (aSessionData->ProxyMethod) {
  273. case pmHTTP: ProxyHTTPButton->Checked = true; break;
  274. case pmSocks4: ProxySocks4Button->Checked = true; break;
  275. case pmSocks5: ProxySocks5Button->Checked = true; break;
  276. case pmTelnet: ProxyTelnetButton->Checked = true; break;
  277. default: ProxyNoneButton->Checked = true; break;
  278. }
  279. ProxyHostEdit->Text = aSessionData->ProxyHost;
  280. ProxyPortEdit->AsInteger = aSessionData->ProxyPort;
  281. ProxyUsernameEdit->Text = aSessionData->ProxyUsername;
  282. ProxyPasswordEdit->Text = aSessionData->ProxyPassword;
  283. ProxyTelnetCommandEdit->Text = aSessionData->ProxyTelnetCommand;
  284. ProxyLocalhostCheck->Checked = aSessionData->ProxyLocalhost;
  285. switch (aSessionData->ProxyDNS) {
  286. case asOn: ProxyDNSOnButton->Checked = true; break;
  287. case asOff: ProxyDNSOffButton->Checked = true; break;
  288. default: ProxyDNSAutoButton->Checked = true; break;
  289. }
  290. // Bugs tab
  291. #define LOAD_BUG_COMBO(BUG) \
  292. Bug ## BUG ## Combo->ItemIndex = 2 - aSessionData->Bug[sb ## BUG]; \
  293. if (Bug ## BUG ## Combo->ItemIndex < 0) Bug ## BUG ## Combo->ItemIndex = 0
  294. LOAD_BUG_COMBO(Ignore1);
  295. LOAD_BUG_COMBO(PlainPW1);
  296. LOAD_BUG_COMBO(RSA1);
  297. LOAD_BUG_COMBO(HMAC2);
  298. LOAD_BUG_COMBO(DeriveKey2);
  299. LOAD_BUG_COMBO(RSAPad2);
  300. LOAD_BUG_COMBO(DHGEx2);
  301. LOAD_BUG_COMBO(PKSessID2);
  302. #undef LOAD_BUG_COMBO
  303. }
  304. __finally
  305. {
  306. NoUpdate--;
  307. UpdateControls();
  308. }
  309. FCurrentSessionName = aSessionData->Name;
  310. }
  311. //---------------------------------------------------------------------
  312. void __fastcall TLoginDialog::SaveSession(TSessionData * aSessionData)
  313. {
  314. aSessionData->Name = FCurrentSessionName;
  315. // Basic tab
  316. aSessionData->UserName = UserNameEdit->Text;
  317. aSessionData->PortNumber = PortNumberEdit->AsInteger;
  318. // must be loaded after UserName, because HostName may be in format user@host
  319. aSessionData->HostName = HostNameEdit->Text;
  320. aSessionData->Password = PasswordEdit->Text;
  321. aSessionData->PublicKeyFile = PrivateKeyEdit->Text;
  322. if (SCPonlyButton->Checked) aSessionData->FSProtocol = fsSCPonly;
  323. else
  324. if (SFTPButton->Checked) aSessionData->FSProtocol = fsSFTP;
  325. else aSessionData->FSProtocol = fsSFTPonly;
  326. // SSH tab
  327. aSessionData->Compression = CompressionCheck->Checked;
  328. aSessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  329. if (SshProt1onlyButton->Checked) aSessionData->SshProt = ssh1only;
  330. else
  331. if (SshProt1Button->Checked) aSessionData->SshProt = ssh1;
  332. else
  333. if (SshProt2Button->Checked) aSessionData->SshProt = ssh2;
  334. else aSessionData->SshProt = ssh2only;
  335. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  336. {
  337. aSessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  338. }
  339. // Authentication tab
  340. aSessionData->AuthTIS = AuthTISCheck->Checked;
  341. aSessionData->AuthKI = AuthKICheck->Checked;
  342. aSessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  343. aSessionData->AuthGSSAPI = AuthGSSAPICheck->Checked;
  344. aSessionData->AgentFwd = AgentFwdCheck->Checked;
  345. // Connection tab
  346. if (PingNullPacketButton->Checked)
  347. {
  348. aSessionData->PingType = ptNullPacket;
  349. }
  350. else if (PingDummyCommandButton->Checked)
  351. {
  352. aSessionData->PingType = ptDummyCommand;
  353. }
  354. else
  355. {
  356. aSessionData->PingType = ptOff;
  357. }
  358. aSessionData->PingInterval = PingIntervalSecEdit->AsInteger;
  359. aSessionData->Timeout = TimeoutEdit->AsInteger;
  360. // Directories tab
  361. aSessionData->LocalDirectory = LocalDirectoryEdit->Text;
  362. aSessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  363. aSessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  364. aSessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  365. aSessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  366. aSessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  367. aSessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  368. // Environment tab
  369. aSessionData->ConsiderDST = ConsiderDSTOnCheck->Checked;
  370. if (EOLTypeLFButton->Checked) aSessionData->EOLType = eolLF;
  371. else aSessionData->EOLType = eolCRLF;
  372. // Shell tab
  373. aSessionData->DefaultShell = DefaultShellButton->Checked;
  374. if (ShellEnterButton->Checked)
  375. aSessionData->Shell = ShellEdit->Text;
  376. aSessionData->DetectReturnVar = ReturnVarAutodetectButton->Checked;
  377. if (ReturnVarEnterButton->Checked)
  378. aSessionData->ReturnVar = ReturnVarEdit->Text;
  379. aSessionData->LookupUserGroups = LookupUserGroupsCheck->Checked;
  380. aSessionData->ClearAliases = ClearAliasesCheck->Checked;
  381. aSessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  382. aSessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  383. aSessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  384. aSessionData->AliasGroupList = AliasGroupListCheck->Checked;
  385. aSessionData->TimeDifference =
  386. (double(TimeDifferenceEdit->AsInteger) / 24) +
  387. (double(TimeDifferenceMinutesEdit->AsInteger) / 24 / 60);
  388. // Proxy tab
  389. if (ProxyHTTPButton->Checked) aSessionData->ProxyMethod = pmHTTP;
  390. else
  391. if (ProxySocks4Button->Checked) aSessionData->ProxyMethod = pmSocks4;
  392. else
  393. if (ProxySocks5Button->Checked) aSessionData->ProxyMethod = pmSocks5;
  394. else
  395. if (ProxyTelnetButton->Checked) aSessionData->ProxyMethod = pmTelnet;
  396. else aSessionData->ProxyMethod = pmNone;
  397. aSessionData->ProxyHost = ProxyHostEdit->Text;
  398. aSessionData->ProxyPort = ProxyPortEdit->AsInteger;
  399. aSessionData->ProxyUsername = ProxyUsernameEdit->Text;
  400. aSessionData->ProxyPassword = ProxyPasswordEdit->Text;
  401. aSessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  402. aSessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  403. if (ProxyDNSOnButton->Checked) aSessionData->ProxyDNS = asOn;
  404. else
  405. if (ProxyDNSOffButton->Checked) aSessionData->ProxyDNS = asOff;
  406. else aSessionData->ProxyDNS = asAuto;
  407. // Bugs tab
  408. #define SAVE_BUG_COMBO(BUG) aSessionData->Bug[sb ## BUG] = (TAutoSwitch)(2 - Bug ## BUG ## Combo->ItemIndex);
  409. SAVE_BUG_COMBO(Ignore1);
  410. SAVE_BUG_COMBO(PlainPW1);
  411. SAVE_BUG_COMBO(RSA1);
  412. SAVE_BUG_COMBO(HMAC2);
  413. SAVE_BUG_COMBO(DeriveKey2);
  414. SAVE_BUG_COMBO(RSAPad2);
  415. SAVE_BUG_COMBO(DHGEx2);
  416. SAVE_BUG_COMBO(PKSessID2);
  417. #undef SAVE_BUG_COMBO
  418. }
  419. //---------------------------------------------------------------------
  420. void __fastcall TLoginDialog::UpdateControls()
  421. {
  422. if (Visible)
  423. {
  424. NoUpdate++;
  425. try
  426. {
  427. #define SHOW_NAVIGATION(TREE, SHOW) if ((TREE)->Visible != (SHOW)) { \
  428. (TREE)->Visible = (SHOW); PageControlChange(PageControl); }
  429. SHOW_NAVIGATION(SimpleNavigationTree, !ShowAdvancedLoginOptionsCheck->Checked);
  430. SHOW_NAVIGATION(AdvancedNavigationTree, ShowAdvancedLoginOptionsCheck->Checked);
  431. #undef SHOW_NAVIGATION
  432. EnableControl(ShellIconsButton, SessionListView->Selected);
  433. if (!PrivateKeyEdit->Text.IsEmpty())
  434. {
  435. PasswordEdit->Clear();
  436. }
  437. EnableControl(PasswordEdit, PrivateKeyEdit->Text.IsEmpty());
  438. if (!PasswordEdit->Text.IsEmpty()) PrivateKeyEdit->Clear();
  439. EnableControl(PrivateKeyEdit, PasswordEdit->Text.IsEmpty());
  440. EnableControl(PingIntervalSecEdit, !PingOffButton->Checked);
  441. EnableControl(SessionListView, SessionListView->Items->Count);
  442. AdjustListColumnsWidth(SessionListView);
  443. SessionListView->Columns->Items[0]->Width -= 2;
  444. EnableControl(AuthTISCheck, !SshProt2onlyButton->Checked);
  445. EnableControl(AuthKICheck, !SshProt1onlyButton->Checked);
  446. EnableControl(AuthKIPasswordCheck,
  447. AuthTISCheck->Checked || AuthKICheck->Checked);
  448. EnableControl(AuthGSSAPICheck, !SshProt1onlyButton->Checked);
  449. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  450. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  451. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  452. EnableControl(Ssh2LegacyDESCheck, !SshProt1onlyButton->Checked);
  453. EnableControl(BugIgnore1Combo, !SshProt2onlyButton->Checked);
  454. EnableControl(BugPlainPW1Combo, !SshProt2onlyButton->Checked);
  455. EnableControl(BugRSA1Combo, !SshProt2onlyButton->Checked);
  456. EnableControl(BugHMAC2Combo, !SshProt1onlyButton->Checked);
  457. EnableControl(BugDeriveKey2Combo, !SshProt1onlyButton->Checked);
  458. EnableControl(BugRSAPad2Combo, !SshProt1onlyButton->Checked);
  459. EnableControl(BugDHGEx2Combo, !SshProt1onlyButton->Checked);
  460. EnableControl(ShellEdit, ShellEnterButton->Checked);
  461. EnableControl(ReturnVarEdit, ReturnVarEnterButton->Checked);
  462. EnableControl(ProxyHostEdit, !ProxyNoneButton->Checked);
  463. EnableControl(ProxyPortEdit, !ProxyNoneButton->Checked);
  464. EnableControl(ProxyUsernameEdit, !ProxyNoneButton->Checked);
  465. EnableControl(ProxyPasswordEdit, !ProxyNoneButton->Checked);
  466. EnableControl(ProxySettingsGroup, !ProxyNoneButton->Checked);
  467. EnableControl(ProxyTelnetCommandEdit, ProxyTelnetButton->Checked);
  468. EnableControl(PreserveDirectoryChangesCheck, CacheDirectoryChangesCheck->Checked);
  469. AboutButton->Visible = (Options & loAbout);
  470. LanguagesButton->Visible = (Options & loLanguage);
  471. ShellIconsButton->Visible = (Options & loTools);
  472. ToolsMenuButton->Visible = (Options & loTools);
  473. LoggingFrame->EnableLogWindow = (Options & loLogWindow);
  474. }
  475. __finally
  476. {
  477. NoUpdate--;
  478. }
  479. }
  480. }
  481. //---------------------------------------------------------------------------
  482. void __fastcall TLoginDialog::DataChange(TObject * /*Sender*/)
  483. {
  484. if (!NoUpdate) UpdateControls();
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TLoginDialog::PrepareNavigationTree(TTreeView * Tree)
  488. {
  489. Tree->FullExpand();
  490. int i = 0;
  491. while (i < Tree->Items->Count)
  492. {
  493. if ((Tree->Items->Item[i]->StateIndex > 0) &&
  494. ((Options & Tree->Items->Item[i]->StateIndex) == 0))
  495. {
  496. Tree->Items->Delete(Tree->Items->Item[i]);
  497. }
  498. else
  499. {
  500. for (int pi = 0; pi < PageControl->PageCount; pi++)
  501. {
  502. if (PageControl->Pages[pi]->Tag == Tree->Items->Item[i]->SelectedIndex)
  503. {
  504. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  505. break;
  506. }
  507. }
  508. i++;
  509. }
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TLoginDialog::FormShow(TObject * /*Sender*/)
  514. {
  515. if (!FInitialized)
  516. {
  517. FInitialized = true;
  518. Init();
  519. TSessionData * Data = GetSessionData();
  520. if (Data == FSessionData)
  521. {
  522. LoadSession(Data);
  523. }
  524. else
  525. {
  526. Default();
  527. }
  528. }
  529. if (FLocaleChanging)
  530. {
  531. Init();
  532. LoadSession(FSessionData);
  533. ChangePage(FSavedTab);
  534. SessionListView->ItemIndex = FSavedSession;
  535. LoadConfiguration();
  536. }
  537. }
  538. //---------------------------------------------------------------------------
  539. void __fastcall TLoginDialog::SessionListViewSelectItem(TObject * /*Sender*/,
  540. TListItem * /*Item*/, bool /*Selected*/)
  541. {
  542. UpdateControls();
  543. }
  544. //---------------------------------------------------------------------------
  545. void __fastcall TLoginDialog::StoreSessions()
  546. {
  547. StoredSessions->Save();
  548. }
  549. //---------------------------------------------------------------------------
  550. void __fastcall TLoginDialog::SetSessionData(TSessionData * value)
  551. {
  552. FSessionData->Assign(value);
  553. FSessionData->Special = false;
  554. LoadSession(FSessionData);
  555. }
  556. //---------------------------------------------------------------------------
  557. TSessionData * __fastcall TLoginDialog::GetSessionData()
  558. {
  559. if (PageControl->ActivePage == SessionListSheet)
  560. {
  561. return SelectedSession;
  562. }
  563. else
  564. {
  565. SaveSession(FSessionData);
  566. return FSessionData;
  567. }
  568. }
  569. //---------------------------------------------------------------------------
  570. void __fastcall TLoginDialog::SetStoredSessions(TStoredSessionList * value)
  571. {
  572. if (FStoredSessions != value)
  573. {
  574. FStoredSessions = value;
  575. LoadSessions();
  576. }
  577. }
  578. //---------------------------------------------------------------------------
  579. void __fastcall TLoginDialog::LoadSessionItem(TListItem * Item)
  580. {
  581. Item->Data = StoredSessions->AtObject(Item->Index);
  582. Item->Caption = ((TSessionData*)Item->Data)->Name;
  583. }
  584. //---------------------------------------------------------------------------
  585. void __fastcall TLoginDialog::SessionListViewDblClick(TObject * /*Sender*/)
  586. {
  587. if (SelectedSession)
  588. {
  589. if (SelectedSession->CanLogin) ModalResult = mrOk;
  590. else
  591. {
  592. SessionData = SelectedSession;
  593. ChangePage(BasicSheet);
  594. if (HostNameEdit->Text.IsEmpty()) HostNameEdit->SetFocus();
  595. else
  596. if (UserNameEdit->Text.IsEmpty()) UserNameEdit->SetFocus();
  597. }
  598. }
  599. }
  600. //---------------------------------------------------------------------------
  601. void __fastcall TLoginDialog::SetSelectedSession(TSessionData * value)
  602. {
  603. if (value)
  604. {
  605. int Index = StoredSessions->IndexOf(value);
  606. if (Index >= 0)
  607. {
  608. TListItem *Item = SessionListView->Items->Item[Index];
  609. Item->Focused = true;
  610. Item->Selected = true;
  611. Item->MakeVisible(false);
  612. }
  613. }
  614. else
  615. {
  616. SessionListView->Selected = NULL;
  617. }
  618. }
  619. //---------------------------------------------------------------------------
  620. TSessionData * __fastcall TLoginDialog::GetSelectedSession()
  621. {
  622. if (SessionListView->Selected)
  623. return (TSessionData *)SessionListView->Selected->Data;
  624. else
  625. return NULL;
  626. }
  627. //---------------------------------------------------------------------------
  628. void __fastcall TLoginDialog::SessionListViewInfoTip(TObject * /*Sender*/,
  629. TListItem * Item, AnsiString & InfoTip)
  630. {
  631. InfoTip = ((TSessionData*)Item->Data)->InfoTip;
  632. }
  633. //---------------------------------------------------------------------------
  634. void __fastcall TLoginDialog::SessionListViewKeyDown(TObject * /*Sender*/,
  635. WORD &Key, TShiftState /*Shift*/)
  636. {
  637. if (Key == VK_DELETE) DeleteSessionAction->Execute();
  638. }
  639. //---------------------------------------------------------------------------
  640. void __fastcall TLoginDialog::LoadSessionActionExecute(TObject * /*Sender*/)
  641. {
  642. if (SelectedSession)
  643. {
  644. SessionData = SelectedSession;
  645. ChangePage(BasicSheet);
  646. }
  647. }
  648. //---------------------------------------------------------------------------
  649. void __fastcall TLoginDialog::SaveSessionActionExecute(TObject * /*Sender*/)
  650. {
  651. AnsiString SessionName;
  652. SaveSession(FSessionData);
  653. SessionName = DoSaveSessionDialog(StoredSessions, FSessionData->SessionName);
  654. if (!SessionName.IsEmpty())
  655. {
  656. TListItem * Item;
  657. TSessionData *NewSession =
  658. StoredSessions->NewSession(SessionName, FSessionData);
  659. StoredSessions->Save();
  660. // by now list must contais same number of items or one less
  661. assert(StoredSessions->Count == SessionListView->Items->Count ||
  662. StoredSessions->Count == SessionListView->Items->Count+1);
  663. if (StoredSessions->Count > SessionListView->Items->Count)
  664. Item = SessionListView->Items->Insert(StoredSessions->IndexOf(NewSession));
  665. else
  666. Item = SessionListView->Items->Item[StoredSessions->IndexOf(NewSession)];
  667. LoadSessionItem(Item);
  668. SelectedSession = NewSession;
  669. SessionData = NewSession;
  670. ChangePage(SessionListSheet);
  671. SessionListView->SetFocus();
  672. }
  673. }
  674. //---------------------------------------------------------------------------
  675. void __fastcall TLoginDialog::DeleteSessionActionExecute(TObject * /*Sender*/)
  676. {
  677. if (SelectedSession)
  678. {
  679. int PrevSelectedIndex = SessionListView->Selected->Index;
  680. SelectedSession->Remove();
  681. StoredSessions->Remove(SelectedSession);
  682. SessionListView->Selected->Delete();
  683. if (SessionListView->Items->Count)
  684. {
  685. if (PrevSelectedIndex >= SessionListView->Items->Count)
  686. PrevSelectedIndex = SessionListView->Items->Count - 1;
  687. SelectedSession =
  688. (TSessionData *)StoredSessions->AtObject(PrevSelectedIndex);
  689. }
  690. }
  691. }
  692. //---------------------------------------------------------------------------
  693. void __fastcall TLoginDialog::ImportSessionsActionExecute(TObject * /*Sender*/)
  694. {
  695. if (DoImportSessionsDialog(StoredSessions))
  696. {
  697. LoadSessions();
  698. if (SessionListView->Items->Count)
  699. SessionListView->Items->Item[0]->MakeVisible(False);
  700. }
  701. }
  702. //---------------------------------------------------------------------------
  703. void __fastcall TLoginDialog::CleanUpActionExecute(TObject * /*Sender*/)
  704. {
  705. if (DoCleanupDialog(StoredSessions, Configuration))
  706. LoadSessions();
  707. }
  708. //---------------------------------------------------------------------------
  709. void __fastcall TLoginDialog::AboutActionExecute(TObject * /*Sender*/)
  710. {
  711. DoAboutDialog(Configuration);
  712. }
  713. //---------------------------------------------------------------------------
  714. void __fastcall TLoginDialog::ActionListUpdate(TBasicAction *Action,
  715. bool &Handled)
  716. {
  717. if (Action == LoadSessionAction)
  718. {
  719. LoadSessionAction->Enabled = SessionListView->Selected;
  720. }
  721. else if (Action == DeleteSessionAction)
  722. {
  723. TSessionData * Data = SessionData;
  724. DeleteSessionAction->Enabled =
  725. SessionListView->Selected && Data && !Data->Special;
  726. }
  727. else if (Action == DesktopIconAction)
  728. {
  729. DesktopIconAction->Enabled = SessionListView->Selected;
  730. }
  731. else if (Action == SendToHookAction)
  732. {
  733. SendToHookAction->Enabled = SessionListView->Selected;
  734. }
  735. else if (Action == LoginAction)
  736. {
  737. TSessionData * Data = SessionData;
  738. LoginAction->Enabled = Data && Data->CanLogin;
  739. }
  740. else if (Action == SaveSessionAction)
  741. {
  742. SaveSessionAction->Enabled = (PageControl->ActivePage != SessionListSheet);
  743. }
  744. Handled = true;
  745. }
  746. //---------------------------------------------------------------------------
  747. bool __fastcall TLoginDialog::Execute()
  748. {
  749. LoadConfiguration();
  750. bool Result = (ShowModal() == mrOk);
  751. if (Result)
  752. {
  753. SaveConfiguration();
  754. }
  755. return Result;
  756. }
  757. //---------------------------------------------------------------------------
  758. void __fastcall TLoginDialog::SaveConfiguration()
  759. {
  760. assert(CustomWinConfiguration);
  761. CustomWinConfiguration->BeginUpdate();
  762. try
  763. {
  764. LoggingFrame->SaveConfiguration();
  765. GeneralSettingsFrame->SaveConfiguration();
  766. CustomWinConfiguration->ShowAdvancedLoginOptions = ShowAdvancedLoginOptionsCheck->Checked;
  767. }
  768. __finally
  769. {
  770. CustomWinConfiguration->EndUpdate();
  771. }
  772. }
  773. //---------------------------------------------------------------------------
  774. void __fastcall TLoginDialog::LoadConfiguration()
  775. {
  776. assert(CustomWinConfiguration);
  777. LoggingFrame->LoadConfiguration();
  778. GeneralSettingsFrame->LoadConfiguration();
  779. ShowAdvancedLoginOptionsCheck->Checked = CustomWinConfiguration->ShowAdvancedLoginOptions;
  780. UpdateControls();
  781. }
  782. //---------------------------------------------------------------------------
  783. void __fastcall TLoginDialog::LoggingGetDefaultLogFileName(
  784. TObject* /*Sender*/, AnsiString & DefaultLogFileName)
  785. {
  786. assert(FSessionData);
  787. DefaultLogFileName = FSessionData->DefaultLogFileName;
  788. }
  789. //---------------------------------------------------------------------------
  790. void __fastcall TLoginDialog::PreferencesButtonClick(TObject * /*Sender*/)
  791. {
  792. ShowPreferencesDialog();
  793. }
  794. //---------------------------------------------------------------------------
  795. void __fastcall TLoginDialog::ShowPreferencesDialog()
  796. {
  797. DoPreferencesDialog(pmLogin);
  798. }
  799. //---------------------------------------------------------------------------
  800. void __fastcall TLoginDialog::NewSessionActionExecute(TObject * /*Sender*/)
  801. {
  802. Default();
  803. ChangePage(BasicSheet);
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TLoginDialog::NavigationTreeChange(TObject * /*Sender*/,
  807. TTreeNode *Node)
  808. {
  809. if (Node->SelectedIndex)
  810. {
  811. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  812. {
  813. if (PageControl->Pages[Index]->Tag == Node->SelectedIndex)
  814. {
  815. PageControl->ActivePage = PageControl->Pages[Index];
  816. return;
  817. }
  818. }
  819. }
  820. assert(false);
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TLoginDialog::ChangePage(TTabSheet * Tab)
  824. {
  825. PageControl->ActivePage = Tab;
  826. PageControlChange(PageControl);
  827. }
  828. //---------------------------------------------------------------------------
  829. void __fastcall TLoginDialog::PageControlChange(TObject *Sender)
  830. {
  831. bool Found = false;
  832. if (PageControl->ActivePage->Tag)
  833. {
  834. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  835. {
  836. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  837. PageControl->ActivePage->Tag)
  838. {
  839. NavigationTree->Items->Item[Index]->Selected = true;
  840. Found = true;
  841. }
  842. }
  843. }
  844. if (!Found)
  845. {
  846. ChangePage(BasicSheet);
  847. }
  848. else
  849. {
  850. DataChange(Sender);
  851. }
  852. }
  853. //---------------------------------------------------------------------------
  854. TTreeView * __fastcall TLoginDialog::GetNavigationTree()
  855. {
  856. return (ShowAdvancedLoginOptionsCheck->Checked ?
  857. AdvancedNavigationTree : SimpleNavigationTree);
  858. }
  859. //---------------------------------------------------------------------------
  860. void __fastcall TLoginDialog::CMDialogKey(TWMKeyDown & Message)
  861. {
  862. if (Message.CharCode == VK_TAB)
  863. {
  864. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  865. if (Shift.Contains(ssCtrl))
  866. {
  867. TTreeNode * Node = NavigationTree->Selected;
  868. if (!Shift.Contains(ssShift))
  869. {
  870. Node = Node->GetNext();
  871. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  872. }
  873. else
  874. {
  875. if (Node->GetPrev()) Node = Node->GetPrev();
  876. else
  877. while (Node->GetNext()) Node = Node->GetNext();
  878. }
  879. Node->Selected = True;
  880. Message.Result = 1;
  881. return;
  882. }
  883. }
  884. TForm::Dispatch(&Message);
  885. }
  886. //---------------------------------------------------------------------------
  887. void __fastcall TLoginDialog::Dispatch(void *Message)
  888. {
  889. TMessage * M = reinterpret_cast<TMessage*>(Message);
  890. assert(M);
  891. if (M->Msg == CM_DIALOGKEY)
  892. {
  893. CMDialogKey(*((TWMKeyDown *)Message));
  894. }
  895. else if (M->Msg == WM_LOCALE_CHANGE)
  896. {
  897. if (M->WParam == 0)
  898. {
  899. SaveConfiguration();
  900. SaveSession(FSessionData);
  901. FSavedTab = PageControl->ActivePage;
  902. FSavedSession = SessionListView->ItemIndex;
  903. assert(FSystemSettings);
  904. RevokeSystemSettings(this, FSystemSettings);
  905. FSystemSettings = NULL;
  906. ShowTabs(true);
  907. Hide();
  908. }
  909. else
  910. {
  911. FLocaleChanging = true;
  912. try
  913. {
  914. Show();
  915. }
  916. __finally
  917. {
  918. FLocaleChanging = false;
  919. }
  920. }
  921. }
  922. else
  923. {
  924. TForm::Dispatch(Message);
  925. }
  926. }
  927. //---------------------------------------------------------------------------
  928. void __fastcall TLoginDialog::CipherListBoxStartDrag(TObject * /*Sender*/,
  929. TDragObject *& /*DragObject*/)
  930. {
  931. FCipherDragSource = CipherListBox->ItemIndex;
  932. FCipherDragDest = -1;
  933. }
  934. //---------------------------------------------------------------------------
  935. void __fastcall TLoginDialog::CipherListBoxDragOver(TObject * /*Sender*/,
  936. TObject *Source, int X, int Y, TDragState /*State*/, bool &Accept)
  937. {
  938. if (Source == CipherListBox) Accept = AllowCipherDrag(X, Y);
  939. }
  940. //---------------------------------------------------------------------------
  941. void __fastcall TLoginDialog::CipherListBoxDragDrop(TObject * /*Sender*/,
  942. TObject *Source, int X, int Y)
  943. {
  944. if (Source == CipherListBox)
  945. {
  946. if (AllowCipherDrag(X, Y)) CipherMove(FCipherDragSource, FCipherDragDest);
  947. }
  948. }
  949. //---------------------------------------------------------------------------
  950. void __fastcall TLoginDialog::CipherButtonClick(TObject *Sender)
  951. {
  952. CipherMove(CipherListBox->ItemIndex,
  953. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  954. UpdateControls();
  955. }
  956. //---------------------------------------------------------------------------
  957. bool __fastcall TLoginDialog::AllowCipherDrag(int X, int Y)
  958. {
  959. FCipherDragDest = CipherListBox->ItemAtPos(TPoint(X, Y), true);
  960. return (FCipherDragDest >= 0) && (FCipherDragDest != FCipherDragSource);
  961. }
  962. //---------------------------------------------------------------------------
  963. void __fastcall TLoginDialog::CipherMove(int Source, int Dest)
  964. {
  965. if (Source >= 0 && Source < CipherListBox->Items->Count &&
  966. Dest >= 0 && Dest < CipherListBox->Items->Count)
  967. {
  968. CipherListBox->Items->Move(Source, Dest);
  969. CipherListBox->ItemIndex = Dest;
  970. CipherListBox->SetFocus();
  971. }
  972. }
  973. //---------------------------------------------------------------------------
  974. void __fastcall TLoginDialog::SetDefaultSessionActionExecute(
  975. TObject * /*Sender*/)
  976. {
  977. if (MessageDialog(LoadStr(SET_DEFAULT_SESSION_SETTINGS), qtConfirmation,
  978. qaOK | qaCancel, 0) == qaOK)
  979. {
  980. SaveSession(FSessionData);
  981. StoredSessions->DefaultSettings = FSessionData;
  982. }
  983. }
  984. //---------------------------------------------------------------------------
  985. void __fastcall TLoginDialog::ToolsMenuButtonClick(TObject * /*Sender*/)
  986. {
  987. TPoint PopupPoint = ToolsMenuButton->ClientToScreen(TPoint(0, ToolsMenuButton->Height));
  988. ToolsPopupMenu->Popup(PopupPoint.x, PopupPoint.y);
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TLoginDialog::ShellIconsButtonClick(TObject * /*Sender*/)
  992. {
  993. TPoint PopupPoint = ShellIconsButton->ClientToScreen(TPoint(0, ShellIconsButton->Height));
  994. IconsPopupMenu->Popup(PopupPoint.x, PopupPoint.y);
  995. }
  996. //---------------------------------------------------------------------------
  997. void __fastcall TLoginDialog::DesktopIconActionExecute(TObject * /*Sender*/)
  998. {
  999. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SHORTCUT, (SelectedSession->Name)),
  1000. qtConfirmation, qaYes | qaNo, 0) == qaYes)
  1001. {
  1002. assert(SelectedSession);
  1003. CreateDesktopShortCut(SelectedSession->Name, Application->ExeName,
  1004. FORMAT("\"%s\"", (SelectedSession->Name)),
  1005. FMTLOAD(SHORTCUT_INFO_TIP, (SelectedSession->Name, SelectedSession->InfoTip)));
  1006. }
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. void __fastcall TLoginDialog::SendToHookActionExecute(TObject * /*Sender*/)
  1010. {
  1011. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SENDTO, (SelectedSession->Name)),
  1012. qtConfirmation, qaYes | qaNo, 0) == qaYes)
  1013. {
  1014. assert(SelectedSession);
  1015. CreateDesktopShortCut(FMTLOAD(SESSION_SENDTO_HOOK_NAME, (SelectedSession->Name)),
  1016. Application->ExeName,
  1017. FORMAT("\"%s\" /upload", (SelectedSession->Name)), "",
  1018. CSIDL_SENDTO);
  1019. }
  1020. }
  1021. //---------------------------------------------------------------------------
  1022. void __fastcall TLoginDialog::SessionListViewCustomDrawItem(
  1023. TCustomListView *Sender, TListItem *Item, TCustomDrawState /*State*/,
  1024. bool &DefaultDraw)
  1025. {
  1026. TSessionData * Data = (TSessionData *)Item->Data;
  1027. TFontStyles Styles = Sender->Canvas->Font->Style;
  1028. if (Data->Special) Styles = Styles /*< fsItalic*/ << fsBold << fsUnderline;
  1029. else Styles = Styles /*>> fsItalic*/ >> fsBold >> fsUnderline;
  1030. Sender->Canvas->Font->Style = Styles;
  1031. DefaultDraw = true;
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void __fastcall TLoginDialog::CheckForUpdatesActionExecute(TObject * /*Sender*/)
  1035. {
  1036. CheckForUpdates();
  1037. }
  1038. //---------------------------------------------------------------------------
  1039. void __fastcall TLoginDialog::SetOptions(int value)
  1040. {
  1041. if (Options != value)
  1042. {
  1043. FOptions = value;
  1044. UpdateControls();
  1045. }
  1046. }
  1047. //---------------------------------------------------------------------------
  1048. void __fastcall TLoginDialog::LanguagesButtonClick(TObject * /*Sender*/)
  1049. {
  1050. TPoint PopupPoint = LanguagesButton->ClientToScreen(TPoint(0, LanguagesButton->Height));
  1051. delete FLanguagesPopupMenu;
  1052. FLanguagesPopupMenu = new TPopupMenu(this);
  1053. TStrings * Locales = GUIConfiguration->Locales;
  1054. for (int Index = 0; Index < Locales->Count; Index++)
  1055. {
  1056. TMenuItem * Item = new TMenuItem(FLanguagesPopupMenu);
  1057. FLanguagesPopupMenu->Items->Add(Item);
  1058. Item->Caption = Locales->Strings[Index];
  1059. Item->Tag = reinterpret_cast<int>(Locales->Objects[Index]);
  1060. Item->OnClick = LocaleClick;
  1061. Item->Checked = (reinterpret_cast<LCID>(Locales->Objects[Index]) ==
  1062. GUIConfiguration->Locale);
  1063. }
  1064. FLanguagesPopupMenu->Popup(PopupPoint.x, PopupPoint.y);
  1065. }
  1066. //---------------------------------------------------------------------------
  1067. void __fastcall TLoginDialog::LocaleClick(TObject * Sender)
  1068. {
  1069. assert(Sender);
  1070. GUIConfiguration->Locale =
  1071. static_cast<LCID>(dynamic_cast<TMenuItem*>(Sender)->Tag);
  1072. LanguagesButton->SetFocus();
  1073. }
  1074. //---------------------------------------------------------------------------
  1075. void __fastcall TLoginDialog::PathEditsKeyDown(TObject * Sender,
  1076. WORD & Key, TShiftState Shift)
  1077. {
  1078. PathEditKeyDown(dynamic_cast<TCustomEdit*>(Sender), Key, Shift,
  1079. (Sender == RemoteDirectoryEdit));
  1080. }
  1081. //---------------------------------------------------------------------------
  1082. void __fastcall TLoginDialog::AuthGSSAPICheckClick(TObject * /*Sender*/)
  1083. {
  1084. if (!NoUpdate)
  1085. {
  1086. UpdateControls();
  1087. if (AuthGSSAPICheck->Checked && !Configuration->GSSAPIInstalled)
  1088. {
  1089. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED));
  1090. }
  1091. }
  1092. }
  1093. //---------------------------------------------------------------------------