mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-04 20:07:36 +00:00
call: Move name property to base class
This let's us avoid some duplication in the derived classes.
This commit is contained in:
parent
a1fefcdbac
commit
dbfa593a07
5 changed files with 37 additions and 122 deletions
|
@ -35,7 +35,6 @@ struct _CallsOfonoCall
|
|||
{
|
||||
GObject parent_instance;
|
||||
GDBOVoiceCall *voice_call;
|
||||
gchar *name;
|
||||
gchar *disconnect_reason;
|
||||
};
|
||||
|
||||
|
@ -48,7 +47,6 @@ G_DEFINE_TYPE_WITH_CODE (CallsOfonoCall, calls_ofono_call, CALLS_TYPE_CALL,
|
|||
enum {
|
||||
PROP_0,
|
||||
PROP_VOICE_CALL,
|
||||
PROP_PROPERTIES,
|
||||
PROP_LAST_PROP,
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
@ -59,14 +57,6 @@ enum {
|
|||
};
|
||||
static guint signals [SIGNAL_LAST_SIGNAL];
|
||||
|
||||
static const char *
|
||||
calls_ofono_call_get_name (CallsCall *call)
|
||||
{
|
||||
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
||||
|
||||
return self->name;
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_ofono_call_get_protocol (CallsCall *call)
|
||||
{
|
||||
|
@ -153,28 +143,6 @@ calls_ofono_call_send_dtmf_tone (CallsCall *call, gchar key)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
set_properties (CallsOfonoCall *self,
|
||||
GVariant *call_props)
|
||||
{
|
||||
CallsCallState state;
|
||||
const char *id = NULL;
|
||||
const char *str = NULL;
|
||||
|
||||
g_return_if_fail (call_props != NULL);
|
||||
|
||||
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);
|
||||
g_return_if_fail (str != NULL);
|
||||
if (calls_call_state_parse_nick (&state, str))
|
||||
calls_call_set_state (CALLS_CALL (self), state);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -189,10 +157,6 @@ set_property (GObject *object,
|
|||
(&self->voice_call, GDBO_VOICE_CALL (g_value_get_object (value)));
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
set_properties (self, g_value_get_variant (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -280,7 +244,6 @@ finalize (GObject *object)
|
|||
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
|
||||
|
||||
g_free (self->disconnect_reason);
|
||||
g_free (self->name);
|
||||
|
||||
G_OBJECT_CLASS (calls_ofono_call_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -298,7 +261,6 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
|
|||
object_class->dispose = dispose;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
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;
|
||||
call_class->hang_up = calls_ofono_call_hang_up;
|
||||
|
@ -312,15 +274,6 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
|
|||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (object_class, PROP_VOICE_CALL, props[PROP_VOICE_CALL]);
|
||||
|
||||
props[PROP_PROPERTIES] =
|
||||
g_param_spec_variant ("properties",
|
||||
"Properties",
|
||||
"The a{sv} dictionary of properties for the voice call object",
|
||||
G_VARIANT_TYPE_ARRAY,
|
||||
NULL,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (object_class, PROP_PROPERTIES, props[PROP_PROPERTIES]);
|
||||
|
||||
signals[SIGNAL_TONE] =
|
||||
g_signal_newv ("tone",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
|
@ -355,8 +308,6 @@ calls_ofono_call_new (GDBOVoiceCall *voice_call,
|
|||
g_return_val_if_fail (GDBO_IS_VOICE_CALL (voice_call), 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);
|
||||
|
||||
|
@ -374,7 +325,7 @@ calls_ofono_call_new (GDBOVoiceCall *voice_call,
|
|||
"voice-call", voice_call,
|
||||
"properties", call_props,
|
||||
"id", id,
|
||||
//"name", name,
|
||||
"name", name,
|
||||
"inbound", inbound,
|
||||
"state", state,
|
||||
NULL);
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -11,18 +11,9 @@
|
|||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_NAME,
|
||||
PROP_LAST_PROP,
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
||||
struct _CallsMockCall
|
||||
{
|
||||
CallsCall parent_instance;
|
||||
|
||||
char *display_name;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CallsMockCall, calls_mock_call, CALLS_TYPE_CALL)
|
||||
|
@ -48,58 +39,19 @@ calls_mock_call_hang_up (CallsCall *call)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_mock_call_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
CallsMockCall *self = CALLS_MOCK_CALL (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_NAME:
|
||||
g_value_set_string (value, self->display_name);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_mock_call_finalize (GObject *object)
|
||||
{
|
||||
CallsMockCall *self = CALLS_MOCK_CALL (object);
|
||||
|
||||
g_free (self->display_name);
|
||||
|
||||
G_OBJECT_CLASS (calls_mock_call_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_mock_call_class_init (CallsMockCallClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
CallsCallClass *call_class = CALLS_CALL_CLASS (klass);
|
||||
|
||||
call_class->answer = calls_mock_call_answer;
|
||||
call_class->hang_up = calls_mock_call_hang_up;
|
||||
|
||||
object_class->get_property = calls_mock_call_get_property;
|
||||
object_class->finalize = calls_mock_call_finalize;
|
||||
|
||||
g_object_class_override_property (object_class,
|
||||
PROP_NAME,
|
||||
"name");
|
||||
props[PROP_NAME] = g_object_class_find_property (object_class, "name");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_mock_call_init (CallsMockCall *self)
|
||||
{
|
||||
self->display_name = g_strdup ("John Doe");
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,18 +61,7 @@ calls_mock_call_new (void)
|
|||
return g_object_new (CALLS_TYPE_MOCK_CALL,
|
||||
"inbound", TRUE,
|
||||
"id", "0800 1234",
|
||||
"name", "John Doe",
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
calls_mock_call_set_name (CallsMockCall *self,
|
||||
const char *name)
|
||||
{
|
||||
g_return_if_fail (CALLS_IS_MOCK_CALL (self));
|
||||
|
||||
g_free (self->display_name);
|
||||
self->display_name = g_strdup (name);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NAME]);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,5 @@ G_DECLARE_FINAL_TYPE (CallsMockCall, calls_mock_call, CALLS, MOCK_CALL, CallsCal
|
|||
CallsMockCall *calls_mock_call_new (void);
|
||||
void calls_mock_call_set_id (CallsMockCall *self,
|
||||
const char *id);
|
||||
void calls_mock_call_set_name (CallsMockCall *self,
|
||||
const char *name);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
Loading…
Reference in a new issue