* Added detection of horizontal-movement and tree view row resolution
authorSergio Villar Senín <svillar@igalia.com>
Thu, 14 May 2009 09:48:09 +0000 (11:48 +0200)
committerSergio Villar Senín <svillar@igalia.com>
Thu, 14 May 2009 11:18:52 +0000 (13:18 +0200)
* 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
src/modest-mail-operation.h
src/widgets/modest-header-view.c
src/widgets/modest-header-view.h

index 1cba33b..a07d999 100644 (file)
@@ -52,6 +52,7 @@
 #include <hildon/hildon-banner.h>
 #include <modest-ui-dimming-rules.h>
 #include <modest-tny-folder.h>
+#include <tny-simple-list.h>
 
 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);
+       }
+}
index f3e17ee..9166b93 100644 (file)
@@ -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
index 5a671fb..f4f8781 100644 (file)
@@ -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;
+}
index 0b23c59..be9b88c 100644 (file)
@@ -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