OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/i18n/number_formatting.h" | 8 #include "base/i18n/number_formatting.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 void DownloadItemModel::CancelTask() { | 26 void DownloadItemModel::CancelTask() { |
27 download_->Cancel(true /* update history service */); | 27 download_->Cancel(true /* update history service */); |
28 } | 28 } |
29 | 29 |
30 std::wstring DownloadItemModel::GetStatusText() { | 30 std::wstring DownloadItemModel::GetStatusText() { |
31 int64 size = download_->received_bytes(); | 31 int64 size = download_->received_bytes(); |
32 int64 total = download_->total_bytes(); | 32 int64 total = download_->total_bytes(); |
33 | 33 |
34 DataUnits amount_units = GetByteDisplayUnits(total); | 34 DataUnits amount_units = GetByteDisplayUnits(total); |
35 const string16 simple_size = WideToUTF16Hack(FormatBytes(size, amount_units, | 35 const string16 simple_size = FormatBytes(size, amount_units, false); |
36 false)); | |
37 | 36 |
38 // In RTL locales, we render the text "size/total" in an RTL context. This | 37 // In RTL locales, we render the text "size/total" in an RTL context. This |
39 // is problematic since a string such as "123/456 MB" is displayed | 38 // is problematic since a string such as "123/456 MB" is displayed |
40 // as "MB 123/456" because it ends with an LTR run. In order to solve this, | 39 // as "MB 123/456" because it ends with an LTR run. In order to solve this, |
41 // we mark the total string as an LTR string if the UI layout is | 40 // we mark the total string as an LTR string if the UI layout is |
42 // right-to-left so that the string "456 MB" is treated as an LTR run. | 41 // right-to-left so that the string "456 MB" is treated as an LTR run. |
43 std::wstring simple_total = FormatBytes(total, amount_units, true); | 42 std::wstring simple_total = |
43 UTF16ToWide(FormatBytes(total, amount_units, true)); | |
44 base::i18n::GetDisplayStringInLTRDirectionality(&simple_total); | 44 base::i18n::GetDisplayStringInLTRDirectionality(&simple_total); |
viettrungluu
2010/08/18 16:15:54
I guess we really should make a string16 version o
| |
45 | 45 |
46 TimeDelta remaining; | 46 TimeDelta remaining; |
47 string16 simple_time; | 47 string16 simple_time; |
48 if (download_->state() == DownloadItem::IN_PROGRESS && | 48 if (download_->state() == DownloadItem::IN_PROGRESS && |
49 download_->is_paused()) { | 49 download_->is_paused()) { |
50 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); | 50 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); |
51 } else if (download_->TimeRemaining(&remaining)) { | 51 } else if (download_->TimeRemaining(&remaining)) { |
52 simple_time = download_->open_when_complete() ? | 52 simple_time = download_->open_when_complete() ? |
53 TimeFormat::TimeRemainingShort(remaining) : | 53 TimeFormat::TimeRemainingShort(remaining) : |
54 TimeFormat::TimeRemaining(remaining); | 54 TimeFormat::TimeRemaining(remaining); |
55 } | 55 } |
56 | 56 |
57 string16 status_text; | 57 string16 status_text; |
58 switch (download_->state()) { | 58 switch (download_->state()) { |
59 case DownloadItem::IN_PROGRESS: | 59 case DownloadItem::IN_PROGRESS: |
60 if (download_->open_when_complete()) { | 60 if (download_->open_when_complete()) { |
61 if (simple_time.empty()) { | 61 if (simple_time.empty()) { |
62 status_text = | 62 status_text = |
63 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); | 63 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); |
64 } else { | 64 } else { |
65 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPEN_IN, | 65 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPEN_IN, |
66 simple_time); | 66 simple_time); |
67 } | 67 } |
68 } else { | 68 } else { |
69 if (simple_time.empty()) { | 69 if (simple_time.empty()) { |
70 // Instead of displaying "0 B" we keep the "Starting..." string. | 70 // Instead of displaying "0 B" we keep the "Starting..." string. |
71 status_text = (size == 0) ? | 71 status_text = (size == 0) ? |
72 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING) : | 72 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING) : |
73 WideToUTF16Hack(FormatBytes(size, GetByteDisplayUnits(size), | 73 FormatBytes(size, GetByteDisplayUnits(size), true); |
74 true)); | |
75 } else { | 74 } else { |
76 status_text = l10n_util::GetStringFUTF16( | 75 status_text = l10n_util::GetStringFUTF16( |
77 IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size, | 76 IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size, |
78 WideToUTF16Hack(simple_total), simple_time); | 77 WideToUTF16(simple_total), simple_time); |
79 } | 78 } |
80 } | 79 } |
81 break; | 80 break; |
82 case DownloadItem::COMPLETE: | 81 case DownloadItem::COMPLETE: |
83 status_text.clear(); | 82 status_text.clear(); |
84 break; | 83 break; |
85 case DownloadItem::CANCELLED: | 84 case DownloadItem::CANCELLED: |
86 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED); | 85 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED); |
87 break; | 86 break; |
88 case DownloadItem::REMOVING: | 87 case DownloadItem::REMOVING: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_CANCELED); | 124 status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_CANCELED); |
126 break; | 125 break; |
127 case DownloadItem::REMOVING: | 126 case DownloadItem::REMOVING: |
128 break; | 127 break; |
129 default: | 128 default: |
130 NOTREACHED(); | 129 NOTREACHED(); |
131 } | 130 } |
132 | 131 |
133 return status_text; | 132 return status_text; |
134 } | 133 } |
OLD | NEW |