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 | |
Guillaume Roguez | a491104 | 2017-12-14 16:11:18 -0500 | [diff] [blame] | 126 | inline namespace helpers |
| 127 | { |
| 128 | |
| 129 | /** |
| 130 | * set the column value by printing the alias and the state of an account in combobox_account_selector. |
| 131 | */ |
| 132 | static void |
| 133 | print_account_and_state(GtkCellLayout* cell_layout, |
| 134 | GtkCellRenderer* cell, |
| 135 | GtkTreeModel* model, |
| 136 | GtkTreeIter* iter, |
| 137 | gpointer* data) |
| 138 | { |
| 139 | (void)cell_layout; |
| 140 | (void)data; |
| 141 | |
| 142 | gchar *alias; |
| 143 | gchar *text; |
| 144 | |
| 145 | gtk_tree_model_get (model, iter, |
| 146 | 1 /* col# */, &alias /* data */, |
| 147 | -1); |
| 148 | |
| 149 | text = g_markup_printf_escaped( |
| 150 | "<span fgcolor=\"gray\">%s</span>", |
| 151 | alias |
| 152 | ); |
| 153 | |
| 154 | g_object_set(G_OBJECT(cell), "markup", text, NULL); |
| 155 | g_free(alias); |
| 156 | } |
| 157 | |
| 158 | inline static void |
| 159 | foreachEnabledLrcAccount(const lrc::api::Lrc& lrc, |
| 160 | const std::function<void(const lrc::api::account::Info&)>& func) |
| 161 | { |
| 162 | auto& acc_model = lrc.getAccountModel(); |
| 163 | for (const auto& id : acc_model.getAccountList()) { |
| 164 | const auto& accountInfo = acc_model.getAccountInfo(id); |
| 165 | if (accountInfo.enabled) |
| 166 | func(accountInfo); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | } // namespace helpers |
| 171 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 172 | class CppImpl |
| 173 | { |
| 174 | public: |
| 175 | explicit CppImpl(RingMainWindow& widget); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 176 | ~CppImpl(); |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 177 | |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 178 | void init(); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 179 | void updateLrc(const std::string& accountId); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 180 | void changeView(GType type, lrc::api::conversation::Info conversation = {}); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 181 | WebKitChatContainer* webkitChatContainer() const; |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 182 | void enterFullScreen(); |
| 183 | void leaveFullScreen(); |
| 184 | void toggleFullScreen(); |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 185 | void resetToWelcome(); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 186 | void setPendingContactRequestTabIcon(); |
| 187 | void showAccountSelectorWidget(bool show = true); |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 188 | void changeAccountSelection(const std::string& id); |
| 189 | void onAccountSelectionChange(const std::string& id); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 190 | void enterAccountCreationWizard(); |
| 191 | void leaveAccountCreationWizard(); |
| 192 | void enterSettingsView(); |
| 193 | void leaveSettingsView(); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 194 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 195 | RingMainWindow* self = nullptr; // The GTK widget itself |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 196 | RingMainWindowPrivate* widgets = nullptr; |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 197 | |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 198 | std::unique_ptr<lrc::api::Lrc> lrc_; |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 199 | std::unique_ptr<AccountContainer> accountContainer_; |
| 200 | std::unique_ptr<lrc::api::conversation::Info> chatViewConversation_; |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 201 | lrc::api::profile::Type currentTypeFilter_; |
| 202 | bool show_settings = false; |
| 203 | bool is_fullscreen = false; |
| 204 | |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 205 | QMetaObject::Connection showChatViewConnection_; |
| 206 | QMetaObject::Connection showCallViewConnection_; |
| 207 | QMetaObject::Connection showIncomingViewConnection_; |
| 208 | QMetaObject::Connection changeAccountConnection_; |
| 209 | QMetaObject::Connection newAccountConnection_; |
| 210 | QMetaObject::Connection rmAccountConnection_; |
| 211 | QMetaObject::Connection historyClearedConnection_; |
| 212 | QMetaObject::Connection modelSortedConnection_; |
| 213 | QMetaObject::Connection filterChangedConnection_; |
| 214 | QMetaObject::Connection newConversationConnection_; |
| 215 | QMetaObject::Connection conversationRemovedConnection_; |
| 216 | QMetaObject::Connection accountStatusChangedConnection_; |
| 217 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 218 | private: |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 219 | CppImpl() = delete; |
| 220 | CppImpl(const CppImpl&) = delete; |
| 221 | CppImpl& operator=(const CppImpl&) = delete; |
| 222 | |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 223 | GtkWidget* displayIncomingView(lrc::api::conversation::Info); |
| 224 | GtkWidget* displayCurrentCallView(lrc::api::conversation::Info); |
| 225 | GtkWidget* displayChatView(lrc::api::conversation::Info); |
| 226 | |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 227 | // Callbacks used as LRC Qt slot |
| 228 | void slotAccountAddedFromLrc(const std::string& id); |
| 229 | void slotAccountRemovedFromLrc(const std::string& id); |
| 230 | void slotAccountStatusChanged(const std::string& id); |
| 231 | void slotConversationCleared(const std::string& uid); |
| 232 | void slotModelSorted(); |
| 233 | void slotFilterChanged(); |
| 234 | void slotNewConversation(const std::string& uid); |
| 235 | void slotConversationRemoved(const std::string& uid); |
| 236 | void slotShowChatView(const std::string& id, lrc::api::conversation::Info origin); |
| 237 | void slotShowCallView(const std::string& id, lrc::api::conversation::Info origin); |
| 238 | void slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin); |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 239 | }; |
| 240 | |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 241 | inline namespace gtk_callbacks |
| 242 | { |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 243 | |
Stepan Salenikovich | 7c71bfe | 2015-05-13 18:08:09 -0400 | [diff] [blame] | 244 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 245 | on_save_accounts_timeout(GtkWidget* working_dialog) |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 246 | { |
| 247 | /* save changes to accounts */ |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 248 | AccountModel::instance().save(); |
Stepan Salenikovich | bd02958 | 2015-03-24 11:00:56 -0400 | [diff] [blame] | 249 | |
| 250 | if (working_dialog) |
| 251 | gtk_widget_destroy(working_dialog); |
| 252 | |
| 253 | return G_SOURCE_REMOVE; |
| 254 | } |
| 255 | |
Stepan Salenikovich | 1514218 | 2015-03-11 17:15:26 -0400 | [diff] [blame] | 256 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 257 | on_video_double_clicked(RingMainWindow* self) |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 258 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 259 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 260 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 261 | priv->cpp->toggleFullScreen(); |
| 262 | } |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 263 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 264 | static void |
| 265 | on_hide_view_clicked(RingMainWindow* self) |
| 266 | { |
| 267 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 268 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 269 | priv->cpp->resetToWelcome(); |
| 270 | } |
Stepan Salenikovich | bd4b377 | 2015-12-13 23:28:06 -0500 | [diff] [blame] | 271 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 272 | static void |
| 273 | on_account_creation_completed(RingMainWindow* self) |
| 274 | { |
| 275 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 276 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 277 | priv->cpp->leaveAccountCreationWizard(); |
| 278 | } |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 279 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 280 | static void |
| 281 | on_account_changed(RingMainWindow* self) |
| 282 | { |
| 283 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 284 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 285 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 286 | auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector); |
| 287 | auto model = gtk_combo_box_get_model(accountComboBox); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 288 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 289 | GtkTreeIter iter; |
| 290 | if (gtk_combo_box_get_active_iter(accountComboBox, &iter)) { |
| 291 | gchar* accountId; |
| 292 | gtk_tree_model_get(model, &iter, 0 /* col# */, &accountId /* data */, -1); |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 293 | priv->cpp->onAccountSelectionChange(accountId); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 294 | g_free(accountId); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
| 298 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 299 | on_settings_clicked(RingMainWindow* self) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 300 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 301 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 302 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 303 | |
| 304 | if (!priv->cpp->show_settings) |
| 305 | priv->cpp->enterSettingsView(); |
| 306 | else |
| 307 | priv->cpp->leaveSettingsView(); |
| 308 | } |
| 309 | |
| 310 | static void |
| 311 | on_show_media_settings(GtkToggleButton* navbutton, RingMainWindow* self) |
| 312 | { |
| 313 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 314 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 315 | |
| 316 | if (gtk_toggle_button_get_active(navbutton)) { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 317 | 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] | 318 | 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] | 319 | priv->last_settings_view = priv->media_settings_view; |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 320 | } else { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 321 | 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] | 322 | } |
| 323 | } |
| 324 | |
| 325 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 326 | on_show_account_settings(GtkToggleButton* navbutton, RingMainWindow* self) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 327 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 328 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 329 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 330 | |
| 331 | if (gtk_toggle_button_get_active(navbutton)) { |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 332 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), ACCOUNT_SETTINGS_VIEW_NAME); |
| 333 | priv->last_settings_view = priv->account_settings_view; |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 337 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 338 | on_show_general_settings(GtkToggleButton* navbutton, RingMainWindow* self) |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 339 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 340 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 341 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 342 | |
| 343 | if (gtk_toggle_button_get_active(navbutton)) { |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 344 | 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] | 345 | gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME); |
| 346 | priv->last_settings_view = priv->general_settings_view; |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 347 | } else { |
| 348 | 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] | 349 | } |
| 350 | } |
| 351 | |
Stepan Salenikovich | b8e4127 | 2015-03-27 14:31:54 -0400 | [diff] [blame] | 352 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 353 | on_search_entry_text_changed(GtkSearchEntry* search_entry, RingMainWindow* self) |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 354 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 355 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 356 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 357 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 358 | // Filter model |
| 359 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry)); |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 360 | priv->cpp->accountContainer_->info.conversationModel->setFilter(text); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 364 | on_search_entry_activated(RingMainWindow* self) |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 365 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 366 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 367 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 368 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 369 | // Select the first conversation of the list |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 370 | auto& conversationModel = priv->cpp->accountContainer_->info.conversationModel; |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 371 | auto conversations = conversationModel->allFilteredConversations(); |
| 372 | if (!conversations.empty()) |
| 373 | conversationModel->selectConversation(conversations[0].uid); |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 376 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 377 | 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] | 378 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 379 | g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE); |
| 380 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 381 | |
Stepan Salenikovich | cac3504 | 2016-10-28 12:07:38 -0400 | [diff] [blame] | 382 | // if esc key pressed, clear the regex (keep the text, the user might not want to actually delete it) |
| 383 | if (key->keyval == GDK_KEY_Escape) { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 384 | priv->cpp->accountContainer_->info.conversationModel->setFilter(""); |
Stepan Salenikovich | cac3504 | 2016-10-28 12:07:38 -0400 | [diff] [blame] | 385 | return GDK_EVENT_STOP; |
| 386 | } |
| 387 | |
| 388 | return GDK_EVENT_PROPAGATE; |
| 389 | } |
| 390 | |
| 391 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 392 | on_dtmf_pressed(RingMainWindow* self, GdkEventKey* event, gpointer user_data) |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 393 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 394 | (void)user_data; |
| 395 | |
| 396 | g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE); |
| 397 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 398 | |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 399 | 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] | 400 | g_return_val_if_fail(priv, GDK_EVENT_PROPAGATE); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 401 | |
| 402 | /* we want to react to digit key presses, as long as a GtkEntry is not the |
| 403 | * input focus |
| 404 | */ |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 405 | GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(self)); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 406 | if (GTK_IS_ENTRY(focus)) |
| 407 | return GDK_EVENT_PROPAGATE; |
| 408 | |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 409 | if (priv->cpp->accountContainer_ && |
| 410 | priv->cpp->accountContainer_->info.profileInfo.type != lrc::api::profile::Type::SIP) |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 411 | return GDK_EVENT_PROPAGATE; |
| 412 | |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 413 | /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c' |
| 414 | * does not result in a 'c' being played. |
| 415 | * we filter Ctrl, Alt, and SUPER/HYPER/META keys */ |
| 416 | if ( event->state |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 417 | & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK )) |
| 418 | return GDK_EVENT_PROPAGATE; |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 419 | |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 420 | // Get current conversation |
| 421 | auto current_view = gtk_bin_get_child(GTK_BIN(priv->frame_call)); |
| 422 | lrc::api::conversation::Info current_item; |
| 423 | if (IS_CURRENT_CALL_VIEW(current_view)) |
| 424 | current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(current_view)); |
| 425 | else |
| 426 | return GDK_EVENT_PROPAGATE; |
| 427 | |
| 428 | if (current_item.callId.empty()) |
| 429 | return GDK_EVENT_PROPAGATE; |
| 430 | |
| 431 | // pass the character that was entered to be played by the daemon; |
| 432 | // the daemon will filter out invalid DTMF characters |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 433 | guint32 unicode_val = gdk_keyval_to_unicode(event->keyval); |
| 434 | QString val = QString::fromUcs4(&unicode_val, 1); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 435 | 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] | 436 | priv->cpp->accountContainer_->info.callModel->playDTMF(current_item.callId, val.toStdString()); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 437 | // always propogate the key, so we don't steal accelerators/shortcuts |
Stepan Salenikovich | 447f4a7 | 2015-04-29 11:09:28 -0400 | [diff] [blame] | 438 | return GDK_EVENT_PROPAGATE; |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 441 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 442 | on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainWindow* self) |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 443 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 444 | (void)notebook; |
| 445 | (void)page; |
| 446 | |
| 447 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 448 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
| 449 | |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 450 | auto newType = page_num == 0 ? priv->cpp->accountContainer_->info.profileInfo.type : lrc::api::profile::Type::PENDING; |
| 451 | if (priv->cpp->currentTypeFilter_ != newType) { |
| 452 | priv->cpp->currentTypeFilter_ = newType; |
| 453 | priv->cpp->accountContainer_->info.conversationModel->setFilter(priv->cpp->currentTypeFilter_); |
Sébastien Blin | 55bff9d | 2017-10-03 15:15:23 -0400 | [diff] [blame] | 454 | } |
Nicolas Jager | 0efc843 | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 457 | static gboolean |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 458 | on_window_size_changed(GtkWidget* self, GdkEventConfigure* event, gpointer user_data) |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 459 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 460 | (void)user_data; |
| 461 | |
| 462 | g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE); |
| 463 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 464 | |
| 465 | g_settings_set_int(priv->settings, "window-width", event->width); |
| 466 | g_settings_set_int(priv->settings, "window-height", event->height); |
| 467 | |
| 468 | return GDK_EVENT_PROPAGATE; |
| 469 | } |
| 470 | |
Stepan Salenikovich | eafc3dd | 2015-04-16 18:38:01 -0400 | [diff] [blame] | 471 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 472 | 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] | 473 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 474 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 475 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 476 | |
| 477 | if (g_settings_get_boolean(settings, key)) { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 478 | gtk_widget_set_tooltip_text(priv->button_new_conversation, |
| 479 | C_("button next to search entry will place a new call", |
| 480 | "place call")); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 481 | } else { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 482 | gtk_widget_set_tooltip_text(priv->button_new_conversation, |
| 483 | C_("button next to search entry will open chat", "open chat")); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
| 487 | static void |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 488 | on_handle_account_migrations(RingMainWindow* self) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 489 | { |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 490 | g_return_if_fail(IS_RING_MAIN_WINDOW(self)); |
| 491 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self)); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 492 | |
| 493 | /* If there is an existing migration view, remove it */ |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 494 | if (priv->account_migration_view) { |
Stepan Salenikovich | 56530b1 | 2016-10-20 17:51:34 -0400 | [diff] [blame] | 495 | gtk_widget_destroy(priv->account_migration_view); |
| 496 | priv->account_migration_view = nullptr; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 499 | auto accounts = AccountModel::instance().accountsToMigrate(); |
| 500 | if (!accounts.isEmpty()) { |
| 501 | auto* account = accounts.first(); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 502 | |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 503 | priv->account_migration_view = account_migration_view_new(account); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 504 | g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed", |
| 505 | G_CALLBACK(on_handle_account_migrations), self); |
| 506 | g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed", |
| 507 | G_CALLBACK(on_handle_account_migrations), self); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 508 | |
| 509 | gtk_widget_hide(priv->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 510 | priv->cpp->showAccountSelectorWidget(false); |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 511 | gtk_widget_show(priv->account_migration_view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 512 | gtk_stack_add_named( |
| 513 | GTK_STACK(priv->stack_main_view), |
aviau | 6908184 | 2016-10-14 14:51:54 -0400 | [diff] [blame] | 514 | priv->account_migration_view, |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 515 | ACCOUNT_MIGRATION_VIEW_NAME |
| 516 | ); |
| 517 | gtk_stack_set_visible_child_name( |
| 518 | GTK_STACK(priv->stack_main_view), |
| 519 | ACCOUNT_MIGRATION_VIEW_NAME |
| 520 | ); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 521 | } else { |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 522 | gtk_widget_show(priv->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 523 | priv->cpp->showAccountSelectorWidget(); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 527 | } // namespace gtk_callbacks |
| 528 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 529 | CppImpl::CppImpl(RingMainWindow& widget) |
| 530 | : self {&widget} |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 531 | , widgets {RING_MAIN_WINDOW_GET_PRIVATE(&widget)} |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 532 | , lrc_ {std::make_unique<lrc::api::Lrc>()} |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 533 | {} |
| 534 | |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 535 | void |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 536 | CppImpl::init() |
| 537 | { |
| 538 | // NOTE: When new models will be fully implemented, we need to move this |
| 539 | // in rign_client.cpp-> |
| 540 | // Init LRC and the vew |
| 541 | const auto accountIds = lrc_->getAccountModel().getAccountList(); |
| 542 | auto isInitialized = false; |
| 543 | if (not accountIds.empty()) { |
| 544 | for (const auto& accountId : accountIds) { |
| 545 | const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId); |
| 546 | if (accountInfo.enabled) { |
| 547 | updateLrc(accountId); |
| 548 | isInitialized = true; |
| 549 | break; |
| 550 | } |
| 551 | } |
| 552 | if (!isInitialized) { |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 553 | widgets->treeview_conversations = conversations_view_new(accountContainer_.get()); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 554 | gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations); |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 555 | widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get()); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 556 | 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] | 557 | } |
| 558 | } |
| 559 | |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 560 | accountStatusChangedConnection_ = QObject::connect(&lrc_->getAccountModel(), |
| 561 | &lrc::api::NewAccountModel::accountStatusChanged, |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 562 | [this](const std::string& id){ slotAccountStatusChanged(id); }); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 563 | newAccountConnection_ = QObject::connect(&lrc_->getAccountModel(), |
Guillaume Roguez | 5121fd6 | 2017-12-13 18:51:52 -0500 | [diff] [blame] | 564 | &lrc::api::NewAccountModel::accountAdded, |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 565 | [this](const std::string& id){ slotAccountAddedFromLrc(id); }); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 566 | rmAccountConnection_ = QObject::connect(&lrc_->getAccountModel(), |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 567 | &lrc::api::NewAccountModel::accountRemoved, |
| 568 | [this](const std::string& id){ slotAccountRemovedFromLrc(id); }); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 569 | |
| 570 | /* bind to window size settings */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 571 | widgets->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr); |
| 572 | auto width = g_settings_get_int(widgets->settings, "window-width"); |
| 573 | auto height = g_settings_get_int(widgets->settings, "window-height"); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 574 | gtk_window_set_default_size(GTK_WINDOW(self), width, height); |
| 575 | g_signal_connect(self, "configure-event", G_CALLBACK(on_window_size_changed), nullptr); |
| 576 | |
| 577 | /* search-entry-places-call setting */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 578 | 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] | 579 | g_signal_connect(widgets->settings, "changed::search-entry-places-call", |
| 580 | G_CALLBACK(on_search_entry_places_call_changed), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 581 | |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 582 | /* set window icon */ |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 583 | GError *error = NULL; |
| 584 | GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error); |
| 585 | if (icon == NULL) { |
| 586 | g_debug("Could not load icon: %s", error->message); |
| 587 | g_clear_error(&error); |
| 588 | } else |
| 589 | gtk_window_set_icon(GTK_WINDOW(self), icon); |
| 590 | |
| 591 | /* set menu icon */ |
| 592 | GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue", |
| 593 | -1, 16, TRUE, &error); |
| 594 | if (image_ring == NULL) { |
| 595 | g_debug("Could not load icon: %s", error->message); |
| 596 | g_clear_error(&error); |
| 597 | } else |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 598 | gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_ring), image_ring); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 599 | |
| 600 | /* ring menu */ |
| 601 | GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui"); |
| 602 | GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu")); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 603 | 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] | 604 | g_object_unref(builder); |
| 605 | |
| 606 | /* settings icon */ |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 607 | gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic", |
| 608 | GTK_ICON_SIZE_SMALL_TOOLBAR); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 609 | |
| 610 | /* connect settings button signal */ |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 611 | g_signal_connect_swapped(widgets->ring_settings, "clicked", |
| 612 | G_CALLBACK(on_settings_clicked), self); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 613 | |
| 614 | /* add the call view to the main stack */ |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 615 | 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] | 616 | CALL_VIEW_NAME); |
| 617 | |
| 618 | /* init the settings views */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 619 | widgets->account_settings_view = account_view_new(); |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 620 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->account_settings_view, |
| 621 | ACCOUNT_SETTINGS_VIEW_NAME); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 622 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 623 | widgets->media_settings_view = media_settings_view_new(); |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 624 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->media_settings_view, |
| 625 | MEDIA_SETTINGS_VIEW_NAME); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 626 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 627 | widgets->general_settings_view = general_settings_view_new(); |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 628 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view, |
| 629 | GENERAL_SETTINGS_VIEW_NAME); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 630 | |
| 631 | /* make the setting we will show first the active one */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 632 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE); |
| 633 | widgets->last_settings_view = widgets->general_settings_view; |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 634 | |
| 635 | /* connect the settings button signals to switch settings views */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 636 | g_signal_connect(widgets->radiobutton_media_settings, "toggled", G_CALLBACK(on_show_media_settings), self); |
| 637 | g_signal_connect(widgets->radiobutton_account_settings, "toggled", G_CALLBACK(on_show_account_settings), self); |
| 638 | 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] | 639 | 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] | 640 | |
| 641 | /* welcome/default view */ |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 642 | widgets->welcome_view = ring_welcome_view_new(accountContainer_.get()); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 643 | g_object_ref(widgets->welcome_view); // increase ref because don't want it to be destroyed when not displayed |
| 644 | gtk_container_add(GTK_CONTAINER(widgets->frame_call), widgets->welcome_view); |
| 645 | gtk_widget_show(widgets->welcome_view); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 646 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 647 | g_signal_connect_swapped(widgets->search_entry, "activate", G_CALLBACK(on_search_entry_activated), self); |
| 648 | g_signal_connect_swapped(widgets->button_new_conversation, "clicked", G_CALLBACK(on_search_entry_activated), self); |
| 649 | g_signal_connect(widgets->search_entry, "search-changed", G_CALLBACK(on_search_entry_text_changed), self); |
| 650 | 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] | 651 | |
| 652 | auto provider = gtk_css_provider_new(); |
| 653 | gtk_css_provider_load_from_data(provider, |
| 654 | ".search-entry-style { border: 0; border-radius: 0; } \ |
| 655 | .spinner-style { border: 0; background: white; } \ |
| 656 | .new-conversation-style { border: 0; background: white; transition: all 0.3s ease; border-radius: 0; } \ |
| 657 | .new-conversation-style:hover { background: #bae5f0; }", |
| 658 | -1, nullptr |
| 659 | ); |
| 660 | gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()), |
| 661 | GTK_STYLE_PROVIDER(provider), |
| 662 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
| 663 | |
| 664 | |
| 665 | /* react to digit key press events */ |
| 666 | g_signal_connect(self, "key-press-event", G_CALLBACK(on_dtmf_pressed), nullptr); |
| 667 | |
| 668 | /* set the search entry placeholder text */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 669 | gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->search_entry), |
Guillaume Roguez | 1eb30c6 | 2017-12-13 19:40:47 -0500 | [diff] [blame] | 670 | C_("Please try to make the translation 50 chars or less so that it fits into the layout", |
| 671 | "Search contacts or enter number")); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 672 | |
| 673 | /* init chat webkit container so that it starts loading before the first time we need it*/ |
| 674 | (void)webkitChatContainer(); |
| 675 | |
| 676 | if (has_ring_account()) { |
| 677 | /* user has ring account, so show the call view right away */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 678 | 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] | 679 | |
| 680 | on_handle_account_migrations(self); |
| 681 | } else { |
| 682 | /* user has to create the ring account */ |
| 683 | enterAccountCreationWizard(); |
| 684 | } |
| 685 | |
| 686 | // setup account selector and select the first account |
| 687 | auto store = gtk_list_store_new (2 /* # of cols */ , |
| 688 | G_TYPE_STRING, |
| 689 | G_TYPE_STRING, |
| 690 | G_TYPE_UINT); |
| 691 | GtkTreeIter iter; |
Guillaume Roguez | 7e23840 | 2017-12-13 19:40:05 -0500 | [diff] [blame] | 692 | foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) { |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 693 | gtk_list_store_append (store, &iter); |
| 694 | gtk_list_store_set (store, &iter, |
Guillaume Roguez | 7e23840 | 2017-12-13 19:40:05 -0500 | [diff] [blame] | 695 | 0 /* col # */ , acc_info.id.c_str() /* celldata */, |
| 696 | 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */, |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 697 | -1 /* end */); |
Guillaume Roguez | 7e23840 | 2017-12-13 19:40:05 -0500 | [diff] [blame] | 698 | }); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 699 | |
| 700 | gtk_combo_box_set_model( |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 701 | GTK_COMBO_BOX(widgets->combobox_account_selector), |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 702 | GTK_TREE_MODEL (store) |
| 703 | ); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 704 | 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] | 705 | |
| 706 | /* set visibility */ |
| 707 | showAccountSelectorWidget(); |
| 708 | |
| 709 | /* layout */ |
| 710 | auto *renderer = gtk_cell_renderer_text_new(); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 711 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, FALSE); |
| 712 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, "text", 0, NULL); |
| 713 | 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] | 714 | renderer, |
| 715 | (GtkCellLayoutDataFunc)print_account_and_state, |
| 716 | nullptr, nullptr); |
| 717 | |
| 718 | // 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] | 719 | 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] | 720 | |
| 721 | // initialize the pending contact request icon. |
| 722 | setPendingContactRequestTabIcon(); |
| 723 | |
| 724 | if (isInitialized) { |
| 725 | auto& conversationModel = accountContainer_->info.conversationModel; |
| 726 | auto conversations = conversationModel->allFilteredConversations(); |
| 727 | for (const auto& conversation: conversations) { |
| 728 | if (!conversation.callId.empty()) { |
| 729 | accountContainer_->info.conversationModel->selectConversation(conversation.uid); |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | CppImpl::~CppImpl() |
| 736 | { |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 737 | QObject::disconnect(showChatViewConnection_); |
| 738 | QObject::disconnect(showIncomingViewConnection_); |
| 739 | QObject::disconnect(historyClearedConnection_); |
| 740 | QObject::disconnect(modelSortedConnection_); |
| 741 | QObject::disconnect(filterChangedConnection_); |
| 742 | QObject::disconnect(newConversationConnection_); |
| 743 | QObject::disconnect(conversationRemovedConnection_); |
| 744 | QObject::disconnect(changeAccountConnection_); |
| 745 | QObject::disconnect(newAccountConnection_); |
| 746 | QObject::disconnect(rmAccountConnection_); |
| 747 | QObject::disconnect(showCallViewConnection_); |
| 748 | QObject::disconnect(modelSortedConnection_); |
| 749 | QObject::disconnect(accountStatusChangedConnection_); |
| 750 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 751 | g_clear_object(&widgets->welcome_view); |
| 752 | g_clear_object(&widgets->webkit_chat_container); |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | void |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 756 | CppImpl::changeView(GType type, lrc::api::conversation::Info conversation) |
| 757 | { |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 758 | leaveFullScreen(); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 759 | gtk_container_remove(GTK_CONTAINER(widgets->frame_call), |
| 760 | gtk_bin_get_child(GTK_BIN(widgets->frame_call))); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 761 | |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 762 | GtkWidget* new_view; |
| 763 | if (g_type_is_a(INCOMING_CALL_VIEW_TYPE, type)) { |
| 764 | new_view = displayIncomingView(conversation); |
| 765 | } else if (g_type_is_a(CURRENT_CALL_VIEW_TYPE, type)) { |
| 766 | new_view = displayCurrentCallView(conversation); |
| 767 | } else if (g_type_is_a(CHAT_VIEW_TYPE, type)) { |
| 768 | new_view = displayChatView(conversation); |
| 769 | } else { |
| 770 | // TODO select first conversation? |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 771 | new_view = widgets->welcome_view; |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 772 | } |
| 773 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 774 | gtk_container_add(GTK_CONTAINER(widgets->frame_call), new_view); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 775 | gtk_widget_show(new_view); |
| 776 | } |
| 777 | |
| 778 | GtkWidget* |
| 779 | CppImpl::displayIncomingView(lrc::api::conversation::Info conversation) |
| 780 | { |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 781 | chatViewConversation_.reset(new lrc::api::conversation::Info(conversation)); |
| 782 | return incoming_call_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get()); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | GtkWidget* |
| 786 | CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation) |
| 787 | { |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 788 | chatViewConversation_.reset(new lrc::api::conversation::Info(conversation)); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 789 | auto* new_view = current_call_view_new(webkitChatContainer(), |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 790 | accountContainer_.get(), chatViewConversation_.get()); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 791 | |
| 792 | try { |
| 793 | auto contactUri = chatViewConversation_->participants.front(); |
| 794 | auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri); |
| 795 | if (auto chat_view = current_call_view_get_chat_view(CURRENT_CALL_VIEW(new_view))) { |
| 796 | chat_view_update_temporary(CHAT_VIEW(chat_view), |
| 797 | contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING |
| 798 | || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY); |
| 799 | } |
| 800 | } catch(...) { } |
| 801 | |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 802 | g_signal_connect_swapped(new_view, "video-double-clicked", |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 803 | G_CALLBACK(on_video_double_clicked), self); |
Guillaume Roguez | 527dc6b | 2017-12-12 22:58:51 -0500 | [diff] [blame] | 804 | return new_view; |
| 805 | } |
| 806 | |
| 807 | GtkWidget* |
| 808 | CppImpl::displayChatView(lrc::api::conversation::Info conversation) |
| 809 | { |
Guillaume Roguez | b96d653 | 2017-12-13 14:31:39 -0500 | [diff] [blame] | 810 | chatViewConversation_.reset(new lrc::api::conversation::Info(conversation)); |
| 811 | auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get()); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 812 | 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] | 813 | return new_view; |
| 814 | } |
| 815 | |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 816 | WebKitChatContainer* |
| 817 | CppImpl::webkitChatContainer() const |
| 818 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 819 | if (!widgets->webkit_chat_container) { |
| 820 | widgets->webkit_chat_container = webkit_chat_container_new(); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 821 | |
| 822 | // We don't want it to be deleted, ever. |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 823 | g_object_ref(widgets->webkit_chat_container); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 824 | } |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 825 | return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container); |
Guillaume Roguez | 11339f8 | 2017-12-12 23:15:34 -0500 | [diff] [blame] | 826 | } |
| 827 | |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 828 | void |
| 829 | CppImpl::enterFullScreen() |
| 830 | { |
| 831 | if (!is_fullscreen) { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 832 | gtk_widget_hide(widgets->vbox_left_pane); |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 833 | gtk_window_fullscreen(GTK_WINDOW(self)); |
| 834 | is_fullscreen = true; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | void |
| 839 | CppImpl::leaveFullScreen() |
| 840 | { |
| 841 | if (is_fullscreen) { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 842 | gtk_widget_show(widgets->vbox_left_pane); |
Guillaume Roguez | 1d96327 | 2017-12-12 23:32:13 -0500 | [diff] [blame] | 843 | gtk_window_unfullscreen(GTK_WINDOW(self)); |
| 844 | is_fullscreen = false; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | void |
| 849 | CppImpl::toggleFullScreen() |
| 850 | { |
| 851 | if (is_fullscreen) |
| 852 | leaveFullScreen(); |
| 853 | else |
| 854 | enterFullScreen(); |
| 855 | } |
| 856 | |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 857 | /// Clear selection and go to welcome page. |
| 858 | void |
| 859 | CppImpl::resetToWelcome() |
| 860 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 861 | 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] | 862 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 863 | 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] | 864 | gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request)); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 865 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
Guillaume Roguez | 6ee8df6 | 2017-12-12 23:54:18 -0500 | [diff] [blame] | 866 | lrc::api::conversation::Info current_item; |
| 867 | if (IS_CHAT_VIEW(old_view)) |
| 868 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 869 | changeView(RING_WELCOME_VIEW_TYPE, current_item); |
| 870 | } |
| 871 | |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 872 | void |
| 873 | CppImpl::setPendingContactRequestTabIcon() |
| 874 | { |
| 875 | if (not accountContainer_) |
| 876 | return; |
| 877 | |
| 878 | auto isRingAccount = accountContainer_->info.profileInfo.type == lrc::api::profile::Type::RING; |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 879 | gtk_widget_set_visible(widgets->scrolled_window_contact_requests, isRingAccount); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 880 | |
| 881 | if (not isRingAccount) |
| 882 | return; |
| 883 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 884 | gtk_image_set_from_resource(GTK_IMAGE(widgets->image_contact_requests_list), |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 885 | (accountContainer_->info.contactModel->hasPendingRequests()) |
| 886 | ? "/cx/ring/RingGnome/contact_requests_list_with_notification" |
| 887 | : "/cx/ring/RingGnome/contact_requests_list"); |
| 888 | } |
| 889 | |
| 890 | void |
| 891 | CppImpl::showAccountSelectorWidget(bool show) |
| 892 | { |
| 893 | // we only want to show the account selector when there is more than 1 enabled |
| 894 | // 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] | 895 | std::size_t activatedAccount = 0; |
| 896 | foreachEnabledLrcAccount(*lrc_, [&] (const auto&) { ++activatedAccount; }); |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 897 | gtk_widget_set_visible(widgets->combobox_account_selector, show && activatedAccount > 1); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | void |
| 901 | CppImpl::enterAccountCreationWizard() |
| 902 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 903 | if (!widgets->account_creation_wizard) { |
| 904 | widgets->account_creation_wizard = account_creation_wizard_new(false); |
| 905 | g_object_add_weak_pointer(G_OBJECT(widgets->account_creation_wizard), |
| 906 | reinterpret_cast<gpointer*>(&widgets->account_creation_wizard)); |
| 907 | g_signal_connect_swapped(widgets->account_creation_wizard, "account-creation-completed", |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 908 | G_CALLBACK(on_account_creation_completed), self); |
| 909 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 910 | gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), |
| 911 | widgets->account_creation_wizard, |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 912 | ACCOUNT_CREATION_WIZARD_VIEW_NAME); |
| 913 | } |
| 914 | |
| 915 | /* hide settings button until account creation is complete */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 916 | gtk_widget_hide(widgets->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 917 | showAccountSelectorWidget(false); |
| 918 | |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 919 | gtk_widget_show(widgets->account_creation_wizard); |
| 920 | 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] | 921 | } |
| 922 | |
| 923 | void |
| 924 | CppImpl::leaveAccountCreationWizard() |
| 925 | { |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 926 | 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] | 927 | |
| 928 | /* destroy the wizard */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 929 | if (widgets->account_creation_wizard) { |
| 930 | gtk_container_remove(GTK_CONTAINER(widgets->stack_main_view), widgets->account_creation_wizard); |
| 931 | gtk_widget_destroy(widgets->account_creation_wizard); |
| 932 | widgets->account_creation_wizard = nullptr; |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* show the settings button */ |
Guillaume Roguez | 3ea37de | 2017-12-13 14:13:54 -0500 | [diff] [blame] | 936 | gtk_widget_show(widgets->ring_settings); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 937 | |
| 938 | /* show the account selector */ |
| 939 | showAccountSelectorWidget(); |
| 940 | } |
| 941 | |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 942 | /// Change the selection of the account ComboBox by account Id. |
| 943 | /// Find in displayed accounts with one corresponding to the given id, then select it |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 944 | void |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 945 | CppImpl::changeAccountSelection(const std::string& id) |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 946 | { |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 947 | // already selected? |
| 948 | if (id == accountContainer_->info.id) |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 949 | return; |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 950 | |
| 951 | if (auto* model = gtk_combo_box_get_model(GTK_COMBO_BOX(widgets->combobox_account_selector))) { |
| 952 | GtkTreeIter iter; |
| 953 | auto valid = gtk_tree_model_get_iter_first(model, &iter); |
| 954 | while (valid) { |
| 955 | const gchar* account_id; |
| 956 | gtk_tree_model_get(model, &iter, 0 /* col# */, &account_id /* data */, -1); |
| 957 | if (id == account_id) { |
| 958 | gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->combobox_account_selector), &iter); |
| 959 | return; |
| 960 | } |
| 961 | valid = gtk_tree_model_iter_next(model, &iter); |
| 962 | } |
| 963 | |
| 964 | g_debug("BUGS: account not listed: %s", id.c_str()); |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 965 | } |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | void |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 969 | CppImpl::onAccountSelectionChange(const std::string& id) |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 970 | { |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 971 | // Go to welcome view |
Guillaume Roguez | dbefafd | 2017-12-12 23:54:49 -0500 | [diff] [blame] | 972 | changeView(RING_WELCOME_VIEW_TYPE); |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 973 | // Show conversation panel |
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 | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 975 | // Reinit LRC |
Guillaume Roguez | 5121fd6 | 2017-12-13 18:51:52 -0500 | [diff] [blame] | 976 | updateLrc(id); |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 977 | // Update the welcome view |
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 | { |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 1336 | changeAccountSelection(id); |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 1337 | // Show chat view if not in call (unless if it's the same conversation) |
| 1338 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
| 1339 | lrc::api::conversation::Info current_item; |
| 1340 | current_item.uid = "-1"; |
| 1341 | if (IS_CHAT_VIEW(old_view)) |
| 1342 | current_item = chat_view_get_conversation(CHAT_VIEW(old_view)); |
| 1343 | if (current_item.uid != origin.uid) { |
| 1344 | if (origin.participants.empty()) return; |
| 1345 | auto firstContactUri = origin.participants.front(); |
| 1346 | auto contactInfo = accountContainer_->info.contactModel->getContact(firstContactUri); |
| 1347 | if (contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING && current_item.uid != "-1") return; |
| 1348 | changeView(CHAT_VIEW_TYPE, origin); |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | void |
| 1353 | CppImpl::slotShowCallView(const std::string& id, lrc::api::conversation::Info origin) |
| 1354 | { |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 1355 | changeAccountSelection(id); |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 1356 | // Change the view if we want a different view. |
| 1357 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
| 1358 | |
| 1359 | lrc::api::conversation::Info current_item; |
| 1360 | if (IS_CURRENT_CALL_VIEW(old_view)) |
| 1361 | current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view)); |
| 1362 | |
| 1363 | if (current_item.uid != origin.uid) |
| 1364 | changeView(CURRENT_CALL_VIEW_TYPE, origin); |
| 1365 | } |
| 1366 | |
| 1367 | void |
| 1368 | CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin) |
| 1369 | { |
Guillaume Roguez | a04f442 | 2017-12-14 13:52:34 -0500 | [diff] [blame] | 1370 | changeAccountSelection(id); |
Guillaume Roguez | 64236c2 | 2017-12-13 20:08:25 -0500 | [diff] [blame] | 1371 | // Change the view if we want a different view. |
| 1372 | auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call)); |
| 1373 | |
| 1374 | lrc::api::conversation::Info current_item; |
| 1375 | if (IS_INCOMING_CALL_VIEW(old_view)) |
| 1376 | current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view)); |
| 1377 | |
| 1378 | if (current_item.uid != origin.uid) |
| 1379 | changeView(INCOMING_CALL_VIEW_TYPE, origin); |
| 1380 | } |
| 1381 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 1382 | } // namespace details |
| 1383 | |
| 1384 | //============================================================================== |
Guillaume Roguez | 0a41120 | 2017-05-25 15:27:26 -0400 | [diff] [blame] | 1385 | |
| 1386 | static void |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1387 | ring_main_window_init(RingMainWindow *win) |
| 1388 | { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 1389 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1390 | gtk_widget_init_template(GTK_WIDGET(win)); |
| 1391 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 1392 | // CppImpl ctor |
| 1393 | priv->cpp = new details::CppImpl {*win}; |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 1394 | priv->cpp->init(); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | static void |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1398 | ring_main_window_dispose(GObject *object) |
| 1399 | { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 1400 | auto* self = RING_MAIN_WINDOW(object); |
| 1401 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 1402 | |
Guillaume Roguez | 1e50f0b | 2017-12-12 20:58:30 -0500 | [diff] [blame] | 1403 | delete priv->cpp; |
| 1404 | priv->cpp = nullptr; |
| 1405 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1406 | G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object); |
| 1407 | } |
| 1408 | |
| 1409 | static void |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1410 | ring_main_window_finalize(GObject *object) |
| 1411 | { |
Guillaume Roguez | 6f43137 | 2017-12-12 21:15:39 -0500 | [diff] [blame] | 1412 | auto* self = RING_MAIN_WINDOW(object); |
| 1413 | auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self); |
Stepan Salenikovich | ba87ae2 | 2016-09-13 14:27:20 -0400 | [diff] [blame] | 1414 | |
| 1415 | g_clear_object(&priv->settings); |
| 1416 | |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1417 | G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object); |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | static void |
| 1421 | ring_main_window_class_init(RingMainWindowClass *klass) |
| 1422 | { |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1423 | G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1424 | G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose; |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 1425 | |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1426 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 1427 | "/cx/ring/RingGnome/ringmainwindow.ui"); |
| 1428 | |
Stepan Salenikovich | bbb10d8 | 2015-05-13 12:26:44 -0400 | [diff] [blame] | 1429 | 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] | 1430 | 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] | 1431 | 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] | 1432 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu); |
| 1433 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring); |
| 1434 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings); |
| 1435 | 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] | 1436 | 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] | 1437 | 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] | 1438 | 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] | 1439 | 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] | 1440 | 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] | 1441 | 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] | 1442 | 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] | 1443 | 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] | 1444 | 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] | 1445 | 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] | 1446 | 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] | 1447 | 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] | 1448 | } |
| 1449 | |
| 1450 | GtkWidget * |
Guillaume Roguez | 47cd8b5 | 2017-12-13 14:06:01 -0500 | [diff] [blame] | 1451 | ring_main_window_new(GtkApplication *app) |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1452 | { |
Stepan Salenikovich | 61cbab0 | 2015-03-16 18:35:10 -0400 | [diff] [blame] | 1453 | gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL); |
Stepan Salenikovich | 61cbab0 | 2015-03-16 18:35:10 -0400 | [diff] [blame] | 1454 | return (GtkWidget *)win; |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 1455 | } |