1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-11-19 01:51:46 +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; GObject parent_instance;
gchar *id; gchar *id;
gboolean inbound;
CallsCallState state; CallsCallState state;
}; };
@ -46,7 +45,6 @@ G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, CALLS_TYPE_CALL,
enum { enum {
PROP_0, PROP_0,
PROP_ID_CONSTRUCTOR, PROP_ID_CONSTRUCTOR,
PROP_INBOUND_CONSTRUCTOR,
PROP_LAST_PROP PROP_LAST_PROP
}; };
static GParamSpec *props[PROP_LAST_PROP]; static GParamSpec *props[PROP_LAST_PROP];
@ -86,14 +84,6 @@ calls_dummy_call_get_state (CallsCall *call)
return self->state; return self->state;
} }
static gboolean
calls_dummy_call_get_inbound (CallsCall *call)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
return self->inbound;
}
static const char* static const char*
calls_dummy_call_get_protocol (CallsCall *call) 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, return g_object_new (CALLS_TYPE_DUMMY_CALL,
"id-constructor", id, "id-constructor", id,
"inbound-constructor", inbound, "inbound", inbound,
NULL); NULL);
} }
@ -181,10 +171,6 @@ set_property (GObject *object,
self->id = g_value_dup_string (value); self->id = g_value_dup_string (value);
break; break;
case PROP_INBOUND_CONSTRUCTOR:
self->inbound = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -197,15 +183,12 @@ constructed (GObject *object)
{ {
CallsDummyCall *self = CALLS_DUMMY_CALL (object); CallsDummyCall *self = CALLS_DUMMY_CALL (object);
if (self->inbound) if (calls_call_get_inbound (CALLS_CALL (object))) {
{ self->state = CALLS_CALL_STATE_INCOMING;
self->state = CALLS_CALL_STATE_INCOMING; } else {
} self->state = CALLS_CALL_STATE_DIALING;
else g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
{ }
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); 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_id = calls_dummy_call_get_id;
call_class->get_state = calls_dummy_call_get_state; 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->get_protocol = calls_dummy_call_get_protocol;
call_class->answer = calls_dummy_call_answer; call_class->answer = calls_dummy_call_answer;
call_class->hang_up = calls_dummy_call_hang_up; call_class->hang_up = calls_dummy_call_hang_up;
@ -246,14 +228,6 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
"+441234567890", "+441234567890",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_ID_CONSTRUCTOR, props[PROP_ID_CONSTRUCTOR]); 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 static void

View file

@ -207,16 +207,6 @@ calls_mm_call_get_state (CallsCall *call)
return self->state; 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 * static const char *
calls_mm_call_get_protocol (CallsCall *self) 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_id = calls_mm_call_get_id;
call_class->get_state = calls_mm_call_get_state; 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->get_protocol = calls_mm_call_get_protocol;
call_class->answer = calls_mm_call_answer; call_class->answer = calls_mm_call_answer;
call_class->hang_up = calls_mm_call_hang_up; call_class->hang_up = calls_mm_call_hang_up;
@ -410,10 +399,14 @@ calls_mm_call_init (CallsMMCall *self)
CallsMMCall * CallsMMCall *
calls_mm_call_new (MMCall *mm_call) calls_mm_call_new (MMCall *mm_call)
{ {
gboolean inbound;
g_return_val_if_fail (MM_IS_CALL (mm_call), NULL); 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, return g_object_new (CALLS_TYPE_MM_CALL,
"mm-call", mm_call, "mm-call", mm_call,
"inbound", inbound,
NULL); NULL);
} }

View file

@ -39,10 +39,6 @@ struct _CallsOfonoCall
gchar *name; gchar *name;
CallsCallState state; CallsCallState state;
gchar *disconnect_reason; 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); 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; return self->state;
} }
static gboolean
calls_ofono_call_get_inbound (CallsCall *call)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
return self->inbound;
}
static const char * static const char *
calls_ofono_call_get_protocol (CallsCall *call) calls_ofono_call_get_protocol (CallsCall *call)
{ {
@ -214,11 +202,6 @@ set_properties (CallsOfonoCall *self,
g_variant_lookup (call_props, "State", "&s", &str); g_variant_lookup (call_props, "State", "&s", &str);
g_return_if_fail (str != NULL); g_return_if_fail (str != NULL);
calls_call_state_parse_nick (&self->state, str); 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_id = calls_ofono_call_get_id;
call_class->get_name = calls_ofono_call_get_name; call_class->get_name = calls_ofono_call_get_name;
call_class->get_state = calls_ofono_call_get_state; 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->get_protocol = calls_ofono_call_get_protocol;
call_class->answer = calls_ofono_call_answer; call_class->answer = calls_ofono_call_answer;
call_class->hang_up = calls_ofono_call_hang_up; call_class->hang_up = calls_ofono_call_hang_up;
@ -393,14 +375,39 @@ calls_ofono_call_init (CallsOfonoCall *self)
CallsOfonoCall * CallsOfonoCall *
calls_ofono_call_new (GDBOVoiceCall *voice_call, 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 (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, return g_object_new (CALLS_TYPE_OFONO_CALL,
"voice-call", voice_call, "voice-call", voice_call,
"properties", properties, "properties", call_props,
//"id", id,
//"name", name,
"inbound", inbound,
//"state", state,
NULL); NULL);
} }

View file

@ -58,7 +58,6 @@ struct _CallsSipCall
{ {
GObject parent_instance; GObject parent_instance;
gchar *id; gchar *id;
gboolean inbound;
CallsCallState state; CallsCallState state;
CallsSipMediaManager *manager; 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 * static const char *
calls_sip_call_get_protocol (CallsCall *call) 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_id = calls_sip_call_get_id;
call_class->get_state = calls_sip_call_get_state; 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->get_protocol = calls_sip_call_get_protocol;
call_class->answer = calls_sip_call_answer; call_class->answer = calls_sip_call_answer;
call_class->hang_up = calls_sip_call_hang_up; 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, call = g_object_new (CALLS_TYPE_SIP_CALL,
"nua-handle", handle, "nua-handle", handle,
"inbound", inbound,
NULL); NULL);
call->id = g_strdup (id); call->id = g_strdup (id);
call->inbound = inbound;
if (inbound) if (inbound)
call->state = CALLS_CALL_STATE_INCOMING; call->state = CALLS_CALL_STATE_INCOMING;

View file

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

View file

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