[gthumb] picasaweb: show an error message if the authentication fails



commit 0db9467c90a5a500f03a728510e88c315a13d032
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Aug 24 18:00:10 2010 +0200

    picasaweb: show an error message if the authentication fails
    
    If the authentication fails show an error message  in the
    authentication dialog; allow to select another account
    if more then one is present.
    
    [bug #627531]

 .../data/ui/picasa-web-account-properties.ui       |   34 +++++++++++-
 extensions/picasaweb/dlg-export-to-picasaweb.c     |   59 ++++++++++++++++----
 extensions/picasaweb/dlg-import-from-picasaweb.c   |   55 +++++++++++++++---
 .../picasaweb/picasa-account-properties-dialog.c   |   38 ++++++++++++-
 .../picasaweb/picasa-account-properties-dialog.h   |    6 ++
 5 files changed, 167 insertions(+), 25 deletions(-)
---
diff --git a/extensions/picasaweb/data/ui/picasa-web-account-properties.ui b/extensions/picasaweb/data/ui/picasa-web-account-properties.ui
index de138f3..1966ef5 100644
--- a/extensions/picasaweb/data/ui/picasa-web-account-properties.ui
+++ b/extensions/picasaweb/data/ui/picasa-web-account-properties.ui
@@ -13,6 +13,38 @@
   <object class="GtkVBox" id="account_properties">
     <property name="visible">True</property>
     <property name="orientation">vertical</property>
+    <property name="spacing">6</property>
+    <child>
+      <object class="GtkHBox" id="error_box">
+        <property name="visible">True</property>
+        <property name="border_width">12</property>
+        <property name="spacing">24</property>
+        <child>
+          <object class="GtkImage" id="image1">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="pixel_size">48</property>
+            <property name="icon_name">dialog-warning</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="error_label">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="position">0</property>
+      </packing>
+    </child>
     <child>
       <object class="GtkTable" id="table1">
         <property name="visible">True</property>
@@ -136,7 +168,7 @@
       <packing>
         <property name="expand">False</property>
         <property name="fill">False</property>
-        <property name="position">0</property>
+        <property name="position">1</property>
       </packing>
     </child>
   </object>
diff --git a/extensions/picasaweb/dlg-export-to-picasaweb.c b/extensions/picasaweb/dlg-export-to-picasaweb.c
index d9978ef..710e138 100644
--- a/extensions/picasaweb/dlg-export-to-picasaweb.c
+++ b/extensions/picasaweb/dlg-export-to-picasaweb.c
@@ -380,8 +380,10 @@ store_password_done_cb (GnomeKeyringResult result,
 
 
 static void account_properties_dialog (DialogData *data,
-			               const char *email);
-static void challange_account_dialog  (DialogData *data);
+			               const char *email,
+			               GError     *error);
+static void challange_account_dialog  (DialogData *data,
+	        		       GError     *error);
 
 
 static void
@@ -395,10 +397,12 @@ connection_ready_cb (GObject      *source_object,
 
 	if (! google_connection_connect_finish (conn, result, &error)) {
 		if (g_error_matches (error, GOOGLE_CONNECTION_ERROR, GOOGLE_CONNECTION_ERROR_CAPTCHA_REQUIRED)) {
-			challange_account_dialog (data);
+			challange_account_dialog (data, error);
+			g_clear_error (&error);
 		}
 		else if (g_error_matches (error, GOOGLE_CONNECTION_ERROR, GOOGLE_CONNECTION_ERROR_BAD_AUTHENTICATION)) {
-			account_properties_dialog (data, data->email);
+			account_properties_dialog (data, data->email, error);
+			g_clear_error (&error);
 		}
 		else {
 			if (data->conn != NULL)
@@ -434,6 +438,7 @@ connection_ready_cb (GObject      *source_object,
 
 
 static void connect_to_server (DialogData *data);
+static void auto_select_account (DialogData *data);
 
 
 static void
@@ -465,6 +470,13 @@ account_properties_dialog_response_cb (GtkDialog *dialog,
 		connect_to_server (data);
 		break;
 
+	case PICASA_ACCOUNT_PROPERTIES_RESPONSE_CHOOSE:
+		gtk_widget_destroy (GTK_WIDGET (dialog));
+		g_free (data->email);
+		data->email = NULL;
+		auto_select_account (data);
+		break;
+
 	default:
 		break;
 	}
@@ -473,7 +485,8 @@ account_properties_dialog_response_cb (GtkDialog *dialog,
 
 static void
 account_properties_dialog (DialogData *data,
-			   const char *email)
+			   const char *email,
+			   GError     *error)
 {
 	GtkWidget *dialog;
 
@@ -481,6 +494,10 @@ account_properties_dialog (DialogData *data,
 		gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
 
 	dialog = picasa_account_properties_dialog_new (email, NULL, NULL);
+	picasa_account_properties_dialog_set_error (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), error);
+	if ((error != NULL) && (data->accounts != NULL) && (data->accounts->next != NULL))
+		picasa_account_properties_dialog_can_choose (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), TRUE);
+
 	g_signal_connect (dialog,
 			  "response",
 			  G_CALLBACK (account_properties_dialog_response_cb),
@@ -496,9 +513,9 @@ account_properties_dialog (DialogData *data,
 static void
 connect_to_server_step2 (DialogData *data)
 {
-	if (data->password == NULL) {
+	if ((data->password == NULL) || g_str_equal (data->password, "")) {
 		gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
-		account_properties_dialog (data, data->email);
+		account_properties_dialog (data, data->email, NULL);
 	}
 	else {
 		gth_task_dialog (GTH_TASK (data->conn), FALSE, NULL);
@@ -583,6 +600,13 @@ challange_account_dialog_response_cb (GtkDialog *dialog,
 		connect_to_server (data);
 		break;
 
+	case PICASA_ACCOUNT_PROPERTIES_RESPONSE_CHOOSE:
+		gtk_widget_destroy (GTK_WIDGET (dialog));
+		g_free (data->email);
+		data->email = NULL;
+		auto_select_account (data);
+		break;
+
 	default:
 		break;
 	}
@@ -590,11 +614,19 @@ challange_account_dialog_response_cb (GtkDialog *dialog,
 
 
 static void
-challange_account_dialog (DialogData *data)
+challange_account_dialog (DialogData *data,
+			  GError     *error)
 {
 	GtkWidget *dialog;
 
+	if (data->conn != NULL)
+		gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
+
 	dialog = picasa_account_properties_dialog_new (data->email, data->password, google_connection_get_challange_url (data->conn));
+	picasa_account_properties_dialog_set_error (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), error);
+	if ((error != NULL) && (data->accounts != NULL) && (data->accounts->next != NULL))
+		picasa_account_properties_dialog_can_choose (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), TRUE);
+
 	g_signal_connect (dialog,
 			  "response",
 			  G_CALLBACK (challange_account_dialog_response_cb),
@@ -636,7 +668,7 @@ account_chooser_dialog_response_cb (GtkDialog *dialog,
 
 	case PICASA_ACCOUNT_CHOOSER_RESPONSE_NEW:
 		gtk_widget_destroy (GTK_WIDGET (dialog));
-		account_properties_dialog (data, NULL);
+		account_properties_dialog (data, NULL, NULL);
 		break;
 
 	default:
@@ -745,7 +777,8 @@ auto_select_account (DialogData *data)
 		else {
 			GtkWidget *dialog;
 
-			gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
+			if (data->conn != NULL)
+				gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
 			dialog = picasa_account_chooser_dialog_new (data->accounts, data->email);
 			g_signal_connect (dialog,
 					  "response",
@@ -759,7 +792,7 @@ auto_select_account (DialogData *data)
 		}
 	}
 	else
-		account_properties_dialog (data, NULL);
+		account_properties_dialog (data, NULL, NULL);
 }
 
 
@@ -834,7 +867,11 @@ account_combobox_changed_cb (GtkComboBox *widget,
 
 	if (g_strcmp0 (email, data->email) != 0) {
 		g_free (data->email);
+		g_free (data->password);
+		g_free (data->challange);
 		data->email = email;
+		data->password = NULL;
+		data->challange = NULL;
 		auto_select_account (data);
 	}
 	else
diff --git a/extensions/picasaweb/dlg-import-from-picasaweb.c b/extensions/picasaweb/dlg-import-from-picasaweb.c
index 8c763f0..f795814 100644
--- a/extensions/picasaweb/dlg-import-from-picasaweb.c
+++ b/extensions/picasaweb/dlg-import-from-picasaweb.c
@@ -327,8 +327,10 @@ store_password_done_cb (GnomeKeyringResult result,
 
 
 static void account_properties_dialog (DialogData *data,
-			               const char *email);
-static void challange_account_dialog  (DialogData *data);
+			               const char *email,
+			               GError     *error);
+static void challange_account_dialog  (DialogData *data,
+	               	       	       GError     *error);
 
 
 static void
@@ -342,10 +344,12 @@ connection_ready_cb (GObject      *source_object,
 
 	if (! google_connection_connect_finish (conn, result, &error)) {
 		if (g_error_matches (error, GOOGLE_CONNECTION_ERROR, GOOGLE_CONNECTION_ERROR_CAPTCHA_REQUIRED)) {
-			challange_account_dialog (data);
+			challange_account_dialog (data, error);
+			g_clear_error (&error);
 		}
 		else if (g_error_matches (error, GOOGLE_CONNECTION_ERROR, GOOGLE_CONNECTION_ERROR_BAD_AUTHENTICATION)) {
-			account_properties_dialog (data, data->email);
+			account_properties_dialog (data, data->email, error);
+			g_clear_error (&error);
 		}
 		else {
 			if (data->conn != NULL)
@@ -381,6 +385,7 @@ connection_ready_cb (GObject      *source_object,
 
 
 static void connect_to_server (DialogData *data);
+static void auto_select_account (DialogData *data);
 
 
 static void
@@ -412,6 +417,13 @@ account_properties_dialog_response_cb (GtkDialog *dialog,
 		connect_to_server (data);
 		break;
 
+	case PICASA_ACCOUNT_PROPERTIES_RESPONSE_CHOOSE:
+		gtk_widget_destroy (GTK_WIDGET (dialog));
+		g_free (data->email);
+		data->email = NULL;
+		auto_select_account (data);
+		break;
+
 	default:
 		break;
 	}
@@ -420,7 +432,8 @@ account_properties_dialog_response_cb (GtkDialog *dialog,
 
 static void
 account_properties_dialog (DialogData *data,
-			   const char *email)
+			   const char *email,
+			   GError     *error)
 {
 	GtkWidget *dialog;
 
@@ -428,6 +441,10 @@ account_properties_dialog (DialogData *data,
 		gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
 
 	dialog = picasa_account_properties_dialog_new (email, NULL, NULL);
+	picasa_account_properties_dialog_set_error (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), error);
+	if ((error != NULL) && (data->accounts != NULL) && (data->accounts->next != NULL))
+		picasa_account_properties_dialog_can_choose (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), TRUE);
+
 	g_signal_connect (dialog,
 			  "response",
 			  G_CALLBACK (account_properties_dialog_response_cb),
@@ -443,9 +460,9 @@ account_properties_dialog (DialogData *data,
 static void
 connect_to_server_step2 (DialogData *data)
 {
-	if (data->password == NULL) {
+	if ((data->password == NULL) || g_str_equal (data->password, "")) {
 		gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
-		account_properties_dialog (data, data->email);
+		account_properties_dialog (data, data->email, NULL);
 	}
 	else {
 		gth_task_dialog (GTH_TASK (data->conn), FALSE, NULL);
@@ -530,6 +547,13 @@ challange_account_dialog_response_cb (GtkDialog *dialog,
 		connect_to_server (data);
 		break;
 
+	case PICASA_ACCOUNT_PROPERTIES_RESPONSE_CHOOSE:
+		gtk_widget_destroy (GTK_WIDGET (dialog));
+		g_free (data->email);
+		data->email = NULL;
+		auto_select_account (data);
+		break;
+
 	default:
 		break;
 	}
@@ -537,11 +561,16 @@ challange_account_dialog_response_cb (GtkDialog *dialog,
 
 
 static void
-challange_account_dialog (DialogData *data)
+challange_account_dialog (DialogData *data,
+			  GError     *error)
 {
 	GtkWidget *dialog;
 
 	dialog = picasa_account_properties_dialog_new (data->email, data->password, google_connection_get_challange_url (data->conn));
+	picasa_account_properties_dialog_set_error (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), error);
+	if ((error != NULL) && (data->accounts != NULL) && (data->accounts->next != NULL))
+		picasa_account_properties_dialog_can_choose (PICASA_ACCOUNT_PROPERTIES_DIALOG (dialog), TRUE);
+
 	g_signal_connect (dialog,
 			  "response",
 			  G_CALLBACK (challange_account_dialog_response_cb),
@@ -583,7 +612,7 @@ account_chooser_dialog_response_cb (GtkDialog *dialog,
 
 	case PICASA_ACCOUNT_CHOOSER_RESPONSE_NEW:
 		gtk_widget_destroy (GTK_WIDGET (dialog));
-		account_properties_dialog (data, NULL);
+		account_properties_dialog (data, NULL, NULL);
 		break;
 
 	default:
@@ -608,6 +637,8 @@ auto_select_account (DialogData *data)
 		else {
 			GtkWidget *dialog;
 
+			if (data->conn != NULL)
+				gth_task_dialog (GTH_TASK (data->conn), TRUE, NULL);
 			dialog = picasa_account_chooser_dialog_new (data->accounts, data->email);
 			g_signal_connect (dialog,
 					  "response",
@@ -621,7 +652,7 @@ auto_select_account (DialogData *data)
 		}
 	}
 	else
-		account_properties_dialog (data, NULL);
+		account_properties_dialog (data, NULL, NULL);
 }
 
 
@@ -696,7 +727,11 @@ account_combobox_changed_cb (GtkComboBox *widget,
 
 	if (g_strcmp0 (email, data->email) != 0) {
 		g_free (data->email);
+		g_free (data->password);
+		g_free (data->challange);
 		data->email = email;
+		data->password = NULL;
+		data->challange = NULL;
 		auto_select_account (data);
 	}
 	else
diff --git a/extensions/picasaweb/picasa-account-properties-dialog.c b/extensions/picasaweb/picasa-account-properties-dialog.c
index 744d08e..f6f0f34 100644
--- a/extensions/picasaweb/picasa-account-properties-dialog.c
+++ b/extensions/picasaweb/picasa-account-properties-dialog.c
@@ -84,6 +84,7 @@ picasa_account_properties_dialog_init (PicasaAccountPropertiesDialog *self)
 
 	gtk_dialog_add_buttons (GTK_DIALOG (self),
 				GTK_STOCK_HELP, GTK_RESPONSE_HELP,
+				_("Other..."), PICASA_ACCOUNT_PROPERTIES_RESPONSE_CHOOSE,
 				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 				GTK_STOCK_OK, GTK_RESPONSE_OK,
 				NULL);
@@ -148,9 +149,9 @@ image_buffer_ready_cb (void     **buffer,
 
 static void
 picasa_account_properties_dialog_construct (PicasaAccountPropertiesDialog *self,
-					    const char                 *email,
-					    const char                 *password,
-					    const char                 *challange_url)
+					    const char                    *email,
+					    const char                    *password,
+					    const char                    *challange_url)
 {
 	if (email != NULL)
 		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("email_entry")), email);
@@ -181,6 +182,8 @@ picasa_account_properties_dialog_construct (PicasaAccountPropertiesDialog *self,
 	else
 		gtk_widget_grab_focus (GET_WIDGET ("challenge_entry"));
 
+	gtk_widget_hide (GET_WIDGET ("error_box"));
+	picasa_account_properties_dialog_can_choose (PICASA_ACCOUNT_PROPERTIES_DIALOG (self), FALSE);
 }
 
 
@@ -198,6 +201,35 @@ picasa_account_properties_dialog_new (const char *email,
 }
 
 
+void
+picasa_account_properties_dialog_can_choose (PicasaAccountPropertiesDialog *self,
+					     gboolean                       can_choose)
+{
+	GtkWidget *button;
+
+	button = gtk_dialog_get_widget_for_response (GTK_DIALOG (self), PICASA_ACCOUNT_PROPERTIES_RESPONSE_CHOOSE);
+	if (can_choose)
+		gtk_widget_show (button);
+	else
+		gtk_widget_hide (button);
+}
+
+
+void
+picasa_account_properties_dialog_set_error (PicasaAccountPropertiesDialog *self,
+					    GError                        *error)
+{
+	if (error == NULL) {
+		gtk_widget_hide (GET_WIDGET ("error_box"));
+		return;
+	}
+
+	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("error_label")), error->message);
+	gtk_widget_show (GET_WIDGET ("error_box"));
+}
+
+
+
 const char *
 picasa_account_properties_dialog_get_email (PicasaAccountPropertiesDialog *self)
 {
diff --git a/extensions/picasaweb/picasa-account-properties-dialog.h b/extensions/picasaweb/picasa-account-properties-dialog.h
index 8afa681..3d13f59 100644
--- a/extensions/picasaweb/picasa-account-properties-dialog.h
+++ b/extensions/picasaweb/picasa-account-properties-dialog.h
@@ -27,6 +27,8 @@
 
 G_BEGIN_DECLS
 
+#define PICASA_ACCOUNT_PROPERTIES_RESPONSE_CHOOSE 1
+
 #define PICASA_TYPE_ACCOUNT_PROPERTIES_DIALOG            (picasa_account_properties_dialog_get_type ())
 #define PICASA_ACCOUNT_PROPERTIES_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), PICASA_TYPE_ACCOUNT_PROPERTIES_DIALOG, PicasaAccountPropertiesDialog))
 #define PICASA_ACCOUNT_PROPERTIES_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), PICASA_TYPE_ACCOUNT_PROPERTIES_DIALOG, PicasaAccountPropertiesDialogClass))
@@ -51,6 +53,10 @@ GType          picasa_account_properties_dialog_get_type      (void);
 GtkWidget *    picasa_account_properties_dialog_new           (const char *email,
 							       const char *password,
 							       const char *challange);
+void           picasa_account_properties_dialog_can_choose    (PicasaAccountPropertiesDialog *self,
+		       	       	       	       	       	       gboolean                       can_choose);
+void           picasa_account_properties_dialog_set_error     (PicasaAccountPropertiesDialog *self,
+							       GError                        *error);
 const char *   picasa_account_properties_dialog_get_email     (PicasaAccountPropertiesDialog *self);
 const char *   picasa_account_properties_dialog_get_password  (PicasaAccountPropertiesDialog *self);
 const char *   picasa_account_properties_dialog_get_challange (PicasaAccountPropertiesDialog *self);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]