[network-manager-applet/aleksander/mobile-providers: 4/9] libnm-gtk, mobile-providers: make all types opaque



commit 9f530e4cf1978d1b8a3d1e71712a4c8976d2377b
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Fri Nov 23 12:28:37 2012 +0100

    libnm-gtk,mobile-providers: make all types opaque
    
    All types defined in the mobile provider parsing code are now opaque, in case we
    need to update them in the future.
    
    'NMAGsmMccMnc' is the only one which is left with the members public, as it is
    not really likely to be modified in the current format. The last update w.r.t
    MCC/MNC was to introduce explicit leading '0's in the MNC, which we can cover
    with the current format as it is expressed as a string instead of an integer.

 src/applet-device-cdma.c            |    6 +-
 src/applet-device-gsm.c             |    8 +-
 src/libnm-gtk/nm-mobile-providers.c |  159 +++++++++++++++++++++++++++++++++++
 src/libnm-gtk/nm-mobile-providers.h |   49 +++--------
 src/libnm-gtk/nm-mobile-wizard.c    |   54 ++++++------
 5 files changed, 209 insertions(+), 67 deletions(-)
---
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index ba75351..f081256 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -730,9 +730,11 @@ find_provider_for_sid (GHashTable *table, guint32 sid)
 			NMAMobileProvider *provider = piter->data;
 
 			/* Search through CDMA SID list */
-			for (siter = provider->cdma_sid; siter; siter = g_slist_next (siter)) {
+			for (siter = nma_mobile_provider_get_cdma_sid (provider);
+			     siter;
+			     siter = g_slist_next (siter)) {
 				if (GPOINTER_TO_UINT (siter->data) == sid) {
-					name = g_strdup (provider->name);
+					name = g_strdup (nma_mobile_provider_get_name (provider));
 					break;
 				}
 			}
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 500111b..0b36a32 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -1120,7 +1120,9 @@ find_provider_for_mcc_mnc (GHashTable *table, const char *mccmnc)
 			NMAMobileProvider *provider = piter->data;
 
 			/* Search through MCC/MNC list */
-			for (siter = provider->gsm_mcc_mnc; siter; siter = g_slist_next (siter)) {
+			for (siter = nma_mobile_provider_get_gsm_mcc_mnc (provider);
+			     siter;
+			     siter = g_slist_next (siter)) {
 				NMAGsmMccMnc *mcc = siter->data;
 
 				/* Match both 2-digit and 3-digit MNC; prefer a
@@ -1132,11 +1134,11 @@ find_provider_for_mcc_mnc (GHashTable *table, const char *mccmnc)
 				if (   !name3
 				    && (strlen (mccmnc) == 6)
 				    && !strncmp (mccmnc + 3, mcc->mnc, 3))
-					name3 = provider->name;
+					name3 = nma_mobile_provider_get_name (provider);
 
 				if (   !name2
 				    && !strncmp (mccmnc + 3, mcc->mnc, 2))
-					name2 = provider->name;
+					name2 = nma_mobile_provider_get_name (provider);
 
 				if (name2 && name3) {
 					done = TRUE;
diff --git a/src/libnm-gtk/nm-mobile-providers.c b/src/libnm-gtk/nm-mobile-providers.c
index c1af42b..9fdea77 100644
--- a/src/libnm-gtk/nm-mobile-providers.c
+++ b/src/libnm-gtk/nm-mobile-providers.c
@@ -19,6 +19,7 @@
  * Author: Tambet Ingo (tambet gmail com).
  *
  * Copyright (C) 2009 - 2012 Red Hat, Inc.
+ * Copyright (C) 2012 Lanedo GmbH
  */
 
 #include "config.h"
@@ -80,6 +81,24 @@ mcc_mnc_free (NMAGsmMccMnc *m)
 /******************************************************************************/
 /* Access method type */
 
+struct _NMAMobileAccessMethod {
+    char *name;
+    /* maps lang (char *) -> name (char *) */
+    GHashTable *lcl_names;
+
+    char *username;
+    char *password;
+    char *gateway;
+    GSList *dns; /* GSList of 'char *' */
+
+    /* Only used with NMA_PROVIDER_TYPE_GSM */
+    char *gsm_apn;
+
+    NMAMobileAccessMethodType type;
+
+    gint refs;
+};
+
 static NMAMobileAccessMethod *
 access_method_new (void)
 {
@@ -125,6 +144,97 @@ nma_mobile_access_method_unref (NMAMobileAccessMethod *method)
     }
 }
 
+/**
+ * nma_mobile_access_method_get_name:
+ *
+ * Returns: (transfer none): the name of the method.
+ */
+const gchar *
+nma_mobile_access_method_get_name (NMAMobileAccessMethod *method)
+{
+    g_return_val_if_fail (method != NULL, NULL);
+
+    return method->name;
+}
+
+/**
+ * nma_mobile_access_method_get_username:
+ *
+ * Returns: (transfer none): the username.
+ */
+const gchar *
+nma_mobile_access_method_get_username (NMAMobileAccessMethod *method)
+{
+    g_return_val_if_fail (method != NULL, NULL);
+
+    return method->username;
+}
+
+/**
+ * nma_mobile_access_method_get_password:
+ *
+ * Returns: (transfer none): the password.
+ */
+const gchar *
+nma_mobile_access_method_get_password (NMAMobileAccessMethod *method)
+{
+    g_return_val_if_fail (method != NULL, NULL);
+
+    return method->password;
+}
+
+/**
+ * nma_mobile_access_method_get_gateway:
+ *
+ * Returns: (transfer none): the gateway.
+ */
+const gchar *
+nma_mobile_access_method_get_gateway (NMAMobileAccessMethod *method)
+{
+    g_return_val_if_fail (method != NULL, NULL);
+
+    return method->gateway;
+}
+
+/**
+ * nma_mobile_access_method_get_dns:
+ *
+ * Returns: (element-type utf8) (transfer none): the list of DNS.
+ */
+const GSList *
+nma_mobile_access_method_get_dns (NMAMobileAccessMethod *method)
+{
+    g_return_val_if_fail (method != NULL, NULL);
+
+    return method->dns;
+}
+
+/**
+ * nma_mobile_access_method_get_gsm_apn:
+ *
+ * Returns: (transfer none): the GSM APN.
+ */
+const gchar *
+nma_mobile_access_method_get_gsm_apn (NMAMobileAccessMethod *method)
+{
+    g_return_val_if_fail (method != NULL, NULL);
+
+    return method->gsm_apn;
+}
+
+/**
+ * nma_mobile_access_method_get_method_type:
+ *
+ * Returns: a #NMAMobileAccessMethodType.
+ */
+NMAMobileAccessMethodType
+nma_mobile_access_method_get_method_type (NMAMobileAccessMethod *method)
+{
+    g_return_val_if_fail (method != NULL, NMA_MOBILE_ACCESS_METHOD_TYPE_UNKNOWN);
+
+    return method->type;
+}
+
 GType
 nma_mobile_access_method_get_type (void)
 {
@@ -141,6 +251,19 @@ nma_mobile_access_method_get_type (void)
 /******************************************************************************/
 /* Mobile provider type */
 
+struct _NMAMobileProvider {
+    char *name;
+    /* maps lang (char *) -> name (char *) */
+    GHashTable *lcl_names;
+
+    GSList *methods; /* GSList of NmaMobileAccessMethod */
+
+    GSList *gsm_mcc_mnc; /* GSList of NmaGsmMccMnc */
+    GSList *cdma_sid; /* GSList of guint32 */
+
+    gint refs;
+};
+
 static NMAMobileProvider *
 provider_new (void)
 {
@@ -183,6 +306,34 @@ nma_mobile_provider_unref (NMAMobileProvider *provider)
 }
 
 /**
+ * nma_mobile_provider_get_name:
+ *
+ * Returns: (transfer none): the name of the provider.
+ */
+const gchar *
+nma_mobile_provider_get_name (NMAMobileProvider *provider)
+{
+    g_return_val_if_fail (provider != NULL, NULL);
+
+    return provider->name;
+}
+
+/**
+ * nma_mobile_provider_get_methods:
+ * @provider: a #NMAMobileProvider
+ *
+ * Returns: (element-type NMGtk.MobileAccessMethod) (transfer none): the
+ *   list of #NMAMobileAccessMethod this provider exposes.
+ */
+GSList *
+nma_mobile_provider_get_methods (NMAMobileProvider *provider)
+{
+    g_return_val_if_fail (provider != NULL, NULL);
+
+    return provider->methods;
+}
+
+/**
  * nma_mobile_provider_get_gsm_mcc_mnc:
  * @provider: a #NMAMobileProvider
  *
@@ -228,6 +379,14 @@ nma_mobile_provider_get_type (void)
 /******************************************************************************/
 /* Country Info type */
 
+struct _NMACountryInfo {
+    char *country_code;
+    char *country_name;
+    GSList *providers;
+
+    gint refs;
+};
+
 static NMACountryInfo *
 country_info_new (const char *country_code,
                   const gchar *country_name)
diff --git a/src/libnm-gtk/nm-mobile-providers.h b/src/libnm-gtk/nm-mobile-providers.h
index fbe4bb9..0e9d9e4 100644
--- a/src/libnm-gtk/nm-mobile-providers.h
+++ b/src/libnm-gtk/nm-mobile-providers.h
@@ -19,6 +19,7 @@
  * Author: Tambet Ingo (tambet gmail com).
  *
  * Copyright (C) 2009 - 2012 Red Hat, Inc.
+ * Copyright (C) 2012 Lanedo GmbH.
  */
 
 /* WARNING: this file is private API between nm-applet and various GNOME
@@ -54,49 +55,31 @@ typedef enum {
 
 #define NMA_TYPE_MOBILE_ACCESS_METHOD (nma_mobile_access_method_get_type ())
 
-typedef struct {
-    char *name;
-    /* maps lang (char *) -> name (char *) */
-    GHashTable *lcl_names;
-
-    char *username;
-    char *password;
-    char *gateway;
-    GSList *dns; /* GSList of 'char *' */
-
-    /* Only used with NMA_PROVIDER_TYPE_GSM */
-    char *gsm_apn;
-
-    NMAMobileAccessMethodType type;
-
-    gint refs;
-} NMAMobileAccessMethod;
+typedef struct _NMAMobileAccessMethod NMAMobileAccessMethod;
 
 GType                      nma_mobile_access_method_get_type        (void);
 NMAMobileAccessMethod     *nma_mobile_access_method_ref             (NMAMobileAccessMethod *method);
 void                       nma_mobile_access_method_unref           (NMAMobileAccessMethod *method);
+const gchar               *nma_mobile_access_method_get_name        (NMAMobileAccessMethod *method);
+const gchar               *nma_mobile_access_method_get_username    (NMAMobileAccessMethod *method);
+const gchar               *nma_mobile_access_method_get_password    (NMAMobileAccessMethod *method);
+const gchar               *nma_mobile_access_method_get_gateway     (NMAMobileAccessMethod *method);
+const GSList              *nma_mobile_access_method_get_dns         (NMAMobileAccessMethod *method);
+const gchar               *nma_mobile_access_method_get_gsm_apn     (NMAMobileAccessMethod *method);
+NMAMobileAccessMethodType  nma_mobile_access_method_get_method_type (NMAMobileAccessMethod *method);
 
 /******************************************************************************/
 /* Mobile provider type */
 
 #define NMA_TYPE_MOBILE_PROVIDER (nma_mobile_provider_get_type ())
 
-typedef struct {
-    char *name;
-    /* maps lang (char *) -> name (char *) */
-    GHashTable *lcl_names;
-
-    GSList *methods; /* GSList of NmaMobileAccessMethod */
-
-    GSList *gsm_mcc_mnc; /* GSList of NmaGsmMccMnc */
-    GSList *cdma_sid; /* GSList of guint32 */
-
-    gint refs;
-} NMAMobileProvider;
+typedef struct _NMAMobileProvider NMAMobileProvider;
 
 GType              nma_mobile_provider_get_type        (void);
 NMAMobileProvider *nma_mobile_provider_ref             (NMAMobileProvider *provider);
 void               nma_mobile_provider_unref           (NMAMobileProvider *provider);
+const gchar       *nma_mobile_provider_get_name        (NMAMobileProvider *provider);
+GSList            *nma_mobile_provider_get_methods     (NMAMobileProvider *provider);
 GSList            *nma_mobile_provider_get_gsm_mcc_mnc (NMAMobileProvider *provider);
 GSList            *nma_mobile_provider_get_cdma_sid    (NMAMobileProvider *provider);
 
@@ -105,13 +88,7 @@ GSList            *nma_mobile_provider_get_cdma_sid    (NMAMobileProvider *provi
 
 #define NMA_TYPE_COUNTRY_INFO (nma_country_info_get_type ())
 
-typedef struct {
-    char *country_code;
-    char *country_name;
-    GSList *providers;
-
-    gint refs;
-} NMACountryInfo;
+typedef struct _NMACountryInfo NMACountryInfo;
 
 GType           nma_country_info_get_type         (void);
 NMACountryInfo *nma_country_info_ref              (NMACountryInfo *country_info);
diff --git a/src/libnm-gtk/nm-mobile-wizard.c b/src/libnm-gtk/nm-mobile-wizard.c
index e247b38..9fbfa14 100644
--- a/src/libnm-gtk/nm-mobile-wizard.c
+++ b/src/libnm-gtk/nm-mobile-wizard.c
@@ -129,27 +129,29 @@ assistant_closed (GtkButton *button, gpointer user_data)
 	} else {
 		gboolean manual = FALSE;
 
-		wiz_method->provider_name = g_strdup (provider->name);
+		wiz_method->provider_name = g_strdup (nma_mobile_provider_get_name (provider));
 		method = get_selected_method (self, &manual);
 		if (method) {
-			if (method->name)
-				wiz_method->plan_name = g_strdup (method->name);
-			method_type = method->type;
+			method_type = nma_mobile_access_method_get_method_type (method);
+			wiz_method->plan_name = g_strdup (nma_mobile_access_method_get_name (method));
+			wiz_method->username = g_strdup (nma_mobile_access_method_get_username (method));
+			wiz_method->password = g_strdup (nma_mobile_access_method_get_password (method));
 			if (method_type == NMA_MOBILE_ACCESS_METHOD_TYPE_GSM)
-				wiz_method->gsm_apn = g_strdup (method->gsm_apn);
-			wiz_method->username = method->username ? g_strdup (method->username) : NULL;
-			wiz_method->password = method->password ? g_strdup (method->password) : NULL;
+				wiz_method->gsm_apn = g_strdup (nma_mobile_access_method_get_gsm_apn (method));
 		} else {
 			if (self->provider_only_cdma) {
+				GSList *methods;
+
 				method_type = NMA_MOBILE_ACCESS_METHOD_TYPE_CDMA;
+
+				methods = nma_mobile_provider_get_methods (provider);
 				/* Take username and password from the first (only) method for CDMA only provider */
-				if (provider->methods) {
-					method = provider->methods->data;
-					wiz_method->username = method->username ? g_strdup (method->username) : NULL;
-					wiz_method->password = method->password ? g_strdup (method->password) : NULL;
+				if (methods) {
+					method = methods->data;
+					wiz_method->username = g_strdup (nma_mobile_access_method_get_username (method));
+					wiz_method->password = g_strdup (nma_mobile_access_method_get_password (method));
 				}
-			}
-			else {
+			} else {
 				method_type = NMA_MOBILE_ACCESS_METHOD_TYPE_GSM;
 				wiz_method->gsm_apn = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->plan_unlisted_entry)));
 			}
@@ -294,7 +296,7 @@ confirm_prepare (NMAMobileWizard *self)
 	/* Provider */
 	str = g_string_new (NULL);
 	if (provider) {
-		g_string_append (str, provider->name);
+		g_string_append (str, nma_mobile_provider_get_name (provider));
 		nma_mobile_provider_unref (provider);
 	} else {
 		const char *unlisted_provider;
@@ -330,8 +332,8 @@ confirm_prepare (NMAMobileWizard *self)
 		gtk_widget_show (self->confirm_apn);
 
 		if (method) {
-			gtk_label_set_text (GTK_LABEL (self->confirm_plan), method->name);
-			apn = method->gsm_apn;
+			gtk_label_set_text (GTK_LABEL (self->confirm_plan), nma_mobile_access_method_get_name (method));
+			apn = nma_mobile_access_method_get_gsm_apn (method);
 		} else {
 			gtk_label_set_text (GTK_LABEL (self->confirm_plan), _("Unlisted"));
 			apn = gtk_entry_get_text (GTK_ENTRY (self->plan_unlisted_entry));
@@ -410,7 +412,7 @@ plan_combo_changed (NMAMobileWizard *self)
 
 	method = get_selected_method (self, &is_manual);
 	if (method) {
-		gtk_entry_set_text (GTK_ENTRY (self->plan_unlisted_entry), method->gsm_apn);
+		gtk_entry_set_text (GTK_ENTRY (self->plan_unlisted_entry), nma_mobile_access_method_get_gsm_apn (method));
 		gtk_widget_set_sensitive (self->plan_unlisted_entry, FALSE);
 	} else {
 		gtk_entry_set_text (GTK_ENTRY (self->plan_unlisted_entry), "");
@@ -563,18 +565,18 @@ plan_prepare (NMAMobileWizard *self)
 		GSList *iter;
 		guint32 count = 0;
 
-		for (iter = provider->methods; iter; iter = g_slist_next (iter)) {
+		for (iter = nma_mobile_provider_get_methods (provider); iter; iter = g_slist_next (iter)) {
 			NMAMobileAccessMethod *method = iter->data;
 
 			if (   (self->method_type != NMA_MOBILE_ACCESS_METHOD_TYPE_UNKNOWN)
-			    && (method->type != self->method_type))
+			    && (nma_mobile_access_method_get_method_type (method) != self->method_type))
 				continue;
 
 			gtk_tree_store_append (GTK_TREE_STORE (self->plan_store), &method_iter, NULL);
 			gtk_tree_store_set (GTK_TREE_STORE (self->plan_store),
 			                    &method_iter,
 			                    PLAN_COL_NAME,
-			                    method->name,
+			                    nma_mobile_access_method_get_name (method),
 			                    PLAN_COL_METHOD,
 			                    method,
 			                    -1);
@@ -875,10 +877,10 @@ providers_prepare (NMAMobileWizard *self)
 			GSList *miter;
 			guint32 count = 0;
 
-			for (miter = provider->methods; miter; miter = g_slist_next (miter)) {
+			for (miter = nma_mobile_provider_get_methods (provider); miter; miter = g_slist_next (miter)) {
 				NMAMobileAccessMethod *method = miter->data;
 
-				if (self->method_type == method->type)
+				if (self->method_type == nma_mobile_access_method_get_method_type (method))
 					count++;
 			}
 
@@ -890,7 +892,7 @@ providers_prepare (NMAMobileWizard *self)
 		gtk_tree_store_set (GTK_TREE_STORE (self->providers_store),
 		                    &provider_iter,
 		                    PROVIDER_COL_NAME,
-		                    provider->name,
+		                    nma_mobile_provider_get_name (provider),
 		                    PROVIDER_COL_PROVIDER,
 		                    provider,
 		                    -1);
@@ -1550,12 +1552,12 @@ forward_func (gint current_page, gpointer user_data)
 
 			provider = get_selected_provider (self);
 			if (provider) {
-				for (iter = provider->methods; iter; iter = g_slist_next (iter)) {
+				for (iter = nma_mobile_provider_get_methods (provider); iter; iter = g_slist_next (iter)) {
 					NMAMobileAccessMethod *method = iter->data;
 
-					if (method->type == NMA_MOBILE_ACCESS_METHOD_TYPE_CDMA)
+					if (nma_mobile_access_method_get_method_type (method) == NMA_MOBILE_ACCESS_METHOD_TYPE_CDMA)
 						cdma = TRUE;
-					else if (method->type == NMA_MOBILE_ACCESS_METHOD_TYPE_GSM)
+					else if (nma_mobile_access_method_get_method_type (method) == NMA_MOBILE_ACCESS_METHOD_TYPE_GSM)
 						gsm = TRUE;
 				}
 				nma_mobile_provider_unref (provider);



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