blob: 2c580727555c1b359476556aa738b4eef1b7e390 [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))) {
876 chat_view_update_temporary(CHAT_VIEW(chat_view),
877 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
878 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
879 }
880 } catch(...) { }
881
Guillaume Roguez1d963272017-12-12 23:32:13 -0500882 g_signal_connect_swapped(new_view, "video-double-clicked",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500883 G_CALLBACK(on_video_double_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500884 return new_view;
885}
886
887GtkWidget*
888CppImpl::displayChatView(lrc::api::conversation::Info conversation)
889{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500890 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
891 auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500892 g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500893 return new_view;
894}
895
Guillaume Roguez11339f82017-12-12 23:15:34 -0500896WebKitChatContainer*
897CppImpl::webkitChatContainer() const
898{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500899 if (!widgets->webkit_chat_container) {
900 widgets->webkit_chat_container = webkit_chat_container_new();
Guillaume Roguez11339f82017-12-12 23:15:34 -0500901
902 // We don't want it to be deleted, ever.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500903 g_object_ref(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500904 }
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500905 return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500906}
907
Guillaume Roguez1d963272017-12-12 23:32:13 -0500908void
909CppImpl::enterFullScreen()
910{
911 if (!is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500912 gtk_widget_hide(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500913 gtk_window_fullscreen(GTK_WINDOW(self));
914 is_fullscreen = true;
915 }
916}
917
918void
919CppImpl::leaveFullScreen()
920{
921 if (is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500922 gtk_widget_show(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500923 gtk_window_unfullscreen(GTK_WINDOW(self));
924 is_fullscreen = false;
925 }
926}
927
928void
929CppImpl::toggleFullScreen()
930{
931 if (is_fullscreen)
932 leaveFullScreen();
933 else
934 enterFullScreen();
935}
936
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500937/// Clear selection and go to welcome page.
938void
939CppImpl::resetToWelcome()
940{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500941 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500942 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500943 auto selection_contact_request = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500944 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500945 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500946 lrc::api::conversation::Info current_item;
947 if (IS_CHAT_VIEW(old_view))
948 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
949 changeView(RING_WELCOME_VIEW_TYPE, current_item);
950}
951
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500952void
Guillaume Rogueza8804822018-01-22 15:03:51 -0500953CppImpl::refreshPendingContactRequestTab()
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500954{
Nicolas Jagere9669d22018-01-12 10:58:55 -0500955 if (not accountContainer_)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500956 return;
957
Guillaume Rogueza8804822018-01-22 15:03:51 -0500958 auto hasPendingRequests = accountContainer_->info.contactModel->hasPendingRequests();
959 gtk_widget_set_visible(widgets->scrolled_window_contact_requests, hasPendingRequests);
960 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widgets->notebook_contacts), hasPendingRequests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500961
Guillaume Rogueza8804822018-01-22 15:03:51 -0500962 // show conversation page if PendingRequests list is empty
963 if (not hasPendingRequests) {
964 auto current_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->notebook_contacts));
965 if (current_page == contactRequestsPageNum)
966 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), smartviewPageNum);
967 }
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500968}
969
970void
971CppImpl::showAccountSelectorWidget(bool show)
972{
973 // we only want to show the account selector when there is more than 1 enabled
974 // account; so every time we want to show it, we should preform this check
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -0500975 std::size_t enabled_accounts = 0;
976 foreachEnabledLrcAccount(*lrc_, [&] (const auto&) { ++enabled_accounts; });
977 gtk_widget_set_visible(widgets->combobox_account_selector, show && enabled_accounts > 1);
978}
979
980/// Update the account GtkComboBox from LRC data and select the given entry.
981/// The widget visibility is changed depending on number of account found.
982/// /note Default selection_row is -1, meaning no selection.
983/// /note Default visibility mode is true, meaning showing the widget.
984std::size_t
985CppImpl::refreshAccountSelectorWidget(int selection_row, bool show)
986{
987 auto store = gtk_list_store_new(2 /* # of cols */ ,
988 G_TYPE_STRING,
989 G_TYPE_STRING,
990 G_TYPE_UINT);
991 GtkTreeIter iter;
992 std::size_t enabled_accounts = 0;
993 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
994 ++enabled_accounts;
995 gtk_list_store_append(store, &iter);
996 gtk_list_store_set(store, &iter,
997 0 /* col # */ , acc_info.id.c_str() /* celldata */,
998 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
999 -1 /* end */);
1000 });
1001
1002 gtk_combo_box_set_model(
1003 GTK_COMBO_BOX(widgets->combobox_account_selector),
Guillaume Roguez5b137be2018-02-21 10:44:58 -05001004 GTK_TREE_MODEL(store)
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001005 );
1006 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), selection_row);
1007 gtk_widget_set_visible(widgets->combobox_account_selector, show && enabled_accounts > 1);
1008
1009 return enabled_accounts;
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001010}
1011
1012void
1013CppImpl::enterAccountCreationWizard()
1014{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001015 if (!widgets->account_creation_wizard) {
1016 widgets->account_creation_wizard = account_creation_wizard_new(false);
1017 g_object_add_weak_pointer(G_OBJECT(widgets->account_creation_wizard),
1018 reinterpret_cast<gpointer*>(&widgets->account_creation_wizard));
1019 g_signal_connect_swapped(widgets->account_creation_wizard, "account-creation-completed",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001020 G_CALLBACK(on_account_creation_completed), self);
1021
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001022 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view),
1023 widgets->account_creation_wizard,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001024 ACCOUNT_CREATION_WIZARD_VIEW_NAME);
1025 }
1026
1027 /* hide settings button until account creation is complete */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001028 gtk_widget_hide(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001029 showAccountSelectorWidget(false);
1030
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001031 gtk_widget_show(widgets->account_creation_wizard);
1032 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->account_creation_wizard);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001033}
1034
1035void
1036CppImpl::leaveAccountCreationWizard()
1037{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001038 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001039
1040 /* destroy the wizard */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001041 if (widgets->account_creation_wizard) {
1042 gtk_container_remove(GTK_CONTAINER(widgets->stack_main_view), widgets->account_creation_wizard);
1043 gtk_widget_destroy(widgets->account_creation_wizard);
1044 widgets->account_creation_wizard = nullptr;
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001045 }
1046
1047 /* show the settings button */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001048 gtk_widget_show(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001049
1050 /* show the account selector */
1051 showAccountSelectorWidget();
1052}
1053
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001054/// Change the selection of the account ComboBox by account Id.
1055/// Find in displayed accounts with one corresponding to the given id, then select it
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001056void
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001057CppImpl::changeAccountSelection(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001058{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001059 // already selected?
1060 if (id == accountContainer_->info.id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001061 return;
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001062
1063 if (auto* model = gtk_combo_box_get_model(GTK_COMBO_BOX(widgets->combobox_account_selector))) {
1064 GtkTreeIter iter;
1065 auto valid = gtk_tree_model_get_iter_first(model, &iter);
1066 while (valid) {
1067 const gchar* account_id;
1068 gtk_tree_model_get(model, &iter, 0 /* col# */, &account_id /* data */, -1);
1069 if (id == account_id) {
1070 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->combobox_account_selector), &iter);
1071 return;
1072 }
1073 valid = gtk_tree_model_iter_next(model, &iter);
1074 }
1075
1076 g_debug("BUGS: account not listed: %s", id.c_str());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001077 }
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001078}
1079
1080void
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001081CppImpl::onAccountSelectionChange(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001082{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001083 // Go to welcome view
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001084 changeView(RING_WELCOME_VIEW_TYPE);
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001085 // Show conversation panel
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001086 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001087 // Reinit LRC
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001088 updateLrc(id);
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001089 // Update the welcome view
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001090 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001091}
1092
1093void
1094CppImpl::enterSettingsView()
1095{
1096 /* show the settings */
1097 show_settings = true;
1098
1099 /* show settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001100 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-ok-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001101 GTK_ICON_SIZE_SMALL_TOOLBAR);
1102
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001103 gtk_widget_show(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001104
1105 /* make sure to start preview if we're showing the video settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001106 if (widgets->last_settings_view == widgets->media_settings_view)
1107 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), TRUE);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001108
1109 /* make sure to show the profile if we're showing the general settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001110 if (widgets->last_settings_view == widgets->general_settings_view)
1111 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001112 TRUE);
1113
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001114 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->last_settings_view);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001115}
1116
1117void
1118CppImpl::leaveSettingsView()
1119{
1120 /* hide the settings */
1121 show_settings = false;
1122
1123 /* show working dialog in case save operation takes time */
1124 auto working = ring_dialog_working(GTK_WIDGET(self), nullptr);
1125 gtk_window_present(GTK_WINDOW(working));
1126
1127 /* now save after the time it takes to transition back to the call view (400ms)
1128 * the save doesn't happen before the "working" dialog is presented
1129 * the timeout function should destroy the "working" dialog when done saving
1130 */
1131 g_timeout_add_full(G_PRIORITY_DEFAULT, 400, GSourceFunc(on_save_accounts_timeout), working,
1132 nullptr);
1133
1134 /* show calls */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001135 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001136 GTK_ICON_SIZE_SMALL_TOOLBAR);
1137
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001138 gtk_widget_hide(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001139
1140 /* make sure video preview is stopped, in case it was started */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001141 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), FALSE);
1142 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001143 FALSE);
1144
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001145 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001146
Nicolas Jager3807d982018-01-11 09:46:31 -05001147 /* return to the welcome view if has_cleared_all_history. The reason is you can have been in a chatview before you
1148 * opened the settings view and did a clear all history. So without the code below, you'll see the chatview with
1149 * obsolete messages. It will also ensure to refresh last interaction printed in the conversations list.
1150 */
1151 if (has_cleared_all_history) {
1152 onAccountSelectionChange(accountContainer_->info.id);
1153 resetToWelcome();
1154 has_cleared_all_history = false;
1155 }
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001156}
1157
1158void
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001159CppImpl::updateLrc(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001160{
1161 // Disconnect old signals.
1162 QObject::disconnect(showChatViewConnection_);
1163 QObject::disconnect(showIncomingViewConnection_);
1164 QObject::disconnect(changeAccountConnection_);
1165 QObject::disconnect(showCallViewConnection_);
1166 QObject::disconnect(modelSortedConnection_);
1167 QObject::disconnect(historyClearedConnection_);
1168 QObject::disconnect(filterChangedConnection_);
1169 QObject::disconnect(newConversationConnection_);
1170 QObject::disconnect(conversationRemovedConnection_);
1171
1172 // Get the account selected
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001173 if (!id.empty())
1174 accountContainer_.reset(new AccountContainer(lrc_->getAccountModel().getAccountInfo(id)));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001175 else
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001176 accountContainer_.reset();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001177
1178 // Reinit tree views
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001179 if (widgets->treeview_conversations) {
1180 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001181 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001182 gtk_widget_destroy(widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001183 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001184 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001185 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001186
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001187 if (widgets->treeview_contact_requests) {
1188 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001189 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001190 gtk_widget_destroy(widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001191 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001192 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001193 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001194
1195 if (!accountContainer_) return;
1196
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001197 // Connect to signals from LRC
1198 historyClearedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001199 &lrc::api::ConversationModel::conversationCleared,
1200 [this] (const std::string& id) { slotConversationCleared(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001201
1202 modelSortedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001203 &lrc::api::ConversationModel::modelSorted,
1204 [this] { slotModelSorted(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001205
1206 filterChangedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001207 &lrc::api::ConversationModel::filterChanged,
1208 [this] { slotFilterChanged(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001209
1210 newConversationConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001211 &lrc::api::ConversationModel::newConversation,
1212 [this] (const std::string& id) { slotNewConversation(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001213
1214 conversationRemovedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001215 &lrc::api::ConversationModel::conversationRemoved,
1216 [this] (const std::string& id) { slotConversationRemoved(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001217
1218 showChatViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001219 &lrc::api::BehaviorController::showChatView,
1220 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowChatView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001221
1222 showCallViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001223 &lrc::api::BehaviorController::showCallView,
1224 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001225
1226 showIncomingViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001227 &lrc::api::BehaviorController::showIncomingCallView,
1228 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowIncomingCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001229
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001230 const gchar *text = gtk_entry_get_text(GTK_ENTRY(widgets->search_entry));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001231 currentTypeFilter_ = accountContainer_->info.profileInfo.type;
1232 accountContainer_->info.conversationModel->setFilter(text);
1233 accountContainer_->info.conversationModel->setFilter(currentTypeFilter_);
1234}
1235
Guillaume Roguez64236c22017-12-13 20:08:25 -05001236void
1237CppImpl::slotAccountAddedFromLrc(const std::string& id)
1238{
1239 (void)id;
Guillaume Roguez64236c22017-12-13 20:08:25 -05001240 auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001241 if (currentIdx == -1)
1242 currentIdx = 0; // If no account selected, select the first account
1243 refreshAccountSelectorWidget(currentIdx);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001244}
1245
1246void
1247CppImpl::slotAccountRemovedFromLrc(const std::string& id)
1248{
1249 (void)id;
1250
1251 auto accounts = lrc_->getAccountModel().getAccountList();
1252 if (accounts.empty()) {
1253 enterAccountCreationWizard();
1254 return;
1255 }
1256
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001257 // Update Account selector
1258 refreshAccountSelectorWidget(0);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001259 // Show conversation panel
1260 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
1261 // Reinit LRC
1262 updateLrc(std::string(accounts.at(0)));
1263 // Update the welcome view
1264 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
1265}
1266
1267void
1268CppImpl::slotAccountStatusChanged(const std::string& id)
1269{
1270 if (not accountContainer_ ) {
1271 updateLrc(id);
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001272 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view),
1273 accountContainer_.get());
Guillaume Roguez64236c22017-12-13 20:08:25 -05001274 return;
1275 }
1276
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001277 auto selectionIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
Guillaume Roguez64236c22017-12-13 20:08:25 -05001278
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001279 // keep current selected account only if account status is enabled
1280 try {
1281 if (!lrc_->getAccountModel().getAccountInfo(id).enabled)
1282 selectionIdx = 0;
1283 } catch (...) {}
Guillaume Roguez64236c22017-12-13 20:08:25 -05001284
Guillaume Roguez1fa8eb22017-12-14 20:33:26 -05001285 auto enabledAccounts = refreshAccountSelectorWidget(selectionIdx);
1286
Guillaume Roguez64236c22017-12-13 20:08:25 -05001287 // if no account. reset the view.
1288 if (enabledAccounts == 0) {
1289 updateLrc("");
1290 changeView(RING_WELCOME_VIEW_TYPE);
1291 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), nullptr);
1292 }
1293}
1294
1295void
1296CppImpl::slotConversationCleared(const std::string& uid)
1297{
1298 // Change the view when the history is cleared.
1299 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1300 lrc::api::conversation::Info current_item;
1301 current_item.uid = "-1"; // Because the Searching item has an empty uid
1302 if (IS_CHAT_VIEW(old_view))
1303 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1304 else
1305 // if incoming or call view we don't want to change the view
1306 return;
1307 if (current_item.uid == uid) {
1308 // We are on the conversation cleared.
1309 // Go to welcome view because user doesn't want this conversation
1310 // TODO go to first conversation?
1311 resetToWelcome();
1312 }
1313}
1314
1315void
1316CppImpl::slotModelSorted()
1317{
1318 // Synchronize selection when sorted and update pending icon
1319 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1320 lrc::api::conversation::Info current_item;
1321 current_item.uid = "-1";
1322 if (IS_CHAT_VIEW(old_view))
1323 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1324 else if (IS_CURRENT_CALL_VIEW(old_view))
1325 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1326 else if (IS_INCOMING_CALL_VIEW(old_view))
1327 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1328 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
Guillaume Rogueza8804822018-01-22 15:03:51 -05001329 refreshPendingContactRequestTab();
Guillaume Roguez64236c22017-12-13 20:08:25 -05001330}
1331
1332void
1333CppImpl::slotFilterChanged()
1334{
1335 // Synchronize selection when filter changes
1336 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1337 lrc::api::conversation::Info current_item;
1338 current_item.uid = "-1";
1339 if (IS_CHAT_VIEW(old_view))
1340 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1341 else if (IS_CURRENT_CALL_VIEW(old_view))
1342 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1343 else if (IS_INCOMING_CALL_VIEW(old_view))
1344 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1345 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
1346 // Get if conversation still exists.
1347 auto& conversationModel = accountContainer_->info.conversationModel;
1348 auto conversations = conversationModel->allFilteredConversations();
1349 auto isInConv = std::find_if(
1350 conversations.begin(), conversations.end(),
1351 [current_item](const lrc::api::conversation::Info& conversation) {
1352 return current_item.uid == conversation.uid;
1353 });
1354 if (IS_CHAT_VIEW(old_view) && isInConv == conversations.end()) {
1355 changeView(RING_WELCOME_VIEW_TYPE);
1356 }
1357}
1358
1359void
1360CppImpl::slotNewConversation(const std::string& uid)
1361{
1362 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
1363 accountContainer_->info.conversationModel->setFilter(lrc::api::profile::Type::RING);
1364 gtk_entry_set_text(GTK_ENTRY(widgets->search_entry), "");
1365 accountContainer_->info.conversationModel->setFilter("");
1366 // Select new conversation if contact added
1367 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1368 if (IS_RING_WELCOME_VIEW(old_view) || (IS_CHAT_VIEW(old_view) && chat_view_get_temporary(CHAT_VIEW(old_view)))) {
1369 accountContainer_->info.conversationModel->selectConversation(uid);
1370 try {
1371 auto contactUri = chatViewConversation_->participants.front();
1372 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
1373 chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))),
1374 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
1375 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
1376 } catch(...) { }
1377 }
1378}
1379
1380void
1381CppImpl::slotConversationRemoved(const std::string& uid)
1382{
1383 // If contact is removed, go to welcome view
1384 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1385 lrc::api::conversation::Info current_item;
1386 if (IS_CHAT_VIEW(old_view))
1387 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1388 else if (IS_CURRENT_CALL_VIEW(old_view))
1389 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1390 else if (IS_INCOMING_CALL_VIEW(old_view))
1391 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1392 if (current_item.uid == uid)
1393 changeView(RING_WELCOME_VIEW_TYPE);
1394}
1395
1396void
1397CppImpl::slotShowChatView(const std::string& id, lrc::api::conversation::Info origin)
1398{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001399 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001400 // Show chat view if not in call (unless if it's the same conversation)
1401 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1402 lrc::api::conversation::Info current_item;
1403 current_item.uid = "-1";
1404 if (IS_CHAT_VIEW(old_view))
1405 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1406 if (current_item.uid != origin.uid) {
1407 if (origin.participants.empty()) return;
1408 auto firstContactUri = origin.participants.front();
1409 auto contactInfo = accountContainer_->info.contactModel->getContact(firstContactUri);
1410 if (contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING && current_item.uid != "-1") return;
1411 changeView(CHAT_VIEW_TYPE, origin);
1412 }
1413}
1414
1415void
1416CppImpl::slotShowCallView(const std::string& id, lrc::api::conversation::Info origin)
1417{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001418 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001419 // Change the view if we want a different view.
1420 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1421
1422 lrc::api::conversation::Info current_item;
1423 if (IS_CURRENT_CALL_VIEW(old_view))
1424 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1425
1426 if (current_item.uid != origin.uid)
1427 changeView(CURRENT_CALL_VIEW_TYPE, origin);
1428}
1429
1430void
1431CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin)
1432{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001433 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001434 // Change the view if we want a different view.
1435 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1436
1437 lrc::api::conversation::Info current_item;
1438 if (IS_INCOMING_CALL_VIEW(old_view))
1439 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1440
1441 if (current_item.uid != origin.uid)
1442 changeView(INCOMING_CALL_VIEW_TYPE, origin);
1443}
1444
Guillaume Roguez1b69f092018-01-24 11:34:50 -05001445}} // namespace <anonymous>::details
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001446
1447//==============================================================================
Guillaume Roguez0a411202017-05-25 15:27:26 -04001448
1449static void
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001450ring_main_window_init(RingMainWindow *win)
1451{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001452 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001453 gtk_widget_init_template(GTK_WIDGET(win));
1454
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001455 // CppImpl ctor
1456 priv->cpp = new details::CppImpl {*win};
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001457 priv->cpp->init();
Nicolas Jagercfeffc32018-01-12 10:58:55 -05001458
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001459}
1460
1461static void
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001462ring_main_window_dispose(GObject *object)
1463{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001464 auto* self = RING_MAIN_WINDOW(object);
1465 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001466
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001467 delete priv->cpp;
1468 priv->cpp = nullptr;
1469
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001470 G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object);
1471}
1472
1473static void
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001474ring_main_window_finalize(GObject *object)
1475{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001476 auto* self = RING_MAIN_WINDOW(object);
1477 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichba87ae22016-09-13 14:27:20 -04001478
1479 g_clear_object(&priv->settings);
1480
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001481 G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001482}
1483
1484static void
1485ring_main_window_class_init(RingMainWindowClass *klass)
1486{
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001487 G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize;
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001488 G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001489
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001490 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
1491 "/cx/ring/RingGnome/ringmainwindow.ui");
1492
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001493 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane);
Sébastien Blin55bff9d2017-10-03 15:15:23 -04001494 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, notebook_contacts);
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -04001495 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001496 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu);
1497 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring);
1498 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings);
1499 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001500 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, hbox_settings);
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -05001501 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, search_entry);
Stepan Salenikovich69771842015-02-24 18:11:45 -05001502 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, stack_main_view);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001503 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_call_view);
Stepan Salenikovich3034d922015-10-09 10:11:42 -04001504 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, frame_call);
Stepan Salenikoviche9933242016-06-21 18:08:48 -04001505 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, button_new_conversation );
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001506 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_general_settings);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -04001507 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001508 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings);
Nicolas Jager15a8b902017-03-21 07:53:06 -04001509 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, combobox_account_selector);
Nicolas Jager0efc8432017-03-22 16:22:00 -04001510 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contact_requests);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001511}
1512
1513GtkWidget *
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001514ring_main_window_new(GtkApplication *app)
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001515{
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001516 gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL);
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001517 return (GtkWidget *)win;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001518}