Update the time and, optionally, the message
| 1352 | // Update the time and, optionally, the message |
| 1353 | // |
| 1354 | ProgressResult ProgressDialog::Update( |
| 1355 | int value, const TranslatableString & message) |
| 1356 | { |
| 1357 | using namespace std::chrono; |
| 1358 | auto updatePollTime = finally([this, pollStart = high_resolution_clock::now()] { |
| 1359 | mTotalPollTime += high_resolution_clock::now() - pollStart; |
| 1360 | }); |
| 1361 | |
| 1362 | mPollsCount++; |
| 1363 | |
| 1364 | if (mCancel) |
| 1365 | { |
| 1366 | // for compatibility with old Update, that returned false on cancel |
| 1367 | return ProgressResult::Cancelled; |
| 1368 | } |
| 1369 | else if (mStop) |
| 1370 | { |
| 1371 | return ProgressResult::Stopped; |
| 1372 | } |
| 1373 | |
| 1374 | wxLongLong_t now = wxGetUTCTimeMillis().GetValue(); |
| 1375 | mElapsedTime = now - mStartTime; |
| 1376 | |
| 1377 | if (mElapsedTime < 500) |
| 1378 | { |
| 1379 | return ProgressResult::Success; |
| 1380 | } |
| 1381 | |
| 1382 | if (mIsTransparent) |
| 1383 | { |
| 1384 | SetTransparent(255); |
| 1385 | mIsTransparent = false; |
| 1386 | } |
| 1387 | |
| 1388 | if (value <= 0) |
| 1389 | { |
| 1390 | value = 1; |
| 1391 | } |
| 1392 | |
| 1393 | if (value > 1000) |
| 1394 | { |
| 1395 | value = 1000; |
| 1396 | } |
| 1397 | |
| 1398 | wxLongLong_t estimate = mElapsedTime * 1000ll / value; |
| 1399 | wxLongLong_t remains = (estimate + mStartTime) - now; |
| 1400 | |
| 1401 | SetMessage(message); |
| 1402 | |
| 1403 | if (value != mLastValue) |
| 1404 | { |
| 1405 | mGauge->SetValue(value); |
| 1406 | mGauge->Update(); |
| 1407 | mLastValue = value; |
| 1408 | } |
| 1409 | |
| 1410 | // Only update if a full second has passed or track progress is complete |
| 1411 | if ((now - mLastUpdate > 1000) || (value == 1000)) |