Properties.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "WinInterface.h"
  5. #include "Properties.h"
  6. #include <VCLCommon.h>
  7. #include <Common.h>
  8. #include <Terminal.h>
  9. #include <TextsWin.h>
  10. #include <GUITools.h>
  11. #include <CoreMain.h>
  12. #include <Tools.h>
  13. #include <BaseUtils.hpp>
  14. //---------------------------------------------------------------------
  15. #pragma link "PathLabel"
  16. #pragma link "Rights"
  17. #pragma link "RightsExt"
  18. #ifndef NO_RESOURCES
  19. #pragma resource "*.dfm"
  20. #endif
  21. //---------------------------------------------------------------------
  22. bool __fastcall DoPropertiesDialog(TStrings * FileList,
  23. const UnicodeString Directory, const TRemoteTokenList * GroupList,
  24. const TRemoteTokenList * UserList, TStrings * ChecksumAlgs,
  25. TRemoteProperties * Properties,
  26. int AllowedChanges, bool UserGroupByID, TCalculateSizeEvent OnCalculateSize,
  27. TCalculateChecksumEvent OnCalculateChecksum)
  28. {
  29. bool Result;
  30. TPropertiesDialog * PropertiesDialog = new TPropertiesDialog(Application,
  31. FileList, Directory, GroupList, UserList, ChecksumAlgs, AllowedChanges, UserGroupByID,
  32. OnCalculateSize, OnCalculateChecksum);
  33. try
  34. {
  35. Result = PropertiesDialog->Execute(*Properties);
  36. }
  37. __finally
  38. {
  39. delete PropertiesDialog;
  40. }
  41. return Result;
  42. }
  43. //---------------------------------------------------------------------
  44. __fastcall TPropertiesDialog::TPropertiesDialog(TComponent* AOwner,
  45. TStrings * FileList, const UnicodeString Directory,
  46. const TRemoteTokenList * GroupList, const TRemoteTokenList * UserList,
  47. TStrings * ChecksumAlgs,
  48. int AllowedChanges, bool UserGroupByID, TCalculateSizeEvent OnCalculateSize,
  49. TCalculateChecksumEvent OnCalculateChecksum)
  50. : TForm(AOwner)
  51. {
  52. FOnCalculateSize = OnCalculateSize;
  53. FOnCalculateChecksum = OnCalculateChecksum;
  54. RightsFrame->OnChange = ControlChange;
  55. FShellImageList = SharedSystemImageList(true);
  56. FShellImageList->DrawingStyle = dsTransparent;
  57. FFileList = new TStringList();
  58. FFileList->Assign(FileList);
  59. FAllowedChanges = AllowedChanges;
  60. FUserGroupByID = UserGroupByID;
  61. FAllowCalculateStats = false;
  62. FStatsNotCalculated = false;
  63. FChecksumLoaded = false;
  64. FMultipleChecksum = false;
  65. LocationLabel->Caption = Directory;
  66. FGroupList = GroupList;
  67. FUserList = UserList;
  68. FChecksumAlgs = ChecksumAlgs;
  69. LoadInfo();
  70. UseSystemSettings(this);
  71. }
  72. //---------------------------------------------------------------------------
  73. __fastcall TPropertiesDialog::~TPropertiesDialog()
  74. {
  75. delete FFileList;
  76. FFileList = NULL;
  77. delete FShellImageList;
  78. FShellImageList = NULL;
  79. }
  80. //---------------------------------------------------------------------
  81. bool __fastcall TPropertiesDialog::Execute(TRemoteProperties & Properties)
  82. {
  83. SetFileProperties(Properties);
  84. PageControl->ActivePage = CommonSheet;
  85. if (FAllowedChanges & cpGroup) ActiveControl = GroupComboBox;
  86. else
  87. if (FAllowedChanges & cpOwner) ActiveControl = OwnerComboBox;
  88. else
  89. if (FAllowedChanges & cpMode) ActiveControl = RightsFrame;
  90. else ActiveControl = CancelButton;
  91. if (ALWAYS_TRUE(FChecksumAlgs != NULL))
  92. {
  93. ChecksumAlgEdit->Items->Assign(FChecksumAlgs);
  94. int ChecksumIndex = FChecksumAlgs->IndexOf(GUIConfiguration->ChecksumAlg);
  95. if (ChecksumIndex < 0)
  96. {
  97. ChecksumIndex = 0;
  98. }
  99. ChecksumAlgEdit->ItemIndex = ChecksumIndex;
  100. }
  101. ResetChecksum();
  102. UpdateControls();
  103. bool Result = (ShowModal() == DefaultResult());
  104. if (Result)
  105. {
  106. Properties = GetFileProperties();
  107. }
  108. return Result;
  109. }
  110. //---------------------------------------------------------------------------
  111. TModalResult __fastcall TPropertiesDialog::DefaultResult()
  112. {
  113. // Fallback when ChecksumButton is default
  114. return ::DefaultResult(this, OkButton);
  115. }
  116. //---------------------------------------------------------------------------
  117. UnicodeString __fastcall TPropertiesDialog::LoadRemoteToken(
  118. const TRemoteToken & Token)
  119. {
  120. UnicodeString Result;
  121. if (FUserGroupByID)
  122. {
  123. if (Token.IDValid)
  124. {
  125. if (Token.NameValid)
  126. {
  127. Result = FORMAT(L"%s [%d]", (Token.Name, int(Token.ID)));
  128. }
  129. else
  130. {
  131. Result = FORMAT(L"[%d]", (int(Token.ID)));
  132. }
  133. }
  134. else
  135. {
  136. // be it valid or not
  137. Result = Token.Name;
  138. }
  139. }
  140. else
  141. {
  142. // what if name is not filled in?
  143. Result = Token.Name;
  144. }
  145. return Result;
  146. }
  147. //---------------------------------------------------------------------------
  148. void __fastcall TPropertiesDialog::LoadRemoteToken(
  149. TComboBox * ComboBox, bool Valid, const TRemoteToken & Token)
  150. {
  151. if (Valid)
  152. {
  153. ComboBox->Text = LoadRemoteToken(Token);
  154. }
  155. else
  156. {
  157. ComboBox->Text = L"";
  158. }
  159. }
  160. //---------------------------------------------------------------------------
  161. void __fastcall TPropertiesDialog::LoadRemoteTokens(TComboBox * ComboBox,
  162. const TRemoteTokenList * List)
  163. {
  164. TStrings * Items = ComboBox->Items;
  165. Items->BeginUpdate();
  166. try
  167. {
  168. Items->Clear();
  169. if (List != NULL)
  170. {
  171. int Count = List->Count();
  172. for (int Index = 0; Index < Count; Index++)
  173. {
  174. Items->Add(LoadRemoteToken(*List->Token(Index)));
  175. }
  176. }
  177. }
  178. __finally
  179. {
  180. Items->EndUpdate();
  181. }
  182. }
  183. //---------------------------------------------------------------------------
  184. void __fastcall TPropertiesDialog::LoadInfo()
  185. {
  186. assert(FFileList->Count > 0);
  187. FMultiple = FFileList->Count > 1;
  188. FMultipleChecksum = FMultiple;
  189. FAllowCalculateStats = false;
  190. FStatsNotCalculated = false;
  191. __int64 FilesSize = 0;
  192. TCalculateSizeStats Stats;
  193. for (int Index = 0; Index < FFileList->Count; Index++)
  194. {
  195. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[Index]);
  196. if (File->IsDirectory)
  197. {
  198. Stats.Directories++;
  199. if (!File->IsSymLink)
  200. {
  201. FAllowCalculateStats = true;
  202. FStatsNotCalculated = true;
  203. FMultipleChecksum = true;
  204. }
  205. }
  206. else
  207. {
  208. Stats.Files++;
  209. }
  210. if (File->IsSymLink)
  211. {
  212. Stats.SymLinks++;
  213. }
  214. FilesSize += File->Size;
  215. }
  216. LoadRemoteTokens(GroupComboBox, FGroupList);
  217. LoadRemoteTokens(OwnerComboBox, FUserList);
  218. RightsFrame->AllowAddXToDirectories = (Stats.Directories > 0);
  219. RecursiveCheck->Visible = (Stats.Directories > 0);
  220. RecursiveBevel->Visible = (Stats.Directories > 0);
  221. LoadStats(FilesSize, Stats);
  222. FileIconImage->Picture->Bitmap = NULL;
  223. RightsFrame->AllowUndef = FMultiple;
  224. if (!FMultiple)
  225. {
  226. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  227. assert(File && FShellImageList);
  228. // shell image list does not have fixed large icon size
  229. // (it is probably 32x32 min, but can be larger, on xp it is 48x48 if
  230. // large icons are enabled, on vista can be even larger).
  231. // so we stretch (shrink) the icon to 32x32 here to be sure.
  232. Graphics::TBitmap * Bitmap = new Graphics::TBitmap;
  233. try
  234. {
  235. FShellImageList->GetBitmap(File->IconIndex, Bitmap);
  236. FileIconImage->Picture->Bitmap->Width = FileIconImage->Width;
  237. FileIconImage->Picture->Bitmap->Height = FileIconImage->Height;
  238. FileIconImage->Picture->Bitmap->Canvas->StretchDraw(
  239. TRect(0, 0, FileIconImage->Width, FileIconImage->Height),
  240. Bitmap);
  241. }
  242. __finally
  243. {
  244. delete Bitmap;
  245. }
  246. LinksToLabelLabel->Visible = File->IsSymLink;
  247. LinksToLabel->Visible = File->IsSymLink;
  248. if (File->IsSymLink)
  249. {
  250. LinksToLabel->Caption = File->LinkTo;
  251. }
  252. RightsFrame->AllowAddXToDirectories = File->IsDirectory;
  253. Caption = FMTLOAD(PROPERTIES_FILE_CAPTION, (File->FileName));
  254. RecursiveCheck->Visible = File->IsDirectory;
  255. RecursiveBevel->Visible = File->IsDirectory;
  256. }
  257. else
  258. {
  259. Caption = FMTLOAD(PROPERTIES_FILES_CAPTION, (FFileList->Strings[0]));
  260. LinksToLabelLabel->Hide();
  261. LinksToLabel->Hide();
  262. }
  263. FilesIconImage->Visible = FMultiple;
  264. FileIconImage->Visible = !FMultiple;
  265. ChecksumGroup->Visible = !FMultipleChecksum;
  266. ChecksumView->Visible = FMultipleChecksum;
  267. }
  268. //---------------------------------------------------------------------------
  269. void __fastcall TPropertiesDialog::LoadStats(__int64 FilesSize,
  270. const TCalculateSizeStats & Stats)
  271. {
  272. UnicodeString SizeStr;
  273. UnicodeString FilesStr;
  274. if (FStatsNotCalculated)
  275. {
  276. SizeStr = LoadStr(PROPERTIES_UNKNOWN_SIZE);
  277. }
  278. else
  279. {
  280. SizeStr = FormatBytes(FilesSize);
  281. UnicodeString SizeUnorderedStr = FormatBytes(FilesSize, fbNone);
  282. if (SizeStr != SizeUnorderedStr)
  283. {
  284. SizeStr = FORMAT(L"%s (%s)", (SizeStr, SizeUnorderedStr));
  285. }
  286. }
  287. if (((Stats.Files + Stats.Directories) == 0) && !FMultiple)
  288. {
  289. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  290. assert(File != NULL);
  291. FilesStr = File->FileName;
  292. }
  293. else
  294. {
  295. if (Stats.Files > 0)
  296. {
  297. FilesStr = (Stats.Files == 1) ? FMTLOAD(PROPERTIES_FILE, (Stats.Files)) :
  298. FMTLOAD(PROPERTIES_FILES, (Stats.Files));
  299. if (Stats.Directories > 0)
  300. {
  301. FilesStr = FORMAT(L"%s, ", (FilesStr));
  302. }
  303. }
  304. if (Stats.Directories > 0)
  305. {
  306. FilesStr += (Stats.Directories == 1) ? FMTLOAD(PROPERTIES_DIRECTORY, (Stats.Directories)) :
  307. FMTLOAD(PROPERTIES_DIRECTORIES, (Stats.Directories));
  308. }
  309. if (Stats.SymLinks > 0)
  310. {
  311. UnicodeString SymLinksStr;
  312. SymLinksStr = (Stats.SymLinks == 1) ? FMTLOAD(PROPERTIES_SYMLINK, (Stats.SymLinks)) :
  313. FMTLOAD(PROPERTIES_SYMLINKS, (Stats.SymLinks));
  314. FilesStr = FORMAT(L"%s (%s)", (FilesStr, SymLinksStr));
  315. }
  316. }
  317. SizeLabel->Caption = SizeStr;
  318. FileLabel->Caption = FilesStr;
  319. }
  320. //---------------------------------------------------------------------------
  321. void __fastcall TPropertiesDialog::SetFileProperties(const TRemoteProperties & value)
  322. {
  323. TValidProperties Valid;
  324. if (value.Valid.Contains(vpRights) && FAllowedChanges & cpMode) Valid << vpRights;
  325. if (value.Valid.Contains(vpOwner) && FAllowedChanges & cpOwner) Valid << vpOwner;
  326. if (value.Valid.Contains(vpGroup) && FAllowedChanges & cpGroup) Valid << vpGroup;
  327. FOrigProperties = value;
  328. FOrigProperties.Valid = Valid;
  329. FOrigProperties.Recursive = false;
  330. if (value.Valid.Contains(vpRights))
  331. {
  332. RightsFrame->Rights = value.Rights;
  333. RightsFrame->AddXToDirectories = value.AddXToDirectories;
  334. }
  335. else
  336. {
  337. RightsFrame->Rights = TRights();
  338. RightsFrame->AddXToDirectories = false;
  339. }
  340. LoadRemoteToken(GroupComboBox, value.Valid.Contains(vpGroup), value.Group);
  341. LoadRemoteToken(OwnerComboBox, value.Valid.Contains(vpOwner), value.Owner);
  342. RecursiveCheck->Checked = value.Recursive;
  343. UpdateControls();
  344. }
  345. //---------------------------------------------------------------------------
  346. void __fastcall TPropertiesDialog::StoreRemoteToken(unsigned int ID,
  347. const UnicodeString & Text, const TRemoteTokenList * List, TRemoteToken & Result)
  348. {
  349. assert(List != NULL);
  350. const TRemoteToken * Token = List->Find(ID);
  351. if (Token == NULL)
  352. {
  353. Result.ID = ID;
  354. Result.Name = Text;
  355. }
  356. else
  357. {
  358. Result = *Token;
  359. }
  360. }
  361. //---------------------------------------------------------------------------
  362. TRemoteToken __fastcall TPropertiesDialog::StoreRemoteToken(const TRemoteToken & Orig,
  363. UnicodeString Text, int Message, const TRemoteTokenList * List)
  364. {
  365. TRemoteToken Result;
  366. Text = Text.Trim();
  367. if (!Text.IsEmpty())
  368. {
  369. if (FUserGroupByID)
  370. {
  371. assert(List != NULL);
  372. int IDStart = Text.LastDelimiter(L"[");
  373. if (!Text.IsEmpty() && (IDStart >= 0) && (Text[Text.Length()] == L']'))
  374. {
  375. int ID;
  376. UnicodeString IDStr = Text.SubString(IDStart + 1, Text.Length() - IDStart - 1);
  377. if (!TryStrToInt(IDStr, ID))
  378. {
  379. throw Exception(Message);
  380. }
  381. else
  382. {
  383. StoreRemoteToken(ID, Text.SubString(1, IDStart - 1).Trim(), List, Result);
  384. }
  385. }
  386. else
  387. {
  388. const TRemoteToken * Token = List->Find(Text);
  389. if (Token == NULL)
  390. {
  391. int ID;
  392. if (TryStrToInt(Text, ID))
  393. {
  394. StoreRemoteToken(ID, Text, List, Result);
  395. }
  396. else
  397. {
  398. throw Exception(MainInstructions(FMTLOAD(PROPERTIES_UNKNOWN_TOKEN, (Text))));
  399. }
  400. }
  401. else
  402. {
  403. Result = *Token;
  404. }
  405. }
  406. }
  407. else
  408. {
  409. Result.Name = Text;
  410. }
  411. }
  412. if (LoadRemoteToken(Result) == LoadRemoteToken(Orig))
  413. {
  414. Result = Orig;
  415. }
  416. return Result;
  417. }
  418. //---------------------------------------------------------------------------
  419. void __fastcall TPropertiesDialog::StoreRemoteToken(TComboBox * ComboBox,
  420. int ChangeFlag, TValidProperty PropertyFlag, const TRemoteToken & Orig,
  421. TRemoteToken & Token, int Message, const TRemoteTokenList * List,
  422. TRemoteProperties & Properties)
  423. {
  424. UnicodeString Text = ComboBox->Text.Trim();
  425. if (FLAGSET(FAllowedChanges, ChangeFlag))
  426. {
  427. Token = StoreRemoteToken(Orig, Text, Message, List);
  428. if (Token.IsSet)
  429. {
  430. Properties.Valid << PropertyFlag;
  431. }
  432. }
  433. }
  434. //---------------------------------------------------------------------------
  435. TRemoteProperties __fastcall TPropertiesDialog::GetFileProperties()
  436. {
  437. TRemoteProperties Result;
  438. if (FAllowedChanges & cpMode)
  439. {
  440. Result.Valid << vpRights;
  441. Result.Rights = RightsFrame->Rights;
  442. Result.AddXToDirectories = RightsFrame->AddXToDirectories;
  443. }
  444. StoreRemoteToken(GroupComboBox, cpGroup, vpGroup, FOrigProperties.Group,
  445. Result.Group, PROPERTIES_INVALID_GROUP, FGroupList, Result);
  446. StoreRemoteToken(OwnerComboBox, cpOwner, vpOwner, FOrigProperties.Owner,
  447. Result.Owner, PROPERTIES_INVALID_OWNER, FUserList, Result);
  448. Result.Recursive = RecursiveCheck->Checked;
  449. return Result;
  450. }
  451. //---------------------------------------------------------------------------
  452. void __fastcall TPropertiesDialog::ControlChange(TObject * /*Sender*/)
  453. {
  454. if (Visible)
  455. {
  456. UpdateControls();
  457. }
  458. }
  459. //---------------------------------------------------------------------------
  460. void __fastcall TPropertiesDialog::UpdateControls()
  461. {
  462. // No point enabling recursive check if there's no change allowed (supported),
  463. // i.e. with WebDAV.
  464. EnableControl(RecursiveCheck, ((FAllowedChanges & (cpGroup | cpOwner | cpMode)) != 0));
  465. bool Allow;
  466. try
  467. {
  468. Allow =
  469. !TRemoteProperties::ChangedProperties(FOrigProperties, GetFileProperties()).Valid.Empty() ||
  470. (RecursiveCheck->Enabled && RecursiveCheck->Checked);
  471. }
  472. catch(...)
  473. {
  474. // when properties are invalid allow submitting the form,
  475. // because that reveals the cause to the user, otherwise he/she
  476. // may not be able to tell what is wrong
  477. Allow = true;
  478. }
  479. EnableControl(OkButton, Allow);
  480. EnableControl(GroupComboBox, FAllowedChanges & cpGroup);
  481. EnableControl(OwnerComboBox, FAllowedChanges & cpOwner);
  482. EnableControl(RightsFrame, FAllowedChanges & cpMode);
  483. CalculateSizeButton->Visible = FAllowCalculateStats;
  484. if (!FMultiple)
  485. {
  486. // when setting properties for one file only, allow undef state
  487. // only when the input right explicitly requires it or
  488. // when "recursive" is on (possible for directory only).
  489. bool AllowUndef =
  490. (FOrigProperties.Valid.Contains(vpRights) &&
  491. FOrigProperties.Rights.AllowUndef) ||
  492. (RecursiveCheck->Checked);
  493. if (!AllowUndef)
  494. {
  495. // when disallowing undef state, make sure, all undef are turned into unset
  496. RightsFrame->Rights = TRights(RightsFrame->Rights.NumberSet);
  497. }
  498. RightsFrame->AllowUndef = AllowUndef;
  499. }
  500. EnableControl(ChecksumSheet, ChecksumSupported());
  501. EnableControl(ChecksumButton, ChecksumSheet->Enabled &&
  502. !ChecksumAlgEdit->Text.IsEmpty());
  503. // hide checksum edit at least if it is disabled to get rid of ugly
  504. // visage on XP
  505. ChecksumEdit->Visible = ChecksumEdit->Enabled;
  506. DefaultButton(ChecksumButton, ChecksumAlgEdit->Focused());
  507. DefaultButton(OkButton, !ChecksumAlgEdit->Focused());
  508. }
  509. //---------------------------------------------------------------------------
  510. void __fastcall TPropertiesDialog::FormCloseQuery(TObject * /*Sender*/,
  511. bool & /*CanClose*/)
  512. {
  513. if (ModalResult == DefaultResult())
  514. {
  515. ExitActiveControl(this);
  516. }
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TPropertiesDialog::CalculateSizeButtonClick(
  520. TObject * /*Sender*/)
  521. {
  522. assert(FOnCalculateSize != NULL);
  523. bool DoClose = false;
  524. try
  525. {
  526. __int64 Size;
  527. TCalculateSizeStats Stats;
  528. FOnCalculateSize(FFileList, Size, Stats, DoClose);
  529. FStatsNotCalculated = false;
  530. LoadStats(Size, Stats);
  531. }
  532. __finally
  533. {
  534. if (DoClose)
  535. {
  536. Close();
  537. }
  538. }
  539. }
  540. //---------------------------------------------------------------------------
  541. void __fastcall TPropertiesDialog::HelpButtonClick(TObject * /*Sender*/)
  542. {
  543. FormHelp(this);
  544. }
  545. //---------------------------------------------------------------------------
  546. void __fastcall TPropertiesDialog::ResetChecksum()
  547. {
  548. ChecksumView->Items->Clear();
  549. ChecksumEdit->Text = LoadStr(PROPERTIES_CHECKSUM_UNKNOWN);
  550. AutoSizeListColumnsWidth(ChecksumView);
  551. }
  552. //---------------------------------------------------------------------------
  553. void __fastcall TPropertiesDialog::CalculateChecksum()
  554. {
  555. assert(FOnCalculateChecksum != NULL);
  556. ResetChecksum();
  557. FChecksumLoaded = true;
  558. FAlgUsed = UnicodeString();
  559. bool DoClose = false;
  560. try
  561. {
  562. FOnCalculateChecksum(ChecksumAlgEdit->Text, FFileList, CalculatedChecksum, DoClose);
  563. }
  564. __finally
  565. {
  566. if (DoClose)
  567. {
  568. Close();
  569. }
  570. }
  571. // If we successfully used the selected checksum, remember it (in normalized form)
  572. if (!FAlgUsed.IsEmpty())
  573. {
  574. GUIConfiguration->ChecksumAlg = FAlgUsed;
  575. }
  576. AutoSizeListColumnsWidth(ChecksumView);
  577. }
  578. //---------------------------------------------------------------------------
  579. void __fastcall TPropertiesDialog::CalculatedChecksum(
  580. const UnicodeString & FileName, const UnicodeString & Alg,
  581. const UnicodeString & Hash)
  582. {
  583. if (FMultipleChecksum)
  584. {
  585. TListItem * Item = ChecksumView->Items->Add();
  586. Item->Caption = FileName;
  587. Item->SubItems->Add(Hash);
  588. // optimization
  589. int TopIndex = ListView_GetTopIndex(ChecksumView->Handle);
  590. int Index = Item->Index;
  591. if ((TopIndex <= Index) &&
  592. (Index <= TopIndex + ChecksumView->VisibleRowCount))
  593. {
  594. AutoSizeListColumnsWidth(ChecksumView);
  595. }
  596. }
  597. else
  598. {
  599. ChecksumEdit->Text = Hash;
  600. }
  601. FAlgUsed = Alg;
  602. }
  603. //---------------------------------------------------------------------------
  604. void __fastcall TPropertiesDialog::NeedChecksum()
  605. {
  606. if (!FChecksumLoaded && ChecksumSupported())
  607. {
  608. CalculateChecksum();
  609. }
  610. }
  611. //---------------------------------------------------------------------------
  612. bool __fastcall TPropertiesDialog::ChecksumSupported()
  613. {
  614. return (FOnCalculateChecksum != NULL);
  615. }
  616. //---------------------------------------------------------------------------
  617. void __fastcall TPropertiesDialog::ChecksumButtonClick(TObject * /*Sender*/)
  618. {
  619. CalculateChecksum();
  620. }
  621. //---------------------------------------------------------------------------
  622. void __fastcall TPropertiesDialog::PageControlChange(TObject * /*Sender*/)
  623. {
  624. if (PageControl->ActivePage == ChecksumSheet)
  625. {
  626. NeedChecksum();
  627. }
  628. }
  629. //---------------------------------------------------------------------------
  630. void __fastcall TPropertiesDialog::ChecksumAlgEditChange(TObject * /*Sender*/)
  631. {
  632. ResetChecksum();
  633. UpdateControls();
  634. }
  635. //---------------------------------------------------------------------------
  636. void __fastcall TPropertiesDialog::CopyClick(TObject * Sender)
  637. {
  638. TInstantOperationVisualizer Visualizer;
  639. TListView * ListView = dynamic_cast<TListView *>(GetPopupComponent(Sender));
  640. assert(ListView != NULL);
  641. int Count = 0;
  642. UnicodeString SingleText;
  643. UnicodeString Text;
  644. TListItem * Item = ListView->GetNextItem(NULL, sdAll, TItemStates() << isSelected);
  645. while (Item != NULL)
  646. {
  647. assert(Item->Selected);
  648. SingleText = Item->SubItems->Strings[0];
  649. Text += FORMAT(L"%s = %s\r\n", (Item->Caption, Item->SubItems->Strings[0]));
  650. Count++;
  651. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  652. }
  653. CopyToClipboard(Count == 1 ? SingleText : Text);
  654. }
  655. //---------------------------------------------------------------------------
  656. void __fastcall TPropertiesDialog::ChecksumViewContextPopup(
  657. TObject * Sender, TPoint & MousePos, bool & Handled)
  658. {
  659. MenuPopup(Sender, MousePos, Handled);
  660. }
  661. //---------------------------------------------------------------------------
  662. void __fastcall TPropertiesDialog::ResolveRemoteToken(
  663. const TRemoteToken & Orig, int Message, TComboBox * ComboBox,
  664. const TRemoteTokenList * List)
  665. {
  666. try
  667. {
  668. ComboBox->Text =
  669. LoadRemoteToken(StoreRemoteToken(Orig, ComboBox->Text, Message, List));
  670. }
  671. catch(...)
  672. {
  673. ComboBox->SetFocus();
  674. throw;
  675. }
  676. }
  677. //---------------------------------------------------------------------------
  678. void __fastcall TPropertiesDialog::GroupComboBoxExit(TObject * Sender)
  679. {
  680. ResolveRemoteToken(FOrigProperties.Group, PROPERTIES_INVALID_GROUP,
  681. dynamic_cast<TComboBox *>(Sender), FGroupList);
  682. }
  683. //---------------------------------------------------------------------------
  684. void __fastcall TPropertiesDialog::OwnerComboBoxExit(TObject * Sender)
  685. {
  686. ResolveRemoteToken(FOrigProperties.Owner, PROPERTIES_INVALID_OWNER,
  687. dynamic_cast<TComboBox *>(Sender), FUserList);
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TPropertiesDialog::FormShow(TObject * /*Sender*/)
  691. {
  692. UpdateControls();
  693. }
  694. //---------------------------------------------------------------------------