* make modest_text_utils_get_display_date return a ptr to
[modest] / src / maemo / modest-platform.c
index 1154846..cac2a48 100644 (file)
@@ -1256,12 +1256,14 @@ modest_platform_on_new_headers_received (TnyList *header_list)
 
        iter = tny_list_create_iterator (header_list);
        while (!tny_iterator_is_done (iter)) {
-               gchar *url = NULL, *display_address = NULL, *display_date = NULL, *summary = NULL;
+               gchar *url = NULL, *display_address = NULL,  *summary = NULL;
+               const gchar *display_date;
                TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
                TnyFolder *folder = tny_header_get_folder (header);
                gboolean first_notification = TRUE;
                gint notif_id;
-       
+
+               /* constant string, don't free */
                display_date = modest_text_utils_get_display_date (tny_header_get_date_received (header));
 
                display_address = g_strdup(tny_header_get_from (header));
@@ -1272,7 +1274,6 @@ modest_platform_on_new_headers_received (TnyList *header_list)
                                                        tny_header_get_subject (header),
                                                        "qgn_list_messagin",
                                                        "email.arrive");
-               
                /* Create the message URL */
                url = g_strdup_printf ("%s/%s", tny_folder_get_url_string (folder), 
                                       tny_header_get_uid (header));
@@ -1318,7 +1319,6 @@ modest_platform_on_new_headers_received (TnyList *header_list)
                   not to store the list in gconf */
        
                /* Free & carry on */
-               g_free (display_date);
                g_free (display_address);
                g_free (summary);
                g_free (url);
@@ -1632,19 +1632,29 @@ on_cert_dialog_response (GtkDialog *dialog, gint response_id,  const gchar* cert
 
 
 gboolean
-modest_platform_run_certificate_conformation_dialog (const gchar* server_name,
+modest_platform_run_certificate_confirmation_dialog (const gchar* server_name,
                                                     const gchar *certificate)
 {
        GtkWidget *note;
        gint response;
-       GtkWindow *main_win =
-               (GtkWindow*)modest_window_mgr_get_main_window (modest_runtime_get_window_mgr());
+       ModestWindow *main_win;
+       
+       if (!modest_window_mgr_main_window_exists (modest_runtime_get_window_mgr())) {
+               g_warning ("%s: don't show dialogs if there's no main window; assuming 'Cancel'",
+                          __FUNCTION__);
+               return FALSE;
+       }
 
+       /* don't create it */
+       main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE);
+       g_return_val_if_fail (main_win, FALSE); /* should not happen */
+       
+       
        gchar *question = g_strdup_printf (_("mcen_nc_unknown_certificate"),
                                           server_name);
        
        note = hildon_note_new_confirmation_add_buttons  (
-               main_win,
+               GTK_WINDOW(main_win),
                question,
                _("mcen_bd_dialog_ok"),     GTK_RESPONSE_OK,
                _("mcen_bd_view"),          GTK_RESPONSE_HELP,   /* abusing this... */
@@ -1662,7 +1672,7 @@ modest_platform_run_certificate_conformation_dialog (const gchar* server_name,
        on_destroy_dialog (GTK_DIALOG(note));
        g_free (question);
        
-       return response;
+       return response == GTK_RESPONSE_OK;
 }
        
 
@@ -1671,8 +1681,16 @@ gboolean
 modest_platform_run_alert_dialog (const gchar* prompt, 
                                  gboolean is_question)
 {      
-       ModestWindow *main_window = 
-               modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ());
+       ModestWindow *main_win; 
+
+       if (!modest_window_mgr_main_window_exists (modest_runtime_get_window_mgr())) {
+               g_warning ("%s:\n'%s'\ndon't show dialogs if there's no main window;"
+                          " assuming 'Cancel' for questions, 'Ok' otherwise", prompt, __FUNCTION__);
+               return is_question ? FALSE : TRUE;
+       }
+
+       main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE);
+       g_return_val_if_fail (main_win, FALSE); /* should not happen */
        
        gboolean retval = TRUE;
        if (is_question) {
@@ -1680,7 +1698,7 @@ modest_platform_run_alert_dialog (const gchar* prompt,
                 * 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 = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_window), 
+               GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_win), 
                                                                              prompt));
                modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
                                             GTK_WINDOW (dialog));
@@ -1691,7 +1709,7 @@ modest_platform_run_alert_dialog (const gchar* prompt,
                on_destroy_dialog (GTK_DIALOG(dialog));         
        } else {
                /* Just show the error text and use the default response: */
-               modest_platform_run_information_dialog (GTK_WINDOW (main_window), 
+               modest_platform_run_information_dialog (GTK_WINDOW (main_win), 
                                                        prompt);
        }
        return retval;