Author: post
Date: 2010-06-14 19:42:02 +0200 (Mon, 14 Jun 2010)
New Revision: 3421

Modified:
   trunk/plugins/output-picasa/output-picasa.c
   trunk/plugins/output-picasa/rs-picasa-client.c
   trunk/plugins/output-picasa/rs-picasa-client.h
Log:
Picasa: Fix crash when unable to log in or no username/password given.

Modified: trunk/plugins/output-picasa/output-picasa.c
===================================================================
--- trunk/plugins/output-picasa/output-picasa.c 2010-06-04 22:15:39 UTC (rev 
3420)
+++ trunk/plugins/output-picasa/output-picasa.c 2010-06-14 17:42:02 UTC (rev 
3421)
@@ -38,7 +38,7 @@
 struct _RSPicasa
 {
        RSOutput parent;
-        gchar *album_id;
+       gchar *album_id;
        gint quality;
 };
 
@@ -261,6 +261,8 @@
         CreateAlbumData *create_album_data = g_malloc(sizeof(CreateAlbumData));
 
        PicasaClient *picasa_client = rs_picasa_client_init();
+       if (NULL == picasa_client)
+               return NULL;
 
         GtkListStore *albums = rs_picasa_client_get_album_list(picasa_client, 
&error);
         GtkWidget *combobox = gtk_combo_box_new();
@@ -300,6 +302,9 @@
 
        PicasaClient *picasa_client = rs_picasa_client_init();
 
+       if (NULL == picasa_client)
+               return FALSE;
+
        gchar *temp_file = g_strdup_printf ("%s%s.rawstudio-tmp-%d.jpg", 
g_get_tmp_dir (), G_DIR_SEPARATOR_S, (gint) (g_random_double () * 10000.0));
 
        g_object_set (jpegsave, "filename", temp_file, "quality", 
picasa->quality, NULL);

Modified: trunk/plugins/output-picasa/rs-picasa-client.c
===================================================================
--- trunk/plugins/output-picasa/rs-picasa-client.c      2010-06-04 22:15:39 UTC 
(rev 3420)
+++ trunk/plugins/output-picasa/rs-picasa-client.c      2010-06-14 17:42:02 UTC 
(rev 3421)
@@ -193,25 +193,35 @@
         gtk_widget_show_all (auth_dialog);
         gint response = gtk_dialog_run (GTK_DIALOG (auth_dialog));
 
+       if (0 == gtk_entry_get_text_length(GTK_ENTRY(input_username)) || 
+                       0 == 
gtk_entry_get_text_length(GTK_ENTRY(input_password)) ||
+                       response != GTK_RESPONSE_OK 
+               )
+       {
+    gtk_widget_destroy (auth_dialog);
+               return FALSE;
+       }
+
+       picasa_client->auth_token = NULL;
        picasa_client->username = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(input_username)));
        picasa_client->password = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(input_password)));
 
-        gtk_widget_destroy (auth_dialog);
-
-        gdk_threads_leave ();
-
-       if (response == GTK_RESPONSE_ACCEPT)
-                return TRUE;
-        else
-                return FALSE;
+    gtk_widget_destroy (auth_dialog);
+    gdk_threads_leave ();
+       return TRUE;
 }
 
-void
+gboolean
 rs_picasa_client_auth(PicasaClient *picasa_client)
 {
-       g_assert(picasa_client->username != NULL);
-       g_assert(picasa_client->password != NULL);
+       /* Already authenticated? */
+       if (picasa_client->username && picasa_client->auth_token != NULL)
+               return TRUE;
 
+       /* do we have enough information? */
+       if (picasa_client->username == NULL || picasa_client->password == NULL)
+               return FALSE;
+
        GString *data = g_string_new(NULL);
         struct curl_slist *header = NULL;
 
@@ -252,6 +262,7 @@
                // FIXME: fetch captcha and let user re-authenticate - call 
this function again.
                g_free(picasa_client->captcha_token);
                g_free(picasa_client->captcha_url);
+               return FALSE;
        }
        else
        {
@@ -261,6 +272,10 @@
        g_string_free(data, TRUE);
        g_string_free(post_str, TRUE);
        curl_slist_free_all(header);
+       if (NULL == picasa_client->auth_token)
+               return FALSE;
+
+       return TRUE;
 }
 
 GtkListStore *
@@ -389,18 +404,23 @@
 PicasaClient *
 rs_picasa_client_init()
 {
-        PicasaClient *picasa_client = g_malloc(sizeof(PicasaClient));
+       PicasaClient *picasa_client = g_malloc0(sizeof(PicasaClient));
        picasa_client->curl = curl_easy_init();
 
        picasa_client->auth_token = 
rs_conf_get_string(CONF_PICASA_CLIENT_AUTH_TOKEN);
        picasa_client->username = 
rs_conf_get_string(CONF_PICASA_CLIENT_USERNAME);
 
-       if (!picasa_client->auth_token || !picasa_client->username)
+       while (!rs_picasa_client_auth(picasa_client))
        {
-               rs_picasa_client_auth_popup(picasa_client);
-               rs_picasa_client_auth(picasa_client);
-               rs_conf_set_string(CONF_PICASA_CLIENT_AUTH_TOKEN, 
picasa_client->auth_token);
-               rs_conf_set_string(CONF_PICASA_CLIENT_USERNAME, 
picasa_client->username);
+               if (!rs_picasa_client_auth_popup(picasa_client))
+               {
+                       /* Cancel pressed, or no info entered */
+                       return NULL;
+               }
        }
+       /* Save information */
+       rs_conf_set_string(CONF_PICASA_CLIENT_AUTH_TOKEN, 
picasa_client->auth_token);
+       rs_conf_set_string(CONF_PICASA_CLIENT_USERNAME, 
picasa_client->username);
+
        return picasa_client;
 }

Modified: trunk/plugins/output-picasa/rs-picasa-client.h
===================================================================
--- trunk/plugins/output-picasa/rs-picasa-client.h      2010-06-04 22:15:39 UTC 
(rev 3420)
+++ trunk/plugins/output-picasa/rs-picasa-client.h      2010-06-14 17:42:02 UTC 
(rev 3421)
@@ -14,7 +14,7 @@
 } PicasaClient;
 
 gboolean rs_picasa_client_auth_popup(PicasaClient *picasa_client);
-void rs_picasa_client_auth(PicasaClient *picasa_client);
+gboolean rs_picasa_client_auth(PicasaClient *picasa_client);
 GtkListStore * rs_picasa_client_get_album_list(PicasaClient *picasa_client, 
GError **error);
 char * rs_picasa_client_create_album(PicasaClient *picasa_client, const gchar 
*name, GError **error);
 gboolean rs_picasa_client_upload_photo(PicasaClient *picasa_client, gchar 
*photo, gchar *albumid, GError **error);


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to