diff options
Diffstat (limited to 'chrome/browser/views/importer_view.cc')
-rw-r--r-- | chrome/browser/views/importer_view.cc | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/chrome/browser/views/importer_view.cc b/chrome/browser/views/importer_view.cc new file mode 100644 index 0000000..bd71637 --- /dev/null +++ b/chrome/browser/views/importer_view.cc @@ -0,0 +1,199 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "chrome/browser/views/importer_view.h" + +#include "chrome/app/locales/locale_settings.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/standard_layout.h" +#include "chrome/common/l10n_util.h" +#include "chrome/views/checkbox.h" +#include "chrome/views/grid_layout.h" +#include "chrome/views/label.h" +#include "chrome/views/window.h" + +#include "generated_resources.h" + +using ChromeViews::ColumnSet; +using ChromeViews::GridLayout; + +ImporterView::ImporterView(Profile* profile) + : dialog_(NULL), + import_from_label_(NULL), + profile_combobox_(NULL), + import_items_label_(NULL), + history_checkbox_(NULL), + favorites_checkbox_(NULL), + passwords_checkbox_(NULL), + search_engines_checkbox_(NULL), + profile_(profile), + importer_host_(new ImporterHost()) { + DCHECK(profile); + SetupControl(); +} + +ImporterView::~ImporterView() { +} + +void ImporterView::SetupControl() { + // Adds all controls. + import_from_label_ = + new ChromeViews::Label(l10n_util::GetString(IDS_IMPORT_FROM_LABEL)); + + profile_combobox_ = new ChromeViews::ComboBox(this); + + import_items_label_ = + new ChromeViews::Label(l10n_util::GetString(IDS_IMPORT_ITEMS_LABEL)); + + history_checkbox_ = + InitCheckbox(l10n_util::GetString(IDS_IMPORT_HISTORY_CHKBOX), true); + favorites_checkbox_ = + InitCheckbox(l10n_util::GetString(IDS_IMPORT_FAVORITES_CHKBOX), true); + passwords_checkbox_ = + InitCheckbox(l10n_util::GetString(IDS_IMPORT_PASSWORDS_CHKBOX), true); + search_engines_checkbox_ = + InitCheckbox(l10n_util::GetString(IDS_IMPORT_SEARCH_ENGINES_CHKBOX), + true); + + // Arranges controls by using GridLayout. + const int column_set_id = 0; + GridLayout* layout = CreatePanelGridLayout(this); + SetLayoutManager(layout); + ColumnSet* column_set = layout->AddColumnSet(column_set_id); + column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, + GridLayout::FIXED, 200, 0); + + layout->StartRow(0, column_set_id); + layout->AddView(import_from_label_); + layout->AddView(profile_combobox_); + + layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); + layout->StartRow(0, column_set_id); + layout->AddView(import_items_label_, 3, 1); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, column_set_id); + layout->AddView(favorites_checkbox_, 3, 1); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, column_set_id); + layout->AddView(search_engines_checkbox_, 3, 1); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, column_set_id); + layout->AddView(passwords_checkbox_, 3, 1); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, column_set_id); + layout->AddView(history_checkbox_, 3, 1); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); +} + +void ImporterView::GetPreferredSize(CSize *out) { + DCHECK(out); + *out = ChromeViews::Window::GetLocalizedContentsSize( + IDS_IMPORT_DIALOG_WIDTH_CHARS, + IDS_IMPORT_DIALOG_HEIGHT_LINES).ToSIZE(); +} + +void ImporterView::Layout() { + GetLayoutManager()->Layout(this); +} + +std::wstring ImporterView::GetDialogButtonLabel( + DialogButton button) const { + if (button == DIALOGBUTTON_OK) { + return l10n_util::GetString(IDS_IMPORT_COMMIT); + } else { + return std::wstring(); + } +} + +bool ImporterView::IsModal() const { + return true; +} + +std::wstring ImporterView::GetWindowTitle() const { + return l10n_util::GetString(IDS_IMPORT_SETTINGS_TITLE); +} + +bool ImporterView::Accept() { + if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) { + return false; + } + + uint16 items = NONE; + if (history_checkbox_->IsEnabled() && history_checkbox_->IsSelected()) + items |= HISTORY; + if (favorites_checkbox_->IsEnabled() && favorites_checkbox_->IsSelected()) + items |= FAVORITES; + if (passwords_checkbox_->IsEnabled() && passwords_checkbox_->IsSelected()) + items |= PASSWORDS; + if (search_engines_checkbox_->IsEnabled() && + search_engines_checkbox_->IsSelected()) + items |= SEARCH_ENGINES; + + Browser* browser = BrowserList::GetLastActive(); + int selected_index = profile_combobox_->GetSelectedItem(); + StartImportingWithUI(browser->GetTopLevelHWND(), items, importer_host_.get(), + importer_host_->GetSourceProfileInfoAt(selected_index), + profile_, this, false); + // We return false here to prevent the window from being closed. We will be + // notified back by our implementation of ImportObserver when the import is + // complete so that we can close ourselves. + return false; +} + +int ImporterView::GetItemCount(ChromeViews::ComboBox* source) { + DCHECK(source == profile_combobox_); + DCHECK(importer_host_.get()); + return importer_host_->GetAvailableProfileCount(); +} + +std::wstring ImporterView::GetItemAt(ChromeViews::ComboBox* source, + int index) { + DCHECK(source == profile_combobox_); + DCHECK(importer_host_.get()); + return importer_host_->GetSourceProfileNameAt(index); +} + +void ImporterView::ImportCanceled() { + ImportComplete(); +} + +void ImporterView::ImportComplete() { + // Now close this window since the import completed or was canceled. + dialog_->Close(); +} + +ChromeViews::CheckBox* ImporterView::InitCheckbox( + const std::wstring& text, bool checked) { + ChromeViews::CheckBox* checkbox = new ChromeViews::CheckBox(text); + checkbox->SetIsSelected(checked); + return checkbox; +} |