SynchronizeProgress.cpp 4.0 KB

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