2007-07-09 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Mon, 9 Jul 2007 11:14:59 +0000 (11:14 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Mon, 9 Jul 2007 11:14:59 +0000 (11:14 +0000)
* src/maemo/modest-maemo-utils.h:
* src/maemo/modest-maemo-utils.c:
Added modest_maemo_show_information_note_and_forget() for use instead of
gtk_dialog_run() when the response is not needed, to avoid an extra
mainloop which could cause a hang.

* src/maemo/modest-main-window.c: (on_sendqueue_error_happened):
Use the logical IDs for the error message, though they are not
specific enough. Note that I used modest_maemo_show_information_note_and_forget()
because gtk_dialog_run() caused a hang here (the window did not close).

pmo-trunk-r2644

ChangeLog2
src/maemo/modest-maemo-utils.c
src/maemo/modest-maemo-utils.h
src/maemo/modest-main-window.c

index 9ed41e5..5de6f11 100644 (file)
@@ -1,5 +1,18 @@
 2007-07-09  Murray Cumming  <murrayc@murrayc.com>
 
 2007-07-09  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/maemo/modest-maemo-utils.h:
+       * src/maemo/modest-maemo-utils.c: 
+       Added modest_maemo_show_information_note_and_forget() for use instead of 
+       gtk_dialog_run() when the response is not needed, to avoid an extra 
+       mainloop which could cause a hang.
+
+       * src/maemo/modest-main-window.c: (on_sendqueue_error_happened):
+       Use the logical IDs for the error message, though they are not 
+       specific enough. Note that I used modest_maemo_show_information_note_and_forget() 
+       because gtk_dialog_run() caused a hang here (the window did not close).
+
+2007-07-09  Murray Cumming  <murrayc@murrayc.com>
+
        * src/modest-account-mgr-helpers.h:
        * src/modest-account-mgr-helpers.c:
        Added modest_account_mgr_get_store_protocol().
        * src/modest-account-mgr-helpers.h:
        * src/modest-account-mgr-helpers.c:
        Added modest_account_mgr_get_store_protocol().
index bb9862c..3f5eff2 100644 (file)
@@ -507,3 +507,20 @@ modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser)
 #endif
 
 }
 #endif
 
 }
+
+static void
+on_response (GtkDialog *dialog, gint response, gpointer user_data)
+{
+       /* Just destroy the dialog: */
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+void modest_maemo_show_information_note_and_forget (GtkWindow *parent_window, const gchar* message)
+{
+       GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, message));
+       
+       /* Destroy the dialog when it is closed: */
+       g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (on_response), NULL);
+       gtk_widget_show (GTK_WIDGET (dialog));
+}
+
index 518f937..7282a9c 100644 (file)
@@ -122,4 +122,14 @@ GList* modest_maemo_utils_get_supported_secure_authentication_methods (ModestTra
  */
 void modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser);
 
  */
 void modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser);
 
+/** modest_maemo_show_information_note_and_forget:
+ * @parent_window: The window for which the note should be transient.
+ * @message: The text to show.
+ * 
+ * Show the information note and destroy it when it is closed, without 
+ * blocking. Use this when you don't want to use gtk_dialog_run(), which might lead 
+ * to hangs.
+ */
+void modest_maemo_show_information_note_and_forget (GtkWindow *parent_window, const gchar* message);
+
 #endif /*__MODEST_MAEMO_UTILS_H__*/
 #endif /*__MODEST_MAEMO_UTILS_H__*/
index a7696f1..6aaeb53 100644 (file)
@@ -34,6 +34,7 @@
 #include <tny-list.h>
 #include <tny-iterator.h>
 #include <tny-maemo-conic-device.h>
 #include <tny-list.h>
 #include <tny-iterator.h>
 #include <tny-maemo-conic-device.h>
+#include <tny-error.h>
 #include "modest-hildon-includes.h"
 #include "modest-defs.h"
 #include <string.h>
 #include "modest-hildon-includes.h"
 #include "modest-defs.h"
 #include <string.h>
@@ -449,37 +450,6 @@ wrap_in_scrolled_window (GtkWidget *win, GtkWidget *widget)
 /*     return FALSE; */
 /* } */
 
 /*     return FALSE; */
 /* } */
 
-typedef struct
-{
-       ModestMainWindow *self;
-       TnySendQueue *queue;
-       TnyHeader *header;
-} OnResponseInfo;
-
-static void
-on_response (GtkDialog *dialog, gint arg1, gpointer user_data)
-{
-       OnResponseInfo *info = (OnResponseInfo *) user_data;
-       ModestMainWindow *self = info->self;
-       TnyHeader *header = info->header;
-       TnySendQueue *queue = info->queue;
-
-       if (arg1 == GTK_RESPONSE_YES) {
-               TnyFolder *outbox = tny_send_queue_get_outbox (queue);
-               tny_folder_remove_msg (outbox, header, NULL);
-               tny_folder_sync (outbox, TRUE, NULL);
-               g_object_unref (outbox);
-       }
-
-       g_object_unref (queue);
-       g_object_unref (header);
-       g_object_unref (self);
-
-       gtk_widget_destroy (GTK_WIDGET (dialog));
-       g_slice_free (OnResponseInfo, info);
-}
-
-
 static void
 on_sendqueue_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, ModestMainWindow *user_data)
 {
 static void
 on_sendqueue_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, ModestMainWindow *user_data)
 {
@@ -487,20 +457,56 @@ on_sendqueue_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg,
                printf ("DEBUG: %s: err->code=%d, err->message=%s\n", __FUNCTION__, err->code, err->message);
        }
 
                printf ("DEBUG: %s: err->code=%d, err->message=%s\n", __FUNCTION__, err->code, err->message);
        }
 
-       if (header) {
-               gchar *str = g_strdup_printf ("%s. Do you want to remove the message (%s)?",
-                       err->message, tny_header_get_subject (header));
-               OnResponseInfo *info = g_slice_new (OnResponseInfo);
-               GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (user_data), 0,
-                       GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, str);
-               g_free (str);
-               info->queue = g_object_ref (self);
-               info->self = g_object_ref (user_data);
-               info->header = g_object_ref (header);
-               g_signal_connect (G_OBJECT (dialog), "response",
-                       G_CALLBACK (on_response), info);
-               gtk_widget_show_all (dialog);
+       /* Get the account name: */
+       const gchar* server_name = NULL;
+       
+       TnyCamelTransportAccount* server_account = tny_camel_send_queue_get_transport_account (
+               TNY_CAMEL_SEND_QUEUE (self));
+       if (server_account) {
+               server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
+                       
+               g_object_unref (server_account);
+               server_account = NULL;
+       }
+       
+       if (!server_name)
+               server_name = _("Unknown Server");      
+
+       /* Show the appropriate message text for the GError: */
+       gchar *message = NULL;
+       if (err) {
+               switch (err->code) {
+                       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
+                               message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
+                               break;
+                       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
+                               message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
+                               break;
+                       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
+                               /* TODO: This logical ID seems more suitable for a wrong username or password than for a 
+                                * wrong authentication method. The user is unlikely to guess at the real cause.
+                                */
+                               message = g_strdup_printf (_("eemev_ni_ui_smtp_authentication_fail_error"), server_name);
+                               break;
+                       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
+                       default:
+                               message = g_strdup (_("emev_ib_ui_smtp_send_error"));
+                               break;
+               }
+       } else {
+               message = g_strdup (_("emev_ib_ui_smtp_send_error"));
        }
        }
+       
+       modest_maemo_show_information_note_and_forget (GTK_WINDOW (user_data), message);
+       g_free (message);
+       
+       /* TODO: Offer to remove the message, to avoid messages in future? */
+       /*
+       TnyFolder *outbox = tny_send_queue_get_outbox (queue);
+       tny_folder_remove_msg (outbox, header, NULL);
+       tny_folder_sync (outbox, TRUE, NULL);
+       g_object_unref (outbox);
+       */
 }
 
 typedef struct {
 }
 
 typedef struct {