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