Progress.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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 TSynchronizeChecklist * SynchronizeChecklist, 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 (!IsIndeterminateOperation(ProgressData->Operation))
  55. {
  56. Result = FORMAT(L"%d%% %s", (ProgressData->OverallProgress(), Result));
  57. }
  58. if (SynchronizeChecklist != NULL)
  59. {
  60. Result = FORMAT(L"%s - %s", (LoadStr(SYNCHRONIZE_PROGRESS_SYNCHRONIZE2), Result));
  61. }
  62. return Result;
  63. }
  64. //---------------------------------------------------------------------
  65. __fastcall TProgressForm::TProgressForm(
  66. TComponent * AOwner, bool AllowMoveToQueue, bool AllowSkip, const TSynchronizeChecklist * SynchronizeChecklist)
  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. FSynchronizeChecklist = SynchronizeChecklist;
  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 (FSynchronizeChecklist != 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 = FData.OverallProgress();
  252. OperationProgress->Position = OverallProgress;
  253. OperationProgress->Hint = IsIndeterminateOperation(FData.Operation) ? UnicodeString() : FORMAT(L"%d%%", (OverallProgress));
  254. Caption = FormatFormCaption(this, ProgressStr(FSynchronizeChecklist, &FData));
  255. if (TransferOperation)
  256. {
  257. if ((FData.Side == osLocal) || !FData.Temp)
  258. {
  259. TargetPathLabel->Caption = FData.Directory;
  260. }
  261. else
  262. {
  263. TargetPathLabel->Caption = LoadStr(PROGRESS_TEMP_DIR);
  264. }
  265. StartTimeLabel->Caption = FData.StartTime.TimeString();
  266. if (FData.TotalSizeSet)
  267. {
  268. TimeLeftLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat,
  269. FData.TotalTimeLeft());
  270. }
  271. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FData.TimeElapsed());
  272. BytesTransferredLabel->Caption = FormatBytes(FData.TotalTransferred);
  273. CPSLabel->Caption = FORMAT(L"%s/s", (FormatBytes(FData.CPS())));
  274. FileProgress->Position = FData.TransferProgress();
  275. FileProgress->Hint = FORMAT(L"%d%%", (FileProgress->Position));
  276. }
  277. }
  278. //---------------------------------------------------------------------
  279. static __int64 DelayStartInterval = MSecsPerSec / 2;
  280. static __int64 UpdateInterval = 1 * MSecsPerSec;
  281. //---------------------------------------------------------------------
  282. bool __fastcall TProgressForm::ReceiveData(bool Force, int ModalLevelOffset)
  283. {
  284. bool Result = false;
  285. if (FDataGot && !FDataReceived)
  286. {
  287. // CPS limit is set set only once from TFileOperationProgressType::Start.
  288. // Needs to be set even when data are not accepted yet, otherwise we would
  289. // write default value to FData in TProgressForm::SetProgressData
  290. FCPSLimit = FData.CPSLimit;
  291. // Never popup over dialog that appeared later than we started
  292. // (this can happen from UpdateTimerTimer when application is
  293. // restored while overwrite confirmation dialog [or any other]
  294. // is already shown).
  295. // TODO We should probably take as-modal windows into account too
  296. // (for extreme cases like restoring while reconnecting [as-modal TAuthenticateForm]).
  297. if ((FModalLevel < 0) || (Application->ModalLevel + ModalLevelOffset <= FModalLevel))
  298. {
  299. // Delay showing the progress until the application is restored,
  300. // otherwise the form popups up unminimized.
  301. // See solution in TMessageForm::CMShowingChanged.
  302. if (!IsApplicationMinimized() &&
  303. (Force || (MilliSecondsBetween(Now(), FStarted) > DelayStartInterval)))
  304. {
  305. FDataReceived = true;
  306. SpeedComboBoxItem->Text = SetSpeedLimit(FCPSLimit);
  307. ShowAsModal(this, FShowAsModalStorage);
  308. // particularly needed for the case, when we are showing the form delayed
  309. // because application was minimized when operation started
  310. Result = true;
  311. }
  312. else if (!FModalBeginHooked && DebugAlwaysTrue(FModalLevel < 0))
  313. {
  314. // record state as of time, the window should be shown,
  315. // had not we implemented delayed show
  316. ApplicationEvents->OnModalBegin = ApplicationModalBegin;
  317. FModalBeginHooked = true;
  318. FModalLevel = Application->ModalLevel;
  319. }
  320. }
  321. }
  322. return Result;
  323. }
  324. //---------------------------------------------------------------------------
  325. void __fastcall TProgressForm::ApplicationModalBegin(TObject * /*Sender*/)
  326. {
  327. // Popup before any modal dialog shows (typically overwrite confirmation,
  328. // as that popups nearly instantly, i.e. less than DelayStartInterval).
  329. // The Application->ModalLevel is already incremented, but we should treat it as
  330. // if it were not as the dialog is not created yet (so we can popup if we are not yet).
  331. ReceiveData(true, -1);
  332. }
  333. //---------------------------------------------------------------------
  334. void __fastcall TProgressForm::SetProgressData(TFileOperationProgressType & AData)
  335. {
  336. bool InstantUpdate = false;
  337. // workaround: to force displaing first file data immediately,
  338. // otherwise form dialog uses to be blank for first second
  339. // (until UpdateTimerTimer)
  340. if (FileLabel->Caption.IsEmpty() && !AData.FileName.IsEmpty())
  341. {
  342. InstantUpdate = true;
  343. }
  344. FData.AssignButKeepSuspendState(AData);
  345. FDataGot = true;
  346. if (!UpdateTimer->Enabled)
  347. {
  348. UpdateTimer->Interval = static_cast<int>(DelayStartInterval);
  349. UpdateTimer->Enabled = true;
  350. FSinceLastUpdate = 0;
  351. }
  352. if (ReceiveData(false, 0))
  353. {
  354. InstantUpdate = true;
  355. }
  356. if (InstantUpdate)
  357. {
  358. UpdateControls();
  359. Application->ProcessMessages();
  360. }
  361. if (ProcessGUI(FUpdateCounter % 5 == 0))
  362. {
  363. FUpdateCounter = 0;
  364. }
  365. FUpdateCounter++;
  366. AData.SetCPSLimit(FCPSLimit);
  367. }
  368. //---------------------------------------------------------------------------
  369. void __fastcall TProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  370. {
  371. // popup the progress window at least here, if SetProgressData is
  372. // not being called (typically this happens when using custom command
  373. // that launches long-lasting external process, such as visual diff)
  374. ReceiveData(false, 0);
  375. if (UpdateTimer->Interval == DelayStartInterval)
  376. {
  377. UpdateTimer->Interval = static_cast<int>(GUIUpdateInterval);
  378. }
  379. if (FDataReceived)
  380. {
  381. FSinceLastUpdate += UpdateTimer->Interval;
  382. if (FSinceLastUpdate >= UpdateInterval)
  383. {
  384. UpdateControls();
  385. FSinceLastUpdate = 0;
  386. }
  387. }
  388. }
  389. //---------------------------------------------------------------------------
  390. void __fastcall TProgressForm::FormShow(TObject * /*Sender*/)
  391. {
  392. CopySpeedLimits(CustomWinConfiguration->History[L"SpeedLimit"], SpeedComboBoxItem->Strings);
  393. ReceiveData(false, 0);
  394. if (FDataReceived)
  395. {
  396. UpdateControls();
  397. }
  398. // HACK: In command-line run (/upload), FormShow gets called twice,
  399. // leading to duplicate hook and memory leak. Make sure we unhook, just in case.
  400. // Calling unhook without hooking first is noop.
  401. UnhookFormActivation(this);
  402. HookFormActivation(this);
  403. }
  404. //---------------------------------------------------------------------------
  405. void __fastcall TProgressForm::FormHide(TObject * /*Sender*/)
  406. {
  407. UnhookFormActivation(this);
  408. // This is to counter the "infinite" timestamp in
  409. // TTerminalManager::ApplicationShowHint.
  410. // Because if form disappears on its own, hint is not hidden.
  411. Application->CancelHint();
  412. CustomWinConfiguration->History[L"SpeedLimit"] = SpeedComboBoxItem->Strings;
  413. UpdateTimer->Enabled = false;
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TProgressForm::CancelItemClick(TObject * /*Sender*/)
  417. {
  418. CancelOperation();
  419. }
  420. //---------------------------------------------------------------------------
  421. void __fastcall TProgressForm::Minimize(TObject * Sender)
  422. {
  423. CallGlobalMinimizeHandler(Sender);
  424. }
  425. //---------------------------------------------------------------------------
  426. void __fastcall TProgressForm::MinimizeItemClick(TObject * Sender)
  427. {
  428. Minimize(Sender);
  429. }
  430. //---------------------------------------------------------------------------
  431. void __fastcall TProgressForm::CancelOperation()
  432. {
  433. DebugAssert(FDataReceived);
  434. if (!FData.Suspended)
  435. {
  436. // mostly useless, as suspend is called over copy of actual progress data
  437. FData.Suspend();
  438. UpdateControls();
  439. try
  440. {
  441. TCancelStatus ACancel;
  442. if (FData.TransferringFile &&
  443. (FData.TimeExpected() > GUIConfiguration->IgnoreCancelBeforeFinish))
  444. {
  445. int Result = MessageDialog(LoadStr(CANCEL_OPERATION_FATAL2), qtWarning,
  446. qaYes | qaNo | qaCancel, HELP_PROGRESS_CANCEL);
  447. switch (Result)
  448. {
  449. case qaYes:
  450. ACancel = csCancelTransfer; break;
  451. case qaNo:
  452. ACancel = csCancel; break;
  453. default:
  454. ACancel = csContinue; break;
  455. }
  456. }
  457. else
  458. {
  459. ACancel = csCancel;
  460. }
  461. SetCancelLower(ACancel);
  462. }
  463. __finally
  464. {
  465. FData.Resume();
  466. }
  467. }
  468. }
  469. //---------------------------------------------------------------------------
  470. void __fastcall TProgressForm::GlobalMinimize(TObject * /*Sender*/)
  471. {
  472. ApplicationMinimize();
  473. FMinimizedByMe = true;
  474. }
  475. //---------------------------------------------------------------------------
  476. TTBCustomItem * __fastcall TProgressForm::CurrentOnceDoneItem()
  477. {
  478. TOnceDoneItems::const_iterator Iterator = FOnceDoneItems.begin();
  479. while (Iterator != FOnceDoneItems.end())
  480. {
  481. if (Iterator->second->Checked)
  482. {
  483. return Iterator->second;
  484. }
  485. Iterator++;
  486. }
  487. DebugFail();
  488. return NULL;
  489. }
  490. //---------------------------------------------------------------------------
  491. TOnceDoneOperation __fastcall TProgressForm::GetOnceDoneOperation()
  492. {
  493. return FOnceDoneItems.LookupFirst(CurrentOnceDoneItem());
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TProgressForm::SetOnceDoneItem(TTBCustomItem * Item)
  497. {
  498. TTBCustomItem * Current = CurrentOnceDoneItem();
  499. if (Current != Item)
  500. {
  501. Current->Checked = false;
  502. Item->Checked = true;
  503. // Not until we have any data to update.
  504. // Happens when set to odoDisconnect in command-line upload/download
  505. // mode from TCustomScpExplorerForm::FileOperationProgress.
  506. if (FDataGot)
  507. {
  508. UpdateControls();
  509. }
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TProgressForm::SetOnceDoneOperation(TOnceDoneOperation value)
  514. {
  515. SetOnceDoneItem(FOnceDoneItems.LookupSecond(value));
  516. }
  517. //---------------------------------------------------------------------------
  518. bool __fastcall TProgressForm::GetAllowMinimize()
  519. {
  520. return MinimizeItem->Visible;
  521. }
  522. //---------------------------------------------------------------------------
  523. void __fastcall TProgressForm::SetAllowMinimize(bool value)
  524. {
  525. MinimizeItem->Visible = value;
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TProgressForm::SetReadOnly(bool value)
  529. {
  530. if (FReadOnly != value)
  531. {
  532. FReadOnly = value;
  533. if (!value)
  534. {
  535. ResetOnceDoneOperation();
  536. }
  537. UpdateControls();
  538. }
  539. }
  540. //---------------------------------------------------------------------------
  541. void __fastcall TProgressForm::ResetOnceDoneOperation()
  542. {
  543. SetOnceDoneOperation(odoIdle);
  544. }
  545. //---------------------------------------------------------------------------
  546. void __fastcall TProgressForm::CMDialogKey(TCMDialogKey & Message)
  547. {
  548. if (Message.CharCode == VK_TAB)
  549. {
  550. Toolbar->KeyboardOpen(L'\0', false);
  551. Message.Result = 1;
  552. }
  553. else
  554. {
  555. TForm::Dispatch(&Message);
  556. }
  557. }
  558. //---------------------------------------------------------------------------
  559. void __fastcall TProgressForm::Dispatch(void * AMessage)
  560. {
  561. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  562. if (Message.Msg == WM_CLOSE)
  563. {
  564. CancelOperation();
  565. }
  566. else if (Message.Msg == CM_DIALOGKEY)
  567. {
  568. CMDialogKey(reinterpret_cast<TCMDialogKey &>(Message));
  569. }
  570. else
  571. {
  572. TForm::Dispatch(AMessage);
  573. }
  574. }
  575. //---------------------------------------------------------------------------
  576. void __fastcall TProgressForm::MoveToQueueItemClick(TObject * /*Sender*/)
  577. {
  578. FMoveToQueue = true;
  579. UpdateControls();
  580. }
  581. //---------------------------------------------------------------------------
  582. void __fastcall TProgressForm::OnceDoneItemClick(TObject * Sender)
  583. {
  584. SetOnceDoneItem(dynamic_cast<TTBCustomItem *>(Sender));
  585. }
  586. //---------------------------------------------------------------------------
  587. void __fastcall TProgressForm::CycleOnceDoneItemClick(TObject * /*Sender*/)
  588. {
  589. TTBCustomItem * Item = CurrentOnceDoneItem();
  590. int Index = Item->Parent->IndexOf(Item);
  591. DebugAssert(Index >= 0);
  592. if (Index < Item->Parent->Count - 1)
  593. {
  594. Index++;
  595. }
  596. else
  597. {
  598. Index = 0;
  599. }
  600. SetOnceDoneItem(Item->Parent->Items[Index]);
  601. }
  602. //---------------------------------------------------------------------------
  603. UnicodeString __fastcall TProgressForm::ItemSpeed(const UnicodeString & Text,
  604. TTBXComboBoxItem * Item)
  605. {
  606. // Keep in sync with TNonVisualDataModule::QueueItemSpeed
  607. FCPSLimit = GetSpeedLimit(Text);
  608. UnicodeString Result = SetSpeedLimit(FCPSLimit);
  609. SaveToHistory(Item->Strings, Result);
  610. CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
  611. return Result;
  612. }
  613. //---------------------------------------------------------------------------
  614. void __fastcall TProgressForm::SpeedComboBoxItemAcceptText(TObject * Sender,
  615. UnicodeString & NewText, bool & /*Accept*/)
  616. {
  617. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  618. NewText = ItemSpeed(NewText, Item);
  619. }
  620. //---------------------------------------------------------------------------
  621. void __fastcall TProgressForm::SpeedComboBoxItemItemClick(TObject * Sender)
  622. {
  623. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  624. Item->Text = ItemSpeed(Item->Text, Item);
  625. }
  626. //---------------------------------------------------------------------------
  627. void __fastcall TProgressForm::SpeedComboBoxItemAdjustImageIndex(
  628. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int /*AIndex*/, int & ImageIndex)
  629. {
  630. // Use fixed image (do not change image by item index)
  631. ImageIndex = Sender->ImageIndex;
  632. }
  633. //---------------------------------------------------------------------------
  634. void __fastcall TProgressForm::SpeedComboBoxItemClick(TObject * Sender)
  635. {
  636. ClickToolbarItem(DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender)), false);
  637. }
  638. //---------------------------------------------------------------------------
  639. void __fastcall TProgressForm::ClearCancel()
  640. {
  641. if (DebugAlwaysTrue(FCancel == csCancelFile))
  642. {
  643. FPendingSkip = true;
  644. }
  645. FCancel = csContinue;
  646. UpdateControls();
  647. }
  648. //---------------------------------------------------------------------------
  649. void __fastcall TProgressForm::SetCancelLower(TCancelStatus ACancel)
  650. {
  651. if (FCancel < ACancel)
  652. {
  653. FCancel = ACancel;
  654. UpdateControls();
  655. }
  656. }
  657. //---------------------------------------------------------------------------
  658. void __fastcall TProgressForm::SkipItemClick(TObject * /*Sender*/)
  659. {
  660. SetCancelLower(csCancelFile);
  661. }
  662. //---------------------------------------------------------------------------