-/*
- * Free the returned string
- */
-static gchar *
-get_gray_color_markup (GtkWidget *styled_widget)
-{
- gchar *gray_color_markup = NULL;
-#ifndef MODEST_HAVE_HILDON0_WIDGETS
- /* Obtain the secondary text color. We need a realized widget, that's why
- we get styled_widget from outside */
- GdkColor color;
- if (gtk_style_lookup_color (styled_widget->style, "SecondaryTextColor", &color))
- gray_color_markup = modest_text_utils_get_color_string (&color);
-#endif /*MODEST_HAVE_HILDON0_WIDGETS*/
-
- if (!gray_color_markup)
- gray_color_markup = g_strdup ("#BBBBBB");
-
- return gray_color_markup;
-}
-
-/*
- * Free the returned string
- */
-static gchar*
-create_device_name_visual_string (const gchar *device_name,
- const gchar *gray_color_markup)
-{
- gchar *tmp, *label;
-
- /* We have to use "" to fill the %s of the translation. We can
- not just use the device name because the device name is
- shown in a different color, so it could not be included
- into the <span> tag */
- tmp = g_strdup_printf (_("mcen_fi_localroot_description"), "");
- label = g_markup_printf_escaped ("<span color='%s'>%s</span>%s",
- gray_color_markup,
- tmp,
- device_name);
- g_free (tmp);
-
- return label;
-}
-
-typedef struct
-{
- GtkWidget *count_label;
- GtkWidget *msg_count_label;
- GtkWidget *size_label;
- gchar *color_markup;
-} DetailsWidgets;
-
-static gchar *
-create_uint_label (const gchar *markup,
- const gchar *name,
- guint count)
-{
- return g_markup_printf_escaped ("<span color='%s'>%s:</span> %d", markup, name, count);
-}
-
-static gchar *
-create_gchar_label (const gchar *markup,
- const gchar *name,
- gchar *count)
-{
- return g_markup_printf_escaped ("<span color='%s'>%s:</span> %s", markup, name, count);
-}
-
-static void
-update_folder_stats_status_cb (ModestFolderStats stats,
- gpointer user_data)
-{
- DetailsWidgets *widgets = (DetailsWidgets *) user_data;
- gchar *label, *tmp;
-
- label = create_uint_label (widgets->color_markup, _("mcen_fi_rootfolder_folders"), stats.folders);
- gtk_label_set_markup (GTK_LABEL (widgets->count_label), label);
- g_free (label);
-
- label = create_uint_label (widgets->color_markup, _("mcen_fi_rootfolder_messages"), stats.msg_count);
- gtk_label_set_markup (GTK_LABEL (widgets->msg_count_label), label);
- g_free (label);
-
- if (widgets->size_label) {
- tmp = modest_text_utils_get_display_size (stats.local_size);
- label = create_gchar_label (widgets->color_markup, _("mcen_fi_rootfolder_size"), tmp);
- gtk_label_set_markup (GTK_LABEL (widgets->size_label), label);
- g_free (label);
- g_free (tmp);
- }
-}
-
-static void
-update_folder_stats_cb (ModestFolderStats stats,
- gpointer user_data)
-{
- DetailsWidgets *widgets = (DetailsWidgets *) user_data;
-
- /* refresh data */
- update_folder_stats_status_cb (stats, user_data);
-
- /* frees. Note that the widgets could have been destroyed but
- we still keep a reference */
- g_free (widgets->color_markup);
- if (widgets->count_label)
- g_object_unref (widgets->count_label);
- if (widgets->msg_count_label)
- g_object_unref (widgets->msg_count_label);
- if (widgets->size_label)
- g_object_unref (widgets->size_label);
- g_slice_free (DetailsWidgets, widgets);
-}
-
-static GtkWidget *
-create_details_widget (GtkWidget *styled_widget, TnyAccount *account)
-{
- /* TODO: Clean up this function. It's a mess, with lots of copy/paste. murrayc. */
-
- GtkWidget *vbox;
- GtkWidget *label_w;
- gchar *label;
- gchar *gray_color_markup;
- DetailsWidgets *widgets;
-
- vbox = gtk_vbox_new (FALSE, 0);
- widgets = g_slice_new0 (DetailsWidgets);
-
- gray_color_markup = get_gray_color_markup (styled_widget);
- widgets->color_markup = g_strdup (gray_color_markup);
-
- /* Account description: */
- if (modest_tny_account_is_virtual_local_folders (account)
- || (modest_tny_account_is_memory_card_account (account))) {
-
- /* Get device name */
- gchar *device_name = NULL;
- if (modest_tny_account_is_virtual_local_folders (account))
- device_name = modest_conf_get_string (modest_runtime_get_conf(),
- MODEST_CONF_DEVICE_NAME, NULL);
- else
- device_name = g_strdup (tny_account_get_name (account));
-
- label = create_device_name_visual_string ((const gchar *) device_name,
- (const gchar *) gray_color_markup);
- label_w = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label_w), label);
- gtk_label_set_ellipsize (GTK_LABEL (label_w), PANGO_ELLIPSIZE_END);
- gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
- g_free (device_name);
- g_free (label);
- } else {
- if(!strcmp (tny_account_get_id (account), MODEST_MMC_ACCOUNT_ID)) {
- gtk_box_pack_start (GTK_BOX (vbox),
- gtk_label_new (tny_account_get_name (account)),
- FALSE, FALSE, 0);
- } else {
- /* Other accounts, such as IMAP and POP: */
-
- GString *proto;
- gchar *tmp;
-
- /* Put proto in uppercase */
- proto = g_string_new (tny_account_get_proto (account));
- proto = g_string_ascii_up (proto);
-
- /* note: mcen_fi_localroot_description is something like "%s account"
- * however, we should display "%s account: %s"... therefore, ugly tmp */
- tmp = g_strdup_printf (_("mcen_fi_remoteroot_account"),proto->str);
- label = g_markup_printf_escaped ("<span color='%s'>%s:</span> %s",
- gray_color_markup, tmp, tny_account_get_name (account));
- g_free (tmp);
-
- label_w = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label_w), label);
- gtk_label_set_ellipsize (GTK_LABEL (label_w), PANGO_ELLIPSIZE_END);
- gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
- g_string_free (proto, TRUE);
- g_free (label);
- }
- }
-
- /* Message count */
- TnyFolderStore *folder_store = TNY_FOLDER_STORE (account);
- label = create_uint_label (gray_color_markup, _("mcen_fi_rootfolder_messages"), 0);
- label_w = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label_w), label);
- gtk_label_set_ellipsize (GTK_LABEL (label_w), PANGO_ELLIPSIZE_END);
- gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
- g_free (label);
-
- widgets->msg_count_label = g_object_ref (label_w);
-
- /* Folder count */
- label = create_uint_label (gray_color_markup, _("mcen_fi_rootfolder_folders"), 0);
- label_w = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label_w), label);
- gtk_label_set_ellipsize (GTK_LABEL (label_w), PANGO_ELLIPSIZE_END);
- gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
- g_free (label);
-
- widgets->count_label = g_object_ref (label_w);
-
- /* Size / Date */
- if (modest_tny_account_is_virtual_local_folders (account)
- || modest_tny_account_is_memory_card_account (account)) {
-
- label = create_gchar_label (gray_color_markup, _("mcen_fi_rootfolder_size"), "0");
-
- label_w = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label_w), label);
- gtk_label_set_ellipsize (GTK_LABEL (label_w), PANGO_ELLIPSIZE_END);
- gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
- g_free (label);
-
- widgets->size_label = g_object_ref (label_w);
-
- } else if (TNY_IS_ACCOUNT(folder_store)) {
- TnyAccount *account = TNY_ACCOUNT(folder_store);
-
- time_t last_updated;
- const gchar *last_updated_string;
- /* Get last updated from configuration */
- last_updated = modest_account_mgr_get_last_updated (modest_runtime_get_account_mgr (),
- tny_account_get_id (account));
-
- if (last_updated > 0)
- last_updated_string = modest_text_utils_get_display_date(last_updated);
- else
- last_updated_string = g_strdup (_("mcen_va_never"));
-
- label = g_markup_printf_escaped ("<span color='%s'>%s:</span> %s",
- gray_color_markup, _("mcen_ti_lastupdated"), last_updated_string);
- label_w = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label_w), label);
- gtk_label_set_ellipsize (GTK_LABEL (label_w), PANGO_ELLIPSIZE_END);
- gtk_box_pack_start (GTK_BOX (vbox), label_w, FALSE, FALSE, 0);
- g_free (label);
- }
-
- g_free (gray_color_markup);
-
- /* Refresh folder stats asynchronously */
- modest_tny_folder_store_get_folder_stats (TNY_FOLDER_STORE (account),
- update_folder_stats_cb,
- update_folder_stats_status_cb,
- widgets);
-
- /* Set alignment */
- gtk_container_foreach (GTK_CONTAINER (vbox), (GtkCallback) set_alignment, NULL);
-
- return vbox;
-}