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