mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-12 07:37:35 +00:00
Implement contact name lookup for call display
* src/calls-manager.h: Add lookup function to header * src/calls-manager.c: Implement lookup function to be used for the call history, call notifier and call display * src/calls-call-holder.c: Use calls_manager_get_contact_name () * src/calls-notifier.c: Use calls_manager_get_contact_name ()
This commit is contained in:
parent
0f0d10e3f2
commit
9fc8ec5e1a
4 changed files with 50 additions and 29 deletions
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
#include "calls-call-holder.h"
|
||||
#include "calls-manager.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
@ -90,8 +91,8 @@ calls_call_holder_get_selector_item (CallsCallHolder *holder)
|
|||
static void
|
||||
set_call (CallsCallHolder *self, CallsCall *call)
|
||||
{
|
||||
CallsParty *party
|
||||
= calls_party_new (NULL, calls_call_get_number (call));
|
||||
CallsParty *party = calls_party_new (calls_manager_get_contact_name (call),
|
||||
calls_call_get_number (call));
|
||||
|
||||
self->data = calls_call_data_new (call, party);
|
||||
g_object_unref (party);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "calls-manager.h"
|
||||
#include "calls-contacts.h"
|
||||
#include "enum-types.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
@ -40,6 +41,7 @@ struct _CallsManager
|
|||
};
|
||||
|
||||
G_DEFINE_TYPE (CallsManager, calls_manager, G_TYPE_OBJECT);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EPhoneNumber, e_phone_number_free)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
@ -518,3 +520,43 @@ calls_manager_set_default_origin (CallsManager *self,
|
|||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_DEFAULT_ORIGIN]);
|
||||
}
|
||||
|
||||
/**
|
||||
* calls_manager_get_contact_name:
|
||||
* @call: a #CallsCall
|
||||
*
|
||||
* Looks up the contact name for @call. If the lookup
|
||||
* succeeds, the contact name will be returned. NULL if
|
||||
* no match has been found in the contact list.
|
||||
* If no number is associated with the @call, then
|
||||
* a translatable string will be returned.
|
||||
*
|
||||
* Returns: (transfer none): The caller's name, a string representing
|
||||
* an unknown caller or %NULL
|
||||
*/
|
||||
const gchar *
|
||||
calls_manager_get_contact_name (CallsCall *call)
|
||||
{
|
||||
g_autoptr (EPhoneNumber) phone_number = NULL;
|
||||
g_autoptr (GError) err = NULL;
|
||||
const gchar *number;
|
||||
CallsBestMatch *match;
|
||||
|
||||
number = calls_call_get_number (call);
|
||||
if (!number || g_strcmp0 (number, "") == 0)
|
||||
return _("Anonymous caller");
|
||||
|
||||
phone_number = e_phone_number_from_string (number, NULL, &err);
|
||||
if (!phone_number)
|
||||
{
|
||||
g_warning ("Failed to convert %s to a phone number: %s", number, err->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
match = calls_contacts_lookup_phone_number (calls_contacts_get_default (),
|
||||
phone_number);
|
||||
if (!match)
|
||||
return NULL;
|
||||
|
||||
return calls_best_match_get_name (match);
|
||||
}
|
||||
|
|
|
@ -60,5 +60,6 @@ void calls_manager_dial (CallsManager *self,
|
|||
CallsOrigin *calls_manager_get_default_origin (CallsManager *self);
|
||||
void calls_manager_set_default_origin (CallsManager *self,
|
||||
CallsOrigin *origin);
|
||||
const gchar *calls_manager_get_contact_name (CallsCall *call);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "calls-notifier.h"
|
||||
#include "calls-manager.h"
|
||||
#include "calls-contacts.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
@ -40,8 +39,6 @@ struct _CallsNotifier
|
|||
|
||||
G_DEFINE_TYPE (CallsNotifier, calls_notifier, G_TYPE_OBJECT);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EPhoneNumber, e_phone_number_free)
|
||||
|
||||
static void
|
||||
notify (CallsNotifier *self, CallsCall *call)
|
||||
{
|
||||
|
@ -49,35 +46,15 @@ notify (CallsNotifier *self, CallsCall *call)
|
|||
g_autoptr(GNotification) notification;
|
||||
g_autofree gchar *msg = NULL;
|
||||
g_autofree gchar *ref = NULL;
|
||||
g_autoptr(EPhoneNumber) phone_number = NULL;
|
||||
g_autoptr(GError) err = NULL;
|
||||
const char *number, *name;
|
||||
CallsBestMatch *match;
|
||||
const char *name;
|
||||
|
||||
notification = g_notification_new (_("Missed call"));
|
||||
|
||||
number = calls_call_get_number (call);
|
||||
if (!number)
|
||||
goto done;
|
||||
|
||||
phone_number = e_phone_number_from_string (number, NULL, &err);
|
||||
if (!phone_number)
|
||||
{
|
||||
g_warning ("Failed to convert %s to a phone number: %s", number, err->message);
|
||||
goto done;
|
||||
}
|
||||
|
||||
match = calls_contacts_lookup_phone_number (calls_contacts_get_default (), phone_number);
|
||||
if (!match)
|
||||
goto done;
|
||||
|
||||
name = calls_best_match_get_name (match);
|
||||
name = calls_manager_get_contact_name (call);
|
||||
if (name)
|
||||
msg = g_strdup_printf (_("Missed call from <b>%s</b>"), name);
|
||||
|
||||
done:
|
||||
if (msg == NULL)
|
||||
msg = g_strdup_printf (_("Missed call from unknown caller"));
|
||||
else
|
||||
msg = g_strdup_printf (_("Missed call from %s"), calls_call_get_number (call));
|
||||
|
||||
g_notification_set_body (notification, msg);
|
||||
ref = g_strdup_printf ("missed-call-%s", calls_call_get_number (call) ?: "unknown");
|
||||
|
|
Loading…
Reference in a new issue