Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 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. |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "ringmainwindow.h" |
| 21 | |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 22 | // system |
| 23 | #include <string.h> |
| 24 | #include <memory> |
| 25 | |
| 26 | // GTK+ related |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 27 | #include <glib/gi18n.h> |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 28 | |
| 29 | // Qt |
| 30 | #include <QtCore/QItemSelectionModel> |
| 31 | #include <QtCore/QSortFilterProxyModel> |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 32 | #include <QtCore/QDateTime> |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 33 | |
| 34 | // LRC |
Stepan Salenikovich | a355745 | 2015-02-20 14:14:12 -0500 | [diff] [blame] | 35 | #include <callmodel.h> |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 36 | #include <call.h> |
Stepan Salenikovich | 1514218 | 2015-03-11 17:15:26 -0400 | [diff] [blame] | 37 | #include <contactmethod.h> |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 38 | #include <accountmodel.h> |
Edric Milaret | 58e7107 | 2016-03-21 12:16:37 -0400 | [diff] [blame] | 39 | #include <codecmodel.h> |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 40 | #include <video/previewmanager.h> |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 41 | #include <personmodel.h> |
Stepan Salenikovich | bbd6c13 | 2015-08-20 15:21:48 -0400 | [diff] [blame] | 42 | #include <globalinstances.h> |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 43 | #include <categorizedcontactmodel.h> |
| 44 | #include <recentmodel.h> |
| 45 | #include <profilemodel.h> |
| 46 | #include <profile.h> |
Stepan Salenikovich | f53128f | 2016-10-07 10:32:16 -0400 | [diff] [blame] | 47 | #include <phonedirectorymodel.h> |
Stepan Salenikovich | 7b7be48 | 2016-11-03 16:57:48 -0400 | [diff] [blame] | 48 | #include <availableaccountmodel.h> |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 49 | |
| 50 | // Ring client |
| 51 | #include "models/gtkqtreemodel.h" |
| 52 | #include "incomingcallview.h" |
| 53 | #include "currentcallview.h" |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 54 | #include "models/gtkqtreemodel.h" |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 55 | #include "accountview.h" |
| 56 | #include "dialogs.h" |
| 57 | #include "mediasettingsview.h" |
| 58 | #include "utils/drawing.h" |
Stepan Salenikovich | bbd6c13 | 2015-08-20 15:21:48 -0400 | [diff] [blame] | 59 | #include "native/pixbufmanipulator.h" |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 60 | #include "models/activeitemproxymodel.h" |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 61 | #include "utils/calling.h" |
| 62 | #include "contactsview.h" |
| 63 | #include "historyview.h" |
| 64 | #include "utils/models.h" |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 65 | #include "generalsettingsview.h" |
Stepan Salenikovich | 75a3917 | 2015-07-10 13:21:08 -0400 | [diff] [blame] | 66 | #include "utils/accounts.h" |
Stepan Salenikovich | 2cde761 | 2015-09-25 10:44:01 -0400 | [diff] [blame] | 67 | #include "ringwelcomeview.h" |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 68 | #include "accountmigrationview.h" |
| 69 | #include "accountcreationwizard.h" |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 70 | #include "recentcontactsview.h" |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 71 | #include "chatview.h" |
Nicolas Jager | b413b30 | 2016-05-06 11:41:32 -0400 | [diff] [blame] | 72 | #include "avatarmanipulation.h" |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 73 | #include "utils/files.h" |
Nicolas Jager | b413b30 | 2016-05-06 11:41:32 -0400 | [diff] [blame] | 74 | |
Stepan Salenikovich | 9ffad5e | 2015-09-25 13:16:50 -0400 | [diff] [blame] | 75 | static constexpr const char* CALL_VIEW_NAME = "calls"; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 76 | static constexpr const char* ACCOUNT_CREATION_WIZARD_VIEW_NAME = "account-creation-wizard"; |
| 77 | static constexpr const char* ACCOUNT_MIGRATION_VIEW_NAME = "account-migration-view"; |
Stepan Salenikovich | 9ffad5e | 2015-09-25 13:16:50 -0400 | [diff] [blame] | 78 | static constexpr const char* GENERAL_SETTINGS_VIEW_NAME = "general"; |
| 79 | static constexpr const char* AUDIO_SETTINGS_VIEW_NAME = "audio"; |
| 80 | static constexpr const char* MEDIA_SETTINGS_VIEW_NAME = "media"; |
| 81 | static constexpr const char* ACCOUNT_SETTINGS_VIEW_NAME = "accounts"; |
Stepan Salenikovich | 2cde761 | 2015-09-25 10:44:01 -0400 | [diff] [blame] | 82 | static constexpr const char* DEFAULT_VIEW_NAME = "welcome"; |
Stepan Salenikovich | 9ffad5e | 2015-09-25 13:16:50 -0400 | [diff] [blame] | 83 | static constexpr const char* VIEW_CONTACTS = "contacts"; |
| 84 | static constexpr const char* VIEW_HISTORY = "history"; |
| 85 | static constexpr const char* VIEW_PRESENCE = "presence"; |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 86 | |
| 87 | struct _RingMainWindow |
| 88 | { |
| 89 | GtkApplicationWindow parent; |
| 90 | }; |
| 91 | |
| 92 | struct _RingMainWindowClass |
| 93 | { |
| 94 | GtkApplicationWindowClass parent_class; |
| 95 | }; |
| 96 | |
| 97 | typedef struct _RingMainWindowPrivate RingMainWindowPrivate; |
| 98 | |
| 99 | struct _RingMainWindowPrivate |
| 100 | { |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 101 | GtkWidget *ring_menu; |
| 102 | GtkWidget *image_ring; |
| 103 | GtkWidget *ring_settings; |
| 104 | GtkWidget *image_settings; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 105 | GtkWidget *hbox_settings; |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 106 | GtkWidget *scrolled_window_smartview; |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 107 | GtkWidget *treeview_conversations; |
Stepan Salenikovich | a7a19bc | 2015-09-24 16:16:28 -0400 | [diff] [blame] | 108 | GtkWidget *scrolled_window_contacts; |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 109 | GtkWidget *treeview_contacts; |
Stepan Salenikovich | a7a19bc | 2015-09-24 16:16:28 -0400 | [diff] [blame] | 110 | GtkWidget *scrolled_window_history; |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 111 | GtkWidget *treeview_history; |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 112 | GtkWidget *vbox_left_pane; |
Stepan Salenikovich | 45d25aa | 2015-02-20 17:39:09 -0500 | [diff] [blame] | 113 | GtkWidget *search_entry; |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 114 | GtkWidget *stack_main_view; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 115 | GtkWidget *vbox_call_view; |
Stepan Salenikovich | 3034d92 | 2015-10-09 10:11:42 -0400 | [diff] [blame] | 116 | GtkWidget *frame_call; |
| 117 | GtkWidget *welcome_view; |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 118 | GtkWidget *button_new_conversation ; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 119 | GtkWidget *account_settings_view; |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 120 | GtkWidget *media_settings_view; |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 121 | GtkWidget *general_settings_view; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 122 | GtkWidget *last_settings_view; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 123 | GtkWidget *radiobutton_general_settings; |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 124 | GtkWidget *radiobutton_media_settings; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 125 | GtkWidget *radiobutton_account_settings; |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 126 | GtkWidget *account_creation_wizard; |
| 127 | GtkWidget *account_migration_view; |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 128 | GtkWidget *spinner_lookup; |
Stepan Salenikovich | 5eab303 | 2015-03-28 10:50:51 -0400 | [diff] [blame] | 129 | |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 130 | /* Pending ring usernames lookup for the search entry */ |
| 131 | QMetaObject::Connection username_lookup; |
Guillaume Roguez | e7221ed | 2017-03-17 20:09:56 -0400 | [diff] [blame] | 132 | std::string* pending_username_lookup; |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 133 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 134 | /* The webkit_chat_container is created once, then reused for all chat views */ |
| 135 | GtkWidget *webkit_chat_container; |
| 136 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 137 | QMetaObject::Connection selected_item_changed; |
| 138 | QMetaObject::Connection selected_call_over; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 139 | |
| 140 | gboolean show_settings; |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 141 | |
Stepan Salenikovich | e1b5489 | 2015-12-13 22:18:44 -0500 | [diff] [blame] | 142 | /* fullscreen */ |
| 143 | gboolean is_fullscreen; |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 144 | |
| 145 | GSettings *settings; |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | G_DEFINE_TYPE_WITH_PRIVATE(RingMainWindow, ring_main_window, GTK_TYPE_APPLICATION_WINDOW); |
| 149 | |
| 150 | #define RING_MAIN_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_MAIN_WINDOW_TYPE, RingMainWindowPrivate)) |
| 151 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 152 | static gboolean selection_changed(RingMainWindow *win); |
| 153 | |
| 154 | static WebKitChatContainer* |
| 155 | get_webkit_chat_container(RingMainWindow *win) |
| 156 | { |
| 157 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 158 | if (!priv->webkit_chat_container) |
| 159 | { |
| 160 | priv->webkit_chat_container = webkit_chat_container_new(); |
| 161 | |
| 162 | //We don't want it to be deleted, ever. |
| 163 | g_object_ref(priv->webkit_chat_container); |
| 164 | } |
| 165 | return WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container); |
| 166 | } |
| 167 | |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 168 | static void |
Stepan Salenikovich | e1b5489 | 2015-12-13 22:18:44 -0500 | [diff] [blame] | 169 | enter_full_screen(RingMainWindow *self) |
| 170 | { |
| 171 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 172 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 173 | |
| 174 | if (!priv->is_fullscreen) { |
| 175 | gtk_widget_hide(priv->vbox_left_pane); |
| 176 | gtk_window_fullscreen(GTK_WINDOW(self)); |
| 177 | priv->is_fullscreen = TRUE; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | static void |
| 182 | leave_full_screen(RingMainWindow *self) |
| 183 | { |
| 184 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 185 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 186 | |
| 187 | if (priv->is_fullscreen) { |
| 188 | gtk_widget_show(priv->vbox_left_pane); |
| 189 | gtk_window_unfullscreen(GTK_WINDOW(self)); |
| 190 | priv->is_fullscreen = FALSE; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | static void |
Stepan Salenikovich | 5e431cf | 2015-12-24 14:09:01 -0500 | [diff] [blame] | 195 | video_double_clicked(G_GNUC_UNUSED CurrentCallView *view, RingMainWindow *self) |
Stepan Salenikovich | e1b5489 | 2015-12-13 22:18:44 -0500 | [diff] [blame] | 196 | { |
| 197 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 198 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 199 | |
| 200 | if (priv->is_fullscreen) { |
| 201 | leave_full_screen(self); |
| 202 | } else { |
| 203 | enter_full_screen(self); |
| 204 | } |
| 205 | } |
| 206 | |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 207 | static void |
| 208 | hide_view_clicked(G_GNUC_UNUSED GtkWidget *view, RingMainWindow *self) |
| 209 | { |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 210 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 211 | |
| 212 | /* clear selection */ |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 213 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_conversations)); |
| 214 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations)); |
| 215 | auto selection_contacts = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_contacts)); |
| 216 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contacts)); |
| 217 | auto selection_history = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_history)); |
| 218 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_history)); |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 219 | } |
| 220 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 221 | static void |
| 222 | change_view(RingMainWindow *self, GtkWidget* old, QObject *object, GType type) |
| 223 | { |
| 224 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 225 | leave_full_screen(self); |
| 226 | gtk_container_remove(GTK_CONTAINER(priv->frame_call), old); |
| 227 | |
| 228 | GtkWidget *new_view = nullptr; |
| 229 | |
| 230 | QObject::disconnect(priv->selected_item_changed); |
| 231 | QObject::disconnect(priv->selected_call_over); |
| 232 | |
| 233 | if (g_type_is_a(INCOMING_CALL_VIEW_TYPE, type)) { |
| 234 | if (auto call = qobject_cast<Call *>(object)) { |
| 235 | new_view = incoming_call_view_new(call, get_webkit_chat_container(self)); |
| 236 | priv->selected_item_changed = QObject::connect( |
| 237 | call, |
| 238 | &Call::lifeCycleStateChanged, |
| 239 | [self] (Call::LifeCycleState, Call::LifeCycleState) |
| 240 | {g_idle_add((GSourceFunc)selection_changed, self);} |
| 241 | ); |
| 242 | priv->selected_call_over = QObject::connect( |
| 243 | call, |
| 244 | &Call::isOver, |
| 245 | [self] () |
| 246 | {g_idle_add((GSourceFunc)selection_changed, self);} |
| 247 | ); |
| 248 | } else |
| 249 | g_warning("Trying to display a view of type IncomingCallView, but the object is not of type Call"); |
| 250 | } else if (g_type_is_a(CURRENT_CALL_VIEW_TYPE, type)) { |
| 251 | if (auto call = qobject_cast<Call *>(object)) { |
| 252 | new_view = current_call_view_new(call, get_webkit_chat_container(self)); |
| 253 | g_signal_connect(new_view, "video-double-clicked", G_CALLBACK(video_double_clicked), self); |
| 254 | priv->selected_item_changed = QObject::connect( |
| 255 | call, |
| 256 | &Call::lifeCycleStateChanged, |
| 257 | [self] (Call::LifeCycleState, Call::LifeCycleState) |
| 258 | {g_idle_add((GSourceFunc)selection_changed, self);} |
| 259 | ); |
| 260 | priv->selected_call_over = QObject::connect( |
| 261 | call, |
| 262 | &Call::isOver, |
| 263 | [self] () |
| 264 | {g_idle_add((GSourceFunc)selection_changed, self);} |
| 265 | ); |
| 266 | } else |
| 267 | g_warning("Trying to display a view of type CurrentCallView, but the object is not of type Call"); |
| 268 | } else if (g_type_is_a(CHAT_VIEW_TYPE, type)) { |
| 269 | if (auto person = qobject_cast<Person *>(object)) { |
| 270 | new_view = chat_view_new_person(get_webkit_chat_container(self), person); |
| 271 | g_signal_connect(new_view, "hide-view-clicked", G_CALLBACK(hide_view_clicked), self); |
| 272 | |
| 273 | /* connect to the Person's callAdded signal, because we want to switch to the call view |
| 274 | * in this case */ |
| 275 | priv->selected_item_changed = QObject::connect( |
| 276 | person, |
| 277 | &Person::callAdded, |
| 278 | [self] (Call*) |
| 279 | {g_idle_add((GSourceFunc)selection_changed, self);} |
| 280 | ); |
| 281 | } else if (auto cm = qobject_cast<ContactMethod *>(object)) { |
| 282 | new_view = chat_view_new_cm(get_webkit_chat_container(self), cm); |
| 283 | g_signal_connect(new_view, "hide-view-clicked", G_CALLBACK(hide_view_clicked), self); |
| 284 | |
| 285 | /* connect to the ContactMethod's callAdded signal, because we want to switch to the |
| 286 | * call view in this case */ |
| 287 | priv->selected_item_changed = QObject::connect( |
| 288 | cm, |
| 289 | &ContactMethod::callAdded, |
| 290 | [self] (Call*) |
| 291 | {g_idle_add((GSourceFunc)selection_changed, self);} |
| 292 | ); |
| 293 | } else { |
| 294 | g_warning("Trying to display a veiw of type ChatView, but the object is neither a Person nor a ContactMethod"); |
| 295 | } |
| 296 | } else { |
| 297 | // display the welcome view |
| 298 | new_view = priv->welcome_view; |
| 299 | } |
| 300 | |
| 301 | gtk_container_add(GTK_CONTAINER(priv->frame_call), new_view); |
| 302 | gtk_widget_show(new_view); |
| 303 | } |
| 304 | |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 305 | /** |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 306 | * This function determines which view to display in the right panel of the main window based on |
| 307 | * which item is selected in one of the 3 contact list views (Conversations, Contacts, History). The |
| 308 | * possible views ares: |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 309 | * - incoming call view |
| 310 | * - current call view |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 311 | * - chat view |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 312 | * - welcome view (if no valid item is selected) |
| 313 | * |
| 314 | * There should never be a conflict of which item should be displayed (ie: which item is selected), |
| 315 | * as there should only ever be one selection at a time in the 3 views except in the case that the |
| 316 | * same item is selected in more than one view (see the compare_treeview_selection() function). |
| 317 | * |
| 318 | * This function could be called from a g_idle source, so it returns a boolean to remove itself from |
| 319 | * being called again. The boolean doesn't reflect success nor failure. |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 320 | */ |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 321 | static gboolean |
| 322 | selection_changed(RingMainWindow *win) |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 323 | { |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 324 | // g_debug("selection changed"); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 325 | |
| 326 | g_return_val_if_fail(IS_RING_MAIN_WINDOW(win), G_SOURCE_REMOVE); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 327 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(win)); |
| 328 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 329 | auto old_view = gtk_bin_get_child(GTK_BIN(priv->frame_call)); |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 330 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 331 | /* if we're showing the settings, then we need to make sure to remove any possible ongoing call |
| 332 | * view so that we don't have more than one VideoWidget at a time */ |
| 333 | if (priv->show_settings) { |
| 334 | if (old_view != priv->welcome_view) { |
| 335 | leave_full_screen(win); |
| 336 | gtk_container_remove(GTK_CONTAINER(priv->frame_call), old_view); |
| 337 | gtk_container_add(GTK_CONTAINER(priv->frame_call), priv->welcome_view); |
| 338 | gtk_widget_show(priv->welcome_view); |
| 339 | } |
| 340 | return G_SOURCE_REMOVE; |
| 341 | } |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 342 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 343 | /* there should only be one item selected at a time, get which one is selected */ |
| 344 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_conversations)); |
| 345 | auto selection_contacts = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_contacts)); |
| 346 | auto selection_history = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_history)); |
| 347 | |
| 348 | GtkTreeModel *model = nullptr; |
| 349 | GtkTreeIter iter; |
| 350 | QModelIndex idx; |
| 351 | |
| 352 | if (gtk_tree_selection_get_selected(selection_conversations, &model, &iter)) { |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 353 | idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &iter); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 354 | } else if (gtk_tree_selection_get_selected(selection_contacts, &model, &iter)) { |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 355 | idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &iter); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 356 | } else if (gtk_tree_selection_get_selected(selection_history, &model, &iter)) { |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 357 | idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &iter); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 358 | } |
Stepan Salenikovich | e1b5489 | 2015-12-13 22:18:44 -0500 | [diff] [blame] | 359 | |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 360 | /* check which object type is selected */ |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 361 | auto type = idx.data(static_cast<int>(Ring::Role::ObjectType)); |
| 362 | auto object = idx.data(static_cast<int>(Ring::Role::Object)); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 363 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 364 | if (idx.isValid() && type.isValid() && object.isValid()) { |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 365 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 366 | /* we prioritize the views in the following order: |
| 367 | * - call view (if there is an ongoing call associated with the item) |
| 368 | * - chat view built from Person |
| 369 | * - chat view built from ContactMethod |
| 370 | */ |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame] | 371 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 372 | Person *person = nullptr; |
| 373 | ContactMethod *cm = nullptr; |
| 374 | Call *call = nullptr; |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 375 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 376 | /* use the RecentModel to see if there are any ongoing calls associated with the selected item */ |
| 377 | switch(type.value<Ring::ObjectType>()) { |
| 378 | case Ring::ObjectType::Person: |
| 379 | { |
| 380 | person = object.value<Person *>(); |
| 381 | auto recent_idx = RecentModel::instance().getIndex(person); |
| 382 | if (recent_idx.isValid()) { |
| 383 | call = RecentModel::instance().getActiveCall(recent_idx); |
| 384 | } |
| 385 | } |
| 386 | break; |
| 387 | case Ring::ObjectType::ContactMethod: |
| 388 | { |
| 389 | cm = object.value<ContactMethod *>(); |
| 390 | auto recent_idx = RecentModel::instance().getIndex(cm); |
| 391 | if (recent_idx.isValid()) { |
| 392 | call = RecentModel::instance().getActiveCall(recent_idx); |
| 393 | } |
| 394 | } |
| 395 | break; |
| 396 | case Ring::ObjectType::Call: |
| 397 | { |
| 398 | /* if the call is over (eg: if it comes from the history model) then we first check |
| 399 | * if there is an ongoing call with the same ContactMethod, otherwise we need to get |
| 400 | * the associated Person or ContactMethod */ |
| 401 | call = object.value<Call *>(); |
| 402 | if (call->isHistory()) { |
| 403 | cm = call->peerContactMethod(); |
| 404 | call = nullptr; |
| 405 | if (cm) { |
| 406 | auto recent_idx = RecentModel::instance().getIndex(cm); |
| 407 | if (recent_idx.isValid()) { |
| 408 | call = RecentModel::instance().getActiveCall(recent_idx); |
| 409 | } |
| 410 | person = cm->contact(); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 411 | } |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 412 | } |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 413 | } |
| 414 | break; |
| 415 | case Ring::ObjectType::Media: |
| 416 | case Ring::ObjectType::Certificate: |
Nicolas Jager | c74f761 | 2017-03-28 09:48:18 -0400 | [diff] [blame^] | 417 | case Ring::ObjectType::ContactRequest: |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 418 | case Ring::ObjectType::COUNT__: |
| 419 | // nothing to do |
| 420 | break; |
| 421 | } |
| 422 | |
| 423 | /* we prioritize showing the call view */ |
| 424 | if (call) { |
| 425 | auto state = call->lifeCycleState(); |
| 426 | |
| 427 | Call *current_call = nullptr; |
| 428 | |
| 429 | switch(state) { |
| 430 | case Call::LifeCycleState::CREATION: |
| 431 | case Call::LifeCycleState::INITIALIZATION: |
| 432 | case Call::LifeCycleState::FINISHED: |
| 433 | // check if we're already displaying this call |
| 434 | if (IS_INCOMING_CALL_VIEW(old_view)) |
| 435 | current_call = incoming_call_view_get_call(INCOMING_CALL_VIEW(old_view)); |
| 436 | if (current_call != call) |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 437 | change_view(win, old_view, call, INCOMING_CALL_VIEW_TYPE); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 438 | break; |
| 439 | case Call::LifeCycleState::PROGRESS: |
| 440 | // check if we're already displaying this call |
| 441 | if (IS_CURRENT_CALL_VIEW(old_view)) |
| 442 | current_call = current_call_view_get_call(CURRENT_CALL_VIEW(old_view)); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 443 | if (current_call != call) |
| 444 | change_view(win, old_view, call, CURRENT_CALL_VIEW_TYPE); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 445 | break; |
| 446 | case Call::LifeCycleState::COUNT__: |
| 447 | g_warning("LifeCycleState should never be COUNT"); |
| 448 | break; |
| 449 | } |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 450 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 451 | } else if (person) { |
| 452 | /* show chat view constructed from Person object */ |
| 453 | |
| 454 | // check if we're already displaying the chat view for this person |
| 455 | Person *current_person = nullptr; |
| 456 | if (IS_CHAT_VIEW(old_view)) |
| 457 | current_person = chat_view_get_person(CHAT_VIEW(old_view)); |
| 458 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 459 | if (current_person != person) |
| 460 | change_view(win, old_view, person, CHAT_VIEW_TYPE); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 461 | } else if (cm) { |
| 462 | /* show chat view constructed from CM */ |
| 463 | |
| 464 | // check if we're already displaying the chat view for this cm |
| 465 | ContactMethod *current_cm = nullptr; |
| 466 | if (IS_CHAT_VIEW(old_view)) |
| 467 | current_cm = chat_view_get_cm(CHAT_VIEW(old_view)); |
| 468 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 469 | if (current_cm != cm) |
| 470 | change_view(win, old_view, cm, CHAT_VIEW_TYPE); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 471 | } else { |
| 472 | /* not a supported object type, display the welcome view */ |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 473 | if (old_view != priv->welcome_view) |
| 474 | change_view(win, old_view, nullptr, RING_WELCOME_VIEW_TYPE); |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 475 | } |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 476 | } else { |
| 477 | /* selection isn't valid, display the welcome view */ |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 478 | if (old_view != priv->welcome_view) |
| 479 | change_view(win, old_view, nullptr, RING_WELCOME_VIEW_TYPE); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 480 | } |
Stepan Salenikovich | 504f772 | 2016-01-20 17:10:45 -0500 | [diff] [blame] | 481 | |
| 482 | return G_SOURCE_REMOVE; |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 483 | } |
| 484 | |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 485 | static void |
Nicolas Jager | 65d6e1f | 2017-03-27 16:57:55 -0400 | [diff] [blame] | 486 | process_search_entry_contact_method(RingMainWindow *self, const URI& uri, Account* accountOrNullptr) |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 487 | { |
| 488 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 489 | |
Nicolas Jager | 65d6e1f | 2017-03-27 16:57:55 -0400 | [diff] [blame] | 490 | auto cm = PhoneDirectoryModel::instance().getNumber(uri, accountOrNullptr); |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 491 | |
| 492 | if (g_settings_get_boolean(priv->settings, "search-entry-places-call")) { |
| 493 | place_new_call(cm); |
| 494 | |
| 495 | /* move focus away from entry so that DTMF tones can be entered via the keyboard */ |
| 496 | gtk_widget_child_focus(GTK_WIDGET(self), GTK_DIR_TAB_FORWARD); |
| 497 | } else { |
| 498 | // if its a new CM, bring it to the top |
| 499 | if (cm->lastUsed() == 0) |
| 500 | cm->setLastUsed(QDateTime::currentDateTime().toTime_t()); |
| 501 | |
| 502 | // select cm |
| 503 | RecentModel::instance().selectionModel()->setCurrentIndex(RecentModel::instance().getIndex(cm), QItemSelectionModel::ClearAndSelect); |
| 504 | } |
| 505 | gtk_entry_set_text(GTK_ENTRY(priv->search_entry), ""); |
| 506 | } |
| 507 | |
| 508 | static void |
Stepan Salenikovich | b0ffc34 | 2016-10-13 13:10:55 -0400 | [diff] [blame] | 509 | search_entry_activated(RingMainWindow *self) |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame] | 510 | { |
Stepan Salenikovich | b0ffc34 | 2016-10-13 13:10:55 -0400 | [diff] [blame] | 511 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame] | 512 | |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 513 | const auto *querry = gtk_entry_get_text(GTK_ENTRY(priv->search_entry)); |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame] | 514 | |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 515 | URI uri = URI(querry); |
Stepan Salenikovich | 7b7be48 | 2016-11-03 16:57:48 -0400 | [diff] [blame] | 516 | |
| 517 | |
| 518 | // make sure the userinfo part isn't empty, only specifying a protocol isn't enough |
| 519 | if (!uri.userinfo().isEmpty()) { |
| 520 | |
| 521 | gboolean lookup_username = FALSE; |
| 522 | |
Stepan Salenikovich | efd8cae | 2016-11-10 13:41:30 -0500 | [diff] [blame] | 523 | /* get the account with which we will do the lookup */ |
| 524 | auto ring_account = AvailableAccountModel::instance().currentDefaultAccount(URI::SchemeType::RING); |
| 525 | |
Stepan Salenikovich | 7b7be48 | 2016-11-03 16:57:48 -0400 | [diff] [blame] | 526 | if (uri.protocolHint() == URI::ProtocolHint::RING_USERNAME ) { |
| 527 | lookup_username = TRUE; |
| 528 | } else if ( |
| 529 | uri.protocolHint() != URI::ProtocolHint::RING && // not a RingID |
| 530 | uri.schemeType() == URI::SchemeType::NONE // scheme type not specified |
| 531 | ) { |
| 532 | // if no scheme type has been specified, determine ring vs sip by the first available account |
| 533 | auto idx = AvailableAccountModel::instance().index(0, 0); |
| 534 | if (idx.isValid()) { |
| 535 | auto account = idx.data((int)Ring::Role::Object).value<Account *>(); |
| 536 | if (account && account->protocol() == Account::Protocol::RING) |
| 537 | lookup_username = TRUE; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | if (lookup_username) |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 542 | { |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 543 | gtk_spinner_start(GTK_SPINNER(priv->spinner_lookup)); |
Guillaume Roguez | e7221ed | 2017-03-17 20:09:56 -0400 | [diff] [blame] | 544 | *priv->pending_username_lookup = querry; |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 545 | gtk_entry_set_text(GTK_ENTRY(priv->search_entry), ""); |
Stepan Salenikovich | 895a70b | 2015-03-27 16:02:27 -0400 | [diff] [blame] | 546 | |
aviau | 8f436a3 | 2016-11-05 01:49:55 -0400 | [diff] [blame] | 547 | QString username_to_lookup = uri.format( |
| 548 | URI::Section::USER_INFO | |
| 549 | URI::Section::HOSTNAME | |
| 550 | URI::Section::PORT |
| 551 | ); |
Stepan Salenikovich | 895a70b | 2015-03-27 16:02:27 -0400 | [diff] [blame] | 552 | |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 553 | QObject::disconnect(priv->username_lookup); |
| 554 | priv->username_lookup = QObject::connect( |
| 555 | &NameDirectory::instance(), |
| 556 | &NameDirectory::registeredNameFound, |
Nicolas Jager | 65d6e1f | 2017-03-27 16:57:55 -0400 | [diff] [blame] | 557 | [self, priv, username_to_lookup] (Account* account, NameDirectory::LookupStatus status, const QString& address, const QString& name) { |
Stepan Salenikovich | 1564bba | 2015-04-29 11:28:43 -0400 | [diff] [blame] | 558 | |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 559 | auto name_qbarray = name.toLatin1(); |
Guillaume Roguez | e7221ed | 2017-03-17 20:09:56 -0400 | [diff] [blame] | 560 | if ( strcmp(priv->pending_username_lookup->data(), name_qbarray.data()) != 0 ) |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 561 | return; |
| 562 | |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 563 | gtk_entry_set_text(GTK_ENTRY(priv->search_entry), ""); |
| 564 | |
| 565 | switch(status) |
| 566 | { |
| 567 | case NameDirectory::LookupStatus::SUCCESS: |
| 568 | { |
| 569 | URI uri = URI("ring:" + address); |
Nicolas Jager | 65d6e1f | 2017-03-27 16:57:55 -0400 | [diff] [blame] | 570 | process_search_entry_contact_method(self, uri, account); |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 571 | break; |
| 572 | } |
| 573 | case NameDirectory::LookupStatus::INVALID_NAME: |
| 574 | { |
| 575 | //Can't be a ring username, could be something else. |
| 576 | auto dialog = gtk_message_dialog_new( |
| 577 | GTK_WINDOW(self), |
| 578 | GTK_DIALOG_DESTROY_WITH_PARENT, |
| 579 | GTK_MESSAGE_ERROR, |
| 580 | GTK_BUTTONS_CLOSE, |
| 581 | _("Invalid Ring username: %s"), |
| 582 | name.toUtf8().constData() |
| 583 | ); |
| 584 | |
| 585 | gtk_dialog_run (GTK_DIALOG (dialog)); |
| 586 | gtk_widget_destroy (dialog); |
| 587 | break; |
| 588 | } |
| 589 | case NameDirectory::LookupStatus::ERROR: |
Stepan Salenikovich | fa24b93 | 2016-11-21 15:19:57 -0500 | [diff] [blame] | 590 | { |
| 591 | auto dialog = gtk_message_dialog_new( |
| 592 | GTK_WINDOW(self), |
| 593 | GTK_DIALOG_DESTROY_WITH_PARENT, |
| 594 | GTK_MESSAGE_ERROR, |
| 595 | GTK_BUTTONS_CLOSE, |
| 596 | _("Error resolving username, nameserver is possibly unreachable") |
| 597 | ); |
| 598 | |
| 599 | gtk_dialog_run(GTK_DIALOG (dialog)); |
| 600 | gtk_widget_destroy(dialog); |
| 601 | break; |
| 602 | } |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 603 | case NameDirectory::LookupStatus::NOT_FOUND: |
| 604 | { |
| 605 | auto dialog = gtk_message_dialog_new( |
| 606 | GTK_WINDOW(self), |
| 607 | GTK_DIALOG_DESTROY_WITH_PARENT, |
| 608 | GTK_MESSAGE_ERROR, |
| 609 | GTK_BUTTONS_CLOSE, |
| 610 | _("Could not resolve Ring username: %s"), |
| 611 | name.toUtf8().constData() |
| 612 | ); |
| 613 | |
| 614 | gtk_dialog_run(GTK_DIALOG (dialog)); |
| 615 | gtk_widget_destroy(dialog); |
| 616 | break; |
| 617 | } |
| 618 | } |
Guillaume Roguez | e7221ed | 2017-03-17 20:09:56 -0400 | [diff] [blame] | 619 | *priv->pending_username_lookup = ""; |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 620 | gtk_spinner_stop(GTK_SPINNER(priv->spinner_lookup)); |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 621 | } |
| 622 | ); |
| 623 | |
Stepan Salenikovich | efd8cae | 2016-11-10 13:41:30 -0500 | [diff] [blame] | 624 | NameDirectory::instance().lookupName(ring_account, QString(), username_to_lookup); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 625 | } |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 626 | else |
| 627 | { |
Guillaume Roguez | e7221ed | 2017-03-17 20:09:56 -0400 | [diff] [blame] | 628 | *priv->pending_username_lookup = ""; |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 629 | gtk_spinner_stop(GTK_SPINNER(priv->spinner_lookup)); |
Nicolas Jager | 65d6e1f | 2017-03-27 16:57:55 -0400 | [diff] [blame] | 630 | process_search_entry_contact_method(self, uri, nullptr); |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 631 | } |
Stepan Salenikovich | 2e6ab56 | 2015-05-07 12:33:07 -0400 | [diff] [blame] | 632 | } |
Stepan Salenikovich | 297b5d1 | 2015-02-26 17:51:13 -0500 | [diff] [blame] | 633 | } |
| 634 | |
Stepan Salenikovich | 7c71bfe | 2015-05-13 18:08:09 -0400 | [diff] [blame] | 635 | static gboolean |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 636 | save_accounts(GtkWidget *working_dialog) |
| 637 | { |
| 638 | /* save changes to accounts */ |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 639 | AccountModel::instance().save(); |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 640 | |
| 641 | if (working_dialog) |
| 642 | gtk_widget_destroy(working_dialog); |
| 643 | |
| 644 | return G_SOURCE_REMOVE; |
| 645 | } |
| 646 | |
Stepan Salenikovich | 1514218 | 2015-03-11 17:15:26 -0400 | [diff] [blame] | 647 | static void |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 648 | settings_clicked(G_GNUC_UNUSED GtkButton *button, RingMainWindow *win) |
| 649 | { |
| 650 | g_return_if_fail(IS_RING_MAIN_WINDOW(win)); |
| 651 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 652 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 653 | /* check which view to show */ |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 654 | if (!priv->show_settings) { |
| 655 | /* show the settings */ |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 656 | priv->show_settings = TRUE; |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 657 | |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 658 | /* make sure we are not showing a call view so we don't have more than one clutter stage at a time */ |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 659 | selection_changed(win); |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 660 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 661 | /* show settings */ |
Stepan Salenikovich | d61974b | 2016-03-18 16:36:27 -0400 | [diff] [blame] | 662 | gtk_image_set_from_icon_name(GTK_IMAGE(priv->image_settings), "emblem-ok-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 663 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 664 | gtk_widget_show(priv->hbox_settings); |
| 665 | |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 666 | /* make sure to start preview if we're showing the video settings */ |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 667 | if (priv->last_settings_view == priv->media_settings_view) |
| 668 | media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 669 | |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 670 | /* make sure to show the profile if we're showing the general settings */ |
| 671 | if (priv->last_settings_view == priv->general_settings_view) |
| 672 | general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE); |
| 673 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 674 | gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_UP); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 675 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_main_view), priv->last_settings_view); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 676 | } else { |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 677 | /* hide the settings */ |
| 678 | priv->show_settings = FALSE; |
| 679 | |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 680 | /* show working dialog in case save operation takes time */ |
| 681 | GtkWidget *working = ring_dialog_working(GTK_WIDGET(win), NULL); |
| 682 | gtk_window_present(GTK_WINDOW(working)); |
| 683 | |
| 684 | /* now save after the time it takes to transition back to the call view (400ms) |
| 685 | * the save doesn't happen before the "working" dialog is presented |
| 686 | * the timeout function should destroy the "working" dialog when done saving |
| 687 | */ |
Stepan Salenikovich | 12fee94 | 2015-03-25 18:38:47 -0400 | [diff] [blame] | 688 | g_timeout_add_full(G_PRIORITY_DEFAULT, 400, (GSourceFunc)save_accounts, working, NULL); |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 689 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 690 | /* show calls */ |
Stepan Salenikovich | d61974b | 2016-03-18 16:36:27 -0400 | [diff] [blame] | 691 | gtk_image_set_from_icon_name(GTK_IMAGE(priv->image_settings), "emblem-system-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 692 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 693 | gtk_widget_hide(priv->hbox_settings); |
| 694 | |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 695 | /* make sure video preview is stopped, in case it was started */ |
| 696 | media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE); |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 697 | general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE); |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 698 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 699 | gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_DOWN); |
| 700 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), CALL_VIEW_NAME); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 701 | |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 702 | /* show the view which was selected previously */ |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 703 | selection_changed(win); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
| 707 | static void |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 708 | show_media_settings(GtkToggleButton *navbutton, RingMainWindow *win) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 709 | { |
| 710 | g_return_if_fail(IS_RING_MAIN_WINDOW(win)); |
| 711 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 712 | |
| 713 | if (gtk_toggle_button_get_active(navbutton)) { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 714 | media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 715 | gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 716 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), MEDIA_SETTINGS_VIEW_NAME); |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 717 | priv->last_settings_view = priv->media_settings_view; |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 718 | } else { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 719 | media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | static void |
| 724 | show_account_settings(GtkToggleButton *navbutton, RingMainWindow *win) |
| 725 | { |
| 726 | g_return_if_fail(IS_RING_MAIN_WINDOW(win)); |
| 727 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 728 | |
| 729 | if (gtk_toggle_button_get_active(navbutton)) { |
| 730 | gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT); |
| 731 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), ACCOUNT_SETTINGS_VIEW_NAME); |
| 732 | priv->last_settings_view = priv->account_settings_view; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 736 | static void |
| 737 | show_general_settings(GtkToggleButton *navbutton, RingMainWindow *win) |
| 738 | { |
| 739 | g_return_if_fail(IS_RING_MAIN_WINDOW(win)); |
| 740 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 741 | |
| 742 | if (gtk_toggle_button_get_active(navbutton)) { |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 743 | general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 744 | gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT); |
| 745 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME); |
| 746 | priv->last_settings_view = priv->general_settings_view; |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 747 | } else { |
| 748 | general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 752 | static void |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 753 | on_account_creation_completed(RingMainWindow *win) |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 754 | { |
Stepan Salenikovich | babe26f | 2016-02-12 16:47:07 -0500 | [diff] [blame] | 755 | g_return_if_fail(IS_RING_MAIN_WINDOW(win)); |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 756 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 757 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 758 | gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT); |
| 759 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), CALL_VIEW_NAME); |
| 760 | |
| 761 | /* destroy the wizard */ |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 762 | if (priv->account_creation_wizard) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 763 | { |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 764 | gtk_container_remove(GTK_CONTAINER(priv->stack_main_view), priv->account_creation_wizard); |
| 765 | gtk_widget_destroy(priv->account_creation_wizard); |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 766 | } |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 767 | |
| 768 | /* show the settings button*/ |
| 769 | gtk_widget_show(priv->ring_settings); |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static void |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 773 | show_account_creation_wizard(RingMainWindow *win) |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 774 | { |
| 775 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 776 | |
aviau | 61d05b3 | 2016-10-18 16:47:53 -0400 | [diff] [blame] | 777 | if (!priv->account_creation_wizard) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 778 | { |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 779 | priv->account_creation_wizard = account_creation_wizard_new(false); |
| 780 | g_object_add_weak_pointer(G_OBJECT(priv->account_creation_wizard), (gpointer *)&priv->account_creation_wizard); |
| 781 | g_signal_connect_swapped(priv->account_creation_wizard, "account-creation-completed", G_CALLBACK(on_account_creation_completed), win); |
Stepan Salenikovich | 419414c | 2016-06-07 10:35:07 -0400 | [diff] [blame] | 782 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 783 | gtk_stack_add_named(GTK_STACK(priv->stack_main_view), |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 784 | priv->account_creation_wizard, |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 785 | ACCOUNT_CREATION_WIZARD_VIEW_NAME); |
| 786 | } |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 787 | |
Stepan Salenikovich | 6450567 | 2015-09-24 10:46:07 -0400 | [diff] [blame] | 788 | /* hide settings button until account creation is complete */ |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 789 | gtk_widget_hide(priv->ring_settings); |
| 790 | |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 791 | gtk_widget_show(priv->account_creation_wizard); |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 792 | |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 793 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_main_view), priv->account_creation_wizard); |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 794 | } |
| 795 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 796 | static void |
Stepan Salenikovich | a06ce19 | 2016-11-01 14:26:43 -0400 | [diff] [blame] | 797 | search_entry_text_changed(GtkSearchEntry *search_entry, RingMainWindow *self) |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 798 | { |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 799 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 800 | |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 801 | /* get the text from the entry */ |
| 802 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry)); |
| 803 | |
Stepan Salenikovich | f53128f | 2016-10-07 10:32:16 -0400 | [diff] [blame] | 804 | RecentModel::instance().peopleProxy()->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString)); |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 805 | contacts_view_set_filter_string(CONTACTS_VIEW(priv->treeview_contacts), text); |
| 806 | history_view_set_filter_string(HISTORY_VIEW(priv->treeview_history), text); |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 807 | } |
| 808 | |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 809 | static gboolean |
Stepan Salenikovich | cac3504 | 2016-10-28 12:07:38 -0400 | [diff] [blame] | 810 | search_entry_key_released(GtkEntry *search_entry, GdkEventKey *key, RingMainWindow *self) |
| 811 | { |
| 812 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 813 | |
| 814 | // if esc key pressed, clear the regex (keep the text, the user might not want to actually delete it) |
| 815 | if (key->keyval == GDK_KEY_Escape) { |
| 816 | RecentModel::instance().peopleProxy()->setFilterRegExp(QRegExp()); |
| 817 | contacts_view_set_filter_string(CONTACTS_VIEW(priv->treeview_contacts), ""); |
| 818 | history_view_set_filter_string(HISTORY_VIEW(priv->treeview_history), ""); |
| 819 | return GDK_EVENT_STOP; |
| 820 | } |
| 821 | |
| 822 | return GDK_EVENT_PROPAGATE; |
| 823 | } |
| 824 | |
| 825 | static gboolean |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 826 | dtmf_pressed(RingMainWindow *win, |
| 827 | GdkEventKey *event, |
| 828 | G_GNUC_UNUSED gpointer user_data) |
| 829 | { |
| 830 | g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE); |
| 831 | |
| 832 | /* we want to react to digit key presses, as long as a GtkEntry is not the |
| 833 | * input focus |
| 834 | */ |
| 835 | GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(win)); |
| 836 | if (GTK_IS_ENTRY(focus)) |
| 837 | return GDK_EVENT_PROPAGATE; |
| 838 | |
| 839 | /* make sure that a call is selected*/ |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 840 | QItemSelectionModel *selection = CallModel::instance().selectionModel(); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 841 | QModelIndex idx = selection->currentIndex(); |
| 842 | if (!idx.isValid()) |
| 843 | return GDK_EVENT_PROPAGATE; |
| 844 | |
| 845 | /* make sure that the selected call is in progress */ |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 846 | Call *call = CallModel::instance().getCall(idx); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 847 | Call::LifeCycleState state = call->lifeCycleState(); |
| 848 | if (state != Call::LifeCycleState::PROGRESS) |
| 849 | return GDK_EVENT_PROPAGATE; |
| 850 | |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 851 | /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c' |
| 852 | * does not result in a 'c' being played. |
| 853 | * we filter Ctrl, Alt, and SUPER/HYPER/META keys */ |
| 854 | if ( event->state |
| 855 | & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK )) |
| 856 | return GDK_EVENT_PROPAGATE; |
| 857 | |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 858 | /* pass the character that was entered to be played by the daemon; |
| 859 | * the daemon will filter out invalid DTMF characters */ |
| 860 | guint32 unicode_val = gdk_keyval_to_unicode(event->keyval); |
| 861 | QString val = QString::fromUcs4(&unicode_val, 1); |
| 862 | call->playDTMF(val); |
| 863 | g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData()); |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 864 | |
| 865 | /* always propogate the key, so we don't steal accelerators/shortcuts */ |
| 866 | return GDK_EVENT_PROPAGATE; |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 867 | } |
| 868 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 869 | /** |
| 870 | * This function determines if two different contact list views (Conversations, Contacts, History) |
| 871 | * have the same item selected. Note that the same item does not necessarily mean the same object. |
| 872 | * For example, if the history view has a Call selected and the Conversations view has a Person |
| 873 | * selected which is associated with the ContactMethod to which that Call was made, then this will |
| 874 | * evaluate to TRUE. |
| 875 | */ |
| 876 | static gboolean |
| 877 | compare_treeview_selection(GtkTreeSelection *selection1, GtkTreeSelection *selection2) |
| 878 | { |
| 879 | g_return_val_if_fail(selection1 && selection2, FALSE); |
| 880 | |
| 881 | if (selection1 == selection2) return TRUE; |
| 882 | |
| 883 | auto idx1 = get_index_from_selection(selection1); |
| 884 | auto type1 = idx1.data(static_cast<int>(Ring::Role::ObjectType)); |
| 885 | auto object1 = idx1.data(static_cast<int>(Ring::Role::Object)); |
| 886 | |
| 887 | auto idx2 = get_index_from_selection(selection2); |
| 888 | auto type2 = idx2.data(static_cast<int>(Ring::Role::ObjectType)); |
| 889 | auto object2 = idx2.data(static_cast<int>(Ring::Role::Object)); |
| 890 | |
| 891 | if (idx1.isValid() && type1.isValid() && object1.isValid() && idx2.isValid() && type2.isValid() && object2.isValid()) { |
| 892 | Call *call1 = nullptr; |
| 893 | ContactMethod *cm1 = nullptr; |
| 894 | Person *person1 = nullptr; |
| 895 | |
| 896 | Call *call2 = nullptr; |
| 897 | ContactMethod *cm2 = nullptr; |
| 898 | Person *person2 = nullptr; |
| 899 | |
| 900 | switch(type1.value<Ring::ObjectType>()) { |
| 901 | case Ring::ObjectType::Person: |
| 902 | person1 = object1.value<Person *>(); |
| 903 | break; |
| 904 | case Ring::ObjectType::ContactMethod: |
| 905 | cm1 = object1.value<ContactMethod *>(); |
| 906 | person1 = cm1->contact(); |
| 907 | break; |
| 908 | case Ring::ObjectType::Call: |
| 909 | call1 = object1.value<Call *>(); |
| 910 | cm1 = call1->peerContactMethod(); |
| 911 | person1 = cm1->contact(); |
| 912 | break; |
| 913 | case Ring::ObjectType::Media: |
| 914 | case Ring::ObjectType::Certificate: |
Nicolas Jager | c74f761 | 2017-03-28 09:48:18 -0400 | [diff] [blame^] | 915 | case Ring::ObjectType::ContactRequest: |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 916 | case Ring::ObjectType::COUNT__: |
| 917 | // nothing to do |
| 918 | break; |
| 919 | } |
| 920 | |
| 921 | switch(type2.value<Ring::ObjectType>()) { |
| 922 | case Ring::ObjectType::Person: |
| 923 | person2 = object2.value<Person *>(); |
| 924 | break; |
| 925 | case Ring::ObjectType::ContactMethod: |
| 926 | cm2 = object2.value<ContactMethod *>(); |
| 927 | person2 = cm2->contact(); |
| 928 | break; |
| 929 | case Ring::ObjectType::Call: |
| 930 | call2 = object2.value<Call *>(); |
| 931 | cm2 = call2->peerContactMethod(); |
| 932 | person2 = cm2->contact(); |
| 933 | break; |
| 934 | case Ring::ObjectType::Media: |
| 935 | case Ring::ObjectType::Certificate: |
Nicolas Jager | c74f761 | 2017-03-28 09:48:18 -0400 | [diff] [blame^] | 936 | case Ring::ObjectType::ContactRequest: |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 937 | case Ring::ObjectType::COUNT__: |
| 938 | // nothing to do |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | if (person1 != nullptr && person1 == person2) |
| 943 | return TRUE; |
| 944 | if (cm1 != nullptr && cm1 == cm2) |
| 945 | return TRUE; |
| 946 | if (call1 != nullptr && call1 == call2) |
| 947 | return TRUE; |
| 948 | } |
| 949 | |
| 950 | return FALSE; |
| 951 | } |
| 952 | |
| 953 | static void |
| 954 | conversation_selection_changed(GtkTreeSelection *selection, RingMainWindow *self) |
| 955 | { |
| 956 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 957 | GtkTreeIter iter; |
| 958 | GtkTreeModel *model = nullptr; |
| 959 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) { |
| 960 | /* something is selected in the conversations view, clear the selection in the other views; |
| 961 | * unless the current selection is of the same item; we don't try to match the selection in |
| 962 | * all views since not all items exist in all 3 contact list views |
| 963 | */ |
| 964 | |
| 965 | auto selection_contacts = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_contacts)); |
| 966 | if (!compare_treeview_selection(selection, selection_contacts)) |
| 967 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contacts)); |
| 968 | |
| 969 | auto selection_history = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_history)); |
| 970 | if (!compare_treeview_selection(selection, selection_history)) |
| 971 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_history)); |
| 972 | } |
| 973 | |
| 974 | selection_changed(self); |
| 975 | } |
| 976 | |
| 977 | static void |
| 978 | contact_selection_changed(GtkTreeSelection *selection, RingMainWindow *self) |
| 979 | { |
| 980 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 981 | GtkTreeIter iter; |
| 982 | if (gtk_tree_selection_get_selected(selection, nullptr, &iter)) { |
| 983 | /* something is selected in the contacts view, clear the selection in the other views; |
| 984 | * unless the current selection is of the same item; we don't try to match the selection in |
| 985 | * all views since not all items exist in all 3 contact list views |
| 986 | */ |
| 987 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_conversations)); |
| 988 | if (!compare_treeview_selection(selection, selection_conversations)) |
| 989 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations)); |
| 990 | |
| 991 | auto selection_history = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_history)); |
| 992 | if (!compare_treeview_selection(selection, selection_history)) |
| 993 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_history)); |
| 994 | } |
| 995 | |
| 996 | selection_changed(self); |
| 997 | } |
| 998 | |
| 999 | static void |
| 1000 | history_selection_changed(GtkTreeSelection *selection, RingMainWindow *self) |
| 1001 | { |
| 1002 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 1003 | GtkTreeIter iter; |
| 1004 | if (gtk_tree_selection_get_selected(selection, nullptr, &iter)) { |
| 1005 | /* something is selected in the history view, clear the selection in the other views; |
| 1006 | * unless the current selection is of the same item; we don't try to match the selection in |
| 1007 | * all views since not all items exist in all 3 contact list views |
| 1008 | */ |
| 1009 | |
| 1010 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_conversations)); |
| 1011 | if (!compare_treeview_selection(selection, selection_conversations)) |
| 1012 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations)); |
| 1013 | |
| 1014 | auto selection_contacts = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_contacts)); |
| 1015 | if (!compare_treeview_selection(selection, selection_contacts)) |
| 1016 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contacts)); |
| 1017 | } |
| 1018 | |
| 1019 | selection_changed(self); |
| 1020 | } |
| 1021 | |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 1022 | static gboolean |
| 1023 | window_size_changed(GtkWidget *win, GdkEventConfigure *event, gpointer) |
| 1024 | { |
| 1025 | auto *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 1026 | |
| 1027 | g_settings_set_int(priv->settings, "window-width", event->width); |
| 1028 | g_settings_set_int(priv->settings, "window-height", event->height); |
| 1029 | |
| 1030 | return GDK_EVENT_PROPAGATE; |
| 1031 | } |
| 1032 | |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 1033 | static void |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 1034 | search_entry_places_call_changed(GSettings *settings, const gchar *key, RingMainWindow *self) |
| 1035 | { |
| 1036 | auto priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 1037 | |
| 1038 | if (g_settings_get_boolean(settings, key)) { |
| 1039 | gtk_widget_set_tooltip_text(priv->button_new_conversation, C_("button next to search entry will place a new call", "place call")); |
| 1040 | } else { |
| 1041 | gtk_widget_set_tooltip_text(priv->button_new_conversation, C_("button next to search entry will open chat", "open chat")); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | static void |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1046 | handle_account_migrations(RingMainWindow *win) |
| 1047 | { |
| 1048 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 1049 | |
| 1050 | /* If there is an existing migration view, remove it */ |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 1051 | if (priv->account_migration_view) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1052 | { |
Stepan Salenikovich | 56530b1 | 2016-10-20 17:51:34 -0400 | [diff] [blame] | 1053 | gtk_widget_destroy(priv->account_migration_view); |
| 1054 | priv->account_migration_view = nullptr; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | QList<Account*> accounts = AccountModel::instance().accountsToMigrate(); |
| 1058 | if (!accounts.isEmpty()) |
| 1059 | { |
| 1060 | Account* account = accounts.first(); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1061 | |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 1062 | priv->account_migration_view = account_migration_view_new(account); |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 1063 | g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed", G_CALLBACK(handle_account_migrations), win); |
| 1064 | g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed", G_CALLBACK(handle_account_migrations), win); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1065 | |
| 1066 | gtk_widget_hide(priv->ring_settings); |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 1067 | gtk_widget_show(priv->account_migration_view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1068 | gtk_stack_add_named( |
| 1069 | GTK_STACK(priv->stack_main_view), |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 1070 | priv->account_migration_view, |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1071 | ACCOUNT_MIGRATION_VIEW_NAME |
| 1072 | ); |
| 1073 | gtk_stack_set_visible_child_name( |
| 1074 | GTK_STACK(priv->stack_main_view), |
| 1075 | ACCOUNT_MIGRATION_VIEW_NAME |
| 1076 | ); |
| 1077 | } |
| 1078 | else |
| 1079 | { |
| 1080 | gtk_widget_show(priv->ring_settings); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | static void |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1085 | ring_main_window_init(RingMainWindow *win) |
| 1086 | { |
| 1087 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
| 1088 | gtk_widget_init_template(GTK_WIDGET(win)); |
| 1089 | |
Guillaume Roguez | e7221ed | 2017-03-17 20:09:56 -0400 | [diff] [blame] | 1090 | priv->pending_username_lookup = new std::string; // see object finilize for delete |
| 1091 | |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 1092 | /* bind to window size settings */ |
| 1093 | priv->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr); |
| 1094 | auto width = g_settings_get_int(priv->settings, "window-width"); |
| 1095 | auto height = g_settings_get_int(priv->settings, "window-height"); |
| 1096 | gtk_window_set_default_size(GTK_WINDOW(win), width, height); |
| 1097 | g_signal_connect(win, "configure-event", G_CALLBACK(window_size_changed), nullptr); |
| 1098 | |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 1099 | /* search-entry-places-call setting */ |
| 1100 | search_entry_places_call_changed(priv->settings, "search-entry-places-call", win); |
| 1101 | g_signal_connect(priv->settings, "changed::search-entry-places-call", G_CALLBACK(search_entry_places_call_changed), win); |
| 1102 | |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1103 | /* set window icon */ |
| 1104 | GError *error = NULL; |
| 1105 | GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error); |
| 1106 | if (icon == NULL) { |
| 1107 | g_debug("Could not load icon: %s", error->message); |
Stepan Salenikovich | 8a287fc | 2015-05-01 16:53:20 -0400 | [diff] [blame] | 1108 | g_clear_error(&error); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1109 | } else |
| 1110 | gtk_window_set_icon(GTK_WINDOW(win), icon); |
| 1111 | |
| 1112 | /* set menu icon */ |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1113 | GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue", |
Stepan Salenikovich | d61974b | 2016-03-18 16:36:27 -0400 | [diff] [blame] | 1114 | -1, 16, TRUE, &error); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1115 | if (image_ring == NULL) { |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1116 | g_debug("Could not load icon: %s", error->message); |
Stepan Salenikovich | 8a287fc | 2015-05-01 16:53:20 -0400 | [diff] [blame] | 1117 | g_clear_error(&error); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1118 | } else |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1119 | gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_ring), image_ring); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1120 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1121 | /* ring menu */ |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1122 | GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui"); |
| 1123 | GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu")); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1124 | gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(priv->ring_menu), menu); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1125 | g_object_unref(builder); |
Stepan Salenikovich | a355745 | 2015-02-20 14:14:12 -0500 | [diff] [blame] | 1126 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1127 | /* settings icon */ |
Stepan Salenikovich | d61974b | 2016-03-18 16:36:27 -0400 | [diff] [blame] | 1128 | gtk_image_set_from_icon_name(GTK_IMAGE(priv->image_settings), "emblem-system-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1129 | |
| 1130 | /* connect settings button signal */ |
| 1131 | g_signal_connect(priv->ring_settings, "clicked", G_CALLBACK(settings_clicked), win); |
| 1132 | |
| 1133 | /* add the call view to the main stack */ |
| 1134 | gtk_stack_add_named(GTK_STACK(priv->stack_main_view), |
| 1135 | priv->vbox_call_view, |
| 1136 | CALL_VIEW_NAME); |
| 1137 | |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 1138 | if (has_ring_account()) { |
| 1139 | /* user has ring account, so show the call view right away */ |
| 1140 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_main_view), priv->vbox_call_view); |
| 1141 | } else { |
| 1142 | /* user has to create the ring account */ |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1143 | show_account_creation_wizard(win); |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 1144 | } |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1145 | |
| 1146 | /* init the settings views */ |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1147 | priv->account_settings_view = account_view_new(); |
| 1148 | gtk_stack_add_named(GTK_STACK(priv->stack_main_view), priv->account_settings_view, ACCOUNT_SETTINGS_VIEW_NAME); |
| 1149 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 1150 | priv->media_settings_view = media_settings_view_new(); |
| 1151 | gtk_stack_add_named(GTK_STACK(priv->stack_main_view), priv->media_settings_view, MEDIA_SETTINGS_VIEW_NAME); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 1152 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 1153 | priv->general_settings_view = general_settings_view_new(); |
| 1154 | gtk_stack_add_named(GTK_STACK(priv->stack_main_view), priv->general_settings_view, GENERAL_SETTINGS_VIEW_NAME); |
| 1155 | |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 1156 | /* make the setting we will show first the active one */ |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 1157 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_general_settings), TRUE); |
| 1158 | priv->last_settings_view = priv->general_settings_view; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 1159 | |
| 1160 | /* connect the settings button signals to switch settings views */ |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 1161 | g_signal_connect(priv->radiobutton_media_settings, "toggled", G_CALLBACK(show_media_settings), win); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 1162 | g_signal_connect(priv->radiobutton_account_settings, "toggled", G_CALLBACK(show_account_settings), win); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 1163 | g_signal_connect(priv->radiobutton_general_settings, "toggled", G_CALLBACK(show_general_settings), win); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 1164 | |
Stepan Salenikovich | a7a19bc | 2015-09-24 16:16:28 -0400 | [diff] [blame] | 1165 | /* populate the notebook */ |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1166 | priv->treeview_conversations = recent_contacts_view_new(); |
| 1167 | gtk_container_add(GTK_CONTAINER(priv->scrolled_window_smartview), priv->treeview_conversations); |
Stepan Salenikovich | 7c71bfe | 2015-05-13 18:08:09 -0400 | [diff] [blame] | 1168 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1169 | priv->treeview_contacts = contacts_view_new(); |
| 1170 | gtk_container_add(GTK_CONTAINER(priv->scrolled_window_contacts), priv->treeview_contacts); |
Stepan Salenikovich | 1514218 | 2015-03-11 17:15:26 -0400 | [diff] [blame] | 1171 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1172 | priv->treeview_history = history_view_new(); |
| 1173 | gtk_container_add(GTK_CONTAINER(priv->scrolled_window_history), priv->treeview_history); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1174 | |
Stepan Salenikovich | 2cde761 | 2015-09-25 10:44:01 -0400 | [diff] [blame] | 1175 | /* welcome/default view */ |
Stepan Salenikovich | 3034d92 | 2015-10-09 10:11:42 -0400 | [diff] [blame] | 1176 | priv->welcome_view = ring_welcome_view_new(); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1177 | g_object_ref(priv->welcome_view); // increase ref because don't want it to be destroyed when not displayed |
Stepan Salenikovich | 3034d92 | 2015-10-09 10:11:42 -0400 | [diff] [blame] | 1178 | gtk_container_add(GTK_CONTAINER(priv->frame_call), priv->welcome_view); |
| 1179 | gtk_widget_show(priv->welcome_view); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 1180 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1181 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_conversations)); |
| 1182 | g_signal_connect(selection_conversations, "changed", G_CALLBACK(conversation_selection_changed), win); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 1183 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1184 | auto selection_contacts = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_contacts)); |
| 1185 | g_signal_connect(selection_contacts, "changed", G_CALLBACK(contact_selection_changed), win); |
| 1186 | |
| 1187 | auto selection_history = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview_history)); |
| 1188 | g_signal_connect(selection_history, "changed", G_CALLBACK(history_selection_changed), win); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 1189 | |
Stepan Salenikovich | b0ffc34 | 2016-10-13 13:10:55 -0400 | [diff] [blame] | 1190 | g_signal_connect_swapped(priv->button_new_conversation, "clicked", G_CALLBACK(search_entry_activated), win); |
| 1191 | g_signal_connect_swapped(priv->search_entry, "activate", G_CALLBACK(search_entry_activated), win); |
Stepan Salenikovich | a06ce19 | 2016-11-01 14:26:43 -0400 | [diff] [blame] | 1192 | g_signal_connect(priv->search_entry, "search-changed", G_CALLBACK(search_entry_text_changed), win); |
Stepan Salenikovich | cac3504 | 2016-10-28 12:07:38 -0400 | [diff] [blame] | 1193 | g_signal_connect(priv->search_entry, "key-release-event", G_CALLBACK(search_entry_key_released), win); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1194 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1195 | /* make sure the incoming call is the selected call in the CallModel */ |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1196 | QObject::connect( |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 1197 | &CallModel::instance(), |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1198 | &CallModel::incomingCall, |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 1199 | [priv](Call* call) { |
Stepan Salenikovich | f53128f | 2016-10-07 10:32:16 -0400 | [diff] [blame] | 1200 | // clear the regex to make sure the call is shown |
| 1201 | RecentModel::instance().peopleProxy()->setFilterRegExp(QRegExp()); |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 1202 | contacts_view_set_filter_string(CONTACTS_VIEW(priv->treeview_contacts),""); |
| 1203 | history_view_set_filter_string(HISTORY_VIEW(priv->treeview_history), ""); |
Stepan Salenikovich | f53128f | 2016-10-07 10:32:16 -0400 | [diff] [blame] | 1204 | |
| 1205 | // now make sure its selected |
| 1206 | RecentModel::instance().selectionModel()->clearCurrentIndex(); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1207 | CallModel::instance().selectCall(call); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1208 | } |
| 1209 | ); |
Stepan Salenikovich | 5eab303 | 2015-03-28 10:50:51 -0400 | [diff] [blame] | 1210 | |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 1211 | /* react to digit key press events */ |
| 1212 | g_signal_connect(win, "key-press-event", G_CALLBACK(dtmf_pressed), NULL); |
Stepan Salenikovich | 48b45c1 | 2015-09-25 15:49:51 -0400 | [diff] [blame] | 1213 | |
| 1214 | /* set the search entry placeholder text */ |
| 1215 | gtk_entry_set_placeholder_text(GTK_ENTRY(priv->search_entry), |
| 1216 | C_("Please try to make the translation 50 chars or less so that it fits into the layout", "Search contacts or enter number")); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1217 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 1218 | /* init chat webkit container so that it starts loading before the first time we need it*/ |
| 1219 | get_webkit_chat_container(win); |
| 1220 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1221 | handle_account_migrations(win); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | static void |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1225 | ring_main_window_dispose(GObject *object) |
| 1226 | { |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 1227 | RingMainWindow *self = RING_MAIN_WINDOW(object); |
| 1228 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 1229 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 1230 | QObject::disconnect(priv->selected_item_changed); |
| 1231 | QObject::disconnect(priv->selected_call_over); |
aviau | 8c0b242 | 2016-10-31 16:06:44 -0400 | [diff] [blame] | 1232 | QObject::disconnect(priv->username_lookup); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 1233 | |
| 1234 | g_clear_object(&priv->welcome_view); |
| 1235 | g_clear_object(&priv->webkit_chat_container); |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 1236 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1237 | G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object); |
| 1238 | } |
| 1239 | |
| 1240 | static void |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1241 | ring_main_window_finalize(GObject *object) |
| 1242 | { |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 1243 | RingMainWindow *self = RING_MAIN_WINDOW(object); |
| 1244 | RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
| 1245 | |
| 1246 | g_clear_object(&priv->settings); |
| 1247 | |
Guillaume Roguez | e7221ed | 2017-03-17 20:09:56 -0400 | [diff] [blame] | 1248 | delete priv->pending_username_lookup; |
| 1249 | priv->pending_username_lookup = nullptr; |
| 1250 | |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1251 | G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | static void |
| 1255 | ring_main_window_class_init(RingMainWindowClass *klass) |
| 1256 | { |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1257 | G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1258 | G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose; |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1259 | |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1260 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 1261 | "/cx/ring/RingGnome/ringmainwindow.ui"); |
| 1262 | |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 1263 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 1264 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview); |
Stepan Salenikovich | a7a19bc | 2015-09-24 16:16:28 -0400 | [diff] [blame] | 1265 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contacts); |
| 1266 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_history); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1267 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu); |
| 1268 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring); |
| 1269 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings); |
| 1270 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_settings); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1271 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, hbox_settings); |
Stepan Salenikovich | 45d25aa | 2015-02-20 17:39:09 -0500 | [diff] [blame] | 1272 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, search_entry); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 1273 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, stack_main_view); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1274 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_call_view); |
Stepan Salenikovich | 3034d92 | 2015-10-09 10:11:42 -0400 | [diff] [blame] | 1275 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, frame_call); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 1276 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, button_new_conversation ); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1277 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_general_settings); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 1278 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1279 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings); |
Nicolas Jager | 5590314 | 2017-02-01 14:43:45 -0500 | [diff] [blame] | 1280 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, spinner_lookup); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | GtkWidget * |
| 1284 | ring_main_window_new (GtkApplication *app) |
| 1285 | { |
Stepan Salenikovich | 61cbab0 | 2015-03-16 18:35:10 -0400 | [diff] [blame] | 1286 | gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL); |
| 1287 | |
Stepan Salenikovich | 61cbab0 | 2015-03-16 18:35:10 -0400 | [diff] [blame] | 1288 | return (GtkWidget *)win; |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1289 | } |