diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 04:12:46 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 04:12:46 +0000 |
commit | b220d13f23af9b126102f407e6d17e804023fd98 (patch) | |
tree | a004321284d007882212368c89e75e9ca83682fc /chrome/browser/views | |
parent | da4a915783ed4ad919b99b175337df8721adc41c (diff) | |
download | chromium_src-b220d13f23af9b126102f407e6d17e804023fd98.zip chromium_src-b220d13f23af9b126102f407e6d17e804023fd98.tar.gz chromium_src-b220d13f23af9b126102f407e6d17e804023fd98.tar.bz2 |
[Windows] Add a button in bookmark manager to show the status of bookmarks synchronization.It does the item 5 of the BUG only.This add a button after |Tools| menu.
And it's showed all the time, with the current status of sync. The user should run 'chrome --enable-sync' to see it.
Patch by Thiago Farina, http://codereview.chromium.org/256017
BUG=23136
TEST=compiled and ran on Windows.
Review URL: http://codereview.chromium.org/268021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/bookmark_manager_view.cc | 79 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_manager_view.h | 40 |
2 files changed, 113 insertions, 6 deletions
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc index 60ec1b9..96345ff 100644 --- a/chrome/browser/views/bookmark_manager_view.cc +++ b/chrome/browser/views/bookmark_manager_view.cc @@ -40,6 +40,11 @@ #include "views/widget/widget.h" #include "views/window/window.h" +#if defined(CHROME_PERSONALIZATION) +#include "chrome/browser/options_window.h" +#include "chrome/browser/sync/sync_status_ui_helper.h" +#endif + // If non-null, there is an open editor and this is the window it is contained // in it. static views::Window* open_window = NULL; @@ -163,6 +168,10 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile) : profile_(profile->GetOriginalProfile()), table_view_(NULL), tree_view_(NULL), +#if defined(CHROME_PERSONALIZATION) + sync_status_button_(NULL), + sync_service_(NULL), +#endif ALLOW_THIS_IN_INITIALIZER_LIST(search_factory_(this)) { search_tf_ = new views::Textfield(); search_tf_->set_default_width_in_chars(30); @@ -201,6 +210,10 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile) 0, views::GridLayout::USE_PREF, 0, 0); column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); +#if defined(CHROME_PERSONALIZATION) + column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, + 0, views::GridLayout::USE_PREF, 0, 0); +#endif column_set->AddPaddingColumn(1, kUnrelatedControlHorizontalSpacing); column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); @@ -216,6 +229,10 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile) layout->StartRow(0, top_id); layout->AddView(organize_menu_button); layout->AddView(tools_menu_button); +#if defined(CHROME_PERSONALIZATION) + sync_status_button_ = new views::TextButton(this, std::wstring()); + layout->AddView(sync_status_button_); +#endif layout->AddView(new views::Label( l10n_util::GetString(IDS_BOOKMARK_MANAGER_SEARCH_TITLE))); layout->AddView(search_tf_); @@ -231,6 +248,14 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile) BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); if (!bookmark_model->IsLoaded()) bookmark_model->AddObserver(this); + +#if defined(CHROME_PERSONALIZATION) + if (profile->GetProfileSyncService()) { + sync_service_ = profile_->GetProfileSyncService(); + sync_service_->AddObserver(this); + UpdateSyncStatus(); + } +#endif } BookmarkManagerView::~BookmarkManagerView() { @@ -248,8 +273,12 @@ BookmarkManagerView::~BookmarkManagerView() { } manager = NULL; open_window = NULL; -} +#if defined(CHROME_PERSONALIZATION) + if (sync_service_) + sync_service_->RemoveObserver(this); +#endif +} // static void BookmarkManagerView::Show(Profile* profile) { @@ -357,6 +386,12 @@ void BookmarkManagerView::WindowClosing() { prefs::kBookmarkManagerSplitLocation, split_view_->divider_offset()); } +#if defined(CHROME_PERSONALIZATION) +void BookmarkManagerView::OnStateChanged() { + UpdateSyncStatus(); +} +#endif + bool BookmarkManagerView::AcceleratorPressed( const views::Accelerator& accelerator) { // Ctrl-W to close bookmark manager. @@ -489,6 +524,16 @@ void BookmarkManagerView::OnTreeViewKeyDown(unsigned short virtual_keycode) { } } +#if defined(CHROME_PERSONALIZATION) +void BookmarkManagerView::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == sync_status_button_) { + UserMetrics::RecordAction(L"BookmarkManager_Sync", profile_); + OpenSyncMyBookmarksDialog(); + } +} +#endif + void BookmarkManagerView::Loaded(BookmarkModel* model) { model->RemoveObserver(this); LoadedImpl(); @@ -793,3 +838,35 @@ void BookmarkManagerView::ShowExportBookmarksFileChooser() { L"html", GetWidget()->GetNativeView(), reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU)); } + +#if defined(CHROME_PERSONALIZATION) +void BookmarkManagerView::UpdateSyncStatus() { + DCHECK(sync_service_); + std::wstring status_label; + std::wstring link_label; + bool synced = SyncStatusUIHelper::GetLabels(sync_service_, + &status_label, &link_label) == SyncStatusUIHelper::SYNCED; + + if (sync_service_->HasSyncSetupCompleted()) { + std::wstring username = UTF16ToWide( + sync_service_->GetAuthenticatedUsername()); + status_label = l10n_util::GetStringF(IDS_SYNC_NTP_SYNCED_TO, username); + } else if (!sync_service_->SetupInProgress() && !synced) { + status_label = l10n_util::GetString(IDS_SYNC_START_SYNC_BUTTON_LABEL); + } + sync_status_button_->SetText(status_label); + sync_status_button_->GetParent()->Layout(); +} + +void BookmarkManagerView::OpenSyncMyBookmarksDialog() { + if (!sync_service_) + return; + if (sync_service_->HasSyncSetupCompleted()) { + ShowOptionsWindow(OPTIONS_PAGE_CONTENT, OPTIONS_GROUP_NONE, profile_); + } else { + sync_service_->EnableForUser(); + ProfileSyncService::SyncEvent( + ProfileSyncService::START_FROM_BOOKMARK_MANAGER); + } +} +#endif diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h index 59bdc94..af3839c 100644 --- a/chrome/browser/views/bookmark_manager_view.h +++ b/chrome/browser/views/bookmark_manager_view.h @@ -9,7 +9,9 @@ #include "base/task.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/shell_dialogs.h" +#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/views/bookmark_context_menu.h" +#include "views/controls/button/text_button.h" #include "views/controls/menu/view_menu_delegate.h" #include "views/controls/table/table_view_observer.h" #include "views/controls/textfield/textfield.h" @@ -34,14 +36,18 @@ class SingleSplitView; // text field is also provided that allows the user to search the contents // of the bookmarks. class BookmarkManagerView : public views::View, - public views::WindowDelegate, - public views::TreeViewController, + public views::ContextMenuController, + public views::MenuDelegate, public views::TableViewObserver, public views::Textfield::Controller, - public BookmarkModelObserver, - public views::ContextMenuController, + public views::TreeViewController, public views::ViewMenuDelegate, - public views::MenuDelegate, + public views::WindowDelegate, +#if defined(CHROME_PERSONALIZATION) + public views::ButtonListener, + public ProfileSyncServiceObserver, +#endif + public BookmarkModelObserver, public SelectFileDialog::Listener { public: enum CutCopyPasteType { @@ -88,6 +94,11 @@ class BookmarkManagerView : public views::View, //virtual bool ShouldShowWindowIcon() const { return true; } virtual void WindowClosing(); +#if defined(CHROME_PERSONALIZATION) + // ProfileSyncServiceObserver method. + virtual void OnStateChanged(); +#endif + Profile* profile() const { return profile_; } protected: @@ -107,6 +118,11 @@ class BookmarkManagerView : public views::View, virtual void OnTreeViewSelectionChanged(views::TreeView* tree_view); virtual void OnTreeViewKeyDown(unsigned short virtual_keycode); +#if defined(CHROME_PERSONALIZATION) + // views::ButtonListener method. + virtual void ButtonPressed(views::Button* sender, const views::Event& event); +#endif + // BookmarkModelObserver. We're only installed as an observer until the // bookmarks are loaded. virtual void Loaded(BookmarkModel* model); @@ -199,6 +215,11 @@ class BookmarkManagerView : public views::View, void ShowImportBookmarksFileChooser(); void ShowExportBookmarksFileChooser(); +#if defined(CHROME_PERSONALIZATION) + void UpdateSyncStatus(); + void OpenSyncMyBookmarksDialog(); +#endif + Profile* profile_; BookmarkTableView* table_view_; BookmarkFolderTreeView* tree_view_; @@ -210,6 +231,15 @@ class BookmarkManagerView : public views::View, // Import/export file dialog. scoped_refptr<SelectFileDialog> select_file_dialog_; +#if defined(CHROME_PERSONALIZATION) + // The sync status button that notifies the user about the current status of + // bookmarks synchronization. + views::TextButton* sync_status_button_; + + // A pointer to the ProfileSyncService instance if one exists. + ProfileSyncService* sync_service_; +#endif + // Factory used for delaying search. ScopedRunnableMethodFactory<BookmarkManagerView> search_factory_; |