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. if (!IsGlobalMinimizeHandler())
  39. {
  40. SetGlobalMinimizeHandler(GlobalMinimize);
  41. };
  42. }
  43. }
  44. //---------------------------------------------------------------------------
  45. __fastcall TSynchronizeProgressForm::~TSynchronizeProgressForm()
  46. {
  47. if (GetGlobalMinimizeHandler() == GlobalMinimize)
  48. {
  49. SetGlobalMinimizeHandler(NULL);
  50. }
  51. ReleaseAsModal(this, FShowAsModalStorage);
  52. if (IsApplicationMinimized() && FMinimizedByMe)
  53. {
  54. ShowNotification(NULL, LoadStr(BALLOON_OPERATION_COMPLETE), qtInformation);
  55. }
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TSynchronizeProgressForm::Start()
  59. {
  60. FStarted = true;
  61. FStartTime = Now();
  62. UpdateTimer->Enabled = true;
  63. StartTimeLabel->Caption = FStartTime.TimeString();
  64. Caption = LoadStr(FCompareOnly ? SYNCHRONIZE_PROGRESS_COMPARE : SYNCHRONIZE_PROGRESS_SYNCHRONIZE);
  65. if (!IsApplicationMinimized())
  66. {
  67. // Do not showing the progress when the application is minimized,
  68. // otherwise the form popups up unminimized.
  69. // Quick as dirty hack: with this form, we do not support showing it
  70. // once the application restores,
  71. // otherwise we would have to synchronize it somehow with the TProgressForm,
  72. // not to show it over the TProgressForm
  73. ShowAsModal(this, FShowAsModalStorage);
  74. }
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TSynchronizeProgressForm::Stop()
  78. {
  79. HideAsModal(this, FShowAsModalStorage);
  80. FStarted = false;
  81. UpdateTimer->Enabled = false;
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TSynchronizeProgressForm::SetData(const UnicodeString LocalDirectory,
  85. const UnicodeString RemoteDirectory, bool & Continue)
  86. {
  87. assert(FStarted);
  88. LocalDirectoryLabel->Caption = LocalDirectory;
  89. RemoteDirectoryLabel->Caption = RemoteDirectory;
  90. Continue = !FCanceled;
  91. UpdateControls();
  92. Application->ProcessMessages();
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TSynchronizeProgressForm::UpdateControls()
  96. {
  97. if (FStarted)
  98. {
  99. FElapsed = Now() - FStartTime;
  100. }
  101. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FElapsed);
  102. }
  103. //---------------------------------------------------------------------------
  104. void __fastcall TSynchronizeProgressForm::CancelButtonClick(TObject * /*Sender*/)
  105. {
  106. if (!FCanceled && (MessageDialog(LoadStr(CANCEL_OPERATION), qtConfirmation,
  107. qaOK | qaCancel, HELP_NONE) == qaOK))
  108. {
  109. FCanceled = true;
  110. }
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TSynchronizeProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  114. {
  115. UpdateControls();
  116. }
  117. //---------------------------------------------------------------------------
  118. void __fastcall TSynchronizeProgressForm::MinimizeButtonClick(
  119. TObject * Sender)
  120. {
  121. GetGlobalMinimizeHandler()(Sender);
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TSynchronizeProgressForm::GlobalMinimize(TObject * /*Sender*/)
  125. {
  126. MinimizeApp();
  127. }
  128. //---------------------------------------------------------------------------
  129. void __fastcall TSynchronizeProgressForm::MinimizeApp()
  130. {
  131. Application->Minimize();
  132. FMinimizedByMe = true;
  133. }
  134. //---------------------------------------------------------------------------