blob: 87b6c13e7e6b3973240347769d1d2c437f833480 [file] [log] [blame]
Stepan Salenikovichd2cad062016-01-08 13:43:49 -05001/*
2 * Copyright (C) 2016 Savoir-faire Linux Inc.
3 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include "chatview.h"
21
22#include <gtk/gtk.h>
23#include <call.h>
24#include <callmodel.h>
25#include <contactmethod.h>
26#include <person.h>
27#include <media/media.h>
28#include <media/text.h>
29#include <media/textrecording.h>
30#include "ringnotify.h"
Stepan Salenikovich5039c9b2016-02-12 14:09:51 -050031#include "numbercategory.h"
Stepan Salenikovich1b7100a2016-02-19 11:50:46 -050032#include <QtCore/QDateTime>
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050033
Stepan Salenikovichce06adb2016-02-19 12:53:53 -050034static constexpr GdkRGBA RING_BLUE = {0.0508, 0.594, 0.676, 1.0}; // outgoing msg color: (13, 152, 173)
35
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050036struct _ChatView
37{
38 GtkBox parent;
39};
40
41struct _ChatViewClass
42{
43 GtkBoxClass parent_class;
44};
45
46typedef struct _ChatViewPrivate ChatViewPrivate;
47
48struct _ChatViewPrivate
49{
50 GtkWidget *textview_chat;
51 GtkWidget *button_chat_input;
52 GtkWidget *entry_chat_input;
53 GtkWidget *scrolledwindow_chat;
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -050054 GtkWidget *hbox_chat_info;
55 GtkWidget *label_peer;
56 GtkWidget *combobox_cm;
Stepan Salenikovich8043a562016-03-18 13:56:40 -040057 GtkWidget *button_close_chatview;
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050058
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -050059 /* only one of the three following pointers should be non void;
60 * either this is an in-call chat (and so the in-call chat APIs will be used)
61 * or it is an out of call chat (and so the account chat APIs will be used)
62 */
63 Call *call;
64 Person *person;
65 ContactMethod *cm;
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050066
67 QMetaObject::Connection new_message_connection;
68};
69
70G_DEFINE_TYPE_WITH_PRIVATE(ChatView, chat_view, GTK_TYPE_BOX);
71
72#define CHAT_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAT_VIEW_TYPE, ChatViewPrivate))
73
74enum {
75 NEW_MESSAGES_DISPLAYED,
Stepan Salenikovich8043a562016-03-18 13:56:40 -040076 HIDE_VIEW_CLICKED,
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050077 LAST_SIGNAL
78};
79
80static guint chat_view_signals[LAST_SIGNAL] = { 0 };
81
82static void
83chat_view_dispose(GObject *object)
84{
85 ChatView *view;
86 ChatViewPrivate *priv;
87
88 view = CHAT_VIEW(object);
89 priv = CHAT_VIEW_GET_PRIVATE(view);
90
91 QObject::disconnect(priv->new_message_connection);
92
93 G_OBJECT_CLASS(chat_view_parent_class)->dispose(object);
94}
95
96
97static void
98send_chat(G_GNUC_UNUSED GtkWidget *widget, ChatView *self)
99{
100 g_return_if_fail(IS_CHAT_VIEW(self));
101 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
102
103 /* make sure there is text to send */
104 const gchar *text = gtk_entry_get_text(GTK_ENTRY(priv->entry_chat_input));
105 if (text && strlen(text) > 0) {
106 QMap<QString, QString> messages;
107 messages["text/plain"] = text;
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500108
109 if (priv->call) {
110 // in call message
111 priv->call->addOutgoingMedia<Media::Text>()->send(messages);
112 } else if (priv->person) {
113 // get the chosen cm
114 auto active = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->combobox_cm));
115 if (active >= 0) {
116 auto cm = priv->person->phoneNumbers().at(active);
117 if (!cm->sendOfflineTextMessage(messages))
118 g_warning("message failed to send"); // TODO: warn the user about this in the UI
119 } else {
120 g_warning("no ContactMethod chosen; message not esnt");
121 }
122 } else if (priv->cm) {
123 if (!priv->cm->sendOfflineTextMessage(messages))
124 g_warning("message failed to send"); // TODO: warn the user about this in the UI
125 } else {
126 g_warning("no Call, Person, or ContactMethod set; message not sent");
127 }
128
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500129 /* clear the entry */
130 gtk_entry_set_text(GTK_ENTRY(priv->entry_chat_input), "");
131 }
132}
133
134static void
135scroll_to_bottom(GtkAdjustment *adjustment, G_GNUC_UNUSED gpointer user_data)
136{
137 gtk_adjustment_set_value(adjustment,
138 gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment));
139}
140
141static void
Stepan Salenikovich8043a562016-03-18 13:56:40 -0400142hide_chat_view(G_GNUC_UNUSED GtkWidget *widget, ChatView *self)
143{
144 g_signal_emit(G_OBJECT(self), chat_view_signals[HIDE_VIEW_CLICKED], 0);
145}
146
147static void
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500148chat_view_init(ChatView *view)
149{
150 gtk_widget_init_template(GTK_WIDGET(view));
151
152 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(view);
153
154 g_signal_connect(priv->button_chat_input, "clicked", G_CALLBACK(send_chat), view);
155 g_signal_connect(priv->entry_chat_input, "activate", G_CALLBACK(send_chat), view);
156
157 /* the adjustment params will change only when the model is created and when
158 * new messages are added; in these cases we want to scroll to the bottom of
159 * the chat treeview */
160 GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(priv->scrolledwindow_chat));
161 g_signal_connect(adjustment, "changed", G_CALLBACK(scroll_to_bottom), NULL);
Stepan Salenikovich8043a562016-03-18 13:56:40 -0400162
163 g_signal_connect(priv->button_close_chatview, "clicked", G_CALLBACK(hide_chat_view), view);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500164}
165
166static void
167chat_view_class_init(ChatViewClass *klass)
168{
169 G_OBJECT_CLASS(klass)->dispose = chat_view_dispose;
170
171 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
172 "/cx/ring/RingGnome/chatview.ui");
173
174 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, textview_chat);
175 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, button_chat_input);
176 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, entry_chat_input);
177 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, scrolledwindow_chat);
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500178 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, hbox_chat_info);
179 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, label_peer);
180 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, combobox_cm);
Stepan Salenikovich8043a562016-03-18 13:56:40 -0400181 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, button_close_chatview);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500182
183 chat_view_signals[NEW_MESSAGES_DISPLAYED] = g_signal_new (
184 "new-messages-displayed",
185 G_TYPE_FROM_CLASS(klass),
186 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
187 0,
188 nullptr,
189 nullptr,
190 g_cclosure_marshal_VOID__VOID,
191 G_TYPE_NONE, 0);
Stepan Salenikovich8043a562016-03-18 13:56:40 -0400192
193 chat_view_signals[HIDE_VIEW_CLICKED] = g_signal_new (
194 "hide-view-clicked",
195 G_TYPE_FROM_CLASS(klass),
196 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
197 0,
198 nullptr,
199 nullptr,
200 g_cclosure_marshal_VOID__VOID,
201 G_TYPE_NONE, 0);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500202}
203
204static void
205print_message_to_buffer(const QModelIndex &idx, GtkTextBuffer *buffer)
206{
207 if (idx.isValid()) {
208 auto message = idx.data().value<QString>().toUtf8();
209 auto sender = idx.data(static_cast<int>(Media::TextRecording::Role::AuthorDisplayname)).value<QString>().toUtf8();
Stepan Salenikovich1b7100a2016-02-19 11:50:46 -0500210 auto timestamp = idx.data(static_cast<int>(Media::TextRecording::Role::Timestamp)).value<time_t>();
211 auto datetime = QDateTime::fromTime_t(timestamp);
Stepan Salenikovichce06adb2016-02-19 12:53:53 -0500212 auto direction = idx.data(static_cast<int>(Media::TextRecording::Role::Direction)).value<Media::Media::Direction>();
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500213
214 GtkTextIter iter;
215
216 /* unless its the very first message, insert a new line */
217 if (idx.row() != 0) {
218 gtk_text_buffer_get_end_iter(buffer, &iter);
219 gtk_text_buffer_insert(buffer, &iter, "\n", -1);
220 }
221
Stepan Salenikovich1b7100a2016-02-19 11:50:46 -0500222 /* if it is the very first row, we print the current date;
223 * otherwise we print the date every time it is different from the previous message */
224 auto date = datetime.date();
225 gchar* new_date = nullptr;
226 if (idx.row() == 0) {
227 new_date = g_strconcat("-- ", date.toString().toUtf8().constData(), " --\n", NULL);
228 } else {
229 auto prev_timestamp = idx.sibling(idx.row() - 1, 0).data(static_cast<int>(Media::TextRecording::Role::Timestamp)).value<time_t>();
230 auto prev_date = QDateTime::fromTime_t(prev_timestamp).date();
231 if (date != prev_date) {
232 new_date = g_strconcat("-- ", date.toString().toUtf8().constData(), " --\n", NULL);
233 }
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500234 }
235
Stepan Salenikovich1b7100a2016-02-19 11:50:46 -0500236 if (new_date) {
237 gtk_text_buffer_get_end_iter(buffer, &iter);
238 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, new_date, -1, "center", NULL);
239 }
240
241 /* insert time */
242 gtk_text_buffer_get_end_iter(buffer, &iter);
243 gtk_text_buffer_insert(buffer, &iter, datetime.time().toString().toUtf8().constData(), -1);
244
245 /* insert sender */
246 auto format_sender = g_strconcat(" ", sender.constData(), ": ", NULL);
247 gtk_text_buffer_get_end_iter(buffer, &iter);
Stepan Salenikovichce06adb2016-02-19 12:53:53 -0500248 if (direction == Media::Media::Direction::OUT)
249 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, format_sender, -1, "bold-blue", NULL);
250 else
251 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, format_sender, -1, "bold", NULL);
Stepan Salenikovich1b7100a2016-02-19 11:50:46 -0500252 g_free(format_sender);
253
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500254 gtk_text_buffer_get_end_iter(buffer, &iter);
Stepan Salenikovichce06adb2016-02-19 12:53:53 -0500255 if (direction == Media::Media::Direction::OUT)
256 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, message.constData(), -1, "blue", NULL);
257 else
258 gtk_text_buffer_insert(buffer, &iter, message.constData(), -1);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500259
260 } else {
261 g_warning("QModelIndex in im model is not valid");
262 }
263}
264
265static void
Stepan Salenikovichd8765072016-01-14 10:58:51 -0500266print_text_recording(Media::TextRecording *recording, ChatView *self)
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500267{
268 g_return_if_fail(IS_CHAT_VIEW(self));
269 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
270
Stepan Salenikovichd8765072016-01-14 10:58:51 -0500271 /* only text messages are supported for now */
272 auto model = recording->instantTextMessagingModel();
273
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500274 /* new model, disconnect from the old model updates and clear the text buffer */
275 QObject::disconnect(priv->new_message_connection);
276
277 GtkTextBuffer *new_buffer = gtk_text_buffer_new(NULL);
278 gtk_text_view_set_buffer(GTK_TEXT_VIEW(priv->textview_chat), new_buffer);
279
280 /* add tags to the buffer */
281 gtk_text_buffer_create_tag(new_buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
Stepan Salenikovich1b7100a2016-02-19 11:50:46 -0500282 gtk_text_buffer_create_tag(new_buffer, "center", "justification", GTK_JUSTIFY_CENTER, NULL);
Stepan Salenikovichce06adb2016-02-19 12:53:53 -0500283 gtk_text_buffer_create_tag(new_buffer, "bold-blue", "weight", PANGO_WEIGHT_BOLD, "foreground-rgba", &RING_BLUE, NULL);
284 gtk_text_buffer_create_tag(new_buffer, "blue", "foreground-rgba", &RING_BLUE, NULL);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500285
286 g_object_unref(new_buffer);
287
288 /* put all the messages in the im model into the text view */
289 for (int row = 0; row < model->rowCount(); ++row) {
290 QModelIndex idx = model->index(row, 0);
291 print_message_to_buffer(idx, new_buffer);
292 }
Stepan Salenikovichd8765072016-01-14 10:58:51 -0500293 /* mark all messages as read */
294 recording->setAllRead();
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500295
296 /* append new messages */
297 priv->new_message_connection = QObject::connect(
298 model,
299 &QAbstractItemModel::rowsInserted,
300 [self, priv, model] (const QModelIndex &parent, int first, int last) {
301 for (int row = first; row <= last; ++row) {
302 QModelIndex idx = model->index(row, 0, parent);
303 print_message_to_buffer(idx, gtk_text_view_get_buffer(GTK_TEXT_VIEW(priv->textview_chat)));
Stepan Salenikovichd8765072016-01-14 10:58:51 -0500304 /* make sure these messages are marked as read */
305 model->setData(idx, true, static_cast<int>(Media::TextRecording::Role::IsRead));
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500306 g_signal_emit(G_OBJECT(self), chat_view_signals[NEW_MESSAGES_DISPLAYED], 0);
307 }
308 }
309 );
310}
311
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500312static void
313selected_cm_changed(GtkComboBox *box, ChatView *self)
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500314{
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500315 g_return_if_fail(IS_CHAT_VIEW(self));
316 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
317
318 auto cms = priv->person->phoneNumbers();
319 auto active = gtk_combo_box_get_active(box);
320 if (active >= 0 && active < cms.size()) {
Stepan Salenikovichd8765072016-01-14 10:58:51 -0500321 print_text_recording(cms.at(active)->textRecording(), self);
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500322 } else {
323 g_warning("no valid ContactMethod selected to display chat conversation");
324 }
325}
326
327static void
Stepan Salenikovich5039c9b2016-02-12 14:09:51 -0500328render_contact_method(G_GNUC_UNUSED GtkCellLayout *cell_layout,
329 GtkCellRenderer *cell,
330 GtkTreeModel *model,
331 GtkTreeIter *iter,
332 G_GNUC_UNUSED gpointer data)
333{
334 GValue value = G_VALUE_INIT;
335 gtk_tree_model_get_value(model, iter, 0, &value);
336 auto cm = (ContactMethod *)g_value_get_pointer(&value);
337
338 gchar *number = nullptr;
339 if (cm && cm->category()) {
340 // try to get the number category, eg: "home"
341 number = g_strdup_printf("(%s) %s", cm->category()->name().toUtf8().constData(),
342 cm->uri().toUtf8().constData());
343 } else if (cm) {
344 number = g_strdup_printf("%s", cm->uri().toUtf8().constData());
345 }
346
347 g_object_set(G_OBJECT(cell), "text", number, NULL);
348 g_free(number);
349}
350
351static void
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500352update_contact_methods(ChatView *self)
353{
354 g_return_if_fail(IS_CHAT_VIEW(self));
355 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
356
Stepan Salenikovichbbfa4402016-05-04 15:07:29 -0400357 g_return_if_fail(priv->person || priv->cm);
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500358
359 /* model for the combobox for the choice of ContactMethods */
360 auto cm_model = gtk_list_store_new(
Stepan Salenikovich5039c9b2016-02-12 14:09:51 -0500361 1, G_TYPE_POINTER
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500362 );
363
Stepan Salenikovichbbfa4402016-05-04 15:07:29 -0400364 Person::ContactMethods cms;
365
366 if (priv->person)
367 cms = priv->person->phoneNumbers();
368 else
369 cms << priv->cm;
370
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500371 for (int i = 0; i < cms.size(); ++i) {
372 GtkTreeIter iter;
373 gtk_list_store_append(cm_model, &iter);
374 gtk_list_store_set(cm_model, &iter,
Stepan Salenikovich5039c9b2016-02-12 14:09:51 -0500375 0, cms.at(i),
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500376 -1);
377 }
378
379 gtk_combo_box_set_model(GTK_COMBO_BOX(priv->combobox_cm), GTK_TREE_MODEL(cm_model));
380 g_object_unref(cm_model);
381
382 auto renderer = gtk_cell_renderer_text_new();
383 g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
384 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(priv->combobox_cm), renderer, FALSE);
Stepan Salenikovich5039c9b2016-02-12 14:09:51 -0500385 gtk_cell_layout_set_cell_data_func(
386 GTK_CELL_LAYOUT(priv->combobox_cm),
387 renderer,
388 (GtkCellLayoutDataFunc)render_contact_method,
389 nullptr, nullptr);
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500390
391 /* select the last used cm */
392 if (!cms.isEmpty()) {
393 auto last_used_cm = cms.at(0);
394 int last_used_cm_idx = 0;
395 for (int i = 1; i < cms.size(); ++i) {
396 auto new_cm = cms.at(i);
397 if (difftime(new_cm->lastUsed(), last_used_cm->lastUsed()) > 0) {
398 last_used_cm = new_cm;
399 last_used_cm_idx = i;
400 }
401 }
402
403 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_cm), last_used_cm_idx);
404 }
405
Stepan Salenikovichbbfa4402016-05-04 15:07:29 -0400406 /* if there is only one CM, make the combo box insensitive */
407 if (cms.size() < 2)
408 gtk_widget_set_sensitive(priv->combobox_cm, FALSE);
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500409}
410
411static void
412update_name(ChatView *self)
413{
414 g_return_if_fail(IS_CHAT_VIEW(self));
415 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
416
417 g_return_if_fail(priv->person || priv->cm);
418
419 QString name;
420 if (priv->person) {
421 name = priv->person->roleData(static_cast<int>(Ring::Role::Name)).toString();
422 } else {
423 name = priv->cm->roleData(static_cast<int>(Ring::Role::Name)).toString();
424 }
425 gtk_label_set_text(GTK_LABEL(priv->label_peer), name.toUtf8().constData());
426}
427
428GtkWidget *
429chat_view_new_call(Call *call)
430{
431 g_return_val_if_fail(call, nullptr);
432
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500433 ChatView *self = CHAT_VIEW(g_object_new(CHAT_VIEW_TYPE, NULL));
434 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
435
436 priv->call = call;
437 auto cm = priv->call->peerContactMethod();
Stepan Salenikovichd8765072016-01-14 10:58:51 -0500438 print_text_recording(cm->textRecording(), self);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500439
440 return (GtkWidget *)self;
441}
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500442
443GtkWidget *
444chat_view_new_cm(ContactMethod *cm)
445{
446 g_return_val_if_fail(cm, nullptr);
447
448 ChatView *self = CHAT_VIEW(g_object_new(CHAT_VIEW_TYPE, NULL));
449 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
450
451 priv->cm = cm;
Stepan Salenikovichd8765072016-01-14 10:58:51 -0500452 print_text_recording(priv->cm->textRecording(), self);
Stepan Salenikovichbbfa4402016-05-04 15:07:29 -0400453 update_contact_methods(self);
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500454 update_name(self);
455
456 gtk_widget_show(priv->hbox_chat_info);
457
458 return (GtkWidget *)self;
459}
460
461GtkWidget *
462chat_view_new_person(Person *p)
463{
464 g_return_val_if_fail(p, nullptr);
465
466 ChatView *self = CHAT_VIEW(g_object_new(CHAT_VIEW_TYPE, NULL));
467 ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
468
469 priv->person = p;
470
471 /* connect to the changed signal before setting the cm combo box, so that the correct
472 * conversation will get displayed */
473 g_signal_connect(priv->combobox_cm, "changed", G_CALLBACK(selected_cm_changed), self);
474 update_contact_methods(self);
475 update_name(self);
476
477 gtk_widget_show(priv->hbox_chat_info);
478
479 return (GtkWidget *)self;
480}