diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2008-10-25 07:02:33 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-10-25 07:02:33 +0800 |
commit | e7a31c5035a0afeed6c1675e30487c1e2bdc139f (patch) | |
tree | eb1e733a6fe69773498725efa64304a9234270bc /addressbook/gui | |
parent | 95cae9b166587d19db3aadde6a21cc12c30da6e6 (diff) | |
download | gsoc2013-evolution-e7a31c5035a0afeed6c1675e30487c1e2bdc139f.tar.gz gsoc2013-evolution-e7a31c5035a0afeed6c1675e30487c1e2bdc139f.tar.zst gsoc2013-evolution-e7a31c5035a0afeed6c1675e30487c1e2bdc139f.zip |
Commit recent work so I can merge from trunk.
svn path=/branches/kill-bonobo/; revision=36684
Diffstat (limited to 'addressbook/gui')
-rw-r--r-- | addressbook/gui/component/e-book-shell-content.c | 40 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-content.h | 12 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-sidebar.c | 34 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-sidebar.h | 5 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view-actions.h | 6 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view.c | 133 |
6 files changed, 170 insertions, 60 deletions
diff --git a/addressbook/gui/component/e-book-shell-content.c b/addressbook/gui/component/e-book-shell-content.c index 6b7b01bc4c..8190a5958a 100644 --- a/addressbook/gui/component/e-book-shell-content.c +++ b/addressbook/gui/component/e-book-shell-content.c @@ -185,10 +185,47 @@ book_shell_content_constructed (GObject *object) gconf_bridge_bind_property_delayed (bridge, key, object, "position"); } +static guint32 +book_shell_content_check_state (EShellContent *shell_content) +{ + EBookShellContent *book_shell_content; + ESelectionModel *selection_model; + EAddressbookModel *model; + EAddressbookView *view; + guint32 state = 0; + gint n_contacts; + gint n_selected; + + book_shell_content = E_BOOK_SHELL_CONTENT (shell_content); + view = e_book_shell_content_get_current_view (book_shell_content); + model = e_addressbook_view_get_model (view); + + selection_model = e_addressbook_view_get_selection_model (view); + n_contacts = (selection_model != NULL) ? + e_selection_model_row_count (selection_model) : 0; + n_selected = (selection_model != NULL) ? + e_selection_model_selected_count (selection_model) : 0; + + /* FIXME Finish the rest of the flags. */ + if (n_selected == 1) + state |= E_BOOK_SHELL_CONTENT_SELECTION_SINGLE; + if (n_selected > 1) + state |= E_BOOK_SHELL_CONTENT_SELECTION_MULTIPLE; + if (e_addressbook_model_can_stop (model)) + state |= E_BOOK_SHELL_CONTENT_SOURCE_IS_BUSY; + if (e_addressbook_model_get_editable (model)) + state |= E_BOOK_SHELL_CONTENT_SOURCE_IS_EDITABLE; + if (n_contacts == 0) + state |= E_BOOK_SHELL_CONTENT_SOURCE_IS_EMPTY; + + return state; +} + static void book_shell_content_class_init (EBookShellContentClass *class) { GObjectClass *object_class; + EShellContentClass *shell_content_class; parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (EBookShellContentPrivate)); @@ -199,6 +236,9 @@ book_shell_content_class_init (EBookShellContentClass *class) object_class->dispose = book_shell_content_dispose; object_class->constructed = book_shell_content_constructed; + shell_content_class = E_SHELL_CONTENT_CLASS (class); + shell_content_class->check_state = book_shell_content_check_state; + g_object_class_install_property ( object_class, PROP_CURRENT_VIEW, diff --git a/addressbook/gui/component/e-book-shell-content.h b/addressbook/gui/component/e-book-shell-content.h index 2194ff3f0d..7f48503a88 100644 --- a/addressbook/gui/component/e-book-shell-content.h +++ b/addressbook/gui/component/e-book-shell-content.h @@ -54,6 +54,18 @@ typedef struct _EBookShellContent EBookShellContent; typedef struct _EBookShellContentClass EBookShellContentClass; typedef struct _EBookShellContentPrivate EBookShellContentPrivate; +enum { + E_BOOK_SHELL_CONTENT_SELECTION_SINGLE = 1 << 0, + E_BOOK_SHELL_CONTENT_SELECTION_MULTIPLE = 1 << 1, + E_BOOK_SHELL_CONTENT_SELECTION_HAS_EMAIL = 1 << 2, + E_BOOK_SHELL_CONTENT_SELECTION_IS_CONTACT_LIST = 1 << 3, + E_BOOK_SHELL_CONTENT_SELECTION_HAS_HTTP_URI = 1 << 4, + E_BOOK_SHELL_CONTENT_SELECTION_HAS_MAILTO_URI = 1 << 5, + E_BOOK_SHELL_CONTENT_SOURCE_IS_BUSY = 1 << 6, + E_BOOK_SHELL_CONTENT_SOURCE_IS_EDITABLE = 1 << 7, + E_BOOK_SHELL_CONTENT_SOURCE_IS_EMPTY = 1 << 8 +}; + struct _EBookShellContent { EShellContent parent; EBookShellContentPrivate *priv; diff --git a/addressbook/gui/component/e-book-shell-sidebar.c b/addressbook/gui/component/e-book-shell-sidebar.c index 4f8d4454d1..266550f1e5 100644 --- a/addressbook/gui/component/e-book-shell-sidebar.c +++ b/addressbook/gui/component/e-book-shell-sidebar.c @@ -115,10 +115,41 @@ book_shell_sidebar_constructed (GObject *object) gtk_widget_show (widget); } +static guint32 +book_shell_sidebar_check_state (EShellSidebar *shell_sidebar) +{ + EBookShellSidebar *book_shell_sidebar; + ESourceSelector *selector; + ESource *source; + gboolean is_system = FALSE; + guint32 state = 0; + + priv = E_BOOK_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar); + + book_shell_sidebar = E_BOOK_SHELL_SIDEBAR (shell_sidebar); + selector = e_book_shell_sidebar_get_selector (book_shell_sidebar); + source = e_source_selector_peek_primary_selection (selector); + + if (source != NULL) { + const gchar *uri; + + uri = e_source_peek_relative_uri (source); + is_system = (uri == NULL || strcmp (uri, "system") == 0); + } + + if (source != NULL) + state |= E_BOOK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE; + if (is_system) + state |= E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_SYSTEM; + + return state; +} + static void book_shell_sidebar_class_init (EBookShellSidebarClass *class) { GObjectClass *object_class; + EShellSidebarClass *shell_sidebar_class; parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (EBookShellSidebarPrivate)); @@ -128,6 +159,9 @@ book_shell_sidebar_class_init (EBookShellSidebarClass *class) object_class->dispose = book_shell_sidebar_dispose; object_class->constructed = book_shell_sidebar_constructed; + shell_sidebar_class = E_SHELL_SIDEBAR_CLASS (class); + shell_sidebar_class->check_state = book_shell_sidebar_check_state; + g_object_class_install_property ( object_class, PROP_SELECTOR, diff --git a/addressbook/gui/component/e-book-shell-sidebar.h b/addressbook/gui/component/e-book-shell-sidebar.h index c22d2cd27d..159c9c7afc 100644 --- a/addressbook/gui/component/e-book-shell-sidebar.h +++ b/addressbook/gui/component/e-book-shell-sidebar.h @@ -52,6 +52,11 @@ typedef struct _EBookShellSidebar EBookShellSidebar; typedef struct _EBookShellSidebarClass EBookShellSidebarClass; typedef struct _EBookShellSidebarPrivate EBookShellSidebarPrivate; +enum { + E_BOOK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE = 1 << 0, + E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_SYSTEM = 1 << 1 +}; + struct _EBookShellSidebar { EShellSidebar parent; EBookShellSidebarPrivate *priv; diff --git a/addressbook/gui/component/e-book-shell-view-actions.h b/addressbook/gui/component/e-book-shell-view-actions.h index 503855dda6..bcb1606933 100644 --- a/addressbook/gui/component/e-book-shell-view-actions.h +++ b/addressbook/gui/component/e-book-shell-view-actions.h @@ -31,6 +31,12 @@ E_SHELL_WINDOW_ACTION ((window), "address-book-delete") #define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_MOVE(window) \ E_SHELL_WINDOW_ACTION ((window), "address-book-move") +#define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_POPUP_DELETE(window) \ + E_SHELL_WINDOW_ACTION ((window), "address-book-popup-delete") +#define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_POPUP_PROPERTIES(window) \ + E_SHELL_WINDOW_ACTION ((window), "address-book-popup-properties") +#define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_POPUP_SAVE_AS(window) \ + E_SHELL_WINDOW_ACTION ((window), "address-book-popup-save-as") #define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_PROPERTIES(window) \ E_SHELL_WINDOW_ACTION ((window), "address-book-properties") #define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_RENAME(window) \ diff --git a/addressbook/gui/component/e-book-shell-view.c b/addressbook/gui/component/e-book-shell-view.c index 243fb908f0..fc5c6d7a7f 100644 --- a/addressbook/gui/component/e-book-shell-view.c +++ b/addressbook/gui/component/e-book-shell-view.c @@ -136,121 +136,134 @@ static void book_shell_view_update_actions (EShellView *shell_view) { EBookShellViewPrivate *priv; - EBookShellContent *book_shell_content; - EBookShellSidebar *book_shell_sidebar; + EShellContent *shell_content; + EShellSidebar *shell_sidebar; EShellWindow *shell_window; - EAddressbookModel *model; - EAddressbookView *view; - ESelectionModel *selection_model; - ESourceSelector *selector; - ESource *source; GtkAction *action; const gchar *label; - gboolean editable; gboolean sensitive; - gint n_contacts; - gint n_selected; + guint32 state; + + /* Be descriptive. */ + gboolean any_contacts_selected; + gboolean has_primary_source; + gboolean multiple_contacts_selected; + gboolean primary_source_is_system; + gboolean single_contact_selected; + gboolean selection_is_contact_list; + gboolean selection_has_email; + gboolean source_is_busy; + gboolean source_is_editable; + gboolean source_is_empty; priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); - book_shell_content = priv->book_shell_content; - view = e_book_shell_content_get_current_view (book_shell_content); - - book_shell_sidebar = priv->book_shell_sidebar; - selector = e_book_shell_sidebar_get_selector (book_shell_sidebar); - source = e_source_selector_peek_primary_selection (selector); + shell_content = e_shell_view_get_shell_content (shell_view); + state = e_shell_content_check_state (shell_content); + + single_contact_selected = + (state & E_BOOK_SHELL_CONTENT_SELECTION_SINGLE); + multiple_contacts_selected = + (state & E_BOOK_SHELL_CONTENT_SELECTION_MULTIPLE); + selection_has_email = + (state & E_BOOK_SHELL_CONTENT_SELECTION_HAS_EMAIL); + selection_is_contact_list = + (state & E_BOOK_SHELL_CONTENT_SELECTION_IS_CONTACT_LIST); + source_is_busy = + (state & E_BOOK_SHELL_CONTENT_SOURCE_IS_BUSY); + source_is_editable = + (state & E_BOOK_SHELL_CONTENT_SOURCE_IS_EDITABLE); + source_is_empty = + (state & E_BOOK_SHELL_CONTENT_SOURCE_IS_EMPTY); + + shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); + state = e_shell_sidebar_check_state (shell_sidebar); + + has_primary_source = + (state & E_BOOK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE); + primary_source_is_system = + (state & E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_SYSTEM); + + any_contacts_selected = + (single_contact_selected || multiple_contacts_selected); - model = e_addressbook_view_get_model (view); - editable = e_addressbook_model_get_editable (model); + action = ACTION (ADDRESS_BOOK_DELETE); + sensitive = has_primary_source && !primary_source_is_system; + gtk_action_set_sensitive (action, sensitive); - selection_model = e_addressbook_view_get_selection_model (view); - n_contacts = (selection_model != NULL) ? - e_selection_model_row_count (selection_model) : 0; - n_selected = (selection_model != NULL) ? - e_selection_model_selected_count (selection_model) : 0; + action = ACTION (ADDRESS_BOOK_POPUP_DELETE); + sensitive = has_primary_source && !primary_source_is_system; + gtk_action_set_sensitive (action, sensitive); action = ACTION (ADDRESS_BOOK_STOP); - sensitive = e_addressbook_model_can_stop (model); + sensitive = source_is_busy; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_CLIPBOARD_COPY); - sensitive = (n_selected > 0); + sensitive = any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_CLIPBOARD_CUT); - sensitive = editable && (n_selected > 0); + sensitive = source_is_editable && any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_CLIPBOARD_PASTE); - sensitive = editable; + sensitive = source_is_editable; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_COPY); - sensitive = (n_selected > 0); + sensitive = any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_DELETE); - sensitive = editable && (n_selected > 0); + sensitive = source_is_editable && any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_FORWARD); - sensitive = (n_selected > 0); + sensitive = any_contacts_selected; gtk_action_set_sensitive (action, sensitive); - label = ngettext ( - "_Forward Contact", - "_Forward Contacts", n_selected); + if (multiple_contacts_selected) + label = _("_Forward Contacts"); + else + label = _("_Forward Contact"); g_object_set (action, "label", label, NULL); action = ACTION (CONTACT_MOVE); - sensitive = editable && (n_selected > 0); + sensitive = source_is_editable && any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_OPEN); - sensitive = (n_selected > 0); + sensitive = any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_PRINT); - sensitive = (n_contacts > 0); + sensitive = any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_PRINT_PREVIEW); - sensitive = (n_contacts > 0); + sensitive = any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_SAVE_AS); - sensitive = (n_selected > 0); + sensitive = any_contacts_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (CONTACT_SELECT_ALL); - sensitive = (n_contacts > 0); + sensitive = !(source_is_empty); gtk_action_set_sensitive (action, sensitive); - /* FIXME Also check for email address. */ action = ACTION (CONTACT_SEND_MESSAGE); - sensitive = (n_selected > 0); + sensitive = any_contacts_selected && selection_has_email; gtk_action_set_sensitive (action, sensitive); - label = ngettext ( - "_Send Message to Contact", - "_Send Message to Contacts", n_selected); + if (multiple_contacts_selected) + label = _("_Send Message to Contacts"); + else if (selection_is_contact_list) + label = _("_Send Message to List"); + else + label = _("_Send Message to Contact"); g_object_set (action, "label", label, NULL); - - /* TODO Add some context sensitivity to SEND_MESSAGE: - * Send Message to Contact (n_selected == 1) - * Send Message to Contacts (n_selected > 1) - * Send Message to List (n_selected == 1 && is_list) - */ - - action = ACTION (ADDRESS_BOOK_DELETE); - if (source != NULL) { - const gchar *uri; - - uri = e_source_peek_relative_uri (source); - sensitive = (uri == NULL || strcmp ("system", uri) != 0); - } else - sensitive = FALSE; - gtk_action_set_sensitive (action, sensitive); } static void |