Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
| 30 | |
| 31 | #include "incomingcallview.h" |
| 32 | |
| 33 | #include <gtk/gtk.h> |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 34 | #include <call.h> |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 35 | #include "utils/drawing.h" |
| 36 | #include <callmodel.h> |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 37 | |
| 38 | struct _IncomingCallView |
| 39 | { |
| 40 | GtkBox parent; |
| 41 | }; |
| 42 | |
| 43 | struct _IncomingCallViewClass |
| 44 | { |
| 45 | GtkBoxClass parent_class; |
| 46 | }; |
| 47 | |
| 48 | typedef struct _IncomingCallViewPrivate IncomingCallViewPrivate; |
| 49 | |
| 50 | struct _IncomingCallViewPrivate |
| 51 | { |
| 52 | GtkWidget *image_incoming; |
| 53 | GtkWidget *label_identity; |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 54 | GtkWidget *label_status; |
| 55 | GtkWidget *button_accept_incoming; |
| 56 | GtkWidget *button_reject_incoming; |
| 57 | GtkWidget *button_end_call; |
| 58 | |
| 59 | QMetaObject::Connection state_change_connection; |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | G_DEFINE_TYPE_WITH_PRIVATE(IncomingCallView, incoming_call_view, GTK_TYPE_BOX); |
| 63 | |
| 64 | #define INCOMING_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), INCOMING_CALL_VIEW_TYPE, IncomingCallViewPrivate)) |
| 65 | |
| 66 | static void |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 67 | incoming_call_dispose(GObject *object) |
| 68 | { |
| 69 | IncomingCallView *view; |
| 70 | IncomingCallViewPrivate *priv; |
| 71 | |
| 72 | view = INCOMING_CALL_VIEW(object); |
| 73 | priv = INCOMING_CALL_VIEW_GET_PRIVATE(view); |
| 74 | |
| 75 | QObject::disconnect(priv->state_change_connection); |
| 76 | |
| 77 | G_OBJECT_CLASS(incoming_call_view_parent_class)->dispose(object); |
| 78 | } |
| 79 | |
| 80 | static void |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 81 | incoming_call_view_init(IncomingCallView *view) |
| 82 | { |
| 83 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 84 | } |
| 85 | |
| 86 | static void |
| 87 | incoming_call_view_class_init(IncomingCallViewClass *klass) |
| 88 | { |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 89 | G_OBJECT_CLASS(klass)->dispose = incoming_call_dispose; |
| 90 | |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 91 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 92 | "/cx/ring/RingGnome/incomingcallview.ui"); |
| 93 | |
| 94 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), IncomingCallView, image_incoming); |
| 95 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), IncomingCallView, label_identity); |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 96 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), IncomingCallView, label_status); |
| 97 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), IncomingCallView, button_accept_incoming); |
| 98 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), IncomingCallView, button_reject_incoming); |
| 99 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), IncomingCallView, button_end_call); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | GtkWidget * |
| 103 | incoming_call_view_new(void) |
| 104 | { |
| 105 | return (GtkWidget *)g_object_new(INCOMING_CALL_VIEW_TYPE, NULL); |
| 106 | } |
| 107 | |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 108 | static void |
| 109 | update_state(IncomingCallView *view, Call *call) |
| 110 | { |
| 111 | IncomingCallViewPrivate *priv = INCOMING_CALL_VIEW_GET_PRIVATE(view); |
| 112 | |
| 113 | /* change state label */ |
| 114 | Call::State state = call->state(); |
| 115 | |
| 116 | switch(state) { |
| 117 | case Call::State::INCOMING: |
| 118 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Incoming..."); |
| 119 | break; |
| 120 | case Call::State::RINGING: |
| 121 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Ringing..."); |
| 122 | break; |
| 123 | case Call::State::CURRENT: |
| 124 | /* note: shouldn't be displayed, as the view should change */ |
| 125 | gtk_label_set_text(GTK_LABEL(priv->label_status), "In progress."); |
| 126 | break; |
| 127 | case Call::State::DIALING: |
| 128 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Dialing..."); |
| 129 | break; |
| 130 | case Call::State::HOLD: |
| 131 | /* note: shouldn't be displayed, as the view should change */ |
| 132 | gtk_label_set_text(GTK_LABEL(priv->label_status), "On hold."); |
| 133 | break; |
| 134 | case Call::State::FAILURE: |
| 135 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Failed."); |
| 136 | break; |
| 137 | case Call::State::BUSY: |
| 138 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Busy."); |
| 139 | break; |
| 140 | case Call::State::TRANSFERRED: |
| 141 | /* note: shouldn't be displayed, as the view should change */ |
| 142 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Transfered."); |
| 143 | break; |
| 144 | case Call::State::TRANSF_HOLD: |
| 145 | /* note: shouldn't be displayed, as the view should change */ |
| 146 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Transfer hold."); |
| 147 | break; |
| 148 | case Call::State::OVER: |
| 149 | /* note: shouldn't be displayed, as the view should change */ |
| 150 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Over."); |
| 151 | break; |
| 152 | case Call::State::ERROR: |
| 153 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Error."); |
| 154 | break; |
| 155 | case Call::State::CONFERENCE: |
| 156 | /* note: shouldn't be displayed, as the view should change */ |
| 157 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Conference."); |
| 158 | break; |
| 159 | case Call::State::CONFERENCE_HOLD: |
| 160 | /* note: shouldn't be displayed, as the view should change */ |
| 161 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Conference hold."); |
| 162 | break; |
| 163 | case Call::State::INITIALIZATION: |
| 164 | gtk_label_set_text(GTK_LABEL(priv->label_status), "Initialization..."); |
| 165 | break; |
| 166 | case Call::State::COUNT__: |
| 167 | break; |
| 168 | } |
| 169 | |
| 170 | /* change button(s) displayed */ |
| 171 | gtk_widget_hide(priv->button_accept_incoming); |
| 172 | gtk_widget_hide(priv->button_reject_incoming); |
| 173 | gtk_widget_hide(priv->button_end_call); |
| 174 | |
| 175 | switch(state) { |
| 176 | case Call::State::INCOMING: |
| 177 | gtk_widget_show(priv->button_accept_incoming); |
| 178 | gtk_widget_show(priv->button_reject_incoming); |
| 179 | break; |
| 180 | case Call::State::RINGING: |
| 181 | case Call::State::CURRENT: |
| 182 | case Call::State::DIALING: |
| 183 | case Call::State::HOLD: |
| 184 | case Call::State::FAILURE: |
| 185 | case Call::State::BUSY: |
| 186 | case Call::State::TRANSFERRED: |
| 187 | case Call::State::TRANSF_HOLD: |
| 188 | case Call::State::OVER: |
| 189 | case Call::State::ERROR: |
| 190 | case Call::State::CONFERENCE: |
| 191 | case Call::State::CONFERENCE_HOLD: |
| 192 | case Call::State::INITIALIZATION: |
| 193 | gtk_widget_show(priv->button_end_call); |
| 194 | break; |
| 195 | case Call::State::COUNT__: |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 200 | void |
| 201 | incoming_call_view_set_call_info(IncomingCallView *view, const QModelIndex& idx) { |
| 202 | IncomingCallViewPrivate *priv = INCOMING_CALL_VIEW_GET_PRIVATE(view); |
| 203 | |
| 204 | QVariant var = idx.model()->data(idx, Call::Role::Name); |
| 205 | QByteArray ba_name = var.toString().toLocal8Bit(); |
| 206 | |
| 207 | /* get image and frame it */ |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 208 | GdkPixbuf *avatar = ring_draw_fallback_avatar(100); |
| 209 | GdkPixbuf *framed_avatar = ring_frame_avatar(avatar); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 210 | g_object_unref(avatar); |
| 211 | |
| 212 | gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_incoming), framed_avatar); |
| 213 | g_object_unref(framed_avatar); |
| 214 | |
| 215 | gtk_label_set_text(GTK_LABEL(priv->label_identity), ba_name.data()); |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame^] | 216 | |
| 217 | /* change some things depending on call state */ |
| 218 | Call *call = CallModel::instance()->getCall(idx); |
| 219 | |
| 220 | update_state(view, call); |
| 221 | |
| 222 | priv->state_change_connection = QObject::connect( |
| 223 | call, |
| 224 | &Call::stateChanged, |
| 225 | [=]() { update_state(view, call); } |
| 226 | ); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 227 | } |