#include <tny-simple-list.h>
#include <tny-folder-monitor.h>
#include <tny-folder-change.h>
+#include <tny-error.h>
#include <string.h>
#include <modest-header-view.h>
GtkTreeModel *model,
const gchar *tny_folder_id);
-static gboolean modest_header_view_on_expose_event(
- GtkTreeView *header_view,
- GdkEventExpose *event,
- gpointer user_data);
+static gboolean modest_header_view_on_expose_event (GtkTreeView *header_view,
+ GdkEventExpose *event,
+ gpointer user_data);
typedef enum {
HEADER_VIEW_NON_EMPTY,
HeaderViewStatus status;
guint status_timeout;
+ gboolean notify_status; /* whether or not the filter_row should notify about changes in the filtering */
};
typedef struct _HeadersCountChangedHelper HeadersCountChangedHelper;
static void
tny_folder_observer_init (TnyFolderObserverIface *klass)
{
- klass->update_func = folder_monitor_update;
+ klass->update = folder_monitor_update;
}
static GtkTreeViewColumn*
g_object_set (G_OBJECT (renderer_subject),
"ellipsize", PANGO_ELLIPSIZE_END, "yalign", 1.0,
NULL);
+ gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer_subject), 1);
g_object_set (G_OBJECT (renderer_recpt),
"ellipsize", PANGO_ELLIPSIZE_END, "yalign", 0.0,
NULL);
+ gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer_recpt), 1);
g_object_set(G_OBJECT(renderer_compact_date_or_status),
"xalign", 1.0, "yalign", 0.0,
NULL);
+ gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer_compact_date_or_status), 1);
g_object_set (G_OBJECT (renderer_priority),
"yalign", 1.0, NULL);
g_object_set (G_OBJECT (renderer_attach),
priv->status = HEADER_VIEW_INIT;
priv->status_timeout = 0;
+ priv->notify_status = TRUE;
priv->observer_list_lock = g_mutex_new();
priv->observer_list = NULL;
return FALSE;
}
-/*
- * This function sets a sortable model in the header view. It's just
- * used for developing purposes, because it only does a
- * gtk_tree_view_set_model
- */
-static void
-modest_header_view_set_model (GtkTreeView *header_view, GtkTreeModel *model)
-{
-/* GtkTreeModel *old_model_sort = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)); */
-/* if (old_model_sort && GTK_IS_TREE_MODEL_SORT (old_model_sort)) { */
-/* GtkTreeModel *old_model; */
-/* ModestHeaderViewPrivate *priv; */
-/* priv = MODEST_HEADER_VIEW_GET_PRIVATE (header_view); */
-/* old_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (old_model_sort)); */
-
-/* /\* Set new model *\/ */
-/* gtk_tree_view_set_model (header_view, model); */
-/* } else */
- gtk_tree_view_set_model (header_view, model);
-}
-
TnyFolder*
modest_header_view_get_folder (ModestHeaderView *self)
{
}
static void
-modest_header_view_set_folder_intern (ModestHeaderView *self, TnyFolder *folder)
+set_folder_intern_get_headers_async_cb (TnyFolder *folder,
+ gboolean cancelled,
+ TnyList *headers,
+ GError *err,
+ gpointer user_data)
{
- TnyFolderType type;
- TnyList *headers;
+ ModestHeaderView *self;
ModestHeaderViewPrivate *priv;
- GList *cols, *cursor;
- GtkTreeModel *filter_model, *sortable;
- guint sort_colid;
- GtkSortType sort_type;
- priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+ g_return_if_fail (MODEST_IS_HEADER_VIEW (user_data));
- headers = TNY_LIST (tny_gtk_header_list_model_new ());
-
- tny_gtk_header_list_model_set_folder (TNY_GTK_HEADER_LIST_MODEL(headers),
- folder, FALSE, NULL, NULL, NULL);
+ self = MODEST_HEADER_VIEW (user_data);
+ priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
/* Add IDLE observer (monitor) and another folder observer for
new messages (self) */
tny_folder_monitor_add_list (priv->monitor, TNY_LIST (headers));
tny_folder_monitor_start (priv->monitor);
g_mutex_unlock (priv->observers_lock);
+}
+
+static void
+modest_header_view_set_folder_intern (ModestHeaderView *self, TnyFolder *folder)
+{
+ TnyFolderType type;
+ TnyList *headers;
+ ModestHeaderViewPrivate *priv;
+ GList *cols, *cursor;
+ GtkTreeModel *filter_model, *sortable;
+ guint sort_colid;
+ GtkSortType sort_type;
+
+ priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+
+ headers = TNY_LIST (tny_gtk_header_list_model_new ());
+
+ /* Start the monitor in the callback of the
+ tny_gtk_header_list_model_set_folder call. It's crucial to
+ do it there and not just after the call because we want the
+ monitor to observe only the headers returned by the
+ tny_folder_get_headers_async call that it's inside the
+ tny_gtk_header_list_model_set_folder call. This way the
+ monitor infrastructure could successfully cope with
+ duplicates. For example if a tny_folder_add_msg_async is
+ happening while tny_gtk_header_list_model_set_folder is
+ invoked, then the first call could add a header that will
+ be added again by tny_gtk_header_list_model_set_folder, so
+ we'd end up with duplicate headers. sergio */
+ tny_gtk_header_list_model_set_folder (TNY_GTK_HEADER_LIST_MODEL(headers),
+ folder, FALSE,
+ set_folder_intern_get_headers_async_cb,
+ NULL, self);
sortable = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL(headers));
g_object_unref (G_OBJECT (headers));
}
/* Set new model */
- modest_header_view_set_model (GTK_TREE_VIEW (self), filter_model);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (self), filter_model);
modest_header_view_notify_observers(self, GTK_TREE_MODEL(filter_model),
tny_folder_get_id(folder));
g_object_unref (G_OBJECT (filter_model));
-/* modest_header_view_set_model (GTK_TREE_VIEW (self), sortable); */
-/* g_object_unref (G_OBJECT (sortable)); */
/* Free */
g_list_free (cols);
g_signal_emit (G_OBJECT (info->header_view),
signals[UPDATING_MSG_LIST_SIGNAL], 0, FALSE, NULL);
+ /* Allow filtering notifications from now on if the current
+ folder is still the same (if not then the user has selected
+ another one to refresh, we should wait until that refresh
+ finishes) */
+ if (priv->folder == folder)
+ priv->notify_status = TRUE;
+
/* Frees */
g_object_unref (info->header_view);
g_free (info);
}
+static void
+refresh_folder_error_handler (ModestMailOperation *mail_op,
+ gpointer user_data)
+{
+ const GError *error = modest_mail_operation_get_error (mail_op);
+
+ if (error->code == TNY_SYSTEM_ERROR_MEMORY ||
+ error->code == TNY_IO_ERROR_WRITE ||
+ error->code == TNY_IO_ERROR_READ) {
+ ModestMailOperationStatus st = modest_mail_operation_get_status (mail_op);
+ /* If the mail op has been cancelled then it's not an error: don't show any message */
+ if (st != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
+ modest_platform_information_banner (NULL, NULL,
+ dgettext("ke-recv",
+ "cerm_device_memory_full"));
+ }
+ }
+}
+
void
modest_header_view_set_folder (ModestHeaderView *self,
TnyFolder *folder,
}
if (priv->folder) {
- if (priv->status_timeout)
+ if (priv->status_timeout) {
g_source_remove (priv->status_timeout);
+ priv->status_timeout = 0;
+ }
g_mutex_lock (priv->observers_lock);
tny_folder_remove_observer (priv->folder, TNY_FOLDER_OBSERVER (self));
/* Pick my reference. Nothing to do with the mail operation */
priv->folder = g_object_ref (folder);
+ /* Do not notify about filterings until the refresh finishes */
+ priv->notify_status = FALSE;
+
/* Clear the selection if exists */
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self));
gtk_tree_selection_unselect_all(selection);
info->user_data = user_data;
/* Create the mail operation (source will be the parent widget) */
- mail_op = modest_mail_operation_new (G_OBJECT(main_win));
+ mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(main_win),
+ refresh_folder_error_handler,
+ NULL, NULL);
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
g_object_unref (G_OBJECT (priv->monitor));
priv->monitor = NULL;
}
- modest_header_view_set_model (GTK_TREE_VIEW (self), NULL);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (self), NULL);
modest_header_view_notify_observers(self, NULL, NULL);
{
GtkTreeSelection *selection = NULL;
GtkTreePath *path = NULL;
- gboolean already_selected = FALSE;
+ gboolean already_selected = FALSE, already_opened = FALSE;
+ ModestTnySendQueueStatus status = MODEST_TNY_SEND_QUEUE_UNKNOWN;
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(self), event->x, event->y, &path, NULL, NULL, NULL)) {
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self));
already_selected = gtk_tree_selection_path_is_selected (selection, path);
+
+ /* Get header from model */
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ if (gtk_tree_model_get_iter (model, &iter, path)) {
+ GValue value = {0,};
+ TnyHeader *header;
+
+ gtk_tree_model_get_value (model, &iter,
+ TNY_GTK_HEADER_LIST_MODEL_INSTANCE_COLUMN,
+ &value);
+ header = (TnyHeader *) g_value_get_object (&value);
+ if (TNY_IS_HEADER (header)) {
+ status = modest_tny_all_send_queues_get_msg_status (header);
+ already_opened = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
+ header, NULL);
+ }
+ g_value_unset (&value);
+ }
}
- /* Enable drag and drop onlly if the user clicks on a row that
+ /* Enable drag and drop only if the user clicks on a row that
it's already selected. If not, let him select items using
- the pointer */
- if (!already_selected) {
+ the pointer. If the message is in an OUTBOX and in sending
+ status disable drag and drop as well */
+ if (!already_selected ||
+ status == MODEST_TNY_SEND_QUEUE_SENDING ||
+ already_opened)
disable_drag_and_drop(self);
- }
- if (path != NULL) {
+ if (path != NULL)
gtk_tree_path_free(path);
- }
+ /* If it's already opened then do not let the button-press
+ event go on because it'll perform a message open because
+ we're clicking on to an already selected header */
return FALSE;
}
notify_filter_change_destroy (gpointer data)
{
NotifyFilterInfo *info = (NotifyFilterInfo *) data;
+ ModestHeaderViewPrivate *priv;
+
+ priv = MODEST_HEADER_VIEW_GET_PRIVATE (info->self);
+ priv->status_timeout = 0;
g_object_unref (info->self);
g_object_unref (info->folder);
/* Check hiding */
if (priv->hidding_ids != NULL) {
- id = g_strdup(tny_header_get_message_id (header));
+ id = tny_header_dup_message_id (header);
for (i=0; i < priv->n_selected && !found; i++)
if (priv->hidding_ids[i] != NULL && id != NULL)
found = (!strcmp (priv->hidding_ids[i], id));
frees:
old_status = priv->status;
priv->status = ((gboolean) priv->status) && !visible;
- if (priv->status != old_status) {
+ if ((priv->notify_status) && (priv->status != old_status)) {
NotifyFilterInfo *info;
if (priv->status_timeout)
my_account = tny_folder_get_account (priv->folder);
if (my_account == account)
modest_header_view_clear (MODEST_HEADER_VIEW (user_data));
- g_object_unref (account);
+ g_object_unref (my_account);
}
}