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
1=== modified file 'mc-plugin/mcp-account-manager-ofono.c'
2--- mc-plugin/mcp-account-manager-ofono.c 2015-07-08 20:01:30 +0000
3+++ mc-plugin/mcp-account-manager-ofono.c 2016-03-24 17:12:16 +0000
4@@ -106,11 +106,49 @@
5 }
6 }
7
8- GSettings *settings = NULL;
9- GSettingsSchemaSource *source = g_settings_schema_source_get_default();
10- if (source != NULL && g_settings_schema_source_lookup(source, "com.ubuntu.phone", TRUE) != NULL) {
11- settings = g_settings_new("com.ubuntu.phone");
12+ GHashTable *sim_names = g_hash_table_new(g_str_hash, g_str_equal);
13+ char dbus_path[80] = {0};
14+ sprintf(dbus_path, "/org/freedesktop/Accounts/User%d", getuid());
15+ GError *bus_error = NULL;
16+ GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &bus_error);
17+ if (bus_error) {
18+ g_warning("Failed to get system bugs: %s", bus_error->message);
19+ g_error_free (bus_error);
20+ } else if (bus) {
21+ GError *call_error = NULL;
22+
23+ /* Retrieve all SimNames from Accounts Service */
24+ GVariant *result = g_dbus_connection_call_sync (bus,
25+ "org.freedesktop.Accounts",
26+ dbus_path,
27+ "org.freedesktop.DBus.Properties",
28+ "Get",
29+ g_variant_new ("(ss)", "com.ubuntu.touch.AccountsService.Phone", "SimNames"),
30+ G_VARIANT_TYPE ("(v)"),
31+ G_DBUS_CALL_FLAGS_NONE,
32+ -1,
33+ NULL,
34+ &call_error);
35+
36+
37+ if (call_error) {
38+ g_warning ("Failed to get SimNames property: %s", call_error->message);
39+ g_error_free (call_error);
40+ } else {
41+ GVariantIter *_iter;
42+ gchar *key;
43+ gchar *value;
44+ GVariant *dict;
45+ g_variant_get (result, "(v)", &dict);
46+ g_variant_get(dict, "a{ss}", &_iter);
47+ while (g_variant_iter_loop (_iter, "{ss}", &key, &value)) {
48+ g_hash_table_insert(sim_names, g_strdup(key), g_strdup(value));
49+ }
50+ g_variant_iter_free(_iter);
51+ }
52+ g_object_unref(bus);
53 }
54+
55 for (index = 0; index < num_modems; index++) {
56 OfonoAccount *account = (OfonoAccount*)malloc(sizeof(OfonoAccount));
57 char account_name[30] = {0};
58@@ -126,62 +164,26 @@
59 g_hash_table_insert(account->params, g_strdup("ConnectAutomatically"), g_strdup("true"));
60 g_hash_table_insert(account->params, g_strdup("always_dispatch"), g_strdup("true"));
61 g_hash_table_insert(account->params, g_strdup("param-modem-objpath"), g_strdup(ril_modem));
62- if (settings) {
63- GVariant *sim_names = g_settings_get_value(settings, "sim-names");
64- if (sim_names) {
65- GVariantIter iter;
66- GVariant *value;
67- GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
68- gchar *key;
69- int found = 0;
70
71- g_variant_iter_init (&iter, sim_names);
72- while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
73- g_variant_builder_add(builder, "(ss)", key, value);
74- if (!strcmp(key, ril_modem)) {
75- g_hash_table_insert(account->params, g_strdup("DisplayName"), g_strdup((char *)value));
76- found = 1;
77- }
78- g_free (key);
79- g_free (value);
80- }
81- if (!found) {
82- char *sim_name = dgettext("telephony-service", "SIM %1");
83- char *final_sim_name = NULL;
84- char sim_index[10] = {0};
85- const char *placeholder = "%1";
86- sprintf(sim_index, "%d", index+1);
87- const char *pos = strstr(sim_name, placeholder);
88- if (pos) {
89- // this is used to replace %1 by the actual index
90- // FIXME: change telephony-service's string to %d to make everything easier
91- final_sim_name = calloc(1, strlen(sim_name) - strlen(placeholder) + strlen(sim_index) + 1);
92- strncpy(final_sim_name, sim_name, pos - sim_name);
93- strcat(final_sim_name, sim_index);
94- strcat(final_sim_name, pos + strlen(placeholder));
95- } else {
96- final_sim_name = strdup(sim_name);
97- }
98-
99- g_hash_table_insert(account->params, g_strdup("DisplayName"), g_strdup(final_sim_name));
100- g_settings_set_value(settings, "sim-names", g_variant_new("a(ss)", builder));
101- free(final_sim_name);
102- }
103- g_variant_builder_unref(builder);
104- }
105- if (sim_names) {
106- g_variant_unref(sim_names);
107+ GHashTableIter iter;
108+ gpointer key, value;
109+ g_hash_table_iter_init(&iter, sim_names);
110+ while (g_hash_table_iter_next(&iter, &key, &value)) {
111+ if (!strcmp((char *)key, ril_modem)) {
112+ g_hash_table_insert(account->params, g_strdup("DisplayName"), g_strdup((char*)value));
113+ break;
114 }
115 }
116
117 self->priv->accounts = g_list_append(self->priv->accounts, account);
118 }
119- if (settings) {
120- g_object_unref (settings);
121- }
122+
123+ g_hash_table_unref(sim_names);
124+
125 if (output) {
126 g_free(output);
127 }
128+
129 if (output2) {
130 g_free (output2);
131 }

Subscribers

People subscribed via source and target branches