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 "chrome/browser/views/new_profile_dialog.h" | 5 #include "chrome/browser/views/new_profile_dialog.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/message_box_flags.h" | 10 #include "app/message_box_flags.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "chrome/browser/user_data_manager.h" | 13 #include "chrome/browser/user_data_manager.h" |
14 #include "grit/chromium_strings.h" | 14 #include "grit/chromium_strings.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/locale_settings.h" | 16 #include "grit/locale_settings.h" |
17 #include "views/controls/message_box_view.h" | 17 #include "views/controls/message_box_view.h" |
18 #include "views/controls/text_field.h" | 18 #include "views/controls/textfield/textfield.h" |
19 #include "views/view.h" | 19 #include "views/view.h" |
20 #include "views/window/window.h" | 20 #include "views/window/window.h" |
21 | 21 |
22 namespace browser { | 22 namespace browser { |
23 | 23 |
24 // Declared in browser_dialogs.h so others don't have to depend on our header. | 24 // Declared in browser_dialogs.h so others don't have to depend on our header. |
25 void ShowNewProfileDialog() { | 25 void ShowNewProfileDialog() { |
26 NewProfileDialog::RunDialog(); | 26 NewProfileDialog::RunDialog(); |
27 } | 27 } |
28 | 28 |
(...skipping 20 matching lines...) Expand all Loading... |
49 message_box_view_->SetCheckBoxLabel( | 49 message_box_view_->SetCheckBoxLabel( |
50 l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_CREATE_SHORTCUT_TEXT)); | 50 l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_CREATE_SHORTCUT_TEXT)); |
51 message_box_view_->SetCheckBoxSelected(true); | 51 message_box_view_->SetCheckBoxSelected(true); |
52 message_box_view_->text_box()->SetController(this); | 52 message_box_view_->text_box()->SetController(this); |
53 } | 53 } |
54 | 54 |
55 NewProfileDialog::~NewProfileDialog() { | 55 NewProfileDialog::~NewProfileDialog() { |
56 } | 56 } |
57 | 57 |
58 views::View* NewProfileDialog::GetInitiallyFocusedView() { | 58 views::View* NewProfileDialog::GetInitiallyFocusedView() { |
59 views::TextField* text_box = message_box_view_->text_box(); | 59 views::Textfield* text_box = message_box_view_->text_box(); |
60 DCHECK(text_box); | 60 DCHECK(text_box); |
61 return text_box; | 61 return text_box; |
62 } | 62 } |
63 | 63 |
64 bool NewProfileDialog::IsDialogButtonEnabled( | 64 bool NewProfileDialog::IsDialogButtonEnabled( |
65 MessageBoxFlags::DialogButton button) const { | 65 MessageBoxFlags::DialogButton button) const { |
66 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { | 66 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { |
67 std::wstring profile_name = message_box_view_->GetInputText(); | 67 std::wstring profile_name = message_box_view_->GetInputText(); |
68 // TODO(munjal): Refactor the function ReplaceIllegalCharacters in | 68 // TODO(munjal): Refactor the function ReplaceIllegalCharacters in |
69 // file_util to something that just checks if there are illegal chars | 69 // file_util to something that just checks if there are illegal chars |
70 // since that's what we really need. Also, replaceIllegalChars seems to | 70 // since that's what we really need. Also, replaceIllegalChars seems to |
71 // be expensive since it builds a list of illegal characters for each call. | 71 // be expensive since it builds a list of illegal characters for each call. |
72 // So at the least fix that. | 72 // So at the least fix that. |
73 file_util::ReplaceIllegalCharacters(&profile_name, L'_'); | 73 file_util::ReplaceIllegalCharacters(&profile_name, L'_'); |
74 return !profile_name.empty() && | 74 return !profile_name.empty() && |
75 profile_name == message_box_view_->GetInputText(); | 75 profile_name == message_box_view_->GetInputText(); |
76 } | 76 } |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 std::wstring NewProfileDialog::GetWindowTitle() const { | 80 std::wstring NewProfileDialog::GetWindowTitle() const { |
81 return l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_TITLE); | 81 return l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_TITLE); |
82 } | 82 } |
83 | 83 |
84 void NewProfileDialog::DeleteDelegate() { | 84 void NewProfileDialog::DeleteDelegate() { |
85 delete this; | 85 delete this; |
86 } | 86 } |
87 | 87 |
88 void NewProfileDialog::ContentsChanged(views::TextField* sender, | 88 void NewProfileDialog::ContentsChanged(views::Textfield* sender, |
89 const std::wstring& new_contents) { | 89 const std::wstring& new_contents) { |
90 GetDialogClientView()->UpdateDialogButtons(); | 90 GetDialogClientView()->UpdateDialogButtons(); |
91 } | 91 } |
92 | 92 |
93 bool NewProfileDialog::Accept() { | 93 bool NewProfileDialog::Accept() { |
94 std::wstring profile_name = message_box_view_->GetInputText(); | 94 std::wstring profile_name = message_box_view_->GetInputText(); |
95 if (profile_name.empty()) { | 95 if (profile_name.empty()) { |
96 NOTREACHED(); | 96 NOTREACHED(); |
97 return true; | 97 return true; |
98 } | 98 } |
99 // Create a desktop shortcut if the corresponding checkbox is checked. | 99 // Create a desktop shortcut if the corresponding checkbox is checked. |
100 if (message_box_view_->IsCheckBoxSelected()) | 100 if (message_box_view_->IsCheckBoxSelected()) |
101 UserDataManager::Get()->CreateDesktopShortcutForProfile( | 101 UserDataManager::Get()->CreateDesktopShortcutForProfile( |
102 profile_name); | 102 profile_name); |
103 | 103 |
104 UserDataManager::Get()->LaunchChromeForProfile(profile_name); | 104 UserDataManager::Get()->LaunchChromeForProfile(profile_name); |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 views::View* NewProfileDialog::GetContentsView() { | 108 views::View* NewProfileDialog::GetContentsView() { |
109 return message_box_view_; | 109 return message_box_view_; |
110 } | 110 } |
OLD | NEW |