diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-07 17:46:04 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-07 17:46:04 +0000 |
commit | 380d11d14957cfa9b70b612d216845fcc3df091d (patch) | |
tree | 917848abd3c57577a8b99665d8056b8ea104024a /chrome | |
parent | e982395967e9164728ba355e573ec08ffb962e8a (diff) | |
download | chromium_src-380d11d14957cfa9b70b612d216845fcc3df091d.zip chromium_src-380d11d14957cfa9b70b612d216845fcc3df091d.tar.gz chromium_src-380d11d14957cfa9b70b612d216845fcc3df091d.tar.bz2 |
Land http://codereview.chromium.org/467012 on behalf of tfarina.
Review URL: http://codereview.chromium.org/465079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.cc | 67 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.h | 22 |
2 files changed, 88 insertions, 1 deletions
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index 8324a72..cc3b9f3 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -23,6 +23,7 @@ #include "chrome/browser/gtk/bookmark_utils_gtk.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/profile.h" +#include "chrome/browser/sync/sync_ui_util.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" @@ -165,7 +166,7 @@ void BookmarkManagerGtk::SelectInTree(const BookmarkNode* node, bool expand) { int64 id = node->is_folder() ? node->id() : node->GetParent()->id(); if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, id)) { GtkTreePath* path = gtk_tree_model_get_path(GTK_TREE_MODEL(left_store_), - &iter); + &iter); gtk_tree_view_expand_to_path(GTK_TREE_VIEW(left_tree_view_), path); gtk_tree_selection_select_path(left_selection(), path); if (expand) @@ -307,6 +308,9 @@ BookmarkManagerGtk::BookmarkManagerGtk(Profile* profile) : profile_(profile), model_(profile->GetBookmarkModel()), organize_is_for_left_(true), + sync_status_menu_(NULL), + sync_service_(NULL), + sync_relogin_required_(false), search_factory_(this), select_file_dialog_(SelectFileDialog::Create(this)), delaying_mousedown_(false), @@ -319,6 +323,12 @@ BookmarkManagerGtk::BookmarkManagerGtk(Profile* profile) if (model_->IsLoaded()) Loaded(model_); + if (profile_->GetProfileSyncService()) { + sync_service_ = profile_->GetProfileSyncService(); + sync_service_->AddObserver(this); + UpdateSyncStatus(); + } + gtk_widget_show_all(window_); } @@ -329,6 +339,9 @@ BookmarkManagerGtk::~BookmarkManagerGtk() { SaveColumnConfiguration(); model_->RemoveObserver(this); + if (sync_service_) + sync_service_->RemoveObserver(this); + gtk_accel_group_disconnect_key(accel_group_, GDK_w, GDK_CONTROL_MASK); gtk_window_remove_accel_group(GTK_WINDOW(window_), accel_group_); g_object_unref(accel_group_); @@ -382,9 +395,15 @@ void BookmarkManagerGtk::InitWidgets() { l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_TOOLS_MENU).c_str()); gtk_menu_item_set_submenu(GTK_MENU_ITEM(tools), tools_menu); + // Build the sync status menu item. + sync_status_menu_ = gtk_menu_item_new_with_label(""); + g_signal_connect(sync_status_menu_, "activate", + G_CALLBACK(OnSyncStatusMenuActivated), this); + GtkWidget* menu_bar = gtk_menu_bar_new(); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), organize_); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), tools); + gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), sync_status_menu_); SetMenuBarStyle(); gtk_widget_set_name(menu_bar, "chrome-bm-menubar"); @@ -1372,6 +1391,18 @@ void BookmarkManagerGtk::OnExportItemActivated( reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU)); } +// static +void BookmarkManagerGtk::OnSyncStatusMenuActivated(GtkMenuItem* menu_item, + BookmarkManagerGtk* bm) { + if (bm->sync_relogin_required_) { + DCHECK(bm->sync_service_); + bm->sync_service_->ShowLoginDialog(); + } else { + sync_ui_util::OpenSyncMyBookmarksDialog( + bm->profile_, ProfileSyncService::START_FROM_BOOKMARK_MANAGER); + } +} + gboolean BookmarkManagerGtk::OnWindowDestroyed(GtkWidget* window) { DCHECK_EQ(this, manager); @@ -1434,6 +1465,10 @@ void BookmarkManagerGtk::FileSelected(const FilePath& path, } } +void BookmarkManagerGtk::OnStateChanged() { + UpdateSyncStatus(); +} + // static gboolean BookmarkManagerGtk::OnGtkAccelerator(GtkAccelGroup* accel_group, GObject* acceleratable, @@ -1451,3 +1486,33 @@ gboolean BookmarkManagerGtk::OnGtkAccelerator(GtkAccelGroup* accel_group, return TRUE; } + +void BookmarkManagerGtk::UpdateSyncStatus() { + DCHECK(sync_service_); + string16 status_label; + string16 link_label; + sync_relogin_required_ = sync_ui_util::GetStatusLabels( + sync_service_, &status_label, &link_label) == sync_ui_util::SYNC_ERROR; + + if (sync_relogin_required_) { + GtkWidget* sync_status_label = gtk_bin_get_child( + GTK_BIN(sync_status_menu_)); + gtk_label_set_label( + GTK_LABEL(sync_status_label), + l10n_util::GetStringUTF8(IDS_SYNC_BOOKMARK_BAR_ERROR).c_str()); + return; + } + + if (sync_service_->HasSyncSetupCompleted()) { + string16 username = sync_service_->GetAuthenticatedUsername(); + status_label = l10n_util::GetStringFUTF16(IDS_SYNC_NTP_SYNCED_TO, + username); + } else if (sync_service_->SetupInProgress()) { + status_label = l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS); + } else { + status_label = l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); + } + GtkWidget* sync_status_label = gtk_bin_get_child(GTK_BIN(sync_status_menu_)); + gtk_label_set_label(GTK_LABEL(sync_status_label), + UTF16ToUTF8(status_label).c_str()); +} diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h index 303dac3..7d21d28 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.h +++ b/chrome/browser/gtk/bookmark_manager_gtk.h @@ -14,6 +14,7 @@ #include "base/task.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/gtk/bookmark_context_menu_gtk.h" +#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/common/gtk_tree.h" #include "testing/gtest/include/gtest/gtest_prod.h" @@ -23,6 +24,7 @@ class BookmarkTableModel; class Profile; class BookmarkManagerGtk : public BookmarkModelObserver, + public ProfileSyncServiceObserver, public gtk_tree::TableAdapter::Delegate, public SelectFileDialog::Listener { public: @@ -68,6 +70,9 @@ class BookmarkManagerGtk : public BookmarkModelObserver, virtual void FileSelected(const FilePath& path, int index, void* params); + // ProfileSyncServiceObserver implementation. + virtual void OnStateChanged(); + private: friend class BookmarkManagerTest; FRIEND_TEST(BookmarkManagerTest, Crash); @@ -264,6 +269,10 @@ class BookmarkManagerGtk : public BookmarkModelObserver, static void OnExportItemActivated(GtkMenuItem* menuitem, BookmarkManagerGtk* bm); + // Sync status menu item callback. + static void OnSyncStatusMenuActivated(GtkMenuItem* menu_item, + BookmarkManagerGtk* bm); + // Window callbacks. static gboolean OnWindowDestroyedThunk(GtkWidget* window, gpointer self) { return reinterpret_cast<BookmarkManagerGtk*>(self)-> @@ -294,6 +303,8 @@ class BookmarkManagerGtk : public BookmarkModelObserver, GdkModifierType modifier, BookmarkManagerGtk* bookmark_manager); + void UpdateSyncStatus(); + GtkWidget* window_; GtkWidget* search_entry_; Profile* profile_; @@ -331,6 +342,17 @@ class BookmarkManagerGtk : public BookmarkModelObserver, // Whether the menu refers to the left selection. bool organize_is_for_left_; + // The sync status menu item that notifies the user about the current status + // of bookmarks synchronization. + GtkWidget* sync_status_menu_; + + // A pointer to the ProfileSyncService instance if one exists. + ProfileSyncService* sync_service_; + + // True if the cached credentials have expired and we need to prompt the + // user to re-enter their password. + bool sync_relogin_required_; + // Factory used for delaying search. ScopedRunnableMethodFactory<BookmarkManagerGtk> search_factory_; |