Progress.cpp 22 KB

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