1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-11-16 16:56:09 +00:00

Convert calls call getters to readonly properties

This is part of a larger refactoring effort, with the goal to replace
all the get_*() member functions in provider abstraction interfaces with
GObject properties. See also: https://source.puri.sm/Librem5/calls/issues/6
This commit is contained in:
Daniel Abrecht 2020-02-22 23:55:45 +00:00 committed by Julian Sparber
parent 1f9859264d
commit a7a679c186
6 changed files with 178 additions and 160 deletions

View file

@ -48,40 +48,16 @@ G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, G_TYPE_OBJECT,
enum {
PROP_0,
PROP_NUMBER,
PROP_NUMBER_CONSTRUCTOR,
PROP_INBOUND_CONSTRUCTOR,
PROP_INBOUND,
PROP_LAST_PROP,
PROP_CALL_NUMBER,
PROP_CALL_INBOUND,
PROP_CALL_STATE,
PROP_CALL_NAME,
PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];
static const gchar *
get_number (CallsCall *iface)
{
CallsDummyCall *self;
g_return_val_if_fail (CALLS_IS_DUMMY_CALL (iface), NULL);
self = CALLS_DUMMY_CALL (iface);
return self->number;
}
static const gchar *
get_name (CallsCall *iface)
{
return NULL;
}
static CallsCallState
get_state (CallsCall *call)
{
CallsDummyCall *self;
g_return_val_if_fail (CALLS_IS_DUMMY_CALL (call), 0);
self = CALLS_DUMMY_CALL (call);
return self->state;
}
static void
change_state (CallsCall *call,
@ -96,6 +72,7 @@ change_state (CallsCall *call,
}
self->state = state;
g_object_notify (G_OBJECT (call), "state");
g_signal_emit_by_name (call,
"state-changed",
state,
@ -171,7 +148,7 @@ calls_dummy_call_new (const gchar *number,
g_return_val_if_fail (number != NULL, NULL);
return g_object_new (CALLS_TYPE_DUMMY_CALL,
"number", number,
"number-constructor", number,
"inbound-constructor", inbound,
NULL);
}
@ -186,7 +163,7 @@ set_property (GObject *object,
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
switch (property_id) {
case PROP_NUMBER:
case PROP_NUMBER_CONSTRUCTOR:
self->number = g_value_dup_string (value);
break;
@ -229,10 +206,22 @@ get_property (GObject *object,
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
switch (property_id) {
case PROP_INBOUND:
case PROP_CALL_INBOUND:
g_value_set_boolean (value, self->inbound);
break;
case PROP_CALL_NUMBER:
g_value_set_string (value, self->number);
break;
case PROP_CALL_STATE:
g_value_set_enum (value, self->state);
break;
case PROP_CALL_NAME:
g_value_set_string (value, NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -261,39 +250,34 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
object_class->constructed = constructed;
object_class->finalize = finalize;
props[PROP_NUMBER] =
g_param_spec_string ("number",
_("Number"),
_("The dialed number"),
g_object_class_install_property (
object_class,
PROP_NUMBER_CONSTRUCTOR,
g_param_spec_string ("number-constructor",
_("Number (constructor)"),
_("The dialed number (dummy class constructor)"),
"+441234567890",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_NUMBER,
props[PROP_NUMBER]);
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
props[PROP_INBOUND_CONSTRUCTOR] =
g_object_class_install_property (
object_class,
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]);
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_override_property (object_class, PROP_CALL_NUMBER, "number");
g_object_class_override_property (object_class, PROP_CALL_INBOUND, "inbound");
g_object_class_override_property (object_class, PROP_CALL_STATE, "state");
g_object_class_override_property (object_class, PROP_CALL_NAME, "name");
props[PROP_INBOUND] =
g_param_spec_boolean ("inbound",
_("Inbound"),
_("Whether the call is inbound"),
FALSE,
G_PARAM_READABLE | G_PARAM_CONSTRUCT);
g_object_class_override_property (object_class, PROP_INBOUND, "inbound");
}
static void
calls_dummy_call_call_interface_init (CallsCallInterface *iface)
{
iface->get_number = get_number;
iface->get_name = get_name;
iface->get_state = get_state;
iface->answer = answer;
iface->hang_up = hang_up;
iface->tone_start = tone_start;

View file

@ -52,33 +52,14 @@ G_DEFINE_TYPE_WITH_CODE (CallsMMCall, calls_mm_call, G_TYPE_OBJECT,
enum {
PROP_0,
PROP_MM_CALL,
PROP_INBOUND,
PROP_CALL_NUMBER,
PROP_CALL_INBOUND,
PROP_CALL_STATE,
PROP_CALL_NAME,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
static const gchar *
get_name (CallsCall *call)
{
return NULL;
}
static const gchar *
get_number (CallsCall *call)
{
CallsMMCall *self = CALLS_MM_CALL (call);
return self->number->str;
}
static CallsCallState
get_state (CallsCall *call)
{
CallsMMCall *self = CALLS_MM_CALL (call);
return self->state;
}
static void
@ -93,6 +74,7 @@ change_state (CallsMMCall *self,
}
self->state = state;
g_object_notify (G_OBJECT (self), "state");
g_signal_emit_by_name (CALLS_CALL (self),
"state-changed",
state,
@ -117,7 +99,7 @@ struct CallsMMCallStateReasonMap
static const struct CallsMMCallStateReasonMap STATE_REASON_MAP[] = {
#define row(ENUMVALUE,DESCRIPTION) \
{ MM_CALL_STATE_REASON_##ENUMVALUE, DESCRIPTION } \
{ MM_CALL_STATE_REASON_##ENUMVALUE, DESCRIPTION }
row (UNKNOWN, N_("Call disconnected (unknown reason)")),
row (OUTGOING_STARTED, N_("Outgoing call started")),
@ -348,12 +330,24 @@ get_property (GObject *object,
CallsMMCall *self = CALLS_MM_CALL (object);
switch (property_id) {
case PROP_INBOUND:
case PROP_CALL_INBOUND:
g_value_set_boolean (value,
mm_call_get_direction (self->mm_call)
== MM_CALL_DIRECTION_INCOMING);
break;
case PROP_CALL_NAME:
g_value_set_string(value, NULL);
break;
case PROP_CALL_NUMBER:
g_value_set_string(value, self->number->str);
break;
case PROP_CALL_STATE:
g_value_set_enum (value, self->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -395,23 +389,20 @@ calls_mm_call_class_init (CallsMMCallClass *klass)
object_class->dispose = dispose;
object_class->finalize = finalize;
props[PROP_MM_CALL] =
g_object_class_install_property (
object_class,
PROP_MM_CALL,
g_param_spec_object ("mm-call",
_("MM call"),
_("A libmm-glib proxy object for the underlying call object"),
MM_TYPE_CALL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_MM_CALL,
props[PROP_MM_CALL]);
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_override_property (object_class, PROP_CALL_NUMBER, "number");
g_object_class_override_property (object_class, PROP_CALL_INBOUND, "inbound");
g_object_class_override_property (object_class, PROP_CALL_STATE, "state");
g_object_class_override_property (object_class, PROP_CALL_NAME, "name");
props[PROP_INBOUND] =
g_param_spec_boolean ("inbound",
_("Inbound"),
_("Whether the call is inbound"),
FALSE,
G_PARAM_READABLE | G_PARAM_CONSTRUCT);
g_object_class_override_property (object_class, PROP_INBOUND, "inbound");
}
@ -424,9 +415,6 @@ calls_mm_call_message_source_interface_init (CallsCallInterface *iface)
static void
calls_mm_call_call_interface_init (CallsCallInterface *iface)
{
iface->get_number = get_number;
iface->get_name = get_name;
iface->get_state = get_state;
iface->answer = answer;
iface->hang_up = hang_up;
iface->tone_start = tone_start;

View file

@ -38,6 +38,10 @@ 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 (CallsCallInterface *iface);
@ -53,9 +57,14 @@ enum {
PROP_0,
PROP_VOICE_CALL,
PROP_PROPERTIES,
PROP_CALL_NUMBER,
PROP_CALL_INBOUND,
PROP_CALL_STATE,
PROP_CALL_NAME,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
enum {
SIGNAL_TONE,
@ -63,26 +72,6 @@ enum {
};
static guint signals [SIGNAL_LAST_SIGNAL];
#define DEFINE_GET_BODY(member) \
get_##member (CallsCall *iface) \
{ \
CallsOfonoCall *self = CALLS_OFONO_CALL (iface); \
return self-> member ; \
}
static const gchar *
DEFINE_GET_BODY(number);
static const gchar *
DEFINE_GET_BODY(name);
static CallsCallState
DEFINE_GET_BODY(state);
#undef DEFINE_GET_BODY
static void
change_state (CallsOfonoCall *self,
CallsCallState state)
@ -95,6 +84,7 @@ change_state (CallsOfonoCall *self,
}
self->state = state;
g_object_notify (G_OBJECT (self), "state");
g_signal_emit_by_name (CALLS_CALL (self),
"state-changed",
state,
@ -195,6 +185,11 @@ set_properties (CallsOfonoCall *self,
g_variant_lookup (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;
}
}
@ -222,6 +217,36 @@ set_property (GObject *object,
}
}
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
switch (property_id) {
case PROP_CALL_INBOUND:
g_value_set_boolean (value, self->state);
break;
case PROP_CALL_NAME:
g_value_set_string(value, self->name);
break;
case PROP_CALL_NUMBER:
g_value_set_string(value, self->number);
break;
case PROP_CALL_STATE:
g_value_set_enum (value, self->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
property_changed_cb (CallsOfonoCall *self,
@ -324,27 +349,34 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
GType tone_arg_types = G_TYPE_CHAR;
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
props[PROP_VOICE_CALL] =
g_object_class_install_property (
object_class,
PROP_VOICE_CALL,
g_param_spec_object ("voice-call",
_("Voice call"),
_("A GDBO proxy object for the underlying call object"),
GDBO_TYPE_VOICE_CALL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
props[PROP_PROPERTIES] =
g_object_class_install_property (
object_class,
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_properties (object_class, PROP_LAST_PROP, props);
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_override_property (object_class, PROP_CALL_NUMBER, "number");
g_object_class_override_property (object_class, PROP_CALL_INBOUND, "inbound");
g_object_class_override_property (object_class, PROP_CALL_STATE, "state");
g_object_class_override_property (object_class, PROP_CALL_NAME, "name");
signals[SIGNAL_TONE] =
g_signal_newv ("tone",
@ -365,9 +397,6 @@ calls_ofono_call_message_source_interface_init (CallsCallInterface *iface)
static void
calls_ofono_call_call_interface_init (CallsCallInterface *iface)
{
iface->get_number = get_number;
iface->get_name = get_name;
iface->get_state = get_state;
iface->answer = answer;
iface->hang_up = hang_up;
iface->tone_start = tone_start;

View file

@ -101,13 +101,6 @@ calls_call_state_parse_nick (CallsCallState *state,
G_DEFINE_INTERFACE (CallsCall, calls_call, CALLS_TYPE_MESSAGE_SOURCE);
enum {
PROP_0,
PROP_INBOUND,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
enum {
SIGNAL_STATE_CHANGED,
SIGNAL_LAST_SIGNAL,
@ -124,14 +117,38 @@ calls_call_default_init (CallsCallInterface *iface)
CALLS_TYPE_CALL_STATE
};
props[PROP_INBOUND] =
g_object_interface_install_property (
iface,
g_param_spec_boolean ("inbound",
_("Inbound"),
_("Whether the call is inbound"),
FALSE,
G_PARAM_READABLE);
G_PARAM_READABLE));
g_object_interface_install_property (iface, props[PROP_INBOUND]);
g_object_interface_install_property (
iface,
g_param_spec_string ("number",
_("Number"),
_("The number the call is connected to if known"),
NULL,
G_PARAM_READABLE));
g_object_interface_install_property (
iface,
g_param_spec_string ("name",
_("Name"),
_("The name of the party the call is connected to, if the network provides it"),
NULL,
G_PARAM_READABLE));
g_object_interface_install_property (
iface,
g_param_spec_enum ("state",
_("State"),
_("The current state of the call"),
CALLS_TYPE_CALL_STATE,
CALLS_CALL_STATE_ACTIVE,
G_PARAM_READABLE));
/**
* CallsCall::state-changed:
@ -152,9 +169,8 @@ calls_call_default_init (CallsCallInterface *iface)
}
#define DEFINE_CALL_FUNC(function,rettype,errval) \
CALLS_DEFINE_IFACE_FUNC(call, Call, CALL, \
function, rettype, errval)
#define DEFINE_CALL_GETTER(prop,rettype,errval) \
CALLS_DEFINE_IFACE_GETTER(call, Call, CALL, prop, rettype, errval)
#define DEFINE_CALL_FUNC_VOID(function) \
CALLS_DEFINE_IFACE_FUNC_VOID(call, Call, CALL, function)
@ -170,7 +186,7 @@ calls_call_default_init (CallsCallInterface *iface)
*
* Returns: the number, or NULL
*/
DEFINE_CALL_FUNC(get_number, const gchar *, NULL);
DEFINE_CALL_GETTER(number, const gchar *, NULL);
/**
* calls_call_get_name:
@ -181,7 +197,7 @@ DEFINE_CALL_FUNC(get_number, const gchar *, NULL);
*
* Returns: the number, or NULL
*/
DEFINE_CALL_FUNC(get_name, const gchar *, NULL);
DEFINE_CALL_GETTER(name, const gchar *, NULL);
/**
* calls_call_get_state:
@ -191,7 +207,7 @@ DEFINE_CALL_FUNC(get_name, const gchar *, NULL);
*
* Returns: the state
*/
DEFINE_CALL_FUNC(get_state, CallsCallState, ((CallsCallState)0));
DEFINE_CALL_GETTER(state, CallsCallState, ((CallsCallState)0));
/**
* calls_call_answer:
@ -220,20 +236,7 @@ DEFINE_CALL_FUNC_VOID(hang_up);
*
* Returns: TRUE if inbound, FALSE if outbound.
*/
gboolean
calls_call_get_inbound (CallsCall *self)
{
gboolean inbound;
g_return_val_if_fail (CALLS_IS_CALL (self), FALSE);
g_object_get (self,
"inbound", &inbound,
NULL);
return inbound;
}
DEFINE_CALL_GETTER(inbound, gboolean, FALSE);
static inline gboolean
tone_key_is_valid (gchar key)

View file

@ -53,9 +53,6 @@ struct _CallsCallInterface
{
GTypeInterface parent_iface;
const gchar * (*get_number) (CallsCall *self);
const gchar * (*get_name) (CallsCall *self);
CallsCallState (*get_state) (CallsCall *self);
void (*answer) (CallsCall *self);
void (*hang_up) (CallsCall *self);
void (*tone_start) (CallsCall *self,

View file

@ -70,6 +70,23 @@ G_BEGIN_DECLS
CALLS_DEFINE_IFACE_FUNC_VOID_BASE(calls,iface,Calls,Iface,CALLS,IFACE,function)
/*
* For defining simple getters for properties
*/
#define CALLS_DEFINE_IFACE_GETTER_BASE(prefix,iface,Prefix,Iface,PREFIX,IFACE,prop,rettype,errval) \
rettype \
prefix##_##iface##_get_ ## prop (Prefix##Iface *self) \
{ \
rettype result; \
g_return_val_if_fail (PREFIX##_IS_##IFACE (self), errval); \
g_object_get (self, #prop, &result, NULL); \
return result; \
}
#define CALLS_DEFINE_IFACE_GETTER(iface,Iface,IFACE,prop,rettype,errval) \
CALLS_DEFINE_IFACE_GETTER_BASE(calls,iface,Calls,Iface,CALLS,IFACE,prop,rettype,errval)
#define CALLS_SET_PTR_PROPERTY(ptr,new_value) \
g_free (ptr); \