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