#include <modest-account-mgr.h>
#include <modest-account-mgr-helpers.h>
#include <modest-text-utils.h>
+#include <modest-runtime.h>
#include <gtk/gtkcellrenderertoggle.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtktreeselection.h>
#include <gtk/gtkliststore.h>
+#include <string.h> /* For strcmp(). */
/* 'private'/'protected' functions */
static void modest_account_view_class_init (ModestAccountViewClass *klass);
ModestAccountMgr *account_mgr;
gulong sig1, sig2;
+ /* When this is TRUE, we ignore configuration key changes.
+ * This is useful when making many changes. */
+ gboolean block_conf_updates;
+
};
#define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MODEST_TYPE_ACCOUNT_VIEW, \
priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
priv->account_mgr = NULL;
+ priv->sig1 = 0;
+ priv->sig2 = 0;
}
static void
priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
if (priv->account_mgr) {
+ if (priv->sig1)
+ g_signal_handler_disconnect (priv->account_mgr, priv->sig1);
+
+ if (priv->sig2)
+ g_signal_handler_disconnect (priv->account_mgr, priv->sig2);
+
g_object_unref (G_OBJECT(priv->account_mgr));
priv->account_mgr = NULL;
}
model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(view)));
gtk_list_store_clear (model);
- cursor = account_names = modest_account_mgr_account_names (account_mgr);
+ /* Note: We do not show disabled accounts.
+ * Of course, this means that there is no UI to enable or disable
+ * accounts. That is OK for maemo where no such feature or UI is
+ * specified, so the "enabled" property is used internally to avoid
+ * showing unfinished accounts. If a user-visible "enabled" is
+ * needed in the future, we must use a second property for the
+ * current use instead */
+ cursor = account_names = modest_account_mgr_account_names (account_mgr,
+ TRUE /* only enabled accounts. */);
+
+ if(account_names == NULL)
+ {
+ printf ("debug: modest_account_mgr_account_names() returned NULL\n");
+ }
while (cursor) {
gchar *account_name;
if (last_updated > 0)
last_updated_string = modest_text_utils_get_display_date(last_updated);
else
- last_updated_string = g_strdup (_("Never"));
+ last_updated_string = g_strdup (_("FIXME: Never"));
- gtk_list_store_insert_with_values (
- model, &iter, 0,
- MODEST_ACCOUNT_VIEW_NAME_COLUMN, account_name,
- MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, account_data->display_name,
- MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, account_data->is_enabled,
- MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, account_data->is_default,
-
- MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
- modest_protocol_info_get_protocol_name (account_data->store_account->proto),
-
- MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
- -1);
- g_free (last_updated_string);
+ if (account_data->is_enabled) {
+ gtk_list_store_insert_with_values (
+ model, &iter, 0,
+ MODEST_ACCOUNT_VIEW_NAME_COLUMN, account_name,
+ MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, account_data->display_name,
+ MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, account_data->is_enabled,
+ MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, account_data->is_default,
+
+ MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
+ modest_protocol_info_get_transport_store_protocol_name (account_data->store_account->proto),
+
+ MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
+ -1);
+ g_free (last_updated_string);
+ }
}
modest_account_mgr_free_account_data (account_mgr, account_data);
const gchar* account, const gchar* key,
gboolean server_account, ModestAccountView *self)
{
- update_account_view (account_mgr, self);
+ /* Never update the view in response to gconf changes.
+ * Always do it explicitly instead.
+ * This is because we have no way to avoid 10 updates when changing
+ * 10 items, and this blocks the UI.
+ *
+ * But this block/unblock API might be useful on platforms where the
+ * notification does not happen so long after the key was set.
+ * (We have no way to know when the last key was set, to do a final update)..
+ */
+ return;
+
+ ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+ if (!priv->block_conf_updates)
+ update_account_view (account_mgr, self);
}
const gchar* account, gboolean server_account,
ModestAccountView *self)
{
- on_account_changed (account_mgr, account, NULL, server_account, self);
+ ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+ if (!priv->block_conf_updates)
+ on_account_changed (account_mgr, account, NULL, server_account, self);
}
-
-
+/* currently unused */
+#if 0
static void
on_account_enable_toggled (GtkCellRendererToggle *cell_renderer, gchar *path,
ModestAccountView *self)
modest_account_mgr_set_enabled (priv->account_mgr, account_name, !enabled);
g_free (account_name);
}
+#endif
+static void
+on_account_default_toggled (GtkCellRendererToggle *cell_renderer, gchar *path,
+ ModestAccountView *self)
+{
+ gboolean is_default = gtk_cell_renderer_toggle_get_active (cell_renderer);
+ if (is_default) {
+ /* Do not allow an account to be marked non-default.
+ * Only allow this to be changed by setting another account to default: */
+ gtk_cell_renderer_toggle_set_active (cell_renderer, TRUE);
+ return;
+ }
+
+ ModestAccountViewPrivate *priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(self));
+
+ GtkTreeIter iter;
+ if (!gtk_tree_model_get_iter_from_string (model, &iter, path)) {
+ g_printerr ("modest: cannot find iterator\n");
+ return;
+ }
+
+ gchar *account_name = NULL;
+ gtk_tree_model_get (model, &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, &account_name,
+ -1);
+
+ /* Set this previously-non-default account as the default: */
+ modest_account_mgr_set_default_account (priv->account_mgr, account_name);
+
+ g_free (account_name);
+}
void
bold_if_default_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
NULL);
}
-
static void
init_view (ModestAccountView *self)
{
G_TYPE_STRING, /* account proto (pop, imap,...) */
G_TYPE_STRING /* last updated (time_t) */
);
+
+ gtk_tree_sortable_set_sort_column_id (
+ GTK_TREE_SORTABLE (model), MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN,
+ GTK_SORT_ASCENDING);
gtk_tree_view_set_model (GTK_TREE_VIEW(self), GTK_TREE_MODEL(model));
+ g_object_unref (G_OBJECT (model));
toggle_renderer = gtk_cell_renderer_toggle_new ();
text_renderer = gtk_cell_renderer_text_new ();
- /* the is_enabled column */
- g_object_set (G_OBJECT(toggle_renderer), "activatable", TRUE,"radio", FALSE, NULL);
- g_signal_connect (G_OBJECT(toggle_renderer), "toggled", G_CALLBACK(on_account_enable_toggled),
- self);
+ /* the is_default column */
+ g_object_set (G_OBJECT(toggle_renderer), "activatable", TRUE, "radio", TRUE, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(self),
gtk_tree_view_column_new_with_attributes (
- _("Enabled"), toggle_renderer,
- "active", MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, NULL));
+ _("mcen_ti_default"), toggle_renderer,
+ "active", MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, NULL));
+
+ /* Disable the Maemo GtkTreeView::allow-checkbox-mode Maemo modification,
+ * which causes the model column to be updated automatically when the row is clicked.
+ * Making this the default in Maemo's GTK+ is obviously a bug:
+ * https://maemo.org/bugzilla/show_bug.cgi?id=146
+ *
+ * djcb: indeed, they have been removed for post-bora, i added the ifdefs...
+ */
+#ifdef MODEST_HILDON_VERSION_0
+ g_object_set(G_OBJECT(self), "allow-checkbox-mode", FALSE, NULL);
+ g_object_set(G_OBJECT(toggle_renderer), "checkbox-mode", FALSE, NULL);
+#endif /*MODEST_HILDON_VERSION_0 */
+ g_signal_connect (G_OBJECT(toggle_renderer), "toggled", G_CALLBACK(on_account_default_toggled),
+ self);
/* account name */
- column = gtk_tree_view_column_new_with_attributes (_("Account"), text_renderer,"text",
+ column = gtk_tree_view_column_new_with_attributes (_("mcen_ti_account"), text_renderer, "text",
MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW(self),column);
- gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
- NULL, NULL);
-
- /* account type */
- column = gtk_tree_view_column_new_with_attributes (_("Type"), text_renderer,"text",
- MODEST_ACCOUNT_VIEW_PROTO_COLUMN, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW(self),column);
+ gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);
gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
NULL, NULL);
/* last update for this account */
- column = gtk_tree_view_column_new_with_attributes (_("Last update"), text_renderer,"text",
+ column = gtk_tree_view_column_new_with_attributes (_("mcen_ti_lastupdated"), text_renderer,"text",
MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(self),column);
gtk_tree_view_column_set_cell_data_func(column, text_renderer, bold_if_default_cell_data,
NULL, NULL);
+
+ /* Show the column headers,
+ * which does not seem to be the default on Maemo.
+ */
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE);
- g_signal_connect (G_OBJECT(priv->account_mgr),"account_removed",
+ priv->sig1 = g_signal_connect (G_OBJECT(priv->account_mgr),"account_removed",
G_CALLBACK(on_account_removed), self);
- g_signal_connect (G_OBJECT(priv->account_mgr), "account_changed",
+ priv->sig2 = g_signal_connect (G_OBJECT(priv->account_mgr), "account_changed",
G_CALLBACK(on_account_changed), self);
}
obj = g_object_new(MODEST_TYPE_ACCOUNT_VIEW, NULL);
priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
- g_object_ref (G_OBJECT(account_mgr));
+ g_object_ref (G_OBJECT (account_mgr));
priv->account_mgr = account_mgr;
init_view (MODEST_ACCOUNT_VIEW (obj));
- update_account_view (account_mgr, MODEST_ACCOUNT_VIEW(obj));
+ update_account_view (account_mgr, MODEST_ACCOUNT_VIEW (obj));
- return MODEST_ACCOUNT_VIEW(obj);
+ return MODEST_ACCOUNT_VIEW (obj);
}
-const gchar *
+gchar *
modest_account_view_get_selected_account (ModestAccountView *self)
{
- const gchar *account_name = NULL;
+ gchar *account_name = NULL;
GtkTreeSelection *sel;
GtkTreeModel *model;
GtkTreeIter iter;
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
- gtk_tree_model_get (model, &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, &account_name,
- -1);
+ gtk_tree_model_get (model, &iter,
+ MODEST_ACCOUNT_VIEW_NAME_COLUMN,
+ &account_name, -1);
}
return account_name;
}
+
+/* This allows us to pass more than one piece of data to the signal handler,
+ * and get a result: */
+typedef struct
+{
+ ModestAccountView* self;
+ const gchar *account_name;
+} ForEachData;
+
+static gboolean
+on_model_foreach_select_account(GtkTreeModel *model,
+ GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
+{
+ ForEachData *state = (ForEachData*)(user_data);
+
+ /* Select the item if it has the matching account name: */
+ gchar *this_account_name = NULL;
+ gtk_tree_model_get (model, iter,
+ MODEST_ACCOUNT_VIEW_NAME_COLUMN, &this_account_name,
+ -1);
+ if(this_account_name && state->account_name
+ && (strcmp (this_account_name, state->account_name) == 0)) {
+
+ GtkTreeSelection *selection =
+ gtk_tree_view_get_selection (GTK_TREE_VIEW (state->self));
+ gtk_tree_selection_select_iter (selection, iter);
+
+ return TRUE; /* Stop walking the tree. */
+ }
+
+ return FALSE; /* Keep walking the tree. */
+}
+
+void modest_account_view_select_account (ModestAccountView *account_view,
+ const gchar* account_name)
+{
+ /* Create a state instance so we can send two items of data to the signal handler: */
+ ForEachData *state = g_new0 (ForEachData, 1);
+ state->self = account_view;
+ state->account_name = account_name;
+
+ GtkTreeModel *model = gtk_tree_view_get_model (
+ GTK_TREE_VIEW (account_view));
+ gtk_tree_model_foreach (model,
+ on_model_foreach_select_account, state);
+
+ g_free (state);
+}
+
+
+
+void modest_account_view_block_conf_updates (ModestAccountView *account_view)
+{
+ ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(account_view);
+ priv->block_conf_updates = TRUE;
+}
+
+void modest_account_view_unblock_conf_updates (ModestAccountView *account_view)
+{
+ ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(account_view);
+ priv->block_conf_updates = FALSE;
+
+ update_account_view (modest_runtime_get_account_mgr(), account_view);
+}