| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
| 6 #include "app/message_box_flags.h" | 6 #include "app/message_box_flags.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/views/user_data_dir_dialog.h" | 9 #include "chrome/browser/views/user_data_dir_dialog.h" |
| 9 #include "grit/chromium_strings.h" | 10 #include "grit/chromium_strings.h" |
| 10 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 11 #include "views/controls/message_box_view.h" | 12 #include "views/controls/message_box_view.h" |
| 12 #include "views/widget/widget.h" | 13 #include "views/widget/widget.h" |
| 13 #include "views/window/window.h" | 14 #include "views/window/window.h" |
| 14 | 15 |
| 15 // static | 16 // static |
| 16 FilePath UserDataDirDialog::RunUserDataDirDialog( | 17 FilePath UserDataDirDialog::RunUserDataDirDialog( |
| 17 const FilePath& user_data_dir) { | 18 const FilePath& user_data_dir) { |
| 18 // When the window closes, it will delete itself. | 19 // When the window closes, it will delete itself. |
| 19 UserDataDirDialog* dlg = new UserDataDirDialog(user_data_dir); | 20 UserDataDirDialog* dlg = new UserDataDirDialog(user_data_dir); |
| 20 MessageLoopForUI::current()->Run(dlg); | 21 MessageLoopForUI::current()->Run(dlg); |
| 21 return dlg->user_data_dir(); | 22 return dlg->user_data_dir(); |
| 22 } | 23 } |
| 23 | 24 |
| 24 UserDataDirDialog::UserDataDirDialog(const FilePath& user_data_dir) | 25 UserDataDirDialog::UserDataDirDialog(const FilePath& user_data_dir) |
| 25 : ALLOW_THIS_IN_INITIALIZER_LIST( | 26 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 26 select_file_dialog_(SelectFileDialog::Create(this))), | 27 select_file_dialog_(SelectFileDialog::Create(this))), |
| 27 is_blocking_(true) { | 28 is_blocking_(true) { |
| 28 std::wstring message_text = l10n_util::GetStringF( | 29 std::wstring message_text = UTF16ToWide(l10n_util::GetStringFUTF16( |
| 29 IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY, user_data_dir.ToWStringHack()); | 30 IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY, |
| 31 WideToUTF16Hack(user_data_dir.ToWStringHack()))); |
| 30 const int kDialogWidth = 400; | 32 const int kDialogWidth = 400; |
| 31 message_box_view_ = new MessageBoxView(MessageBoxFlags::kIsConfirmMessageBox, | 33 message_box_view_ = new MessageBoxView(MessageBoxFlags::kIsConfirmMessageBox, |
| 32 message_text.c_str(), std::wstring(), kDialogWidth); | 34 message_text.c_str(), std::wstring(), kDialogWidth); |
| 33 | 35 |
| 34 views::Window::CreateChromeWindow(NULL, gfx::Rect(), this)->Show(); | 36 views::Window::CreateChromeWindow(NULL, gfx::Rect(), this)->Show(); |
| 35 } | 37 } |
| 36 | 38 |
| 37 UserDataDirDialog::~UserDataDirDialog() { | 39 UserDataDirDialog::~UserDataDirDialog() { |
| 38 select_file_dialog_->ListenerDestroyed(); | 40 select_file_dialog_->ListenerDestroyed(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 std::wstring UserDataDirDialog::GetDialogButtonLabel( | 43 std::wstring UserDataDirDialog::GetDialogButtonLabel( |
| 42 MessageBoxFlags::DialogButton button) const { | 44 MessageBoxFlags::DialogButton button) const { |
| 43 | 45 |
| 44 switch (button) { | 46 switch (button) { |
| 45 case MessageBoxFlags::DIALOGBUTTON_OK: | 47 case MessageBoxFlags::DIALOGBUTTON_OK: |
| 46 return l10n_util::GetString( | 48 return UTF16ToWide(l10n_util::GetStringUTF16( |
| 47 IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON); | 49 IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON)); |
| 48 case MessageBoxFlags::DIALOGBUTTON_CANCEL: | 50 case MessageBoxFlags::DIALOGBUTTON_CANCEL: |
| 49 return l10n_util::GetString(IDS_CANT_WRITE_USER_DIRECTORY_EXIT_BUTTON); | 51 return UTF16ToWide(l10n_util::GetStringUTF16( |
| 52 IDS_CANT_WRITE_USER_DIRECTORY_EXIT_BUTTON)); |
| 50 default: | 53 default: |
| 51 NOTREACHED(); | 54 NOTREACHED(); |
| 52 } | 55 } |
| 53 | 56 |
| 54 return std::wstring(); | 57 return std::wstring(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 std::wstring UserDataDirDialog::GetWindowTitle() const { | 60 std::wstring UserDataDirDialog::GetWindowTitle() const { |
| 58 return l10n_util::GetString(IDS_CANT_WRITE_USER_DIRECTORY_TITLE); | 61 return UTF16ToWide( |
| 62 l10n_util::GetStringUTF16(IDS_CANT_WRITE_USER_DIRECTORY_TITLE)); |
| 59 } | 63 } |
| 60 | 64 |
| 61 void UserDataDirDialog::DeleteDelegate() { | 65 void UserDataDirDialog::DeleteDelegate() { |
| 62 delete this; | 66 delete this; |
| 63 } | 67 } |
| 64 | 68 |
| 65 bool UserDataDirDialog::Accept() { | 69 bool UserDataDirDialog::Accept() { |
| 66 // Directory picker | 70 // Directory picker |
| 67 std::wstring dialog_title = l10n_util::GetString( | 71 std::wstring dialog_title = UTF16ToWide(l10n_util::GetStringUTF16( |
| 68 IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON); | 72 IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON)); |
| 69 HWND owning_hwnd = | 73 HWND owning_hwnd = |
| 70 GetAncestor(message_box_view_->GetWidget()->GetNativeView(), GA_ROOT); | 74 GetAncestor(message_box_view_->GetWidget()->GetNativeView(), GA_ROOT); |
| 71 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, | 75 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, |
| 72 dialog_title, FilePath(), NULL, | 76 dialog_title, FilePath(), NULL, |
| 73 0, std::wstring(), owning_hwnd, NULL); | 77 0, std::wstring(), owning_hwnd, NULL); |
| 74 return false; | 78 return false; |
| 75 } | 79 } |
| 76 | 80 |
| 77 bool UserDataDirDialog::Cancel() { | 81 bool UserDataDirDialog::Cancel() { |
| 78 is_blocking_ = false; | 82 is_blocking_ = false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 } | 94 } |
| 91 | 95 |
| 92 void UserDataDirDialog::FileSelected(const FilePath& path, | 96 void UserDataDirDialog::FileSelected(const FilePath& path, |
| 93 int index, void* params) { | 97 int index, void* params) { |
| 94 user_data_dir_ = path; | 98 user_data_dir_ = path; |
| 95 is_blocking_ = false; | 99 is_blocking_ = false; |
| 96 } | 100 } |
| 97 | 101 |
| 98 void UserDataDirDialog::FileSelectionCanceled(void* params) { | 102 void UserDataDirDialog::FileSelectionCanceled(void* params) { |
| 99 } | 103 } |
| OLD | NEW |