SynchronizeProgress.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TSynchronizeProgressForm::CancelOperation()
  94. {
  95. if (!FCanceled && (MessageDialog(LoadStr(CANCEL_OPERATION2), qtConfirmation,
  96. qaYes | qaNo, HELP_NONE) == qaYes))
  97. {
  98. FCanceled = true;
  99. }
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TSynchronizeProgressForm::CancelButtonClick(TObject * /*Sender*/)
  103. {
  104. CancelOperation();
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TSynchronizeProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  108. {
  109. UpdateControls();
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TSynchronizeProgressForm::MinimizeButtonClick(
  113. TObject * Sender)
  114. {
  115. CallGlobalMinimizeHandler(Sender);
  116. }
  117. //---------------------------------------------------------------------------
  118. void __fastcall TSynchronizeProgressForm::GlobalMinimize(TObject * /*Sender*/)
  119. {
  120. ApplicationMinimize();
  121. FMinimizedByMe = true;
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TSynchronizeProgressForm::Dispatch(void * AMessage)
  125. {
  126. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  127. if (Message.Msg == WM_CLOSE)
  128. {
  129. CancelOperation();
  130. }
  131. else
  132. {
  133. TForm::Dispatch(AMessage);
  134. }
  135. }
  136. //---------------------------------------------------------------------------