diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-24 21:46:36 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-24 21:46:36 +0000 |
commit | 6f1ece11cc87ef228d55939ce62593207b0acfa5 (patch) | |
tree | 4d77b926d7aa4ded830a48b1923fcee611cc351b /chrome/browser/gtk | |
parent | 16ac16a5d3d646772a32815d66a8ca7b83c0e86c (diff) | |
download | chromium_src-6f1ece11cc87ef228d55939ce62593207b0acfa5.zip chromium_src-6f1ece11cc87ef228d55939ce62593207b0acfa5.tar.gz chromium_src-6f1ece11cc87ef228d55939ce62593207b0acfa5.tar.bz2 |
Update the sync menu item to change on Linux to reflect the current sync state.
BUG=28209
TEST=Enable sync and sign in. The "Sync my Bookmarks" label should now read "Bookmarks Synced..."
Review URL: http://codereview.chromium.org/431032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 49 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 10 |
2 files changed, 59 insertions, 0 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index e0c5965..9fc35fb 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -5,6 +5,7 @@ #include "chrome/browser/gtk/browser_toolbar_gtk.h" #include <gdk/gdkkeysyms.h> +#include <gtk/gtk.h> #include <X11/XF86keysym.h> #include "app/gfx/gtk_util.h" @@ -33,6 +34,7 @@ #include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/profile.h" +#include "chrome/browser/sync/sync_status_ui_helper.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/gtk_util.h" #include "chrome/common/notification_details.h" @@ -80,6 +82,7 @@ BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) browser_(browser), window_(window), profile_(NULL), + sync_service_(NULL), menu_bar_helper_(this) { browser_->command_updater()->AddCommandObserver(IDC_BACK, this); browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); @@ -93,6 +96,9 @@ BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) } BrowserToolbarGtk::~BrowserToolbarGtk() { + if (sync_service_) + sync_service_->RemoveObserver(this); + browser_->command_updater()->RemoveCommandObserver(IDC_BACK, this); browser_->command_updater()->RemoveCommandObserver(IDC_FORWARD, this); browser_->command_updater()->RemoveCommandObserver(IDC_RELOAD, this); @@ -409,6 +415,13 @@ void BrowserToolbarGtk::SetProfile(Profile* profile) { profile_ = profile; location_bar_->SetProfile(profile); + + if (profile_->GetProfileSyncService()) { + // Obtain a pointer to the profile sync service and add our instance as an + // observer. + sync_service_ = profile_->GetProfileSyncService(); + sync_service_->AddObserver(this); + } } void BrowserToolbarGtk::UpdateTabContents(TabContents* contents, @@ -683,6 +696,42 @@ void BrowserToolbarGtk::OnDragDataReceived(GtkWidget* widget, } } +void BrowserToolbarGtk::OnStateChanged() { + DCHECK(sync_service_); + + string16 label; + string16 link; + // TODO(zork): Need a ui helper method to just get the type without + // needing labels. + SyncStatusUIHelper::MessageType type = SyncStatusUIHelper::GetLabels( + sync_service_, &label, &link); + + int menu_label = type == SyncStatusUIHelper::SYNCED ? + IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL : + type == SyncStatusUIHelper::SYNC_ERROR ? + IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL : + IDS_SYNC_START_SYNC_BUTTON_LABEL; + + gtk_container_foreach(GTK_CONTAINER(app_menu_->widget()), &SetSyncMenuLabel, + &menu_label); +} + +// static +void BrowserToolbarGtk::SetSyncMenuLabel(GtkWidget* widget, gpointer userdata) { + const MenuCreateMaterial* data = + reinterpret_cast<const MenuCreateMaterial*>( + g_object_get_data(G_OBJECT(widget), "menu-data")); + if (data) { + if (data->id == IDC_SYNC_BOOKMARKS) { + std::string label; + label = l10n_util::GetStringUTF8(*((int *)userdata)); + label = gtk_util::ConvertAcceleratorsFromWindowsStyle(label); + GtkWidget *menu_label = gtk_bin_get_child(GTK_BIN(widget)); + gtk_label_set_label(GTK_LABEL(menu_label), label.c_str()); + } + } +} + bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { // If we're a popup window, only show the location bar (omnibox). return browser_->type() != Browser::TYPE_NORMAL; diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index dd5aea9e..7d934f4 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -13,6 +13,7 @@ #include "chrome/browser/command_updater.h" #include "chrome/browser/gtk/menu_bar_helper.h" #include "chrome/browser/gtk/menu_gtk.h" +#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/pref_member.h" @@ -34,6 +35,7 @@ class ToolbarStarToggleGtk; // View class that displays the GTK version of the toolbar and routes gtk // events back to the Browser. class BrowserToolbarGtk : public CommandUpdater::CommandObserver, + public ProfileSyncServiceObserver, public MenuGtk::Delegate, public NotificationObserver, public BubblePositioner, @@ -155,6 +157,11 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, guint info, guint time, BrowserToolbarGtk* toolbar); + // ProfileSyncServiceObserver method. + virtual void OnStateChanged(); + + static void SetSyncMenuLabel(GtkWidget* widget, gpointer userdata); + // Sometimes we only want to show the location w/o the toolbar buttons (e.g., // in a popup window). bool ShouldOnlyShowLocation() const; @@ -204,6 +211,9 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, BrowserWindowGtk* window_; Profile* profile_; + // A pointer to the ProfileSyncService instance if one exists. + ProfileSyncService* sync_service_; + // Controls whether or not a home button should be shown on the toolbar. BooleanPrefMember show_home_button_; |