Pulsing a dialog to make it more user responsive, final bugfix for 82810
[modest] / src / modest-utils.c
index 0128966..545f636 100644 (file)
@@ -43,6 +43,7 @@
 #include <modest-defs.h>
 #include "modest-utils.h"
 #include "modest-platform.h"
+#include <modest-local-folder-info.h>
 
 GQuark
 modest_utils_get_supported_secure_authentication_error_quark (void)
@@ -59,16 +60,18 @@ modest_utils_folder_writable (const gchar *filename)
                return FALSE;
        
        if (g_strncasecmp (filename, "obex", 4) != 0) {
-               GnomeVFSFileInfo folder_info;
+               GnomeVFSFileInfo *folder_info;
                gchar *folder;
                folder = g_path_get_dirname (filename);
-               gnome_vfs_get_file_info (folder, &folder_info,
+               folder_info = gnome_vfs_file_info_new ();
+               gnome_vfs_get_file_info (folder, folder_info,
                                         GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
                g_free (folder);
-               if (!((folder_info.permissions & GNOME_VFS_PERM_ACCESS_WRITABLE) ||
-                     (folder_info.permissions & GNOME_VFS_PERM_USER_WRITE))) {
+               if (!((folder_info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE) ||
+                     (folder_info->permissions & GNOME_VFS_PERM_USER_WRITE))) {
                        return FALSE;
                }
+               gnome_vfs_file_info_unref (folder_info);
        }
        return TRUE;
 }
@@ -163,6 +166,7 @@ typedef struct
        GtkWidget* dialog;
        GtkWidget* progress;
        GError* error;
+       gboolean pulsing;
 } ModestGetSupportedAuthInfo;
 
 static void on_camel_account_get_supported_secure_authentication_status (
@@ -182,6 +186,7 @@ on_idle_secure_auth_finished (gpointer user_data)
         * the code below is or does Gtk+ code */
 
        gdk_threads_enter(); /* CHECKED */
+       info->pulsing = FALSE;
        gtk_dialog_response (GTK_DIALOG (info->dialog), GTK_RESPONSE_ACCEPT);
        gdk_threads_leave(); /* CHECKED */
 
@@ -270,8 +275,29 @@ on_secure_auth_cancel(GtkWidget* dialog, int response, gpointer user_data)
                /* This gives the ownership of the info to the worker thread. */
                info->result = NULL;
                info->cancel = TRUE;
+               info->pulsing = FALSE;
        }
 }
+typedef struct {
+       GtkProgressBar *progress;
+       gboolean not_finished;
+} KeepPulsing;
+
+static gboolean
+keep_pulsing (gpointer user_data)
+{
+       KeepPulsing *info = (KeepPulsing *) user_data;
+       
+       gtk_progress_bar_pulse (info->progress);
+
+       if (!info->not_finished) {
+               g_object_unref (info->progress);
+               g_slice_free (KeepPulsing, info);
+               return FALSE;
+       }
+       
+       return TRUE;
+}
 
 GList*
 modest_utils_get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto, 
@@ -337,9 +363,10 @@ modest_utils_get_supported_secure_authentication_methods (ModestTransportStorePr
        info->result = NULL;
        info->cancel = FALSE;
        info->error = NULL;
+       info->pulsing = TRUE;
        info->progress = gtk_progress_bar_new();
        /* TODO: Need logical_ID for the title: */
-       info->dialog = gtk_dialog_new_with_buttons(_("Authentication"),
+       info->dialog = gtk_dialog_new_with_buttons(" ",
                                                   parent_window, GTK_DIALOG_MODAL,
                                                   _("mcen_bd_dialog_cancel"),
                                                   GTK_RESPONSE_REJECT,
@@ -349,12 +376,19 @@ modest_utils_get_supported_secure_authentication_methods (ModestTransportStorePr
        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_label_new(_("emev_ni_checking_supported_auth_methods")));
        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));
+
+       KeepPulsing *pi = g_slice_new (KeepPulsing);
+       pi->progress = (GtkProgressBar *) g_object_ref (info->progress);
+       pi->not_finished = TRUE;
+       
+       /* Starts the pulsing of the progressbar */
+       g_timeout_add (500, keep_pulsing, pi);
        
        printf ("DEBUG: %s: STARTING.\n", __FUNCTION__);
+       
        tny_camel_account_get_supported_secure_authentication (
                TNY_CAMEL_ACCOUNT (tny_account),
                on_camel_account_get_supported_secure_authentication,
@@ -363,6 +397,9 @@ modest_utils_get_supported_secure_authentication_methods (ModestTransportStorePr
 
        gtk_dialog_run (GTK_DIALOG (info->dialog));
        
+       pi->not_finished = FALSE;
+       /* pi is freed in the timeout itself to avoid a GCond here */
+       
        gtk_widget_destroy(info->dialog);
                        
        GList *result = info->result;
@@ -462,3 +499,28 @@ modest_list_index (TnyList *list, GObject *object)
        g_object_unref (iter);
        return index;
 }
+
+guint64 
+modest_folder_available_space (const gchar *maildir_path)
+{
+       gchar *folder;
+       gchar *uri_string;
+       GnomeVFSURI *uri;
+       GnomeVFSFileSize size;
+
+       folder = modest_local_folder_info_get_maildir_path (maildir_path);
+       uri_string = gnome_vfs_get_uri_from_local_path (folder);
+       uri = gnome_vfs_uri_new (uri_string);
+       g_free (folder);
+       g_free (uri_string);
+
+       if (uri) {
+               if (gnome_vfs_get_volume_free_space (uri, &size) != GNOME_VFS_OK)
+                       size = -1;
+               gnome_vfs_uri_unref (uri);
+       } else {
+               size = -1;
+       }
+
+       return (guint64) size;
+}