Merge lp:~tiagosh/telepathy-ofono/use-accounts-service into lp:telepathy-ofono

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 172
Merged at revision: 171
Proposed branch: lp:~tiagosh/telepathy-ofono/use-accounts-service
Merge into: lp:telepathy-ofono
Diff against target: 131 lines (+53/-51)
1 file modified
mc-plugin/mcp-account-manager-ofono.c (+53/-51)
To merge this branch: bzr merge lp:~tiagosh/telepathy-ofono/use-accounts-service
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Needs Fixing
Review via email: mp+289539@code.launchpad.net

Commit message

Use accounts service to get the sim names.

Description of the change

Use accounts service to get the sim names.

To post a comment you must log in.
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

There is a couple things to fix in the code.

review: Needs Fixing
172. By Tiago Salem Herrmann

Fix logic and use new glib dbus api

Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

> There is a couple things to fix in the code.

all fixed.

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Just one more thing to fix.

review: Needs Fixing
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

> Just one more thing to fix.

The previous comment was wrong, the MR is ready to go.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'mc-plugin/mcp-account-manager-ofono.c'
--- mc-plugin/mcp-account-manager-ofono.c 2015-07-08 20:01:30 +0000
+++ mc-plugin/mcp-account-manager-ofono.c 2016-03-24 17:12:16 +0000
@@ -106,11 +106,49 @@
106 }106 }
107 }107 }
108108
109 GSettings *settings = NULL;109 GHashTable *sim_names = g_hash_table_new(g_str_hash, g_str_equal);
110 GSettingsSchemaSource *source = g_settings_schema_source_get_default();110 char dbus_path[80] = {0};
111 if (source != NULL && g_settings_schema_source_lookup(source, "com.ubuntu.phone", TRUE) != NULL) {111 sprintf(dbus_path, "/org/freedesktop/Accounts/User%d", getuid());
112 settings = g_settings_new("com.ubuntu.phone");112 GError *bus_error = NULL;
113 GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &bus_error);
114 if (bus_error) {
115 g_warning("Failed to get system bugs: %s", bus_error->message);
116 g_error_free (bus_error);
117 } else if (bus) {
118 GError *call_error = NULL;
119
120 /* Retrieve all SimNames from Accounts Service */
121 GVariant *result = g_dbus_connection_call_sync (bus,
122 "org.freedesktop.Accounts",
123 dbus_path,
124 "org.freedesktop.DBus.Properties",
125 "Get",
126 g_variant_new ("(ss)", "com.ubuntu.touch.AccountsService.Phone", "SimNames"),
127 G_VARIANT_TYPE ("(v)"),
128 G_DBUS_CALL_FLAGS_NONE,
129 -1,
130 NULL,
131 &call_error);
132
133
134 if (call_error) {
135 g_warning ("Failed to get SimNames property: %s", call_error->message);
136 g_error_free (call_error);
137 } else {
138 GVariantIter *_iter;
139 gchar *key;
140 gchar *value;
141 GVariant *dict;
142 g_variant_get (result, "(v)", &dict);
143 g_variant_get(dict, "a{ss}", &_iter);
144 while (g_variant_iter_loop (_iter, "{ss}", &key, &value)) {
145 g_hash_table_insert(sim_names, g_strdup(key), g_strdup(value));
146 }
147 g_variant_iter_free(_iter);
148 }
149 g_object_unref(bus);
113 }150 }
151
114 for (index = 0; index < num_modems; index++) {152 for (index = 0; index < num_modems; index++) {
115 OfonoAccount *account = (OfonoAccount*)malloc(sizeof(OfonoAccount));153 OfonoAccount *account = (OfonoAccount*)malloc(sizeof(OfonoAccount));
116 char account_name[30] = {0};154 char account_name[30] = {0};
@@ -126,62 +164,26 @@
126 g_hash_table_insert(account->params, g_strdup("ConnectAutomatically"), g_strdup("true"));164 g_hash_table_insert(account->params, g_strdup("ConnectAutomatically"), g_strdup("true"));
127 g_hash_table_insert(account->params, g_strdup("always_dispatch"), g_strdup("true"));165 g_hash_table_insert(account->params, g_strdup("always_dispatch"), g_strdup("true"));
128 g_hash_table_insert(account->params, g_strdup("param-modem-objpath"), g_strdup(ril_modem));166 g_hash_table_insert(account->params, g_strdup("param-modem-objpath"), g_strdup(ril_modem));
129 if (settings) {
130 GVariant *sim_names = g_settings_get_value(settings, "sim-names");
131 if (sim_names) {
132 GVariantIter iter;
133 GVariant *value;
134 GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
135 gchar *key;
136 int found = 0;
137167
138 g_variant_iter_init (&iter, sim_names);168 GHashTableIter iter;
139 while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {169 gpointer key, value;
140 g_variant_builder_add(builder, "(ss)", key, value);170 g_hash_table_iter_init(&iter, sim_names);
141 if (!strcmp(key, ril_modem)) {171 while (g_hash_table_iter_next(&iter, &key, &value)) {
142 g_hash_table_insert(account->params, g_strdup("DisplayName"), g_strdup((char *)value));172 if (!strcmp((char *)key, ril_modem)) {
143 found = 1;173 g_hash_table_insert(account->params, g_strdup("DisplayName"), g_strdup((char*)value));
144 }174 break;
145 g_free (key);
146 g_free (value);
147 }
148 if (!found) {
149 char *sim_name = dgettext("telephony-service", "SIM %1");
150 char *final_sim_name = NULL;
151 char sim_index[10] = {0};
152 const char *placeholder = "%1";
153 sprintf(sim_index, "%d", index+1);
154 const char *pos = strstr(sim_name, placeholder);
155 if (pos) {
156 // this is used to replace %1 by the actual index
157 // FIXME: change telephony-service's string to %d to make everything easier
158 final_sim_name = calloc(1, strlen(sim_name) - strlen(placeholder) + strlen(sim_index) + 1);
159 strncpy(final_sim_name, sim_name, pos - sim_name);
160 strcat(final_sim_name, sim_index);
161 strcat(final_sim_name, pos + strlen(placeholder));
162 } else {
163 final_sim_name = strdup(sim_name);
164 }
165
166 g_hash_table_insert(account->params, g_strdup("DisplayName"), g_strdup(final_sim_name));
167 g_settings_set_value(settings, "sim-names", g_variant_new("a(ss)", builder));
168 free(final_sim_name);
169 }
170 g_variant_builder_unref(builder);
171 }
172 if (sim_names) {
173 g_variant_unref(sim_names);
174 }175 }
175 }176 }
176177
177 self->priv->accounts = g_list_append(self->priv->accounts, account);178 self->priv->accounts = g_list_append(self->priv->accounts, account);
178 }179 }
179 if (settings) {180
180 g_object_unref (settings);181 g_hash_table_unref(sim_names);
181 }182
182 if (output) {183 if (output) {
183 g_free(output);184 g_free(output);
184 }185 }
186
185 if (output2) {187 if (output2) {
186 g_free (output2);188 g_free (output2);
187 }189 }

Subscribers

People subscribed via source and target branches