1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-06-30 15:49:31 +00:00

call: Move inbound property into base class

This avoids some repetition in the derived classes.
This commit is contained in:
Evangelos Ribeiro Tzaras 2021-12-10 08:00:11 +01:00
parent 88cd7ce222
commit ddf1dd7349
7 changed files with 66 additions and 89 deletions

View file

@ -33,7 +33,6 @@ struct _CallsDummyCall
{
GObject parent_instance;
gchar *id;
gboolean inbound;
CallsCallState state;
};
@ -46,7 +45,6 @@ G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, CALLS_TYPE_CALL,
enum {
PROP_0,
PROP_ID_CONSTRUCTOR,
PROP_INBOUND_CONSTRUCTOR,
PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];
@ -86,14 +84,6 @@ calls_dummy_call_get_state (CallsCall *call)
return self->state;
}
static gboolean
calls_dummy_call_get_inbound (CallsCall *call)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
return self->inbound;
}
static const char*
calls_dummy_call_get_protocol (CallsCall *call)
{
@ -163,7 +153,7 @@ calls_dummy_call_new (const gchar *id,
return g_object_new (CALLS_TYPE_DUMMY_CALL,
"id-constructor", id,
"inbound-constructor", inbound,
"inbound", inbound,
NULL);
}
@ -181,10 +171,6 @@ set_property (GObject *object,
self->id = 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;
@ -197,15 +183,12 @@ constructed (GObject *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);
}
if (calls_call_get_inbound (CALLS_CALL (object))) {
self->state = CALLS_CALL_STATE_INCOMING;
} else {
self->state = CALLS_CALL_STATE_DIALING;
g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
}
G_OBJECT_CLASS (calls_dummy_call_parent_class)->constructed (object);
}
@ -233,7 +216,6 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
call_class->get_id = calls_dummy_call_get_id;
call_class->get_state = calls_dummy_call_get_state;
call_class->get_inbound = calls_dummy_call_get_inbound;
call_class->get_protocol = calls_dummy_call_get_protocol;
call_class->answer = calls_dummy_call_answer;
call_class->hang_up = calls_dummy_call_hang_up;
@ -246,14 +228,6 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
"+441234567890",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_ID_CONSTRUCTOR, props[PROP_ID_CONSTRUCTOR]);
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]);
}
static void

View file

@ -207,16 +207,6 @@ calls_mm_call_get_state (CallsCall *call)
return self->state;
}
static gboolean
calls_mm_call_get_inbound (CallsCall *call)
{
CallsMMCall *self = CALLS_MM_CALL (call);
if (self->mm_call)
return mm_call_get_direction (self->mm_call) == MM_CALL_DIRECTION_INCOMING;
return FALSE;
}
static const char *
calls_mm_call_get_protocol (CallsCall *self)
@ -380,7 +370,6 @@ calls_mm_call_class_init (CallsMMCallClass *klass)
call_class->get_id = calls_mm_call_get_id;
call_class->get_state = calls_mm_call_get_state;
call_class->get_inbound = calls_mm_call_get_inbound;
call_class->get_protocol = calls_mm_call_get_protocol;
call_class->answer = calls_mm_call_answer;
call_class->hang_up = calls_mm_call_hang_up;
@ -410,10 +399,14 @@ calls_mm_call_init (CallsMMCall *self)
CallsMMCall *
calls_mm_call_new (MMCall *mm_call)
{
gboolean inbound;
g_return_val_if_fail (MM_IS_CALL (mm_call), NULL);
inbound = mm_call_get_direction (mm_call) == MM_CALL_DIRECTION_INCOMING;
return g_object_new (CALLS_TYPE_MM_CALL,
"mm-call", mm_call,
"inbound", inbound,
NULL);
}

View file

@ -39,10 +39,6 @@ struct _CallsOfonoCall
gchar *name;
CallsCallState state;
gchar *disconnect_reason;
/* `inbound` is derived from `state` at construction time.
* If the call was already somehow accepted and thus state=active,
* then it's not possible to know the correct value for `inbound`. */
gboolean inbound;
};
static void calls_ofono_call_message_source_interface_init (CallsMessageSourceInterface *iface);
@ -108,14 +104,6 @@ calls_ofono_call_get_state (CallsCall *call)
return self->state;
}
static gboolean
calls_ofono_call_get_inbound (CallsCall *call)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
return self->inbound;
}
static const char *
calls_ofono_call_get_protocol (CallsCall *call)
{
@ -214,11 +202,6 @@ set_properties (CallsOfonoCall *self,
g_variant_lookup (call_props, "State", "&s", &str);
g_return_if_fail (str != NULL);
calls_call_state_parse_nick (&self->state, str);
if (self->state == CALLS_CALL_STATE_INCOMING)
{
self->inbound = TRUE;
}
}
@ -347,7 +330,6 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
call_class->get_id = calls_ofono_call_get_id;
call_class->get_name = calls_ofono_call_get_name;
call_class->get_state = calls_ofono_call_get_state;
call_class->get_inbound = calls_ofono_call_get_inbound;
call_class->get_protocol = calls_ofono_call_get_protocol;
call_class->answer = calls_ofono_call_answer;
call_class->hang_up = calls_ofono_call_hang_up;
@ -393,14 +375,39 @@ calls_ofono_call_init (CallsOfonoCall *self)
CallsOfonoCall *
calls_ofono_call_new (GDBOVoiceCall *voice_call,
GVariant *properties)
GVariant *call_props)
{
const char *state_str = NULL;
const char *name = NULL;
const char *id = NULL;
CallsCallState state = CALLS_CALL_STATE_UNKNOWN;
gboolean inbound = FALSE;
g_return_val_if_fail (GDBO_IS_VOICE_CALL (voice_call), NULL);
g_return_val_if_fail (properties != NULL, NULL);
g_return_val_if_fail (call_props != NULL, NULL);
/* The following is a copy of set_properties() that we will get rid off
once all properties have been moved */
g_variant_lookup (call_props, "LineIdentification", "s", &id);
g_variant_lookup (call_props, "Name", "s", &name);
g_variant_lookup (call_props, "State", "&s", &state_str);
if (state_str)
calls_call_state_parse_nick (&state, state_str);
/* `inbound` is derived from `state` at construction time.
* If the call was already somehow accepted and thus state=active,
* then it's not possible to know the correct value for `inbound`. */
if (state == CALLS_CALL_STATE_INCOMING)
inbound = TRUE;
return g_object_new (CALLS_TYPE_OFONO_CALL,
"voice-call", voice_call,
"properties", properties,
"properties", call_props,
//"id", id,
//"name", name,
"inbound", inbound,
//"state", state,
NULL);
}

View file

@ -58,7 +58,6 @@ struct _CallsSipCall
{
GObject parent_instance;
gchar *id;
gboolean inbound;
CallsCallState state;
CallsSipMediaManager *manager;
@ -135,15 +134,6 @@ calls_sip_call_get_state (CallsCall *call)
}
static gboolean
calls_sip_call_get_inbound (CallsCall *call)
{
CallsSipCall *self = CALLS_SIP_CALL (call);
return self->inbound;
}
static const char *
calls_sip_call_get_protocol (CallsCall *call)
{
@ -299,7 +289,6 @@ calls_sip_call_class_init (CallsSipCallClass *klass)
call_class->get_id = calls_sip_call_get_id;
call_class->get_state = calls_sip_call_get_state;
call_class->get_inbound = calls_sip_call_get_inbound;
call_class->get_protocol = calls_sip_call_get_protocol;
call_class->answer = calls_sip_call_answer;
call_class->hang_up = calls_sip_call_hang_up;
@ -404,10 +393,10 @@ calls_sip_call_new (const gchar *id,
call = g_object_new (CALLS_TYPE_SIP_CALL,
"nua-handle", handle,
"inbound", inbound,
NULL);
call->id = g_strdup (id);
call->inbound = inbound;
if (inbound)
call->state = CALLS_CALL_STATE_INCOMING;

View file

@ -67,6 +67,7 @@ static GParamSpec *properties[N_PROPS];
static guint signals[N_SIGNALS];
typedef struct {
gboolean inbound;
gboolean silenced;
} CallsCallPrivate;
@ -91,12 +92,6 @@ calls_call_real_get_state (CallsCall *self)
return 0;
}
static gboolean
calls_call_real_get_inbound (CallsCall *self)
{
return FALSE;
}
static const char *
calls_call_real_get_protocol (CallsCall *self)
{
@ -120,6 +115,26 @@ calls_call_real_send_dtmf_tone (CallsCall *self,
g_info ("Beep! (%c)", key);
}
static void
calls_call_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
CallsCall *self = CALLS_CALL (object);
CallsCallPrivate *priv = calls_call_get_instance_private (self);
switch (prop_id) {
case PROP_INBOUND:
priv->inbound = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
calls_call_get_property (GObject *object,
guint prop_id,
@ -164,11 +179,11 @@ calls_call_class_init (CallsCallClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = calls_call_get_property;
object_class->set_property = calls_call_set_property;
klass->get_id = calls_call_real_get_id;
klass->get_name = calls_call_real_get_name;
klass->get_state = calls_call_real_get_state;
klass->get_inbound = calls_call_real_get_inbound;
klass->get_protocol = calls_call_real_get_protocol;
klass->answer = calls_call_real_answer;
klass->hang_up = calls_call_real_hang_up;
@ -179,7 +194,7 @@ calls_call_class_init (CallsCallClass *klass)
"Inbound",
"Whether the call is inbound",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
properties[PROP_ID] =
g_param_spec_string ("id",
@ -335,9 +350,11 @@ calls_call_hang_up (CallsCall *self)
gboolean
calls_call_get_inbound (CallsCall *self)
{
CallsCallPrivate *priv = calls_call_get_instance_private (self);
g_return_val_if_fail (CALLS_IS_CALL (self), FALSE);
return CALLS_CALL_GET_CLASS (self)->get_inbound (self);
return priv->inbound;
}
/**

View file

@ -54,7 +54,6 @@ struct _CallsCallClass
const char *(*get_id) (CallsCall *self);
const char *(*get_name) (CallsCall *self);
CallsCallState (*get_state) (CallsCall *self);
gboolean (*get_inbound) (CallsCall *self);
const char *(*get_protocol) (CallsCall *self);
void (*answer) (CallsCall *self);
void (*hang_up) (CallsCall *self);

View file

@ -24,7 +24,5 @@ void calls_mock_call_set_name (CallsMockCall *self,
const char *name);
void calls_mock_call_set_state (CallsMockCall *self,
CallsCallState state);
void calls_mock_call_set_inbound (CallsMockCall *self,
gboolean inbound);
G_END_DECLS