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

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

Issue 3165009: Convert TimeFormat (chrome/common/time_format.*) to string16 (from wstring). (Closed)
Patch Set: bar Created 10 years, 4 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
« no previous file with comments | « chrome/browser/dom_ui/history_ui.cc ('k') | chrome/browser/download/download_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/download/download_item.h" 12 #include "chrome/browser/download/download_item.h"
12 #include "chrome/browser/download/save_package.h" 13 #include "chrome/browser/download/save_package.h"
13 #include "chrome/common/time_format.h" 14 #include "chrome/common/time_format.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 16
16 using base::TimeDelta; 17 using base::TimeDelta;
17 18
18 // ----------------------------------------------------------------------------- 19 // -----------------------------------------------------------------------------
19 // DownloadItemModel 20 // DownloadItemModel
20 21
21 DownloadItemModel::DownloadItemModel(DownloadItem* download) 22 DownloadItemModel::DownloadItemModel(DownloadItem* download)
22 : BaseDownloadItemModel(download) { 23 : BaseDownloadItemModel(download) {
23 } 24 }
24 25
25 void DownloadItemModel::CancelTask() { 26 void DownloadItemModel::CancelTask() {
26 download_->Cancel(true /* update history service */); 27 download_->Cancel(true /* update history service */);
27 } 28 }
28 29
29 std::wstring DownloadItemModel::GetStatusText() { 30 std::wstring DownloadItemModel::GetStatusText() {
30 int64 size = download_->received_bytes(); 31 int64 size = download_->received_bytes();
31 int64 total = download_->total_bytes(); 32 int64 total = download_->total_bytes();
32 33
33 DataUnits amount_units = GetByteDisplayUnits(total); 34 DataUnits amount_units = GetByteDisplayUnits(total);
34 const std::wstring simple_size = FormatBytes(size, amount_units, false); 35 const string16 simple_size = WideToUTF16Hack(FormatBytes(size, amount_units,
36 false));
35 37
36 // 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
37 // 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
38 // 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,
39 // 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
40 // 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.
41 std::wstring simple_total = FormatBytes(total, amount_units, true); 43 std::wstring simple_total = FormatBytes(total, amount_units, true);
42 base::i18n::GetDisplayStringInLTRDirectionality(&simple_total); 44 base::i18n::GetDisplayStringInLTRDirectionality(&simple_total);
43 45
44 TimeDelta remaining; 46 TimeDelta remaining;
45 std::wstring simple_time; 47 string16 simple_time;
46 if (download_->state() == DownloadItem::IN_PROGRESS && 48 if (download_->state() == DownloadItem::IN_PROGRESS &&
47 download_->is_paused()) { 49 download_->is_paused()) {
48 simple_time = l10n_util::GetString(IDS_DOWNLOAD_PROGRESS_PAUSED); 50 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED);
49 } else if (download_->TimeRemaining(&remaining)) { 51 } else if (download_->TimeRemaining(&remaining)) {
50 simple_time = download_->open_when_complete() ? 52 simple_time = download_->open_when_complete() ?
51 TimeFormat::TimeRemainingShort(remaining) : 53 TimeFormat::TimeRemainingShort(remaining) :
52 TimeFormat::TimeRemaining(remaining); 54 TimeFormat::TimeRemaining(remaining);
53 } 55 }
54 56
55 std::wstring status_text; 57 string16 status_text;
56 switch (download_->state()) { 58 switch (download_->state()) {
57 case DownloadItem::IN_PROGRESS: 59 case DownloadItem::IN_PROGRESS:
58 if (download_->open_when_complete()) { 60 if (download_->open_when_complete()) {
59 if (simple_time.empty()) { 61 if (simple_time.empty()) {
60 status_text = 62 status_text =
61 l10n_util::GetString(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); 63 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE);
62 } else { 64 } else {
63 status_text = l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_OPEN_IN, 65 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPEN_IN,
64 simple_time); 66 simple_time);
65 } 67 }
66 } else { 68 } else {
67 if (simple_time.empty()) { 69 if (simple_time.empty()) {
68 // Instead of displaying "0 B" we keep the "Starting..." string. 70 // Instead of displaying "0 B" we keep the "Starting..." string.
69 status_text = (size == 0) ? 71 status_text = (size == 0) ?
70 l10n_util::GetString(IDS_DOWNLOAD_STATUS_STARTING) : 72 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING) :
71 FormatBytes(size, GetByteDisplayUnits(size), true); 73 WideToUTF16Hack(FormatBytes(size, GetByteDisplayUnits(size),
74 true));
72 } else { 75 } else {
73 status_text = l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_IN_PROGRESS, 76 status_text = l10n_util::GetStringFUTF16(
74 simple_size, 77 IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size,
75 simple_total, 78 WideToUTF16Hack(simple_total), simple_time);
76 simple_time);
77 } 79 }
78 } 80 }
79 break; 81 break;
80 case DownloadItem::COMPLETE: 82 case DownloadItem::COMPLETE:
81 status_text.clear(); 83 status_text.clear();
82 break; 84 break;
83 case DownloadItem::CANCELLED: 85 case DownloadItem::CANCELLED:
84 status_text = l10n_util::GetString(IDS_DOWNLOAD_STATUS_CANCELED); 86 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED);
85 break; 87 break;
86 case DownloadItem::REMOVING: 88 case DownloadItem::REMOVING:
87 break; 89 break;
88 default: 90 default:
89 NOTREACHED(); 91 NOTREACHED();
90 } 92 }
91 93
92 return status_text; 94 return UTF16ToWideHack(status_text);
93 } 95 }
94 96
95 // ----------------------------------------------------------------------------- 97 // -----------------------------------------------------------------------------
96 // SavePageModel 98 // SavePageModel
97 99
98 SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download) 100 SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download)
99 : BaseDownloadItemModel(download), 101 : BaseDownloadItemModel(download),
100 save_(save) { 102 save_(save) {
101 } 103 }
102 104
(...skipping 20 matching lines...) Expand all
123 status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_CANCELED); 125 status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_CANCELED);
124 break; 126 break;
125 case DownloadItem::REMOVING: 127 case DownloadItem::REMOVING:
126 break; 128 break;
127 default: 129 default:
128 NOTREACHED(); 130 NOTREACHED();
129 } 131 }
130 132
131 return status_text; 133 return status_text;
132 } 134 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/history_ui.cc ('k') | chrome/browser/download/download_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698