From d9eb3162361166eee20ddb8b5a8518c7ea310372 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sergio=20Villar=20Sen=C3=ADn?= Date: Thu, 14 May 2009 11:48:09 +0200 Subject: [PATCH] * Added detection of horizontal-movement and tree view row resolution * Created a new API to return a TnyHeader from its coordinates in the header view * Delete header when horizontal-movement from left to right is detected --- src/hildon2/modest-header-window.c | 79 +++++++++++++++++++++++++++++++++++- src/modest-mail-operation.h | 2 +- src/widgets/modest-header-view.c | 33 +++++++++++++++ src/widgets/modest-header-view.h | 16 ++++++++ 4 files changed, 127 insertions(+), 3 deletions(-) diff --git a/src/hildon2/modest-header-window.c b/src/hildon2/modest-header-window.c index 1cba33b..a07d999 100644 --- a/src/hildon2/modest-header-window.c +++ b/src/hildon2/modest-header-window.c @@ -52,6 +52,7 @@ #include #include #include +#include typedef enum { CONTENTS_STATE_NONE = 0, @@ -159,7 +160,11 @@ static void update_progress_hint (ModestHeaderWindow *self); static void on_sort_column_changed (GtkTreeSortable *treesortable, gpointer user_data); static void update_sort_button (ModestHeaderWindow *self); - +static void on_horizontal_movement (HildonPannableArea *hildonpannable, + gint direction, + gdouble initial_x, + gdouble initial_y, + gpointer user_data); /* globals */ static GtkWindowClass *parent_class = NULL; @@ -350,11 +355,19 @@ connect_signals (ModestHeaderWindow *self) G_OBJECT (modest_runtime_get_window_mgr ()), "progress-list-changed", G_CALLBACK (on_progress_list_changed), self); - priv->sighandlers = + priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, G_OBJECT (priv->new_message_button), "clicked", G_CALLBACK (modest_ui_actions_on_new_msg), self); + + /* Pannable area */ + priv->sighandlers = + modest_signal_mgr_connect (priv->sighandlers, + (GObject *) priv->contents_view, + "horizontal-movement", + G_CALLBACK (on_horizontal_movement), + self); } static void @@ -1144,3 +1157,65 @@ update_sort_button (ModestHeaderWindow *self) hildon_button_set_value (HILDON_BUTTON (priv->sort_button), value?value:""); } + +static void +on_horizontal_movement (HildonPannableArea *hildonpannable, + gint direction, + gdouble initial_x, + gdouble initial_y, + gpointer user_data) +{ + ModestHeaderWindowPrivate *priv; + gint dest_x, dest_y; + TnyHeader *header; + + /* Ignore right to left movement */ + if (direction == HILDON_MOVEMENT_LEFT) + return; + + /* Get the header to delete */ + priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data); + + /* Get tree view coordinates */ + if (!gtk_widget_translate_coordinates ((GtkWidget *) hildonpannable, + priv->header_view, + initial_x, + initial_y, + &dest_x, + &dest_y)) + return; + + header = modest_header_view_get_header_at_pos ((ModestHeaderView *) priv->header_view, + dest_x, dest_y); + if (header) { + gint response; + gchar *subject, *msg; + + subject = tny_header_dup_subject (header); + if (!subject) + subject = g_strdup (_("mail_va_no_subject")); + + msg = g_strdup_printf (ngettext("emev_nc_delete_message", "emev_nc_delete_messages", 1), + subject); + g_free (subject); + + /* Confirmation dialog */ + response = modest_platform_run_confirmation_dialog ((GtkWindow *) user_data, msg); + g_free (msg); + + if (response == GTK_RESPONSE_OK) { + ModestMailOperation *mail_op; + TnyList *header_list; + + header_list = tny_simple_list_new (); + tny_list_append (header_list, (GObject *) header); + mail_op = modest_mail_operation_new ((GObject *) user_data); + modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), + mail_op); + modest_mail_operation_remove_msgs (mail_op, header_list, FALSE); + g_object_unref (mail_op); + g_object_unref (header_list); + } + g_object_unref (header); + } +} diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h index f3e17ee..9166b93 100644 --- a/src/modest-mail-operation.h +++ b/src/modest-mail-operation.h @@ -580,7 +580,7 @@ void modest_mail_operation_xfer_msgs (ModestMailOperation *self, gpointer user_data); /** - * modest_mail_operation_remove_msg: + * modest_mail_operation_remove_msgs: * @self: a #ModestMailOperation * @headers: the #TnyList of the messages to delete * @remove_to_trash: TRUE to move it to trash or FALSE to delete it diff --git a/src/widgets/modest-header-view.c b/src/widgets/modest-header-view.c index 5a671fb..f4f8781 100644 --- a/src/widgets/modest-header-view.c +++ b/src/widgets/modest-header-view.c @@ -2419,3 +2419,36 @@ update_style (ModestHeaderView *self) g_object_set_data_full (G_OBJECT (priv->renderer_subject), ACTIVE_COLOR, new_color, (GDestroyNotify) gdk_color_free); #endif } + +TnyHeader * +modest_header_view_get_header_at_pos (ModestHeaderView *header_view, + gint initial_x, + gint initial_y) +{ + GtkTreePath *path; + GtkTreeModel *tree_model; + GtkTreeIter iter; + TnyHeader *header; + + /* Get tree path */ + if (!gtk_tree_view_get_dest_row_at_pos ((GtkTreeView *) header_view, + initial_x, + initial_y, + &path, + NULL)) + return NULL; + + g_debug ("located path: %s", gtk_tree_path_to_string (path)); + + /* Get model */ + tree_model = gtk_tree_view_get_model ((GtkTreeView *) header_view); + if (!gtk_tree_model_get_iter (tree_model, &iter, path)) + return NULL; + + /* Get header */ + gtk_tree_model_get (tree_model, &iter, + TNY_GTK_HEADER_LIST_MODEL_INSTANCE_COLUMN, + &header, -1); + + return header; +} diff --git a/src/widgets/modest-header-view.h b/src/widgets/modest-header-view.h index 0b23c59..be9b88c 100644 --- a/src/widgets/modest-header-view.h +++ b/src/widgets/modest-header-view.h @@ -451,6 +451,22 @@ void modest_header_view_remove_observer( ModestHeaderView *header_view, ModestHeaderViewObserver *observer); +/** + * modest_header_view_get_header_at_pos: + * @header_view: a #ModestHeaderView + * @initial_x: the x coordinate + * @initial_y: the y coordinate + * + * Return the #TnyHeader stored in the row at (x,y) coordinates + * relatives to the widget. It returns a new reference so you must + * unref it once you're done with it. + * + * Returns: a #TnyHeader if found, else NULL + **/ +TnyHeader* modest_header_view_get_header_at_pos (ModestHeaderView *header_view, + gint initial_x, + gint initial_y); + G_END_DECLS -- 1.7.9.5