mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-05 19:15:32 +00:00
parent
6a7fbf0b59
commit
9fe575053d
7 changed files with 267 additions and 41 deletions
|
@ -31,6 +31,7 @@
|
|||
#include "calls-encryption-indicator.h"
|
||||
#include "calls-ringer.h"
|
||||
#include "calls-record-store.h"
|
||||
#include "calls-contacts.h"
|
||||
#include "calls-call-window.h"
|
||||
#include "calls-main-window.h"
|
||||
#include "calls-application.h"
|
||||
|
@ -60,6 +61,7 @@ struct _CallsApplication
|
|||
CallsProvider *provider;
|
||||
CallsRinger *ringer;
|
||||
CallsRecordStore *record_store;
|
||||
CallsContacts *contacts;
|
||||
CallsMainWindow *main_window;
|
||||
CallsCallWindow *call_window;
|
||||
};
|
||||
|
@ -280,10 +282,14 @@ start_proper (CallsApplication *self)
|
|||
self->record_store = calls_record_store_new (self->provider);
|
||||
g_assert (self->record_store != NULL);
|
||||
|
||||
self->contacts = calls_contacts_new ();
|
||||
g_assert (self->contacts != NULL);
|
||||
|
||||
self->main_window = calls_main_window_new
|
||||
(gtk_app,
|
||||
self->provider,
|
||||
G_LIST_MODEL (self->record_store));
|
||||
G_LIST_MODEL (self->record_store),
|
||||
self->contacts);
|
||||
g_assert (self->main_window != NULL);
|
||||
|
||||
self->call_window = calls_call_window_new
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
#include "calls-call-record-row.h"
|
||||
#include "calls-vala.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
@ -47,6 +48,11 @@ struct _CallsCallRecordRow
|
|||
gulong end_notify_handler_id;
|
||||
guint date_change_timeout;
|
||||
|
||||
CallsContacts *contacts;
|
||||
CallsBestMatchView *contact_view;
|
||||
FolksIndividual *contact;
|
||||
gulong contact_notify_handler_id;
|
||||
|
||||
CallsNewCallBox *new_call;
|
||||
};
|
||||
|
||||
|
@ -56,6 +62,7 @@ G_DEFINE_TYPE (CallsCallRecordRow, calls_call_record_row, GTK_TYPE_BOX);
|
|||
enum {
|
||||
PROP_0,
|
||||
PROP_RECORD,
|
||||
PROP_CONTACTS,
|
||||
PROP_NEW_CALL,
|
||||
PROP_LAST_PROP,
|
||||
};
|
||||
|
@ -122,9 +129,9 @@ nice_time (GDateTime *t,
|
|||
|
||||
|
||||
static void
|
||||
update_time (CallsCallRecordRow *self,
|
||||
GDateTime *end,
|
||||
gboolean *final)
|
||||
update_time_text (CallsCallRecordRow *self,
|
||||
GDateTime *end,
|
||||
gboolean *final)
|
||||
{
|
||||
gchar *nice;
|
||||
nice_time (end, &nice, final);
|
||||
|
@ -204,7 +211,7 @@ date_change_cb (CallsCallRecordRow *self)
|
|||
NULL);
|
||||
g_assert (end != NULL);
|
||||
|
||||
update_time (self, end, &final);
|
||||
update_time_text (self, end, &final);
|
||||
g_date_time_unref (end);
|
||||
|
||||
if (final)
|
||||
|
@ -221,10 +228,10 @@ date_change_cb (CallsCallRecordRow *self)
|
|||
|
||||
|
||||
static void
|
||||
update (CallsCallRecordRow *self,
|
||||
gboolean inbound,
|
||||
GDateTime *answered,
|
||||
GDateTime *end)
|
||||
update_time (CallsCallRecordRow *self,
|
||||
gboolean inbound,
|
||||
GDateTime *answered,
|
||||
GDateTime *end)
|
||||
{
|
||||
gboolean missed = FALSE;
|
||||
gchar *type_icon_name;
|
||||
|
@ -233,7 +240,7 @@ update (CallsCallRecordRow *self,
|
|||
{
|
||||
gboolean time_final;
|
||||
|
||||
update_time (self, end, &time_final);
|
||||
update_time_text (self, end, &time_final);
|
||||
|
||||
if (!time_final && !self->date_change_timeout)
|
||||
{
|
||||
|
@ -258,9 +265,9 @@ update (CallsCallRecordRow *self,
|
|||
|
||||
|
||||
static void
|
||||
notify_cb (CallsCallRecordRow *self,
|
||||
GParamSpec *pspec,
|
||||
CallsCallRecord *record)
|
||||
notify_time_cb (CallsCallRecordRow *self,
|
||||
GParamSpec *pspec,
|
||||
CallsCallRecord *record)
|
||||
{
|
||||
gboolean inbound;
|
||||
GDateTime *answered;
|
||||
|
@ -272,7 +279,7 @@ notify_cb (CallsCallRecordRow *self,
|
|||
"end", &end,
|
||||
NULL);
|
||||
|
||||
update (self, inbound, answered, end);
|
||||
update_time (self, inbound, answered, end);
|
||||
|
||||
if (answered)
|
||||
{
|
||||
|
@ -287,6 +294,177 @@ notify_cb (CallsCallRecordRow *self,
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
setup_time (CallsCallRecordRow *self,
|
||||
gboolean inbound,
|
||||
GDateTime *answered,
|
||||
GDateTime *end)
|
||||
{
|
||||
if (!end)
|
||||
{
|
||||
self->end_notify_handler_id =
|
||||
g_signal_connect_swapped (self->record,
|
||||
"notify::end",
|
||||
G_CALLBACK (notify_time_cb),
|
||||
self);
|
||||
|
||||
if (!answered)
|
||||
{
|
||||
self->answered_notify_handler_id =
|
||||
g_signal_connect_swapped (self->record,
|
||||
"notify::answered",
|
||||
G_CALLBACK (notify_time_cb),
|
||||
self);
|
||||
}
|
||||
}
|
||||
|
||||
update_time (self, inbound, answered, end);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
update_target (CallsCallRecordRow *self)
|
||||
{
|
||||
if (self->contact)
|
||||
{
|
||||
const gchar *name =
|
||||
folks_individual_get_display_name (self->contact);
|
||||
|
||||
gtk_label_set_text (self->target, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *target;
|
||||
|
||||
g_object_get (G_OBJECT (self->record),
|
||||
"target", &target,
|
||||
NULL);
|
||||
|
||||
gtk_label_set_text (self->target, target);
|
||||
|
||||
g_free (target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline static void
|
||||
clear_contact (CallsCallRecordRow *self)
|
||||
{
|
||||
calls_clear_signal (self->contact,
|
||||
&self->contact_notify_handler_id);
|
||||
g_clear_object (&self->contact);
|
||||
}
|
||||
|
||||
|
||||
inline static void
|
||||
set_contact (CallsCallRecordRow *self,
|
||||
FolksIndividual *contact)
|
||||
{
|
||||
self->contact = contact;
|
||||
g_object_ref (contact);
|
||||
|
||||
self->contact_notify_handler_id =
|
||||
g_signal_connect_swapped (self->contact,
|
||||
"notify::display-name",
|
||||
G_CALLBACK (update_target),
|
||||
self);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
update_contact (CallsCallRecordRow *self)
|
||||
{
|
||||
FolksIndividual *best_match;
|
||||
|
||||
best_match = calls_best_match_view_get_best_match
|
||||
(self->contact_view);
|
||||
|
||||
if (best_match)
|
||||
{
|
||||
if (self->contact)
|
||||
{
|
||||
if (self->contact == best_match)
|
||||
{
|
||||
// No change
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Different best match object
|
||||
clear_contact (self);
|
||||
set_contact (self, best_match);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// New best match
|
||||
set_contact (self, best_match);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self->contact)
|
||||
{
|
||||
// Best match disappeared
|
||||
clear_contact (self);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No change
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
update_target (self);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
setup_contact_view (CallsCallRecordRow *self)
|
||||
{
|
||||
g_autofree gchar *target = NULL;
|
||||
EPhoneNumber *phone_number;
|
||||
GError *error = NULL;
|
||||
|
||||
// Get the target number
|
||||
g_object_get (G_OBJECT (self->record),
|
||||
"target", &target,
|
||||
NULL);
|
||||
g_assert (target != NULL);
|
||||
|
||||
// Parse it
|
||||
phone_number = e_phone_number_from_string
|
||||
(target, NULL, &error);
|
||||
if (!phone_number)
|
||||
{
|
||||
g_warning ("Error parsing phone number `%s': %s",
|
||||
target, error->message);
|
||||
g_error_free (error);
|
||||
update_target (self);
|
||||
return;
|
||||
}
|
||||
|
||||
// Look up the search view
|
||||
self->contact_view = calls_contacts_lookup_phone_number
|
||||
(self->contacts, phone_number);
|
||||
g_assert (self->contact_view != NULL);
|
||||
g_clear_object (&self->contacts);
|
||||
e_phone_number_free (phone_number);
|
||||
|
||||
g_object_ref (self->contact_view);
|
||||
g_signal_connect_swapped (self->contact_view,
|
||||
"notify::best-match",
|
||||
G_CALLBACK (update_contact),
|
||||
self);
|
||||
|
||||
update_contact (self);
|
||||
if (!self->contact)
|
||||
{
|
||||
update_target (self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -301,6 +479,11 @@ set_property (GObject *object,
|
|||
CALLS_CALL_RECORD (g_value_get_object (value)));
|
||||
break;
|
||||
|
||||
case PROP_CONTACTS:
|
||||
g_set_object (&self->contacts,
|
||||
CALLS_CONTACTS (g_value_get_object (value)));
|
||||
break;
|
||||
|
||||
case PROP_NEW_CALL:
|
||||
g_set_object (&self->new_call,
|
||||
CALLS_NEW_CALL_BOX (g_value_get_object (value)));
|
||||
|
@ -318,43 +501,22 @@ constructed (GObject *object)
|
|||
{
|
||||
GObjectClass *obj_class = g_type_class_peek (G_TYPE_OBJECT);
|
||||
CallsCallRecordRow *self = CALLS_CALL_RECORD_ROW (object);
|
||||
gchar *target;
|
||||
gboolean inbound;
|
||||
GDateTime *answered;
|
||||
GDateTime *end;
|
||||
|
||||
g_object_get (G_OBJECT (self->record),
|
||||
"target", &target,
|
||||
"inbound", &inbound,
|
||||
"answered", &answered,
|
||||
"end", &end,
|
||||
NULL);
|
||||
|
||||
gtk_label_set_text (self->target, target);
|
||||
g_free (target);
|
||||
|
||||
if (!end)
|
||||
{
|
||||
self->end_notify_handler_id =
|
||||
g_signal_connect_swapped (self->record,
|
||||
"notify::end",
|
||||
G_CALLBACK (notify_cb),
|
||||
self);
|
||||
|
||||
if (!answered)
|
||||
{
|
||||
self->answered_notify_handler_id =
|
||||
g_signal_connect_swapped (self->record,
|
||||
"notify::answered",
|
||||
G_CALLBACK (notify_cb),
|
||||
self);
|
||||
}
|
||||
}
|
||||
|
||||
update (self, inbound, answered, end);
|
||||
setup_time (self, inbound, answered, end);
|
||||
calls_date_time_unref (answered);
|
||||
calls_date_time_unref (end);
|
||||
|
||||
setup_contact_view (self);
|
||||
|
||||
obj_class->constructed (object);
|
||||
}
|
||||
|
||||
|
@ -387,6 +549,10 @@ dispose (GObject *object)
|
|||
|
||||
g_clear_object (&self->new_call);
|
||||
|
||||
g_clear_object (&self->contacts);
|
||||
g_clear_object (&self->contact_view);
|
||||
clear_contact (self);
|
||||
|
||||
calls_clear_source (&self->date_change_timeout);
|
||||
calls_clear_signal (self->record, &self->answered_notify_handler_id);
|
||||
calls_clear_signal (self->record, &self->end_notify_handler_id);
|
||||
|
@ -414,6 +580,13 @@ calls_call_record_row_class_init (CallsCallRecordRowClass *klass)
|
|||
CALLS_TYPE_CALL_RECORD,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
props[PROP_CONTACTS] =
|
||||
g_param_spec_object ("contacts",
|
||||
_("Contacts"),
|
||||
_("Interface for libfolks"),
|
||||
CALLS_TYPE_CONTACTS,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
props[PROP_NEW_CALL] =
|
||||
g_param_spec_object ("new-call",
|
||||
_("New call"),
|
||||
|
@ -442,10 +615,12 @@ calls_call_record_row_init (CallsCallRecordRow *self)
|
|||
|
||||
CallsCallRecordRow *
|
||||
calls_call_record_row_new (CallsCallRecord *record,
|
||||
CallsContacts *contacts,
|
||||
CallsNewCallBox *new_call)
|
||||
{
|
||||
return g_object_new (CALLS_TYPE_CALL_RECORD_ROW,
|
||||
"record", record,
|
||||
"contacts", contacts,
|
||||
"new-call", new_call,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define CALLS_CALL_RECORD_ROW_H__
|
||||
|
||||
#include "calls-call-record.h"
|
||||
#include "calls-contacts.h"
|
||||
#include "calls-new-call-box.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
@ -38,6 +39,7 @@ G_DECLARE_FINAL_TYPE (CallsCallRecordRow, calls_call_record_row,
|
|||
CALLS, CALL_RECORD_ROW, GtkBox);
|
||||
|
||||
CallsCallRecordRow *calls_call_record_row_new (CallsCallRecord *record,
|
||||
CallsContacts *contacts,
|
||||
CallsNewCallBox *new_call);
|
||||
CallsCallRecord * calls_call_record_row_get_record (CallsCallRecordRow *self);
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ struct _CallsHistoryBox
|
|||
GListModel *model;
|
||||
gulong model_changed_handler_id;
|
||||
|
||||
CallsContacts *contacts;
|
||||
|
||||
CallsNewCallBox *new_call;
|
||||
};
|
||||
|
||||
|
@ -52,6 +54,7 @@ G_DEFINE_TYPE (CallsHistoryBox, calls_history_box, GTK_TYPE_STACK);
|
|||
enum {
|
||||
PROP_0,
|
||||
PROP_MODEL,
|
||||
PROP_CONTACTS,
|
||||
PROP_NEW_CALL,
|
||||
PROP_LAST_PROP,
|
||||
};
|
||||
|
@ -107,7 +110,9 @@ static GtkWidget *
|
|||
create_row_cb (CallsCallRecord *record,
|
||||
CallsHistoryBox *self)
|
||||
{
|
||||
return GTK_WIDGET (calls_call_record_row_new (record, self->new_call));
|
||||
return GTK_WIDGET (calls_call_record_row_new (record,
|
||||
self->contacts,
|
||||
self->new_call));
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,6 +131,11 @@ set_property (GObject *object,
|
|||
G_LIST_MODEL (g_value_get_object (value)));
|
||||
break;
|
||||
|
||||
case PROP_CONTACTS:
|
||||
g_set_object (&self->contacts,
|
||||
CALLS_CONTACTS (g_value_get_object (value)));
|
||||
break;
|
||||
|
||||
case PROP_NEW_CALL:
|
||||
g_set_object (&self->new_call,
|
||||
CALLS_NEW_CALL_BOX (g_value_get_object (value)));
|
||||
|
@ -175,6 +185,7 @@ dispose (GObject *object)
|
|||
CallsHistoryBox *self = CALLS_HISTORY_BOX (object);
|
||||
|
||||
g_clear_object (&self->new_call);
|
||||
g_clear_object (&self->contacts);
|
||||
g_clear_object (&self->model);
|
||||
|
||||
parent_class->dispose (object);
|
||||
|
@ -198,6 +209,13 @@ calls_history_box_class_init (CallsHistoryBoxClass *klass)
|
|||
G_TYPE_LIST_MODEL,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
props[PROP_CONTACTS] =
|
||||
g_param_spec_object ("contacts",
|
||||
_("Contacts"),
|
||||
_("Interface for libfolks"),
|
||||
CALLS_TYPE_CONTACTS,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
props[PROP_NEW_CALL] =
|
||||
g_param_spec_object ("new-call",
|
||||
_("New call"),
|
||||
|
@ -222,10 +240,12 @@ calls_history_box_init (CallsHistoryBox *self)
|
|||
|
||||
CallsHistoryBox *
|
||||
calls_history_box_new (GListModel *model,
|
||||
CallsContacts *contacts,
|
||||
CallsNewCallBox *new_call)
|
||||
{
|
||||
return g_object_new (CALLS_TYPE_HISTORY_BOX,
|
||||
"model", model,
|
||||
"contacts", contacts,
|
||||
"new-call", new_call,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define CALLS_HISTORY_BOX_H__
|
||||
|
||||
#include "calls-new-call-box.h"
|
||||
#include "calls-contacts.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
|
@ -39,6 +40,7 @@ G_BEGIN_DECLS
|
|||
G_DECLARE_FINAL_TYPE (CallsHistoryBox, calls_history_box, CALLS, HISTORY_BOX, GtkStack);
|
||||
|
||||
CallsHistoryBox * calls_history_box_new (GListModel *model,
|
||||
CallsContacts *contacts,
|
||||
CallsNewCallBox *new_call);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -45,6 +45,7 @@ struct _CallsMainWindow
|
|||
|
||||
CallsProvider *provider;
|
||||
GListModel *record_store;
|
||||
CallsContacts *contacts;
|
||||
|
||||
GtkRevealer *info_revealer;
|
||||
guint info_timeout;
|
||||
|
@ -67,6 +68,7 @@ enum {
|
|||
PROP_0,
|
||||
PROP_PROVIDER,
|
||||
PROP_RECORD_STORE,
|
||||
PROP_CONTACTS,
|
||||
PROP_LAST_PROP,
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
@ -208,6 +210,11 @@ set_property (GObject *object,
|
|||
G_LIST_MODEL (g_value_get_object (value)));
|
||||
break;
|
||||
|
||||
case PROP_CONTACTS:
|
||||
g_set_object (&self->contacts,
|
||||
CALLS_CONTACTS (g_value_get_object (value)));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -267,6 +274,7 @@ constructed (GObject *object)
|
|||
|
||||
// Add call records
|
||||
history = calls_history_box_new (self->record_store,
|
||||
self->contacts,
|
||||
self->new_call);
|
||||
widget = GTK_WIDGET (history);
|
||||
gtk_stack_add_titled (self->main_stack, widget,
|
||||
|
@ -313,6 +321,7 @@ dispose (GObject *object)
|
|||
CallsMainWindow *self = CALLS_MAIN_WINDOW (object);
|
||||
|
||||
stop_info_timeout (self);
|
||||
g_clear_object (&self->contacts);
|
||||
g_clear_object (&self->record_store);
|
||||
g_clear_object (&self->provider);
|
||||
|
||||
|
@ -362,6 +371,13 @@ calls_main_window_class_init (CallsMainWindowClass *klass)
|
|||
G_TYPE_LIST_MODEL,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
props[PROP_CONTACTS] =
|
||||
g_param_spec_object ("contacts",
|
||||
_("Contacts"),
|
||||
_("Interface for libfolks"),
|
||||
CALLS_TYPE_CONTACTS,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
|
||||
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
||||
|
||||
|
||||
|
@ -391,16 +407,19 @@ calls_main_window_init (CallsMainWindow *self)
|
|||
CallsMainWindow *
|
||||
calls_main_window_new (GtkApplication *application,
|
||||
CallsProvider *provider,
|
||||
GListModel *record_store)
|
||||
GListModel *record_store,
|
||||
CallsContacts *contacts)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
|
||||
g_return_val_if_fail (CALLS_IS_PROVIDER (provider), NULL);
|
||||
g_return_val_if_fail (G_IS_LIST_MODEL (record_store), NULL);
|
||||
g_return_val_if_fail (CALLS_IS_CONTACTS (contacts), NULL);
|
||||
|
||||
return g_object_new (CALLS_TYPE_MAIN_WINDOW,
|
||||
"application", application,
|
||||
"provider", provider,
|
||||
"record-store", record_store,
|
||||
"contacts", contacts,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
#include "calls-provider.h"
|
||||
#include "calls-contacts.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -37,7 +38,8 @@ G_DECLARE_FINAL_TYPE (CallsMainWindow, calls_main_window, CALLS, MAIN_WINDOW, Gt
|
|||
|
||||
CallsMainWindow *calls_main_window_new (GtkApplication *application,
|
||||
CallsProvider *provider,
|
||||
GListModel *record_store);
|
||||
GListModel *record_store,
|
||||
CallsContacts *contacts);
|
||||
void calls_main_window_dial (CallsMainWindow *self,
|
||||
const gchar *target);
|
||||
|
||||
|
|
Loading…
Reference in a new issue