mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-06 03:25:31 +00:00
plugins/dummy: Implement inbound property
Also simulating dialing/ringing/active state changes for outbound calls.
This commit is contained in:
parent
0dc906c2bb
commit
824395b040
5 changed files with 130 additions and 16 deletions
|
@ -33,6 +33,7 @@ struct _CallsDummyCall
|
|||
{
|
||||
GObject parent_instance;
|
||||
gchar *number;
|
||||
gboolean inbound;
|
||||
CallsCallState state;
|
||||
};
|
||||
|
||||
|
@ -48,6 +49,8 @@ G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, G_TYPE_OBJECT,
|
|||
enum {
|
||||
PROP_0,
|
||||
PROP_NUMBER,
|
||||
PROP_INBOUND_CONSTRUCTOR,
|
||||
PROP_INBOUND,
|
||||
PROP_LAST_PROP,
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
@ -135,16 +138,45 @@ tone_stop (CallsCall *call, gchar key)
|
|||
g_info ("Beep end (%c)", (int)key);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
outbound_timeout_cb (CallsDummyCall *self)
|
||||
{
|
||||
switch (self->state)
|
||||
{
|
||||
case CALLS_CALL_STATE_DIALING:
|
||||
change_state (CALLS_CALL (self), self,
|
||||
CALLS_CALL_STATE_ALERTING);
|
||||
g_timeout_add_seconds
|
||||
(3, (GSourceFunc)outbound_timeout_cb, self);
|
||||
break;
|
||||
|
||||
case CALLS_CALL_STATE_ALERTING:
|
||||
change_state (CALLS_CALL (self), self,
|
||||
CALLS_CALL_STATE_ACTIVE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
CallsDummyCall *
|
||||
calls_dummy_call_new (const gchar *number)
|
||||
calls_dummy_call_new (const gchar *number,
|
||||
gboolean inbound)
|
||||
{
|
||||
g_return_val_if_fail (number != NULL, NULL);
|
||||
|
||||
return g_object_new (CALLS_TYPE_DUMMY_CALL,
|
||||
"number", number,
|
||||
"inbound-constructor", inbound,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -158,12 +190,57 @@ set_property (GObject *object,
|
|||
self->number = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_INBOUND_CONSTRUCTOR:
|
||||
self->inbound = g_value_get_boolean (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
|
||||
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
||||
|
||||
if (self->inbound)
|
||||
{
|
||||
self->state = CALLS_CALL_STATE_INCOMING;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->state = CALLS_CALL_STATE_DIALING;
|
||||
g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
|
||||
}
|
||||
|
||||
parent_class->constructed (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_INBOUND:
|
||||
g_value_set_boolean (value, self->inbound);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
|
@ -181,8 +258,10 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
|
|||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = finalize;
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
object_class->constructed = constructed;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
props[PROP_NUMBER] =
|
||||
g_param_spec_string ("number",
|
||||
|
@ -190,8 +269,25 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
|
|||
_("The dialed number"),
|
||||
"+441234567890",
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (object_class, PROP_NUMBER,
|
||||
props[PROP_NUMBER]);
|
||||
|
||||
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
||||
props[PROP_INBOUND_CONSTRUCTOR] =
|
||||
g_param_spec_boolean ("inbound-constructor",
|
||||
_("Inbound (constructor)"),
|
||||
_("Whether the calls is inbound (dummy class constructor)"),
|
||||
FALSE,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (object_class, PROP_INBOUND_CONSTRUCTOR,
|
||||
props[PROP_INBOUND_CONSTRUCTOR]);
|
||||
|
||||
props[PROP_INBOUND] =
|
||||
g_param_spec_boolean ("inbound",
|
||||
_("Inbound"),
|
||||
_("Whether the call is inbound"),
|
||||
FALSE,
|
||||
G_PARAM_READABLE | G_PARAM_CONSTRUCT);
|
||||
g_object_class_override_property (object_class, PROP_INBOUND, "inbound");
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -33,7 +33,8 @@ G_BEGIN_DECLS
|
|||
|
||||
G_DECLARE_FINAL_TYPE (CallsDummyCall, calls_dummy_call, CALLS, DUMMY_CALL, GObject);
|
||||
|
||||
CallsDummyCall *calls_dummy_call_new (const gchar *number);
|
||||
CallsDummyCall *calls_dummy_call_new (const gchar *number,
|
||||
gboolean inbound);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -127,19 +127,13 @@ call_state_changed_cb (CallsDummyOrigin *self,
|
|||
|
||||
|
||||
static void
|
||||
dial (CallsOrigin *origin, const gchar *number)
|
||||
add_call (CallsDummyOrigin *self, const gchar *number, gboolean inbound)
|
||||
{
|
||||
CallsDummyOrigin *self;
|
||||
CallsDummyCall *dummy_call;
|
||||
CallsCall *call;
|
||||
|
||||
g_return_if_fail (number != NULL);
|
||||
g_return_if_fail (CALLS_IS_DUMMY_ORIGIN (origin));
|
||||
|
||||
self = CALLS_DUMMY_ORIGIN (origin);
|
||||
|
||||
dummy_call = calls_dummy_call_new (number);
|
||||
g_return_if_fail (dummy_call != NULL);
|
||||
dummy_call = calls_dummy_call_new (number, inbound);
|
||||
g_assert (dummy_call != NULL);
|
||||
|
||||
call = CALLS_CALL (dummy_call);
|
||||
g_signal_connect_swapped (call, "state-changed",
|
||||
|
@ -148,7 +142,17 @@ dial (CallsOrigin *origin, const gchar *number)
|
|||
|
||||
self->calls = g_list_append (self->calls, dummy_call);
|
||||
|
||||
g_signal_emit_by_name (origin, "call-added", call);
|
||||
g_signal_emit_by_name (CALLS_ORIGIN (self), "call-added", call);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dial (CallsOrigin *origin, const gchar *number)
|
||||
{
|
||||
g_return_if_fail (number != NULL);
|
||||
g_return_if_fail (CALLS_IS_DUMMY_ORIGIN (origin));
|
||||
|
||||
add_call (CALLS_DUMMY_ORIGIN (origin), number, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,3 +249,14 @@ calls_dummy_origin_init (CallsDummyOrigin *self)
|
|||
{
|
||||
self->name = g_string_new (NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
calls_dummy_origin_create_inbound (CallsDummyOrigin *self,
|
||||
const gchar *number)
|
||||
{
|
||||
g_return_if_fail (number != NULL);
|
||||
g_return_if_fail (CALLS_IS_DUMMY_ORIGIN (self));
|
||||
|
||||
add_call (self, number, TRUE);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,9 @@ G_BEGIN_DECLS
|
|||
|
||||
G_DECLARE_FINAL_TYPE (CallsDummyOrigin, calls_dummy_origin, CALLS, DUMMY_ORIGIN, GObject);
|
||||
|
||||
CallsDummyOrigin *calls_dummy_origin_new (const gchar *name);
|
||||
CallsDummyOrigin *calls_dummy_origin_new (const gchar *name);
|
||||
void calls_dummy_origin_create_inbound (CallsDummyOrigin *self,
|
||||
const gchar *number);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ test_dummy_call_get_state (CallFixture *fixture,
|
|||
{
|
||||
CallsCallState state;
|
||||
state = calls_call_get_state (CALLS_CALL (fixture->dummy_call));
|
||||
g_assert_true (state == CALLS_CALL_STATE_ACTIVE);
|
||||
g_assert_true (state == CALLS_CALL_STATE_DIALING);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue