[network-manager-applet/aleksander/mobile-providers: 5/19] libnm-gtk: new 'nma_mobile_providers_find_for_mcc_mnc()' method
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/aleksander/mobile-providers: 5/19] libnm-gtk: new 'nma_mobile_providers_find_for_mcc_mnc()' method
- Date: Tue, 27 Nov 2012 20:20:57 +0000 (UTC)
commit 6a24f6813bde2e42b0a05b949eaf22c9c95a7851
Author: Aleksander Morgado <aleksander lanedo com>
Date: Fri Nov 23 13:04:57 2012 +0100
libnm-gtk: new 'nma_mobile_providers_find_for_mcc_mnc()' method
This new method of the API takes care of looking for a specific
'NMAMobileProvider' given a MCC/MNC string.
Originally developed as 'find_provider_for_mcc_mnc()' in
'src/applet-device-gsm.c'.
src/applet-device-gsm.c | 61 ++------------------------------
src/libnm-gtk/nm-mobile-providers.c | 66 +++++++++++++++++++++++++++++++++++
src/libnm-gtk/nm-mobile-providers.h | 8 +++--
3 files changed, 74 insertions(+), 61 deletions(-)
---
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 0b36a32..b46b422 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -1097,65 +1097,9 @@ signal_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
}
static char *
-find_provider_for_mcc_mnc (GHashTable *table, const char *mccmnc)
-{
- GHashTableIter iter;
- gpointer value;
- GSList *piter, *siter;
- const char *name2 = NULL, *name3 = NULL;
- gboolean done = FALSE;
-
- if (!mccmnc)
- return NULL;
-
- g_hash_table_iter_init (&iter, table);
- /* Search through each country */
- while (g_hash_table_iter_next (&iter, NULL, &value) && !done) {
- NMACountryInfo *country_info = value;
-
- /* Search through each country's providers */
- for (piter = nma_country_info_get_providers (country_info);
- piter && !done;
- piter = g_slist_next (piter)) {
- NMAMobileProvider *provider = piter->data;
-
- /* Search through MCC/MNC list */
- 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
- * 3-digit match if found, otherwise a 2-digit one.
- */
- if (strncmp (mcc->mcc, mccmnc, 3))
- continue; /* MCC was wrong */
-
- if ( !name3
- && (strlen (mccmnc) == 6)
- && !strncmp (mccmnc + 3, mcc->mnc, 3))
- name3 = nma_mobile_provider_get_name (provider);
-
- if ( !name2
- && !strncmp (mccmnc + 3, mcc->mnc, 2))
- name2 = nma_mobile_provider_get_name (provider);
-
- if (name2 && name3) {
- done = TRUE;
- break;
- }
- }
- }
- }
-
- if (name3)
- return g_strdup (name3);
- return g_strdup (name2);
-}
-
-static char *
parse_op_name (GsmDeviceInfo *info, const char *orig, const char *op_code)
{
+ NMAMobileProvider *provider;
guint i, orig_len;
/* Some devices return the MCC/MNC if they haven't fully initialized
@@ -1189,7 +1133,8 @@ parse_op_name (GsmDeviceInfo *info, const char *orig, const char *op_code)
if (!info->country_infos)
return strdup (orig);
- return find_provider_for_mcc_mnc (info->country_infos, orig);
+ provider = nma_mobile_providers_find_for_mcc_mnc (info->country_infos, orig);
+ return (provider ? g_strdup (nma_mobile_provider_get_name (provider)) : NULL);
}
static void
diff --git a/src/libnm-gtk/nm-mobile-providers.c b/src/libnm-gtk/nm-mobile-providers.c
index 10899ca..f137582 100644
--- a/src/libnm-gtk/nm-mobile-providers.c
+++ b/src/libnm-gtk/nm-mobile-providers.c
@@ -1096,3 +1096,69 @@ nma_mobile_providers_dump (GHashTable *country_infos)
g_return_if_fail (country_infos != NULL);
g_hash_table_foreach (country_infos, dump_country, NULL);
}
+
+/**
+ * nma_mobile_providers_find_for_mcc_mnc:
+ * @country_infos: (element-type utf8 NMGtk.CountryInfo) (transfer none): the table of country infos.
+ * @mccmnc: the MCC/MNC string to look for.
+ *
+ * Returns: (transfer none): a #NMAMobileProvider.
+ */
+NMAMobileProvider *
+nma_mobile_providers_find_for_mcc_mnc (GHashTable *country_infos,
+ const gchar *mccmnc)
+{
+ GHashTableIter iter;
+ gpointer value;
+ GSList *piter, *siter;
+ NMAMobileProvider *provider_match_2mnc = NULL;
+ NMAMobileProvider *provider_match_3mnc = NULL;
+ gboolean done = FALSE;
+
+ if (!mccmnc)
+ return NULL;
+
+ g_hash_table_iter_init (&iter, country_infos);
+ /* Search through each country */
+ while (g_hash_table_iter_next (&iter, NULL, &value) && !done) {
+ NMACountryInfo *country_info = value;
+
+ /* Search through each country's providers */
+ for (piter = nma_country_info_get_providers (country_info);
+ piter && !done;
+ piter = g_slist_next (piter)) {
+ NMAMobileProvider *provider = piter->data;
+
+ /* Search through MCC/MNC list */
+ 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
+ * 3-digit match if found, otherwise a 2-digit one.
+ */
+ if (strncmp (mcc->mcc, mccmnc, 3))
+ continue; /* MCC was wrong */
+
+ if ( !provider_match_3mnc
+ && (strlen (mccmnc) == 6)
+ && !strncmp (mccmnc + 3, mcc->mnc, 3))
+ provider_match_3mnc = provider;
+
+ if ( !provider_match_2mnc
+ && !strncmp (mccmnc + 3, mcc->mnc, 2))
+ provider_match_2mnc = provider;
+
+ if (provider_match_2mnc && provider_match_3mnc) {
+ done = TRUE;
+ break;
+ }
+ }
+ }
+ }
+
+ if (provider_match_3mnc)
+ return provider_match_3mnc;
+ return provider_match_2mnc;
+}
diff --git a/src/libnm-gtk/nm-mobile-providers.h b/src/libnm-gtk/nm-mobile-providers.h
index 0e9d9e4..50a8cf3 100644
--- a/src/libnm-gtk/nm-mobile-providers.h
+++ b/src/libnm-gtk/nm-mobile-providers.h
@@ -102,8 +102,10 @@ GSList *nma_country_info_get_providers (NMACountryInfo *country_info)
/* Returns a table where keys are country codes and values are NMACountryInfo
* values */
-GHashTable *nma_mobile_providers_parse (const gchar *country_codes,
- const gchar *service_providers);
-void nma_mobile_providers_dump (GHashTable *country_infos);
+GHashTable *nma_mobile_providers_parse (const gchar *country_codes,
+ const gchar *service_providers);
+void nma_mobile_providers_dump (GHashTable *country_infos);
+NMAMobileProvider *nma_mobile_providers_find_for_mcc_mnc (GHashTable *country_infos,
+ const gchar *mccmnc);
#endif /* NM_MOBILE_PROVIDERS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]