Login.cpp 37 KB

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