* src/widgets/modest-msg-view.c:
authorJose Dapena Paz <jdapena@igalia.com>
Thu, 19 Jul 2007 16:39:42 +0000 (16:39 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Thu, 19 Jul 2007 16:39:42 +0000 (16:39 +0000)
* Added implementation of get_message_is_empty method. It uses
  gtk_html_export method to know if the buffer has any text
  representation and this is empty or not.
* src/maemo/modest-msg-view-window.c:
* Removed check for empty buffer to show "nothing to find"
  banner on toggling the toolbar. This should be shown on trying
  to search in the toolbar, not on trying to show the toolbar.
* Added the nothing to find banner on searching empty buffers,
  using the new implementation. This is a partial fix to
  NB#62350.

pmo-trunk-r2756

src/maemo/modest-msg-view-window.c
src/widgets/modest-msg-view.c

index b4152d2..e2668ae 100644 (file)
@@ -789,13 +789,6 @@ modest_msg_view_window_toggle_find_toolbar (GtkToggleAction *toggle,
 
        is_active = gtk_toggle_action_get_active (toggle);
 
 
        is_active = gtk_toggle_action_get_active (toggle);
 
-       /* Show a warning if there is nothing to search: */
-       if (is_active && priv->msg_view && 
-               modest_msg_view_get_message_is_empty (MODEST_MSG_VIEW (priv->msg_view))) {
-               hildon_banner_show_information (GTK_WIDGET (window), NULL, _("mail_ib_nothing_to_find"));
-               return;
-       }
-
        if (is_active) {
                gtk_widget_show (priv->find_toolbar);
                hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
        if (is_active) {
                gtk_widget_show (priv->find_toolbar);
                hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
@@ -830,6 +823,11 @@ modest_msg_view_window_find_toolbar_search (GtkWidget *widget,
        gchar *current_search;
        ModestMsgViewWindowPrivate *priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (obj);
 
        gchar *current_search;
        ModestMsgViewWindowPrivate *priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (obj);
 
+       if (modest_msg_view_get_message_is_empty (MODEST_MSG_VIEW (priv->msg_view))) {
+               hildon_banner_show_information (NULL, NULL, _("mail_ib_nothing_to_find"));
+               return;
+       }
+
        g_object_get (G_OBJECT (widget), "prefix", &current_search, NULL);
 
        if ((current_search == NULL) || (strcmp (current_search, "") == 0)) {
        g_object_get (G_OBJECT (widget), "prefix", &current_search, NULL);
 
        if ((current_search == NULL) || (strcmp (current_search, "") == 0)) {
index d2116ef..373f75b 100644 (file)
@@ -869,7 +869,6 @@ modest_msg_view_init (ModestMsgView *obj)
        priv->headers_window = NULL;
        priv->html_window = NULL;
 
        priv->headers_window = NULL;
        priv->html_window = NULL;
 
-
        gtk_widget_push_composite_child ();
        priv->html_scroll = gtk_scrolled_window_new (NULL, NULL);
        gtk_widget_set_composite_name (priv->html_scroll, "contents");
        gtk_widget_push_composite_child ();
        priv->html_scroll = gtk_scrolled_window_new (NULL, NULL);
        gtk_widget_set_composite_name (priv->html_scroll, "contents");
@@ -1323,6 +1322,7 @@ set_empty_message (ModestMsgView *self)
 
        gtk_html_load_from_string (GTK_HTML(priv->gtkhtml),
                                   "", 1);
 
        gtk_html_load_from_string (GTK_HTML(priv->gtkhtml),
                                   "", 1);
+
        
        return TRUE;
 }
        
        return TRUE;
 }
@@ -1422,14 +1422,30 @@ modest_msg_view_get_message (ModestMsgView *self)
        return msg;
 }
 
        return msg;
 }
 
+static gboolean
+has_contents_receiver (gpointer engine, const gchar *data,
+                      size_t len, gboolean *has_contents)
+{
+       if (len > 1 || ((len == 1)&&(data[0]!='\n'))) {
+               *has_contents = TRUE;
+               return FALSE;
+       }
+       return TRUE;
+}
+
 gboolean 
 modest_msg_view_get_message_is_empty (ModestMsgView *self)
 {
        /* TODO: Find some gtkhtml API to check whether there is any (visible, non markup)
         * text in the message:
         */
 gboolean 
 modest_msg_view_get_message_is_empty (ModestMsgView *self)
 {
        /* TODO: Find some gtkhtml API to check whether there is any (visible, non markup)
         * text in the message:
         */
+       ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
+       gboolean has_contents = FALSE;
+
+       gtk_html_export (GTK_HTML (priv->gtkhtml), "text/plain", 
+                        (GtkHTMLSaveReceiverFn) has_contents_receiver, &has_contents);
        
        
-       return FALSE;
+       return !has_contents;
 }
 
 
 }