SynchronizeProgress.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <CoreMain.h>
  9. #include <TextsWin.h>
  10. #include <VCLCommon.h>
  11. #include <GUITools.h>
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "PathLabel"
  15. #ifndef NO_RESOURCES
  16. #pragma resource "*.dfm"
  17. #endif
  18. //---------------------------------------------------------------------------
  19. __fastcall TSynchronizeProgressForm::TSynchronizeProgressForm(TComponent * Owner,
  20. bool AllowMinimize, bool CompareOnly)
  21. : TForm(Owner)
  22. {
  23. FStarted = false;
  24. FCanceled = false;
  25. FElapsed = EncodeTimeVerbose(0, 0, 0, 0);
  26. FShowAsModalStorage = NULL;
  27. FMinimizedByMe = false;
  28. FCompareOnly = CompareOnly;
  29. UseSystemSettings(this);
  30. if (!AllowMinimize)
  31. {
  32. CancelButton->Left = CancelButton->Left +
  33. (MinimizeButton->Left - CancelButton->Left) / 2;
  34. MinimizeButton->Visible = false;
  35. }
  36. else
  37. {
  38. SetGlobalMinimizeHandler(this, GlobalMinimize);
  39. }
  40. }
  41. //---------------------------------------------------------------------------
  42. __fastcall TSynchronizeProgressForm::~TSynchronizeProgressForm()
  43. {
  44. ClearGlobalMinimizeHandler(GlobalMinimize);
  45. ReleaseAsModal(this, FShowAsModalStorage);
  46. if (IsApplicationMinimized() && FMinimizedByMe)
  47. {
  48. ShowNotification(
  49. NULL, MainInstructions(LoadStr(BALLOON_OPERATION_COMPLETE)),
  50. qtInformation);
  51. }
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TSynchronizeProgressForm::Start()
  55. {
  56. FStarted = true;
  57. FStartTime = Now();
  58. UpdateTimer->Enabled = true;
  59. StartTimeLabel->Caption = FStartTime.TimeString();
  60. Caption = FormatFormCaption(this, LoadStr(FCompareOnly ? SYNCHRONIZE_PROGRESS_COMPARE : SYNCHRONIZE_PROGRESS_SYNCHRONIZE2));
  61. if (!IsApplicationMinimized())
  62. {
  63. // Do not showing the progress when the application is minimized,
  64. // otherwise the form popups up unminimized.
  65. // Quick and dirty hack: with this form, we do not support showing it
  66. // once the application restores,
  67. // otherwise we would have to synchronize it somehow with the TProgressForm,
  68. // not to show it over the TProgressForm
  69. ShowAsModal(this, FShowAsModalStorage);
  70. }
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TSynchronizeProgressForm::SetData(const UnicodeString LocalDirectory,
  74. const UnicodeString RemoteDirectory, bool & Continue)
  75. {
  76. assert(FStarted);
  77. LocalDirectoryLabel->Caption = LocalDirectory;
  78. RemoteDirectoryLabel->Caption = RemoteDirectory;
  79. Continue = !FCanceled;
  80. UpdateControls();
  81. Application->ProcessMessages();
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TSynchronizeProgressForm::UpdateControls()
  85. {
  86. if (FStarted)
  87. {
  88. FElapsed = Now() - FStartTime;
  89. }
  90. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FElapsed);
  91. CancelButton->Enabled = !FCanceled;
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TSynchronizeProgressForm::CancelOperation()
  95. {
  96. FCanceled = true;
  97. UpdateControls();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TSynchronizeProgressForm::CancelButtonClick(TObject * /*Sender*/)
  101. {
  102. CancelOperation();
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TSynchronizeProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  106. {
  107. UpdateControls();
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TSynchronizeProgressForm::MinimizeButtonClick(
  111. TObject * Sender)
  112. {
  113. CallGlobalMinimizeHandler(Sender);
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TSynchronizeProgressForm::GlobalMinimize(TObject * /*Sender*/)
  117. {
  118. ApplicationMinimize();
  119. FMinimizedByMe = true;
  120. }
  121. //---------------------------------------------------------------------------
  122. void __fastcall TSynchronizeProgressForm::Dispatch(void * AMessage)
  123. {
  124. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  125. if (Message.Msg == WM_CLOSE)
  126. {
  127. CancelOperation();
  128. }
  129. else
  130. {
  131. TForm::Dispatch(AMessage);
  132. }
  133. }
  134. //---------------------------------------------------------------------------