SynchronizeProgress.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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)
  19. : TForm(Owner)
  20. {
  21. FStarted = false;
  22. FCanceled = false;
  23. FElapsed = EncodeTime(0, 0, 0, 0);
  24. FShowAsModalStorage = NULL;
  25. FMinimizedByMe = false;
  26. if (!AllowMinimize)
  27. {
  28. CancelButton->Left = CancelButton->Left +
  29. (MinimizeButton->Left - CancelButton->Left) / 2;
  30. MinimizeButton->Visible = false;
  31. }
  32. }
  33. //---------------------------------------------------------------------------
  34. __fastcall TSynchronizeProgressForm::~TSynchronizeProgressForm()
  35. {
  36. if (IsIconic(Application->Handle) && FMinimizedByMe)
  37. {
  38. Application->Restore();
  39. }
  40. ReleaseAsModal(this, FShowAsModalStorage);
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TSynchronizeProgressForm::Start()
  44. {
  45. FStarted = true;
  46. FStartTime = Now();
  47. UpdateTimer->Enabled = true;
  48. StartTimeLabel->Caption = FStartTime.TimeString();
  49. ShowAsModal(this, FShowAsModalStorage);
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TSynchronizeProgressForm::Stop()
  53. {
  54. HideAsModal(this, FShowAsModalStorage);
  55. FStarted = false;
  56. UpdateTimer->Enabled = false;
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TSynchronizeProgressForm::SetData(const AnsiString LocalDirectory,
  60. const AnsiString RemoteDirectory, bool & Continue)
  61. {
  62. assert(FStarted);
  63. LocalDirectoryLabel->Caption = LocalDirectory;
  64. RemoteDirectoryLabel->Caption = RemoteDirectory;
  65. Continue = !FCanceled;
  66. UpdateControls();
  67. Application->ProcessMessages();
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TSynchronizeProgressForm::UpdateControls()
  71. {
  72. if (FStarted)
  73. {
  74. FElapsed = Now() - FStartTime;
  75. }
  76. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FElapsed);
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TSynchronizeProgressForm::CancelButtonClick(TObject * /*Sender*/)
  80. {
  81. if (!FCanceled && (MessageDialog(LoadStr(CANCEL_OPERATION), qtConfirmation,
  82. qaOK | qaCancel, HELP_NONE) == qaOK))
  83. {
  84. FCanceled = true;
  85. }
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TSynchronizeProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  89. {
  90. UpdateControls();
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TSynchronizeProgressForm::MinimizeButtonClick(
  94. TObject * /*Sender*/)
  95. {
  96. Application->Minimize();
  97. FMinimizedByMe = true;
  98. }
  99. //---------------------------------------------------------------------------