call: Move name property to base class

This let's us avoid some duplication in the derived classes.
This commit is contained in:
Evangelos Ribeiro Tzaras
2021-12-11 09:24:57 +01:00
parent a1fefcdbac
commit dbfa593a07
5 changed files with 37 additions and 122 deletions

View File

@@ -68,6 +68,7 @@ static guint signals[N_SIGNALS];
typedef struct {
char *id;
char *name;
CallsCallState state;
gboolean inbound;
gboolean silenced;
@@ -76,12 +77,6 @@ typedef struct {
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (CallsCall, calls_call, G_TYPE_OBJECT)
static const char *
calls_call_real_get_name (CallsCall *self)
{
return NULL;
}
static const char *
calls_call_real_get_protocol (CallsCall *self)
{
@@ -127,6 +122,10 @@ calls_call_set_property (GObject *object,
calls_call_set_id (self, g_value_get_string (value));
break;
case PROP_NAME:
calls_call_set_name (self, g_value_get_string (value));
break;
case PROP_STATE:
calls_call_set_state (self, g_value_get_enum (value));
break;
@@ -183,7 +182,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_name = calls_call_real_get_name;
klass->get_protocol = calls_call_real_get_protocol;
klass->answer = calls_call_real_answer;
klass->hang_up = calls_call_real_hang_up;
@@ -211,7 +209,9 @@ calls_call_class_init (CallsCallClass *klass)
"Name",
"The name of the party the call is connected to, if the network provides it",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
G_PARAM_READWRITE |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
properties[PROP_STATE] =
g_param_spec_enum ("state",
@@ -319,9 +319,33 @@ calls_call_set_id (CallsCall *self,
const char *
calls_call_get_name (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_name (self);
return priv->name;
}
/**
* calls_call_set_name:
* @self: a #CallsCall
* @name: the name to set
*
* Sets the name of the call as provided by the network.
*/
void
calls_call_set_name (CallsCall *self,
const char *name)
{
CallsCallPrivate *priv = calls_call_get_instance_private (self);
g_return_if_fail (CALLS_IS_CALL (self));
g_clear_pointer (&priv->name, g_free);
if (name)
priv->name = g_strdup (name);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]);
}
/**

View File

@@ -51,7 +51,6 @@ struct _CallsCallClass
{
GObjectClass parent_iface;
const char *(*get_name) (CallsCall *self);
const char *(*get_protocol) (CallsCall *self);
void (*answer) (CallsCall *self);
void (*hang_up) (CallsCall *self);
@@ -63,6 +62,8 @@ 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);
void calls_call_set_name (CallsCall *self,
const char *name);
CallsCallState calls_call_get_state (CallsCall *self);
void calls_call_set_state (CallsCall *self,
CallsCallState state);