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