[calls] ui-call-data: Provide API to get the name of the origin used
- From: Evangelos Ribeiro Tzaras <devrtz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [calls] ui-call-data: Provide API to get the name of the origin used
- Date: Fri, 4 Mar 2022 17:38:07 +0000 (UTC)
commit 7e538d736e7d97560135cdf8d9822b22abfb54fc
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date: Thu Feb 10 10:12:16 2022 +0100
ui-call-data: Provide API to get the name of the origin used
This will be used as a fallback when displaying the call details (see #222).
src/calls-manager.c | 56 ++++++++++++++++++++++++++----------------------
src/calls-manager.h | 2 ++
src/calls-ui-call-data.c | 22 +++++++++++++++++++
src/calls-ui-call-data.h | 1 +
4 files changed, 55 insertions(+), 26 deletions(-)
---
diff --git a/src/calls-manager.c b/src/calls-manager.c
index d34c82ba..2afd9001 100644
--- a/src/calls-manager.c
+++ b/src/calls-manager.c
@@ -153,31 +153,6 @@ update_state_flags (CallsManager *self)
}
-static CallsOrigin *
-lookup_origin_by_id (CallsManager *self,
- const char *origin_id)
-{
- uint n_origins;
-
- g_assert (CALLS_IS_MANAGER (self));
-
- if (!origin_id || !*origin_id)
- goto out;
-
- n_origins = g_list_model_get_n_items (G_LIST_MODEL (self->origins));
- for (uint i = 0; i < n_origins; i++) {
- g_autoptr (CallsOrigin) origin =
- g_list_model_get_item (G_LIST_MODEL (self->origins), i);
- g_autofree char *id = calls_origin_get_id (origin);
-
- if (g_strcmp0 (id, origin_id) == 0)
- return origin;
- }
- out:
- return NULL;
-}
-
-
static void
on_dial_protocol_activated (GSimpleAction *action,
GVariant *parameter,
@@ -189,7 +164,7 @@ on_dial_protocol_activated (GSimpleAction *action,
g_autofree char *origin_id = NULL;
g_variant_get (parameter, "(ss)", &target, &origin_id);
- origin = lookup_origin_by_id (self, origin_id);
+ origin = calls_manager_get_origin_by_id (self, origin_id);
if (origin) {
calls_origin_dial (origin, target);
@@ -1132,3 +1107,32 @@ calls_manager_get_settings (CallsManager *self)
return self->settings;
}
+
+/**
+ * calls_manager_get_origin_by_id:
+ * @self: The #CallsManager
+ * @origin_id: The id to use for the lookup
+ *
+ * Returns: (transfer none): The #CallsOrigin if found, %NULL otherwise
+ */
+CallsOrigin *
+calls_manager_get_origin_by_id (CallsManager *self,
+ const char *origin_id)
+{
+ uint n_origins;
+
+ g_return_val_if_fail (CALLS_IS_MANAGER (self), NULL);
+ g_return_val_if_fail (origin_id && *origin_id, NULL);
+
+ n_origins = g_list_model_get_n_items (G_LIST_MODEL (self->origins));
+ for (uint i = 0; i < n_origins; i++) {
+ g_autoptr (CallsOrigin) origin =
+ g_list_model_get_item (G_LIST_MODEL (self->origins), i);
+ g_autofree char *id = calls_origin_get_id (origin);
+
+ if (g_strcmp0 (id, origin_id) == 0)
+ return origin;
+ }
+
+ return NULL;
+}
diff --git a/src/calls-manager.h b/src/calls-manager.h
index 0e33def8..9d1c9868 100644
--- a/src/calls-manager.h
+++ b/src/calls-manager.h
@@ -64,6 +64,8 @@ GListModel *calls_manager_get_origins (CallsManager *sel
GList *calls_manager_get_calls (CallsManager *self);
GListModel *calls_manager_get_suitable_origins (CallsManager *self,
const char *target);
+CallsOrigin *calls_manager_get_origin_by_id (CallsManager *self,
+ const char *origin_id);
const gchar *calls_manager_get_contact_name (CallsCall *call);
gboolean calls_manager_has_active_call (CallsManager *self);
void calls_manager_hang_up_all_calls (CallsManager *self);
diff --git a/src/calls-ui-call-data.c b/src/calls-ui-call-data.c
index 80432f48..b6ae0614 100644
--- a/src/calls-ui-call-data.c
+++ b/src/calls-ui-call-data.c
@@ -714,6 +714,28 @@ calls_ui_call_data_get_origin_id (CallsUiCallData *self)
return self->origin_id;
}
+/**
+ * calls_ui_call_data_dup_origin_name:
+ * @self: a #CallsUiCallData
+ *
+ * Returns: (transfer full): The name of the origin this call was placed from
+ * or %NULL, if unknown.
+ */
+char *
+calls_ui_call_data_dup_origin_name (CallsUiCallData *self)
+{
+ CallsOrigin *origin;
+ g_return_val_if_fail (CALLS_IS_UI_CALL_DATA (self), NULL);
+
+ origin = calls_manager_get_origin_by_id (calls_manager_get_default (),
+ self->origin_id);
+
+ if (origin)
+ return calls_origin_get_name (origin);
+
+ return NULL;
+}
+
/**
* calls_call_state_to_cui_call_state:
* @state: A #CallsCallState
diff --git a/src/calls-ui-call-data.h b/src/calls-ui-call-data.h
index 018fa841..4e1d5ad2 100644
--- a/src/calls-ui-call-data.h
+++ b/src/calls-ui-call-data.h
@@ -42,6 +42,7 @@ gboolean calls_ui_call_data_get_silenced (CallsUiCallData *
gboolean calls_ui_call_data_get_ui_active (CallsUiCallData *self);
CallsCallType calls_ui_call_data_get_call_type (CallsUiCallData *self);
const char *calls_ui_call_data_get_origin_id (CallsUiCallData *self);
+char *calls_ui_call_data_dup_origin_name (CallsUiCallData *self);
CuiCallState calls_call_state_to_cui_call_state (CallsCallState state);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]