Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: chrome/browser/download/download_item_model.cc

Issue 7189076: Localize strings, speeds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright dates Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/download/download_item_model.h" 5 #include "chrome/browser/download/download_item_model.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/download/download_item.h" 11 #include "chrome/browser/download/download_item.h"
12 #include "chrome/browser/download/save_package.h" 12 #include "chrome/browser/download/save_package.h"
13 #include "chrome/common/time_format.h" 13 #include "chrome/common/time_format.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/text/bytes_formatting.h"
16 17
17 using base::TimeDelta; 18 using base::TimeDelta;
18 19
19 // ----------------------------------------------------------------------------- 20 // -----------------------------------------------------------------------------
20 // DownloadItemModel 21 // DownloadItemModel
21 22
22 DownloadItemModel::DownloadItemModel(DownloadItem* download) 23 DownloadItemModel::DownloadItemModel(DownloadItem* download)
23 : BaseDownloadItemModel(download) { 24 : BaseDownloadItemModel(download) {
24 } 25 }
25 26
26 void DownloadItemModel::CancelTask() { 27 void DownloadItemModel::CancelTask() {
27 download_->Cancel(true /* update history service */); 28 download_->Cancel(true /* update history service */);
28 } 29 }
29 30
30 string16 DownloadItemModel::GetStatusText() { 31 string16 DownloadItemModel::GetStatusText() {
31 int64 size = download_->received_bytes(); 32 int64 size = download_->received_bytes();
32 int64 total = download_->total_bytes(); 33 int64 total = download_->total_bytes();
33 34
34 DataUnits amount_units = GetByteDisplayUnits(total); 35 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total);
35 const string16 simple_size = FormatBytes(size, amount_units, false); 36 string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false);
36 37
37 // In RTL locales, we render the text "size/total" in an RTL context. This 38 // In RTL locales, we render the text "size/total" in an RTL context. This
38 // is problematic since a string such as "123/456 MB" is displayed 39 // is problematic since a string such as "123/456 MB" is displayed
39 // as "MB 123/456" because it ends with an LTR run. In order to solve this, 40 // as "MB 123/456" because it ends with an LTR run. In order to solve this,
40 // we mark the total string as an LTR string if the UI layout is 41 // we mark the total string as an LTR string if the UI layout is
41 // right-to-left so that the string "456 MB" is treated as an LTR run. 42 // right-to-left so that the string "456 MB" is treated as an LTR run.
42 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( 43 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality(
43 FormatBytes(total, amount_units, true)); 44 ui::FormatBytesWithUnits(total, amount_units, true));
44 45
45 TimeDelta remaining; 46 TimeDelta remaining;
46 string16 simple_time; 47 string16 simple_time;
47 if (download_->IsInProgress() && download_->is_paused()) { 48 if (download_->IsInProgress() && download_->is_paused()) {
48 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); 49 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED);
49 } else if (download_->TimeRemaining(&remaining)) { 50 } else if (download_->TimeRemaining(&remaining)) {
50 simple_time = download_->open_when_complete() ? 51 simple_time = download_->open_when_complete() ?
51 TimeFormat::TimeRemainingShort(remaining) : 52 TimeFormat::TimeRemainingShort(remaining) :
52 TimeFormat::TimeRemaining(remaining); 53 TimeFormat::TimeRemaining(remaining);
53 } 54 }
(...skipping 10 matching lines...) Expand all
64 if (simple_time.empty()) { 65 if (simple_time.empty()) {
65 status_text = 66 status_text =
66 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); 67 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE);
67 } else { 68 } else {
68 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPEN_IN, 69 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPEN_IN,
69 simple_time); 70 simple_time);
70 } 71 }
71 } else { 72 } else {
72 if (simple_time.empty()) { 73 if (simple_time.empty()) {
73 // Instead of displaying "0 B" we keep the "Starting..." string. 74 // Instead of displaying "0 B" we keep the "Starting..." string.
74 status_text = (size == 0) ? 75 status_text = (size == 0)
75 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING) : 76 ? l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)
76 FormatBytes(size, GetByteDisplayUnits(size), true); 77 : ui::FormatBytes(size);
77 } else { 78 } else {
78 status_text = l10n_util::GetStringFUTF16( 79 status_text = l10n_util::GetStringFUTF16(
79 IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size, simple_total, 80 IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size, simple_total,
80 simple_time); 81 simple_time);
81 } 82 }
82 } 83 }
83 break; 84 break;
84 case DownloadItem::COMPLETE: 85 case DownloadItem::COMPLETE:
85 if (download_->file_externally_removed()) { 86 if (download_->file_externally_removed()) {
86 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED); 87 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 IDS_SAVE_PAGE_STATUS_INTERRUPTED, 143 IDS_SAVE_PAGE_STATUS_INTERRUPTED,
143 base::FormatNumber(size), 144 base::FormatNumber(size),
144 base::FormatNumber(total_size)); 145 base::FormatNumber(total_size));
145 break; 146 break;
146 default: 147 default:
147 NOTREACHED(); 148 NOTREACHED();
148 } 149 }
149 150
150 return status_text; 151 return status_text;
151 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698