Progress.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <CoreMain.h>
  6. #include <TextsWin.h>
  7. #include <HelpWin.h>
  8. #include <WinInterface.h>
  9. #include <VCLCommon.h>
  10. #include <CustomWinConfiguration.h>
  11. #include <GUITools.h>
  12. #include <BaseUtils.hpp>
  13. #include <DateUtils.hpp>
  14. #include <Consts.hpp>
  15. #include <HistoryComboBox.hpp>
  16. #include "Progress.h"
  17. //---------------------------------------------------------------------
  18. #pragma link "PathLabel"
  19. #pragma link "PngImageList"
  20. #pragma link "TB2Dock"
  21. #pragma link "TB2Item"
  22. #pragma link "TB2Toolbar"
  23. #pragma link "TBX"
  24. #pragma link "TB2ExtItems"
  25. #pragma link "TBXExtItems"
  26. #ifndef NO_RESOURCES
  27. #pragma resource "*.dfm"
  28. #endif
  29. //---------------------------------------------------------------------
  30. bool __fastcall TProgressForm::IsIndeterminateOperation(TFileOperation Operation)
  31. {
  32. return (Operation == foCalculateSize);
  33. }
  34. //---------------------------------------------------------------------
  35. UnicodeString __fastcall TProgressForm::ProgressStr(
  36. const TSynchronizeProgress * SynchronizeProgress, const TFileOperationProgressType * ProgressData)
  37. {
  38. static const int Captions[] = { 0, 0, PROGRESS_DELETE,
  39. PROGRESS_SETPROPERTIES, 0, PROGRESS_CUSTOM_COMAND, PROGRESS_CALCULATE_SIZE,
  40. PROGRESS_REMOTE_MOVE, PROGRESS_REMOTE_COPY, PROGRESS_GETPROPERTIES,
  41. PROGRESS_CALCULATE_CHECKSUM, PROGRESS_LOCK, PROGRESS_UNLOCK };
  42. DebugAssert((unsigned int)ProgressData->Operation >= 1 && ((unsigned int)ProgressData->Operation - 1) < LENOF(Captions));
  43. int Id;
  44. if ((ProgressData->Operation == foCopy) || (ProgressData->Operation == foMove))
  45. {
  46. Id = (ProgressData->Side == osLocal) ? PROGRESS_UPLOAD : PROGRESS_DOWNLOAD;
  47. }
  48. else
  49. {
  50. Id = Captions[(int)ProgressData->Operation - 1];
  51. DebugAssert(Id != 0);
  52. }
  53. UnicodeString Result = LoadStr(Id);
  54. if (SynchronizeProgress != NULL)
  55. {
  56. Result = FORMAT(L"%d%% %s - %s", (SynchronizeProgress->Progress(), LoadStr(SYNCHRONIZE_PROGRESS_SYNCHRONIZE2), Result));
  57. }
  58. else if (!IsIndeterminateOperation(ProgressData->Operation))
  59. {
  60. Result = FORMAT(L"%d%% %s", (ProgressData->OverallProgress(), Result));
  61. }
  62. return Result;
  63. }
  64. //---------------------------------------------------------------------
  65. __fastcall TProgressForm::TProgressForm(
  66. TComponent * AOwner, bool AllowMoveToQueue, bool AllowSkip, TSynchronizeProgress * SynchronizeProgress)
  67. : FData(), TForm(AOwner)
  68. {
  69. FLastOperation = foNone;
  70. FLastSide = (TOperationSide)-1;
  71. FLastTotalSizeSet = false;
  72. FDataGot = false;
  73. FDataReceived = false;
  74. FCancel = csContinue;
  75. FMoveToQueue = false;
  76. FMinimizedByMe = false;
  77. FUpdateCounter = 0;
  78. FDeleteLocalToRecycleBin = false;
  79. FDeleteRemoteToRecycleBin = false;
  80. FReadOnly = false;
  81. FShowAsModalStorage = NULL;
  82. FStarted = Now();
  83. FModalBeginHooked = false;
  84. FModalLevel = -1;
  85. FPendingSkip = false;
  86. FSynchronizeProgress = SynchronizeProgress;
  87. FAllowSkip = AllowSkip;
  88. UseSystemSettings(this);
  89. FOnceDoneItems.Add(odoIdle, IdleOnceDoneItem);
  90. FOnceDoneItems.Add(odoDisconnect, DisconnectOnceDoneItem);
  91. FOnceDoneItems.Add(odoSuspend, SuspendOnceDoneItem);
  92. FOnceDoneItems.Add(odoShutDown, ShutDownOnceDoneItem);
  93. ResetOnceDoneOperation();
  94. HideComponentsPanel(this);
  95. SelectScaledImageList(ImageList);
  96. SetGlobalMinimizeHandler(this, GlobalMinimize);
  97. MoveToQueueItem->Visible = AllowMoveToQueue;
  98. }
  99. //---------------------------------------------------------------------------
  100. __fastcall TProgressForm::~TProgressForm()
  101. {
  102. // to prevent raising assertion (e.g. IsProgress == True)
  103. FData.Clear();
  104. ClearGlobalMinimizeHandler(GlobalMinimize);
  105. if (IsApplicationMinimized() && FMinimizedByMe)
  106. {
  107. ShowNotification(
  108. NULL, MainInstructions(LoadStr(BALLOON_OPERATION_COMPLETE)),
  109. qtInformation);
  110. }
  111. ReleaseAsModal(this, FShowAsModalStorage);
  112. }
  113. //---------------------------------------------------------------------
  114. void __fastcall TProgressForm::UpdateControls()
  115. {
  116. DebugAssert((FData.Operation >= foCopy) && (FData.Operation <= foUnlock) &&
  117. (FData.Operation != foRename));
  118. bool TransferOperation =
  119. ((FData.Operation == foCopy) || (FData.Operation == foMove));
  120. CancelItem->Enabled = !FReadOnly && (FCancel < csCancel);
  121. SkipItem->Visible = TransferOperation && FAllowSkip;
  122. SkipItem->Enabled = !FReadOnly && (FCancel < csCancelFile) && !FPendingSkip;
  123. MoveToQueueItem->Enabled = !FMoveToQueue && (FCancel == csContinue) && !FPendingSkip;
  124. CycleOnceDoneItem->Visible =
  125. !FReadOnly &&
  126. (FData.Operation != foCalculateSize) &&
  127. (FData.Operation != foGetProperties) &&
  128. (FData.Operation != foCalculateChecksum);
  129. CycleOnceDoneItem->ImageIndex = CurrentOnceDoneItem()->ImageIndex;
  130. SpeedComboBoxItem->Visible = TransferOperation;
  131. if ((FData.Operation != FLastOperation) ||
  132. (FData.Side != FLastSide))
  133. {
  134. UnicodeString Animation;
  135. UnicodeString CancelCaption = Vcl_Consts_SMsgDlgCancel;
  136. int MoveToQueueImageIndex = -1;
  137. FPendingSkip = false; // just in case
  138. int MoveTransferToQueueImageIndex;
  139. if (FData.Side == osRemote)
  140. {
  141. MoveTransferToQueueImageIndex = 7;
  142. }
  143. else
  144. {
  145. MoveTransferToQueueImageIndex = 8;
  146. }
  147. switch (FData.Operation)
  148. {
  149. case foCopy:
  150. if (FData.Side == osRemote)
  151. {
  152. Animation = L"CopyRemote";
  153. }
  154. else
  155. {
  156. Animation = L"CopyLocal";
  157. }
  158. MoveToQueueImageIndex = MoveTransferToQueueImageIndex;
  159. break;
  160. case foMove:
  161. if (FData.Side == osRemote)
  162. {
  163. Animation = L"MoveRemote";
  164. }
  165. else
  166. {
  167. Animation = L"MoveLocal";
  168. }
  169. MoveToQueueImageIndex = MoveTransferToQueueImageIndex;
  170. break;
  171. case foDelete:
  172. Animation = ((FData.Side == osRemote) ? DeleteRemoteToRecycleBin : DeleteLocalToRecycleBin) ? L"Recycle" : L"Delete";
  173. break;
  174. case foCalculateSize:
  175. Animation = L"CalculateSize";
  176. CancelCaption = LoadStr(SKIP_BUTTON);
  177. MoveToQueueImageIndex = MoveTransferToQueueImageIndex;
  178. break;
  179. case foSetProperties:
  180. Animation = "SetProperties";
  181. break;
  182. default:
  183. DebugAssert(
  184. (FData.Operation == foCustomCommand) ||
  185. (FData.Operation == foGetProperties) ||
  186. (FData.Operation == foCalculateChecksum) ||
  187. (FData.Operation == foLock) ||
  188. (FData.Operation == foUnlock) ||
  189. (FData.Operation == foRemoteCopy) ||
  190. (FData.Operation == foRemoteMove));
  191. break;
  192. }
  193. CancelItem->Caption = CancelCaption;
  194. OperationProgress->Style = IsIndeterminateOperation(FData.Operation) ? pbstMarquee : pbstNormal;
  195. if (SynchronizeProgress != NULL)
  196. {
  197. Animation = L"SynchronizeDirectories";
  198. }
  199. FFrameAnimation.Init(AnimationPaintBox, Animation);
  200. FFrameAnimation.Start();
  201. int Delta = 0;
  202. if (TransferOperation && !TransferPanel->Visible) Delta += TransferPanel->Height;
  203. else
  204. if (!TransferOperation && TransferPanel->Visible) Delta += -TransferPanel->Height;
  205. TransferPanel->Visible = TransferOperation;
  206. ClientHeight = ClientHeight + Delta;
  207. TargetLabel->Visible = TransferOperation;
  208. TargetPathLabel->Visible = TransferOperation;
  209. TargetPathLabel->UnixPath = (FData.Side == osLocal);
  210. FileLabel->UnixPath = (FData.Side == osRemote);
  211. PathLabel->Caption =
  212. LoadStr((FData.Operation == foCalculateSize) ? PROGRESS_PATH_LABEL : PROGRESS_FILE_LABEL);
  213. MoveToQueueItem->ImageIndex = MoveToQueueImageIndex;
  214. FLastOperation = FData.Operation;
  215. FLastSide = FData.Side;
  216. FLastTotalSizeSet = !FData.TotalSizeSet;
  217. }
  218. if (FLastTotalSizeSet != FData.TotalSizeSet)
  219. {
  220. StartTimeLabelLabel->Visible = !FData.TotalSizeSet;
  221. StartTimeLabel->Visible = !FData.TotalSizeSet;
  222. TimeLeftLabelLabel->Visible = FData.TotalSizeSet;
  223. TimeLeftLabel->Visible = FData.TotalSizeSet;
  224. FLastTotalSizeSet = FData.TotalSizeSet;
  225. }
  226. UnicodeString FileCaption;
  227. if ((FData.Operation == foCalculateSize) && DebugAlwaysTrue(!FData.Temp))
  228. {
  229. if (FData.Side == osRemote)
  230. {
  231. FileCaption = UnixExtractFileDir(FData.FullFileName);
  232. }
  233. else
  234. {
  235. FileCaption = ExtractFileDir(FData.FullFileName);
  236. }
  237. }
  238. else if ((FData.Side == osRemote) || !FData.Temp)
  239. {
  240. FileCaption = FData.FileName;
  241. }
  242. else
  243. {
  244. FileCaption = ExtractFileName(FData.FileName);
  245. }
  246. if (FileLabel->Caption != FileCaption)
  247. {
  248. FileLabel->Caption = FileCaption;
  249. FPendingSkip = false;
  250. }
  251. int OverallProgress;
  252. if (SynchronizeProgress != NULL)
  253. {
  254. OverallProgress = SynchronizeProgress->Progress();
  255. }
  256. else
  257. {
  258. if (IsIndeterminateOperation(FData.Operation))
  259. {
  260. OverallProgress = -1;
  261. }
  262. else
  263. {
  264. OverallProgress = FData.OverallProgress();
  265. }
  266. }
  267. OperationProgress->Position = std::max(0, OverallProgress);
  268. OperationProgress->Hint = (OverallProgress < 0) ? UnicodeString() : FORMAT(L"%d%%", (OverallProgress));
  269. Caption = FormatFormCaption(this, ProgressStr(SynchronizeProgress, &FData));
  270. if (TransferOperation)
  271. {
  272. if ((FData.Side == osLocal) || !FData.Temp)
  273. {
  274. TargetPathLabel->Caption = FData.Directory;
  275. }
  276. else
  277. {
  278. TargetPathLabel->Caption = LoadStr(PROGRESS_TEMP_DIR);
  279. }
  280. StartTimeLabel->Caption = FData.StartTime.TimeString();
  281. if (FData.TotalSizeSet)
  282. {
  283. TimeLeftLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat,
  284. FData.TotalTimeLeft());
  285. }
  286. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FData.TimeElapsed());
  287. BytesTransferredLabel->Caption = FormatBytes(FData.TotalTransferred);
  288. CPSLabel->Caption = FORMAT(L"%s/s", (FormatBytes(FData.CPS())));
  289. FileProgress->Position = FData.TransferProgress();
  290. FileProgress->Hint = FORMAT(L"%d%%", (FileProgress->Position));
  291. }
  292. }
  293. //---------------------------------------------------------------------
  294. static __int64 DelayStartInterval = MSecsPerSec / 2;
  295. static __int64 UpdateInterval = 1 * MSecsPerSec;
  296. //---------------------------------------------------------------------
  297. bool __fastcall TProgressForm::ReceiveData(bool Force, int ModalLevelOffset)
  298. {
  299. bool Result = false;
  300. if (FDataGot && !FDataReceived)
  301. {
  302. // CPS limit is set set only once from TFileOperationProgressType::Start.
  303. // Needs to be set even when data are not accepted yet, otherwise we would
  304. // write default value to FData in TProgressForm::SetProgressData
  305. FCPSLimit = FData.CPSLimit;
  306. // Never popup over dialog that appeared later than we started
  307. // (this can happen from UpdateTimerTimer when application is
  308. // restored while overwrite confirmation dialog [or any other]
  309. // is already shown).
  310. // TODO We should probably take as-modal windows into account too
  311. // (for extreme cases like restoring while reconnecting [as-modal TAuthenticateForm]).
  312. if ((FModalLevel < 0) || (Application->ModalLevel + ModalLevelOffset <= FModalLevel))
  313. {
  314. // Delay showing the progress until the application is restored,
  315. // otherwise the form popups up unminimized.
  316. // See solution in TMessageForm::CMShowingChanged.
  317. if (!IsApplicationMinimized() &&
  318. (Force || (MilliSecondsBetween(Now(), FStarted) > DelayStartInterval)))
  319. {
  320. FDataReceived = true;
  321. SpeedComboBoxItem->Text = SetSpeedLimit(FCPSLimit);
  322. ShowAsModal(this, FShowAsModalStorage);
  323. // particularly needed for the case, when we are showing the form delayed
  324. // because application was minimized when operation started
  325. Result = true;
  326. }
  327. else if (!FModalBeginHooked && DebugAlwaysTrue(FModalLevel < 0))
  328. {
  329. // record state as of time, the window should be shown,
  330. // had not we implemented delayed show
  331. ApplicationEvents->OnModalBegin = ApplicationModalBegin;
  332. FModalBeginHooked = true;
  333. FModalLevel = Application->ModalLevel;
  334. }
  335. }
  336. }
  337. return Result;
  338. }
  339. //---------------------------------------------------------------------------
  340. void __fastcall TProgressForm::ApplicationModalBegin(TObject * /*Sender*/)
  341. {
  342. // Popup before any modal dialog shows (typically overwrite confirmation,
  343. // as that popups nearly instantly, i.e. less than DelayStartInterval).
  344. // The Application->ModalLevel is already incremented, but we should treat it as
  345. // if it were not as the dialog is not created yet (so we can popup if we are not yet).
  346. ReceiveData(true, -1);
  347. }
  348. //---------------------------------------------------------------------
  349. void __fastcall TProgressForm::SetProgressData(TFileOperationProgressType & AData)
  350. {
  351. bool InstantUpdate = false;
  352. // workaround: to force displaing first file data immediately,
  353. // otherwise form dialog uses to be blank for first second
  354. // (until UpdateTimerTimer)
  355. if (FileLabel->Caption.IsEmpty() && !AData.FileName.IsEmpty())
  356. {
  357. InstantUpdate = true;
  358. }
  359. FData.AssignButKeepSuspendState(AData);
  360. FDataGot = true;
  361. if (!UpdateTimer->Enabled)
  362. {
  363. UpdateTimer->Interval = static_cast<int>(DelayStartInterval);
  364. UpdateTimer->Enabled = true;
  365. FSinceLastUpdate = 0;
  366. }
  367. if (ReceiveData(false, 0))
  368. {
  369. InstantUpdate = true;
  370. }
  371. if (InstantUpdate)
  372. {
  373. UpdateControls();
  374. Application->ProcessMessages();
  375. }
  376. if (ProcessGUI(FUpdateCounter % 5 == 0))
  377. {
  378. FUpdateCounter = 0;
  379. }
  380. FUpdateCounter++;
  381. AData.SetCPSLimit(FCPSLimit);
  382. }
  383. //---------------------------------------------------------------------------
  384. void __fastcall TProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  385. {
  386. // popup the progress window at least here, if SetProgressData is
  387. // not being called (typically this happens when using custom command
  388. // that launches long-lasting external process, such as visual diff)
  389. ReceiveData(false, 0);
  390. if (UpdateTimer->Interval == DelayStartInterval)
  391. {
  392. UpdateTimer->Interval = static_cast<int>(GUIUpdateInterval);
  393. }
  394. if (FDataReceived)
  395. {
  396. FSinceLastUpdate += UpdateTimer->Interval;
  397. if (FSinceLastUpdate >= UpdateInterval)
  398. {
  399. UpdateControls();
  400. FSinceLastUpdate = 0;
  401. }
  402. }
  403. }
  404. //---------------------------------------------------------------------------
  405. void __fastcall TProgressForm::FormShow(TObject * /*Sender*/)
  406. {
  407. CopySpeedLimits(CustomWinConfiguration->History[L"SpeedLimit"], SpeedComboBoxItem->Strings);
  408. ReceiveData(false, 0);
  409. if (FDataReceived)
  410. {
  411. UpdateControls();
  412. }
  413. // HACK: In command-line run (/upload), FormShow gets called twice,
  414. // leading to duplicate hook and memory leak. Make sure we unhook, just in case.
  415. // Calling unhook without hooking first is noop.
  416. UnhookFormActivation(this);
  417. HookFormActivation(this);
  418. }
  419. //---------------------------------------------------------------------------
  420. void __fastcall TProgressForm::FormHide(TObject * /*Sender*/)
  421. {
  422. UnhookFormActivation(this);
  423. // This is to counter the "infinite" timestamp in
  424. // TTerminalManager::ApplicationShowHint.
  425. // Because if form disappears on its own, hint is not hidden.
  426. Application->CancelHint();
  427. CustomWinConfiguration->History[L"SpeedLimit"] = SpeedComboBoxItem->Strings;
  428. UpdateTimer->Enabled = false;
  429. }
  430. //---------------------------------------------------------------------------
  431. void __fastcall TProgressForm::CancelItemClick(TObject * /*Sender*/)
  432. {
  433. CancelOperation();
  434. }
  435. //---------------------------------------------------------------------------
  436. void __fastcall TProgressForm::Minimize(TObject * Sender)
  437. {
  438. CallGlobalMinimizeHandler(Sender);
  439. }
  440. //---------------------------------------------------------------------------
  441. void __fastcall TProgressForm::MinimizeItemClick(TObject * Sender)
  442. {
  443. Minimize(Sender);
  444. }
  445. //---------------------------------------------------------------------------
  446. void __fastcall TProgressForm::CancelOperation()
  447. {
  448. DebugAssert(FDataReceived);
  449. if (!FData.Suspended)
  450. {
  451. // mostly useless, as suspend is called over copy of actual progress data
  452. FData.Suspend();
  453. UpdateControls();
  454. try
  455. {
  456. TCancelStatus ACancel;
  457. if (FData.TransferringFile &&
  458. (FData.TimeExpected() > GUIConfiguration->IgnoreCancelBeforeFinish))
  459. {
  460. int Result = MessageDialog(LoadStr(CANCEL_OPERATION_FATAL2), qtWarning,
  461. qaYes | qaNo | qaCancel, HELP_PROGRESS_CANCEL);
  462. switch (Result)
  463. {
  464. case qaYes:
  465. ACancel = csCancelTransfer; break;
  466. case qaNo:
  467. ACancel = csCancel; break;
  468. default:
  469. ACancel = csContinue; break;
  470. }
  471. }
  472. else
  473. {
  474. ACancel = csCancel;
  475. }
  476. SetCancelLower(ACancel);
  477. }
  478. __finally
  479. {
  480. FData.Resume();
  481. }
  482. }
  483. }
  484. //---------------------------------------------------------------------------
  485. void __fastcall TProgressForm::GlobalMinimize(TObject * /*Sender*/)
  486. {
  487. ApplicationMinimize();
  488. FMinimizedByMe = true;
  489. }
  490. //---------------------------------------------------------------------------
  491. TTBCustomItem * __fastcall TProgressForm::CurrentOnceDoneItem()
  492. {
  493. TOnceDoneItems::const_iterator Iterator = FOnceDoneItems.begin();
  494. while (Iterator != FOnceDoneItems.end())
  495. {
  496. if (Iterator->second->Checked)
  497. {
  498. return Iterator->second;
  499. }
  500. Iterator++;
  501. }
  502. DebugFail();
  503. return NULL;
  504. }
  505. //---------------------------------------------------------------------------
  506. TOnceDoneOperation __fastcall TProgressForm::GetOnceDoneOperation()
  507. {
  508. return FOnceDoneItems.LookupFirst(CurrentOnceDoneItem());
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TProgressForm::SetOnceDoneItem(TTBCustomItem * Item)
  512. {
  513. TTBCustomItem * Current = CurrentOnceDoneItem();
  514. if (Current != Item)
  515. {
  516. Current->Checked = false;
  517. Item->Checked = true;
  518. // Not until we have any data to update.
  519. // Happens when set to odoDisconnect in command-line upload/download
  520. // mode from TCustomScpExplorerForm::FileOperationProgress.
  521. if (FDataGot)
  522. {
  523. UpdateControls();
  524. }
  525. }
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TProgressForm::SetOnceDoneOperation(TOnceDoneOperation value)
  529. {
  530. SetOnceDoneItem(FOnceDoneItems.LookupSecond(value));
  531. }
  532. //---------------------------------------------------------------------------
  533. bool __fastcall TProgressForm::GetAllowMinimize()
  534. {
  535. return MinimizeItem->Visible;
  536. }
  537. //---------------------------------------------------------------------------
  538. void __fastcall TProgressForm::SetAllowMinimize(bool value)
  539. {
  540. MinimizeItem->Visible = value;
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TProgressForm::SetReadOnly(bool value)
  544. {
  545. if (FReadOnly != value)
  546. {
  547. FReadOnly = value;
  548. if (!value)
  549. {
  550. ResetOnceDoneOperation();
  551. }
  552. UpdateControls();
  553. }
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TProgressForm::ResetOnceDoneOperation()
  557. {
  558. SetOnceDoneOperation(odoIdle);
  559. }
  560. //---------------------------------------------------------------------------
  561. void __fastcall TProgressForm::CMDialogKey(TCMDialogKey & Message)
  562. {
  563. if (Message.CharCode == VK_TAB)
  564. {
  565. Toolbar->KeyboardOpen(L'\0', false);
  566. Message.Result = 1;
  567. }
  568. else
  569. {
  570. TForm::Dispatch(&Message);
  571. }
  572. }
  573. //---------------------------------------------------------------------------
  574. void __fastcall TProgressForm::Dispatch(void * AMessage)
  575. {
  576. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  577. if (Message.Msg == WM_CLOSE)
  578. {
  579. CancelOperation();
  580. }
  581. else if (Message.Msg == CM_DIALOGKEY)
  582. {
  583. CMDialogKey(reinterpret_cast<TCMDialogKey &>(Message));
  584. }
  585. else
  586. {
  587. TForm::Dispatch(AMessage);
  588. }
  589. }
  590. //---------------------------------------------------------------------------
  591. void __fastcall TProgressForm::MoveToQueueItemClick(TObject * /*Sender*/)
  592. {
  593. FMoveToQueue = true;
  594. UpdateControls();
  595. }
  596. //---------------------------------------------------------------------------
  597. void __fastcall TProgressForm::OnceDoneItemClick(TObject * Sender)
  598. {
  599. SetOnceDoneItem(dynamic_cast<TTBCustomItem *>(Sender));
  600. }
  601. //---------------------------------------------------------------------------
  602. void __fastcall TProgressForm::CycleOnceDoneItemClick(TObject * /*Sender*/)
  603. {
  604. TTBCustomItem * Item = CurrentOnceDoneItem();
  605. int Index = Item->Parent->IndexOf(Item);
  606. DebugAssert(Index >= 0);
  607. if (Index < Item->Parent->Count - 1)
  608. {
  609. Index++;
  610. }
  611. else
  612. {
  613. Index = 0;
  614. }
  615. SetOnceDoneItem(Item->Parent->Items[Index]);
  616. }
  617. //---------------------------------------------------------------------------
  618. UnicodeString __fastcall TProgressForm::ItemSpeed(const UnicodeString & Text,
  619. TTBXComboBoxItem * Item)
  620. {
  621. // Keep in sync with TNonVisualDataModule::QueueItemSpeed
  622. FCPSLimit = GetSpeedLimit(Text);
  623. UnicodeString Result = SetSpeedLimit(FCPSLimit);
  624. SaveToHistory(Item->Strings, Result);
  625. CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
  626. return Result;
  627. }
  628. //---------------------------------------------------------------------------
  629. void __fastcall TProgressForm::SpeedComboBoxItemAcceptText(TObject * Sender,
  630. UnicodeString & NewText, bool & /*Accept*/)
  631. {
  632. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  633. NewText = ItemSpeed(NewText, Item);
  634. }
  635. //---------------------------------------------------------------------------
  636. void __fastcall TProgressForm::SpeedComboBoxItemItemClick(TObject * Sender)
  637. {
  638. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  639. Item->Text = ItemSpeed(Item->Text, Item);
  640. }
  641. //---------------------------------------------------------------------------
  642. void __fastcall TProgressForm::SpeedComboBoxItemAdjustImageIndex(
  643. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int /*AIndex*/, int & ImageIndex)
  644. {
  645. // Use fixed image (do not change image by item index)
  646. ImageIndex = Sender->ImageIndex;
  647. }
  648. //---------------------------------------------------------------------------
  649. void __fastcall TProgressForm::SpeedComboBoxItemClick(TObject * Sender)
  650. {
  651. ClickToolbarItem(DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender)), false);
  652. }
  653. //---------------------------------------------------------------------------
  654. void __fastcall TProgressForm::ClearCancel()
  655. {
  656. if (DebugAlwaysTrue(FCancel == csCancelFile))
  657. {
  658. FPendingSkip = true;
  659. }
  660. FCancel = csContinue;
  661. UpdateControls();
  662. }
  663. //---------------------------------------------------------------------------
  664. void __fastcall TProgressForm::SetCancelLower(TCancelStatus ACancel)
  665. {
  666. if (FCancel < ACancel)
  667. {
  668. FCancel = ACancel;
  669. UpdateControls();
  670. }
  671. }
  672. //---------------------------------------------------------------------------
  673. void __fastcall TProgressForm::SkipItemClick(TObject * /*Sender*/)
  674. {
  675. SetCancelLower(csCancelFile);
  676. }
  677. //---------------------------------------------------------------------------