summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-11-23 13:38:27 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-12-04 18:12:15 +0100
commit16d2224861be824daa5dffd19d173b18e88b6cea (patch)
treedb0ac00b8607ad6bbaa7d6b6247cc5e1f5309925
parentb6d526f75944583b9d81c8041369fd0cf29c75af (diff)
downloadnetwork-manager-applet-16d2224861be824daa5dffd19d173b18e88b6cea.tar.gz
libnm-gtk: new 'nma_mobile_providers_find_for_sid()' method
This new method of the API takes care of looking for a specific 'NMAMobileProvider' given a SID integer. Originally developed as 'find_provider_for_sid()' in 'src/applet-device-cdma.c'.
-rw-r--r--src/applet-device-cdma.c46
-rw-r--r--src/libnm-gtk/nm-mobile-providers.c42
-rw-r--r--src/libnm-gtk/nm-mobile-providers.h2
3 files changed, 51 insertions, 39 deletions
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index f081256b..cfec8478 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -707,43 +707,6 @@ signal_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
#define SERVING_SYSTEM_TYPE (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))
-static char *
-find_provider_for_sid (GHashTable *table, guint32 sid)
-{
- GHashTableIter iter;
- gpointer value;
- GSList *piter, *siter;
- char *name = NULL;
-
- if (sid == 0)
- return NULL;
-
- g_hash_table_iter_init (&iter, table);
- /* Search through each country */
- while (g_hash_table_iter_next (&iter, NULL, &value) && !name) {
- NMACountryInfo *country_info = value;
-
- /* Search through each country's providers */
- for (piter = nma_country_info_get_providers (country_info);
- piter && !name;
- piter = g_slist_next (piter)) {
- NMAMobileProvider *provider = piter->data;
-
- /* Search through CDMA SID list */
- 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 (nma_mobile_provider_get_name (provider));
- break;
- }
- }
- }
- }
-
- return name;
-}
-
static void
serving_system_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
{
@@ -768,9 +731,14 @@ serving_system_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_dat
if (new_sid && (new_sid != info->sid)) {
info->sid = new_sid;
if (info->country_infos) {
+ NMAMobileProvider *provider;
+
g_free (info->provider_name);
- info->provider_name = NULL;
- info->provider_name = find_provider_for_sid (info->country_infos, new_sid);
+
+ provider = nma_mobile_providers_find_for_sid (info->country_infos, new_sid);
+ info->provider_name = (provider ?
+ g_strdup (nma_mobile_provider_get_name (provider)) :
+ NULL);
}
} else if (!new_sid) {
info->sid = 0;
diff --git a/src/libnm-gtk/nm-mobile-providers.c b/src/libnm-gtk/nm-mobile-providers.c
index aeadb2d8..c4b25b8d 100644
--- a/src/libnm-gtk/nm-mobile-providers.c
+++ b/src/libnm-gtk/nm-mobile-providers.c
@@ -1156,3 +1156,45 @@ nma_mobile_providers_find_for_mcc_mnc (GHashTable *country_infos,
return provider_match_2mnc;
}
+
+/**
+ * nma_mobile_providers_find_for_sid:
+ * @country_infos: (element-type utf8 NMGtk.CountryInfo) (transfer none): the table of country infos.
+ * @sid: the SID to look for.
+ *
+ * Returns: (transfer none): a #NMAMobileProvider.
+ */
+NMAMobileProvider *
+nma_mobile_providers_find_for_sid (GHashTable *country_infos,
+ guint32 sid)
+{
+ GHashTableIter iter;
+ gpointer value;
+ GSList *piter, *siter;
+
+ if (sid == 0)
+ return NULL;
+
+ g_hash_table_iter_init (&iter, country_infos);
+ /* Search through each country */
+ while (g_hash_table_iter_next (&iter, NULL, &value)) {
+ NMACountryInfo *country_info = value;
+
+ /* Search through each country's providers */
+ for (piter = nma_country_info_get_providers (country_info);
+ piter;
+ piter = g_slist_next (piter)) {
+ NMAMobileProvider *provider = piter->data;
+
+ /* Search through CDMA SID list */
+ for (siter = nma_mobile_provider_get_cdma_sid (provider);
+ siter;
+ siter = g_slist_next (siter)) {
+ if (GPOINTER_TO_UINT (siter->data) == sid)
+ return provider;
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/src/libnm-gtk/nm-mobile-providers.h b/src/libnm-gtk/nm-mobile-providers.h
index 50a8cf30..98febc25 100644
--- a/src/libnm-gtk/nm-mobile-providers.h
+++ b/src/libnm-gtk/nm-mobile-providers.h
@@ -107,5 +107,7 @@ GHashTable *nma_mobile_providers_parse (const gchar *country_c
void nma_mobile_providers_dump (GHashTable *country_infos);
NMAMobileProvider *nma_mobile_providers_find_for_mcc_mnc (GHashTable *country_infos,
const gchar *mccmnc);
+NMAMobileProvider *nma_mobile_providers_find_for_sid (GHashTable *country_infos,
+ guint32 sid);
#endif /* NM_MOBILE_PROVIDERS_H */