Ticket #13686: 0001-Web-Use-BDurationFormat-to-format-time-remaining-in-.patch

File 0001-Web-Use-BDurationFormat-to-format-time-remaining-in-.patch, 3.5 KB (added by akshay, 7 years ago)
  • src/apps/webpositive/DownloadProgressView.cpp

    From cc8acfd5178dcc5fd94724a20a6f475c7c11a5a5 Mon Sep 17 00:00:00 2001
    From: Akshay Agarwal <agarwal.akshay.akshay8@gmail.com>
    Date: Sun, 27 Aug 2017 10:33:18 +0530
    Subject: [PATCH] Web+: Use BDurationFormat to format time remaining in
     Downloads.
    
    ---
     src/apps/webpositive/DownloadProgressView.cpp | 65 ++++-----------------------
     1 file changed, 9 insertions(+), 56 deletions(-)
    
    diff --git a/src/apps/webpositive/DownloadProgressView.cpp b/src/apps/webpositive/DownloadProgressView.cpp
    index 2e50c96..a76f1da 100644
    a b  
    1515#include <Catalog.h>
    1616#include <Clipboard.h>
    1717#include <Directory.h>
     18#include <DurationFormat.h>
    1819#include <Entry.h>
    1920#include <FindDirectory.h>
    2021#include <GroupLayoutBuilder.h>
    DownloadProgressView::_UpdateStatusText()  
    785786            * 1000000LL / (system_time() - fEstimatedFinishReferenceTime);
    786787        double secondsRemaining = (fExpectedSize - fCurrentSize)
    787788            / totalBytesPerSecond;
    788         time_t now = (time_t)real_time_clock();
    789         time_t finishTime = (time_t)(now + secondsRemaining);
    790 
    791         tm _time;
    792         tm* time = localtime_r(&finishTime, &_time);
    793         int32 year = time->tm_year + 1900;
    794 
    795         char timeText[32];
    796         time_t secondsPerDay = 24 * 60 * 60;
    797         // TODO: Localization of time string...
    798         if (now < finishTime - secondsPerDay) {
    799             // process is going to take more than a day!
    800             sprintf(timeText, "%0*d:%0*d %0*d/%0*d/%" B_PRId32,
    801                 2, time->tm_hour, 2, time->tm_min,
    802                 2, time->tm_mon + 1, 2, time->tm_mday, year);
    803         } else {
    804             sprintf(timeText, "%0*d:%0*d",
    805                 2, time->tm_hour, 2, time->tm_min);
    806         }
    807 
    808         BString buffer1(B_TRANSLATE_COMMENT("Finish: ", "Finishing time"));
    809         buffer1 << timeText;
    810         finishTime -= now;
    811         time = gmtime(&finishTime);
    812 
    813         BTimeUnitFormat timeFormat;
    814789
     790        BString buffer1(B_TRANSLATE("Time Left"));
     791        buffer1 << ": ";
    815792        BString buffer2;
    816         if (finishTime > secondsPerDay) {
    817             int64 days = finishTime / secondsPerDay;
    818 
    819             BString time;
    820             timeFormat.Format(time, days, B_TIME_UNIT_DAY);
    821 
    822             buffer2 << B_TRANSLATE("Over %days left");
    823             buffer2.ReplaceFirst("%days", time);
    824         } else if (finishTime > 60 * 60) {
    825             int64 hours = finishTime / (60 * 60);
    826             BString time;
    827             timeFormat.Format(time, hours, B_TIME_UNIT_HOUR);
    828 
    829             buffer2 << B_TRANSLATE("Over %hours left");
    830             buffer2.ReplaceFirst("%hours", time);
    831         } else if (finishTime > 60) {
    832             int64 minutes = finishTime / 60;
    833             if (minutes == 1)
    834                 buffer2 << B_TRANSLATE("Over 1 minute left");
    835             else
    836                 timeFormat.Format(buffer2, minutes, B_TIME_UNIT_MINUTE);
    837         } else {
    838             BString time;
    839             timeFormat.Format(time, finishTime, B_TIME_UNIT_SECOND);
    840 
    841             buffer2 << B_TRANSLATE("%seconds left");
    842             buffer2.ReplaceFirst("%seconds", time);
    843         }
     793        BDurationFormat().Format(buffer2, 0, secondsRemaining * 1000000);
    844794
    845795        buffer = "(";
    846         buffer << buffer1 << " - " << buffer2 << ")";
     796        buffer << buffer1 << buffer2 << ")";
    847797
    848798        float stringWidth = fInfoView->StringWidth(buffer.String());
    849799        if (stringWidth < fInfoView->Bounds().Width())
    850800            fInfoView->SetText(buffer.String());
    851801        else {
    852802            // complete string too wide, try with shorter version
     803            buffer2 = "";
     804            BDurationFormat(", ", B_TIME_UNIT_ABBREVIATED).Format(buffer2,
     805                0, secondsRemaining * 1000000 );
    853806            buffer = "(";
    854             buffer << buffer1 << ")";
     807            buffer << buffer1 << buffer2 << ")";
    855808            stringWidth = fInfoView->StringWidth(buffer.String());
    856809            if (stringWidth < fInfoView->Bounds().Width())
    857810                fInfoView->SetText(buffer.String());