Home | History | Annotate | Download | only in importer
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/views/importer/import_lock_dialog_view.h"
      6 
      7 #include "base/message_loop.h"
      8 #include "base/utf_string_conversions.h"
      9 #include "chrome/browser/importer/importer_host.h"
     10 #include "chrome/browser/importer/importer_lock_dialog.h"
     11 #include "chrome/browser/metrics/user_metrics.h"
     12 #include "grit/chromium_strings.h"
     13 #include "grit/generated_resources.h"
     14 #include "grit/locale_settings.h"
     15 #include "ui/base/l10n/l10n_util.h"
     16 #include "views/controls/label.h"
     17 #include "views/layout/layout_constants.h"
     18 #include "views/window/window.h"
     19 
     20 // Default size of the dialog window.
     21 static const int kDefaultWindowWidth = 320;
     22 static const int kDefaultWindowHeight = 100;
     23 
     24 namespace importer {
     25 
     26 void ShowImportLockDialog(gfx::NativeWindow parent,
     27                           ImporterHost* importer_host) {
     28   ImportLockDialogView::Show(parent, importer_host);
     29   UserMetrics::RecordAction(UserMetricsAction("ImportLockDialogView_Shown"));
     30 }
     31 
     32 }  // namespace importer
     33 
     34 // static
     35 void ImportLockDialogView::Show(gfx::NativeWindow parent,
     36                                 ImporterHost* importer_host) {
     37   views::Window::CreateChromeWindow(
     38       NULL, gfx::Rect(),
     39       new ImportLockDialogView(importer_host))->Show();
     40 }
     41 
     42 ImportLockDialogView::ImportLockDialogView(ImporterHost* importer_host)
     43     : description_label_(NULL),
     44       importer_host_(importer_host) {
     45   description_label_ = new views::Label(
     46       UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT)));
     47   description_label_->SetMultiLine(true);
     48   description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
     49   AddChildView(description_label_);
     50 }
     51 
     52 ImportLockDialogView::~ImportLockDialogView() {
     53 }
     54 
     55 gfx::Size ImportLockDialogView::GetPreferredSize() {
     56   return gfx::Size(views::Window::GetLocalizedContentsSize(
     57       IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS,
     58       IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES));
     59 }
     60 
     61 void ImportLockDialogView::Layout() {
     62   description_label_->SetBounds(
     63       views::kPanelHorizMargin,
     64       views::kPanelVertMargin,
     65       width() - 2 * views::kPanelHorizMargin,
     66       height() - 2 * views::kPanelVertMargin);
     67 }
     68 
     69 std::wstring ImportLockDialogView::GetDialogButtonLabel(
     70     MessageBoxFlags::DialogButton button) const {
     71   if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
     72     return UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_OK));
     73   } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) {
     74     return UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_CANCEL));
     75   }
     76   return std::wstring();
     77 }
     78 
     79 bool ImportLockDialogView::IsModal() const {
     80   return false;
     81 }
     82 
     83 std::wstring ImportLockDialogView::GetWindowTitle() const {
     84   return UTF16ToWide(l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE));
     85 }
     86 
     87 bool ImportLockDialogView::Accept() {
     88   MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
     89       importer_host_.get(), &ImporterHost::OnImportLockDialogEnd, true));
     90   return true;
     91 }
     92 
     93 bool ImportLockDialogView::Cancel() {
     94   MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
     95       importer_host_.get(), &ImporterHost::OnImportLockDialogEnd, false));
     96   return true;
     97 }
     98 
     99 views::View* ImportLockDialogView::GetContentsView() {
    100   return this;
    101 }
    102