X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-folder-view.c;h=0353cd8b9a6ce8db15d9f1b165624041ca663949;hp=4a8306660b891e7a923edfbb617e585abbc80ada;hb=04fa8f60ad3ce55f41e650558c56f210e0d87143;hpb=d65b3f3000504c6601926e81363352e70dc0765a diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index 4a83066..0353cd8 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -69,15 +69,16 @@ static void modest_folder_view_set_account_store (TnyAccountStoreView *s static void on_selection_changed (GtkTreeSelection *sel, gpointer data); -static void on_account_update (TnyAccountStore *account_store, - const gchar *account, +static void on_account_removed (TnyAccountStore *self, + TnyAccount *account, gpointer user_data); -static void on_account_removed (TnyAccountStore *self, +static void on_account_inserted (TnyAccountStore *self, TnyAccount *account, gpointer user_data); -static void on_accounts_reloaded (TnyAccountStore *store, +static void on_account_changed (TnyAccountStore *self, + TnyAccount *account, gpointer user_data); static gint cmp_rows (GtkTreeModel *tree_model, @@ -93,10 +94,11 @@ static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data); -static void on_configuration_key_changed (ModestConf* conf, - const gchar *key, - ModestConfEvent event, - ModestFolderView *self); +static void on_configuration_key_changed (ModestConf* conf, + const gchar *key, + ModestConfEvent event, + ModestConfNotificationId notification_id, + ModestFolderView *self); /* DnD functions */ static void on_drag_data_get (GtkWidget *widget, @@ -149,10 +151,12 @@ struct _ModestFolderViewPrivate { TnyFolder *folder_to_select; /* folder to select after the next update */ - gulong account_update_signal; + ModestConfNotificationId notification_id; + gulong changed_signal; - gulong accounts_reloaded_signal; + gulong account_inserted_signal; gulong account_removed_signal; + gulong account_changed_signal; gulong conf_key_signal; /* not unref this object, its a singlenton */ @@ -169,8 +173,8 @@ struct _ModestFolderViewPrivate { gchar *visible_account_id; ModestFolderViewStyle style; - gboolean reselect; /* we use this to force a reselection of the INBOX */ - gboolean show_non_move; + gboolean reselect; /* we use this to force a reselection of the INBOX */ + gboolean show_non_move; }; #define MODEST_FOLDER_VIEW_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -258,7 +262,8 @@ modest_folder_view_class_init (ModestFolderViewClass *klass) } /* Simplify checks for NULLs: */ -static gboolean strings_are_equal (const gchar *a, const gchar *b) +static gboolean +strings_are_equal (const gchar *a, const gchar *b) { if (!a && !b) return TRUE; @@ -270,7 +275,8 @@ static gboolean strings_are_equal (const gchar *a, const gchar *b) return FALSE; } -static gboolean on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +static gboolean +on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { GObject *instance = NULL; @@ -314,7 +320,8 @@ typedef struct gchar *previous_name; } GetMmcAccountNameData; -static void on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data) +static void +on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data) { /* printf ("DEBU1G: %s: account name=%s\n", __FUNCTION__, tny_account_get_name (TNY_ACCOUNT(account))); */ @@ -469,28 +476,19 @@ icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GObject *rendobj = NULL, *instance = NULL; GdkPixbuf *pixbuf = NULL; TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN; - gchar *fname = NULL; const gchar *account_id = NULL; - gint unread = 0; gboolean has_children; rendobj = G_OBJECT(renderer); gtk_tree_model_get (tree_model, iter, TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type, - TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &fname, - TNY_GTK_FOLDER_STORE_TREE_MODEL_UNREAD_COLUMN, &unread, TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance, -1); has_children = gtk_tree_model_iter_has_child (tree_model, iter); - if (!fname) + if (!instance) return; - if (!instance) { - g_free (fname); - return; - } - /* MERGE is not needed anymore as the folder now has the correct type jschmid */ /* We include the MERGE type here because it's used to create the local OUTBOX folder */ @@ -542,7 +540,6 @@ icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, } g_object_unref (G_OBJECT (instance)); - g_free (fname); /* Set pixbuf */ g_object_set (rendobj, "pixbuf", pixbuf, NULL); @@ -662,10 +659,12 @@ modest_folder_view_init (ModestFolderView *obj) * Track changes in the local account name (in the device it * will be the device name) */ - priv->conf_key_signal = - g_signal_connect (G_OBJECT(conf), - "key_changed", - G_CALLBACK(on_configuration_key_changed), obj); + priv->notification_id = modest_conf_listen_to_namespace (conf, + MODEST_CONF_NAMESPACE); + priv->conf_key_signal = g_signal_connect (G_OBJECT(conf), + "key_changed", + G_CALLBACK(on_configuration_key_changed), + obj); } static void @@ -688,6 +687,12 @@ modest_folder_view_finalize (GObject *obj) priv = MODEST_FOLDER_VIEW_GET_PRIVATE(obj); + if (priv->notification_id) { + modest_conf_forget_namespace (modest_runtime_get_conf (), + MODEST_CONF_NAMESPACE, + priv->notification_id); + } + if (priv->timer_expander != 0) { g_source_remove (priv->timer_expander); priv->timer_expander = 0; @@ -695,11 +700,11 @@ modest_folder_view_finalize (GObject *obj) if (priv->account_store) { g_signal_handler_disconnect (G_OBJECT(priv->account_store), - priv->account_update_signal); - g_signal_handler_disconnect (G_OBJECT(priv->account_store), - priv->accounts_reloaded_signal); + priv->account_inserted_signal); g_signal_handler_disconnect (G_OBJECT(priv->account_store), priv->account_removed_signal); + g_signal_handler_disconnect (G_OBJECT(priv->account_store), + priv->account_changed_signal); g_object_unref (G_OBJECT(priv->account_store)); priv->account_store = NULL; } @@ -757,54 +762,109 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore if (G_UNLIKELY (priv->account_store)) { - if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), - priv->account_update_signal)) - g_signal_handler_disconnect (G_OBJECT (priv->account_store), - priv->account_update_signal); - if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), - priv->accounts_reloaded_signal)) - g_signal_handler_disconnect (G_OBJECT (priv->account_store), - priv->accounts_reloaded_signal); + if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), + priv->account_inserted_signal)) + g_signal_handler_disconnect (G_OBJECT (priv->account_store), + priv->account_inserted_signal); if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), priv->account_removed_signal)) g_signal_handler_disconnect (G_OBJECT (priv->account_store), priv->account_removed_signal); - + if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), + priv->account_changed_signal)) + g_signal_handler_disconnect (G_OBJECT (priv->account_store), + priv->account_changed_signal); g_object_unref (G_OBJECT (priv->account_store)); } priv->account_store = g_object_ref (G_OBJECT (account_store)); - priv->account_update_signal = - g_signal_connect (G_OBJECT(account_store), "account_update", - G_CALLBACK (on_account_update), self); - priv->account_removed_signal = g_signal_connect (G_OBJECT(account_store), "account_removed", G_CALLBACK (on_account_removed), self); - priv->accounts_reloaded_signal = - g_signal_connect (G_OBJECT(account_store), "accounts_reloaded", - G_CALLBACK (on_accounts_reloaded), self); + priv->account_inserted_signal = + g_signal_connect (G_OBJECT(account_store), "account_inserted", + G_CALLBACK (on_account_inserted), self); - g_signal_connect (G_OBJECT(account_store), "connecting_finished", - G_CALLBACK (on_accounts_reloaded), self); + priv->account_changed_signal = + g_signal_connect (G_OBJECT(account_store), "account_changed", + G_CALLBACK (on_account_changed), self); - on_accounts_reloaded (account_store, (gpointer ) self); + modest_folder_view_update_model (MODEST_FOLDER_VIEW (self), account_store); g_object_unref (G_OBJECT (device)); } static void +on_account_inserted (TnyAccountStore *account_store, + TnyAccount *account, + gpointer user_data) +{ + ModestFolderViewPrivate *priv; + GtkTreeModel *sort_model, *filter_model; + + /* Ignore transport account insertions, we're not showing them + in the folder view */ + if (TNY_IS_TRANSPORT_ACCOUNT (account)) + return; + + priv = MODEST_FOLDER_VIEW_GET_PRIVATE (user_data); + + /* If we're adding a new account, and there is no previous + one, we need to select the visible server account */ + if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE && + !priv->visible_account_id) + modest_widget_memory_restore (modest_runtime_get_conf(), + G_OBJECT (user_data), + MODEST_CONF_FOLDER_VIEW_KEY); + + /* Get the inner model */ + filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data)); + sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model)); + + /* Insert the account in the model */ + tny_list_append (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))), + G_OBJECT (account)); +} + + +static void +on_account_changed (TnyAccountStore *account_store, TnyAccount *tny_account, + gpointer user_data) +{ + g_warning ("%s: account_id = %s", __FUNCTION__, tny_account_get_id(tny_account)); +} + + + +static void on_account_removed (TnyAccountStore *account_store, TnyAccount *account, gpointer user_data) { - ModestFolderView *self = MODEST_FOLDER_VIEW (user_data); + ModestFolderView *self = NULL; ModestFolderViewPrivate *priv; + GtkTreeModel *sort_model, *filter_model; + /* Ignore transport account removals, we're not showing them + in the folder view */ + if (TNY_IS_TRANSPORT_ACCOUNT (account)) + return; + + g_print ("--------------------- FOLDER ---------------\n"); + + self = MODEST_FOLDER_VIEW (user_data); priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self); + /* TODO: invalidate the cur_folder_* and folder_to_select things */ + + /* Remove the account from the model */ + filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (self)); + sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model)); + tny_list_remove (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))), + G_OBJECT (account)); + /* If the removed account is the currently viewed one then clear the configuration value. The new visible account will be the default account */ if (priv->visible_account_id && @@ -816,42 +876,10 @@ on_account_removed (TnyAccountStore *account_store, /* Call the restore method, this will set the new visible account */ modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self), MODEST_CONF_FOLDER_VIEW_KEY); - - /* Select the INBOX */ - modest_folder_view_select_first_inbox_or_local (self); } -} - -static void -on_account_update (TnyAccountStore *account_store, - const gchar *account, - gpointer user_data) -{ - ModestFolderView *self = NULL; - ModestFolderViewPrivate *priv; - - g_return_if_fail (MODEST_IS_FOLDER_VIEW (user_data)); - self = MODEST_FOLDER_VIEW (user_data); - priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self); - /* If we're adding a new account, and there is no previous - one, we need to select the visible server account */ - if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE && - !priv->visible_account_id) - modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self), - MODEST_CONF_FOLDER_VIEW_KEY); - - if (!modest_folder_view_update_model (self, account_store)) - g_printerr ("modest: failed to update model for changes in '%s'", - account); -} - -static void -on_accounts_reloaded (TnyAccountStore *account_store, - gpointer user_data) -{ - g_return_if_fail (MODEST_IS_FOLDER_VIEW (user_data)); - modest_folder_view_update_model (MODEST_FOLDER_VIEW (user_data), account_store); + /* Select the INBOX */ + modest_folder_view_select_first_inbox_or_local (self); } void @@ -1071,7 +1099,7 @@ modest_folder_view_update_model (ModestFolderView *self, /* FIXME: the local accounts are not shown when the query selects only the subscribed folders. */ /* model = tny_gtk_folder_store_tree_model_new (TRUE, priv->query); */ - model = tny_gtk_folder_store_tree_model_new (TRUE, NULL); + model = tny_gtk_folder_store_tree_model_new (NULL); /* Deal with the model via its TnyList Interface, * filling the TnyList via a get_accounts() call: */ @@ -1436,6 +1464,22 @@ on_progress_changed (ModestMailOperation *mail_op, g_slice_free (DndHelper, helper); } + +/* get the folder for the row the treepath refers to. */ +/* folder must be unref'd */ +static TnyFolder* +tree_path_to_folder (GtkTreeModel *model, GtkTreePath *path) +{ + GtkTreeIter iter; + TnyFolder *folder = NULL; + + if (gtk_tree_model_get_iter (model,&iter, path)) + gtk_tree_model_get (model, &iter, + TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder, + -1); + return folder; +} + /* * This function is used by drag_data_received_cb to manage drag and * drop of a header, i.e, and drag from the header view to the folder @@ -1451,13 +1495,13 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model, TnyHeader *header = NULL; TnyFolder *folder = NULL; ModestMailOperation *mail_op = NULL; - GtkTreeIter source_iter, dest_iter; + GtkTreeIter source_iter; g_return_if_fail (GTK_IS_TREE_MODEL(source_model)); g_return_if_fail (GTK_IS_TREE_MODEL(dest_model)); g_return_if_fail (dest_row); g_return_if_fail (helper); - + /* Get header */ gtk_tree_model_get_iter (source_model, &source_iter, helper->source_row); gtk_tree_model_get (source_model, &source_iter, @@ -1469,15 +1513,16 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model, } /* Get Folder */ - gtk_tree_model_get_iter (dest_model, &dest_iter, dest_row); - gtk_tree_model_get (dest_model, &dest_iter, - TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, - &folder, -1); - + folder = tree_path_to_folder (dest_model, dest_row); if (!TNY_IS_FOLDER(folder)) { g_warning ("BUG: %s could not get a valid folder", __FUNCTION__); goto cleanup; } + if (modest_tny_folder_get_rules(folder) & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) { + g_debug ("folder rules: cannot write to that folder"); + goto cleanup; + } + /* Transfer message */ mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, @@ -1525,13 +1570,35 @@ drag_and_drop_from_folder_view (GtkTreeModel *source_model, GtkTreeIter parent_iter, iter; TnyFolderStore *parent_folder = NULL; TnyFolder *folder = NULL; + gboolean forbidden = TRUE; + + /* check the folder rules for the destination */ + folder = tree_path_to_folder (dest_model, dest_row); + if (folder) { + ModestTnyFolderRules rules = + modest_tny_folder_get_rules (folder); + forbidden = rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE; + if (forbidden) + g_debug ("folder rules: cannot write to that folder"); + g_object_unref (folder); + } + + if (!forbidden) { + /* check the folder rules for the source */ + folder = tree_path_to_folder (source_model, helper->source_row); + if (folder) { + ModestTnyFolderRules rules = + modest_tny_folder_get_rules (folder); + forbidden = rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE; + if (forbidden) + g_debug ("folder rules: cannot move that folder"); + g_object_unref (folder); + } + } + /* Check if the drag is possible */ -/* if (!gtk_tree_path_compare (helper->source_row, dest_row) || */ -/* !gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (dest_model), */ -/* dest_row, */ -/* selection_data)) { */ - if (!gtk_tree_path_compare (helper->source_row, dest_row)) { + if (forbidden || !gtk_tree_path_compare (helper->source_row, dest_row)) { gtk_drag_finish (helper->context, FALSE, FALSE, helper->time); gtk_tree_path_free (helper->source_row); @@ -1920,17 +1987,20 @@ on_key_pressed (GtkWidget *self, static void on_configuration_key_changed (ModestConf* conf, const gchar *key, - ModestConfEvent event, + ModestConfEvent event, + ModestConfNotificationId id, ModestFolderView *self) { ModestFolderViewPrivate *priv; - if (!key) - return; g_return_if_fail (MODEST_IS_FOLDER_VIEW (self)); priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self); + /* Do not listen for changes in other namespaces */ + if (priv->notification_id != id) + return; + if (!strcmp (key, MODEST_CONF_DEVICE_NAME)) { g_free (priv->local_account_name); @@ -1949,7 +2019,7 @@ on_configuration_key_changed (ModestConf* conf, } } -void +void modest_folder_view_set_style (ModestFolderView *self, ModestFolderViewStyle style) { @@ -2010,28 +2080,15 @@ find_inbox_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *inbox_iter do { GtkTreeIter child; TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN; - gchar *name = NULL; gtk_tree_model_get (model, iter, - TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name, TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type, -1); gboolean result = FALSE; if (type == TNY_FOLDER_TYPE_INBOX) { result = TRUE; - } else if (type == TNY_FOLDER_TYPE_NORMAL) { - /* tinymail's camel implementation only provides TNY_FOLDER_TYPE_NORMAL - * when getting folders from the cache, before connectin, so we do - * an extra check. We could fix this in tinymail, but it's easier - * to do here. - */ - if (strcmp (name, "Inbox") == 0) - result = TRUE; - } - - g_free (name); - + } if (result) { *inbox_iter = *iter; return TRUE; @@ -2056,10 +2113,7 @@ modest_folder_view_select_first_inbox_or_local (ModestFolderView *self) GtkTreeModel *model; GtkTreeIter iter, inbox_iter; GtkTreeSelection *sel; - -/* /\* Do not set it if the folder view was not painted *\/ */ -/* if (!GTK_WIDGET_MAPPED (self)) */ -/* return; */ + GtkTreePath *path = NULL; model = gtk_tree_view_get_model (GTK_TREE_VIEW (self)); if (!model) @@ -2069,15 +2123,15 @@ modest_folder_view_select_first_inbox_or_local (ModestFolderView *self) sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self)); gtk_tree_model_get_iter_first (model, &iter); - gtk_tree_selection_unselect_all (sel); - if (find_inbox_iter (model, &iter, &inbox_iter)) { - gtk_tree_selection_select_iter (sel, &inbox_iter); - } - else { - gtk_tree_model_get_iter_first (model, &iter); - gtk_tree_selection_select_iter (sel, &iter); - } + if (find_inbox_iter (model, &iter, &inbox_iter)) + path = gtk_tree_model_get_path (model, &inbox_iter); + else + path = gtk_tree_path_new_first (); + + /* Select the row and free */ + gtk_tree_view_set_cursor (GTK_TREE_VIEW (self), path, NULL, FALSE); + gtk_tree_path_free (path); }