[discident-glib] lib: Remove need for _login() function



commit a4152bcc3580d531d84f0f8f3df2804367e7677f
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Dec 3 23:21:04 2012 +0100

    lib: Remove need for _login() function
    
    Just do the login when required.

 discident-glib/discident-ean-glib.c   |   20 ++++++++++----------
 discident-glib/discident-ean-glib.h   |    5 +----
 discident-glib/discident-glib.symbols |    1 -
 discident-glib/test-diglib.c          |    7 -------
 4 files changed, 11 insertions(+), 22 deletions(-)
---
diff --git a/discident-glib/discident-ean-glib.c b/discident-glib/discident-ean-glib.c
index eb66705..ceac94c 100644
--- a/discident-glib/discident-ean-glib.c
+++ b/discident-glib/discident-ean-glib.c
@@ -48,6 +48,7 @@ struct DiscidentEanPrivate {
 	char *server;
 	gboolean enabled;
 	char *message;
+	gboolean login_done;
 };
 
 G_DEFINE_TYPE (DiscidentEan, discident_ean, G_TYPE_OBJECT)
@@ -83,6 +84,7 @@ discident_ean_init (DiscidentEan *ean)
 {
 	ean->priv = G_TYPE_INSTANCE_GET_PRIVATE ((ean), DISCIDENT_TYPE_EAN, DiscidentEanPrivate);
 	ean->priv->enabled = TRUE;
+	ean->priv->login_done = FALSE;
 }
 
 static gboolean
@@ -127,21 +129,14 @@ parse_login_response (DiscidentEan *ean,
 		ean->priv->enabled = FALSE;
 	}
 
+	ean->priv->login_done = TRUE;
+
 	g_hash_table_destroy (hash);
 
 	return TRUE;
 }
 
-/**
- * discident_ean_login_sync:
- * @ean: a #DiscidentEan object representing a query
- * @error: a #GError
- *
- * Log into the EAN lookup web service.
- *
- * Returns: %TRUE on success. %FALSE on failure with @error set.
- **/
-gboolean
+static gboolean
 discident_ean_login_sync (DiscidentEan *ean,
 			  GError      **error)
 {
@@ -292,6 +287,11 @@ discident_ean_lookup_sync (DiscidentEan *ean,
 	g_return_val_if_fail (DISCIDENT_IS_EAN (ean), FALSE);
 	g_return_val_if_fail (title != NULL, FALSE);
 
+	if (ean->priv->login_done == FALSE) {
+		if (discident_ean_login_sync (ean, error) == FALSE)
+			return FALSE;
+	}
+
 	session = soup_session_sync_new_with_options (
 	    SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_GNOME,
 	    NULL);
diff --git a/discident-glib/discident-ean-glib.h b/discident-glib/discident-ean-glib.h
index 2467756..22f6c11 100644
--- a/discident-glib/discident-ean-glib.h
+++ b/discident-glib/discident-ean-glib.h
@@ -59,10 +59,7 @@ typedef struct {
 
 GType         discident_ean_get_type     (void);
 DiscidentEan *discident_ean_new          (void);
-gboolean      discident_ean_login_sync   (DiscidentEan *ean,
-					  GError      **error);
-
-gboolean       discident_ean_lookup_sync (DiscidentEan *ean,
+gboolean      discident_ean_lookup_sync  (DiscidentEan *ean,
 					  const char   *barcode,
 					  char        **title,
 					  char        **img_url,
diff --git a/discident-glib/discident-glib.symbols b/discident-glib/discident-glib.symbols
index e3e91c1..fe877b6 100644
--- a/discident-glib/discident-glib.symbols
+++ b/discident-glib/discident-glib.symbols
@@ -8,6 +8,5 @@ generate_hash
 discident_get_title_for_gtin
 discident_ean_get_type
 discident_ean_new
-discident_ean_login_sync
 discident_ean_lookup_sync
 discident_error_quark
diff --git a/discident-glib/test-diglib.c b/discident-glib/test-diglib.c
index b0a1fa9..52f3742 100644
--- a/discident-glib/test-diglib.c
+++ b/discident-glib/test-diglib.c
@@ -89,7 +89,6 @@ test_ean (void)
 	gboolean ret;
 
 	ean = discident_ean_new ();
-	g_assert (discident_ean_login_sync (ean, NULL) != FALSE);
 
 	/* The Little Book of Stress: Calm is for Wimps, Get Real, Get Stressed */
 	ret = discident_ean_lookup_sync (ean, "9780091865856", &title, &img_url, &error);
@@ -164,12 +163,6 @@ handle_ean (const char *ean)
 	gboolean ret;
 
 	object = discident_ean_new ();
-	if (discident_ean_login_sync (object, &error) == FALSE) {
-		g_message ("Failed to login: %s", error->message);
-		g_object_unref (object);
-		return;
-	}
-
 	ret = discident_ean_lookup_sync (object, ean, &title, &img_url, &error);
 	if (ret == FALSE) {
 		g_message ("discident_ean_lookup_sync() failed with: %s", error->message);



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