* Fixes NB#59138, message is saved to drafts when main window is closed
[modest] / src / maemo / modest-maemo-utils.c
index 7754685..150dbcf 100644 (file)
@@ -255,20 +255,17 @@ modest_maemo_utils_create_temp_stream (const gchar *extension, gchar **path)
 typedef struct 
 {
        gboolean finished;
+       gboolean cancel;
        GList *result;
-  GtkWidget* banner;
+       GtkWidget* dialog;
+       GtkWidget* progress;
+       GError* error;
 } ModestGetSupportedAuthInfo;
 
-#if 0
 static void on_camel_account_get_supported_secure_authentication_status (
        GObject *self, TnyStatus *status, gpointer user_data)
 {
-
-       printf ("DEBUG: %s.\n", __FUNCTION__);
-  ModestGetSupportedAuthInfo* info = (ModestGetSupportedAuthInfo*) user_data;
-  GDK_THREADS_ENTER();
-  hildon_banner_set_fraction(HILDON_BANNER(info->banner), tny_status_get_fraction(status));
-  GDK_THREADS_LEAVE();
+       /*ModestGetSupportedAuthInfo* info = (ModestGetSupportedAuthInfo*) user_data;*/
 }
 
 static void
@@ -277,10 +274,25 @@ on_camel_account_get_supported_secure_authentication (
   TnyList *auth_types, GError **err, 
   gpointer user_data)
 {
-       printf ("DEBUG: %s.\n", __FUNCTION__);
                
        ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
        g_return_if_fail (info);
+
+       /* Free everything if the actual action was canceled */
+       if (info->cancel)
+       {
+               g_slice_free (ModestGetSupportedAuthInfo, info);
+               info = NULL;
+               return;
+       }
+
+       /* Why is this a pointer to a pointer? We are not supposed to set it,
+        * are we? */
+       if(err != NULL && *err != NULL)
+       {
+               printf("Err: %s\n", (*err)->message);
+               info->error = g_error_copy(*err);
+       }
        
        if (!auth_types) {
                printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
@@ -313,14 +325,19 @@ on_camel_account_get_supported_secure_authentication (
   printf("DEBUG: finished\n");
        info->finished = TRUE; /* We are blocking, waiting for this. */
 }
-#endif
+
+static void on_secure_auth_cancel(GtkWidget* dialog, int response, gpointer user_data)
+{
+       ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
+       g_return_if_fail(info);
+       /* We are blocking */
+       info->result = NULL;
+       info->cancel = TRUE;
+}
 
 GList* modest_maemo_utils_get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto, 
-       const gchar* hostname, gint port, GtkWindow *parent_window)
+       const gchar* hostname, gint port, const gchar* username, GtkWindow *parent_window, GError** error)
 {
-       return NULL;
-/* FIXME: Activate when changes are merged into tinymail */
-#if 0
        g_return_val_if_fail (proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN, NULL);
        
        /*
@@ -355,6 +372,10 @@ GList* modest_maemo_utils_get_supported_secure_authentication_methods (ModestTra
         /* TODO: Why isn't this done in account_new()? */
        tny_account_set_proto (tny_account,
                               modest_protocol_info_get_transport_store_protocol_name(proto));
+
+       tny_account_set_hostname (tny_account, hostname);
+       /* Required for POP, at least */
+       tny_account_set_user (tny_account, username);
                               
        /* Set the session for the account, so we can use it: */
        ModestTnyAccountStore *account_store = modest_runtime_get_account_store ();
@@ -363,8 +384,6 @@ GList* modest_maemo_utils_get_supported_secure_authentication_methods (ModestTra
        g_return_val_if_fail (session, NULL);
        tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
        
-       tny_account_set_hostname (tny_account, hostname);
-       
        if(port > 0)
                tny_account_set_port (tny_account, port);
                
@@ -373,12 +392,23 @@ GList* modest_maemo_utils_get_supported_secure_authentication_methods (ModestTra
        ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
        info->finished = FALSE;
        info->result = NULL;
-       GtkWidget* progressbar = gtk_progress_bar_new();
-  info->banner = hildon_banner_show_progress (GTK_WIDGET(parent_window), 
-                                              GTK_PROGRESS_BAR(progressbar),
-                                              _("Checking for supported authentification types"));
-  gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
+       info->cancel = FALSE;
+       info->error = NULL;
+       info->progress = gtk_progress_bar_new();
+  info->dialog = gtk_dialog_new_with_buttons(_("Authentication"),
+                                                                                                                               parent_window, GTK_DIALOG_MODAL,
+                                                                                                                               GTK_STOCK_CANCEL,
+                                                                                                                               GTK_RESPONSE_REJECT,
+                                                                                                                               NULL);
+       //gtk_window_set_default_size(GTK_WINDOW(info->dialog), 300, 100);
        
+       g_signal_connect(G_OBJECT(info->dialog), "response", G_CALLBACK(on_secure_auth_cancel), info);
+       
+       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox),
+                                                                               gtk_label_new("Checking for supported authentication types..."));
+       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox), info->progress);
+       gtk_widget_show_all(info->dialog);
+  gtk_progress_bar_pulse(GTK_PROGRESS_BAR(info->progress));
        
        printf ("DEBUG: %s: STARTING.\n", __FUNCTION__);
        tny_camel_account_get_supported_secure_authentication (
@@ -390,16 +420,56 @@ GList* modest_maemo_utils_get_supported_secure_authentication_methods (ModestTra
        /* Block until the callback has been called,
         * driving the main context, so that the (idle handler) callback can be 
         * called, and so that our dialog is clickable: */
-       while (!(info->finished)) {
+       while (!(info->finished) && !(info->cancel)) {
     gtk_main_iteration_do(FALSE); 
        }
        
-  gtk_widget_destroy(info->banner);
+  gtk_widget_destroy(info->dialog);
                
        GList *result = info->result;
-       g_slice_free (ModestGetSupportedAuthInfo, info);
-       info = NULL;
-       
+       if (!info->cancel)
+       {
+               if(info->error != NULL)
+                       g_propagate_error(error, info->error);
+
+               g_slice_free (ModestGetSupportedAuthInfo, info);
+               info = NULL;
+       }
        return result;
+}
+
+void
+modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser)
+{
+       gchar *images_folder;
+       GtkFileFilter *file_filter;
+       GList *image_mimetypes_list;
+       GList *node;
+
+       g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
+
+       /* Set the default folder to images folder */
+       images_folder = g_build_filename (g_get_home_dir (), 
+                                         MODEST_MAEMO_UTILS_MYDOCS_FOLDER,
+                                         MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER, NULL);
+       gtk_file_chooser_set_current_folder (chooser, images_folder);
+       g_free (images_folder);
+
+       /* Set the images mime filter */
+       file_filter = gtk_file_filter_new ();
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
+       image_mimetypes_list = osso_mime_get_mime_types_for_category (OSSO_MIME_CATEGORY_IMAGES);
+#else
+       image_mimetypes_list = hildon_mime_get_mime_types_for_category (HILDON_MIME_CATEGORY_IMAGES);
 #endif
+       for (node = image_mimetypes_list; node != NULL; node = g_list_next (node)) {
+               gtk_file_filter_add_mime_type (file_filter, node->data);
+       }
+       gtk_file_chooser_set_filter (chooser, file_filter);
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
+       osso_mime_types_list_free (image_mimetypes_list);
+#else
+       hildon_mime_types_list_free (image_mimetypes_list);
+#endif
+
 }