static void on_selection_changed (GtkTreeSelection *sel, gpointer data);
-static void on_account_update (TnyAccountStore *account_store,
- const gchar *account,
- gpointer user_data);
-
static void on_account_removed (TnyAccountStore *self,
TnyAccount *account,
gpointer user_data);
-static void on_accounts_reloaded (TnyAccountStore *store,
+static void on_account_inserted (TnyAccountStore *self,
+ TnyAccount *account,
gpointer user_data);
static gint cmp_rows (GtkTreeModel *tree_model,
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,
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 conf_key_signal;
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), \
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 */
}
g_object_unref (G_OBJECT (instance));
- g_free (fname);
/* Set pixbuf */
g_object_set (rendobj, "pixbuf", pixbuf, NULL);
* 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
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;
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_object_unref (G_OBJECT(priv->account_store));
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_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);
+/* g_signal_connect (G_OBJECT(account_store), "connecting_finished", */
+/* G_CALLBACK (on_accounts_reloaded), self); */
- on_accounts_reloaded (account_store, (gpointer ) 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_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 &&
/* 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
/* 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: */
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);
}
}
-void
+void
modest_folder_view_set_style (ModestFolderView *self,
ModestFolderViewStyle style)
{