Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Savoir-faire Linux Inc. |
| 3 | * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 4 | * Author: Alexandre Viau <alexandre.viau@savoirfairelinux.com> |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include "chatview.h" |
Nicolas Jager | 759faea | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 22 | #include "utils/accounts.h" |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 23 | |
| 24 | #include <gtk/gtk.h> |
| 25 | #include <call.h> |
| 26 | #include <callmodel.h> |
| 27 | #include <contactmethod.h> |
| 28 | #include <person.h> |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 29 | #include <media/text.h> |
| 30 | #include <media/textrecording.h> |
| 31 | #include "ringnotify.h" |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 32 | #include "profilemodel.h" |
| 33 | #include "profile.h" |
Stepan Salenikovich | 5039c9b | 2016-02-12 14:09:51 -0500 | [diff] [blame] | 34 | #include "numbercategory.h" |
Stepan Salenikovich | 1b7100a | 2016-02-19 11:50:46 -0500 | [diff] [blame] | 35 | #include <QtCore/QDateTime> |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 36 | #include "utils/calling.h" |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 37 | #include "webkitchatcontainer.h" |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 38 | |
Nicolas Jager | 759faea | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 39 | // LRC |
| 40 | #include <account.h> |
| 41 | |
| 42 | |
Stepan Salenikovich | ce06adb | 2016-02-19 12:53:53 -0500 | [diff] [blame] | 43 | static constexpr GdkRGBA RING_BLUE = {0.0508, 0.594, 0.676, 1.0}; // outgoing msg color: (13, 152, 173) |
| 44 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 45 | struct _ChatView |
| 46 | { |
| 47 | GtkBox parent; |
| 48 | }; |
| 49 | |
| 50 | struct _ChatViewClass |
| 51 | { |
| 52 | GtkBoxClass parent_class; |
| 53 | }; |
| 54 | |
| 55 | typedef struct _ChatViewPrivate ChatViewPrivate; |
| 56 | |
| 57 | struct _ChatViewPrivate |
| 58 | { |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 59 | GtkWidget *box_webkit_chat_container; |
| 60 | GtkWidget *webkit_chat_container; |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 61 | GtkWidget *button_chat_input; |
| 62 | GtkWidget *entry_chat_input; |
| 63 | GtkWidget *scrolledwindow_chat; |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 64 | GtkWidget *hbox_chat_info; |
| 65 | GtkWidget *label_peer; |
| 66 | GtkWidget *combobox_cm; |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 67 | GtkWidget *button_close_chatview; |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 68 | GtkWidget *button_placecall; |
Nicolas Jager | 759faea | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 69 | GtkWidget *button_send_invitation; |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 70 | |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 71 | /* only one of the three following pointers should be non void; |
| 72 | * either this is an in-call chat (and so the in-call chat APIs will be used) |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 73 | * or it is an out of call chat (and so the account chat APIs will be used) */ |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 74 | Call *call; |
| 75 | Person *person; |
| 76 | ContactMethod *cm; |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 77 | |
| 78 | QMetaObject::Connection new_message_connection; |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 79 | QMetaObject::Connection message_changed_connection; |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 80 | QMetaObject::Connection update_name; |
| 81 | |
| 82 | gulong webkit_ready; |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | G_DEFINE_TYPE_WITH_PRIVATE(ChatView, chat_view, GTK_TYPE_BOX); |
| 86 | |
| 87 | #define CHAT_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAT_VIEW_TYPE, ChatViewPrivate)) |
| 88 | |
| 89 | enum { |
| 90 | NEW_MESSAGES_DISPLAYED, |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 91 | HIDE_VIEW_CLICKED, |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 92 | LAST_SIGNAL |
| 93 | }; |
| 94 | |
| 95 | static guint chat_view_signals[LAST_SIGNAL] = { 0 }; |
| 96 | |
| 97 | static void |
| 98 | chat_view_dispose(GObject *object) |
| 99 | { |
| 100 | ChatView *view; |
| 101 | ChatViewPrivate *priv; |
| 102 | |
| 103 | view = CHAT_VIEW(object); |
| 104 | priv = CHAT_VIEW_GET_PRIVATE(view); |
| 105 | |
| 106 | QObject::disconnect(priv->new_message_connection); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 107 | QObject::disconnect(priv->message_changed_connection); |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 108 | QObject::disconnect(priv->update_name); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 109 | |
| 110 | /* Destroying the box will also destroy its children, and we wouldn't |
| 111 | * want that. So we remove the webkit_chat_container from the box. */ |
| 112 | if (priv->webkit_chat_container) { |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 113 | /* disconnect for webkit signals */ |
| 114 | g_signal_handler_disconnect(priv->webkit_chat_container, priv->webkit_ready); |
| 115 | priv->webkit_ready = 0; |
| 116 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 117 | gtk_container_remove( |
| 118 | GTK_CONTAINER(priv->box_webkit_chat_container), |
| 119 | GTK_WIDGET(priv->webkit_chat_container) |
| 120 | ); |
| 121 | priv->webkit_chat_container = nullptr; |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 122 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 123 | } |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 124 | |
| 125 | G_OBJECT_CLASS(chat_view_parent_class)->dispose(object); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | static void |
| 130 | send_chat(G_GNUC_UNUSED GtkWidget *widget, ChatView *self) |
| 131 | { |
| 132 | g_return_if_fail(IS_CHAT_VIEW(self)); |
| 133 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 134 | |
Stepan Salenikovich | 4fbc3bf | 2016-11-03 15:01:10 -0400 | [diff] [blame] | 135 | /* make sure there is more than just whitespace, but if so, send the original text */ |
| 136 | const auto text = QString(gtk_entry_get_text(GTK_ENTRY(priv->entry_chat_input))); |
| 137 | if (!text.trimmed().isEmpty()) { |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 138 | QMap<QString, QString> messages; |
| 139 | messages["text/plain"] = text; |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 140 | |
| 141 | if (priv->call) { |
| 142 | // in call message |
| 143 | priv->call->addOutgoingMedia<Media::Text>()->send(messages); |
| 144 | } else if (priv->person) { |
| 145 | // get the chosen cm |
| 146 | auto active = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->combobox_cm)); |
| 147 | if (active >= 0) { |
| 148 | auto cm = priv->person->phoneNumbers().at(active); |
| 149 | if (!cm->sendOfflineTextMessage(messages)) |
| 150 | g_warning("message failed to send"); // TODO: warn the user about this in the UI |
| 151 | } else { |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 152 | g_warning("no ContactMethod chosen; message not sent"); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 153 | } |
| 154 | } else if (priv->cm) { |
| 155 | if (!priv->cm->sendOfflineTextMessage(messages)) |
| 156 | g_warning("message failed to send"); // TODO: warn the user about this in the UI |
| 157 | } else { |
| 158 | g_warning("no Call, Person, or ContactMethod set; message not sent"); |
| 159 | } |
| 160 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 161 | /* clear the entry */ |
| 162 | gtk_entry_set_text(GTK_ENTRY(priv->entry_chat_input), ""); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | static void |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 167 | hide_chat_view(G_GNUC_UNUSED GtkWidget *widget, ChatView *self) |
| 168 | { |
| 169 | g_signal_emit(G_OBJECT(self), chat_view_signals[HIDE_VIEW_CLICKED], 0); |
| 170 | } |
| 171 | |
| 172 | static void |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 173 | placecall_clicked(ChatView *self) |
| 174 | { |
| 175 | auto priv = CHAT_VIEW_GET_PRIVATE(self); |
| 176 | |
| 177 | if (priv->person) { |
| 178 | // get the chosen cm |
| 179 | auto active = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->combobox_cm)); |
| 180 | if (active >= 0) { |
| 181 | auto cm = priv->person->phoneNumbers().at(active); |
| 182 | place_new_call(cm); |
| 183 | } else { |
| 184 | g_warning("no ContactMethod chosen; cannot place call"); |
| 185 | } |
| 186 | } else if (priv->cm) { |
| 187 | place_new_call(priv->cm); |
| 188 | } else { |
| 189 | g_warning("no Person or ContactMethod set; cannot place call"); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | static void |
Nicolas Jager | 759faea | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 194 | button_send_invitation_clicked(ChatView *self) |
| 195 | { |
| 196 | auto priv = CHAT_VIEW_GET_PRIVATE(self); |
| 197 | |
| 198 | // get the account associated to the selected cm |
| 199 | auto active = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->combobox_cm)); |
| 200 | |
| 201 | if (priv->person) |
| 202 | priv->cm = priv->person->phoneNumbers().at(active); |
| 203 | |
| 204 | if (!priv->cm) { |
| 205 | g_warning("invalid contact, cannot send invitation!"); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | // try first to use the account associated to the contact method |
| 210 | auto account = priv->cm->account(); |
| 211 | if (not account) { |
| 212 | |
| 213 | // get the choosen account |
| 214 | account = get_active_ring_account(); |
| 215 | |
| 216 | if (not account) { |
| 217 | g_warning("invalid account, cannot send invitation!"); |
| 218 | return; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // perform the request |
| 223 | if (not account->sendContactRequest(priv->cm)) |
| 224 | g_warning("contact request not forwarded, cannot send invitation!"); |
| 225 | |
| 226 | // TODO : add an entry in the conversation to tell the user an invitation was sent. |
| 227 | } |
| 228 | |
| 229 | static void |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 230 | chat_view_init(ChatView *view) |
| 231 | { |
| 232 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 233 | |
| 234 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(view); |
| 235 | |
| 236 | g_signal_connect(priv->button_chat_input, "clicked", G_CALLBACK(send_chat), view); |
| 237 | g_signal_connect(priv->entry_chat_input, "activate", G_CALLBACK(send_chat), view); |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 238 | g_signal_connect(priv->button_close_chatview, "clicked", G_CALLBACK(hide_chat_view), view); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 239 | g_signal_connect_swapped(priv->button_placecall, "clicked", G_CALLBACK(placecall_clicked), view); |
Nicolas Jager | 759faea | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 240 | g_signal_connect_swapped(priv->button_send_invitation, "clicked", G_CALLBACK(button_send_invitation_clicked), view); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | static void |
| 244 | chat_view_class_init(ChatViewClass *klass) |
| 245 | { |
| 246 | G_OBJECT_CLASS(klass)->dispose = chat_view_dispose; |
| 247 | |
| 248 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 249 | "/cx/ring/RingGnome/chatview.ui"); |
| 250 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 251 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, box_webkit_chat_container); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 252 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, button_chat_input); |
| 253 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, entry_chat_input); |
| 254 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, scrolledwindow_chat); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 255 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, hbox_chat_info); |
| 256 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, label_peer); |
| 257 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, combobox_cm); |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 258 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, button_close_chatview); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 259 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, button_placecall); |
Nicolas Jager | 759faea | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 260 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, button_send_invitation); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 261 | |
| 262 | chat_view_signals[NEW_MESSAGES_DISPLAYED] = g_signal_new ( |
| 263 | "new-messages-displayed", |
| 264 | G_TYPE_FROM_CLASS(klass), |
| 265 | (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION), |
| 266 | 0, |
| 267 | nullptr, |
| 268 | nullptr, |
| 269 | g_cclosure_marshal_VOID__VOID, |
| 270 | G_TYPE_NONE, 0); |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 271 | |
| 272 | chat_view_signals[HIDE_VIEW_CLICKED] = g_signal_new ( |
| 273 | "hide-view-clicked", |
| 274 | G_TYPE_FROM_CLASS(klass), |
| 275 | (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION), |
| 276 | 0, |
| 277 | nullptr, |
| 278 | nullptr, |
| 279 | g_cclosure_marshal_VOID__VOID, |
| 280 | G_TYPE_NONE, 0); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 281 | } |
| 282 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 283 | |
| 284 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 285 | static void |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 286 | print_message_to_buffer(ChatView* self, const QModelIndex &idx) |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 287 | { |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 288 | if (!idx.isValid()) { |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 289 | g_warning("QModelIndex in im model is not valid"); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 290 | return; |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 291 | } |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 292 | |
| 293 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 294 | |
| 295 | webkit_chat_container_print_new_message( |
| 296 | WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), |
| 297 | idx |
| 298 | ); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 299 | } |
| 300 | |
aviau | fc21355 | 2016-11-01 12:39:39 -0400 | [diff] [blame] | 301 | ContactMethod* |
| 302 | get_active_contactmethod(ChatView *self) |
| 303 | { |
| 304 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 305 | |
| 306 | auto cms = priv->person->phoneNumbers(); |
| 307 | auto active = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->combobox_cm)); |
| 308 | if (active >= 0 && active < cms.size()) { |
| 309 | return cms.at(active); |
| 310 | } else { |
| 311 | return nullptr; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | static void |
| 316 | set_participant_images(ChatView* self) |
| 317 | { |
| 318 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 319 | |
| 320 | webkit_chat_container_clear_sender_images( |
| 321 | WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container) |
| 322 | ); |
| 323 | |
| 324 | /* Set the sender image for the peer */ |
| 325 | ContactMethod* sender_contact_method_peer; |
| 326 | QVariant photo_variant_peer; |
| 327 | |
| 328 | if (priv->person) |
| 329 | { |
| 330 | photo_variant_peer = priv->person->photo(); |
| 331 | sender_contact_method_peer = get_active_contactmethod(self); |
| 332 | } |
| 333 | else |
| 334 | { |
| 335 | if (priv->cm) |
| 336 | { |
| 337 | sender_contact_method_peer = priv->cm; |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | sender_contact_method_peer = priv->call->peerContactMethod(); |
| 342 | } |
| 343 | photo_variant_peer = sender_contact_method_peer->roleData((int) Call::Role::Photo); |
| 344 | } |
| 345 | |
| 346 | if (photo_variant_peer.isValid()) |
| 347 | { |
| 348 | webkit_chat_container_set_sender_image( |
| 349 | WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), |
| 350 | sender_contact_method_peer, |
| 351 | photo_variant_peer |
| 352 | ); |
| 353 | } |
| 354 | |
| 355 | /* set sender image for "ME" */ |
| 356 | auto profile = ProfileModel::instance().selectedProfile(); |
| 357 | if (profile) |
| 358 | { |
| 359 | auto person = profile->person(); |
| 360 | if (person) |
| 361 | { |
| 362 | auto photo_variant_me = person->photo(); |
| 363 | if (photo_variant_me.isValid()) |
| 364 | { |
| 365 | webkit_chat_container_set_sender_image( |
| 366 | WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), |
| 367 | nullptr, |
| 368 | photo_variant_me |
| 369 | ); |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 375 | static void |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 376 | print_text_recording(Media::TextRecording *recording, ChatView *self) |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 377 | { |
| 378 | g_return_if_fail(IS_CHAT_VIEW(self)); |
| 379 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 380 | |
aviau | fc21355 | 2016-11-01 12:39:39 -0400 | [diff] [blame] | 381 | /* set the photos of the chat participants */ |
| 382 | set_participant_images(self); |
| 383 | |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 384 | /* only text messages are supported for now */ |
| 385 | auto model = recording->instantTextMessagingModel(); |
| 386 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 387 | /* new model, disconnect from the old model updates and clear the text buffer */ |
| 388 | QObject::disconnect(priv->new_message_connection); |
| 389 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 390 | /* put all the messages in the im model into the text view */ |
| 391 | for (int row = 0; row < model->rowCount(); ++row) { |
| 392 | QModelIndex idx = model->index(row, 0); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 393 | print_message_to_buffer(self, idx); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 394 | } |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 395 | /* mark all messages as read */ |
| 396 | recording->setAllRead(); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 397 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 398 | |
| 399 | /* messages modified */ |
| 400 | /* connecting on instantMessagingModel and not textMessagingModel */ |
| 401 | priv->message_changed_connection = QObject::connect( |
| 402 | model, |
| 403 | &QAbstractItemModel::dataChanged, |
| 404 | [self, priv] (const QModelIndex & topLeft, G_GNUC_UNUSED const QModelIndex & bottomRight) |
| 405 | { |
| 406 | webkit_chat_container_update_message( |
| 407 | WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), |
| 408 | topLeft |
| 409 | ); |
| 410 | } |
| 411 | ); |
| 412 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 413 | /* append new messages */ |
| 414 | priv->new_message_connection = QObject::connect( |
| 415 | model, |
| 416 | &QAbstractItemModel::rowsInserted, |
| 417 | [self, priv, model] (const QModelIndex &parent, int first, int last) { |
| 418 | for (int row = first; row <= last; ++row) { |
| 419 | QModelIndex idx = model->index(row, 0, parent); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 420 | print_message_to_buffer(self, idx); |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 421 | /* make sure these messages are marked as read */ |
| 422 | model->setData(idx, true, static_cast<int>(Media::TextRecording::Role::IsRead)); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 423 | g_signal_emit(G_OBJECT(self), chat_view_signals[NEW_MESSAGES_DISPLAYED], 0); |
| 424 | } |
| 425 | } |
| 426 | ); |
| 427 | } |
| 428 | |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 429 | static void |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 430 | selected_cm_changed(ChatView *self) |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 431 | { |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 432 | auto priv = CHAT_VIEW_GET_PRIVATE(self); |
| 433 | |
| 434 | /* make sure the webkit view is ready, in case we get this signal before it is */ |
| 435 | if (!webkit_chat_container_is_ready(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container))) |
| 436 | return; |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 437 | |
aviau | fc21355 | 2016-11-01 12:39:39 -0400 | [diff] [blame] | 438 | auto cm = get_active_contactmethod(self); |
| 439 | if (cm){ |
| 440 | print_text_recording(cm->textRecording(), self); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 441 | } else { |
| 442 | g_warning("no valid ContactMethod selected to display chat conversation"); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static void |
Stepan Salenikovich | 5039c9b | 2016-02-12 14:09:51 -0500 | [diff] [blame] | 447 | render_contact_method(G_GNUC_UNUSED GtkCellLayout *cell_layout, |
| 448 | GtkCellRenderer *cell, |
| 449 | GtkTreeModel *model, |
| 450 | GtkTreeIter *iter, |
| 451 | G_GNUC_UNUSED gpointer data) |
| 452 | { |
| 453 | GValue value = G_VALUE_INIT; |
| 454 | gtk_tree_model_get_value(model, iter, 0, &value); |
| 455 | auto cm = (ContactMethod *)g_value_get_pointer(&value); |
| 456 | |
| 457 | gchar *number = nullptr; |
| 458 | if (cm && cm->category()) { |
| 459 | // try to get the number category, eg: "home" |
| 460 | number = g_strdup_printf("(%s) %s", cm->category()->name().toUtf8().constData(), |
Nicolas Jager | 153b765 | 2017-01-17 10:06:54 -0500 | [diff] [blame] | 461 | cm->getBestId().toUtf8().constData()); |
Stepan Salenikovich | 5039c9b | 2016-02-12 14:09:51 -0500 | [diff] [blame] | 462 | } else if (cm) { |
Nicolas Jager | 153b765 | 2017-01-17 10:06:54 -0500 | [diff] [blame] | 463 | number = g_strdup_printf("%s", cm->getBestId().toUtf8().constData()); |
Stepan Salenikovich | 5039c9b | 2016-02-12 14:09:51 -0500 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | g_object_set(G_OBJECT(cell), "text", number, NULL); |
| 467 | g_free(number); |
| 468 | } |
| 469 | |
| 470 | static void |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 471 | update_contact_methods(ChatView *self) |
| 472 | { |
| 473 | g_return_if_fail(IS_CHAT_VIEW(self)); |
| 474 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 475 | |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 476 | g_return_if_fail(priv->call || priv->person || priv->cm); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 477 | |
| 478 | /* model for the combobox for the choice of ContactMethods */ |
| 479 | auto cm_model = gtk_list_store_new( |
Stepan Salenikovich | 5039c9b | 2016-02-12 14:09:51 -0500 | [diff] [blame] | 480 | 1, G_TYPE_POINTER |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 481 | ); |
| 482 | |
Stepan Salenikovich | bbfa440 | 2016-05-04 15:07:29 -0400 | [diff] [blame] | 483 | Person::ContactMethods cms; |
| 484 | |
| 485 | if (priv->person) |
| 486 | cms = priv->person->phoneNumbers(); |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 487 | else if (priv->cm) |
Stepan Salenikovich | bbfa440 | 2016-05-04 15:07:29 -0400 | [diff] [blame] | 488 | cms << priv->cm; |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 489 | else if (priv->call) |
| 490 | cms << priv->call->peerContactMethod(); |
Stepan Salenikovich | bbfa440 | 2016-05-04 15:07:29 -0400 | [diff] [blame] | 491 | |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 492 | for (int i = 0; i < cms.size(); ++i) { |
| 493 | GtkTreeIter iter; |
| 494 | gtk_list_store_append(cm_model, &iter); |
| 495 | gtk_list_store_set(cm_model, &iter, |
Stepan Salenikovich | 5039c9b | 2016-02-12 14:09:51 -0500 | [diff] [blame] | 496 | 0, cms.at(i), |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 497 | -1); |
| 498 | } |
| 499 | |
| 500 | gtk_combo_box_set_model(GTK_COMBO_BOX(priv->combobox_cm), GTK_TREE_MODEL(cm_model)); |
| 501 | g_object_unref(cm_model); |
| 502 | |
| 503 | auto renderer = gtk_cell_renderer_text_new(); |
| 504 | g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
| 505 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(priv->combobox_cm), renderer, FALSE); |
Stepan Salenikovich | 5039c9b | 2016-02-12 14:09:51 -0500 | [diff] [blame] | 506 | gtk_cell_layout_set_cell_data_func( |
| 507 | GTK_CELL_LAYOUT(priv->combobox_cm), |
| 508 | renderer, |
| 509 | (GtkCellLayoutDataFunc)render_contact_method, |
| 510 | nullptr, nullptr); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 511 | |
| 512 | /* select the last used cm */ |
| 513 | if (!cms.isEmpty()) { |
| 514 | auto last_used_cm = cms.at(0); |
| 515 | int last_used_cm_idx = 0; |
| 516 | for (int i = 1; i < cms.size(); ++i) { |
| 517 | auto new_cm = cms.at(i); |
| 518 | if (difftime(new_cm->lastUsed(), last_used_cm->lastUsed()) > 0) { |
| 519 | last_used_cm = new_cm; |
| 520 | last_used_cm_idx = i; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_cm), last_used_cm_idx); |
| 525 | } |
| 526 | |
Stepan Salenikovich | bbfa440 | 2016-05-04 15:07:29 -0400 | [diff] [blame] | 527 | /* if there is only one CM, make the combo box insensitive */ |
| 528 | if (cms.size() < 2) |
| 529 | gtk_widget_set_sensitive(priv->combobox_cm, FALSE); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 530 | |
| 531 | /* if no CMs make the call button insensitive */ |
| 532 | gtk_widget_set_sensitive(priv->button_placecall, !cms.isEmpty()); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static void |
| 536 | update_name(ChatView *self) |
| 537 | { |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 538 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 539 | |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 540 | g_return_if_fail(priv->person || priv->cm || priv->call); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 541 | |
| 542 | QString name; |
| 543 | if (priv->person) { |
| 544 | name = priv->person->roleData(static_cast<int>(Ring::Role::Name)).toString(); |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 545 | } else if (priv->cm) { |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 546 | name = priv->cm->roleData(static_cast<int>(Ring::Role::Name)).toString(); |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 547 | } else if (priv->call) { |
| 548 | name = priv->call->peerContactMethod()->roleData(static_cast<int>(Ring::Role::Name)).toString(); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 549 | } |
| 550 | gtk_label_set_text(GTK_LABEL(priv->label_peer), name.toUtf8().constData()); |
| 551 | } |
| 552 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 553 | static void |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 554 | webkit_chat_container_ready(ChatView* self) |
| 555 | { |
| 556 | /* The webkit chat container has loaded the javascript libraries, we can |
| 557 | * now use it. */ |
| 558 | |
| 559 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 560 | |
| 561 | webkit_chat_container_clear( |
| 562 | WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container) |
| 563 | ); |
| 564 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 565 | /* print the text recordings */ |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 566 | if (priv->call) { |
| 567 | print_text_recording(priv->call->peerContactMethod()->textRecording(), self); |
| 568 | } else if (priv->cm) { |
| 569 | print_text_recording(priv->cm->textRecording(), self); |
| 570 | } else if (priv->person) { |
| 571 | /* get the selected cm and print the text recording */ |
| 572 | selected_cm_changed(self); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 573 | } |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static void |
| 577 | build_chat_view(ChatView* self) |
| 578 | { |
| 579 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 580 | |
| 581 | gtk_container_add(GTK_CONTAINER(priv->box_webkit_chat_container), priv->webkit_chat_container); |
| 582 | gtk_widget_show(priv->webkit_chat_container); |
| 583 | |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 584 | /* keep name updated */ |
| 585 | if (priv->call) { |
| 586 | priv->update_name = QObject::connect( |
| 587 | priv->call, |
| 588 | &Call::changed, |
| 589 | [self] () { update_name(self); } |
| 590 | ); |
| 591 | } else if (priv->cm) { |
| 592 | priv->update_name = QObject::connect( |
| 593 | priv->cm, |
| 594 | &ContactMethod::changed, |
| 595 | [self] () { update_name(self); } |
| 596 | ); |
| 597 | } else if (priv->person) { |
| 598 | priv->update_name = QObject::connect( |
| 599 | priv->person, |
| 600 | &Person::changed, |
| 601 | [self] () { update_name(self); } |
| 602 | ); |
| 603 | } |
| 604 | update_name(self); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 605 | |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 606 | /* keep selected cm updated */ |
| 607 | update_contact_methods(self); |
| 608 | g_signal_connect_swapped(priv->combobox_cm, "changed", G_CALLBACK(selected_cm_changed), self); |
| 609 | |
| 610 | priv->webkit_ready = g_signal_connect_swapped( |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 611 | priv->webkit_chat_container, |
| 612 | "ready", |
| 613 | G_CALLBACK(webkit_chat_container_ready), |
| 614 | self |
| 615 | ); |
| 616 | |
| 617 | if (webkit_chat_container_is_ready(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container))) |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 618 | webkit_chat_container_ready(self); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 619 | |
Stepan Salenikovich | 1f73121 | 2016-11-10 11:55:10 -0500 | [diff] [blame] | 620 | /* we only show the chat info in the case of cm / person */ |
| 621 | gtk_widget_set_visible(priv->hbox_chat_info, (priv->cm || priv->person)); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 622 | } |
| 623 | |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 624 | GtkWidget * |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 625 | chat_view_new_call(WebKitChatContainer *webkit_chat_container, Call *call) |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 626 | { |
| 627 | g_return_val_if_fail(call, nullptr); |
| 628 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 629 | ChatView *self = CHAT_VIEW(g_object_new(CHAT_VIEW_TYPE, NULL)); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 630 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 631 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 632 | priv->webkit_chat_container = GTK_WIDGET(webkit_chat_container); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 633 | priv->call = call; |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 634 | |
| 635 | build_chat_view(self); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 636 | |
| 637 | return (GtkWidget *)self; |
| 638 | } |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 639 | |
| 640 | GtkWidget * |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 641 | chat_view_new_cm(WebKitChatContainer *webkit_chat_container, ContactMethod *cm) |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 642 | { |
| 643 | g_return_val_if_fail(cm, nullptr); |
| 644 | |
| 645 | ChatView *self = CHAT_VIEW(g_object_new(CHAT_VIEW_TYPE, NULL)); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 646 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 647 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 648 | priv->webkit_chat_container = GTK_WIDGET(webkit_chat_container); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 649 | priv->cm = cm; |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 650 | |
| 651 | build_chat_view(self); |
| 652 | |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 653 | return (GtkWidget *)self; |
| 654 | } |
| 655 | |
| 656 | GtkWidget * |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 657 | chat_view_new_person(WebKitChatContainer *webkit_chat_container, Person *p) |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 658 | { |
| 659 | g_return_val_if_fail(p, nullptr); |
| 660 | |
| 661 | ChatView *self = CHAT_VIEW(g_object_new(CHAT_VIEW_TYPE, NULL)); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 662 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 663 | ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self); |
| 664 | priv->webkit_chat_container = GTK_WIDGET(webkit_chat_container); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 665 | priv->person = p; |
| 666 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 667 | build_chat_view(self); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 668 | |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 669 | return (GtkWidget *)self; |
| 670 | } |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 671 | |
| 672 | Call* |
| 673 | chat_view_get_call(ChatView *self) |
| 674 | { |
| 675 | g_return_val_if_fail(IS_CHAT_VIEW(self), nullptr); |
| 676 | auto priv = CHAT_VIEW_GET_PRIVATE(self); |
| 677 | |
| 678 | return priv->call; |
| 679 | } |
| 680 | |
| 681 | ContactMethod* |
| 682 | chat_view_get_cm(ChatView *self) |
| 683 | { |
| 684 | g_return_val_if_fail(IS_CHAT_VIEW(self), nullptr); |
| 685 | auto priv = CHAT_VIEW_GET_PRIVATE(self); |
| 686 | |
| 687 | return priv->cm; |
| 688 | } |
| 689 | |
| 690 | Person* |
| 691 | chat_view_get_person(ChatView *self) |
| 692 | { |
| 693 | g_return_val_if_fail(IS_CHAT_VIEW(self), nullptr); |
| 694 | auto priv = CHAT_VIEW_GET_PRIVATE(self); |
| 695 | |
| 696 | return priv->person; |
| 697 | } |
Stepan Salenikovich | daf3cb3 | 2016-10-12 16:39:42 -0400 | [diff] [blame] | 698 | |
| 699 | void |
| 700 | chat_view_set_header_visible(ChatView *self, gboolean visible) |
| 701 | { |
| 702 | auto priv = CHAT_VIEW_GET_PRIVATE(self); |
| 703 | |
| 704 | gtk_widget_set_visible(priv->hbox_chat_info, visible); |
| 705 | } |