* Merged revision 5291 from trunk
[modest] / src / maemo / modest-platform.c
index d2e97b4..734611e 100644 (file)
@@ -56,6 +56,7 @@
 #include <modest-account-settings-dialog.h>
 #include <easysetup/modest-easysetup-wizard-dialog.h>
 #include <hildon/hildon-sound.h>
+#include <osso-mem.h>
 
 #ifdef MODEST_HAVE_MCE
 #include <mce/dbus-names.h>
@@ -859,21 +860,22 @@ modest_platform_run_folder_name_dialog (GtkWindow *parent_window,
                          G_CALLBACK (entry_changed),
                          dialog);
 
+
+       /* Some locales like pt_BR need this to get the full window
+          title shown */
+       gtk_widget_set_size_request (GTK_WIDGET (dialog), 300, -1);
+
        /* Create the hbox */
        hbox = gtk_hbox_new (FALSE, 12);
-       gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
 
        /* Add hbox to dialog */
        gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
                            hbox, FALSE, FALSE, 0);
-
-       gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
-       gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
-
-       /* Some locales like pt_BR need this to get the full window
-          title shown */
-       gtk_widget_set_size_request (GTK_WIDGET (dialog), 300, -1);
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
+                                    GTK_WINDOW (dialog));
+       gtk_widget_show_all (GTK_WIDGET(dialog));
                
        result = gtk_dialog_run (GTK_DIALOG(dialog));
        if (result == GTK_RESPONSE_ACCEPT)
@@ -963,9 +965,16 @@ modest_platform_run_rename_folder_dialog (GtkWindow *parent_window,
 
 
 static void
-on_destroy_dialog (GtkDialog *dialog)
+on_destroy_dialog (GtkWidget *dialog)
 {
-       gtk_widget_destroy (GTK_WIDGET(dialog));
+       /* This could happen when the dialogs get programatically
+          hidden or destroyed (for example when closing the
+          application while a dialog is being shown) */
+       if (!GTK_IS_WIDGET (dialog))
+               return;
+
+       gtk_widget_destroy (dialog);
+
        if (gtk_events_pending ())
                gtk_main_iteration ();
 }
@@ -983,10 +992,7 @@ modest_platform_run_confirmation_dialog (GtkWindow *parent_window,
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
 
-       on_destroy_dialog (GTK_DIALOG(dialog));
-       
-       while (gtk_events_pending ())
-               gtk_main_iteration ();
+       on_destroy_dialog (dialog);
 
        return response;
 }
@@ -1009,10 +1015,7 @@ modest_platform_run_confirmation_dialog_with_buttons (GtkWindow *parent_window,
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
 
-       on_destroy_dialog (GTK_DIALOG(dialog));
-       
-       while (gtk_events_pending ())
-               gtk_main_iteration ();
+       on_destroy_dialog (dialog);
 
        return response;
 }
@@ -1031,10 +1034,7 @@ modest_platform_run_yes_no_dialog (GtkWindow *parent_window,
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        
-       on_destroy_dialog (GTK_DIALOG(dialog));
-
-       while (gtk_events_pending ())
-               gtk_main_iteration ();
+       on_destroy_dialog (dialog);
 
        return response;
 }
@@ -1055,10 +1055,7 @@ modest_platform_run_information_dialog (GtkWindow *parent_window,
        if (block) {
                gtk_dialog_run (GTK_DIALOG (note));
        
-               on_destroy_dialog (GTK_DIALOG (note));
-
-               while (gtk_events_pending ())
-                       gtk_main_iteration ();
+               on_destroy_dialog (note);
        } else {
                g_signal_connect_swapped (note,
                                          "response", 
@@ -1263,7 +1260,7 @@ modest_platform_run_sort_dialog (GtkWindow *parent_window,
        }
        
        /* Free */
-       on_destroy_dialog (GTK_DIALOG(dialog));
+       on_destroy_dialog (dialog);
 }
 
 
@@ -1688,6 +1685,10 @@ modest_platform_animation_banner (GtkWidget *parent,
 
        g_return_val_if_fail (text != NULL, NULL);
 
+       /* If the parent is not visible then do not show */
+       if (parent && !GTK_WIDGET_VISIBLE (parent))
+               return NULL;
+
        inf_note = hildon_banner_show_animation (parent, animation_name, text);
 
        return inf_note;
@@ -1867,7 +1868,7 @@ modest_platform_run_certificate_confirmation_dialog (const gchar* server_name,
                                     GTK_WINDOW (note));
        response = gtk_dialog_run(GTK_DIALOG(note));
 
-       on_destroy_dialog (GTK_DIALOG(note));
+       on_destroy_dialog (note);
        g_free (question);
        
        return response == GTK_RESPONSE_OK;
@@ -1902,7 +1903,7 @@ modest_platform_run_alert_dialog (const gchar* prompt,
                const int response = gtk_dialog_run (GTK_DIALOG (dialog));
                retval = (response == GTK_RESPONSE_YES) || (response == GTK_RESPONSE_OK);
                
-               on_destroy_dialog (GTK_DIALOG(dialog));         
+               on_destroy_dialog (dialog);             
        } else {
                /* Just show the error text and use the default response: */
                modest_platform_run_information_dialog (GTK_WINDOW (main_win), 
@@ -2216,7 +2217,7 @@ modest_platform_get_account_settings_dialog (ModestAccountSettings *settings)
 }
 
 GtkWidget *
-modest_platform_get_account_settings_wizard ()
+modest_platform_get_account_settings_wizard (void)
 {
        ModestEasysetupWizardDialog *dialog = modest_easysetup_wizard_dialog_new ();
 
@@ -2257,3 +2258,27 @@ modest_platform_get_current_connection (void)
 #endif /* MODEST_HAVE_CONIC */
        return retval;
 }
+
+
+
+gboolean
+modest_platform_check_memory_low (ModestWindow *win,
+                                 gboolean visuals)
+{
+       gboolean lowmem;
+       
+       /* are we in low memory state? */
+       lowmem = osso_mem_in_lowmem_state () ? TRUE : FALSE;
+       
+       if (win && lowmem && visuals)
+               modest_platform_run_information_dialog (
+                       GTK_WINDOW(win),
+                       dgettext("ke-recv","memr_ib_operation_disabled"),
+                       TRUE);
+
+       if (lowmem)
+               g_debug ("%s: low memory reached. disallowing some operations",
+                        __FUNCTION__);
+
+       return lowmem;
+}