#include <telepathy-glib/telepathy-glib.h>
+#include <telepathy-yell/telepathy-yell.h>
+
#include <libnotify/notification.h>
-#include <libempathy/empathy-channel-factory.h>
#include <libempathy/empathy-utils.h>
#include <libempathy-gtk/empathy-images.h>
g_object_ref (channel), g_object_unref, G_OBJECT (self));
}
-static void
-on_cdo_claim_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- AutoRejectCtx *ctx = user_data;
- TpChannelDispatchOperation *cdo;
- GError *error = NULL;
- GPtrArray *channels;
- guint i;
-
- cdo = TP_CHANNEL_DISPATCH_OPERATION (source_object);
-
- tp_channel_dispatch_operation_claim_with_finish (cdo, result, &error);
- if (error != NULL)
- {
- DEBUG ("Could not claim CDO: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- channels = tp_channel_dispatch_operation_borrow_channels (cdo);
- for (i = 0; i < channels->len; i++)
- {
- TpChannel *channel = g_ptr_array_index (channels, i);
-
- tp_channel_leave_async (channel,
- TP_CHANNEL_GROUP_CHANGE_REASON_BUSY, "Already in a call",
- NULL, NULL);
- }
-
- display_reject_notification (ctx->self, ctx->main_channel);
-
-out:
- auto_reject_ctx_free (ctx);
-}
-
-static void
-cdo_prepare_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- AutoRejectCtx *ctx = user_data;
- GError *error = NULL;
- TpChannelDispatchOperation *cdo;
-
- cdo = TP_CHANNEL_DISPATCH_OPERATION (source_object);
-
- if (!tp_proxy_prepare_finish (source_object, result, &error))
- {
- DEBUG ("Failed to prepare ChannelDispatchOperation: %s", error->message);
-
- tp_observe_channels_context_fail (ctx->context, error);
-
- g_error_free (error);
- auto_reject_ctx_free (ctx);
- return;
- }
-
- tp_channel_dispatch_operation_claim_with_async (cdo,
- ctx->self->priv->observer, on_cdo_claim_cb, ctx);
-
- tp_observe_channels_context_accept (ctx->context);
-}
-
static TpChannel *
find_main_channel (GList *channels)
{
channel_type = tp_channel_get_channel_type_id (channel);
- if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
+ if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA ||
+ channel_type == TPY_IFACE_QUARK_CHANNEL_TYPE_CALL)
return channel;
}
static gboolean
has_ongoing_calls (EmpathyCallObserver *self)
{
- if (self->priv->channels != NULL)
- return TRUE;
+ GList *l;
+
+ for (l = self->priv->channels; l != NULL; l = l->next)
+ {
+ TpChannel *channel = TP_CHANNEL (l->data);
+ GQuark type = tp_channel_get_channel_type_id (channel);
+
+ /* Check that Call channels are not ended */
+ if (type == TPY_IFACE_QUARK_CHANNEL_TYPE_CALL &&
+ tpy_call_channel_get_state (TPY_CALL_CHANNEL (channel), NULL, NULL)
+ == TPY_CALL_STATE_ENDED)
+ continue;
+
+ return TRUE;
+ }
return FALSE;
}
+static void
+claim_and_leave_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ AutoRejectCtx *ctx = user_data;
+ GError *error = NULL;
+
+ if (!tp_channel_dispatch_operation_leave_channels_finish (
+ TP_CHANNEL_DISPATCH_OPERATION (source), result, &error))
+ {
+ DEBUG ("Failed to reject call: %s", error->message);
+
+ g_error_free (error);
+ goto out;
+ }
+
+ display_reject_notification (ctx->self, ctx->main_channel);
+
+out:
+ auto_reject_ctx_free (ctx);
+}
+
static void
observe_channels (TpSimpleObserver *observer,
TpAccount *account,
if (has_ongoing_calls (self))
{
AutoRejectCtx *ctx = auto_reject_ctx_new (self, context, channel);
- GQuark features[] = { TP_CHANNEL_DISPATCH_OPERATION_FEATURE_CORE, 0 };
DEBUG ("Autorejecting incoming call since there are others in "
"progress: %s", tp_proxy_get_object_path (channel));
- /* We have to prepare dispatch_operation so we'll be able to get the
- * channels from it. */
- tp_proxy_prepare_async (dispatch_operation, features,
- cdo_prepare_cb, ctx);
+ tp_channel_dispatch_operation_leave_channels_async (dispatch_operation,
+ TP_CHANNEL_GROUP_CHANGE_REASON_BUSY, "Already in a call",
+ claim_and_leave_cb, ctx);
- tp_observe_channels_context_delay (context);
+ tp_observe_channels_context_accept (context);
return;
}
{
EmpathyCallObserverPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
EMPATHY_TYPE_CALL_OBSERVER, EmpathyCallObserverPriv);
- TpDBusDaemon *dbus;
- EmpathyChannelFactory *factory;
+ TpAccountManager *am;
GError *error = NULL;
self->priv = priv;
self->priv->notify_mgr = empathy_notify_manager_dup_singleton ();
- dbus = tp_dbus_daemon_dup (&error);
- if (dbus == NULL)
- {
- DEBUG ("Failed to get TpDBusDaemon: %s", error->message);
- g_error_free (error);
- return;
- }
+ am = tp_account_manager_dup ();
- self->priv->observer = tp_simple_observer_new (dbus, TRUE,
+ self->priv->observer = tp_simple_observer_new_with_am (am, TRUE,
"Empathy.CallObserver", FALSE,
observe_channels, self, NULL);
- factory = empathy_channel_factory_dup ();
- tp_base_client_set_channel_factory (self->priv->observer,
- TP_CLIENT_CHANNEL_FACTORY (factory));
- g_object_unref (factory);
-
- /* Observe StreamedMedia channels */
+ /* Observe Call and StreamedMedia channels */
tp_base_client_take_observer_filter (self->priv->observer,
tp_asv_new (
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
TP_HANDLE_TYPE_CONTACT,
NULL));
+ tp_base_client_take_observer_filter (self->priv->observer,
+ tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
+ TPY_IFACE_CHANNEL_TYPE_CALL,
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
+ TP_HANDLE_TYPE_CONTACT,
+ NULL));
tp_base_client_set_observer_delay_approvers (self->priv->observer, TRUE);
g_error_free (error);
}
- g_object_unref (dbus);
+ g_object_unref (am);
}
EmpathyCallObserver *