2007-06-17 Johannes Schmid <johannes.schmid@openismus.com>
[modest] / src / maemo / modest-maemo-utils.c
index d085049..d45f1d8 100644 (file)
@@ -229,13 +229,18 @@ modest_maemo_utils_file_exists (const gchar *filename)
 }
 
 TnyFsStream *
-modest_maemo_utils_create_temp_stream (gchar **path)
+modest_maemo_utils_create_temp_stream (const gchar *extension, gchar **path)
 {
-       TnyStream *tmp_fs_stream;
+       TnyStream *tmp_fs_stream = NULL;
        gint fd;
-       gchar *filepath;
+       gchar *filepath = NULL;
+       gchar *template = NULL;
 
-       fd = g_file_open_tmp (NULL, &filepath, NULL);
+       if (extension != NULL)
+               template = g_strdup_printf ("XXXXXX.%s", extension);
+
+       fd = g_file_open_tmp (template, &filepath, NULL);
+       g_free (template);
        if (path != NULL)
                *path = filepath;
        if (fd == -1) {
@@ -250,20 +255,16 @@ modest_maemo_utils_create_temp_stream (gchar **path)
 typedef struct 
 {
        gboolean finished;
+       gboolean cancel;
        GList *result;
-  GtkWidget* banner;
+       GtkWidget* dialog;
+  GtkWidget* progress;
 } 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
@@ -272,11 +273,18 @@ 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;
+       }
+
        if (!auth_types) {
                printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
                info->finished = TRUE; /* We are blocking, waiting for this. */
@@ -308,14 +316,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)
 {
-       return NULL;
-/* FIXME: Activate when changes are merged into tinymail */
-#if 0
        g_return_val_if_fail (proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN, NULL);
        
        /*
@@ -368,12 +381,22 @@ 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->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 (
@@ -385,16 +408,17 @@ 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)
+       {
+               g_slice_free (ModestGetSupportedAuthInfo, info);
+               info = NULL;
+       }
        return result;
-#endif
 }