Ticket #13686: 0001-Use-formatters-from-locale-kit-to-format-time-remain.patch
File 0001-Use-formatters-from-locale-kit-to-format-time-remain.patch, 4.7 KB (added by , 7 years ago) |
---|
-
src/apps/webpositive/DownloadProgressView.cpp
From 43e20ed991ecfe7fc7282862d6996b807a0df83b Mon Sep 17 00:00:00 2001 From: Akshay Agarwal <agarwal.akshay.akshay8@gmail.com> Date: Tue, 29 Aug 2017 08:20:37 +0530 Subject: [PATCH] Use formatters from locale kit to format time remaining/finish time. --- src/apps/webpositive/DownloadProgressView.cpp | 84 +++++++++------------------ 1 file changed, 27 insertions(+), 57 deletions(-) diff --git a/src/apps/webpositive/DownloadProgressView.cpp b/src/apps/webpositive/DownloadProgressView.cpp index 2e50c96..447a1c8 100644
a b 15 15 #include <Catalog.h> 16 16 #include <Clipboard.h> 17 17 #include <Directory.h> 18 #include <DateTimeFormat.h> 19 #include <DurationFormat.h> 18 20 #include <Entry.h> 19 21 #include <FindDirectory.h> 20 22 #include <GroupLayoutBuilder.h> … … 28 30 #include <SpaceLayoutItem.h> 29 31 #include <StatusBar.h> 30 32 #include <StringView.h> 31 #include <Time UnitFormat.h>33 #include <TimeFormat.h> 32 34 33 35 #include "BrowserWindow.h" 34 36 #include "WebDownload.h" … … const bigtime_t kShowEstimatedFinishInterval = 4000000LL; 55 57 56 58 bigtime_t DownloadProgressView::sLastEstimatedFinishSpeedToggleTime = -1; 57 59 bool DownloadProgressView::sShowSpeed = true; 60 static const time_t kSecondsPerDay = 24 * 60 * 60; 61 static const time_t kSecondsPerHour = 60 * 60; 58 62 59 63 60 64 class IconView : public BView { … … DownloadProgressView::_UpdateStatusText() 788 792 time_t now = (time_t)real_time_clock(); 789 793 time_t finishTime = (time_t)(now + secondsRemaining); 790 794 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); 795 BString timeText; 796 if (finishTime - now > kSecondsPerDay) { 797 BDateTimeFormat().Format(timeText, finishTime, 798 B_MEDIUM_DATE_FORMAT, B_MEDIUM_TIME_FORMAT); 803 799 } else { 804 sprintf(timeText, "%0*d:%0*d",805 2, time->tm_hour, 2, time->tm_min);800 BTimeFormat().Format(timeText, finishTime, 801 B_MEDIUM_TIME_FORMAT); 806 802 } 807 803 808 BString buffer1(B_TRANSLATE_COMMENT("Finish: ", "Finishing time")); 809 buffer1 << timeText; 810 finishTime -= now; 811 time = gmtime(&finishTime); 812 813 BTimeUnitFormat timeFormat; 814 815 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); 804 BString statusString; 805 BDurationFormat formatter; 806 BString finishString; 807 if (finishTime - now > kSecondsPerHour) { 808 statusString.SetTo(B_TRANSLATE("(Finish: %time - Over %finishtime left)")); 809 formatter.Format(finishString, now * 1000000LL, finishTime * 1000000LL); 837 810 } 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); 811 statusString.SetTo(B_TRANSLATE("(Finish: %time - %finishtime left)")); 812 formatter.Format(finishString, now * 1000000LL, finishTime * 1000000LL); 843 813 } 844 814 845 buffer = "(";846 buffer << buffer1 << " - " << buffer2 << ")";815 statusString.ReplaceFirst("%time", timeText); 816 statusString.ReplaceFirst("%finishtime", finishString); 847 817 848 float stringWidth = fInfoView->StringWidth( buffer.String());818 float stringWidth = fInfoView->StringWidth(statusString.String()); 849 819 if (stringWidth < fInfoView->Bounds().Width()) 850 fInfoView->SetText( buffer.String());820 fInfoView->SetText(statusString.String()); 851 821 else { 852 822 // complete string too wide, try with shorter version 853 buffer = "(";854 buffer << buffer1 << ")";855 stringWidth = fInfoView->StringWidth( buffer.String());823 statusString.SetTo(B_TRANSLATE("(Finish: %time)")); 824 statusString.ReplaceFirst("%time", timeText); 825 stringWidth = fInfoView->StringWidth(statusString.String()); 856 826 if (stringWidth < fInfoView->Bounds().Width()) 857 fInfoView->SetText( buffer.String());827 fInfoView->SetText(statusString.String()); 858 828 } 859 829 } 860 830 }