~mterry/indicator-application/gdbus

« back to all changes in this revision

Viewing changes to src/application-service-appstore.c

  • Committer: Michael Terry
  • Date: 2011-01-13 15:09:47 UTC
  • Revision ID: mike@mterry.name-20110113150947-he4vwf5abfs1luo4
watch for name change, instead of name owner change for approver connections

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
        ApplicationServiceAppstore * appstore; /* not ref'd */
80
80
        GCancellable * proxy_cancel;
81
81
        GDBusProxy * proxy;
 
82
        guint name_watcher;
82
83
};
83
84
 
84
85
typedef struct _Application Application;
1155
1156
        ApplicationServiceAppstore * appstore = APPLICATION_SERVICE_APPSTORE(user_data);
1156
1157
        g_list_foreach(appstore->priv->applications, remove_approver, approver->proxy);
1157
1158
        
 
1159
        if (approver->name_watcher != 0) {
 
1160
                g_dbus_connection_signal_unsubscribe(g_dbus_proxy_get_connection(approver->proxy), approver->name_watcher);
 
1161
                approver->name_watcher = 0;
 
1162
        }
 
1163
 
1158
1164
        if (approver->proxy != NULL) {
1159
1165
                g_object_unref(approver->proxy);
1160
1166
                approver->proxy = NULL;
1216
1222
        return;
1217
1223
}
1218
1224
 
1219
 
/* Tracks when a proxy gets destroyed so that we know that the
1220
 
   approver has dropped off the bus. */
1221
 
static void
1222
 
approver_owner_changed (GObject * gobject, GParamSpec * pspec,
1223
 
                        gpointer user_data)
1224
 
{
1225
 
        Approver * approver = (Approver *)user_data;
1226
 
        ApplicationServiceAppstore * appstore = approver->appstore;
1227
 
        GDBusProxy * proxy = G_DBUS_PROXY(gobject);
1228
 
 
1229
 
        gchar * owner = g_dbus_proxy_get_name_owner(proxy);
1230
 
        if (owner != NULL) {
1231
 
                /* Reapprove everything with new owner */
1232
 
                g_list_foreach(appstore->priv->applications, check_with_new_approver, approver);
1233
 
                g_free (owner);
1234
 
                return;
1235
 
        }
1236
 
 
1237
 
        /* Approver died */
1238
 
        appstore->priv->approvers = g_list_remove(appstore->priv->approvers, approver);
1239
 
        approver_free(approver, appstore);
1240
 
 
1241
 
        return;
1242
 
}
1243
 
 
1244
1225
/* A signal when an approver changes the why that it thinks about
1245
1226
   a particular indicator. */
1246
1227
void
1279
1260
        approver->appstore = appstore;
1280
1261
        approver->proxy_cancel = NULL;
1281
1262
        approver->proxy = NULL;
 
1263
        approver->name_watcher = 0;
1282
1264
 
1283
1265
        approver->proxy_cancel = g_cancellable_new();
1284
1266
        g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION,
1296
1278
        return;
1297
1279
}
1298
1280
 
 
1281
static void
 
1282
approver_name_changed (GDBusConnection * connection, const gchar * sender_name,
 
1283
                       const gchar * object_path, const gchar * interface_name,
 
1284
                       const gchar * signal_name, GVariant * parameters,
 
1285
                       gpointer user_data)
 
1286
{
 
1287
        Approver * approver = (Approver *)user_data;
 
1288
        ApplicationServiceAppstore * appstore = approver->appstore;
 
1289
 
 
1290
        const gchar * new_name;
 
1291
        g_variant_get(parameters, "(&s&s&s)", NULL, NULL, &new_name);
 
1292
 
 
1293
        if (new_name == NULL || new_name[0] == 0) {
 
1294
                appstore->priv->approvers = g_list_remove(appstore->priv->approvers, approver);
 
1295
                approver_free(approver, appstore);
 
1296
        }
 
1297
}
 
1298
 
1299
1299
/* Callback from trying to create the proxy for the approver. */
1300
1300
static void
1301
1301
approver_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
1324
1324
        approver->proxy = proxy;
1325
1325
 
1326
1326
        /* We've got it, let's watch it for destruction */
1327
 
        g_signal_connect(proxy, "notify::g-name-owner",
1328
 
                         G_CALLBACK(approver_owner_changed), approver);
 
1327
        approver->name_watcher = g_dbus_connection_signal_subscribe(
 
1328
                                           g_dbus_proxy_get_connection(proxy),
 
1329
                                           "org.freedesktop.DBus",
 
1330
                                           "org.freedesktop.DBus",
 
1331
                                           "NameOwnerChanged",
 
1332
                                           "/org/freedesktop/DBus",
 
1333
                                           g_dbus_proxy_get_name(proxy),
 
1334
                                           G_DBUS_SIGNAL_FLAGS_NONE,
 
1335
                                           approver_name_changed,
 
1336
                                           approver,
 
1337
                                           NULL);
 
1338
 
1329
1339
        g_signal_connect(proxy, "g-signal", G_CALLBACK(approver_receive_signal),
1330
1340
                         approver);
1331
1341