| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/download_item_model.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "chrome/browser/download_manager.h" | |
| 9 #include "chrome/common/l10n_util.h" | |
| 10 #include "chrome/common/time_format.h" | |
| 11 | |
| 12 #include "generated_resources.h" | |
| 13 | |
| 14 DownloadItemModel::DownloadItemModel(DownloadItem* download) | |
| 15 : download_(download) { | |
| 16 } | |
| 17 | |
| 18 void DownloadItemModel::CancelTask() { | |
| 19 download_->Cancel(true /* update history service */); | |
| 20 } | |
| 21 | |
| 22 std::wstring DownloadItemModel::GetStatusText() { | |
| 23 int64 size = download_->received_bytes(); | |
| 24 int64 total = download_->total_bytes(); | |
| 25 | |
| 26 DataUnits amount_units = GetByteDisplayUnits(total); | |
| 27 const std::wstring simple_size = FormatBytes(size, amount_units, false); | |
| 28 | |
| 29 // In RTL locales, we render the text "size/total" in an RTL context. This | |
| 30 // is problematic since a string such as "123/456 MB" is displayed | |
| 31 // as "MB 123/456" because it ends with an LTR run. In order to solve this, | |
| 32 // we mark the total string as an LTR string if the UI layout is | |
| 33 // right-to-left so that the string "456 MB" is treated as an LTR run. | |
| 34 std::wstring simple_total = FormatBytes(total, amount_units, true); | |
| 35 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) | |
| 36 l10n_util::WrapStringWithLTRFormatting(&simple_total); | |
| 37 | |
| 38 TimeDelta remaining; | |
| 39 std::wstring simple_time; | |
| 40 if (download_->state() == DownloadItem::IN_PROGRESS && | |
| 41 download_->is_paused()) { | |
| 42 simple_time = l10n_util::GetString(IDS_DOWNLOAD_PROGRESS_PAUSED); | |
| 43 } else if (download_->TimeRemaining(&remaining)) { | |
| 44 simple_time = download_->open_when_complete() ? | |
| 45 TimeFormat::TimeRemainingShort(remaining) : | |
| 46 TimeFormat::TimeRemaining(remaining); | |
| 47 } | |
| 48 | |
| 49 std::wstring status_text; | |
| 50 switch (download_->state()) { | |
| 51 case DownloadItem::IN_PROGRESS: | |
| 52 if (download_->open_when_complete()) { | |
| 53 if (simple_time.empty()) { | |
| 54 status_text = | |
| 55 l10n_util::GetString(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); | |
| 56 } else { | |
| 57 status_text = l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_OPEN_IN, | |
| 58 simple_time); | |
| 59 } | |
| 60 } else { | |
| 61 if (simple_time.empty()) { | |
| 62 // Instead of displaying "0 B" we keep the "Starting..." string. | |
| 63 status_text = (size == 0) ? | |
| 64 l10n_util::GetString(IDS_DOWNLOAD_STATUS_STARTING) : | |
| 65 FormatBytes(size, GetByteDisplayUnits(size), true); | |
| 66 } else { | |
| 67 status_text = l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_IN_PROGRESS, | |
| 68 simple_size, | |
| 69 simple_total, | |
| 70 simple_time); | |
| 71 } | |
| 72 } | |
| 73 break; | |
| 74 case DownloadItem::COMPLETE: | |
| 75 status_text.clear(); | |
| 76 break; | |
| 77 case DownloadItem::CANCELLED: | |
| 78 status_text = l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_CANCELLED, | |
| 79 simple_size); | |
| 80 break; | |
| 81 case DownloadItem::REMOVING: | |
| 82 break; | |
| 83 default: | |
| 84 NOTREACHED(); | |
| 85 } | |
| 86 | |
| 87 return status_text; | |
| 88 } | |
| 89 | |
| OLD | NEW |