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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/download/download_item.h" | 12 #include "chrome/browser/download/download_item.h" |
13 #include "chrome/browser/download/save_package.h" | 13 #include "chrome/browser/download/save_package.h" |
14 #include "chrome/common/time_format.h" | 14 #include "chrome/common/time_format.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 | 16 |
17 using base::TimeDelta; | 17 using base::TimeDelta; |
18 | 18 |
19 // ----------------------------------------------------------------------------- | 19 // ----------------------------------------------------------------------------- |
20 // DownloadItemModel | 20 // DownloadItemModel |
21 | 21 |
22 DownloadItemModel::DownloadItemModel(DownloadItem* download) | 22 DownloadItemModel::DownloadItemModel(DownloadItem* download) |
23 : BaseDownloadItemModel(download) { | 23 : BaseDownloadItemModel(download) { |
24 } | 24 } |
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 string16 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 = FormatBytes(size, amount_units, false); | 35 const string16 simple_size = FormatBytes(size, amount_units, false); |
36 | 36 |
37 // 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 |
38 // 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 |
39 // 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, |
40 // 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 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 break; | 82 break; |
83 case DownloadItem::CANCELLED: | 83 case DownloadItem::CANCELLED: |
84 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED); | 84 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED); |
85 break; | 85 break; |
86 case DownloadItem::REMOVING: | 86 case DownloadItem::REMOVING: |
87 break; | 87 break; |
88 default: | 88 default: |
89 NOTREACHED(); | 89 NOTREACHED(); |
90 } | 90 } |
91 | 91 |
92 return UTF16ToWideHack(status_text); | 92 return status_text; |
93 } | 93 } |
94 | 94 |
95 // ----------------------------------------------------------------------------- | 95 // ----------------------------------------------------------------------------- |
96 // SavePageModel | 96 // SavePageModel |
97 | 97 |
98 SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download) | 98 SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download) |
99 : BaseDownloadItemModel(download), | 99 : BaseDownloadItemModel(download), |
100 save_(save) { | 100 save_(save) { |
101 } | 101 } |
102 | 102 |
103 void SavePageModel::CancelTask() { | 103 void SavePageModel::CancelTask() { |
104 save_->Cancel(true); | 104 save_->Cancel(true); |
105 } | 105 } |
106 | 106 |
107 std::wstring SavePageModel::GetStatusText() { | 107 string16 SavePageModel::GetStatusText() { |
108 int64 size = download_->received_bytes(); | 108 int64 size = download_->received_bytes(); |
109 int64 total_size = download_->total_bytes(); | 109 int64 total_size = download_->total_bytes(); |
110 | 110 |
111 std::wstring status_text; | 111 string16 status_text; |
112 switch (download_->state()) { | 112 switch (download_->state()) { |
113 case DownloadItem::IN_PROGRESS: | 113 case DownloadItem::IN_PROGRESS: |
114 status_text = l10n_util::GetStringF( | 114 status_text = l10n_util::GetStringFUTF16( |
115 IDS_SAVE_PAGE_PROGRESS, | 115 IDS_SAVE_PAGE_PROGRESS, |
116 UTF16ToWide(base::FormatNumber(size)), | 116 base::FormatNumber(size), |
117 UTF16ToWide(base::FormatNumber(total_size))); | 117 base::FormatNumber(total_size)); |
118 break; | 118 break; |
119 case DownloadItem::COMPLETE: | 119 case DownloadItem::COMPLETE: |
120 status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_COMPLETED); | 120 status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_COMPLETED); |
121 break; | 121 break; |
122 case DownloadItem::CANCELLED: | 122 case DownloadItem::CANCELLED: |
123 status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_CANCELED); | 123 status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_CANCELED); |
124 break; | 124 break; |
125 case DownloadItem::REMOVING: | 125 case DownloadItem::REMOVING: |
126 break; | 126 break; |
127 default: | 127 default: |
128 NOTREACHED(); | 128 NOTREACHED(); |
129 } | 129 } |
130 | 130 |
131 return status_text; | 131 return status_text; |
132 } | 132 } |
OLD | NEW |