summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/new_profile_dialog.cc
diff options
context:
space:
mode:
authormunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 23:52:03 +0000
committermunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 23:52:03 +0000
commitf253006b157f9c917fba21a7312290aaa2e889e7 (patch)
tree377183f9511bed141b5fd7a706c3407a122540d9 /chrome/browser/views/new_profile_dialog.cc
parentdadacf06556b4f63a62ec3cea91d7fc5abccd67c (diff)
downloadchromium_src-f253006b157f9c917fba21a7312290aaa2e889e7.zip
chromium_src-f253006b157f9c917fba21a7312290aaa2e889e7.tar.gz
chromium_src-f253006b157f9c917fba21a7312290aaa2e889e7.tar.bz2
Chromium-MultiProfile-Prototype
Summary ======= Implement a prototype of multiple profiles in Chrome by utilizing the functionality of user-data-dir command line flag that already exists. A profile in this case is an umbrella for all user data including cookies, history, bookmarks, settings, etc. Each profile gives the user a separation of all these data elements. User Interface ============== - Wrench > "New window in profile" menu item, with sub-menu items. This new menu item has sub menu items for each existing profile, for up to 9 profiles, and one more sub menu item to launch a window in a new profile. The 9 sub-menu items also have the accelerators like CTRL + SHIFT + 1, CTRL + SHIFT + 2, etc. If there are more than 9 profiles, we will also show an extra sub-menu item, "Other...". - New Profile dialog box This dialog box is shown to the use when (s)he clicks Wrench > New window in profile > <New Profile>. It lets the user specify a profile name, and also shows a checkbox to create a desktop shortcut to launch Chrome in that profile. - Choose profile dialog box This dialog box lets the user select a profile from a drop down to open a new window in. It also has an item <New Profile> in the drop down, selecting which will show the new profile dialog box mentioned above. CTRL + M shortcut also launches this dialog box. Code Organization ================= chrome\browser\user_data_dir_profile_manager.h/.cc: This class provides an abstraction of profiles on top of the user data dir command line flag. chrome\browser\views\user_data_dir_new_profile_dialog.h/.cc New profile dialog box code. chrome\browser\views\user_data_dir_profiles_dialog.h/.cc Choose profile dialog box code. Review URL: http://codereview.chromium.org/12895 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6333 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/new_profile_dialog.cc')
-rw-r--r--chrome/browser/views/new_profile_dialog.cc105
1 files changed, 105 insertions, 0 deletions
diff --git a/chrome/browser/views/new_profile_dialog.cc b/chrome/browser/views/new_profile_dialog.cc
new file mode 100644
index 0000000..07c3c708
--- /dev/null
+++ b/chrome/browser/views/new_profile_dialog.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/views/new_profile_dialog.h"
+
+#include <string>
+
+#include "base/logging.h"
+#include "base/file_util.h"
+#include "chrome/app/locales/locale_settings.h"
+#include "chrome/browser/user_data_manager.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/views/message_box_view.h"
+#include "chrome/views/text_field.h"
+#include "chrome/views/view.h"
+#include "chrome/views/window.h"
+
+#include "chromium_strings.h"
+#include "generated_resources.h"
+
+// static
+void NewProfileDialog::RunDialog() {
+ NewProfileDialog* dlg = new NewProfileDialog();
+ views::Window::CreateChromeWindow(NULL, gfx::Rect(), dlg)->Show();
+}
+
+NewProfileDialog::NewProfileDialog() {
+ std::wstring message_text = l10n_util::GetString(
+ IDS_NEW_PROFILE_DIALOG_LABEL_TEXT);
+ const int kDialogWidth = views::Window::GetLocalizedContentsWidth(
+ IDS_NEW_PROFILE_DIALOG_WIDTH_CHARS);
+ const int kMessageBoxFlags = MessageBoxView::kFlagHasOKButton |
+ MessageBoxView::kFlagHasCancelButton |
+ MessageBoxView::kFlagHasPromptField;
+ message_box_view_ = new MessageBoxView(kMessageBoxFlags,
+ message_text.c_str(),
+ std::wstring(),
+ kDialogWidth);
+ message_box_view_->SetCheckBoxLabel(
+ l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_CREATE_SHORTCUT_TEXT));
+ message_box_view_->SetCheckBoxSelected(true);
+ message_box_view_->text_box()->SetController(this);
+}
+
+NewProfileDialog::~NewProfileDialog() {
+}
+
+int NewProfileDialog::GetDialogButtons() const {
+ return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL;
+}
+
+views::View* NewProfileDialog::GetInitiallyFocusedView() const {
+ views::TextField* text_box = message_box_view_->text_box();
+ DCHECK(text_box);
+ return text_box;
+}
+
+bool NewProfileDialog::IsDialogButtonEnabled(
+ DialogButton button) const {
+ if (button == DIALOGBUTTON_OK) {
+ std::wstring profile_name = message_box_view_->GetInputText();
+ // TODO(munjal): Refactor the function ReplaceIllegalCharacters in
+ // file_util to something that just checks if there are illegal chars
+ // since that's what we really need. Also, replaceIllegalChars seems to
+ // be expensive since it builds a list of illegal characters for each call.
+ // So at the least fix that.
+ file_util::ReplaceIllegalCharacters(&profile_name, L'_');
+ return !profile_name.empty() &&
+ profile_name == message_box_view_->GetInputText();
+ }
+ return true;
+}
+
+std::wstring NewProfileDialog::GetWindowTitle() const {
+ return l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_TITLE);
+}
+
+void NewProfileDialog::WindowClosing() {
+ delete this;
+}
+
+void NewProfileDialog::ContentsChanged(views::TextField* sender,
+ const std::wstring& new_contents) {
+ GetDialogClientView()->UpdateDialogButtons();
+}
+
+bool NewProfileDialog::Accept() {
+ std::wstring profile_name = message_box_view_->GetInputText();
+ if (profile_name.empty()) {
+ NOTREACHED();
+ return true;
+ }
+ // Create a desktop shortcut if the corresponding checkbox is checked.
+ if (message_box_view_->IsCheckBoxSelected())
+ UserDataManager::Get()->CreateDesktopShortcutForProfile(
+ profile_name);
+
+ UserDataManager::Get()->LaunchChromeForProfile(profile_name);
+ return true;
+}
+
+views::View* NewProfileDialog::GetContentsView() {
+ return message_box_view_;
+}