mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-04 20:07:36 +00:00
call: Move id property into base class
This allows us to avoid some duplication in the derived classes.
This commit is contained in:
parent
a048b4c83d
commit
a1fefcdbac
7 changed files with 63 additions and 149 deletions
|
@ -32,7 +32,6 @@
|
|||
struct _CallsDummyCall
|
||||
{
|
||||
GObject parent_instance;
|
||||
gchar *id;
|
||||
};
|
||||
|
||||
static void calls_dummy_call_message_source_interface_init (CallsMessageSourceInterface *iface);
|
||||
|
@ -41,21 +40,6 @@ G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, CALLS_TYPE_CALL,
|
|||
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
|
||||
calls_dummy_call_message_source_interface_init))
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ID_CONSTRUCTOR,
|
||||
PROP_LAST_PROP
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
||||
static const char *
|
||||
calls_dummy_call_get_id (CallsCall *call)
|
||||
{
|
||||
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
|
||||
|
||||
return self->id;
|
||||
}
|
||||
|
||||
static const char*
|
||||
calls_dummy_call_get_protocol (CallsCall *call)
|
||||
{
|
||||
|
@ -121,32 +105,12 @@ calls_dummy_call_new (const gchar *id,
|
|||
g_return_val_if_fail (id != NULL, NULL);
|
||||
|
||||
return g_object_new (CALLS_TYPE_DUMMY_CALL,
|
||||
"id-constructor", id,
|
||||
"id", id,
|
||||
"inbound", inbound,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_ID_CONSTRUCTOR:
|
||||
self->id = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
|
@ -158,16 +122,6 @@ constructed (GObject *object)
|
|||
G_OBJECT_CLASS (calls_dummy_call_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
||||
|
||||
g_free (self->id);
|
||||
|
||||
G_OBJECT_CLASS (calls_dummy_call_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_dummy_call_class_init (CallsDummyCallClass *klass)
|
||||
|
@ -175,23 +129,12 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
|
|||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
CallsCallClass *call_class = CALLS_CALL_CLASS (klass);
|
||||
|
||||
object_class->set_property = set_property;
|
||||
object_class->constructed = constructed;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
call_class->get_id = calls_dummy_call_get_id;
|
||||
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;
|
||||
call_class->send_dtmf_tone = calls_dummy_call_send_dtmf_tone;
|
||||
|
||||
props[PROP_ID_CONSTRUCTOR] =
|
||||
g_param_spec_string ("id-constructor",
|
||||
"Id (constructor)",
|
||||
"The dialed id (dummy class constructor)",
|
||||
"+441234567890",
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (object_class, PROP_ID_CONSTRUCTOR, props[PROP_ID_CONSTRUCTOR]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -37,7 +37,6 @@ struct _CallsMMCall
|
|||
{
|
||||
GObject parent_instance;
|
||||
MMCall *mm_call;
|
||||
GString *id;
|
||||
gchar *disconnect_reason;
|
||||
};
|
||||
|
||||
|
@ -58,8 +57,7 @@ static void
|
|||
notify_id_cb (CallsMMCall *self,
|
||||
const gchar *id)
|
||||
{
|
||||
g_string_assign (self->id, id);
|
||||
g_object_notify (G_OBJECT (self), "id");
|
||||
calls_call_set_id (CALLS_CALL (self), id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -170,14 +168,6 @@ state_changed_cb (CallsMMCall *self,
|
|||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_mm_call_get_id (CallsCall *call)
|
||||
{
|
||||
CallsMMCall *self = CALLS_MM_CALL (call);
|
||||
|
||||
return self->id->str;
|
||||
}
|
||||
|
||||
|
||||
static const char *
|
||||
calls_mm_call_get_protocol (CallsCall *self)
|
||||
|
@ -204,7 +194,9 @@ operation_cb (MMCall *mm_call,
|
|||
if (!ok)
|
||||
{
|
||||
g_warning ("Error %s ModemManager call to `%s': %s",
|
||||
data->desc, data->self->id->str, error->message);
|
||||
data->desc,
|
||||
calls_call_get_id (CALLS_CALL (data->self)),
|
||||
error->message);
|
||||
CALLS_ERROR (data->self, error);
|
||||
}
|
||||
|
||||
|
@ -322,7 +314,6 @@ finalize (GObject *object)
|
|||
CallsMMCall *self = CALLS_MM_CALL (object);
|
||||
|
||||
g_free (self->disconnect_reason);
|
||||
g_string_free (self->id, TRUE);
|
||||
|
||||
G_OBJECT_CLASS (calls_mm_call_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -339,7 +330,6 @@ calls_mm_call_class_init (CallsMMCallClass *klass)
|
|||
object_class->dispose = dispose;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
call_class->get_id = calls_mm_call_get_id;
|
||||
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;
|
||||
|
@ -362,7 +352,6 @@ calls_mm_call_message_source_interface_init (CallsMessageSourceInterface *iface)
|
|||
static void
|
||||
calls_mm_call_init (CallsMMCall *self)
|
||||
{
|
||||
self->id = g_string_new (NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ struct _CallsOfonoCall
|
|||
{
|
||||
GObject parent_instance;
|
||||
GDBOVoiceCall *voice_call;
|
||||
gchar *id;
|
||||
gchar *name;
|
||||
gchar *disconnect_reason;
|
||||
};
|
||||
|
@ -60,14 +59,6 @@ enum {
|
|||
};
|
||||
static guint signals [SIGNAL_LAST_SIGNAL];
|
||||
|
||||
static const char *
|
||||
calls_ofono_call_get_id (CallsCall *call)
|
||||
{
|
||||
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
||||
|
||||
return self->id;
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_ofono_call_get_name (CallsCall *call)
|
||||
{
|
||||
|
@ -101,7 +92,9 @@ operation_cb (GDBOVoiceCall *voice_call,
|
|||
ok = data->finish_func (voice_call, res, &error);
|
||||
if (!ok) {
|
||||
g_warning ("Error %s oFono voice call to `%s': %s",
|
||||
data->desc, data->self->id, error->message);
|
||||
data->desc,
|
||||
calls_call_get_id (CALLS_CALL (data->self)),
|
||||
error->message);
|
||||
CALLS_ERROR (data->self, error);
|
||||
}
|
||||
|
||||
|
@ -152,7 +145,7 @@ calls_ofono_call_send_dtmf_tone (CallsCall *call, gchar key)
|
|||
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
||||
if (calls_call_get_state (call) != CALLS_CALL_STATE_ACTIVE) {
|
||||
g_warning ("Tone start requested for non-active call to `%s'",
|
||||
self->id);
|
||||
calls_call_get_id (call));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -165,11 +158,14 @@ set_properties (CallsOfonoCall *self,
|
|||
GVariant *call_props)
|
||||
{
|
||||
CallsCallState state;
|
||||
const gchar *str = NULL;
|
||||
const char *id = NULL;
|
||||
const char *str = NULL;
|
||||
|
||||
g_return_if_fail (call_props != NULL);
|
||||
|
||||
g_variant_lookup (call_props, "LineIdentification", "s", &self->id);
|
||||
g_variant_lookup (call_props, "LineIdentification", "s", &id);
|
||||
calls_call_set_id (CALLS_CALL (self), id);
|
||||
|
||||
g_variant_lookup (call_props, "Name", "s", &self->name);
|
||||
|
||||
g_variant_lookup (call_props, "State", "&s", &str);
|
||||
|
@ -215,7 +211,9 @@ property_changed_cb (CallsOfonoCall *self,
|
|||
g_autofree char *text = g_variant_print (value, TRUE);
|
||||
|
||||
g_debug ("Property `%s' for oFono call to `%s' changed to: %s",
|
||||
name, self->id, text);
|
||||
name,
|
||||
calls_call_get_id (CALLS_CALL (self)),
|
||||
text);
|
||||
|
||||
if (g_strcmp0 (name, "State") != 0)
|
||||
return;
|
||||
|
@ -230,7 +228,7 @@ property_changed_cb (CallsOfonoCall *self,
|
|||
else
|
||||
g_warning ("Could not parse new state `%s'"
|
||||
" of oFono call to `%s'",
|
||||
str, self->id);
|
||||
str, calls_call_get_id (CALLS_CALL (self)));
|
||||
|
||||
g_variant_unref (str_var);
|
||||
}
|
||||
|
@ -283,7 +281,6 @@ finalize (GObject *object)
|
|||
|
||||
g_free (self->disconnect_reason);
|
||||
g_free (self->name);
|
||||
g_free (self->id);
|
||||
|
||||
G_OBJECT_CLASS (calls_ofono_call_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -301,7 +298,6 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
|
|||
object_class->dispose = dispose;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
call_class->get_id = calls_ofono_call_get_id;
|
||||
call_class->get_name = calls_ofono_call_get_name;
|
||||
call_class->get_protocol = calls_ofono_call_get_protocol;
|
||||
call_class->answer = calls_ofono_call_answer;
|
||||
|
@ -377,7 +373,7 @@ calls_ofono_call_new (GDBOVoiceCall *voice_call,
|
|||
return g_object_new (CALLS_TYPE_OFONO_CALL,
|
||||
"voice-call", voice_call,
|
||||
"properties", call_props,
|
||||
//"id", id,
|
||||
"id", id,
|
||||
//"name", name,
|
||||
"inbound", inbound,
|
||||
"state", state,
|
||||
|
|
|
@ -57,7 +57,6 @@ static GParamSpec *props[PROP_LAST_PROP];
|
|||
struct _CallsSipCall
|
||||
{
|
||||
GObject parent_instance;
|
||||
gchar *id;
|
||||
|
||||
CallsSipMediaManager *manager;
|
||||
CallsSipMediaPipeline *pipeline;
|
||||
|
@ -115,21 +114,11 @@ try_setting_up_media_pipeline (CallsSipCall *self)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_sip_call_get_id (CallsCall *call)
|
||||
{
|
||||
CallsSipCall *self = CALLS_SIP_CALL (call);
|
||||
|
||||
return self->id;
|
||||
}
|
||||
|
||||
|
||||
static const char *
|
||||
calls_sip_call_get_protocol (CallsCall *call)
|
||||
{
|
||||
CallsSipCall *self = CALLS_SIP_CALL (call);
|
||||
|
||||
return get_protocol_from_address (self->id);
|
||||
return get_protocol_from_address (calls_call_get_id (call));
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,8 +244,6 @@ calls_sip_call_finalize (GObject *object)
|
|||
{
|
||||
CallsSipCall *self = CALLS_SIP_CALL (object);
|
||||
|
||||
g_free (self->id);
|
||||
|
||||
if (self->pipeline) {
|
||||
calls_sip_media_pipeline_stop (self->pipeline);
|
||||
g_clear_object (&self->pipeline);
|
||||
|
@ -278,7 +265,6 @@ calls_sip_call_class_init (CallsSipCallClass *klass)
|
|||
object_class->set_property = calls_sip_call_set_property;
|
||||
object_class->finalize = calls_sip_call_finalize;
|
||||
|
||||
call_class->get_id = calls_sip_call_get_id;
|
||||
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;
|
||||
|
@ -377,19 +363,14 @@ calls_sip_call_new (const gchar *id,
|
|||
gboolean inbound,
|
||||
nua_handle_t *handle)
|
||||
{
|
||||
CallsSipCall *call;
|
||||
g_return_val_if_fail (id, NULL);
|
||||
|
||||
g_return_val_if_fail (id != NULL, NULL);
|
||||
|
||||
call = g_object_new (CALLS_TYPE_SIP_CALL,
|
||||
return g_object_new (CALLS_TYPE_SIP_CALL,
|
||||
"nua-handle", handle,
|
||||
"id", id,
|
||||
"inbound", inbound,
|
||||
"state", inbound ? CALLS_CALL_STATE_INCOMING : CALLS_CALL_STATE_DIALING,
|
||||
NULL);
|
||||
|
||||
call->id = g_strdup (id);
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,6 +67,7 @@ static GParamSpec *properties[N_PROPS];
|
|||
static guint signals[N_SIGNALS];
|
||||
|
||||
typedef struct {
|
||||
char *id;
|
||||
CallsCallState state;
|
||||
gboolean inbound;
|
||||
gboolean silenced;
|
||||
|
@ -75,12 +76,6 @@ typedef struct {
|
|||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (CallsCall, calls_call, G_TYPE_OBJECT)
|
||||
|
||||
|
||||
static const char *
|
||||
calls_call_real_get_id (CallsCall *self)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_call_real_get_name (CallsCall *self)
|
||||
{
|
||||
|
@ -128,6 +123,10 @@ calls_call_set_property (GObject *object,
|
|||
calls_call_set_state (self, CALLS_CALL_STATE_DIALING);
|
||||
break;
|
||||
|
||||
case PROP_ID:
|
||||
calls_call_set_id (self, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
case PROP_STATE:
|
||||
calls_call_set_state (self, g_value_get_enum (value));
|
||||
break;
|
||||
|
@ -184,7 +183,6 @@ calls_call_class_init (CallsCallClass *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_protocol = calls_call_real_get_protocol;
|
||||
klass->answer = calls_call_real_answer;
|
||||
|
@ -203,7 +201,10 @@ calls_call_class_init (CallsCallClass *klass)
|
|||
"Id",
|
||||
"The id the call is connected to if known",
|
||||
NULL,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_EXPLICIT_NOTIFY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_NAME] =
|
||||
g_param_spec_string ("name",
|
||||
|
@ -274,9 +275,36 @@ calls_call_init (CallsCall *self)
|
|||
const char *
|
||||
calls_call_get_id (CallsCall *self)
|
||||
{
|
||||
CallsCallPrivate *priv = calls_call_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (CALLS_IS_CALL (self), NULL);
|
||||
|
||||
return CALLS_CALL_GET_CLASS (self)->get_id (self);
|
||||
return priv->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* calls_call_set_id:
|
||||
* @self: a #CallsCall
|
||||
* @id: the id of the remote party
|
||||
*
|
||||
* Set the id of the call. Some implementations might only be able to set
|
||||
* the id after construction.
|
||||
*/
|
||||
void
|
||||
calls_call_set_id (CallsCall *self,
|
||||
const char *id)
|
||||
{
|
||||
CallsCallPrivate *priv = calls_call_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (CALLS_IS_CALL (self));
|
||||
g_return_if_fail (id);
|
||||
|
||||
if (g_strcmp0 (id, priv->id) == 0)
|
||||
return;
|
||||
|
||||
g_free (priv->id);
|
||||
priv->id = g_strdup (id);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ID]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,6 @@ struct _CallsCallClass
|
|||
{
|
||||
GObjectClass parent_iface;
|
||||
|
||||
const char *(*get_id) (CallsCall *self);
|
||||
const char *(*get_name) (CallsCall *self);
|
||||
const char *(*get_protocol) (CallsCall *self);
|
||||
void (*answer) (CallsCall *self);
|
||||
|
@ -61,6 +60,8 @@ struct _CallsCallClass
|
|||
};
|
||||
|
||||
const char *calls_call_get_id (CallsCall *self);
|
||||
void calls_call_set_id (CallsCall *self,
|
||||
const char *id);
|
||||
const char *calls_call_get_name (CallsCall *self);
|
||||
CallsCallState calls_call_get_state (CallsCall *self);
|
||||
void calls_call_set_state (CallsCall *self,
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
enum {
|
||||
PROP_0,
|
||||
PROP_NAME,
|
||||
PROP_ID,
|
||||
PROP_LAST_PROP,
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
@ -23,7 +22,6 @@ struct _CallsMockCall
|
|||
{
|
||||
CallsCall parent_instance;
|
||||
|
||||
char *id;
|
||||
char *display_name;
|
||||
};
|
||||
|
||||
|
@ -59,9 +57,6 @@ calls_mock_call_get_property (GObject *object,
|
|||
CallsMockCall *self = CALLS_MOCK_CALL (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ID:
|
||||
g_value_set_string (value, self->id);
|
||||
break;
|
||||
case PROP_NAME:
|
||||
g_value_set_string (value, self->display_name);
|
||||
break;
|
||||
|
@ -76,7 +71,6 @@ calls_mock_call_finalize (GObject *object)
|
|||
{
|
||||
CallsMockCall *self = CALLS_MOCK_CALL (object);
|
||||
|
||||
g_free (self->id);
|
||||
g_free (self->display_name);
|
||||
|
||||
G_OBJECT_CLASS (calls_mock_call_parent_class)->finalize (object);
|
||||
|
@ -95,11 +89,6 @@ calls_mock_call_class_init (CallsMockCallClass *klass)
|
|||
object_class->get_property = calls_mock_call_get_property;
|
||||
object_class->finalize = calls_mock_call_finalize;
|
||||
|
||||
g_object_class_override_property (object_class,
|
||||
PROP_ID,
|
||||
"id");
|
||||
props[PROP_ID] = g_object_class_find_property (object_class, "id");
|
||||
|
||||
g_object_class_override_property (object_class,
|
||||
PROP_NAME,
|
||||
"name");
|
||||
|
@ -111,7 +100,6 @@ static void
|
|||
calls_mock_call_init (CallsMockCall *self)
|
||||
{
|
||||
self->display_name = g_strdup ("John Doe");
|
||||
self->id = g_strdup ("0800 1234");
|
||||
}
|
||||
|
||||
|
||||
|
@ -120,23 +108,11 @@ calls_mock_call_new (void)
|
|||
{
|
||||
return g_object_new (CALLS_TYPE_MOCK_CALL,
|
||||
"inbound", TRUE,
|
||||
"id", "0800 1234",
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
calls_mock_call_set_id (CallsMockCall *self,
|
||||
const char *id)
|
||||
{
|
||||
g_return_if_fail (CALLS_IS_MOCK_CALL (self));
|
||||
|
||||
g_free (self->id);
|
||||
self->id = g_strdup (id);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ID]);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
calls_mock_call_set_name (CallsMockCall *self,
|
||||
const char *name)
|
||||
|
|
Loading…
Reference in a new issue