2007-07-25 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Wed, 25 Jul 2007 12:34:45 +0000 (12:34 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Wed, 25 Jul 2007 12:34:45 +0000 (12:34 +0000)
* src/maemo/modest-maemo-utils.h:
* src/maemo/modest-maemo-utils.c: Added
modest_maemo_show_information_note_in_main_context_and_forget().
* src/modest-tny-account-store.c: (modest_tny_account_store_alert):
Use the new function to show simple error dialogs in the main
context, though question dialogs are still in the current context,
which is unfortunately usually not the main context. This should
fix some hangs.

pmo-trunk-r2792

ChangeLog2
src/maemo/modest-maemo-utils.c
src/maemo/modest-maemo-utils.h
src/modest-tny-account-store.c

index b29410f..61c95b6 100644 (file)
@@ -1,5 +1,16 @@
 2007-07-25  Murray Cumming  <murrayc@murrayc.com>
 
 2007-07-25  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/maemo/modest-maemo-utils.h: 
+       * src/maemo/modest-maemo-utils.c: Added 
+       modest_maemo_show_information_note_in_main_context_and_forget().
+       * src/modest-tny-account-store.c: (modest_tny_account_store_alert):
+       Use the new function to show simple error dialogs in the main 
+       context, though question dialogs are still in the current context, 
+       which is unfortunately usually not the main context. This should 
+       fix some hangs.
+
+2007-07-25  Murray Cumming  <murrayc@murrayc.com>
+
        * src/modest-tny-account-store.c: (get_password):
        Never save the entered username and password in gconf, 
        because the UI spec says we should not. This helps 
        * src/modest-tny-account-store.c: (get_password):
        Never save the entered username and password in gconf, 
        because the UI spec says we should not. This helps 
index b48c804..522392b 100644 (file)
@@ -546,6 +546,35 @@ on_hide (GtkDialog *dialog, gpointer user_data)
 }
 #endif
 
 }
 #endif
 
+/* user_data for the idle callback: */
+typedef struct 
+{
+       GtkWindow *parent_window;
+       gchar *message;
+} ModestIdleNoteInfo;
+
+static gboolean
+on_idle_show_information(gpointer user_data)
+{
+       ModestIdleNoteInfo *info = (ModestIdleNoteInfo*)user_data;
+       
+       modest_maemo_show_information_note_and_forget (info->parent_window, info->message);
+       
+       g_free (info->message);
+       g_slice_free (ModestIdleNoteInfo, info);
+       
+       return FALSE; /* Don't call this again. */
+}
+
+void modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *parent_window, const gchar* message)
+{
+       ModestIdleNoteInfo *info = g_slice_new (ModestIdleNoteInfo);
+       info->parent_window = parent_window;
+       info->message = g_strdup (message);
+       
+       g_idle_add (on_idle_show_information, info);
+}
+
 void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *dialog)
 {
        gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
 void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *dialog)
 {
        gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
@@ -555,6 +584,8 @@ void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *d
        gtk_widget_show (GTK_WIDGET (dialog));
 }
 
        gtk_widget_show (GTK_WIDGET (dialog));
 }
 
+
+
 void
 modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, gboolean thumbable)
 {
 void
 modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, gboolean thumbable)
 {
index 3fa9ef3..3bae920 100644 (file)
@@ -132,6 +132,16 @@ void modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser);
  */
 void modest_maemo_show_information_note_and_forget (GtkWindow *parent_window, const gchar* message);
 
  */
 void modest_maemo_show_information_note_and_forget (GtkWindow *parent_window, const gchar* message);
 
+/** modest_maemo_show_information_note_in_main_context_and_forget:
+ * @parent_window: The window for which the note should be transient.
+ * @message: The text to show.
+ * 
+ * This calls modest_maemo_show_information_note_and_forget() in an idle handler.
+ * This should be used when you are not sure that you are in the main context, 
+ * because you should try to use GTK+ UI code only in the main context.
+ */
+void modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *parent_window, const gchar* message);
+
 /** modest_maemo_show_dialog_and_forget:
  * @parent_window: The window for which the note should be transient.
  * @message: The dialog to show.
 /** modest_maemo_show_dialog_and_forget:
  * @parent_window: The window for which the note should be transient.
  * @message: The dialog to show.
index 2291b62..bf01e38 100644 (file)
@@ -1336,48 +1336,31 @@ modest_tny_account_store_alert (TnyAccountStore *self, TnyAccount *account, TnyA
        if (!prompt)
                return FALSE;
 
        if (!prompt)
                return FALSE;
 
-#ifdef MODEST_PLATFORM_MAEMO
-       /* The Tinymail documentation says that we should show Yes and No buttons, 
-        * when it is a question.
-        * Obviously, we need tinymail to use more specific error codes instead,
-        * so we know what buttons to show. */
-        GtkWidget *dialog = NULL;
-        if (question) {
-               dialog = GTK_WIDGET (hildon_note_new_confirmation (NULL, 
+       ModestWindow *main_window = 
+               modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ());
+       gboolean retval = TRUE;
+       if (question) {
+               /* The Tinymail documentation says that we should show Yes and No buttons, 
+                * when it is a question.
+                * Obviously, we need tinymail to use more specific error codes instead,
+                * so we know what buttons to show. */
+        
+               /* TODO: Do this in the main context: */
+               GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_window), 
                        prompt));
                        prompt));
+               const int response = gtk_dialog_run (GTK_DIALOG (dialog));
+               if (question) {
+                       retval = (response == GTK_RESPONSE_YES) ||
+                                        (response == GTK_RESPONSE_OK);
+               }
+       
+               gtk_widget_destroy (dialog);
+       
         } else {
         } else {
-               dialog = GTK_WIDGET (hildon_note_new_information (NULL, 
-                       prompt));
+               /* Just show the error text and use the default response: */
+               modest_maemo_show_information_note_in_main_context_and_forget (GTK_WINDOW (main_window), 
+                       prompt);
         }
         }
-#else
-
-       GtkMessageType gtktype = GTK_MESSAGE_ERROR;
-       switch (type)
-       {
-               case TNY_ALERT_TYPE_INFO:
-               gtktype = GTK_MESSAGE_INFO;
-               break;
-               case TNY_ALERT_TYPE_WARNING:
-               gtktype = GTK_MESSAGE_WARNING;
-               break;
-               case TNY_ALERT_TYPE_ERROR:
-               default:
-               gtktype = GTK_MESSAGE_ERROR;
-               break;
-       }
-       
-       GtkWidget *dialog = gtk_message_dialog_new (NULL, 0,
-               gtktype, GTK_BUTTONS_YES_NO, prompt);
-#endif /* #ifdef MODEST_PLATFORM_MAEMO */
-
-       gboolean retval = TRUE;
-       const int response = gtk_dialog_run (GTK_DIALOG (dialog));
-       if (question) {
-               retval = (response == GTK_RESPONSE_YES) ||
-                                (response == GTK_RESPONSE_OK);
-       }
-
-       gtk_widget_destroy (dialog);
        
        /* TODO: Don't free this when we no longer strdup the message for testers. */
        g_free (prompt);
        
        /* TODO: Don't free this when we no longer strdup the message for testers. */
        g_free (prompt);