blob: ab3a3b6f9ac7804eab1fc06247d43d1c40bd8a77 [file] [log] [blame]
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001/*
Guillaume Roguez77c579d2018-01-30 15:54:02 -05002 * Copyright (C) 2015-2018 Savoir-faire Linux Inc.
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05003 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05004 * Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05005 *
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 Salenikovich434b88f2015-02-19 17:49:08 -050019 */
20
21#include "ringmainwindow.h"
22
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -040023// GTK+ related
Stepan Salenikovicha1b8cb32015-09-11 14:58:35 -040024#include <glib/gi18n.h>
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -040025
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -040026// LRC
Sébastien Blin55bff9d2017-10-03 15:15:23 -040027#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 Jagercfeffc32018-01-12 10:58:55 -050039#include <media/textrecording.h>
40#include <media/recordingmodel.h>
41#include <media/text.h>
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -040042
43// Ring client
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -040044#include "accountview.h"
aviau6aeb4852016-08-18 16:01:09 -040045#include "accountmigrationview.h"
46#include "accountcreationwizard.h"
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -050047#include "chatview.h"
Sébastien Blin55bff9d2017-10-03 15:15:23 -040048#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 Salenikovichba87ae22016-09-13 14:27:20 -040057#include "utils/files.h"
Nicolas Jagercfeffc32018-01-12 10:58:55 -050058#include "ringnotify.h"
Nicolas Jagerb413b302016-05-06 11:41:32 -040059
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -050060//==============================================================================
61
Guillaume Roguez1b69f092018-01-24 11:34:50 -050062namespace { namespace details
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -050063{
64class CppImpl;
Guillaume Roguez1b69f092018-01-24 11:34:50 -050065}}
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050066
67struct _RingMainWindow
68{
69 GtkApplicationWindow parent;
70};
71
72struct _RingMainWindowClass
73{
74 GtkApplicationWindowClass parent_class;
75};
76
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -050077struct RingMainWindowPrivate
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050078{
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040079 GtkWidget *ring_menu;
80 GtkWidget *image_ring;
81 GtkWidget *ring_settings;
82 GtkWidget *image_settings;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040083 GtkWidget *hbox_settings;
Sébastien Blin55bff9d2017-10-03 15:15:23 -040084 GtkWidget *notebook_contacts;
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -040085 GtkWidget *scrolled_window_smartview;
Stepan Salenikovich09e0b782016-09-07 16:28:50 -040086 GtkWidget *treeview_conversations;
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -040087 GtkWidget *vbox_left_pane;
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -050088 GtkWidget *search_entry;
Stepan Salenikovich69771842015-02-24 18:11:45 -050089 GtkWidget *stack_main_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040090 GtkWidget *vbox_call_view;
Stepan Salenikovich3034d922015-10-09 10:11:42 -040091 GtkWidget *frame_call;
92 GtkWidget *welcome_view;
Sébastien Blin55bff9d2017-10-03 15:15:23 -040093 GtkWidget *button_new_conversation;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040094 GtkWidget *account_settings_view;
Stepan Salenikovich0bd53492015-05-11 14:28:52 -040095 GtkWidget *media_settings_view;
Stepan Salenikovichde896112015-05-11 16:46:33 -040096 GtkWidget *general_settings_view;
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -040097 GtkWidget *last_settings_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040098 GtkWidget *radiobutton_general_settings;
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -040099 GtkWidget *radiobutton_media_settings;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400100 GtkWidget *radiobutton_account_settings;
aviau69081842016-10-14 14:51:54 -0400101 GtkWidget *account_creation_wizard;
102 GtkWidget *account_migration_view;
Nicolas Jager15a8b902017-03-21 07:53:06 -0400103 GtkWidget *combobox_account_selector;
Nicolas Jager0efc8432017-03-22 16:22:00 -0400104 GtkWidget *treeview_contact_requests;
105 GtkWidget *scrolled_window_contact_requests;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500106 GtkWidget *webkit_chat_container; ///< The webkit_chat_container is created once, then reused for all chat views
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400107
108 GSettings *settings;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400109
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500110 details::CppImpl* cpp; ///< Non-UI and C++ only code
Stepan Salenikovich434b88f2015-02-19 17:49:08 -0500111};
112
113G_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 Roguez1e50f0b2017-12-12 20:58:30 -0500117//==============================================================================
118
Guillaume Roguez1b69f092018-01-24 11:34:50 -0500119namespace { namespace details
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500120{
121
122static constexpr const char* CALL_VIEW_NAME = "calls";
123static constexpr const char* ACCOUNT_CREATION_WIZARD_VIEW_NAME = "account-creation-wizard";
124static constexpr const char* ACCOUNT_MIGRATION_VIEW_NAME = "account-migration-view";
125static constexpr const char* GENERAL_SETTINGS_VIEW_NAME = "general";
126static constexpr const char* MEDIA_SETTINGS_VIEW_NAME = "media";
127static constexpr const char* ACCOUNT_SETTINGS_VIEW_NAME = "accounts";
128
Guillaume Rogueza4911042017-12-14 16:11:18 -0500129inline 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 */
135static void
136print_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
161inline static void
162foreachEnabledLrcAccount(const lrc::api::Lrc& lrc,
163 const std::function<void(const lrc::api::account::Info&)>& func)
164{
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -0500165 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 Rogueza4911042017-12-14 16:11:18 -0500170 }
171}
172
173} // namespace helpers
174
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500175class CppImpl
176{
177public:
178 explicit CppImpl(RingMainWindow& widget);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500179 ~CppImpl();
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500180
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500181 void init();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500182 void updateLrc(const std::string& accountId);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500183 void changeView(GType type, lrc::api::conversation::Info conversation = {});
Guillaume Roguez1d963272017-12-12 23:32:13 -0500184 void enterFullScreen();
185 void leaveFullScreen();
186 void toggleFullScreen();
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500187 void resetToWelcome();
Guillaume Rogueza8804822018-01-22 15:03:51 -0500188 void refreshPendingContactRequestTab();
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500189 void changeAccountSelection(const std::string& id);
190 void onAccountSelectionChange(const std::string& id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500191 void enterAccountCreationWizard();
192 void leaveAccountCreationWizard();
193 void enterSettingsView();
194 void leaveSettingsView();
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500195
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -0500196 void showAccountSelectorWidget(bool show = true);
197 std::size_t refreshAccountSelectorWidget(int selection_row = -1, bool show = true);
198
199 WebKitChatContainer* webkitChatContainer() const;
200
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500201 RingMainWindow* self = nullptr; // The GTK widget itself
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500202 RingMainWindowPrivate* widgets = nullptr;
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500203
Guillaume Roguez6f431372017-12-12 21:15:39 -0500204 std::unique_ptr<lrc::api::Lrc> lrc_;
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500205 std::unique_ptr<AccountContainer> accountContainer_;
206 std::unique_ptr<lrc::api::conversation::Info> chatViewConversation_;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500207 lrc::api::profile::Type currentTypeFilter_;
208 bool show_settings = false;
209 bool is_fullscreen = false;
Nicolas Jager3807d982018-01-11 09:46:31 -0500210 bool has_cleared_all_history = false;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500211
Guillaume Rogueza8804822018-01-22 15:03:51 -0500212 int smartviewPageNum = 0;
213 int contactRequestsPageNum = 0;
214
Guillaume Roguez6f431372017-12-12 21:15:39 -0500215 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 Jagerbaf20c82018-01-16 15:08:14 -0500227 QMetaObject::Connection chatNotification_;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500228
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500229private:
Guillaume Roguez64236c22017-12-13 20:08:25 -0500230 CppImpl() = delete;
231 CppImpl(const CppImpl&) = delete;
232 CppImpl& operator=(const CppImpl&) = delete;
233
Guillaume Rogueza8804822018-01-22 15:03:51 -0500234 GtkWidget* displayWelcomeView(lrc::api::conversation::Info);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500235 GtkWidget* displayIncomingView(lrc::api::conversation::Info);
236 GtkWidget* displayCurrentCallView(lrc::api::conversation::Info);
237 GtkWidget* displayChatView(lrc::api::conversation::Info);
Nicolas Jagerbaf20c82018-01-16 15:08:14 -0500238 void chatNotifications();
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500239
Guillaume Roguez64236c22017-12-13 20:08:25 -0500240 // 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 Roguez1e50f0b2017-12-12 20:58:30 -0500252};
253
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500254inline namespace gtk_callbacks
255{
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500256
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400257static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500258on_save_accounts_timeout(GtkWidget* working_dialog)
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400259{
260 /* save changes to accounts */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400261 AccountModel::instance().save();
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400262
263 if (working_dialog)
264 gtk_widget_destroy(working_dialog);
265
266 return G_SOURCE_REMOVE;
267}
268
Stepan Salenikovich15142182015-03-11 17:15:26 -0400269static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500270on_video_double_clicked(RingMainWindow* self)
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400271{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500272 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 Salenikovich2d63d5e2015-03-22 23:23:54 -0400276
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500277static void
278on_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 Salenikovichbd4b3772015-12-13 23:28:06 -0500284
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500285static void
286on_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 Salenikovich2d63d5e2015-03-22 23:23:54 -0400292
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500293static void
294on_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 Salenikovich2d63d5e2015-03-22 23:23:54 -0400298
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500299 auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector);
300 auto model = gtk_combo_box_get_model(accountComboBox);
Stepan Salenikovich41118912015-05-01 11:25:46 -0400301
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500302 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 Rogueza04f4422017-12-14 13:52:34 -0500306 priv->cpp->onAccountSelectionChange(accountId);
Nicolas Jager3e4055b2018-01-10 13:48:41 -0500307 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(priv->notebook_contacts),
308 priv->cpp->accountContainer_->info.contactModel->hasPendingRequests());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500309 g_free(accountId);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400310 }
311}
312
313static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500314on_settings_clicked(RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400315{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500316 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
325static void
326on_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 Salenikovichf903d1b2015-03-25 14:51:45 -0400330
331 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400332 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -0400333 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), MEDIA_SETTINGS_VIEW_NAME);
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400334 priv->last_settings_view = priv->media_settings_view;
Stepan Salenikovich41118912015-05-01 11:25:46 -0400335 } else {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400336 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400337 }
338}
339
340static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500341on_show_account_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400342{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500343 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
344 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400345
346 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400347 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 Salenikovich2d63d5e2015-03-22 23:23:54 -0400349 }
350}
351
Stepan Salenikovichde896112015-05-11 16:46:33 -0400352static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500353on_show_general_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichde896112015-05-11 16:46:33 -0400354{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500355 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
356 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichde896112015-05-11 16:46:33 -0400357
358 if (gtk_toggle_button_get_active(navbutton)) {
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400359 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400360 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 Jager6f5e04a2016-05-18 15:04:59 -0400362 } else {
363 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400364 }
365}
366
Stepan Salenikovichb8e41272015-03-27 14:31:54 -0400367static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500368on_search_entry_text_changed(GtkSearchEntry* search_entry, RingMainWindow* self)
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400369{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500370 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
371 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400372
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400373 // Filter model
374 const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry));
Guillaume Roguez6f431372017-12-12 21:15:39 -0500375 priv->cpp->accountContainer_->info.conversationModel->setFilter(text);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400376}
377
378static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500379on_search_entry_activated(RingMainWindow* self)
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400380{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500381 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
382 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
383
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400384 // Select the first conversation of the list
Guillaume Roguez6f431372017-12-12 21:15:39 -0500385 auto& conversationModel = priv->cpp->accountContainer_->info.conversationModel;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400386 auto conversations = conversationModel->allFilteredConversations();
387 if (!conversations.empty())
388 conversationModel->selectConversation(conversations[0].uid);
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400389}
390
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400391static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500392on_search_entry_key_released(G_GNUC_UNUSED GtkEntry* search_entry, GdkEventKey* key, RingMainWindow* self)
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400393{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500394 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 Blin55bff9d2017-10-03 15:15:23 -0400396
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400397 // 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 Roguez6f431372017-12-12 21:15:39 -0500399 priv->cpp->accountContainer_->info.conversationModel->setFilter("");
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400400 return GDK_EVENT_STOP;
401 }
402
403 return GDK_EVENT_PROPAGATE;
404}
405
406static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500407on_dtmf_pressed(RingMainWindow* self, GdkEventKey* event, gpointer user_data)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400408{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500409 (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 Salenikovichb01d7362015-04-27 23:02:00 -0400414 g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400415 g_return_val_if_fail(priv, GDK_EVENT_PROPAGATE);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400416
417 /* we want to react to digit key presses, as long as a GtkEntry is not the
418 * input focus
419 */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500420 GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(self));
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400421 if (GTK_IS_ENTRY(focus))
422 return GDK_EVENT_PROPAGATE;
423
Guillaume Roguez6f431372017-12-12 21:15:39 -0500424 if (priv->cpp->accountContainer_ &&
425 priv->cpp->accountContainer_->info.profileInfo.type != lrc::api::profile::Type::SIP)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400426 return GDK_EVENT_PROPAGATE;
427
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400428 /* 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 Blin55bff9d2017-10-03 15:15:23 -0400432 & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ))
433 return GDK_EVENT_PROPAGATE;
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400434
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400435 // 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 Salenikovichb01d7362015-04-27 23:02:00 -0400448 guint32 unicode_val = gdk_keyval_to_unicode(event->keyval);
449 QString val = QString::fromUcs4(&unicode_val, 1);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400450 g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData());
Guillaume Roguez6f431372017-12-12 21:15:39 -0500451 priv->cpp->accountContainer_->info.callModel->playDTMF(current_item.callId, val.toStdString());
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400452 // always propogate the key, so we don't steal accelerators/shortcuts
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400453 return GDK_EVENT_PROPAGATE;
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400454}
455
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400456static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500457on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainWindow* self)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400458{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500459 (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 Roguez6f431372017-12-12 21:15:39 -0500465 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 Blin55bff9d2017-10-03 15:15:23 -0400469 }
Nicolas Jager0efc8432017-03-22 16:22:00 -0400470}
471
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400472static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500473on_window_size_changed(GtkWidget* self, GdkEventConfigure* event, gpointer user_data)
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400474{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500475 (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 Salenikovichba87ae22016-09-13 14:27:20 -0400479
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 Salenikovicheafc3dd2015-04-16 18:38:01 -0400486static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500487on_search_entry_places_call_changed(GSettings* settings, const gchar* key, RingMainWindow* self)
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400488{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500489 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
490 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400491
492 if (g_settings_get_boolean(settings, key)) {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500493 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 Salenikoviche9933242016-06-21 18:08:48 -0400496 } else {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500497 gtk_widget_set_tooltip_text(priv->button_new_conversation,
498 C_("button next to search entry will open chat", "open chat"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400499 }
500}
501
502static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500503on_handle_account_migrations(RingMainWindow* self)
aviau6aeb4852016-08-18 16:01:09 -0400504{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500505 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
506 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
aviau6aeb4852016-08-18 16:01:09 -0400507
508 /* If there is an existing migration view, remove it */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500509 if (priv->account_migration_view) {
Stepan Salenikovich56530b12016-10-20 17:51:34 -0400510 gtk_widget_destroy(priv->account_migration_view);
511 priv->account_migration_view = nullptr;
aviau6aeb4852016-08-18 16:01:09 -0400512 }
513
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500514 auto accounts = AccountModel::instance().accountsToMigrate();
515 if (!accounts.isEmpty()) {
516 auto* account = accounts.first();
aviau6aeb4852016-08-18 16:01:09 -0400517
aviau69081842016-10-14 14:51:54 -0400518 priv->account_migration_view = account_migration_view_new(account);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500519 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);
aviau6aeb4852016-08-18 16:01:09 -0400523
524 gtk_widget_hide(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500525 priv->cpp->showAccountSelectorWidget(false);
aviau69081842016-10-14 14:51:54 -0400526 gtk_widget_show(priv->account_migration_view);
aviau6aeb4852016-08-18 16:01:09 -0400527 gtk_stack_add_named(
528 GTK_STACK(priv->stack_main_view),
aviau69081842016-10-14 14:51:54 -0400529 priv->account_migration_view,
aviau6aeb4852016-08-18 16:01:09 -0400530 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 Roguezdbefafd2017-12-12 23:54:49 -0500536 } else {
aviau6aeb4852016-08-18 16:01:09 -0400537 gtk_widget_show(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500538 priv->cpp->showAccountSelectorWidget();
aviau6aeb4852016-08-18 16:01:09 -0400539 }
540}
541
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500542} // namespace gtk_callbacks
543
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500544CppImpl::CppImpl(RingMainWindow& widget)
545 : self {&widget}
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500546 , widgets {RING_MAIN_WINDOW_GET_PRIVATE(&widget)}
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500547 , lrc_ {std::make_unique<lrc::api::Lrc>()}
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500548{}
549
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500550void
Nicolas Jagerbaf20c82018-01-16 15:08:14 -0500551CppImpl::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 Jager3807d982018-01-11 09:46:31 -0500567static gboolean
568on_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
583static void
584on_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 Jagerbaf20c82018-01-16 15:08:14 -0500596void
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500597CppImpl::init()
598{
Guillaume Rogueza8804822018-01-22 15:03:51 -0500599 // 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 Roguez47cd8b52017-12-13 14:06:01 -0500606 // 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 Rogueza8804822018-01-22 15:03:51 -0500610 decltype(accountIds)::value_type activeAccountId; // non-empty if a enabled account is found below
611
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500612 if (not accountIds.empty()) {
Guillaume Rogueza8804822018-01-22 15:03:51 -0500613 for (const auto& id : accountIds) {
614 const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(id);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500615 if (accountInfo.enabled) {
Guillaume Rogueza8804822018-01-22 15:03:51 -0500616 activeAccountId = id;
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500617 break;
618 }
619 }
Guillaume Rogueza8804822018-01-22 15:03:51 -0500620 }
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 Roguez47cd8b52017-12-13 14:06:01 -0500630 }
631
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500632 accountStatusChangedConnection_ = QObject::connect(&lrc_->getAccountModel(),
633 &lrc::api::NewAccountModel::accountStatusChanged,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500634 [this](const std::string& id){ slotAccountStatusChanged(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500635 newAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500636 &lrc::api::NewAccountModel::accountAdded,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500637 [this](const std::string& id){ slotAccountAddedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500638 rmAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez64236c22017-12-13 20:08:25 -0500639 &lrc::api::NewAccountModel::accountRemoved,
640 [this](const std::string& id){ slotAccountRemovedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500641
642 /* bind to window size settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500643 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 Roguez47cd8b52017-12-13 14:06:01 -0500646 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 Roguez3ea37de2017-12-13 14:13:54 -0500650 on_search_entry_places_call_changed(widgets->settings, "search-entry-places-call", self);
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500651 g_signal_connect(widgets->settings, "changed::search-entry-places-call",
652 G_CALLBACK(on_search_entry_places_call_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500653
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500654 /* set window icon */
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500655 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 Roguez3ea37de2017-12-13 14:13:54 -0500670 gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_ring), image_ring);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500671
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 Roguez3ea37de2017-12-13 14:13:54 -0500675 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(widgets->ring_menu), menu);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500676 g_object_unref(builder);
677
678 /* settings icon */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500679 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
680 GTK_ICON_SIZE_SMALL_TOOLBAR);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500681
682 /* connect settings button signal */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500683 g_signal_connect_swapped(widgets->ring_settings, "clicked",
684 G_CALLBACK(on_settings_clicked), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500685
686 /* add the call view to the main stack */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500687 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500688 CALL_VIEW_NAME);
689
690 /* init the settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500691 widgets->account_settings_view = account_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500692 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->account_settings_view,
693 ACCOUNT_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500694
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500695 widgets->media_settings_view = media_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500696 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->media_settings_view,
697 MEDIA_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500698
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500699 widgets->general_settings_view = general_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500700 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view,
701 GENERAL_SETTINGS_VIEW_NAME);
Nicolas Jager3807d982018-01-11 09:46:31 -0500702 g_signal_connect_swapped(widgets->general_settings_view, "clear-all-history", G_CALLBACK(on_clear_all_history_clicked), self);
703
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500704
705 /* make the setting we will show first the active one */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500706 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE);
707 widgets->last_settings_view = widgets->general_settings_view;
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500708
709 /* connect the settings button signals to switch settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500710 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 Roguez3ea37de2017-12-13 14:13:54 -0500713 g_signal_connect(widgets->notebook_contacts, "switch-page", G_CALLBACK(on_tab_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500714
715 /* welcome/default view */
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500716 widgets->welcome_view = ring_welcome_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500717 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 Roguez47cd8b52017-12-13 14:06:01 -0500720
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500721 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 Roguez47cd8b52017-12-13 14:06:01 -0500725
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 Roguez3ea37de2017-12-13 14:13:54 -0500743 gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->search_entry),
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500744 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 Roguez47cd8b52017-12-13 14:06:01 -0500746
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 Roguez3ea37de2017-12-13 14:13:54 -0500752 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500753
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 Roguez1fa8eb22017-12-14 20:33:26 -0500761 refreshAccountSelectorWidget(0);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500762
763 /* layout */
764 auto *renderer = gtk_cell_renderer_text_new();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500765 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 Roguez47cd8b52017-12-13 14:06:01 -0500768 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 Roguez3ea37de2017-12-13 14:13:54 -0500773 g_signal_connect_swapped(widgets->combobox_account_selector, "changed", G_CALLBACK(on_account_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500774
775 // initialize the pending contact request icon.
Guillaume Rogueza8804822018-01-22 15:03:51 -0500776 refreshPendingContactRequestTab();
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500777
Guillaume Rogueza8804822018-01-22 15:03:51 -0500778 if (accountContainer_) {
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500779 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 Jagerbaf20c82018-01-16 15:08:14 -0500787
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 Roguez47cd8b52017-12-13 14:06:01 -0500800}
801
802CppImpl::~CppImpl()
803{
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500804 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 Jagerbaf20c82018-01-16 15:08:14 -0500817 QObject::disconnect(chatNotification_);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500818
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500819 g_clear_object(&widgets->welcome_view);
820 g_clear_object(&widgets->webkit_chat_container);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500821}
822
823void
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500824CppImpl::changeView(GType type, lrc::api::conversation::Info conversation)
825{
Guillaume Roguez1d963272017-12-12 23:32:13 -0500826 leaveFullScreen();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500827 gtk_container_remove(GTK_CONTAINER(widgets->frame_call),
828 gtk_bin_get_child(GTK_BIN(widgets->frame_call)));
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500829
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500830 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 Rogueza8804822018-01-22 15:03:51 -0500838 new_view = displayWelcomeView(conversation);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500839 }
840
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500841 gtk_container_add(GTK_CONTAINER(widgets->frame_call), new_view);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500842 gtk_widget_show(new_view);
843}
844
845GtkWidget*
Guillaume Rogueza8804822018-01-22 15:03:51 -0500846CppImpl::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
858GtkWidget*
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500859CppImpl::displayIncomingView(lrc::api::conversation::Info conversation)
860{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500861 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
862 return incoming_call_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500863}
864
865GtkWidget*
866CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation)
867{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500868 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
Guillaume Roguez11339f82017-12-12 23:15:34 -0500869 auto* new_view = current_call_view_new(webkitChatContainer(),
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500870 accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500871
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 Blin8ab4a812018-02-27 13:24:17 -0500876 auto isPending = contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING;
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500877 chat_view_update_temporary(CHAT_VIEW(chat_view),
Sébastien Blin8ab4a812018-02-27 13:24:17 -0500878 isPending || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY,
879 isPending);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500880 }
881 } catch(...) { }
882
Guillaume Roguez1d963272017-12-12 23:32:13 -0500883 g_signal_connect_swapped(new_view, "video-double-clicked",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500884 G_CALLBACK(on_video_double_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500885 return new_view;
886}
887
888GtkWidget*
889CppImpl::displayChatView(lrc::api::conversation::Info conversation)
890{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500891 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
892 auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500893 g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500894 return new_view;
895}
896
Guillaume Roguez11339f82017-12-12 23:15:34 -0500897WebKitChatContainer*
898CppImpl::webkitChatContainer() const
899{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500900 if (!widgets->webkit_chat_container) {
901 widgets->webkit_chat_container = webkit_chat_container_new();
Guillaume Roguez11339f82017-12-12 23:15:34 -0500902
903 // We don't want it to be deleted, ever.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500904 g_object_ref(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500905 }
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500906 return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500907}
908
Guillaume Roguez1d963272017-12-12 23:32:13 -0500909void
910CppImpl::enterFullScreen()
911{
912 if (!is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500913 gtk_widget_hide(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500914 gtk_window_fullscreen(GTK_WINDOW(self));
915 is_fullscreen = true;
916 }
917}
918
919void
920CppImpl::leaveFullScreen()
921{
922 if (is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500923 gtk_widget_show(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500924 gtk_window_unfullscreen(GTK_WINDOW(self));
925 is_fullscreen = false;
926 }
927}
928
929void
930CppImpl::toggleFullScreen()
931{
932 if (is_fullscreen)
933 leaveFullScreen();
934 else
935 enterFullScreen();
936}
937
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500938/// Clear selection and go to welcome page.
939void
940CppImpl::resetToWelcome()
941{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500942 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500943 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500944 auto selection_contact_request = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500945 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500946 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500947 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 Roguezdbefafd2017-12-12 23:54:49 -0500953void
Guillaume Rogueza8804822018-01-22 15:03:51 -0500954CppImpl::refreshPendingContactRequestTab()
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500955{
Nicolas Jagere9669d22018-01-12 10:58:55 -0500956 if (not accountContainer_)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500957 return;
958
Guillaume Rogueza8804822018-01-22 15:03:51 -0500959 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 Roguezdbefafd2017-12-12 23:54:49 -0500962
Guillaume Rogueza8804822018-01-22 15:03:51 -0500963 // 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 Roguezdbefafd2017-12-12 23:54:49 -0500969}
970
971void
972CppImpl::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 Roguez1fa8eb22017-12-14 20:33:26 -0500976 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.
985std::size_t
986CppImpl::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 Roguez5b137be2018-02-21 10:44:58 -05001005 GTK_TREE_MODEL(store)
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001006 );
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 Roguezdbefafd2017-12-12 23:54:49 -05001011}
1012
1013void
1014CppImpl::enterAccountCreationWizard()
1015{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001016 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 Roguezdbefafd2017-12-12 23:54:49 -05001021 G_CALLBACK(on_account_creation_completed), self);
1022
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001023 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view),
1024 widgets->account_creation_wizard,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001025 ACCOUNT_CREATION_WIZARD_VIEW_NAME);
1026 }
1027
1028 /* hide settings button until account creation is complete */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001029 gtk_widget_hide(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001030 showAccountSelectorWidget(false);
1031
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001032 gtk_widget_show(widgets->account_creation_wizard);
1033 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->account_creation_wizard);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001034}
1035
1036void
1037CppImpl::leaveAccountCreationWizard()
1038{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001039 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001040
1041 /* destroy the wizard */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001042 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 Roguezdbefafd2017-12-12 23:54:49 -05001046 }
1047
1048 /* show the settings button */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001049 gtk_widget_show(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001050
1051 /* show the account selector */
1052 showAccountSelectorWidget();
1053}
1054
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001055/// 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 Roguezdbefafd2017-12-12 23:54:49 -05001057void
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001058CppImpl::changeAccountSelection(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001059{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001060 // already selected?
1061 if (id == accountContainer_->info.id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001062 return;
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001063
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 Roguezdbefafd2017-12-12 23:54:49 -05001078 }
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001079}
1080
1081void
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001082CppImpl::onAccountSelectionChange(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001083{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001084 // Go to welcome view
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001085 changeView(RING_WELCOME_VIEW_TYPE);
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001086 // Show conversation panel
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001087 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001088 // Reinit LRC
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001089 updateLrc(id);
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001090 // Update the welcome view
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001091 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001092}
1093
1094void
1095CppImpl::enterSettingsView()
1096{
1097 /* show the settings */
1098 show_settings = true;
1099
1100 /* show settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001101 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-ok-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001102 GTK_ICON_SIZE_SMALL_TOOLBAR);
1103
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001104 gtk_widget_show(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001105
1106 /* make sure to start preview if we're showing the video settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001107 if (widgets->last_settings_view == widgets->media_settings_view)
1108 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), TRUE);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001109
1110 /* make sure to show the profile if we're showing the general settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001111 if (widgets->last_settings_view == widgets->general_settings_view)
1112 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001113 TRUE);
1114
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001115 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->last_settings_view);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001116}
1117
1118void
1119CppImpl::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 Roguez3ea37de2017-12-13 14:13:54 -05001136 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001137 GTK_ICON_SIZE_SMALL_TOOLBAR);
1138
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001139 gtk_widget_hide(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001140
1141 /* make sure video preview is stopped, in case it was started */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001142 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 Roguezdbefafd2017-12-12 23:54:49 -05001144 FALSE);
1145
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001146 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001147
Nicolas Jager3807d982018-01-11 09:46:31 -05001148 /* 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 Roguezdbefafd2017-12-12 23:54:49 -05001157}
1158
1159void
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001160CppImpl::updateLrc(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001161{
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 Roguez5121fd62017-12-13 18:51:52 -05001174 if (!id.empty())
1175 accountContainer_.reset(new AccountContainer(lrc_->getAccountModel().getAccountInfo(id)));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001176 else
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001177 accountContainer_.reset();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001178
1179 // Reinit tree views
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001180 if (widgets->treeview_conversations) {
1181 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001182 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001183 gtk_widget_destroy(widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001184 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001185 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001186 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001187
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001188 if (widgets->treeview_contact_requests) {
1189 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001190 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001191 gtk_widget_destroy(widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001192 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001193 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001194 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001195
1196 if (!accountContainer_) return;
1197
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001198 // Connect to signals from LRC
1199 historyClearedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001200 &lrc::api::ConversationModel::conversationCleared,
1201 [this] (const std::string& id) { slotConversationCleared(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001202
1203 modelSortedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001204 &lrc::api::ConversationModel::modelSorted,
1205 [this] { slotModelSorted(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001206
1207 filterChangedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001208 &lrc::api::ConversationModel::filterChanged,
1209 [this] { slotFilterChanged(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001210
1211 newConversationConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001212 &lrc::api::ConversationModel::newConversation,
1213 [this] (const std::string& id) { slotNewConversation(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001214
1215 conversationRemovedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001216 &lrc::api::ConversationModel::conversationRemoved,
1217 [this] (const std::string& id) { slotConversationRemoved(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001218
1219 showChatViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001220 &lrc::api::BehaviorController::showChatView,
1221 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowChatView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001222
1223 showCallViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001224 &lrc::api::BehaviorController::showCallView,
1225 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001226
1227 showIncomingViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001228 &lrc::api::BehaviorController::showIncomingCallView,
1229 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowIncomingCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001230
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001231 const gchar *text = gtk_entry_get_text(GTK_ENTRY(widgets->search_entry));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001232 currentTypeFilter_ = accountContainer_->info.profileInfo.type;
1233 accountContainer_->info.conversationModel->setFilter(text);
1234 accountContainer_->info.conversationModel->setFilter(currentTypeFilter_);
1235}
1236
Guillaume Roguez64236c22017-12-13 20:08:25 -05001237void
1238CppImpl::slotAccountAddedFromLrc(const std::string& id)
1239{
1240 (void)id;
Guillaume Roguez64236c22017-12-13 20:08:25 -05001241 auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001242 if (currentIdx == -1)
1243 currentIdx = 0; // If no account selected, select the first account
1244 refreshAccountSelectorWidget(currentIdx);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001245}
1246
1247void
1248CppImpl::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 Roguez1fa8eb22017-12-14 20:33:26 -05001258 // Update Account selector
1259 refreshAccountSelectorWidget(0);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001260 // 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
1268void
1269CppImpl::slotAccountStatusChanged(const std::string& id)
1270{
1271 if (not accountContainer_ ) {
1272 updateLrc(id);
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001273 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view),
1274 accountContainer_.get());
Guillaume Roguez64236c22017-12-13 20:08:25 -05001275 return;
1276 }
1277
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001278 auto selectionIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
Guillaume Roguez64236c22017-12-13 20:08:25 -05001279
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001280 // 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 Roguez64236c22017-12-13 20:08:25 -05001285
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001286 auto enabledAccounts = refreshAccountSelectorWidget(selectionIdx);
1287
Guillaume Roguez64236c22017-12-13 20:08:25 -05001288 // 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
1296void
1297CppImpl::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
1316void
1317CppImpl::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 Rogueza8804822018-01-22 15:03:51 -05001330 refreshPendingContactRequestTab();
Guillaume Roguez64236c22017-12-13 20:08:25 -05001331}
1332
1333void
1334CppImpl::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
1360void
1361CppImpl::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 Blin8ab4a812018-02-27 13:24:17 -05001374 auto isPending = contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING;
Guillaume Roguez64236c22017-12-13 20:08:25 -05001375 chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))),
Sébastien Blin8ab4a812018-02-27 13:24:17 -05001376 isPending || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY,
1377 isPending);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001378 } catch(...) { }
1379 }
1380}
1381
1382void
1383CppImpl::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
1398void
1399CppImpl::slotShowChatView(const std::string& id, lrc::api::conversation::Info origin)
1400{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001401 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001402 // 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 Blin8ab4a812018-02-27 13:24:17 -05001408 // 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 Roguez64236c22017-12-13 20:08:25 -05001413 if (current_item.uid != origin.uid) {
Guillaume Roguez64236c22017-12-13 20:08:25 -05001414 changeView(CHAT_VIEW_TYPE, origin);
Sébastien Blin8ab4a812018-02-27 13:24:17 -05001415 } 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 Roguez64236c22017-12-13 20:08:25 -05001420 }
1421}
1422
1423void
1424CppImpl::slotShowCallView(const std::string& id, lrc::api::conversation::Info origin)
1425{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001426 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001427 // 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
1438void
1439CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin)
1440{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001441 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001442 // 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 Roguez1b69f092018-01-24 11:34:50 -05001453}} // namespace <anonymous>::details
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001454
1455//==============================================================================
Guillaume Roguez0a411202017-05-25 15:27:26 -04001456
1457static void
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001458ring_main_window_init(RingMainWindow *win)
1459{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001460 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001461 gtk_widget_init_template(GTK_WIDGET(win));
1462
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001463 // CppImpl ctor
1464 priv->cpp = new details::CppImpl {*win};
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001465 priv->cpp->init();
Nicolas Jagercfeffc32018-01-12 10:58:55 -05001466
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001467}
1468
1469static void
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001470ring_main_window_dispose(GObject *object)
1471{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001472 auto* self = RING_MAIN_WINDOW(object);
1473 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001474
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001475 delete priv->cpp;
1476 priv->cpp = nullptr;
1477
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001478 G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object);
1479}
1480
1481static void
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001482ring_main_window_finalize(GObject *object)
1483{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001484 auto* self = RING_MAIN_WINDOW(object);
1485 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichba87ae22016-09-13 14:27:20 -04001486
1487 g_clear_object(&priv->settings);
1488
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001489 G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001490}
1491
1492static void
1493ring_main_window_class_init(RingMainWindowClass *klass)
1494{
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001495 G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize;
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001496 G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001497
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001498 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
1499 "/cx/ring/RingGnome/ringmainwindow.ui");
1500
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001501 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane);
Sébastien Blin55bff9d2017-10-03 15:15:23 -04001502 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, notebook_contacts);
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -04001503 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001504 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 Salenikovich2d63d5e2015-03-22 23:23:54 -04001508 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, hbox_settings);
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -05001509 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, search_entry);
Stepan Salenikovich69771842015-02-24 18:11:45 -05001510 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, stack_main_view);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001511 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_call_view);
Stepan Salenikovich3034d922015-10-09 10:11:42 -04001512 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, frame_call);
Stepan Salenikoviche9933242016-06-21 18:08:48 -04001513 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, button_new_conversation );
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001514 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_general_settings);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -04001515 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001516 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings);
Nicolas Jager15a8b902017-03-21 07:53:06 -04001517 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, combobox_account_selector);
Nicolas Jager0efc8432017-03-22 16:22:00 -04001518 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contact_requests);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001519}
1520
1521GtkWidget *
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001522ring_main_window_new(GtkApplication *app)
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001523{
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001524 gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL);
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001525 return (GtkWidget *)win;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001526}