1
0

SynchronizeProgress.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 link "PngImageList"
  17. #pragma link "TB2Dock"
  18. #pragma link "TB2Item"
  19. #pragma link "TB2Toolbar"
  20. #pragma link "TBX"
  21. #pragma resource "*.dfm"
  22. #endif
  23. //---------------------------------------------------------------------------
  24. __fastcall TSynchronizeProgressForm::TSynchronizeProgressForm(TComponent * Owner,
  25. bool AllowMinimize, bool CompareOnly)
  26. : TForm(Owner)
  27. {
  28. FStarted = false;
  29. FCanceled = false;
  30. FElapsed = EncodeTimeVerbose(0, 0, 0, 0);
  31. FShowAsModalStorage = NULL;
  32. FMinimizedByMe = false;
  33. FCompareOnly = CompareOnly;
  34. UseSystemSettings(this);
  35. HideComponentsPanel(this);
  36. SelectScaledImageList(ImageList);
  37. if (!AllowMinimize)
  38. {
  39. MinimizeItem->Visible = false;
  40. }
  41. else
  42. {
  43. SetGlobalMinimizeHandler(this, GlobalMinimize);
  44. }
  45. FFrameAnimation.Init(AnimationPaintBox, L"SynchronizeDirectories");
  46. }
  47. //---------------------------------------------------------------------------
  48. __fastcall TSynchronizeProgressForm::~TSynchronizeProgressForm()
  49. {
  50. ClearGlobalMinimizeHandler(GlobalMinimize);
  51. ReleaseAsModal(this, FShowAsModalStorage);
  52. UnhookFormActivation(this);
  53. if (IsApplicationMinimized() && FMinimizedByMe)
  54. {
  55. ShowNotification(
  56. NULL, MainInstructions(LoadStr(BALLOON_OPERATION_COMPLETE)),
  57. qtInformation);
  58. }
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TSynchronizeProgressForm::Start()
  62. {
  63. FStarted = true;
  64. FStartTime = Now();
  65. UpdateTimer->Enabled = true;
  66. StartTimeLabel->Caption = FStartTime.TimeString();
  67. Caption = FormatFormCaption(this, LoadStr(FCompareOnly ? SYNCHRONIZE_PROGRESS_COMPARE : SYNCHRONIZE_PROGRESS_SYNCHRONIZE2));
  68. if (!IsApplicationMinimized())
  69. {
  70. // Do not show the progress when the application is minimized,
  71. // otherwise the form popups up unminimized.
  72. // Quick and dirty hack: with this form, we do not support showing it
  73. // once the application restores,
  74. // otherwise we would have to synchronize it somehow with the TProgressForm,
  75. // not to show it over the TProgressForm
  76. // See solution in TMessageForm::CMShowingChanged.
  77. ShowAsModal(this, FShowAsModalStorage);
  78. HookFormActivation(this);
  79. }
  80. FFrameAnimation.Start();
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TSynchronizeProgressForm::SetData(const UnicodeString LocalDirectory,
  84. const UnicodeString RemoteDirectory, bool & Continue)
  85. {
  86. DebugAssert(FStarted);
  87. LocalDirectoryLabel->Caption = LocalDirectory;
  88. RemoteDirectoryLabel->Caption = RemoteDirectory;
  89. Continue = !FCanceled;
  90. UpdateControls();
  91. Application->ProcessMessages();
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TSynchronizeProgressForm::UpdateControls()
  95. {
  96. if (FStarted)
  97. {
  98. FElapsed = Now() - FStartTime;
  99. }
  100. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FElapsed);
  101. CancelItem->Enabled = !FCanceled;
  102. }
  103. //---------------------------------------------------------------------------
  104. void __fastcall TSynchronizeProgressForm::CancelOperation()
  105. {
  106. FCanceled = true;
  107. UpdateControls();
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TSynchronizeProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  111. {
  112. UpdateControls();
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TSynchronizeProgressForm::GlobalMinimize(TObject * /*Sender*/)
  116. {
  117. ApplicationMinimize();
  118. FMinimizedByMe = true;
  119. }
  120. //---------------------------------------------------------------------------
  121. void __fastcall TSynchronizeProgressForm::CMDialogKey(TCMDialogKey & Message)
  122. {
  123. if (Message.CharCode == VK_TAB)
  124. {
  125. Toolbar->KeyboardOpen(L'\0', false);
  126. Message.Result = 1;
  127. }
  128. else
  129. {
  130. TForm::Dispatch(&Message);
  131. }
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TSynchronizeProgressForm::Dispatch(void * AMessage)
  135. {
  136. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  137. if (Message.Msg == WM_CLOSE)
  138. {
  139. CancelOperation();
  140. }
  141. else if (Message.Msg == CM_DIALOGKEY)
  142. {
  143. CMDialogKey(reinterpret_cast<TCMDialogKey &>(Message));
  144. }
  145. else
  146. {
  147. TForm::Dispatch(AMessage);
  148. }
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TSynchronizeProgressForm::CancelItemClick(TObject * /*Sender*/)
  152. {
  153. CancelOperation();
  154. }
  155. //---------------------------------------------------------------------------
  156. void __fastcall TSynchronizeProgressForm::MinimizeItemClick(TObject * Sender)
  157. {
  158. CallGlobalMinimizeHandler(Sender);
  159. }
  160. //---------------------------------------------------------------------------