Progress.cpp 23 KB

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