SynchronizeProgress.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <WinInterface.h>
  5. #include "SynchronizeProgress.h"
  6. #include <Common.h>
  7. #include <Configuration.h>
  8. #include <ScpMain.h>
  9. #include <TextsWin.h>
  10. #include <VCLCommon.h>
  11. #include <GUITools.h>
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "PathLabel"
  15. #pragma resource "*.dfm"
  16. //---------------------------------------------------------------------------
  17. __fastcall TSynchronizeProgressForm::TSynchronizeProgressForm(TComponent * Owner,
  18. bool AllowMinimize, bool CompareOnly)
  19. : TForm(Owner)
  20. {
  21. FStarted = false;
  22. FCanceled = false;
  23. FElapsed = EncodeTime(0, 0, 0, 0);
  24. FShowAsModalStorage = NULL;
  25. FMinimizedByMe = false;
  26. FCompareOnly = CompareOnly;
  27. if (!AllowMinimize)
  28. {
  29. CancelButton->Left = CancelButton->Left +
  30. (MinimizeButton->Left - CancelButton->Left) / 2;
  31. MinimizeButton->Visible = false;
  32. }
  33. }
  34. //---------------------------------------------------------------------------
  35. __fastcall TSynchronizeProgressForm::~TSynchronizeProgressForm()
  36. {
  37. if (IsIconic(Application->Handle) && FMinimizedByMe)
  38. {
  39. Application->Restore();
  40. Application->BringToFront();
  41. }
  42. ReleaseAsModal(this, FShowAsModalStorage);
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TSynchronizeProgressForm::Start()
  46. {
  47. FStarted = true;
  48. FStartTime = Now();
  49. UpdateTimer->Enabled = true;
  50. StartTimeLabel->Caption = FStartTime.TimeString();
  51. Caption = LoadStr(FCompareOnly ? SYNCHRONIZE_PROGRESS_COMPARE : SYNCHRONIZE_PROGRESS_SYNCHRONIZE);
  52. ShowAsModal(this, FShowAsModalStorage);
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TSynchronizeProgressForm::Stop()
  56. {
  57. HideAsModal(this, FShowAsModalStorage);
  58. FStarted = false;
  59. UpdateTimer->Enabled = false;
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TSynchronizeProgressForm::SetData(const AnsiString LocalDirectory,
  63. const AnsiString RemoteDirectory, bool & Continue)
  64. {
  65. assert(FStarted);
  66. LocalDirectoryLabel->Caption = LocalDirectory;
  67. RemoteDirectoryLabel->Caption = RemoteDirectory;
  68. Continue = !FCanceled;
  69. UpdateControls();
  70. Application->ProcessMessages();
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TSynchronizeProgressForm::UpdateControls()
  74. {
  75. if (FStarted)
  76. {
  77. FElapsed = Now() - FStartTime;
  78. }
  79. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FElapsed);
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TSynchronizeProgressForm::CancelButtonClick(TObject * /*Sender*/)
  83. {
  84. if (!FCanceled && (MessageDialog(LoadStr(CANCEL_OPERATION), qtConfirmation,
  85. qaOK | qaCancel, HELP_NONE) == qaOK))
  86. {
  87. FCanceled = true;
  88. }
  89. }
  90. //---------------------------------------------------------------------------
  91. void __fastcall TSynchronizeProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  92. {
  93. UpdateControls();
  94. }
  95. //---------------------------------------------------------------------------
  96. void __fastcall TSynchronizeProgressForm::MinimizeButtonClick(
  97. TObject * /*Sender*/)
  98. {
  99. Application->Minimize();
  100. FMinimizedByMe = true;
  101. }
  102. //---------------------------------------------------------------------------