blob: e831d1b318054f6b7fe4a70140e27a3b75febbce [file] [log] [blame]
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001/*
Guillaume Roguez2a6150d2017-07-19 18:24:47 -04002 * Copyright (C) 2015-2017 Savoir-faire Linux Inc.
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05003 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Guillaume Roguez6d4734e2017-05-26 16:44:45 -04004 * Author: Guillaume Roguew <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
62namespace details
63{
64class CppImpl;
65}
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
119inline namespace details
120{
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{
165 auto& acc_model = lrc.getAccountModel();
166 for (const auto& id : acc_model.getAccountList()) {
167 const auto& accountInfo = acc_model.getAccountInfo(id);
168 if (accountInfo.enabled)
169 func(accountInfo);
170 }
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 Roguez11339f82017-12-12 23:15:34 -0500184 WebKitChatContainer* webkitChatContainer() const;
Guillaume Roguez1d963272017-12-12 23:32:13 -0500185 void enterFullScreen();
186 void leaveFullScreen();
187 void toggleFullScreen();
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500188 void resetToWelcome();
Nicolas Jager3e4055b2018-01-10 13:48:41 -0500189 void setPendingContactRequestTabIcon(RingMainWindow *win);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500190 void showAccountSelectorWidget(bool show = true);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500191 void changeAccountSelection(const std::string& id);
192 void onAccountSelectionChange(const std::string& id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500193 void enterAccountCreationWizard();
194 void leaveAccountCreationWizard();
195 void enterSettingsView();
196 void leaveSettingsView();
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500197
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500198 RingMainWindow* self = nullptr; // The GTK widget itself
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500199 RingMainWindowPrivate* widgets = nullptr;
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500200
Guillaume Roguez6f431372017-12-12 21:15:39 -0500201 std::unique_ptr<lrc::api::Lrc> lrc_;
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500202 std::unique_ptr<AccountContainer> accountContainer_;
203 std::unique_ptr<lrc::api::conversation::Info> chatViewConversation_;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500204 lrc::api::profile::Type currentTypeFilter_;
205 bool show_settings = false;
206 bool is_fullscreen = false;
207
Guillaume Roguez6f431372017-12-12 21:15:39 -0500208 QMetaObject::Connection showChatViewConnection_;
209 QMetaObject::Connection showCallViewConnection_;
210 QMetaObject::Connection showIncomingViewConnection_;
211 QMetaObject::Connection changeAccountConnection_;
212 QMetaObject::Connection newAccountConnection_;
213 QMetaObject::Connection rmAccountConnection_;
214 QMetaObject::Connection historyClearedConnection_;
215 QMetaObject::Connection modelSortedConnection_;
216 QMetaObject::Connection filterChangedConnection_;
217 QMetaObject::Connection newConversationConnection_;
218 QMetaObject::Connection conversationRemovedConnection_;
219 QMetaObject::Connection accountStatusChangedConnection_;
Nicolas Jagercfeffc32018-01-12 10:58:55 -0500220 QMetaObject::Connection chat_notification_;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500221
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500222private:
Guillaume Roguez64236c22017-12-13 20:08:25 -0500223 CppImpl() = delete;
224 CppImpl(const CppImpl&) = delete;
225 CppImpl& operator=(const CppImpl&) = delete;
226
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500227 GtkWidget* displayIncomingView(lrc::api::conversation::Info);
228 GtkWidget* displayCurrentCallView(lrc::api::conversation::Info);
229 GtkWidget* displayChatView(lrc::api::conversation::Info);
230
Guillaume Roguez64236c22017-12-13 20:08:25 -0500231 // Callbacks used as LRC Qt slot
232 void slotAccountAddedFromLrc(const std::string& id);
233 void slotAccountRemovedFromLrc(const std::string& id);
234 void slotAccountStatusChanged(const std::string& id);
235 void slotConversationCleared(const std::string& uid);
236 void slotModelSorted();
237 void slotFilterChanged();
238 void slotNewConversation(const std::string& uid);
239 void slotConversationRemoved(const std::string& uid);
240 void slotShowChatView(const std::string& id, lrc::api::conversation::Info origin);
241 void slotShowCallView(const std::string& id, lrc::api::conversation::Info origin);
242 void slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin);
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500243};
244
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500245inline namespace gtk_callbacks
246{
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500247
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400248static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500249on_save_accounts_timeout(GtkWidget* working_dialog)
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400250{
251 /* save changes to accounts */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400252 AccountModel::instance().save();
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400253
254 if (working_dialog)
255 gtk_widget_destroy(working_dialog);
256
257 return G_SOURCE_REMOVE;
258}
259
Stepan Salenikovich15142182015-03-11 17:15:26 -0400260static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500261on_video_double_clicked(RingMainWindow* self)
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400262{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500263 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
264 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
265 priv->cpp->toggleFullScreen();
266}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400267
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500268static void
269on_hide_view_clicked(RingMainWindow* self)
270{
271 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
272 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
273 priv->cpp->resetToWelcome();
274}
Stepan Salenikovichbd4b3772015-12-13 23:28:06 -0500275
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500276static void
277on_account_creation_completed(RingMainWindow* self)
278{
279 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
280 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
281 priv->cpp->leaveAccountCreationWizard();
282}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400283
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500284static void
285on_account_changed(RingMainWindow* self)
286{
287 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
288 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400289
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500290 auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector);
291 auto model = gtk_combo_box_get_model(accountComboBox);
Stepan Salenikovich41118912015-05-01 11:25:46 -0400292
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500293 GtkTreeIter iter;
294 if (gtk_combo_box_get_active_iter(accountComboBox, &iter)) {
295 gchar* accountId;
296 gtk_tree_model_get(model, &iter, 0 /* col# */, &accountId /* data */, -1);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500297 priv->cpp->onAccountSelectionChange(accountId);
Nicolas Jager3e4055b2018-01-10 13:48:41 -0500298 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(priv->notebook_contacts),
299 priv->cpp->accountContainer_->info.contactModel->hasPendingRequests());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500300 g_free(accountId);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400301 }
302}
303
304static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500305on_settings_clicked(RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400306{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500307 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
308 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
309
310 if (!priv->cpp->show_settings)
311 priv->cpp->enterSettingsView();
312 else
313 priv->cpp->leaveSettingsView();
314}
315
316static void
317on_show_media_settings(GtkToggleButton* navbutton, RingMainWindow* self)
318{
319 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
320 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400321
322 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400323 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -0400324 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), MEDIA_SETTINGS_VIEW_NAME);
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400325 priv->last_settings_view = priv->media_settings_view;
Stepan Salenikovich41118912015-05-01 11:25:46 -0400326 } else {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400327 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400328 }
329}
330
331static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500332on_show_account_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400333{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500334 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
335 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400336
337 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400338 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), ACCOUNT_SETTINGS_VIEW_NAME);
339 priv->last_settings_view = priv->account_settings_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400340 }
341}
342
Stepan Salenikovichde896112015-05-11 16:46:33 -0400343static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500344on_show_general_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichde896112015-05-11 16:46:33 -0400345{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500346 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
347 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichde896112015-05-11 16:46:33 -0400348
349 if (gtk_toggle_button_get_active(navbutton)) {
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400350 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400351 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME);
352 priv->last_settings_view = priv->general_settings_view;
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400353 } else {
354 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400355 }
356}
357
Stepan Salenikovichb8e41272015-03-27 14:31:54 -0400358static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500359on_search_entry_text_changed(GtkSearchEntry* search_entry, RingMainWindow* self)
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400360{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500361 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
362 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400363
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400364 // Filter model
365 const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry));
Guillaume Roguez6f431372017-12-12 21:15:39 -0500366 priv->cpp->accountContainer_->info.conversationModel->setFilter(text);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400367}
368
369static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500370on_search_entry_activated(RingMainWindow* self)
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400371{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500372 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
373 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
374
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400375 // Select the first conversation of the list
Guillaume Roguez6f431372017-12-12 21:15:39 -0500376 auto& conversationModel = priv->cpp->accountContainer_->info.conversationModel;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400377 auto conversations = conversationModel->allFilteredConversations();
378 if (!conversations.empty())
379 conversationModel->selectConversation(conversations[0].uid);
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400380}
381
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400382static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500383on_search_entry_key_released(G_GNUC_UNUSED GtkEntry* search_entry, GdkEventKey* key, RingMainWindow* self)
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400384{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500385 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
386 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400387
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400388 // if esc key pressed, clear the regex (keep the text, the user might not want to actually delete it)
389 if (key->keyval == GDK_KEY_Escape) {
Guillaume Roguez6f431372017-12-12 21:15:39 -0500390 priv->cpp->accountContainer_->info.conversationModel->setFilter("");
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400391 return GDK_EVENT_STOP;
392 }
393
394 return GDK_EVENT_PROPAGATE;
395}
396
397static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500398on_dtmf_pressed(RingMainWindow* self, GdkEventKey* event, gpointer user_data)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400399{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500400 (void)user_data;
401
402 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
403 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
404
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400405 g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400406 g_return_val_if_fail(priv, GDK_EVENT_PROPAGATE);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400407
408 /* we want to react to digit key presses, as long as a GtkEntry is not the
409 * input focus
410 */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500411 GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(self));
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400412 if (GTK_IS_ENTRY(focus))
413 return GDK_EVENT_PROPAGATE;
414
Guillaume Roguez6f431372017-12-12 21:15:39 -0500415 if (priv->cpp->accountContainer_ &&
416 priv->cpp->accountContainer_->info.profileInfo.type != lrc::api::profile::Type::SIP)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400417 return GDK_EVENT_PROPAGATE;
418
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400419 /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c'
420 * does not result in a 'c' being played.
421 * we filter Ctrl, Alt, and SUPER/HYPER/META keys */
422 if ( event->state
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400423 & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ))
424 return GDK_EVENT_PROPAGATE;
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400425
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400426 // Get current conversation
427 auto current_view = gtk_bin_get_child(GTK_BIN(priv->frame_call));
428 lrc::api::conversation::Info current_item;
429 if (IS_CURRENT_CALL_VIEW(current_view))
430 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(current_view));
431 else
432 return GDK_EVENT_PROPAGATE;
433
434 if (current_item.callId.empty())
435 return GDK_EVENT_PROPAGATE;
436
437 // pass the character that was entered to be played by the daemon;
438 // the daemon will filter out invalid DTMF characters
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400439 guint32 unicode_val = gdk_keyval_to_unicode(event->keyval);
440 QString val = QString::fromUcs4(&unicode_val, 1);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400441 g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData());
Guillaume Roguez6f431372017-12-12 21:15:39 -0500442 priv->cpp->accountContainer_->info.callModel->playDTMF(current_item.callId, val.toStdString());
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400443 // always propogate the key, so we don't steal accelerators/shortcuts
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400444 return GDK_EVENT_PROPAGATE;
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400445}
446
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400447static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500448on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainWindow* self)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400449{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500450 (void)notebook;
451 (void)page;
452
453 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
454 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
455
Guillaume Roguez6f431372017-12-12 21:15:39 -0500456 auto newType = page_num == 0 ? priv->cpp->accountContainer_->info.profileInfo.type : lrc::api::profile::Type::PENDING;
457 if (priv->cpp->currentTypeFilter_ != newType) {
458 priv->cpp->currentTypeFilter_ = newType;
459 priv->cpp->accountContainer_->info.conversationModel->setFilter(priv->cpp->currentTypeFilter_);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400460 }
Nicolas Jager0efc8432017-03-22 16:22:00 -0400461}
462
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400463static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500464on_window_size_changed(GtkWidget* self, GdkEventConfigure* event, gpointer user_data)
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400465{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500466 (void)user_data;
467
468 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
469 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400470
471 g_settings_set_int(priv->settings, "window-width", event->width);
472 g_settings_set_int(priv->settings, "window-height", event->height);
473
474 return GDK_EVENT_PROPAGATE;
475}
476
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400477static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500478on_search_entry_places_call_changed(GSettings* settings, const gchar* key, RingMainWindow* self)
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400479{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500480 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
481 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400482
483 if (g_settings_get_boolean(settings, key)) {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500484 gtk_widget_set_tooltip_text(priv->button_new_conversation,
485 C_("button next to search entry will place a new call",
486 "place call"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400487 } else {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500488 gtk_widget_set_tooltip_text(priv->button_new_conversation,
489 C_("button next to search entry will open chat", "open chat"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400490 }
491}
492
493static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500494on_handle_account_migrations(RingMainWindow* self)
aviau6aeb4852016-08-18 16:01:09 -0400495{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500496 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
497 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
aviau6aeb4852016-08-18 16:01:09 -0400498
499 /* If there is an existing migration view, remove it */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500500 if (priv->account_migration_view) {
Stepan Salenikovich56530b12016-10-20 17:51:34 -0400501 gtk_widget_destroy(priv->account_migration_view);
502 priv->account_migration_view = nullptr;
aviau6aeb4852016-08-18 16:01:09 -0400503 }
504
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500505 auto accounts = AccountModel::instance().accountsToMigrate();
506 if (!accounts.isEmpty()) {
507 auto* account = accounts.first();
aviau6aeb4852016-08-18 16:01:09 -0400508
aviau69081842016-10-14 14:51:54 -0400509 priv->account_migration_view = account_migration_view_new(account);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500510 g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed",
511 G_CALLBACK(on_handle_account_migrations), self);
512 g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed",
513 G_CALLBACK(on_handle_account_migrations), self);
aviau6aeb4852016-08-18 16:01:09 -0400514
515 gtk_widget_hide(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500516 priv->cpp->showAccountSelectorWidget(false);
aviau69081842016-10-14 14:51:54 -0400517 gtk_widget_show(priv->account_migration_view);
aviau6aeb4852016-08-18 16:01:09 -0400518 gtk_stack_add_named(
519 GTK_STACK(priv->stack_main_view),
aviau69081842016-10-14 14:51:54 -0400520 priv->account_migration_view,
aviau6aeb4852016-08-18 16:01:09 -0400521 ACCOUNT_MIGRATION_VIEW_NAME
522 );
523 gtk_stack_set_visible_child_name(
524 GTK_STACK(priv->stack_main_view),
525 ACCOUNT_MIGRATION_VIEW_NAME
526 );
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500527 } else {
aviau6aeb4852016-08-18 16:01:09 -0400528 gtk_widget_show(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500529 priv->cpp->showAccountSelectorWidget();
aviau6aeb4852016-08-18 16:01:09 -0400530 }
531}
532
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500533} // namespace gtk_callbacks
534
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500535CppImpl::CppImpl(RingMainWindow& widget)
536 : self {&widget}
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500537 , widgets {RING_MAIN_WINDOW_GET_PRIVATE(&widget)}
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500538 , lrc_ {std::make_unique<lrc::api::Lrc>()}
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500539{}
540
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500541void
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500542CppImpl::init()
543{
544 // NOTE: When new models will be fully implemented, we need to move this
545 // in rign_client.cpp->
546 // Init LRC and the vew
547 const auto accountIds = lrc_->getAccountModel().getAccountList();
548 auto isInitialized = false;
549 if (not accountIds.empty()) {
550 for (const auto& accountId : accountIds) {
551 const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId);
552 if (accountInfo.enabled) {
553 updateLrc(accountId);
554 isInitialized = true;
555 break;
556 }
557 }
558 if (!isInitialized) {
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500559 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500560 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500561 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500562 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500563 }
564 }
565
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500566 accountStatusChangedConnection_ = QObject::connect(&lrc_->getAccountModel(),
567 &lrc::api::NewAccountModel::accountStatusChanged,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500568 [this](const std::string& id){ slotAccountStatusChanged(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500569 newAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500570 &lrc::api::NewAccountModel::accountAdded,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500571 [this](const std::string& id){ slotAccountAddedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500572 rmAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez64236c22017-12-13 20:08:25 -0500573 &lrc::api::NewAccountModel::accountRemoved,
574 [this](const std::string& id){ slotAccountRemovedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500575
576 /* bind to window size settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500577 widgets->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr);
578 auto width = g_settings_get_int(widgets->settings, "window-width");
579 auto height = g_settings_get_int(widgets->settings, "window-height");
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500580 gtk_window_set_default_size(GTK_WINDOW(self), width, height);
581 g_signal_connect(self, "configure-event", G_CALLBACK(on_window_size_changed), nullptr);
582
583 /* search-entry-places-call setting */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500584 on_search_entry_places_call_changed(widgets->settings, "search-entry-places-call", self);
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500585 g_signal_connect(widgets->settings, "changed::search-entry-places-call",
586 G_CALLBACK(on_search_entry_places_call_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500587
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500588 /* set window icon */
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500589 GError *error = NULL;
590 GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error);
591 if (icon == NULL) {
592 g_debug("Could not load icon: %s", error->message);
593 g_clear_error(&error);
594 } else
595 gtk_window_set_icon(GTK_WINDOW(self), icon);
596
597 /* set menu icon */
598 GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue",
599 -1, 16, TRUE, &error);
600 if (image_ring == NULL) {
601 g_debug("Could not load icon: %s", error->message);
602 g_clear_error(&error);
603 } else
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500604 gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_ring), image_ring);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500605
606 /* ring menu */
607 GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui");
608 GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu"));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500609 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(widgets->ring_menu), menu);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500610 g_object_unref(builder);
611
612 /* settings icon */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500613 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
614 GTK_ICON_SIZE_SMALL_TOOLBAR);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500615
616 /* connect settings button signal */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500617 g_signal_connect_swapped(widgets->ring_settings, "clicked",
618 G_CALLBACK(on_settings_clicked), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500619
620 /* add the call view to the main stack */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500621 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500622 CALL_VIEW_NAME);
623
624 /* init the settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500625 widgets->account_settings_view = account_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500626 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->account_settings_view,
627 ACCOUNT_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500628
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500629 widgets->media_settings_view = media_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500630 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->media_settings_view,
631 MEDIA_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500632
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500633 widgets->general_settings_view = general_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500634 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view,
635 GENERAL_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500636
637 /* make the setting we will show first the active one */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500638 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE);
639 widgets->last_settings_view = widgets->general_settings_view;
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500640
641 /* connect the settings button signals to switch settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500642 g_signal_connect(widgets->radiobutton_media_settings, "toggled", G_CALLBACK(on_show_media_settings), self);
643 g_signal_connect(widgets->radiobutton_account_settings, "toggled", G_CALLBACK(on_show_account_settings), self);
644 g_signal_connect(widgets->radiobutton_general_settings, "toggled", G_CALLBACK(on_show_general_settings), self);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500645 g_signal_connect(widgets->notebook_contacts, "switch-page", G_CALLBACK(on_tab_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500646
647 /* welcome/default view */
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500648 widgets->welcome_view = ring_welcome_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500649 g_object_ref(widgets->welcome_view); // increase ref because don't want it to be destroyed when not displayed
650 gtk_container_add(GTK_CONTAINER(widgets->frame_call), widgets->welcome_view);
651 gtk_widget_show(widgets->welcome_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500652
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500653 g_signal_connect_swapped(widgets->search_entry, "activate", G_CALLBACK(on_search_entry_activated), self);
654 g_signal_connect_swapped(widgets->button_new_conversation, "clicked", G_CALLBACK(on_search_entry_activated), self);
655 g_signal_connect(widgets->search_entry, "search-changed", G_CALLBACK(on_search_entry_text_changed), self);
656 g_signal_connect(widgets->search_entry, "key-release-event", G_CALLBACK(on_search_entry_key_released), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500657
658 auto provider = gtk_css_provider_new();
659 gtk_css_provider_load_from_data(provider,
660 ".search-entry-style { border: 0; border-radius: 0; } \
661 .spinner-style { border: 0; background: white; } \
662 .new-conversation-style { border: 0; background: white; transition: all 0.3s ease; border-radius: 0; } \
663 .new-conversation-style:hover { background: #bae5f0; }",
664 -1, nullptr
665 );
666 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
667 GTK_STYLE_PROVIDER(provider),
668 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
669
670
671 /* react to digit key press events */
672 g_signal_connect(self, "key-press-event", G_CALLBACK(on_dtmf_pressed), nullptr);
673
674 /* set the search entry placeholder text */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500675 gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->search_entry),
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500676 C_("Please try to make the translation 50 chars or less so that it fits into the layout",
677 "Search contacts or enter number"));
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500678
679 /* init chat webkit container so that it starts loading before the first time we need it*/
680 (void)webkitChatContainer();
681
682 if (has_ring_account()) {
683 /* user has ring account, so show the call view right away */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500684 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500685
686 on_handle_account_migrations(self);
687 } else {
688 /* user has to create the ring account */
689 enterAccountCreationWizard();
690 }
691
692 // setup account selector and select the first account
693 auto store = gtk_list_store_new (2 /* # of cols */ ,
694 G_TYPE_STRING,
695 G_TYPE_STRING,
696 G_TYPE_UINT);
697 GtkTreeIter iter;
Guillaume Roguez7e238402017-12-13 19:40:05 -0500698 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500699 gtk_list_store_append (store, &iter);
700 gtk_list_store_set (store, &iter,
Guillaume Roguez7e238402017-12-13 19:40:05 -0500701 0 /* col # */ , acc_info.id.c_str() /* celldata */,
702 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500703 -1 /* end */);
Guillaume Roguez7e238402017-12-13 19:40:05 -0500704 });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500705
706 gtk_combo_box_set_model(
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500707 GTK_COMBO_BOX(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500708 GTK_TREE_MODEL (store)
709 );
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500710 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500711
712 /* set visibility */
713 showAccountSelectorWidget();
714
715 /* layout */
716 auto *renderer = gtk_cell_renderer_text_new();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500717 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, FALSE);
718 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, "text", 0, NULL);
719 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500720 renderer,
721 (GtkCellLayoutDataFunc)print_account_and_state,
722 nullptr, nullptr);
723
724 // we closing any view opened to avoid confusion (especially between SIP and Ring protocols).
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500725 g_signal_connect_swapped(widgets->combobox_account_selector, "changed", G_CALLBACK(on_account_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500726
727 // initialize the pending contact request icon.
Nicolas Jager3e4055b2018-01-10 13:48:41 -0500728 setPendingContactRequestTabIcon(self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500729
730 if (isInitialized) {
731 auto& conversationModel = accountContainer_->info.conversationModel;
732 auto conversations = conversationModel->allFilteredConversations();
733 for (const auto& conversation: conversations) {
734 if (!conversation.callId.empty()) {
735 accountContainer_->info.conversationModel->selectConversation(conversation.uid);
736 }
737 }
738 }
739}
740
741CppImpl::~CppImpl()
742{
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500743 QObject::disconnect(showChatViewConnection_);
744 QObject::disconnect(showIncomingViewConnection_);
745 QObject::disconnect(historyClearedConnection_);
746 QObject::disconnect(modelSortedConnection_);
747 QObject::disconnect(filterChangedConnection_);
748 QObject::disconnect(newConversationConnection_);
749 QObject::disconnect(conversationRemovedConnection_);
750 QObject::disconnect(changeAccountConnection_);
751 QObject::disconnect(newAccountConnection_);
752 QObject::disconnect(rmAccountConnection_);
753 QObject::disconnect(showCallViewConnection_);
754 QObject::disconnect(modelSortedConnection_);
755 QObject::disconnect(accountStatusChangedConnection_);
Nicolas Jagercfeffc32018-01-12 10:58:55 -0500756 QObject::disconnect(chat_notification_);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500757
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500758 g_clear_object(&widgets->welcome_view);
759 g_clear_object(&widgets->webkit_chat_container);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500760}
761
762void
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500763CppImpl::changeView(GType type, lrc::api::conversation::Info conversation)
764{
Guillaume Roguez1d963272017-12-12 23:32:13 -0500765 leaveFullScreen();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500766 gtk_container_remove(GTK_CONTAINER(widgets->frame_call),
767 gtk_bin_get_child(GTK_BIN(widgets->frame_call)));
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500768
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500769 GtkWidget* new_view;
770 if (g_type_is_a(INCOMING_CALL_VIEW_TYPE, type)) {
771 new_view = displayIncomingView(conversation);
772 } else if (g_type_is_a(CURRENT_CALL_VIEW_TYPE, type)) {
773 new_view = displayCurrentCallView(conversation);
774 } else if (g_type_is_a(CHAT_VIEW_TYPE, type)) {
775 new_view = displayChatView(conversation);
776 } else {
Nicolas Jagercfeffc32018-01-12 10:58:55 -0500777 chatViewConversation_.reset(nullptr);
778
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500779 // TODO select first conversation?
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500780 new_view = widgets->welcome_view;
Nicolas Jager3e4055b2018-01-10 13:48:41 -0500781
782 // refresh the tabs
783 auto hasPendingRequests = accountContainer_->info.contactModel->hasPendingRequests();
784
785 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widgets->notebook_contacts), hasPendingRequests);
786
787 if (not hasPendingRequests) {
788 gtk_notebook_prev_page(GTK_NOTEBOOK(widgets->notebook_contacts));
789 }
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500790 }
791
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500792 gtk_container_add(GTK_CONTAINER(widgets->frame_call), new_view);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500793 gtk_widget_show(new_view);
794}
795
796GtkWidget*
797CppImpl::displayIncomingView(lrc::api::conversation::Info conversation)
798{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500799 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
800 return incoming_call_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500801}
802
803GtkWidget*
804CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation)
805{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500806 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
Guillaume Roguez11339f82017-12-12 23:15:34 -0500807 auto* new_view = current_call_view_new(webkitChatContainer(),
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500808 accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500809
810 try {
811 auto contactUri = chatViewConversation_->participants.front();
812 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
813 if (auto chat_view = current_call_view_get_chat_view(CURRENT_CALL_VIEW(new_view))) {
814 chat_view_update_temporary(CHAT_VIEW(chat_view),
815 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
816 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
817 }
818 } catch(...) { }
819
Guillaume Roguez1d963272017-12-12 23:32:13 -0500820 g_signal_connect_swapped(new_view, "video-double-clicked",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500821 G_CALLBACK(on_video_double_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500822 return new_view;
823}
824
825GtkWidget*
826CppImpl::displayChatView(lrc::api::conversation::Info conversation)
827{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500828 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
829 auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500830 g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500831 return new_view;
832}
833
Guillaume Roguez11339f82017-12-12 23:15:34 -0500834WebKitChatContainer*
835CppImpl::webkitChatContainer() const
836{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500837 if (!widgets->webkit_chat_container) {
838 widgets->webkit_chat_container = webkit_chat_container_new();
Guillaume Roguez11339f82017-12-12 23:15:34 -0500839
840 // We don't want it to be deleted, ever.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500841 g_object_ref(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500842 }
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500843 return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500844}
845
Guillaume Roguez1d963272017-12-12 23:32:13 -0500846void
847CppImpl::enterFullScreen()
848{
849 if (!is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500850 gtk_widget_hide(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500851 gtk_window_fullscreen(GTK_WINDOW(self));
852 is_fullscreen = true;
853 }
854}
855
856void
857CppImpl::leaveFullScreen()
858{
859 if (is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500860 gtk_widget_show(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500861 gtk_window_unfullscreen(GTK_WINDOW(self));
862 is_fullscreen = false;
863 }
864}
865
866void
867CppImpl::toggleFullScreen()
868{
869 if (is_fullscreen)
870 leaveFullScreen();
871 else
872 enterFullScreen();
873}
874
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500875/// Clear selection and go to welcome page.
876void
877CppImpl::resetToWelcome()
878{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500879 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500880 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500881 auto selection_contact_request = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500882 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500883 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500884 lrc::api::conversation::Info current_item;
885 if (IS_CHAT_VIEW(old_view))
886 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
887 changeView(RING_WELCOME_VIEW_TYPE, current_item);
888}
889
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500890void
Nicolas Jager3e4055b2018-01-10 13:48:41 -0500891CppImpl::setPendingContactRequestTabIcon(RingMainWindow *win)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500892{
Nicolas Jager3e4055b2018-01-10 13:48:41 -0500893 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
894
Nicolas Jagere9669d22018-01-12 10:58:55 -0500895 if (not accountContainer_)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500896 return;
897
Nicolas Jagere9669d22018-01-12 10:58:55 -0500898 auto hasPendingRequest = priv->cpp->accountContainer_->info.contactModel->hasPendingRequests();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500899
Nicolas Jagere9669d22018-01-12 10:58:55 -0500900 gtk_widget_set_visible(widgets->scrolled_window_contact_requests, hasPendingRequest);
901 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(priv->notebook_contacts), hasPendingRequest);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500902}
903
904void
905CppImpl::showAccountSelectorWidget(bool show)
906{
907 // we only want to show the account selector when there is more than 1 enabled
908 // account; so every time we want to show it, we should preform this check
Guillaume Roguez7e238402017-12-13 19:40:05 -0500909 std::size_t activatedAccount = 0;
910 foreachEnabledLrcAccount(*lrc_, [&] (const auto&) { ++activatedAccount; });
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500911 gtk_widget_set_visible(widgets->combobox_account_selector, show && activatedAccount > 1);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500912}
913
914void
915CppImpl::enterAccountCreationWizard()
916{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500917 if (!widgets->account_creation_wizard) {
918 widgets->account_creation_wizard = account_creation_wizard_new(false);
919 g_object_add_weak_pointer(G_OBJECT(widgets->account_creation_wizard),
920 reinterpret_cast<gpointer*>(&widgets->account_creation_wizard));
921 g_signal_connect_swapped(widgets->account_creation_wizard, "account-creation-completed",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500922 G_CALLBACK(on_account_creation_completed), self);
923
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500924 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view),
925 widgets->account_creation_wizard,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500926 ACCOUNT_CREATION_WIZARD_VIEW_NAME);
927 }
928
929 /* hide settings button until account creation is complete */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500930 gtk_widget_hide(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500931 showAccountSelectorWidget(false);
932
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500933 gtk_widget_show(widgets->account_creation_wizard);
934 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->account_creation_wizard);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500935}
936
937void
938CppImpl::leaveAccountCreationWizard()
939{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500940 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500941
942 /* destroy the wizard */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500943 if (widgets->account_creation_wizard) {
944 gtk_container_remove(GTK_CONTAINER(widgets->stack_main_view), widgets->account_creation_wizard);
945 gtk_widget_destroy(widgets->account_creation_wizard);
946 widgets->account_creation_wizard = nullptr;
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500947 }
948
949 /* show the settings button */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500950 gtk_widget_show(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500951
952 /* show the account selector */
953 showAccountSelectorWidget();
954}
955
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500956/// Change the selection of the account ComboBox by account Id.
957/// Find in displayed accounts with one corresponding to the given id, then select it
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500958void
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500959CppImpl::changeAccountSelection(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500960{
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500961 // already selected?
962 if (id == accountContainer_->info.id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500963 return;
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500964
965 if (auto* model = gtk_combo_box_get_model(GTK_COMBO_BOX(widgets->combobox_account_selector))) {
966 GtkTreeIter iter;
967 auto valid = gtk_tree_model_get_iter_first(model, &iter);
968 while (valid) {
969 const gchar* account_id;
970 gtk_tree_model_get(model, &iter, 0 /* col# */, &account_id /* data */, -1);
971 if (id == account_id) {
972 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->combobox_account_selector), &iter);
973 return;
974 }
975 valid = gtk_tree_model_iter_next(model, &iter);
976 }
977
978 g_debug("BUGS: account not listed: %s", id.c_str());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500979 }
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500980}
981
982void
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500983CppImpl::onAccountSelectionChange(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500984{
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500985 // Go to welcome view
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500986 changeView(RING_WELCOME_VIEW_TYPE);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500987 // Show conversation panel
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500988 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500989 // Reinit LRC
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500990 updateLrc(id);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500991 // Update the welcome view
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500992 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500993}
994
995void
996CppImpl::enterSettingsView()
997{
998 /* show the settings */
999 show_settings = true;
1000
1001 /* show settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001002 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-ok-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001003 GTK_ICON_SIZE_SMALL_TOOLBAR);
1004
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001005 gtk_widget_show(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001006
1007 /* make sure to start preview if we're showing the video settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001008 if (widgets->last_settings_view == widgets->media_settings_view)
1009 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), TRUE);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001010
1011 /* make sure to show the profile if we're showing the general settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001012 if (widgets->last_settings_view == widgets->general_settings_view)
1013 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001014 TRUE);
1015
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001016 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->last_settings_view);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001017}
1018
1019void
1020CppImpl::leaveSettingsView()
1021{
1022 /* hide the settings */
1023 show_settings = false;
1024
1025 /* show working dialog in case save operation takes time */
1026 auto working = ring_dialog_working(GTK_WIDGET(self), nullptr);
1027 gtk_window_present(GTK_WINDOW(working));
1028
1029 /* now save after the time it takes to transition back to the call view (400ms)
1030 * the save doesn't happen before the "working" dialog is presented
1031 * the timeout function should destroy the "working" dialog when done saving
1032 */
1033 g_timeout_add_full(G_PRIORITY_DEFAULT, 400, GSourceFunc(on_save_accounts_timeout), working,
1034 nullptr);
1035
1036 /* show calls */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001037 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001038 GTK_ICON_SIZE_SMALL_TOOLBAR);
1039
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001040 gtk_widget_hide(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001041
1042 /* make sure video preview is stopped, in case it was started */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001043 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), FALSE);
1044 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001045 FALSE);
1046
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001047 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001048
1049 /* show the view which was selected previously */
1050}
1051
1052void
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001053CppImpl::updateLrc(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001054{
1055 // Disconnect old signals.
1056 QObject::disconnect(showChatViewConnection_);
1057 QObject::disconnect(showIncomingViewConnection_);
1058 QObject::disconnect(changeAccountConnection_);
1059 QObject::disconnect(showCallViewConnection_);
1060 QObject::disconnect(modelSortedConnection_);
1061 QObject::disconnect(historyClearedConnection_);
1062 QObject::disconnect(filterChangedConnection_);
1063 QObject::disconnect(newConversationConnection_);
1064 QObject::disconnect(conversationRemovedConnection_);
1065
1066 // Get the account selected
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001067 if (!id.empty())
1068 accountContainer_.reset(new AccountContainer(lrc_->getAccountModel().getAccountInfo(id)));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001069 else
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001070 accountContainer_.reset();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001071
1072 // Reinit tree views
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001073 if (widgets->treeview_conversations) {
1074 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001075 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001076 gtk_widget_destroy(widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001077 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001078 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001079 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001080
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001081 if (widgets->treeview_contact_requests) {
1082 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001083 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001084 gtk_widget_destroy(widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001085 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001086 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001087 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001088
1089 if (!accountContainer_) return;
1090
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001091 // Connect to signals from LRC
1092 historyClearedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001093 &lrc::api::ConversationModel::conversationCleared,
1094 [this] (const std::string& id) { slotConversationCleared(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001095
1096 modelSortedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001097 &lrc::api::ConversationModel::modelSorted,
1098 [this] { slotModelSorted(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001099
1100 filterChangedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001101 &lrc::api::ConversationModel::filterChanged,
1102 [this] { slotFilterChanged(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001103
1104 newConversationConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001105 &lrc::api::ConversationModel::newConversation,
1106 [this] (const std::string& id) { slotNewConversation(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001107
1108 conversationRemovedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001109 &lrc::api::ConversationModel::conversationRemoved,
1110 [this] (const std::string& id) { slotConversationRemoved(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001111
1112 showChatViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001113 &lrc::api::BehaviorController::showChatView,
1114 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowChatView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001115
1116 showCallViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001117 &lrc::api::BehaviorController::showCallView,
1118 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001119
1120 showIncomingViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001121 &lrc::api::BehaviorController::showIncomingCallView,
1122 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowIncomingCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001123
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001124 const gchar *text = gtk_entry_get_text(GTK_ENTRY(widgets->search_entry));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001125 currentTypeFilter_ = accountContainer_->info.profileInfo.type;
1126 accountContainer_->info.conversationModel->setFilter(text);
1127 accountContainer_->info.conversationModel->setFilter(currentTypeFilter_);
1128}
1129
Guillaume Roguez64236c22017-12-13 20:08:25 -05001130void
1131CppImpl::slotAccountAddedFromLrc(const std::string& id)
1132{
1133 (void)id;
1134
1135 // go to this account
1136 auto accounts = lrc_->getAccountModel().getAccountList();
1137 auto store = gtk_list_store_new (2 /* # of cols */ ,
1138 G_TYPE_STRING,
1139 G_TYPE_STRING,
1140 G_TYPE_UINT);
1141 auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
1142 GtkTreeIter iter;
1143 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
1144 gtk_list_store_append (store, &iter);
1145 gtk_list_store_set (store, &iter,
1146 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1147 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
1148 -1 /* end */);
1149 });
1150 // Redraw combobox
1151 gtk_combo_box_set_model(
1152 GTK_COMBO_BOX(widgets->combobox_account_selector),
1153 GTK_TREE_MODEL (store)
1154 );
1155 // If no account selected, select the new account
1156 if (currentIdx == -1) currentIdx = 0;
1157 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx);
1158 showAccountSelectorWidget();
1159}
1160
1161void
1162CppImpl::slotAccountRemovedFromLrc(const std::string& id)
1163{
1164 (void)id;
1165
1166 auto accounts = lrc_->getAccountModel().getAccountList();
1167 if (accounts.empty()) {
1168 enterAccountCreationWizard();
1169 return;
1170 }
1171
1172 auto store = gtk_list_store_new (2 /* # of cols */ ,
1173 G_TYPE_STRING,
1174 G_TYPE_STRING,
1175 G_TYPE_UINT);
1176 GtkTreeIter iter;
1177 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
1178 gtk_list_store_append (store, &iter);
1179 gtk_list_store_set (store, &iter,
1180 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1181 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
1182 -1 /* end */);
1183 });
1184 gtk_combo_box_set_model(
1185 GTK_COMBO_BOX(widgets->combobox_account_selector),
1186 GTK_TREE_MODEL (store)
1187 );
1188 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0);
1189 showAccountSelectorWidget();
1190 // Show conversation panel
1191 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
1192 // Reinit LRC
1193 updateLrc(std::string(accounts.at(0)));
1194 // Update the welcome view
1195 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
1196}
1197
1198void
1199CppImpl::slotAccountStatusChanged(const std::string& id)
1200{
1201 if (not accountContainer_ ) {
1202 updateLrc(id);
1203 if (accountContainer_)
1204 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view),
1205 accountContainer_.get());
1206 return;
1207 }
1208
1209 auto accounts = lrc_->getAccountModel().getAccountList();
1210 auto store = gtk_list_store_new (2 /* # of cols */ ,
1211 G_TYPE_STRING,
1212 G_TYPE_STRING,
1213 G_TYPE_UINT);
1214
1215 gint currentIdx = 0;
1216 std::size_t enabledAccounts = 0;
1217 GtkTreeIter iter;
1218 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
1219 ++enabledAccounts;
1220 gtk_list_store_append (store, &iter);
1221 gtk_list_store_set (store, &iter,
1222 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1223 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
1224 -1 /* end */);
1225 if (id == acc_info.id) {
1226 // keep current selected account only if account status is enabled
1227 currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
1228 }
1229 });
1230 showAccountSelectorWidget();
1231
1232 // Redraw combobox
1233 gtk_combo_box_set_model(
1234 GTK_COMBO_BOX(widgets->combobox_account_selector),
1235 GTK_TREE_MODEL (store)
1236 );
1237 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx);
1238 // if no account. reset the view.
1239 if (enabledAccounts == 0) {
1240 updateLrc("");
1241 changeView(RING_WELCOME_VIEW_TYPE);
1242 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), nullptr);
1243 }
1244}
1245
1246void
1247CppImpl::slotConversationCleared(const std::string& uid)
1248{
1249 // Change the view when the history is cleared.
1250 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1251 lrc::api::conversation::Info current_item;
1252 current_item.uid = "-1"; // Because the Searching item has an empty uid
1253 if (IS_CHAT_VIEW(old_view))
1254 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1255 else
1256 // if incoming or call view we don't want to change the view
1257 return;
1258 if (current_item.uid == uid) {
1259 // We are on the conversation cleared.
1260 // Go to welcome view because user doesn't want this conversation
1261 // TODO go to first conversation?
1262 resetToWelcome();
1263 }
1264}
1265
1266void
1267CppImpl::slotModelSorted()
1268{
1269 // Synchronize selection when sorted and update pending icon
1270 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1271 lrc::api::conversation::Info current_item;
1272 current_item.uid = "-1";
1273 if (IS_CHAT_VIEW(old_view))
1274 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1275 else if (IS_CURRENT_CALL_VIEW(old_view))
1276 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1277 else if (IS_INCOMING_CALL_VIEW(old_view))
1278 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1279 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
Nicolas Jager3e4055b2018-01-10 13:48:41 -05001280 setPendingContactRequestTabIcon(self);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001281}
1282
1283void
1284CppImpl::slotFilterChanged()
1285{
1286 // Synchronize selection when filter changes
1287 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1288 lrc::api::conversation::Info current_item;
1289 current_item.uid = "-1";
1290 if (IS_CHAT_VIEW(old_view))
1291 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1292 else if (IS_CURRENT_CALL_VIEW(old_view))
1293 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1294 else if (IS_INCOMING_CALL_VIEW(old_view))
1295 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1296 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
1297 // Get if conversation still exists.
1298 auto& conversationModel = accountContainer_->info.conversationModel;
1299 auto conversations = conversationModel->allFilteredConversations();
1300 auto isInConv = std::find_if(
1301 conversations.begin(), conversations.end(),
1302 [current_item](const lrc::api::conversation::Info& conversation) {
1303 return current_item.uid == conversation.uid;
1304 });
1305 if (IS_CHAT_VIEW(old_view) && isInConv == conversations.end()) {
1306 changeView(RING_WELCOME_VIEW_TYPE);
1307 }
1308}
1309
1310void
1311CppImpl::slotNewConversation(const std::string& uid)
1312{
1313 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
1314 accountContainer_->info.conversationModel->setFilter(lrc::api::profile::Type::RING);
1315 gtk_entry_set_text(GTK_ENTRY(widgets->search_entry), "");
1316 accountContainer_->info.conversationModel->setFilter("");
1317 // Select new conversation if contact added
1318 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1319 if (IS_RING_WELCOME_VIEW(old_view) || (IS_CHAT_VIEW(old_view) && chat_view_get_temporary(CHAT_VIEW(old_view)))) {
1320 accountContainer_->info.conversationModel->selectConversation(uid);
1321 try {
1322 auto contactUri = chatViewConversation_->participants.front();
1323 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
1324 chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))),
1325 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
1326 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
1327 } catch(...) { }
1328 }
1329}
1330
1331void
1332CppImpl::slotConversationRemoved(const std::string& uid)
1333{
1334 // If contact is removed, go to welcome view
1335 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1336 lrc::api::conversation::Info current_item;
1337 if (IS_CHAT_VIEW(old_view))
1338 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1339 else if (IS_CURRENT_CALL_VIEW(old_view))
1340 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1341 else if (IS_INCOMING_CALL_VIEW(old_view))
1342 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1343 if (current_item.uid == uid)
1344 changeView(RING_WELCOME_VIEW_TYPE);
1345}
1346
1347void
1348CppImpl::slotShowChatView(const std::string& id, lrc::api::conversation::Info origin)
1349{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001350 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001351 // Show chat view if not in call (unless if it's the same conversation)
1352 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1353 lrc::api::conversation::Info current_item;
1354 current_item.uid = "-1";
1355 if (IS_CHAT_VIEW(old_view))
1356 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1357 if (current_item.uid != origin.uid) {
1358 if (origin.participants.empty()) return;
1359 auto firstContactUri = origin.participants.front();
1360 auto contactInfo = accountContainer_->info.contactModel->getContact(firstContactUri);
1361 if (contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING && current_item.uid != "-1") return;
1362 changeView(CHAT_VIEW_TYPE, origin);
1363 }
1364}
1365
1366void
1367CppImpl::slotShowCallView(const std::string& id, lrc::api::conversation::Info origin)
1368{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001369 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001370 // Change the view if we want a different view.
1371 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1372
1373 lrc::api::conversation::Info current_item;
1374 if (IS_CURRENT_CALL_VIEW(old_view))
1375 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1376
1377 if (current_item.uid != origin.uid)
1378 changeView(CURRENT_CALL_VIEW_TYPE, origin);
1379}
1380
1381void
1382CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin)
1383{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001384 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001385 // Change the view if we want a different view.
1386 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1387
1388 lrc::api::conversation::Info current_item;
1389 if (IS_INCOMING_CALL_VIEW(old_view))
1390 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1391
1392 if (current_item.uid != origin.uid)
1393 changeView(INCOMING_CALL_VIEW_TYPE, origin);
1394}
1395
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001396} // namespace details
1397
1398//==============================================================================
Guillaume Roguez0a411202017-05-25 15:27:26 -04001399
1400static void
Nicolas Jagercfeffc32018-01-12 10:58:55 -05001401chat_notifications(RingMainWindow *win)
1402{
1403 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
1404 priv->cpp->chat_notification_ = QObject::connect(
1405 &Media::RecordingModel::instance(),
1406 &Media::RecordingModel::newTextMessage,
1407 [win, priv] (Media::TextRecording* t, ContactMethod* cm) {
1408 if ((priv->cpp->chatViewConversation_
1409 && priv->cpp->chatViewConversation_->participants[0] == cm->uri().toStdString())
1410 || not g_settings_get_boolean(priv->settings, "enable-chat-notifications"))
1411 return;
1412
1413 ring_notify_message(cm, t);
1414 }
1415 );
1416}
1417
1418static void
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001419ring_main_window_init(RingMainWindow *win)
1420{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001421 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001422 gtk_widget_init_template(GTK_WIDGET(win));
1423
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001424 // CppImpl ctor
1425 priv->cpp = new details::CppImpl {*win};
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001426 priv->cpp->init();
Nicolas Jagercfeffc32018-01-12 10:58:55 -05001427
1428 // setup chat notification
1429 chat_notifications(win);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001430}
1431
1432static void
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001433ring_main_window_dispose(GObject *object)
1434{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001435 auto* self = RING_MAIN_WINDOW(object);
1436 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001437
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001438 delete priv->cpp;
1439 priv->cpp = nullptr;
1440
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001441 G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object);
1442}
1443
1444static void
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001445ring_main_window_finalize(GObject *object)
1446{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001447 auto* self = RING_MAIN_WINDOW(object);
1448 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichba87ae22016-09-13 14:27:20 -04001449
1450 g_clear_object(&priv->settings);
1451
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001452 G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001453}
1454
1455static void
1456ring_main_window_class_init(RingMainWindowClass *klass)
1457{
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001458 G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize;
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001459 G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001460
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001461 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
1462 "/cx/ring/RingGnome/ringmainwindow.ui");
1463
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001464 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane);
Sébastien Blin55bff9d2017-10-03 15:15:23 -04001465 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, notebook_contacts);
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -04001466 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001467 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu);
1468 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring);
1469 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings);
1470 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001471 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, hbox_settings);
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -05001472 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, search_entry);
Stepan Salenikovich69771842015-02-24 18:11:45 -05001473 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, stack_main_view);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001474 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_call_view);
Stepan Salenikovich3034d922015-10-09 10:11:42 -04001475 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, frame_call);
Stepan Salenikoviche9933242016-06-21 18:08:48 -04001476 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, button_new_conversation );
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001477 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_general_settings);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -04001478 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001479 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings);
Nicolas Jager15a8b902017-03-21 07:53:06 -04001480 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, combobox_account_selector);
Nicolas Jager0efc8432017-03-22 16:22:00 -04001481 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contact_requests);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001482}
1483
1484GtkWidget *
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001485ring_main_window_new(GtkApplication *app)
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001486{
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001487 gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL);
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001488 return (GtkWidget *)win;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001489}