Set proper logical id for "Invitation" string to mail_fi_invitation.
[modest] / src / widgets / modest-account-view.c
index 88e5739..cf07ff6 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include <glib/gi18n.h>
+#include <gtk/gtk.h>
 #include "modest-account-view.h"
 
 #include <modest-account-mgr.h>
 #include <modest-runtime.h>
 #include <modest-signal-mgr.h>
 
-#include <gtk/gtkcellrenderertoggle.h>
-#include <gtk/gtkcellrenderertext.h>
-#include <gtk/gtktreeselection.h>
-#include <gtk/gtkliststore.h>
 #include <string.h> /* For strcmp(). */
 #include <modest-account-mgr-helpers.h>
 #include <modest-datetime-formatter.h>
+#include <modest-ui-constants.h>
 #ifdef MODEST_TOOLKIT_HILDON2
 #include <hildon/hildon-defines.h>
 #endif
@@ -66,15 +64,11 @@ static void on_display_name_changed            (ModestAccountMgr *self,
                                                const gchar *account,
                                                gpointer user_data);
 
-#ifndef MODEST_TOOLKIT_HILDON2
-static void modest_account_view_select_first_account (ModestAccountView *account_view);
-#endif
-
 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 +87,7 @@ struct _ModestAccountViewPrivate {
 
        ModestDatetimeFormatter *datetime_formatter;
        gboolean picker_mode;
+       gboolean show_last_updated;
 
        /* Signal handlers */
        GSList *sig_handlers;
@@ -160,6 +155,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,15 +208,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);
-       last_updated -= time_get_utc_offset (localtime_tm->tm_zone);
-#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)) {
@@ -234,7 +221,7 @@ get_last_updated_string(ModestAccountView *self, ModestAccountMgr* account_mgr,
        } else  {
                last_updated_string = _("mcen_va_refreshing");
        }
-       
+
        return last_updated_string;
 }
 
@@ -243,9 +230,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.
@@ -292,13 +281,15 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
                                ModestProtocolRegistry *protocol_registry;
                                ModestProtocol *protocol;
                                const gchar *proto_name;
-#ifdef MODEST_TOOLKIT_HILDON2
                                gchar *last_updated_hildon2;
 
-                               last_updated_hildon2 = g_strconcat (_("mcen_ti_lastupdated"), "\n", 
-                                                                  last_updated_string,
-                                                                  NULL);
-#endif
+                               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);
+                               }
                                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);
@@ -313,15 +304,9 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
                                        MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, 
                                        modest_account_settings_get_is_default (settings),
                                        MODEST_ACCOUNT_VIEW_PROTO_COLUMN, proto_name,
-#ifdef MODEST_TOOLKIT_HILDON2
                                        MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN,  last_updated_hildon2,
-#else
-                                       MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN,  last_updated_string,
-#endif
                                        -1);
-#ifdef MODEST_TOOLKIT_HILDON2
                                g_free (last_updated_hildon2);
-#endif
                        }
                }
                
@@ -337,10 +322,6 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
        if (selected_name) {
                modest_account_view_select_account (view, selected_name);
                g_free (selected_name);
-       } else {
-#ifndef MODEST_TOOLKIT_HILDON2
-               modest_account_view_select_first_account (view);
-#endif
        }
 }
 
@@ -371,24 +352,16 @@ on_account_busy_changed(ModestAccountMgr *account_mgr,
                                return;
                        }
                        const gchar* last_updated_string = get_last_updated_string(self, account_mgr, settings);
-#ifdef MODEST_TOOLKIT_HILDON2
                        gchar *last_updated_hildon2;
 
                        last_updated_hildon2 = g_strconcat (_("mcen_ti_lastupdated"), "\n", 
                                                            last_updated_string,
                                                            NULL);
-#endif
                        gtk_list_store_set(model, &iter, 
-#ifdef MODEST_TOOLKIT_HILDON2
                                           MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_hildon2,
-#else
-                                          MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN, last_updated_string,
-#endif
                                           -1);
 
-#ifdef MODEST_TOOLKIT_HILDON2
                        g_free (last_updated_hildon2);
-#endif
                        g_object_unref (settings);
                        found = TRUE;
                }
@@ -435,10 +408,6 @@ on_account_removed (TnyAccountStore *account_store,
        
        selected_name = modest_account_view_get_selected_account (self);
        if (selected_name == NULL) {
-#ifndef MODEST_TOOLKIT_HILDON2
-               /* we select the first account if none is selected */
-               modest_account_view_select_first_account (self);
-#endif
        } else {
                g_free (selected_name);
        }
@@ -608,9 +577,7 @@ init_view (ModestAccountView *self)
                 "active", MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, NULL);
        gtk_tree_view_append_column (GTK_TREE_VIEW(self),
                                     column);
-#ifdef MODEST_TOOLKIT_HILDON2
        gtk_tree_view_column_set_visible (column, FALSE);
-#endif
                                        
        /* Disable the Maemo GtkTreeView::allow-checkbox-mode Maemo modification, 
         * which causes the model column to be updated automatically when the row is clicked.
@@ -619,10 +586,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,
@@ -635,9 +598,7 @@ init_view (ModestAccountView *self)
        text_renderer = gtk_cell_renderer_text_new ();
        g_object_set (G_OBJECT (text_renderer), 
                      "ellipsize", PANGO_ELLIPSIZE_END, "ellipsize-set", TRUE, 
-#ifdef MODEST_TOOLKIT_HILDON2
-                     "xpad", HILDON_MARGIN_DOUBLE,
-#endif
+                     "xpad", MODEST_MARGIN_DOUBLE,
                      NULL);
 
        column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_account"), text_renderer, "text",
@@ -652,9 +613,7 @@ init_view (ModestAccountView *self)
        g_object_set (G_OBJECT (text_renderer), 
                      "alignment", PANGO_ALIGN_RIGHT, 
                      "xalign", 1.0,
-#ifdef MODEST_TOOLKIT_HILDON2
-                     "xpad", HILDON_MARGIN_DOUBLE,
-#endif
+                     "xpad", MODEST_MARGIN_DOUBLE,
                      NULL);
 
        column =  gtk_tree_view_column_new_with_attributes (_("mcen_ti_lastupdated"), text_renderer,"markup",
@@ -667,11 +626,8 @@ init_view (ModestAccountView *self)
        /* Show the column headers,
         * which does not seem to be the default on Maemo.
         */
-#ifndef MODEST_TOOLKIT_HILDON2
-       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, 
@@ -733,6 +689,10 @@ modest_account_view_new (ModestAccountMgr *account_mgr)
        init_view (MODEST_ACCOUNT_VIEW (obj));
        update_account_view (account_mgr, MODEST_ACCOUNT_VIEW (obj));
        
+       /* Hide headers by default */
+       gtk_tree_view_set_headers_visible ((GtkTreeView *)obj, FALSE);
+       gtk_tree_view_set_rules_hint ((GtkTreeView *) obj, TRUE);
+
        return MODEST_ACCOUNT_VIEW (obj);
 }
 
@@ -783,65 +743,13 @@ typedef struct
                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. */
-}
-
 static void 
 modest_account_view_select_account (ModestAccountView *account_view, 
                                    const gchar* account_name)
 {      
-#ifdef MODEST_TOOLKIT_HILDON2
        return;
-#endif
-       /* 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);
 }
 
-#ifndef MODEST_TOOLKIT_HILDON2
-static void
-modest_account_view_select_first_account (ModestAccountView *account_view)
-{
-       GtkTreeIter iter;
-       GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (account_view));
-
-       if (gtk_tree_model_get_iter_first (model, &iter)) {
-               GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (account_view));
-
-               gtk_tree_selection_select_iter (selection, &iter);
-       }
-}
-#endif
-
 static void
 on_default_account_changed (ModestAccountMgr *mgr,
                            gpointer user_data)
@@ -899,7 +807,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;
@@ -915,7 +823,7 @@ update_picker_mode (ModestAccountView *self)
 
        /* Name column */
        column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 1);
-       renderers = gtk_tree_view_column_get_cell_renderers (column);
+       renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
        renderer = (GtkCellRenderer *) renderers->data;
        g_object_set (renderer, 
                      "align-set", TRUE,
@@ -933,7 +841,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 
@@ -946,3 +854,27 @@ 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;
+}