diff options
-rw-r--r-- | mail/e-mail-print-config-headers.c | 473 | ||||
-rw-r--r-- | mail/e-mail-print-config-headers.h | 5 |
2 files changed, 55 insertions, 423 deletions
diff --git a/mail/e-mail-print-config-headers.c b/mail/e-mail-print-config-headers.c index 20705004f2..5a5cf35083 100644 --- a/mail/e-mail-print-config-headers.c +++ b/mail/e-mail-print-config-headers.c @@ -28,14 +28,6 @@ ((obj), E_TYPE_MAIL_PRINT_CONFIG_HEADERS, EMailPrintConfigHeadersPrivate)) struct _EMailPrintConfigHeadersPrivate { - GtkTreeView *tree_view; /* not referenced */ - GtkWidget *go_top_button; /* not referenced */ - GtkWidget *go_up_button; /* not referenced */ - GtkWidget *go_down_button; /* not referenced */ - GtkWidget *go_bottom_button; /* not referenced */ - GtkWidget *select_all_button; /* not referenced */ - GtkWidget *clear_button; /* not referenced */ - EMailPartHeaders *part; }; @@ -47,293 +39,21 @@ enum { G_DEFINE_TYPE ( EMailPrintConfigHeaders, e_mail_print_config_headers, - GTK_TYPE_BOX) - -static GtkToolItem * -mail_print_config_headers_new_tool_button (const gchar *icon_name) -{ - GIcon *icon; - GtkWidget *image; - - icon = g_themed_icon_new_with_default_fallbacks (icon_name); - image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_widget_show (image); - g_object_unref (icon); - - return gtk_tool_button_new (image, NULL); -} - -static gboolean -mail_print_config_headers_first_row_selected (EMailPrintConfigHeaders *config) -{ - GtkTreeModel *tree_model; - GtkTreeSelection *selection; - GtkTreeIter iter; - - tree_model = gtk_tree_view_get_model (config->priv->tree_view); - selection = gtk_tree_view_get_selection (config->priv->tree_view); - - if (!gtk_tree_model_iter_nth_child (tree_model, &iter, NULL, 0)) - return FALSE; - - return gtk_tree_selection_iter_is_selected (selection, &iter); -} - -static gboolean -mail_print_config_headers_last_row_selected (EMailPrintConfigHeaders *config) -{ - GtkTreeModel *tree_model; - GtkTreeSelection *selection; - GtkTreeIter iter; - gint last; - - tree_model = gtk_tree_view_get_model (config->priv->tree_view); - selection = gtk_tree_view_get_selection (config->priv->tree_view); - - last = gtk_tree_model_iter_n_children (tree_model, NULL) - 1; - if (last < 0) - return FALSE; - - if (!gtk_tree_model_iter_nth_child (tree_model, &iter, NULL, last)) - return FALSE; - - return gtk_tree_selection_iter_is_selected (selection, &iter); -} - -static gboolean -mail_print_config_headers_move_selection_up (EMailPrintConfigHeaders *config) -{ - GtkListStore *list_store; - GtkTreeModel *tree_model; - GtkTreeSelection *selection; - GList *list, *link; - - /* Move all selected rows up one, even - * if the selection is not contiguous. */ - - if (mail_print_config_headers_first_row_selected (config)) - return FALSE; - - selection = gtk_tree_view_get_selection (config->priv->tree_view); - list = gtk_tree_selection_get_selected_rows (selection, &tree_model); - - list_store = GTK_LIST_STORE (tree_model); - - for (link = list; link != NULL; link = g_list_next (link)) { - GtkTreePath *path = link->data; - GtkTreeIter iter; - GtkTreeIter prev; - - if (!gtk_tree_model_get_iter (tree_model, &iter, path)) { - g_warn_if_reached (); - continue; - } - - prev = iter; - if (!gtk_tree_model_iter_previous (tree_model, &prev)) { - g_warn_if_reached (); - continue; - } - - gtk_list_store_swap (list_store, &iter, &prev); - } - - g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); - - return TRUE; -} - -static gboolean -mail_print_config_headers_move_selection_down (EMailPrintConfigHeaders *config) -{ - GtkListStore *list_store; - GtkTreeModel *tree_model; - GtkTreeSelection *selection; - GList *list, *link; - - /* Move all selected rows down one, even - * if the selection is not contiguous. */ - - if (mail_print_config_headers_last_row_selected (config)) - return FALSE; - - selection = gtk_tree_view_get_selection (config->priv->tree_view); - list = gtk_tree_selection_get_selected_rows (selection, &tree_model); - - /* Reverse the list so we don't disturb rows we've already moved. */ - list = g_list_reverse (list); - - list_store = GTK_LIST_STORE (tree_model); - - for (link = list; link != NULL; link = g_list_next (link)) { - GtkTreePath *path = link->data; - GtkTreeIter iter; - GtkTreeIter next; - - if (!gtk_tree_model_get_iter (tree_model, &iter, path)) { - g_warn_if_reached (); - continue; - } - - next = iter; - if (!gtk_tree_model_iter_next (tree_model, &next)) { - g_warn_if_reached (); - continue; - } - - gtk_list_store_swap (list_store, &iter, &next); - } - - g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); - - return TRUE; -} - -static void -mail_print_config_headers_scroll_to_cursor (EMailPrintConfigHeaders *config) -{ - GtkTreePath *path = NULL; - - gtk_tree_view_get_cursor (config->priv->tree_view, &path, NULL); - - if (path != NULL) { - gtk_tree_view_scroll_to_cell ( - config->priv->tree_view, - path, NULL, FALSE, 0.0, 0.0); - gtk_tree_path_free (path); - } -} - -static void -mail_print_config_headers_update_buttons (EMailPrintConfigHeaders *config) -{ - GtkWidget *widget; - GtkTreeModel *tree_model; - GtkTreeSelection *selection; - gboolean first_row_selected; - gboolean last_row_selected; - gboolean sensitive; - gint n_selected_rows; - gint n_rows; - - tree_model = gtk_tree_view_get_model (config->priv->tree_view); - selection = gtk_tree_view_get_selection (config->priv->tree_view); - - n_rows = gtk_tree_model_iter_n_children (tree_model, NULL); - n_selected_rows = gtk_tree_selection_count_selected_rows (selection); - - first_row_selected = - mail_print_config_headers_first_row_selected (config); - last_row_selected = - mail_print_config_headers_last_row_selected (config); - - widget = config->priv->go_top_button; - sensitive = (n_selected_rows > 0 && !first_row_selected); - gtk_widget_set_sensitive (widget, sensitive); - - widget = config->priv->go_up_button; - sensitive = (n_selected_rows > 0 && !first_row_selected); - gtk_widget_set_sensitive (widget, sensitive); - - widget = config->priv->go_down_button; - sensitive = (n_selected_rows > 0 && !last_row_selected); - gtk_widget_set_sensitive (widget, sensitive); - - widget = config->priv->go_bottom_button; - sensitive = (n_selected_rows > 0 && !last_row_selected); - gtk_widget_set_sensitive (widget, sensitive); - - widget = config->priv->select_all_button; - sensitive = (n_selected_rows < n_rows); - gtk_widget_set_sensitive (widget, sensitive); - - widget = config->priv->clear_button; - sensitive = (n_selected_rows > 0); - gtk_widget_set_sensitive (widget, sensitive); -} - -static void -mail_print_config_headers_go_top_cb (GtkToolButton *tool_button, - EMailPrintConfigHeaders *config) -{ - /* Not the most efficient method, but it's simple and works. - * There should not be so many headers that this is a major - * performance hit anyway. */ - while (mail_print_config_headers_move_selection_up (config)) - ; - - mail_print_config_headers_scroll_to_cursor (config); - mail_print_config_headers_update_buttons (config); -} - -static void -mail_print_config_headers_go_up_cb (GtkToolButton *tool_button, - EMailPrintConfigHeaders *config) -{ - mail_print_config_headers_move_selection_up (config); - - mail_print_config_headers_scroll_to_cursor (config); - mail_print_config_headers_update_buttons (config); -} - -static void -mail_print_config_headers_go_down_cb (GtkToolButton *tool_button, - EMailPrintConfigHeaders *config) -{ - mail_print_config_headers_move_selection_down (config); - - mail_print_config_headers_scroll_to_cursor (config); - mail_print_config_headers_update_buttons (config); -} - -static void -mail_print_config_headers_go_bottom_cb (GtkToolButton *tool_button, - EMailPrintConfigHeaders *config) -{ - /* Not the most efficient method, but it's simple and works. - * There should not be so many headers that this is a major - * performance hit anyway. */ - while (mail_print_config_headers_move_selection_down (config)) - ; - - mail_print_config_headers_scroll_to_cursor (config); - mail_print_config_headers_update_buttons (config); -} - -static void -mail_print_config_headers_select_all_cb (GtkToolButton *tool_button, - EMailPrintConfigHeaders *config) -{ - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (config->priv->tree_view); - gtk_tree_selection_select_all (selection); - - mail_print_config_headers_update_buttons (config); -} - -static void -mail_print_config_headers_unselect_all_cb (GtkToolButton *tool_button, - EMailPrintConfigHeaders *config) -{ - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (config->priv->tree_view); - gtk_tree_selection_unselect_all (selection); - - mail_print_config_headers_update_buttons (config); -} + E_TYPE_TREE_VIEW_FRAME) static void mail_print_config_headers_toggled_cb (GtkCellRendererToggle *renderer, const gchar *path_string, - EMailPrintConfigHeaders *config) + ETreeViewFrame *tree_view_frame) { + GtkTreeView *tree_view; GtkTreeModel *tree_model; GtkTreeIter iter; gboolean include; - tree_model = gtk_tree_view_get_model (config->priv->tree_view); + tree_view = e_tree_view_frame_get_tree_view (tree_view_frame); + + tree_model = gtk_tree_view_get_model (tree_view); gtk_tree_model_get_iter_from_string (tree_model, &iter, path_string); gtk_tree_model_get ( @@ -344,14 +64,8 @@ mail_print_config_headers_toggled_cb (GtkCellRendererToggle *renderer, GTK_LIST_STORE (tree_model), &iter, E_MAIL_PART_HEADERS_PRINT_MODEL_COLUMN_INCLUDE, !include, -1); - mail_print_config_headers_update_buttons (config); -} - -static void -mail_print_config_headers_selection_changed_cb (GtkTreeSelection *selection, - EMailPrintConfigHeaders *config) -{ - mail_print_config_headers_update_buttons (config); + /* XXX Maybe not needed? */ + e_tree_view_frame_update_toolbar_actions (tree_view_frame); } static void @@ -417,17 +131,15 @@ static void mail_print_config_headers_constructed (GObject *object) { EMailPrintConfigHeaders *config; - GtkStyleContext *style_context; - GtkWidget *widget; - GtkWidget *container; - GtkToolItem *tool_item; + ETreeViewFrame *tree_view_frame; + GtkAction *action; + GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreeViewColumn *column; GtkCellRenderer *renderer; EMailPartHeaders *part; GtkTreeModel *print_model; - const gchar *icon_name; - const gchar *text; + const gchar *tooltip; config = E_MAIL_PRINT_CONFIG_HEADERS (object); @@ -435,124 +147,47 @@ mail_print_config_headers_constructed (GObject *object) G_OBJECT_CLASS (e_mail_print_config_headers_parent_class)-> constructed (object); - gtk_container_set_border_width (GTK_CONTAINER (object), 12); + tree_view_frame = E_TREE_VIEW_FRAME (object); + tree_view = e_tree_view_frame_get_tree_view (tree_view_frame); - gtk_orientable_set_orientation ( - GTK_ORIENTABLE (object), GTK_ORIENTATION_VERTICAL); + gtk_tree_view_set_reorderable (tree_view, TRUE); - container = GTK_WIDGET (object); + /* Configure the toolbar actions. */ - widget = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type ( - GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - gtk_widget_show (widget); + action = e_tree_view_frame_lookup_toolbar_action ( + tree_view_frame, E_TREE_VIEW_FRAME_ACTION_ADD); + gtk_action_set_visible (action, FALSE); - container = widget; + action = e_tree_view_frame_lookup_toolbar_action ( + tree_view_frame, E_TREE_VIEW_FRAME_ACTION_REMOVE); + gtk_action_set_visible (action, FALSE); - widget = gtk_tree_view_new (); - gtk_tree_view_set_reorderable (GTK_TREE_VIEW (widget), TRUE); - gtk_container_add (GTK_CONTAINER (container), widget); - config->priv->tree_view = GTK_TREE_VIEW (widget); - gtk_widget_show (widget); + action = e_tree_view_frame_lookup_toolbar_action ( + tree_view_frame, E_TREE_VIEW_FRAME_ACTION_MOVE_TOP); + tooltip = _("Move selected headers to top"); + gtk_action_set_tooltip (action, tooltip); - container = GTK_WIDGET (object); + action = e_tree_view_frame_lookup_toolbar_action ( + tree_view_frame, E_TREE_VIEW_FRAME_ACTION_MOVE_UP); + tooltip = _("Move selected headers up one row"); + gtk_action_set_tooltip (action, tooltip); - widget = gtk_toolbar_new (); - gtk_toolbar_set_icon_size (GTK_TOOLBAR (widget), GTK_ICON_SIZE_MENU); - style_context = gtk_widget_get_style_context (widget); - gtk_style_context_set_junction_sides ( - style_context, GTK_JUNCTION_TOP); - gtk_style_context_add_class ( - style_context, GTK_STYLE_CLASS_INLINE_TOOLBAR); - gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); - gtk_widget_show (widget); + action = e_tree_view_frame_lookup_toolbar_action ( + tree_view_frame, E_TREE_VIEW_FRAME_ACTION_MOVE_DOWN); + tooltip = _("Move selected headers down one row"); + gtk_action_set_tooltip (action, tooltip); - container = widget; + action = e_tree_view_frame_lookup_toolbar_action ( + tree_view_frame, E_TREE_VIEW_FRAME_ACTION_MOVE_BOTTOM); + tooltip = _("Move selected headers to bottom"); + gtk_action_set_tooltip (action, tooltip); - icon_name = "go-top-symbolic"; - tool_item = mail_print_config_headers_new_tool_button (icon_name); - gtk_toolbar_insert (GTK_TOOLBAR (container), tool_item, -1); - config->priv->go_top_button = GTK_WIDGET (tool_item); - gtk_widget_show (GTK_WIDGET (tool_item)); + action = e_tree_view_frame_lookup_toolbar_action ( + tree_view_frame, E_TREE_VIEW_FRAME_ACTION_SELECT_ALL); + tooltip = _("Select all headers"); + gtk_action_set_tooltip (action, tooltip); - text = _("Move selection to top"); - gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), text); - - g_signal_connect ( - tool_item, "clicked", - G_CALLBACK (mail_print_config_headers_go_top_cb), - config); - - icon_name = "go-up-symbolic"; - tool_item = mail_print_config_headers_new_tool_button (icon_name); - gtk_toolbar_insert (GTK_TOOLBAR (container), tool_item, -1); - config->priv->go_up_button = GTK_WIDGET (tool_item); - gtk_widget_show (GTK_WIDGET (tool_item)); - - text = _("Move selection up one row"); - gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), text); - - g_signal_connect ( - tool_item, "clicked", - G_CALLBACK (mail_print_config_headers_go_up_cb), - config); - - icon_name = "go-down-symbolic"; - tool_item = mail_print_config_headers_new_tool_button (icon_name); - gtk_toolbar_insert (GTK_TOOLBAR (container), tool_item, -1); - config->priv->go_down_button = GTK_WIDGET (tool_item); - gtk_widget_show (GTK_WIDGET (tool_item)); - - text = _("Move selection down one row"); - gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), text); - - g_signal_connect ( - tool_item, "clicked", - G_CALLBACK (mail_print_config_headers_go_down_cb), - config); - - icon_name = "go-bottom-symbolic"; - tool_item = mail_print_config_headers_new_tool_button (icon_name); - gtk_toolbar_insert (GTK_TOOLBAR (container), tool_item, -1); - config->priv->go_bottom_button = GTK_WIDGET (tool_item); - gtk_widget_show (GTK_WIDGET (tool_item)); - - text = _("Move selection to bottom"); - gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), text); - - g_signal_connect ( - tool_item, "clicked", - G_CALLBACK (mail_print_config_headers_go_bottom_cb), - config); - - icon_name = "edit-select-all-symbolic"; - tool_item = mail_print_config_headers_new_tool_button (icon_name); - gtk_toolbar_insert (GTK_TOOLBAR (container), tool_item, -1); - config->priv->select_all_button = GTK_WIDGET (tool_item); - gtk_widget_show (GTK_WIDGET (tool_item)); - - text = _("Select all headers"); - gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), text); - - g_signal_connect ( - tool_item, "clicked", - G_CALLBACK (mail_print_config_headers_select_all_cb), - config); - - icon_name = "edit-clear-symbolic"; - tool_item = mail_print_config_headers_new_tool_button (icon_name); - gtk_toolbar_insert (GTK_TOOLBAR (container), tool_item, -1); - config->priv->clear_button = GTK_WIDGET (tool_item); - gtk_widget_show (GTK_WIDGET (tool_item)); - - text = _("Unselect all headers"); - gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), text); - - g_signal_connect ( - tool_item, "clicked", - G_CALLBACK (mail_print_config_headers_unselect_all_cb), - config); + /* Configure the tree view columns. */ column = gtk_tree_view_column_new (); renderer = gtk_cell_renderer_toggle_new (); @@ -560,11 +195,12 @@ mail_print_config_headers_constructed (GObject *object) gtk_tree_view_column_add_attribute ( column, renderer, "active", E_MAIL_PART_HEADERS_PRINT_MODEL_COLUMN_INCLUDE); - gtk_tree_view_append_column (config->priv->tree_view, column); + gtk_tree_view_append_column (tree_view, column); g_signal_connect ( renderer, "toggled", - G_CALLBACK (mail_print_config_headers_toggled_cb), config); + G_CALLBACK (mail_print_config_headers_toggled_cb), + tree_view_frame); column = gtk_tree_view_column_new (); gtk_tree_view_column_set_title (column, _("Header Name")); @@ -573,7 +209,7 @@ mail_print_config_headers_constructed (GObject *object) gtk_tree_view_column_add_attribute ( column, renderer, "text", E_MAIL_PART_HEADERS_PRINT_MODEL_COLUMN_HEADER_NAME); - gtk_tree_view_append_column (config->priv->tree_view, column); + gtk_tree_view_append_column (tree_view, column); column = gtk_tree_view_column_new (); gtk_tree_view_column_set_title (column, _("Header Value")); @@ -582,23 +218,18 @@ mail_print_config_headers_constructed (GObject *object) gtk_tree_view_column_add_attribute ( column, renderer, "text", E_MAIL_PART_HEADERS_PRINT_MODEL_COLUMN_HEADER_VALUE); - gtk_tree_view_append_column (config->priv->tree_view, column); + gtk_tree_view_append_column (tree_view, column); + + /* Set the tree model and selection mode. */ part = e_mail_print_config_headers_ref_part (config); print_model = e_mail_part_headers_ref_print_model (part); - gtk_tree_view_set_model (config->priv->tree_view, print_model); + gtk_tree_view_set_model (tree_view, print_model); g_object_unref (print_model); g_object_unref (part); - selection = gtk_tree_view_get_selection (config->priv->tree_view); + selection = gtk_tree_view_get_selection (tree_view); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); - - g_signal_connect ( - selection, "changed", - G_CALLBACK (mail_print_config_headers_selection_changed_cb), - config); - - mail_print_config_headers_update_buttons (config); } static void diff --git a/mail/e-mail-print-config-headers.h b/mail/e-mail-print-config-headers.h index 5b7d923a07..3baad2ec8d 100644 --- a/mail/e-mail-print-config-headers.h +++ b/mail/e-mail-print-config-headers.h @@ -19,6 +19,7 @@ #ifndef E_MAIL_PRINT_CONFIG_HEADERS_H #define E_MAIL_PRINT_CONFIG_HEADERS_H +#include <e-util/e-util.h> #include <em-format/e-mail-part-headers.h> /* Standard GObject macros */ @@ -47,12 +48,12 @@ typedef struct _EMailPrintConfigHeadersClass EMailPrintConfigHeadersClass; typedef struct _EMailPrintConfigHeadersPrivate EMailPrintConfigHeadersPrivate; struct _EMailPrintConfigHeaders { - GtkBox parent; + ETreeViewFrame parent; EMailPrintConfigHeadersPrivate *priv; }; struct _EMailPrintConfigHeadersClass { - GtkBoxClass parent_class; + ETreeViewFrameClass parent_class; }; GType e_mail_print_config_headers_get_type |