X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fwidgets%2Fmodest-account-view.c;h=f78c5da3c7d6ab0fec838d8d4d6fb6aa11bf85c7;hb=cb2af4c518371ac1af7c0fdd48cd2e979ae54753;hp=74e86f47fb88051d40373ea6fd06b710c1cce4b4;hpb=c7f65a5481ff942748c65fe8abacb53767fc83ec;p=modest diff --git a/src/widgets/modest-account-view.c b/src/widgets/modest-account-view.c index 74e86f4..f78c5da 100644 --- a/src/widgets/modest-account-view.c +++ b/src/widgets/modest-account-view.c @@ -46,6 +46,7 @@ #include #ifdef MODEST_TOOLKIT_HILDON2 #include +#include #endif #ifdef MODEST_USE_LIBTIME #include @@ -74,7 +75,7 @@ static void on_account_updated (ModestAccountMgr* mgr, gchar* account_name, gpointer user_data); static void update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view); static void on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata); -static void update_picker_mode (ModestAccountView *self); +static void update_display_mode (ModestAccountView *self); typedef enum { MODEST_ACCOUNT_VIEW_NAME_COLUMN, @@ -93,6 +94,10 @@ struct _ModestAccountViewPrivate { ModestDatetimeFormatter *datetime_formatter; gboolean picker_mode; + gboolean show_last_updated; + + GtkTreeModel *model; + GtkTreeModel *filter; /* Signal handlers */ GSList *sig_handlers; @@ -160,6 +165,7 @@ modest_account_view_init (ModestAccountView *obj) priv->datetime_formatter = modest_datetime_formatter_new (); priv->picker_mode = FALSE; + priv->show_last_updated = TRUE; g_signal_connect (G_OBJECT (priv->datetime_formatter), "format-changed", G_CALLBACK (datetime_format_changed), (gpointer) obj); #ifdef MODEST_TOOLKIT_HILDON2 @@ -212,16 +218,6 @@ get_last_updated_string(ModestAccountView *self, ModestAccountMgr* account_mgr, store_account_name = modest_server_account_settings_get_account_name (server_settings); last_updated = modest_account_mgr_get_last_updated (account_mgr, store_account_name); -#ifdef MODEST_USE_LIBTIME - /* If we use libtime, we are storing the time in UTC so we have to convert to currently - * selected time */ - time_t now; - struct tm *localtime_tm; - time (&now); - localtime_tm = localtime (&now); - if (last_updated) - last_updated -= localtime_tm->tm_gmtoff; -#endif g_object_unref (server_settings); account_name = modest_account_settings_get_account_name (settings); if (!modest_account_mgr_account_is_busy(account_mgr, account_name)) { @@ -243,9 +239,9 @@ static void update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) { GSList *account_names, *cursor; - GtkListStore *model; - - model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(view))); + ModestAccountViewPrivate *priv; + + priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(view); /* Get the ID of the currently-selected account, * so we can select it again after rebuilding the list. @@ -253,7 +249,7 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) */ gchar *selected_name = modest_account_view_get_selected_account (view); - gtk_list_store_clear (model); + gtk_list_store_clear (GTK_LIST_STORE (priv->model)); /* Note: We do not show disabled accounts. * Of course, this means that there is no UI to enable or disable @@ -296,16 +292,20 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) #ifdef MODEST_TOOLKIT_HILDON2 gchar *last_updated_hildon2; - last_updated_hildon2 = g_strconcat (_("mcen_ti_lastupdated"), "\n", - last_updated_string, - NULL); + if (priv->show_last_updated) { + last_updated_hildon2 = g_strconcat (_("mcen_ti_lastupdated"), "\n", + last_updated_string, + NULL); + } else { + last_updated_hildon2 = g_strconcat (_("mcen_ti_lastupdated"), "\n", NULL); + } #endif protocol_registry = modest_runtime_get_protocol_registry (); protocol_type = modest_server_account_settings_get_protocol (store_settings); protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type); proto_name = modest_protocol_get_name (protocol); gtk_list_store_insert_with_values ( - model, &iter, 0, + GTK_LIST_STORE (priv->model), &iter, 0, MODEST_ACCOUNT_VIEW_NAME_COLUMN, account_name, MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, modest_account_settings_get_display_name (settings), @@ -351,16 +351,18 @@ on_account_busy_changed(ModestAccountMgr *account_mgr, gboolean busy, ModestAccountView *self) { - GtkListStore *model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(self))); GtkTreeIter iter; gboolean found = FALSE; + ModestAccountViewPrivate *priv; + + priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self); - if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->model), &iter)) return; do { gchar* cur_name; - gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, + gtk_tree_model_get(GTK_TREE_MODEL(priv->model), &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, &cur_name, -1); @@ -379,7 +381,7 @@ on_account_busy_changed(ModestAccountMgr *account_mgr, last_updated_string, NULL); #endif - gtk_list_store_set(model, &iter, + gtk_list_store_set(GTK_LIST_STORE (priv->model), &iter, #ifdef MODEST_TOOLKIT_HILDON2 MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_hildon2, #else @@ -395,7 +397,7 @@ on_account_busy_changed(ModestAccountMgr *account_mgr, } g_free (cur_name); - } while (!found && gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter)); + } while (!found && gtk_tree_model_iter_next(priv->model, &iter)); } static void @@ -454,7 +456,6 @@ on_account_default_toggled (GtkCellRendererToggle *cell_renderer, ModestAccountView *self) { ModestAccountViewPrivate *priv; - GtkTreeModel *model; GtkTreeIter iter; gchar *account_name = NULL; @@ -466,14 +467,13 @@ on_account_default_toggled (GtkCellRendererToggle *cell_renderer, return; priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self); - model = gtk_tree_view_get_model (GTK_TREE_VIEW(self)); - if (!gtk_tree_model_get_iter_from_string (model, &iter, path)) { + if (!gtk_tree_model_get_iter_from_string (priv->filter, &iter, path)) { g_warning ("Got path of a not existing iter"); return; } - gtk_tree_model_get (model, &iter, + gtk_tree_model_get (priv->filter, &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, &account_name, -1); @@ -579,27 +579,29 @@ init_view (ModestAccountView *self) { ModestAccountViewPrivate *priv; GtkCellRenderer *toggle_renderer, *text_renderer; - GtkListStore *model; GtkTreeViewColumn *column; g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self)); priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self); - model = gtk_list_store_new (6, - G_TYPE_STRING, /* account name */ - G_TYPE_STRING, /* account display name */ - G_TYPE_BOOLEAN, /* is-enabled */ - G_TYPE_BOOLEAN, /* is-default */ - G_TYPE_STRING, /* account proto (pop, imap,...) */ - G_TYPE_STRING /* last updated (time_t) */ - ); + priv->model = GTK_TREE_MODEL (gtk_list_store_new (6, + G_TYPE_STRING, /* account name */ + G_TYPE_STRING, /* account display name */ + G_TYPE_BOOLEAN, /* is-enabled */ + G_TYPE_BOOLEAN, /* is-default */ + 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_TREE_SORTABLE (priv->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)); + priv->filter = gtk_tree_model_filter_new (priv->model, NULL); + + gtk_tree_view_set_model (GTK_TREE_VIEW(self), GTK_TREE_MODEL(priv->filter)); + g_object_unref (G_OBJECT (priv->model)); + g_object_unref (G_OBJECT (priv->filter)); toggle_renderer = gtk_cell_renderer_toggle_new (); /* the is_default column */ @@ -620,10 +622,6 @@ init_view (ModestAccountView *self) * * djcb: indeed, they have been removed for post-bora, i added the ifdefs... */ -#ifdef MODEST_HAVE_HILDON0_WIDGETS - g_object_set(G_OBJECT(self), "allow-checkbox-mode", FALSE, NULL); - g_object_set(G_OBJECT(toggle_renderer), "checkbox-mode", FALSE, NULL); -#endif /* MODEST_HAVE_HILDON0_WIDGETS */ priv->sig_handlers = modest_signal_mgr_connect (priv->sig_handlers, @@ -672,7 +670,7 @@ init_view (ModestAccountView *self) gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE); #endif - update_picker_mode (self); + update_display_mode (self); priv->sig_handlers = modest_signal_mgr_connect (priv->sig_handlers, @@ -900,7 +898,7 @@ on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata) } static void -update_picker_mode (ModestAccountView *self) +update_display_mode (ModestAccountView *self) { ModestAccountViewPrivate *priv; GtkTreeViewColumn *column; @@ -934,7 +932,7 @@ modest_account_view_set_picker_mode (ModestAccountView *self, gboolean enable) priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self); priv->picker_mode = enable; - update_picker_mode (self); + update_display_mode (self); } gboolean @@ -947,3 +945,82 @@ modest_account_view_get_picker_mode (ModestAccountView *self) return priv->picker_mode; } + +void +modest_account_view_set_show_last_update (ModestAccountView *self, + gboolean show) +{ + ModestAccountViewPrivate *priv; + + g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self)); + priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self); + + priv->show_last_updated = show; + update_account_view (priv->account_mgr, self); +} + +gboolean +modest_account_view_get_show_last_updated (ModestAccountView *self) +{ + ModestAccountViewPrivate *priv; + + g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), FALSE); + priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self); + + return priv->show_last_updated; +} + +GtkTreeModel * +modest_account_view_get_model (ModestAccountView *self) +{ + ModestAccountViewPrivate *priv; + + priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self); + + return priv->model; +} + +GtkTreeModel * +modest_account_view_get_filter (ModestAccountView *self) +{ + ModestAccountViewPrivate *priv; + + priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self); + + return priv->filter; +} + +#ifdef MODEST_TOOLKIT_HILDON2 +static gboolean +live_search_visible_func (GtkTreeModel *model, + GtkTreeIter *iter, + gchar *text, + gpointer data) +{ + gchar *display_name; + gboolean result; + gtk_tree_model_get(model, iter, + MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN, + &display_name, -1); + + result = modest_text_utils_live_search_find (display_name, text); + + g_free (display_name); + + return result; +} + +GtkWidget * +modest_account_view_setup_live_search (ModestAccountView *self) +{ + GtkWidget *live_search; + live_search = hildon_live_search_new (); + hildon_live_search_set_filter (HILDON_LIVE_SEARCH (live_search), + GTK_TREE_MODEL_FILTER (modest_account_view_get_filter (MODEST_ACCOUNT_VIEW (self)))); + hildon_live_search_set_visible_func (HILDON_LIVE_SEARCH (live_search), live_search_visible_func, self, NULL); + hildon_live_search_set_text_column (HILDON_LIVE_SEARCH (live_search), + MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN); + + return live_search; +} +#endif