Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1 | /* |
Guillaume Roguez | 2a6150d | 2017-07-19 18:24:47 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015-2017 Savoir-faire Linux Inc. |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 3 | * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> |
Guillaume Roguez | 6d4734e | 2017-05-26 16:44:45 -0400 | [diff] [blame] | 4 | * Author: Guillaume Roguew <guillaume.roguez@savoirfairelinux.com> |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "ringmainwindow.h" |
| 22 | |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 23 | // GTK+ related |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 24 | #include <glib/gi18n.h> |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 25 | |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 26 | // LRC |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 27 | #include <accountmodel.h> // Old lrc but still used |
| 28 | #include <api/account.h> |
| 29 | #include <api/contact.h> |
| 30 | #include <api/profile.h> |
| 31 | #include <api/contactmodel.h> |
| 32 | #include <api/conversation.h> |
| 33 | #include <api/conversationmodel.h> |
| 34 | #include <api/lrc.h> |
| 35 | #include <api/newaccountmodel.h> |
| 36 | #include <api/newcallmodel.h> |
| 37 | #include <api/behaviorcontroller.h> |
| 38 | #include "accountcontainer.h" |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 39 | |
| 40 | // Ring client |
Stepan Salenikovich | 5fd97bc | 2016-08-30 09:40:38 -0400 | [diff] [blame] | 41 | #include "accountview.h" |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 42 | #include "accountmigrationview.h" |
| 43 | #include "accountcreationwizard.h" |
Stepan Salenikovich | c6a3b98 | 2016-01-11 18:11:39 -0500 | [diff] [blame] | 44 | #include "chatview.h" |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 45 | #include "conversationsview.h" |
| 46 | #include "currentcallview.h" |
| 47 | #include "dialogs.h" |
| 48 | #include "generalsettingsview.h" |
| 49 | #include "incomingcallview.h" |
| 50 | #include "mediasettingsview.h" |
| 51 | #include "models/gtkqtreemodel.h" |
| 52 | #include "ringwelcomeview.h" |
| 53 | #include "utils/accounts.h" |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 54 | #include "utils/files.h" |
Nicolas Jager | b413b30 | 2016-05-06 11:41:32 -0400 | [diff] [blame] | 55 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 56 | //============================================================================== |
| 57 | |
| 58 | namespace details |
| 59 | { |
| 60 | class CppImpl; |
| 61 | } |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 62 | |
| 63 | struct _RingMainWindow |
| 64 | { |
| 65 | GtkApplicationWindow parent; |
| 66 | }; |
| 67 | |
| 68 | struct _RingMainWindowClass |
| 69 | { |
| 70 | GtkApplicationWindowClass parent_class; |
| 71 | }; |
| 72 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 73 | struct RingMainWindowPrivate |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 74 | { |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 75 | GtkWidget *ring_menu; |
| 76 | GtkWidget *image_ring; |
| 77 | GtkWidget *ring_settings; |
| 78 | GtkWidget *image_settings; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 79 | GtkWidget *hbox_settings; |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 80 | GtkWidget *notebook_contacts; |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 81 | GtkWidget *scrolled_window_smartview; |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 82 | GtkWidget *treeview_conversations; |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 83 | GtkWidget *vbox_left_pane; |
Stepan Salenikovich | 45d25aa | 2015-02-20 17:39:09 -0500 | [diff] [blame] | 84 | GtkWidget *search_entry; |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 85 | GtkWidget *stack_main_view; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 86 | GtkWidget *vbox_call_view; |
Stepan Salenikovich | 3034d92 | 2015-10-09 10:11:42 -0400 | [diff] [blame] | 87 | GtkWidget *frame_call; |
| 88 | GtkWidget *welcome_view; |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 89 | GtkWidget *button_new_conversation; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 90 | GtkWidget *account_settings_view; |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 91 | GtkWidget *media_settings_view; |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 92 | GtkWidget *general_settings_view; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 93 | GtkWidget *last_settings_view; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 94 | GtkWidget *radiobutton_general_settings; |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 95 | GtkWidget *radiobutton_media_settings; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 96 | GtkWidget *radiobutton_account_settings; |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 97 | GtkWidget *account_creation_wizard; |
| 98 | GtkWidget *account_migration_view; |
Nicolas Jager | 15a8b90 | 2017-03-21 07:53:06 -0400 | [diff] [blame] | 99 | GtkWidget *combobox_account_selector; |
Nicolas Jager | 0efc843 | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 100 | GtkWidget *treeview_contact_requests; |
| 101 | GtkWidget *scrolled_window_contact_requests; |
Guillaume Roguez | 0a41120 | 2017-05-25 15:27:26 -0400 | [diff] [blame] | 102 | GtkWidget *image_contact_requests_list; |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 103 | GtkWidget *webkit_chat_container; ///< The webkit_chat_container is created once, then reused for all chat views |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 104 | |
| 105 | GSettings *settings; |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 106 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 107 | details::CppImpl* cpp; ///< Non-UI and C++ only code |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | G_DEFINE_TYPE_WITH_PRIVATE(RingMainWindow, ring_main_window, GTK_TYPE_APPLICATION_WINDOW); |
| 111 | |
| 112 | #define RING_MAIN_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_MAIN_WINDOW_TYPE, RingMainWindowPrivate)) |
| 113 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 114 | //============================================================================== |
| 115 | |
| 116 | inline namespace details |
| 117 | { |
| 118 | |
| 119 | static constexpr const char* CALL_VIEW_NAME = "calls"; |
| 120 | static constexpr const char* ACCOUNT_CREATION_WIZARD_VIEW_NAME = "account-creation-wizard"; |
| 121 | static constexpr const char* ACCOUNT_MIGRATION_VIEW_NAME = "account-migration-view"; |
| 122 | static constexpr const char* GENERAL_SETTINGS_VIEW_NAME = "general"; |
| 123 | static constexpr const char* MEDIA_SETTINGS_VIEW_NAME = "media"; |
| 124 | static constexpr const char* ACCOUNT_SETTINGS_VIEW_NAME = "accounts"; |
| 125 | |
| 126 | class CppImpl |
| 127 | { |
| 128 | public: |
| 129 | explicit CppImpl(RingMainWindow& widget); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 130 | ~CppImpl(); |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 131 | |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 132 | void init(); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 133 | void updateLrc(const std::string& accountId); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 134 | void changeView(GType type, lrc::api::conversation::Info conversation = {}); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 135 | WebKitChatContainer* webkitChatContainer() const; |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 136 | void enterFullScreen(); |
| 137 | void leaveFullScreen(); |
| 138 | void toggleFullScreen(); |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 139 | void resetToWelcome(); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 140 | void setPendingContactRequestTabIcon(); |
| 141 | void showAccountSelectorWidget(bool show = true); |
| 142 | void useAccount(const std::string& accountId); |
| 143 | void onAccountChanged(const std::string& accountId); |
| 144 | void enterAccountCreationWizard(); |
| 145 | void leaveAccountCreationWizard(); |
| 146 | void enterSettingsView(); |
| 147 | void leaveSettingsView(); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 148 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 149 | RingMainWindow* self = nullptr; // The GTK widget itself |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 150 | RingMainWindowPrivate* widgets = nullptr; |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 151 | |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 152 | std::unique_ptr<lrc::api::Lrc> lrc_; |
| 153 | AccountContainer* accountContainer_ = nullptr; |
| 154 | lrc::api::conversation::Info* chatViewConversation_ = nullptr; |
| 155 | lrc::api::profile::Type currentTypeFilter_; |
| 156 | bool show_settings = false; |
| 157 | bool is_fullscreen = false; |
| 158 | |
| 159 | QMetaObject::Connection selected_item_changed; |
| 160 | QMetaObject::Connection selected_call_over; |
| 161 | QMetaObject::Connection showChatViewConnection_; |
| 162 | QMetaObject::Connection showCallViewConnection_; |
| 163 | QMetaObject::Connection showIncomingViewConnection_; |
| 164 | QMetaObject::Connection changeAccountConnection_; |
| 165 | QMetaObject::Connection newAccountConnection_; |
| 166 | QMetaObject::Connection rmAccountConnection_; |
| 167 | QMetaObject::Connection historyClearedConnection_; |
| 168 | QMetaObject::Connection modelSortedConnection_; |
| 169 | QMetaObject::Connection filterChangedConnection_; |
| 170 | QMetaObject::Connection newConversationConnection_; |
| 171 | QMetaObject::Connection conversationRemovedConnection_; |
| 172 | QMetaObject::Connection accountStatusChangedConnection_; |
| 173 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 174 | private: |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 175 | GtkWidget* displayIncomingView(lrc::api::conversation::Info); |
| 176 | GtkWidget* displayCurrentCallView(lrc::api::conversation::Info); |
| 177 | GtkWidget* displayChatView(lrc::api::conversation::Info); |
| 178 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 179 | CppImpl() = delete; |
| 180 | CppImpl(const CppImpl&) = delete; |
| 181 | CppImpl& operator=(const CppImpl&) = delete; |
| 182 | }; |
| 183 | |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 184 | inline namespace gtk_callbacks |
| 185 | { |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 186 | |
Stepan Salenikovich | 7c71bfe | 2015-05-13 18:08:09 -0400 | [diff] [blame] | 187 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 188 | on_save_accounts_timeout(GtkWidget* working_dialog) |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 189 | { |
| 190 | /* save changes to accounts */ |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 191 | AccountModel::instance().save(); |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 192 | |
| 193 | if (working_dialog) |
| 194 | gtk_widget_destroy(working_dialog); |
| 195 | |
| 196 | return G_SOURCE_REMOVE; |
| 197 | } |
| 198 | |
Stepan Salenikovich | 1514218 | 2015-03-11 17:15:26 -0400 | [diff] [blame] | 199 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 200 | on_video_double_clicked(RingMainWindow* self) |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 201 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 202 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 203 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 204 | priv->cpp->toggleFullScreen(); |
| 205 | } |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 206 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 207 | static void |
| 208 | on_hide_view_clicked(RingMainWindow* self) |
| 209 | { |
| 210 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 211 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 212 | priv->cpp->resetToWelcome(); |
| 213 | } |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 214 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 215 | static void |
| 216 | on_account_creation_completed(RingMainWindow* self) |
| 217 | { |
| 218 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 219 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 220 | priv->cpp->leaveAccountCreationWizard(); |
| 221 | } |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 222 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 223 | static void |
| 224 | on_account_changed(RingMainWindow* self) |
| 225 | { |
| 226 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 227 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 228 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 229 | auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector); |
| 230 | auto model = gtk_combo_box_get_model(accountComboBox); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 231 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 232 | GtkTreeIter iter; |
| 233 | if (gtk_combo_box_get_active_iter(accountComboBox, &iter)) { |
| 234 | gchar* accountId; |
| 235 | gtk_tree_model_get(model, &iter, 0 /* col# */, &accountId /* data */, -1); |
| 236 | priv->cpp->onAccountChanged(accountId); |
| 237 | g_free(accountId); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
| 241 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 242 | on_settings_clicked(RingMainWindow* self) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 243 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 244 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 245 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 246 | |
| 247 | if (!priv->cpp->show_settings) |
| 248 | priv->cpp->enterSettingsView(); |
| 249 | else |
| 250 | priv->cpp->leaveSettingsView(); |
| 251 | } |
| 252 | |
| 253 | static void |
| 254 | on_show_media_settings(GtkToggleButton* navbutton, RingMainWindow* self) |
| 255 | { |
| 256 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 257 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 258 | |
| 259 | if (gtk_toggle_button_get_active(navbutton)) { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 260 | 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] | 261 | 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] | 262 | priv->last_settings_view = priv->media_settings_view; |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 263 | } else { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 264 | 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] | 265 | } |
| 266 | } |
| 267 | |
| 268 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 269 | on_show_account_settings(GtkToggleButton* navbutton, RingMainWindow* self) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 270 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 271 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 272 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 273 | |
| 274 | if (gtk_toggle_button_get_active(navbutton)) { |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 275 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), ACCOUNT_SETTINGS_VIEW_NAME); |
| 276 | priv->last_settings_view = priv->account_settings_view; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 280 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 281 | on_show_general_settings(GtkToggleButton* navbutton, RingMainWindow* self) |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 282 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 283 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 284 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 285 | |
| 286 | if (gtk_toggle_button_get_active(navbutton)) { |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 287 | 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] | 288 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME); |
| 289 | priv->last_settings_view = priv->general_settings_view; |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 290 | } else { |
| 291 | 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] | 292 | } |
| 293 | } |
| 294 | |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 295 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 296 | on_search_entry_text_changed(GtkSearchEntry* search_entry, RingMainWindow* self) |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 297 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 298 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 299 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 300 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 301 | // Filter model |
| 302 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry)); |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 303 | priv->cpp->accountContainer_->info.conversationModel->setFilter(text); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 307 | on_search_entry_activated(RingMainWindow* self) |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 308 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 309 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 310 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 311 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 312 | // Select the first conversation of the list |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 313 | auto& conversationModel = priv->cpp->accountContainer_->info.conversationModel; |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 314 | auto conversations = conversationModel->allFilteredConversations(); |
| 315 | if (!conversations.empty()) |
| 316 | conversationModel->selectConversation(conversations[0].uid); |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 319 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 320 | on_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] | 321 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 322 | g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE); |
| 323 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 324 | |
Stepan Salenikovich | cac3504 | 2016-10-28 12:07:38 -0400 | [diff] [blame] | 325 | // if esc key pressed, clear the regex (keep the text, the user might not want to actually delete it) |
| 326 | if (key->keyval == GDK_KEY_Escape) { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 327 | priv->cpp->accountContainer_->info.conversationModel->setFilter(""); |
Stepan Salenikovich | cac3504 | 2016-10-28 12:07:38 -0400 | [diff] [blame] | 328 | return GDK_EVENT_STOP; |
| 329 | } |
| 330 | |
| 331 | return GDK_EVENT_PROPAGATE; |
| 332 | } |
| 333 | |
| 334 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 335 | on_dtmf_pressed(RingMainWindow* self, GdkEventKey* event, gpointer user_data) |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 336 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 337 | (void)user_data; |
| 338 | |
| 339 | g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE); |
| 340 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 341 | |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 342 | g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 343 | g_return_val_if_fail(priv, GDK_EVENT_PROPAGATE); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 344 | |
| 345 | /* we want to react to digit key presses, as long as a GtkEntry is not the |
| 346 | * input focus |
| 347 | */ |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 348 | GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(self)); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 349 | if (GTK_IS_ENTRY(focus)) |
| 350 | return GDK_EVENT_PROPAGATE; |
| 351 | |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 352 | if (priv->cpp->accountContainer_ && |
| 353 | priv->cpp->accountContainer_->info.profileInfo.type != lrc::api::profile::Type::SIP) |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 354 | return GDK_EVENT_PROPAGATE; |
| 355 | |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 356 | /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c' |
| 357 | * does not result in a 'c' being played. |
| 358 | * we filter Ctrl, Alt, and SUPER/HYPER/META keys */ |
| 359 | if ( event->state |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 360 | & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK )) |
| 361 | return GDK_EVENT_PROPAGATE; |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 362 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 363 | // Get current conversation |
| 364 | auto current_view = gtk_bin_get_child(GTK_BIN(priv->frame_call)); |
| 365 | lrc::api::conversation::Info current_item; |
| 366 | if (IS_CURRENT_CALL_VIEW(current_view)) |
| 367 | current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(current_view)); |
| 368 | else |
| 369 | return GDK_EVENT_PROPAGATE; |
| 370 | |
| 371 | if (current_item.callId.empty()) |
| 372 | return GDK_EVENT_PROPAGATE; |
| 373 | |
| 374 | // pass the character that was entered to be played by the daemon; |
| 375 | // the daemon will filter out invalid DTMF characters |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 376 | guint32 unicode_val = gdk_keyval_to_unicode(event->keyval); |
| 377 | QString val = QString::fromUcs4(&unicode_val, 1); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 378 | g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData()); |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 379 | priv->cpp->accountContainer_->info.callModel->playDTMF(current_item.callId, val.toStdString()); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 380 | // always propogate the key, so we don't steal accelerators/shortcuts |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 381 | return GDK_EVENT_PROPAGATE; |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 382 | } |
| 383 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 384 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 385 | on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainWindow* self) |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 386 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 387 | (void)notebook; |
| 388 | (void)page; |
| 389 | |
| 390 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 391 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 392 | |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 393 | auto newType = page_num == 0 ? priv->cpp->accountContainer_->info.profileInfo.type : lrc::api::profile::Type::PENDING; |
| 394 | if (priv->cpp->currentTypeFilter_ != newType) { |
| 395 | priv->cpp->currentTypeFilter_ = newType; |
| 396 | priv->cpp->accountContainer_->info.conversationModel->setFilter(priv->cpp->currentTypeFilter_); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 397 | } |
Nicolas Jager | 0efc843 | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 398 | } |
| 399 | |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 400 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 401 | on_window_size_changed(GtkWidget* self, GdkEventConfigure* event, gpointer user_data) |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 402 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 403 | (void)user_data; |
| 404 | |
| 405 | g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE); |
| 406 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 407 | |
| 408 | g_settings_set_int(priv->settings, "window-width", event->width); |
| 409 | g_settings_set_int(priv->settings, "window-height", event->height); |
| 410 | |
| 411 | return GDK_EVENT_PROPAGATE; |
| 412 | } |
| 413 | |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 414 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 415 | on_search_entry_places_call_changed(GSettings* settings, const gchar* key, RingMainWindow* self) |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 416 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 417 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 418 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 419 | |
| 420 | if (g_settings_get_boolean(settings, key)) { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 421 | gtk_widget_set_tooltip_text(priv->button_new_conversation, |
| 422 | C_("button next to search entry will place a new call", |
| 423 | "place call")); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 424 | } else { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 425 | gtk_widget_set_tooltip_text(priv->button_new_conversation, |
| 426 | C_("button next to search entry will open chat", "open chat")); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 431 | on_handle_account_migrations(RingMainWindow* self) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 432 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 433 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 434 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 435 | |
| 436 | /* If there is an existing migration view, remove it */ |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 437 | if (priv->account_migration_view) { |
Stepan Salenikovich | 56530b1 | 2016-10-20 17:51:34 -0400 | [diff] [blame] | 438 | gtk_widget_destroy(priv->account_migration_view); |
| 439 | priv->account_migration_view = nullptr; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 440 | } |
| 441 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 442 | auto accounts = AccountModel::instance().accountsToMigrate(); |
| 443 | if (!accounts.isEmpty()) { |
| 444 | auto* account = accounts.first(); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 445 | |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 446 | priv->account_migration_view = account_migration_view_new(account); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 447 | g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed", |
| 448 | G_CALLBACK(on_handle_account_migrations), self); |
| 449 | g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed", |
| 450 | G_CALLBACK(on_handle_account_migrations), self); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 451 | |
| 452 | gtk_widget_hide(priv->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 453 | priv->cpp->showAccountSelectorWidget(false); |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 454 | gtk_widget_show(priv->account_migration_view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 455 | gtk_stack_add_named( |
| 456 | GTK_STACK(priv->stack_main_view), |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 457 | priv->account_migration_view, |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 458 | ACCOUNT_MIGRATION_VIEW_NAME |
| 459 | ); |
| 460 | gtk_stack_set_visible_child_name( |
| 461 | GTK_STACK(priv->stack_main_view), |
| 462 | ACCOUNT_MIGRATION_VIEW_NAME |
| 463 | ); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 464 | } else { |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 465 | gtk_widget_show(priv->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 466 | priv->cpp->showAccountSelectorWidget(); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 470 | } // namespace gtk_callbacks |
| 471 | |
Nicolas Jager | 5e2be73 | 2017-03-18 21:35:50 -0400 | [diff] [blame] | 472 | /** |
| 473 | * set the column value by printing the alias and the state of an account in combobox_account_selector. |
| 474 | */ |
| 475 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 476 | print_account_and_state(GtkCellLayout* cell_layout, |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 477 | GtkCellRenderer* cell, |
| 478 | GtkTreeModel* model, |
Nicolas Jager | 5e2be73 | 2017-03-18 21:35:50 -0400 | [diff] [blame] | 479 | GtkTreeIter* iter, |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 480 | gpointer* data) |
Nicolas Jager | 5e2be73 | 2017-03-18 21:35:50 -0400 | [diff] [blame] | 481 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 482 | (void)cell_layout; |
| 483 | (void)data; |
| 484 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 485 | gchar *alias; |
| 486 | gchar *text; |
Nicolas Jager | 5e2be73 | 2017-03-18 21:35:50 -0400 | [diff] [blame] | 487 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 488 | gtk_tree_model_get (model, iter, |
| 489 | 1 /* col# */, &alias /* data */, |
| 490 | -1); |
Nicolas Jager | 5e2be73 | 2017-03-18 21:35:50 -0400 | [diff] [blame] | 491 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 492 | text = g_markup_printf_escaped( |
| 493 | "<span fgcolor=\"gray\">%s</span>", |
| 494 | alias |
| 495 | ); |
Nicolas Jager | 5e2be73 | 2017-03-18 21:35:50 -0400 | [diff] [blame] | 496 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 497 | g_object_set(G_OBJECT(cell), "markup", text, NULL); |
| 498 | g_free(alias); |
Nicolas Jager | 5e2be73 | 2017-03-18 21:35:50 -0400 | [diff] [blame] | 499 | } |
| 500 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 501 | CppImpl::CppImpl(RingMainWindow& widget) |
| 502 | : self {&widget} |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 503 | , widgets {RING_MAIN_WINDOW_GET_PRIVATE(&widget)} |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 504 | , lrc_ {std::make_unique<lrc::api::Lrc>()} |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 505 | {} |
| 506 | |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 507 | void |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 508 | CppImpl::init() |
| 509 | { |
| 510 | // NOTE: When new models will be fully implemented, we need to move this |
| 511 | // in rign_client.cpp-> |
| 512 | // Init LRC and the vew |
| 513 | const auto accountIds = lrc_->getAccountModel().getAccountList(); |
| 514 | auto isInitialized = false; |
| 515 | if (not accountIds.empty()) { |
| 516 | for (const auto& accountId : accountIds) { |
| 517 | const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId); |
| 518 | if (accountInfo.enabled) { |
| 519 | updateLrc(accountId); |
| 520 | isInitialized = true; |
| 521 | break; |
| 522 | } |
| 523 | } |
| 524 | if (!isInitialized) { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 525 | widgets->treeview_conversations = conversations_view_new(accountContainer_); |
| 526 | gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations); |
| 527 | widgets->treeview_contact_requests = conversations_view_new(accountContainer_); |
| 528 | gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
| 532 | // Account status changed |
| 533 | auto slotAccountStatusChanged = [this] (const std::string& accountId) { |
| 534 | if (not accountContainer_ ) { |
| 535 | updateLrc(accountId); |
| 536 | |
| 537 | if (accountContainer_) |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 538 | ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 539 | accountContainer_); |
| 540 | } else { |
| 541 | auto accounts = lrc_->getAccountModel().getAccountList(); |
| 542 | auto store = gtk_list_store_new (2 /* # of cols */ , |
| 543 | G_TYPE_STRING, |
| 544 | G_TYPE_STRING, |
| 545 | G_TYPE_UINT); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 546 | auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector)); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 547 | GtkTreeIter iter; |
| 548 | auto enabledAccounts = 0; |
| 549 | for (const auto& account : accounts) { |
| 550 | const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(account); |
| 551 | showAccountSelectorWidget(); |
| 552 | if (accountId == account && !accountInfo.enabled) currentIdx = 0; |
| 553 | if (accountInfo.enabled) { |
| 554 | ++enabledAccounts; |
| 555 | gtk_list_store_append (store, &iter); |
| 556 | gtk_list_store_set (store, &iter, |
| 557 | 0 /* col # */ , account.c_str() /* celldata */, |
| 558 | 1 /* col # */ , accountInfo.profileInfo.alias.c_str() /* celldata */, |
| 559 | -1 /* end */); |
| 560 | } |
| 561 | } |
| 562 | // Redraw combobox |
| 563 | gtk_combo_box_set_model( |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 564 | GTK_COMBO_BOX(widgets->combobox_account_selector), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 565 | GTK_TREE_MODEL (store) |
| 566 | ); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 567 | gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 568 | // if no account. reset the view. |
| 569 | if (enabledAccounts == 0) { |
| 570 | updateLrc(""); |
| 571 | changeView(RING_WELCOME_VIEW_TYPE); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 572 | ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), nullptr); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | }; |
| 576 | |
| 577 | accountStatusChangedConnection_ = QObject::connect(&lrc_->getAccountModel(), |
| 578 | &lrc::api::NewAccountModel::accountStatusChanged, |
| 579 | slotAccountStatusChanged); |
| 580 | |
| 581 | // This signal must be connected if no account |
| 582 | auto slotAccountAdded = [this] (const std::string& idAdded) { |
| 583 | Q_UNUSED(idAdded) |
| 584 | // New account added. go to this account |
| 585 | auto accounts = lrc_->getAccountModel().getAccountList(); |
| 586 | auto store = gtk_list_store_new (2 /* # of cols */ , |
| 587 | G_TYPE_STRING, |
| 588 | G_TYPE_STRING, |
| 589 | G_TYPE_UINT); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 590 | auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector)); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 591 | GtkTreeIter iter; |
| 592 | for (const auto& accountId : accounts) { |
| 593 | const auto& account = lrc_->getAccountModel().getAccountInfo(accountId); |
| 594 | if (account.enabled) { |
| 595 | gtk_list_store_append (store, &iter); |
| 596 | gtk_list_store_set (store, &iter, |
| 597 | 0 /* col # */ , accountId.c_str() /* celldata */, |
| 598 | 1 /* col # */ , account.profileInfo.alias.c_str() /* celldata */, |
| 599 | -1 /* end */); |
| 600 | } |
| 601 | } |
| 602 | // Redraw combobox |
| 603 | gtk_combo_box_set_model( |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 604 | GTK_COMBO_BOX(widgets->combobox_account_selector), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 605 | GTK_TREE_MODEL (store) |
| 606 | ); |
| 607 | // If no account selected, select the new account |
| 608 | if (currentIdx == -1) currentIdx = 0; |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 609 | gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 610 | showAccountSelectorWidget(); |
| 611 | }; |
| 612 | |
| 613 | newAccountConnection_ = QObject::connect(&lrc_->getAccountModel(), |
| 614 | &lrc::api::NewAccountModel::accountAdded, |
| 615 | slotAccountAdded); |
| 616 | |
| 617 | auto slotAccountRemoved = [this] (G_GNUC_UNUSED const std::string& idRemoved) { |
| 618 | // Account removed, change account if it's the current account selected. |
| 619 | auto accounts = lrc_->getAccountModel().getAccountList(); |
| 620 | if (accounts.empty()) { |
| 621 | enterAccountCreationWizard(); |
| 622 | } else { |
| 623 | auto store = gtk_list_store_new (2 /* # of cols */ , |
| 624 | G_TYPE_STRING, |
| 625 | G_TYPE_STRING, |
| 626 | G_TYPE_UINT); |
| 627 | GtkTreeIter iter; |
| 628 | for (const auto& accountId : accounts) { |
| 629 | const auto& account = lrc_->getAccountModel().getAccountInfo(accountId); |
| 630 | if (account.enabled) { |
| 631 | gtk_list_store_append (store, &iter); |
| 632 | gtk_list_store_set (store, &iter, |
| 633 | 0 /* col # */ , accountId.c_str() /* celldata */, |
| 634 | 1 /* col # */ , account.profileInfo.alias.c_str() /* celldata */, |
| 635 | -1 /* end */); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | gtk_combo_box_set_model( |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 640 | GTK_COMBO_BOX(widgets->combobox_account_selector), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 641 | GTK_TREE_MODEL (store) |
| 642 | ); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 643 | gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 644 | showAccountSelectorWidget(); |
| 645 | // Show conversation panel |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 646 | gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 647 | // Reinit LRC |
| 648 | updateLrc(std::string(accounts.at(0))); |
| 649 | // Update the welcome view |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 650 | ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 651 | } |
| 652 | }; |
| 653 | |
| 654 | rmAccountConnection_ = QObject::connect(&lrc_->getAccountModel(), |
| 655 | &lrc::api::NewAccountModel::accountRemoved, |
| 656 | slotAccountRemoved); |
| 657 | |
| 658 | /* bind to window size settings */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 659 | widgets->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr); |
| 660 | auto width = g_settings_get_int(widgets->settings, "window-width"); |
| 661 | auto height = g_settings_get_int(widgets->settings, "window-height"); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 662 | gtk_window_set_default_size(GTK_WINDOW(self), width, height); |
| 663 | g_signal_connect(self, "configure-event", G_CALLBACK(on_window_size_changed), nullptr); |
| 664 | |
| 665 | /* search-entry-places-call setting */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 666 | on_search_entry_places_call_changed(widgets->settings, "search-entry-places-call", self); |
| 667 | g_signal_connect(widgets->settings, "changed::search-entry-places-call", G_CALLBACK(on_search_entry_places_call_changed), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 668 | |
| 669 | /* set window icon */ |
| 670 | GError *error = NULL; |
| 671 | GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error); |
| 672 | if (icon == NULL) { |
| 673 | g_debug("Could not load icon: %s", error->message); |
| 674 | g_clear_error(&error); |
| 675 | } else |
| 676 | gtk_window_set_icon(GTK_WINDOW(self), icon); |
| 677 | |
| 678 | /* set menu icon */ |
| 679 | GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue", |
| 680 | -1, 16, TRUE, &error); |
| 681 | if (image_ring == NULL) { |
| 682 | g_debug("Could not load icon: %s", error->message); |
| 683 | g_clear_error(&error); |
| 684 | } else |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 685 | gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_ring), image_ring); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 686 | |
| 687 | /* ring menu */ |
| 688 | GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui"); |
| 689 | GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu")); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 690 | gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(widgets->ring_menu), menu); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 691 | g_object_unref(builder); |
| 692 | |
| 693 | /* settings icon */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 694 | gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 695 | |
| 696 | /* connect settings button signal */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 697 | g_signal_connect_swapped(widgets->ring_settings, "clicked", G_CALLBACK(on_settings_clicked), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 698 | |
| 699 | /* add the call view to the main stack */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 700 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), |
| 701 | widgets->vbox_call_view, |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 702 | CALL_VIEW_NAME); |
| 703 | |
| 704 | /* init the settings views */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 705 | widgets->account_settings_view = account_view_new(); |
| 706 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->account_settings_view, ACCOUNT_SETTINGS_VIEW_NAME); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 707 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 708 | widgets->media_settings_view = media_settings_view_new(); |
| 709 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->media_settings_view, MEDIA_SETTINGS_VIEW_NAME); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 710 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 711 | widgets->general_settings_view = general_settings_view_new(); |
| 712 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view, GENERAL_SETTINGS_VIEW_NAME); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 713 | |
| 714 | /* make the setting we will show first the active one */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 715 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE); |
| 716 | widgets->last_settings_view = widgets->general_settings_view; |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 717 | |
| 718 | /* connect the settings button signals to switch settings views */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 719 | g_signal_connect(widgets->radiobutton_media_settings, "toggled", G_CALLBACK(on_show_media_settings), self); |
| 720 | g_signal_connect(widgets->radiobutton_account_settings, "toggled", G_CALLBACK(on_show_account_settings), self); |
| 721 | g_signal_connect(widgets->radiobutton_general_settings, "toggled", G_CALLBACK(on_show_general_settings), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 722 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 723 | g_signal_connect(widgets->notebook_contacts, "switch-page", G_CALLBACK(on_tab_changed), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 724 | |
| 725 | /* welcome/default view */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 726 | widgets->welcome_view = ring_welcome_view_new(accountContainer_); |
| 727 | g_object_ref(widgets->welcome_view); // increase ref because don't want it to be destroyed when not displayed |
| 728 | gtk_container_add(GTK_CONTAINER(widgets->frame_call), widgets->welcome_view); |
| 729 | gtk_widget_show(widgets->welcome_view); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 730 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 731 | g_signal_connect_swapped(widgets->search_entry, "activate", G_CALLBACK(on_search_entry_activated), self); |
| 732 | g_signal_connect_swapped(widgets->button_new_conversation, "clicked", G_CALLBACK(on_search_entry_activated), self); |
| 733 | g_signal_connect(widgets->search_entry, "search-changed", G_CALLBACK(on_search_entry_text_changed), self); |
| 734 | g_signal_connect(widgets->search_entry, "key-release-event", G_CALLBACK(on_search_entry_key_released), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 735 | |
| 736 | auto provider = gtk_css_provider_new(); |
| 737 | gtk_css_provider_load_from_data(provider, |
| 738 | ".search-entry-style { border: 0; border-radius: 0; } \ |
| 739 | .spinner-style { border: 0; background: white; } \ |
| 740 | .new-conversation-style { border: 0; background: white; transition: all 0.3s ease; border-radius: 0; } \ |
| 741 | .new-conversation-style:hover { background: #bae5f0; }", |
| 742 | -1, nullptr |
| 743 | ); |
| 744 | gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()), |
| 745 | GTK_STYLE_PROVIDER(provider), |
| 746 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
| 747 | |
| 748 | |
| 749 | /* react to digit key press events */ |
| 750 | g_signal_connect(self, "key-press-event", G_CALLBACK(on_dtmf_pressed), nullptr); |
| 751 | |
| 752 | /* set the search entry placeholder text */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 753 | gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->search_entry), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 754 | C_("Please try to make the translation 50 chars or less so that it fits into the layout", "Search contacts or enter number")); |
| 755 | |
| 756 | /* init chat webkit container so that it starts loading before the first time we need it*/ |
| 757 | (void)webkitChatContainer(); |
| 758 | |
| 759 | if (has_ring_account()) { |
| 760 | /* user has ring account, so show the call view right away */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 761 | gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 762 | |
| 763 | on_handle_account_migrations(self); |
| 764 | } else { |
| 765 | /* user has to create the ring account */ |
| 766 | enterAccountCreationWizard(); |
| 767 | } |
| 768 | |
| 769 | // setup account selector and select the first account |
| 770 | auto store = gtk_list_store_new (2 /* # of cols */ , |
| 771 | G_TYPE_STRING, |
| 772 | G_TYPE_STRING, |
| 773 | G_TYPE_UINT); |
| 774 | GtkTreeIter iter; |
| 775 | for (const auto& accountId : accountIds) { |
| 776 | const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId); |
| 777 | if (accountInfo.enabled) { |
| 778 | gtk_list_store_append (store, &iter); |
| 779 | gtk_list_store_set (store, &iter, |
| 780 | 0 /* col # */ , accountId.c_str() /* celldata */, |
| 781 | 1 /* col # */ , accountInfo.profileInfo.alias.c_str() /* celldata */, |
| 782 | -1 /* end */); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | gtk_combo_box_set_model( |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 787 | GTK_COMBO_BOX(widgets->combobox_account_selector), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 788 | GTK_TREE_MODEL (store) |
| 789 | ); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 790 | gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 791 | |
| 792 | /* set visibility */ |
| 793 | showAccountSelectorWidget(); |
| 794 | |
| 795 | /* layout */ |
| 796 | auto *renderer = gtk_cell_renderer_text_new(); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 797 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, FALSE); |
| 798 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, "text", 0, NULL); |
| 799 | gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(widgets->combobox_account_selector), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 800 | renderer, |
| 801 | (GtkCellLayoutDataFunc)print_account_and_state, |
| 802 | nullptr, nullptr); |
| 803 | |
| 804 | // we closing any view opened to avoid confusion (especially between SIP and Ring protocols). |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 805 | g_signal_connect_swapped(widgets->combobox_account_selector, "changed", G_CALLBACK(on_account_changed), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 806 | |
| 807 | // initialize the pending contact request icon. |
| 808 | setPendingContactRequestTabIcon(); |
| 809 | |
| 810 | if (isInitialized) { |
| 811 | auto& conversationModel = accountContainer_->info.conversationModel; |
| 812 | auto conversations = conversationModel->allFilteredConversations(); |
| 813 | for (const auto& conversation: conversations) { |
| 814 | if (!conversation.callId.empty()) { |
| 815 | accountContainer_->info.conversationModel->selectConversation(conversation.uid); |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | CppImpl::~CppImpl() |
| 822 | { |
| 823 | delete accountContainer_; |
| 824 | delete chatViewConversation_; |
| 825 | |
| 826 | QObject::disconnect(selected_item_changed); |
| 827 | QObject::disconnect(selected_call_over); |
| 828 | QObject::disconnect(showChatViewConnection_); |
| 829 | QObject::disconnect(showIncomingViewConnection_); |
| 830 | QObject::disconnect(historyClearedConnection_); |
| 831 | QObject::disconnect(modelSortedConnection_); |
| 832 | QObject::disconnect(filterChangedConnection_); |
| 833 | QObject::disconnect(newConversationConnection_); |
| 834 | QObject::disconnect(conversationRemovedConnection_); |
| 835 | QObject::disconnect(changeAccountConnection_); |
| 836 | QObject::disconnect(newAccountConnection_); |
| 837 | QObject::disconnect(rmAccountConnection_); |
| 838 | QObject::disconnect(showCallViewConnection_); |
| 839 | QObject::disconnect(modelSortedConnection_); |
| 840 | QObject::disconnect(accountStatusChangedConnection_); |
| 841 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 842 | g_clear_object(&widgets->welcome_view); |
| 843 | g_clear_object(&widgets->webkit_chat_container); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | void |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 847 | CppImpl::changeView(GType type, lrc::api::conversation::Info conversation) |
| 848 | { |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 849 | leaveFullScreen(); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 850 | gtk_container_remove(GTK_CONTAINER(widgets->frame_call), |
| 851 | gtk_bin_get_child(GTK_BIN(widgets->frame_call))); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 852 | |
| 853 | QObject::disconnect(selected_item_changed); |
| 854 | QObject::disconnect(selected_call_over); |
| 855 | |
| 856 | GtkWidget* new_view; |
| 857 | if (g_type_is_a(INCOMING_CALL_VIEW_TYPE, type)) { |
| 858 | new_view = displayIncomingView(conversation); |
| 859 | } else if (g_type_is_a(CURRENT_CALL_VIEW_TYPE, type)) { |
| 860 | new_view = displayCurrentCallView(conversation); |
| 861 | } else if (g_type_is_a(CHAT_VIEW_TYPE, type)) { |
| 862 | new_view = displayChatView(conversation); |
| 863 | } else { |
| 864 | // TODO select first conversation? |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 865 | new_view = widgets->welcome_view; |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 866 | } |
| 867 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 868 | gtk_container_add(GTK_CONTAINER(widgets->frame_call), new_view); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 869 | gtk_widget_show(new_view); |
| 870 | } |
| 871 | |
| 872 | GtkWidget* |
| 873 | CppImpl::displayIncomingView(lrc::api::conversation::Info conversation) |
| 874 | { |
| 875 | delete chatViewConversation_; |
| 876 | chatViewConversation_ = new lrc::api::conversation::Info(conversation); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 877 | return incoming_call_view_new(webkitChatContainer(), accountContainer_, chatViewConversation_); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | GtkWidget* |
| 881 | CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation) |
| 882 | { |
| 883 | delete chatViewConversation_; |
| 884 | chatViewConversation_ = new lrc::api::conversation::Info(conversation); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 885 | auto* new_view = current_call_view_new(webkitChatContainer(), |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 886 | accountContainer_, chatViewConversation_); |
| 887 | |
| 888 | try { |
| 889 | auto contactUri = chatViewConversation_->participants.front(); |
| 890 | auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri); |
| 891 | if (auto chat_view = current_call_view_get_chat_view(CURRENT_CALL_VIEW(new_view))) { |
| 892 | chat_view_update_temporary(CHAT_VIEW(chat_view), |
| 893 | contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING |
| 894 | || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY); |
| 895 | } |
| 896 | } catch(...) { } |
| 897 | |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 898 | g_signal_connect_swapped(new_view, "video-double-clicked", |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 899 | G_CALLBACK(on_video_double_clicked), self); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 900 | return new_view; |
| 901 | } |
| 902 | |
| 903 | GtkWidget* |
| 904 | CppImpl::displayChatView(lrc::api::conversation::Info conversation) |
| 905 | { |
| 906 | delete chatViewConversation_; |
| 907 | chatViewConversation_ = new lrc::api::conversation::Info(conversation); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 908 | auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_, chatViewConversation_); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 909 | g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 910 | return new_view; |
| 911 | } |
| 912 | |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 913 | WebKitChatContainer* |
| 914 | CppImpl::webkitChatContainer() const |
| 915 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 916 | if (!widgets->webkit_chat_container) { |
| 917 | widgets->webkit_chat_container = webkit_chat_container_new(); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 918 | |
| 919 | // We don't want it to be deleted, ever. |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 920 | g_object_ref(widgets->webkit_chat_container); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 921 | } |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 922 | return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 923 | } |
| 924 | |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 925 | void |
| 926 | CppImpl::enterFullScreen() |
| 927 | { |
| 928 | if (!is_fullscreen) { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 929 | gtk_widget_hide(widgets->vbox_left_pane); |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 930 | gtk_window_fullscreen(GTK_WINDOW(self)); |
| 931 | is_fullscreen = true; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | void |
| 936 | CppImpl::leaveFullScreen() |
| 937 | { |
| 938 | if (is_fullscreen) { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 939 | gtk_widget_show(widgets->vbox_left_pane); |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 940 | gtk_window_unfullscreen(GTK_WINDOW(self)); |
| 941 | is_fullscreen = false; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | void |
| 946 | CppImpl::toggleFullScreen() |
| 947 | { |
| 948 | if (is_fullscreen) |
| 949 | leaveFullScreen(); |
| 950 | else |
| 951 | enterFullScreen(); |
| 952 | } |
| 953 | |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 954 | /// Clear selection and go to welcome page. |
| 955 | void |
| 956 | CppImpl::resetToWelcome() |
| 957 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 958 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations)); |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 959 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 960 | auto selection_contact_request = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests)); |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 961 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 962 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 963 | lrc::api::conversation::Info current_item; |
| 964 | if (IS_CHAT_VIEW(old_view)) |
| 965 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 966 | changeView(RING_WELCOME_VIEW_TYPE, current_item); |
| 967 | } |
| 968 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 969 | void |
| 970 | CppImpl::setPendingContactRequestTabIcon() |
| 971 | { |
| 972 | if (not accountContainer_) |
| 973 | return; |
| 974 | |
| 975 | auto isRingAccount = accountContainer_->info.profileInfo.type == lrc::api::profile::Type::RING; |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 976 | gtk_widget_set_visible(widgets->scrolled_window_contact_requests, isRingAccount); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 977 | |
| 978 | if (not isRingAccount) |
| 979 | return; |
| 980 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 981 | gtk_image_set_from_resource(GTK_IMAGE(widgets->image_contact_requests_list), |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 982 | (accountContainer_->info.contactModel->hasPendingRequests()) |
| 983 | ? "/cx/ring/RingGnome/contact_requests_list_with_notification" |
| 984 | : "/cx/ring/RingGnome/contact_requests_list"); |
| 985 | } |
| 986 | |
| 987 | void |
| 988 | CppImpl::showAccountSelectorWidget(bool show) |
| 989 | { |
| 990 | // we only want to show the account selector when there is more than 1 enabled |
| 991 | // account; so every time we want to show it, we should preform this check |
| 992 | auto activatedAccount = 0; |
| 993 | auto accounts = lrc_->getAccountModel().getAccountList(); |
| 994 | for (const auto& account : accounts) { |
| 995 | const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(account); |
| 996 | if (accountInfo.enabled) |
| 997 | ++activatedAccount; |
| 998 | } |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 999 | gtk_widget_set_visible(widgets->combobox_account_selector, show && activatedAccount > 1); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | void |
| 1003 | CppImpl::enterAccountCreationWizard() |
| 1004 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1005 | if (!widgets->account_creation_wizard) { |
| 1006 | widgets->account_creation_wizard = account_creation_wizard_new(false); |
| 1007 | g_object_add_weak_pointer(G_OBJECT(widgets->account_creation_wizard), |
| 1008 | reinterpret_cast<gpointer*>(&widgets->account_creation_wizard)); |
| 1009 | g_signal_connect_swapped(widgets->account_creation_wizard, "account-creation-completed", |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1010 | G_CALLBACK(on_account_creation_completed), self); |
| 1011 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1012 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), |
| 1013 | widgets->account_creation_wizard, |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1014 | ACCOUNT_CREATION_WIZARD_VIEW_NAME); |
| 1015 | } |
| 1016 | |
| 1017 | /* hide settings button until account creation is complete */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1018 | gtk_widget_hide(widgets->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1019 | showAccountSelectorWidget(false); |
| 1020 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1021 | gtk_widget_show(widgets->account_creation_wizard); |
| 1022 | gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->account_creation_wizard); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | void |
| 1026 | CppImpl::leaveAccountCreationWizard() |
| 1027 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1028 | gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1029 | |
| 1030 | /* destroy the wizard */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1031 | if (widgets->account_creation_wizard) { |
| 1032 | gtk_container_remove(GTK_CONTAINER(widgets->stack_main_view), widgets->account_creation_wizard); |
| 1033 | gtk_widget_destroy(widgets->account_creation_wizard); |
| 1034 | widgets->account_creation_wizard = nullptr; |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | /* show the settings button */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1038 | gtk_widget_show(widgets->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1039 | |
| 1040 | /* show the account selector */ |
| 1041 | showAccountSelectorWidget(); |
| 1042 | } |
| 1043 | |
| 1044 | void |
| 1045 | CppImpl::useAccount(const std::string& accountId) |
| 1046 | { |
| 1047 | // Go to welcome view |
| 1048 | changeView(RING_WELCOME_VIEW_TYPE); |
| 1049 | |
| 1050 | // Change account selection widget |
| 1051 | auto accounts = lrc_->getAccountModel().getAccountList(); |
| 1052 | auto it = std::find(accounts.begin(), accounts.end(), accountId ); |
| 1053 | if (it == accounts.end()) { |
| 1054 | qDebug() << "useAccount, cannot find account " << accountId.c_str(); |
| 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | int row = it - accounts.begin(); |
| 1059 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1060 | gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), row); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1061 | // Show conversation panel |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1062 | gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1063 | // Reinit LRC |
| 1064 | updateLrc(std::string(accountId)); |
| 1065 | // Update the welcome view |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1066 | ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | void |
| 1070 | CppImpl::onAccountChanged(const std::string& accountId) |
| 1071 | { |
| 1072 | // Reinit view |
| 1073 | changeView(RING_WELCOME_VIEW_TYPE); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1074 | gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1075 | |
| 1076 | // Change account |
| 1077 | updateLrc(accountId); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1078 | ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | void |
| 1082 | CppImpl::enterSettingsView() |
| 1083 | { |
| 1084 | /* show the settings */ |
| 1085 | show_settings = true; |
| 1086 | |
| 1087 | /* show settings */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1088 | gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-ok-symbolic", |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1089 | GTK_ICON_SIZE_SMALL_TOOLBAR); |
| 1090 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1091 | gtk_widget_show(widgets->hbox_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1092 | |
| 1093 | /* make sure to start preview if we're showing the video settings */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1094 | if (widgets->last_settings_view == widgets->media_settings_view) |
| 1095 | media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), TRUE); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1096 | |
| 1097 | /* make sure to show the profile if we're showing the general settings */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1098 | if (widgets->last_settings_view == widgets->general_settings_view) |
| 1099 | general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view), |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1100 | TRUE); |
| 1101 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1102 | gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->last_settings_view); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | void |
| 1106 | CppImpl::leaveSettingsView() |
| 1107 | { |
| 1108 | /* hide the settings */ |
| 1109 | show_settings = false; |
| 1110 | |
| 1111 | /* show working dialog in case save operation takes time */ |
| 1112 | auto working = ring_dialog_working(GTK_WIDGET(self), nullptr); |
| 1113 | gtk_window_present(GTK_WINDOW(working)); |
| 1114 | |
| 1115 | /* now save after the time it takes to transition back to the call view (400ms) |
| 1116 | * the save doesn't happen before the "working" dialog is presented |
| 1117 | * the timeout function should destroy the "working" dialog when done saving |
| 1118 | */ |
| 1119 | g_timeout_add_full(G_PRIORITY_DEFAULT, 400, GSourceFunc(on_save_accounts_timeout), working, |
| 1120 | nullptr); |
| 1121 | |
| 1122 | /* show calls */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1123 | gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic", |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1124 | GTK_ICON_SIZE_SMALL_TOOLBAR); |
| 1125 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1126 | gtk_widget_hide(widgets->hbox_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1127 | |
| 1128 | /* make sure video preview is stopped, in case it was started */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1129 | media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), FALSE); |
| 1130 | general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view), |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1131 | FALSE); |
| 1132 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1133 | gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1134 | |
| 1135 | /* show the view which was selected previously */ |
| 1136 | } |
| 1137 | |
| 1138 | void |
| 1139 | CppImpl::updateLrc(const std::string& accountId) |
| 1140 | { |
| 1141 | // Disconnect old signals. |
| 1142 | QObject::disconnect(showChatViewConnection_); |
| 1143 | QObject::disconnect(showIncomingViewConnection_); |
| 1144 | QObject::disconnect(changeAccountConnection_); |
| 1145 | QObject::disconnect(showCallViewConnection_); |
| 1146 | QObject::disconnect(modelSortedConnection_); |
| 1147 | QObject::disconnect(historyClearedConnection_); |
| 1148 | QObject::disconnect(filterChangedConnection_); |
| 1149 | QObject::disconnect(newConversationConnection_); |
| 1150 | QObject::disconnect(conversationRemovedConnection_); |
| 1151 | |
| 1152 | // Get the account selected |
| 1153 | if (accountContainer_) delete accountContainer_; |
| 1154 | if (!accountId.empty()) |
| 1155 | accountContainer_ = new AccountContainer(lrc_->getAccountModel().getAccountInfo(accountId)); |
| 1156 | else |
| 1157 | accountContainer_ = nullptr; |
| 1158 | |
| 1159 | // Reinit tree views |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1160 | if (widgets->treeview_conversations) { |
| 1161 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1162 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1163 | gtk_widget_destroy(widgets->treeview_conversations); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1164 | } |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1165 | widgets->treeview_conversations = conversations_view_new(accountContainer_); |
| 1166 | gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1167 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1168 | if (widgets->treeview_contact_requests) { |
| 1169 | auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1170 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1171 | gtk_widget_destroy(widgets->treeview_contact_requests); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1172 | } |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1173 | widgets->treeview_contact_requests = conversations_view_new(accountContainer_); |
| 1174 | gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1175 | |
| 1176 | if (!accountContainer_) return; |
| 1177 | |
| 1178 | // define slots (we are using this way because gtk is not a c++ lib) |
| 1179 | auto slotConversationCleared = [this] (const std::string& uid) { |
| 1180 | // Change the view when the history is cleared. |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1181 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1182 | lrc::api::conversation::Info current_item; |
| 1183 | current_item.uid = "-1"; // Because the Searching item has an empty uid |
| 1184 | if (IS_CHAT_VIEW(old_view)) |
| 1185 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 1186 | else |
| 1187 | // if incoming or call view we don't want to change the view |
| 1188 | return; |
| 1189 | if (current_item.uid == uid) { |
| 1190 | // We are on the conversation cleared. |
| 1191 | // Go to welcome view because user doesn't want this conversation |
| 1192 | // TODO go to first conversation? |
| 1193 | resetToWelcome(); |
| 1194 | } |
| 1195 | }; |
| 1196 | |
| 1197 | auto slotModelSorted = [this] () { |
| 1198 | // Synchronize selection when sorted and update pending icon |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1199 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1200 | lrc::api::conversation::Info current_item; |
| 1201 | current_item.uid = "-1"; |
| 1202 | if (IS_CHAT_VIEW(old_view)) |
| 1203 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 1204 | else if (IS_CURRENT_CALL_VIEW(old_view)) |
| 1205 | current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view)); |
| 1206 | else if (IS_INCOMING_CALL_VIEW(old_view)) |
| 1207 | current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1208 | conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1209 | setPendingContactRequestTabIcon(); |
| 1210 | }; |
| 1211 | |
| 1212 | auto slotFilterChanged = [this] () { |
| 1213 | // Synchronize selection when filter changes |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1214 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1215 | lrc::api::conversation::Info current_item; |
| 1216 | current_item.uid = "-1"; |
| 1217 | if (IS_CHAT_VIEW(old_view)) |
| 1218 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 1219 | else if (IS_CURRENT_CALL_VIEW(old_view)) |
| 1220 | current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view)); |
| 1221 | else if (IS_INCOMING_CALL_VIEW(old_view)) |
| 1222 | current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1223 | conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1224 | // Get if conversation still exists. |
| 1225 | auto& conversationModel = accountContainer_->info.conversationModel; |
| 1226 | auto conversations = conversationModel->allFilteredConversations(); |
| 1227 | auto isInConv = std::find_if( |
| 1228 | conversations.begin(), conversations.end(), |
| 1229 | [current_item](const lrc::api::conversation::Info& conversation) { |
| 1230 | return current_item.uid == conversation.uid; |
| 1231 | }); |
| 1232 | if (IS_CHAT_VIEW(old_view) && isInConv == conversations.end()) { |
| 1233 | changeView(RING_WELCOME_VIEW_TYPE); |
| 1234 | } |
| 1235 | }; |
| 1236 | |
| 1237 | auto slotNewConversation = [this] (const std::string& uid) { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1238 | gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1239 | accountContainer_->info.conversationModel->setFilter(lrc::api::profile::Type::RING); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1240 | gtk_entry_set_text(GTK_ENTRY(widgets->search_entry), ""); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1241 | accountContainer_->info.conversationModel->setFilter(""); |
| 1242 | // Select new conversation if contact added |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1243 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1244 | if (IS_RING_WELCOME_VIEW(old_view) || (IS_CHAT_VIEW(old_view) && chat_view_get_temporary(CHAT_VIEW(old_view)))) { |
| 1245 | accountContainer_->info.conversationModel->selectConversation(uid); |
| 1246 | try { |
| 1247 | auto contactUri = chatViewConversation_->participants.front(); |
| 1248 | auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1249 | chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))), |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1250 | contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING |
| 1251 | || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY); |
| 1252 | } catch(...) { } |
| 1253 | } |
| 1254 | }; |
| 1255 | |
| 1256 | auto slotConversationRemoved = [this] (const std::string& uid) { |
| 1257 | // If contact is removed, go to welcome view |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1258 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1259 | lrc::api::conversation::Info current_item; |
| 1260 | if (IS_CHAT_VIEW(old_view)) |
| 1261 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 1262 | else if (IS_CURRENT_CALL_VIEW(old_view)) |
| 1263 | current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view)); |
| 1264 | else if (IS_INCOMING_CALL_VIEW(old_view)) |
| 1265 | current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view)); |
| 1266 | if (current_item.uid == uid) |
| 1267 | changeView(RING_WELCOME_VIEW_TYPE); |
| 1268 | }; |
| 1269 | |
| 1270 | auto slotShowChatView = [this] (const std::string& accountId, lrc::api::conversation::Info origin) { |
| 1271 | if (accountId != accountContainer_->info.id) |
| 1272 | useAccount(accountId); |
| 1273 | // Show chat view if not in call (unless if it's the same conversation) |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1274 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1275 | lrc::api::conversation::Info current_item; |
| 1276 | current_item.uid = "-1"; |
| 1277 | if (IS_CHAT_VIEW(old_view)) |
| 1278 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 1279 | if (current_item.uid != origin.uid) { |
| 1280 | if (origin.participants.empty()) return; |
| 1281 | auto firstContactUri = origin.participants.front(); |
| 1282 | auto contactInfo = accountContainer_->info.contactModel->getContact(firstContactUri); |
| 1283 | if (contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING && current_item.uid != "-1") return; |
| 1284 | changeView(CHAT_VIEW_TYPE, origin); |
| 1285 | } |
| 1286 | }; |
| 1287 | |
| 1288 | auto slotShowCallView = [this] (const std::string& accountId, lrc::api::conversation::Info origin) { |
| 1289 | if (accountId != accountContainer_->info.id) |
| 1290 | useAccount(accountId); |
| 1291 | // Change the view if we want a different view. |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1292 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1293 | |
| 1294 | lrc::api::conversation::Info current_item; |
| 1295 | if (IS_CURRENT_CALL_VIEW(old_view)) |
| 1296 | current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view)); |
| 1297 | |
| 1298 | if (current_item.uid != origin.uid) |
| 1299 | changeView(CURRENT_CALL_VIEW_TYPE, origin); |
| 1300 | }; |
| 1301 | |
| 1302 | auto slotShowIncomingCallView = [this] (const std::string& accountId, lrc::api::conversation::Info origin) { |
| 1303 | if (accountId != accountContainer_->info.id) |
| 1304 | useAccount(accountId); |
| 1305 | // Change the view if we want a different view. |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1306 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1307 | |
| 1308 | lrc::api::conversation::Info current_item; |
| 1309 | if (IS_INCOMING_CALL_VIEW(old_view)) |
| 1310 | current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view)); |
| 1311 | |
| 1312 | if (current_item.uid != origin.uid) |
| 1313 | changeView(INCOMING_CALL_VIEW_TYPE, origin); |
| 1314 | }; |
| 1315 | |
| 1316 | // Connect to signals from LRC |
| 1317 | historyClearedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel, |
| 1318 | &lrc::api::ConversationModel::conversationCleared, |
| 1319 | slotConversationCleared); |
| 1320 | |
| 1321 | modelSortedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel, |
| 1322 | &lrc::api::ConversationModel::modelSorted, |
| 1323 | slotModelSorted); |
| 1324 | |
| 1325 | filterChangedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel, |
| 1326 | &lrc::api::ConversationModel::filterChanged, |
| 1327 | slotFilterChanged); |
| 1328 | |
| 1329 | newConversationConnection_ = QObject::connect(&*accountContainer_->info.conversationModel, |
| 1330 | &lrc::api::ConversationModel::newConversation, |
| 1331 | slotNewConversation); |
| 1332 | |
| 1333 | conversationRemovedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel, |
| 1334 | &lrc::api::ConversationModel::conversationRemoved, |
| 1335 | slotConversationRemoved); |
| 1336 | |
| 1337 | showChatViewConnection_ = QObject::connect(&lrc_->getBehaviorController(), |
| 1338 | &lrc::api::BehaviorController::showChatView, |
| 1339 | slotShowChatView); |
| 1340 | |
| 1341 | showCallViewConnection_ = QObject::connect(&lrc_->getBehaviorController(), |
| 1342 | &lrc::api::BehaviorController::showCallView, |
| 1343 | slotShowCallView); |
| 1344 | |
| 1345 | showIncomingViewConnection_ = QObject::connect(&lrc_->getBehaviorController(), |
| 1346 | &lrc::api::BehaviorController::showIncomingCallView, |
| 1347 | slotShowIncomingCallView); |
| 1348 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame^] | 1349 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(widgets->search_entry)); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 1350 | currentTypeFilter_ = accountContainer_->info.profileInfo.type; |
| 1351 | accountContainer_->info.conversationModel->setFilter(text); |
| 1352 | accountContainer_->info.conversationModel->setFilter(currentTypeFilter_); |
| 1353 | } |
| 1354 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 1355 | } // namespace details |
| 1356 | |
| 1357 | //============================================================================== |
Guillaume Roguez | 0a41120 | 2017-05-25 15:27:26 -0400 | [diff] [blame] | 1358 | |
| 1359 | static void |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1360 | ring_main_window_init(RingMainWindow *win) |
| 1361 | { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 1362 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1363 | gtk_widget_init_template(GTK_WIDGET(win)); |
| 1364 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 1365 | // CppImpl ctor |
| 1366 | priv->cpp = new details::CppImpl {*win}; |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 1367 | priv->cpp->init(); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | static void |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1371 | ring_main_window_dispose(GObject *object) |
| 1372 | { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 1373 | auto* self = RING_MAIN_WINDOW(object); |
| 1374 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 1375 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 1376 | delete priv->cpp; |
| 1377 | priv->cpp = nullptr; |
| 1378 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1379 | G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object); |
| 1380 | } |
| 1381 | |
| 1382 | static void |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1383 | ring_main_window_finalize(GObject *object) |
| 1384 | { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 1385 | auto* self = RING_MAIN_WINDOW(object); |
| 1386 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 1387 | |
| 1388 | g_clear_object(&priv->settings); |
| 1389 | |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1390 | G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | static void |
| 1394 | ring_main_window_class_init(RingMainWindowClass *klass) |
| 1395 | { |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1396 | G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1397 | G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose; |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1398 | |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1399 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 1400 | "/cx/ring/RingGnome/ringmainwindow.ui"); |
| 1401 | |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 1402 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 1403 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, notebook_contacts); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 1404 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 1405 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu); |
| 1406 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring); |
| 1407 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings); |
| 1408 | 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] | 1409 | 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] | 1410 | 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] | 1411 | 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] | 1412 | 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] | 1413 | 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] | 1414 | 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] | 1415 | 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] | 1416 | 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] | 1417 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings); |
Nicolas Jager | 15a8b90 | 2017-03-21 07:53:06 -0400 | [diff] [blame] | 1418 | 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] | 1419 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contact_requests); |
Guillaume Roguez | 0a41120 | 2017-05-25 15:27:26 -0400 | [diff] [blame] | 1420 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_contact_requests_list); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | GtkWidget * |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 1424 | ring_main_window_new(GtkApplication *app) |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1425 | { |
Stepan Salenikovich | 61cbab0 | 2015-03-16 18:35:10 -0400 | [diff] [blame] | 1426 | gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL); |
Stepan Salenikovich | 61cbab0 | 2015-03-16 18:35:10 -0400 | [diff] [blame] | 1427 | return (GtkWidget *)win; |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1428 | } |