Commit ed0da2a3 authored by Julian Sparber's avatar Julian Sparber Committed by Julian Sparber
Browse files

MMPlugin: emit *-removed after removing object

This makes sure that when we use calls_provider_get_origins/calls ()
in the signal handler it doesn't include the removed origin/call.
parent 389e7720
......@@ -113,43 +113,22 @@ dial (CallsOrigin *origin, const gchar *number)
static void
remove_call (CallsMMOrigin *self,
CallsMMCall *call,
const gchar *path,
const gchar *reason)
{
g_signal_emit_by_name (CALLS_ORIGIN(self), "call-removed",
CALLS_CALL(call), reason);
g_hash_table_remove (self->calls, path);
}
struct CallsMMRemoveCallsData
{
CallsOrigin *origin;
const gchar *reason;
};
static gboolean
remove_calls_cb (const gchar *path,
CallsMMCall *call,
struct CallsMMRemoveCallsData *data)
remove_calls (CallsMMOrigin *self, const gchar *reason)
{
g_signal_emit_by_name (data->origin, "call-removed",
CALLS_CALL(call), data->reason);
return TRUE;
}
GList *paths, *node;
gpointer call;
paths = g_hash_table_get_keys (self->calls);
static void
remove_calls (CallsMMOrigin *self, const gchar *reason)
{
struct CallsMMRemoveCallsData data = { CALLS_ORIGIN (self), reason };
for (node = paths; node != NULL; node = node->next)
{
g_hash_table_steal_extended (self->calls, node->data, NULL, &call);
g_signal_emit_by_name (self, "call-removed",
CALLS_CALL(call), reason);
g_object_unref (call);
}
g_hash_table_foreach_remove (self->calls,
(GHRFunc) remove_calls_cb,
&data);
g_list_free_full (paths, g_free);
}
......@@ -341,13 +320,17 @@ call_deleted_cb (MMModemVoice *voice,
const gchar *path,
CallsMMOrigin *self)
{
CallsMMCall *call;
gpointer call;
gpointer key;
GString *reason;
const gchar *mm_reason;
g_debug ("Removing call `%s'", path);
call = g_hash_table_lookup (self->calls, path);
g_hash_table_steal_extended (self->calls, path, &key, &call);
g_free (key);
if (!call)
{
g_warning ("Could not find removed call `%s'", path);
......@@ -356,14 +339,15 @@ call_deleted_cb (MMModemVoice *voice,
reason = g_string_new ("Call removed");
mm_reason = calls_mm_call_get_disconnect_reason (call);
mm_reason = calls_mm_call_get_disconnect_reason (CALLS_MM_CALL (call));
if (mm_reason)
{
g_string_assign (reason, mm_reason);
}
remove_call (self, call, path, reason->str);
g_signal_emit_by_name (self, "call-removed", call, reason);
g_object_unref (call);
g_string_free (reason, TRUE);
g_debug ("Removed call `%s'", path);
......
......@@ -186,10 +186,12 @@ remove_modem_object (CallsMMProvider *self,
g_assert (CALLS_IS_ORIGIN (origin));
g_object_ref (origin);
g_hash_table_remove (self->origins, path);
g_signal_emit_by_name (CALLS_PROVIDER (self),
"origin-removed", CALLS_ORIGIN (origin));
g_hash_table_remove (self->origins, path);
g_object_unref (origin);
update_status (self);
}
......@@ -322,23 +324,24 @@ mm_appeared_cb (GDBusConnection *connection,
}
static gboolean
remove_origins_cb (const gchar *path,
CallsMMOrigin *origin,
CallsMMProvider *self)
{
g_signal_emit_by_name (CALLS_PROVIDER (self),
"origin-removed", CALLS_ORIGIN (origin));
return TRUE;
}
static void
clear_dbus (CallsMMProvider *self)
{
g_hash_table_foreach_remove (self->origins,
(GHRFunc)remove_origins_cb,
self);
GList *paths, *node;
gpointer origin;
paths = g_hash_table_get_keys (self->origins);
for (node = paths; node != NULL; node = node->next)
{
g_hash_table_steal_extended (self->origins, node->data, NULL, &origin);
g_signal_emit_by_name (CALLS_PROVIDER (self),
"origin-removed", CALLS_ORIGIN (origin));
g_object_unref (origin);
}
g_list_free_full (paths, g_free);
g_clear_object (&self->mm);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment