Fixed the dimming rule for "add_to_contacts" in the case of ModestMsgEditWindow
[modest] / src / widgets / modest-account-view.c
index 52e771d..fd9f115 100644 (file)
@@ -47,6 +47,9 @@
 #ifdef MODEST_TOOLKIT_HILDON2
 #include <hildon/hildon-defines.h>
 #endif
+#ifdef MODEST_USE_LIBTIME
+#include <clockd/libtime.h>
+#endif
 
 /* 'private'/'protected' functions */
 static void modest_account_view_class_init    (ModestAccountViewClass *klass);
@@ -71,6 +74,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_display_mode (ModestAccountView *self);
 
 typedef enum {
        MODEST_ACCOUNT_VIEW_NAME_COLUMN,
@@ -88,6 +92,8 @@ struct _ModestAccountViewPrivate {
        ModestAccountMgr *account_mgr;
 
        ModestDatetimeFormatter *datetime_formatter;
+       gboolean picker_mode;
+       gboolean show_last_updated;
 
        /* Signal handlers */
        GSList *sig_handlers;
@@ -154,6 +160,8 @@ modest_account_view_init (ModestAccountView *obj)
        priv->sig_handlers = NULL;
 
        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
@@ -205,6 +213,7 @@ get_last_updated_string(ModestAccountView *self, ModestAccountMgr* account_mgr,
        server_settings = modest_account_settings_get_store_settings (settings);
        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);
+
        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)) {
@@ -218,7 +227,7 @@ get_last_updated_string(ModestAccountView *self, ModestAccountMgr* account_mgr,
        } else  {
                last_updated_string = _("mcen_va_refreshing");
        }
-       
+
        return last_updated_string;
 }
 
@@ -227,9 +236,11 @@ 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);
+       model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(view)));
+
        /* Get the ID of the currently-selected account,
         * so we can select it again after rebuilding the list.
         * Note that the name doesn't change even when the display name changes.
@@ -279,9 +290,13 @@ 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);
@@ -449,8 +464,12 @@ 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));  
-       gtk_tree_model_get_iter_from_string (model, &iter, path);
+       model = gtk_tree_view_get_model (GTK_TREE_VIEW(self));
+
+       if (!gtk_tree_model_get_iter_from_string (model, &iter, path)) {
+               g_warning ("Got path of a not existing iter");
+               return;
+       }
        
        gtk_tree_model_get (model, &iter, 
                            MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
@@ -599,10 +618,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,
@@ -651,6 +666,8 @@ init_view (ModestAccountView *self)
        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE);
 #endif
 
+       update_display_mode (self);
+
        priv->sig_handlers = 
                modest_signal_mgr_connect (priv->sig_handlers, 
                                           G_OBJECT (modest_runtime_get_account_store ()),
@@ -876,3 +893,75 @@ on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata)
        } 
 }
 
+static void
+update_display_mode (ModestAccountView *self)
+{
+       ModestAccountViewPrivate *priv;
+       GtkTreeViewColumn *column;
+       GList *renderers;
+       GtkCellRenderer *renderer;
+       
+       g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+       /* Last updated column */
+       column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 2);
+       gtk_tree_view_column_set_visible (column, !priv->picker_mode);
+
+       /* Name column */
+       column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 1);
+       renderers = gtk_tree_view_column_get_cell_renderers (column);
+       renderer = (GtkCellRenderer *) renderers->data;
+       g_object_set (renderer, 
+                     "align-set", TRUE,
+                     "alignment", priv->picker_mode?PANGO_ALIGN_CENTER:PANGO_ALIGN_LEFT,
+                     NULL);
+       g_list_free (renderers);
+}
+
+void 
+modest_account_view_set_picker_mode (ModestAccountView *self, gboolean enable)
+{
+       ModestAccountViewPrivate *priv;
+       
+       g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+       priv->picker_mode = enable;
+       update_display_mode (self);
+}
+
+gboolean 
+modest_account_view_get_picker_mode (ModestAccountView *self)
+{
+       ModestAccountViewPrivate *priv;
+       
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), FALSE);
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(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;
+}