blob: 6673af1dd92598c3438514353c92c510d4ce4697 [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"
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -040039
40// Ring client
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -040041#include "accountview.h"
aviau6aeb4852016-08-18 16:01:09 -040042#include "accountmigrationview.h"
43#include "accountcreationwizard.h"
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -050044#include "chatview.h"
Sébastien Blin55bff9d2017-10-03 15:15:23 -040045#include "conversationsview.h"
46#include "currentcallview.h"
47#include "dialogs.h"
48#include "generalsettingsview.h"
49#include "incomingcallview.h"
50#include "mediasettingsview.h"
51#include "models/gtkqtreemodel.h"
52#include "ringwelcomeview.h"
53#include "utils/accounts.h"
Stepan Salenikovichba87ae22016-09-13 14:27:20 -040054#include "utils/files.h"
Nicolas Jagerb413b302016-05-06 11:41:32 -040055
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -050056//==============================================================================
57
58namespace details
59{
60class CppImpl;
61}
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050062
63struct _RingMainWindow
64{
65 GtkApplicationWindow parent;
66};
67
68struct _RingMainWindowClass
69{
70 GtkApplicationWindowClass parent_class;
71};
72
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -050073struct RingMainWindowPrivate
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050074{
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040075 GtkWidget *ring_menu;
76 GtkWidget *image_ring;
77 GtkWidget *ring_settings;
78 GtkWidget *image_settings;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040079 GtkWidget *hbox_settings;
Sébastien Blin55bff9d2017-10-03 15:15:23 -040080 GtkWidget *notebook_contacts;
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -040081 GtkWidget *scrolled_window_smartview;
Stepan Salenikovich09e0b782016-09-07 16:28:50 -040082 GtkWidget *treeview_conversations;
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -040083 GtkWidget *vbox_left_pane;
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -050084 GtkWidget *search_entry;
Stepan Salenikovich69771842015-02-24 18:11:45 -050085 GtkWidget *stack_main_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040086 GtkWidget *vbox_call_view;
Stepan Salenikovich3034d922015-10-09 10:11:42 -040087 GtkWidget *frame_call;
88 GtkWidget *welcome_view;
Sébastien Blin55bff9d2017-10-03 15:15:23 -040089 GtkWidget *button_new_conversation;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040090 GtkWidget *account_settings_view;
Stepan Salenikovich0bd53492015-05-11 14:28:52 -040091 GtkWidget *media_settings_view;
Stepan Salenikovichde896112015-05-11 16:46:33 -040092 GtkWidget *general_settings_view;
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -040093 GtkWidget *last_settings_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040094 GtkWidget *radiobutton_general_settings;
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -040095 GtkWidget *radiobutton_media_settings;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -040096 GtkWidget *radiobutton_account_settings;
aviau69081842016-10-14 14:51:54 -040097 GtkWidget *account_creation_wizard;
98 GtkWidget *account_migration_view;
Nicolas Jager15a8b902017-03-21 07:53:06 -040099 GtkWidget *combobox_account_selector;
Nicolas Jager0efc8432017-03-22 16:22:00 -0400100 GtkWidget *treeview_contact_requests;
101 GtkWidget *scrolled_window_contact_requests;
Guillaume Roguez0a411202017-05-25 15:27:26 -0400102 GtkWidget *image_contact_requests_list;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500103 GtkWidget *webkit_chat_container; ///< The webkit_chat_container is created once, then reused for all chat views
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400104
105 GSettings *settings;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400106
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500107 details::CppImpl* cpp; ///< Non-UI and C++ only code
Stepan Salenikovich434b88f2015-02-19 17:49:08 -0500108};
109
110G_DEFINE_TYPE_WITH_PRIVATE(RingMainWindow, ring_main_window, GTK_TYPE_APPLICATION_WINDOW);
111
112#define RING_MAIN_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_MAIN_WINDOW_TYPE, RingMainWindowPrivate))
113
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500114//==============================================================================
115
116inline namespace details
117{
118
119static constexpr const char* CALL_VIEW_NAME = "calls";
120static constexpr const char* ACCOUNT_CREATION_WIZARD_VIEW_NAME = "account-creation-wizard";
121static constexpr const char* ACCOUNT_MIGRATION_VIEW_NAME = "account-migration-view";
122static constexpr const char* GENERAL_SETTINGS_VIEW_NAME = "general";
123static constexpr const char* MEDIA_SETTINGS_VIEW_NAME = "media";
124static constexpr const char* ACCOUNT_SETTINGS_VIEW_NAME = "accounts";
125
126class CppImpl
127{
128public:
129 explicit CppImpl(RingMainWindow& widget);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500130 ~CppImpl();
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500131
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500132 void init();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500133 void updateLrc(const std::string& accountId);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500134 void changeView(GType type, lrc::api::conversation::Info conversation = {});
Guillaume Roguez11339f82017-12-12 23:15:34 -0500135 WebKitChatContainer* webkitChatContainer() const;
Guillaume Roguez1d963272017-12-12 23:32:13 -0500136 void enterFullScreen();
137 void leaveFullScreen();
138 void toggleFullScreen();
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500139 void resetToWelcome();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500140 void setPendingContactRequestTabIcon();
141 void showAccountSelectorWidget(bool show = true);
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500142 void useAccount(const std::string& id);
143 void onAccountAddedFromLrc(const std::string& id);
144 void onAccountRemovedFromLrc(const std::string& id);
145 void onAccountChangeFromLrc(const std::string& id);
146 void onAccountChangeFromUI(const std::string& id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500147 void enterAccountCreationWizard();
148 void leaveAccountCreationWizard();
149 void enterSettingsView();
150 void leaveSettingsView();
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500151
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500152 RingMainWindow* self = nullptr; // The GTK widget itself
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500153 RingMainWindowPrivate* widgets = nullptr;
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500154
Guillaume Roguez6f431372017-12-12 21:15:39 -0500155 std::unique_ptr<lrc::api::Lrc> lrc_;
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500156 std::unique_ptr<AccountContainer> accountContainer_;
157 std::unique_ptr<lrc::api::conversation::Info> chatViewConversation_;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500158 lrc::api::profile::Type currentTypeFilter_;
159 bool show_settings = false;
160 bool is_fullscreen = false;
161
162 QMetaObject::Connection selected_item_changed;
163 QMetaObject::Connection selected_call_over;
164 QMetaObject::Connection showChatViewConnection_;
165 QMetaObject::Connection showCallViewConnection_;
166 QMetaObject::Connection showIncomingViewConnection_;
167 QMetaObject::Connection changeAccountConnection_;
168 QMetaObject::Connection newAccountConnection_;
169 QMetaObject::Connection rmAccountConnection_;
170 QMetaObject::Connection historyClearedConnection_;
171 QMetaObject::Connection modelSortedConnection_;
172 QMetaObject::Connection filterChangedConnection_;
173 QMetaObject::Connection newConversationConnection_;
174 QMetaObject::Connection conversationRemovedConnection_;
175 QMetaObject::Connection accountStatusChangedConnection_;
176
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500177private:
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500178 GtkWidget* displayIncomingView(lrc::api::conversation::Info);
179 GtkWidget* displayCurrentCallView(lrc::api::conversation::Info);
180 GtkWidget* displayChatView(lrc::api::conversation::Info);
181
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500182 CppImpl() = delete;
183 CppImpl(const CppImpl&) = delete;
184 CppImpl& operator=(const CppImpl&) = delete;
185};
186
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500187inline namespace gtk_callbacks
188{
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500189
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400190static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500191on_save_accounts_timeout(GtkWidget* working_dialog)
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400192{
193 /* save changes to accounts */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400194 AccountModel::instance().save();
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400195
196 if (working_dialog)
197 gtk_widget_destroy(working_dialog);
198
199 return G_SOURCE_REMOVE;
200}
201
Stepan Salenikovich15142182015-03-11 17:15:26 -0400202static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500203on_video_double_clicked(RingMainWindow* self)
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400204{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500205 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
206 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
207 priv->cpp->toggleFullScreen();
208}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400209
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500210static void
211on_hide_view_clicked(RingMainWindow* self)
212{
213 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
214 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
215 priv->cpp->resetToWelcome();
216}
Stepan Salenikovichbd4b3772015-12-13 23:28:06 -0500217
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500218static void
219on_account_creation_completed(RingMainWindow* self)
220{
221 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
222 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
223 priv->cpp->leaveAccountCreationWizard();
224}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400225
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500226static void
227on_account_changed(RingMainWindow* self)
228{
229 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
230 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400231
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500232 auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector);
233 auto model = gtk_combo_box_get_model(accountComboBox);
Stepan Salenikovich41118912015-05-01 11:25:46 -0400234
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500235 GtkTreeIter iter;
236 if (gtk_combo_box_get_active_iter(accountComboBox, &iter)) {
237 gchar* accountId;
238 gtk_tree_model_get(model, &iter, 0 /* col# */, &accountId /* data */, -1);
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500239 priv->cpp->onAccountChangeFromUI(accountId);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500240 g_free(accountId);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400241 }
242}
243
244static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500245on_settings_clicked(RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400246{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500247 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
248 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
249
250 if (!priv->cpp->show_settings)
251 priv->cpp->enterSettingsView();
252 else
253 priv->cpp->leaveSettingsView();
254}
255
256static void
257on_show_media_settings(GtkToggleButton* navbutton, RingMainWindow* self)
258{
259 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
260 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400261
262 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400263 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -0400264 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), MEDIA_SETTINGS_VIEW_NAME);
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400265 priv->last_settings_view = priv->media_settings_view;
Stepan Salenikovich41118912015-05-01 11:25:46 -0400266 } else {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400267 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400268 }
269}
270
271static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500272on_show_account_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400273{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500274 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
275 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400276
277 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400278 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), ACCOUNT_SETTINGS_VIEW_NAME);
279 priv->last_settings_view = priv->account_settings_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400280 }
281}
282
Stepan Salenikovichde896112015-05-11 16:46:33 -0400283static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500284on_show_general_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichde896112015-05-11 16:46:33 -0400285{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500286 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
287 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichde896112015-05-11 16:46:33 -0400288
289 if (gtk_toggle_button_get_active(navbutton)) {
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400290 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400291 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME);
292 priv->last_settings_view = priv->general_settings_view;
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400293 } else {
294 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400295 }
296}
297
Stepan Salenikovichb8e41272015-03-27 14:31:54 -0400298static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500299on_search_entry_text_changed(GtkSearchEntry* search_entry, RingMainWindow* self)
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400300{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500301 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
302 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400303
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400304 // Filter model
305 const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry));
Guillaume Roguez6f431372017-12-12 21:15:39 -0500306 priv->cpp->accountContainer_->info.conversationModel->setFilter(text);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400307}
308
309static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500310on_search_entry_activated(RingMainWindow* self)
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400311{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500312 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
313 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
314
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400315 // Select the first conversation of the list
Guillaume Roguez6f431372017-12-12 21:15:39 -0500316 auto& conversationModel = priv->cpp->accountContainer_->info.conversationModel;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400317 auto conversations = conversationModel->allFilteredConversations();
318 if (!conversations.empty())
319 conversationModel->selectConversation(conversations[0].uid);
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400320}
321
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400322static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500323on_search_entry_key_released(G_GNUC_UNUSED GtkEntry* search_entry, GdkEventKey* key, RingMainWindow* self)
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400324{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500325 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
326 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400327
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400328 // if esc key pressed, clear the regex (keep the text, the user might not want to actually delete it)
329 if (key->keyval == GDK_KEY_Escape) {
Guillaume Roguez6f431372017-12-12 21:15:39 -0500330 priv->cpp->accountContainer_->info.conversationModel->setFilter("");
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400331 return GDK_EVENT_STOP;
332 }
333
334 return GDK_EVENT_PROPAGATE;
335}
336
337static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500338on_dtmf_pressed(RingMainWindow* self, GdkEventKey* event, gpointer user_data)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400339{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500340 (void)user_data;
341
342 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
343 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
344
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400345 g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400346 g_return_val_if_fail(priv, GDK_EVENT_PROPAGATE);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400347
348 /* we want to react to digit key presses, as long as a GtkEntry is not the
349 * input focus
350 */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500351 GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(self));
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400352 if (GTK_IS_ENTRY(focus))
353 return GDK_EVENT_PROPAGATE;
354
Guillaume Roguez6f431372017-12-12 21:15:39 -0500355 if (priv->cpp->accountContainer_ &&
356 priv->cpp->accountContainer_->info.profileInfo.type != lrc::api::profile::Type::SIP)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400357 return GDK_EVENT_PROPAGATE;
358
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400359 /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c'
360 * does not result in a 'c' being played.
361 * we filter Ctrl, Alt, and SUPER/HYPER/META keys */
362 if ( event->state
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400363 & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ))
364 return GDK_EVENT_PROPAGATE;
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400365
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400366 // Get current conversation
367 auto current_view = gtk_bin_get_child(GTK_BIN(priv->frame_call));
368 lrc::api::conversation::Info current_item;
369 if (IS_CURRENT_CALL_VIEW(current_view))
370 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(current_view));
371 else
372 return GDK_EVENT_PROPAGATE;
373
374 if (current_item.callId.empty())
375 return GDK_EVENT_PROPAGATE;
376
377 // pass the character that was entered to be played by the daemon;
378 // the daemon will filter out invalid DTMF characters
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400379 guint32 unicode_val = gdk_keyval_to_unicode(event->keyval);
380 QString val = QString::fromUcs4(&unicode_val, 1);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400381 g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData());
Guillaume Roguez6f431372017-12-12 21:15:39 -0500382 priv->cpp->accountContainer_->info.callModel->playDTMF(current_item.callId, val.toStdString());
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400383 // always propogate the key, so we don't steal accelerators/shortcuts
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400384 return GDK_EVENT_PROPAGATE;
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400385}
386
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400387static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500388on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainWindow* self)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400389{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500390 (void)notebook;
391 (void)page;
392
393 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
394 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
395
Guillaume Roguez6f431372017-12-12 21:15:39 -0500396 auto newType = page_num == 0 ? priv->cpp->accountContainer_->info.profileInfo.type : lrc::api::profile::Type::PENDING;
397 if (priv->cpp->currentTypeFilter_ != newType) {
398 priv->cpp->currentTypeFilter_ = newType;
399 priv->cpp->accountContainer_->info.conversationModel->setFilter(priv->cpp->currentTypeFilter_);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400400 }
Nicolas Jager0efc8432017-03-22 16:22:00 -0400401}
402
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400403static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500404on_window_size_changed(GtkWidget* self, GdkEventConfigure* event, gpointer user_data)
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400405{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500406 (void)user_data;
407
408 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
409 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400410
411 g_settings_set_int(priv->settings, "window-width", event->width);
412 g_settings_set_int(priv->settings, "window-height", event->height);
413
414 return GDK_EVENT_PROPAGATE;
415}
416
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400417static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500418on_search_entry_places_call_changed(GSettings* settings, const gchar* key, RingMainWindow* self)
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400419{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500420 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
421 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400422
423 if (g_settings_get_boolean(settings, key)) {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500424 gtk_widget_set_tooltip_text(priv->button_new_conversation,
425 C_("button next to search entry will place a new call",
426 "place call"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400427 } else {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500428 gtk_widget_set_tooltip_text(priv->button_new_conversation,
429 C_("button next to search entry will open chat", "open chat"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400430 }
431}
432
433static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500434on_handle_account_migrations(RingMainWindow* self)
aviau6aeb4852016-08-18 16:01:09 -0400435{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500436 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
437 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
aviau6aeb4852016-08-18 16:01:09 -0400438
439 /* If there is an existing migration view, remove it */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500440 if (priv->account_migration_view) {
Stepan Salenikovich56530b12016-10-20 17:51:34 -0400441 gtk_widget_destroy(priv->account_migration_view);
442 priv->account_migration_view = nullptr;
aviau6aeb4852016-08-18 16:01:09 -0400443 }
444
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500445 auto accounts = AccountModel::instance().accountsToMigrate();
446 if (!accounts.isEmpty()) {
447 auto* account = accounts.first();
aviau6aeb4852016-08-18 16:01:09 -0400448
aviau69081842016-10-14 14:51:54 -0400449 priv->account_migration_view = account_migration_view_new(account);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500450 g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed",
451 G_CALLBACK(on_handle_account_migrations), self);
452 g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed",
453 G_CALLBACK(on_handle_account_migrations), self);
aviau6aeb4852016-08-18 16:01:09 -0400454
455 gtk_widget_hide(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500456 priv->cpp->showAccountSelectorWidget(false);
aviau69081842016-10-14 14:51:54 -0400457 gtk_widget_show(priv->account_migration_view);
aviau6aeb4852016-08-18 16:01:09 -0400458 gtk_stack_add_named(
459 GTK_STACK(priv->stack_main_view),
aviau69081842016-10-14 14:51:54 -0400460 priv->account_migration_view,
aviau6aeb4852016-08-18 16:01:09 -0400461 ACCOUNT_MIGRATION_VIEW_NAME
462 );
463 gtk_stack_set_visible_child_name(
464 GTK_STACK(priv->stack_main_view),
465 ACCOUNT_MIGRATION_VIEW_NAME
466 );
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500467 } else {
aviau6aeb4852016-08-18 16:01:09 -0400468 gtk_widget_show(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500469 priv->cpp->showAccountSelectorWidget();
aviau6aeb4852016-08-18 16:01:09 -0400470 }
471}
472
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500473} // namespace gtk_callbacks
474
Nicolas Jager5e2be732017-03-18 21:35:50 -0400475/**
476 * set the column value by printing the alias and the state of an account in combobox_account_selector.
477 */
478static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500479print_account_and_state(GtkCellLayout* cell_layout,
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400480 GtkCellRenderer* cell,
481 GtkTreeModel* model,
Nicolas Jager5e2be732017-03-18 21:35:50 -0400482 GtkTreeIter* iter,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500483 gpointer* data)
Nicolas Jager5e2be732017-03-18 21:35:50 -0400484{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500485 (void)cell_layout;
486 (void)data;
487
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400488 gchar *alias;
489 gchar *text;
Nicolas Jager5e2be732017-03-18 21:35:50 -0400490
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400491 gtk_tree_model_get (model, iter,
492 1 /* col# */, &alias /* data */,
493 -1);
Nicolas Jager5e2be732017-03-18 21:35:50 -0400494
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400495 text = g_markup_printf_escaped(
496 "<span fgcolor=\"gray\">%s</span>",
497 alias
498 );
Nicolas Jager5e2be732017-03-18 21:35:50 -0400499
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400500 g_object_set(G_OBJECT(cell), "markup", text, NULL);
501 g_free(alias);
Nicolas Jager5e2be732017-03-18 21:35:50 -0400502}
503
Guillaume Roguez7e238402017-12-13 19:40:05 -0500504inline static void
505foreachEnabledLrcAccount(const lrc::api::Lrc& lrc,
506 const std::function<void(const lrc::api::account::Info&)>& func)
507{
508 auto& acc_model = lrc.getAccountModel();
509 for (const auto& id : acc_model.getAccountList()) {
510 const auto& accountInfo = acc_model.getAccountInfo(id);
511 if (accountInfo.enabled)
512 func(accountInfo);
513 }
514}
515
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500516CppImpl::CppImpl(RingMainWindow& widget)
517 : self {&widget}
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500518 , widgets {RING_MAIN_WINDOW_GET_PRIVATE(&widget)}
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500519 , lrc_ {std::make_unique<lrc::api::Lrc>()}
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500520{}
521
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500522void
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500523CppImpl::init()
524{
525 // NOTE: When new models will be fully implemented, we need to move this
526 // in rign_client.cpp->
527 // Init LRC and the vew
528 const auto accountIds = lrc_->getAccountModel().getAccountList();
529 auto isInitialized = false;
530 if (not accountIds.empty()) {
531 for (const auto& accountId : accountIds) {
532 const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId);
533 if (accountInfo.enabled) {
534 updateLrc(accountId);
535 isInitialized = true;
536 break;
537 }
538 }
539 if (!isInitialized) {
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500540 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500541 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500542 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500543 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500544 }
545 }
546
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500547 accountStatusChangedConnection_ = QObject::connect(&lrc_->getAccountModel(),
548 &lrc::api::NewAccountModel::accountStatusChanged,
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500549 [this](const std::string& v){ onAccountChangeFromLrc(v); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500550 newAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500551 &lrc::api::NewAccountModel::accountAdded,
552 [this](const std::string& v){ onAccountAddedFromLrc(v); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500553 rmAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
554 &lrc::api::NewAccountModel::accountRemoved,
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500555 [this](const std::string& v){ onAccountRemovedFromLrc(v); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500556
557 /* bind to window size settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500558 widgets->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr);
559 auto width = g_settings_get_int(widgets->settings, "window-width");
560 auto height = g_settings_get_int(widgets->settings, "window-height");
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500561 gtk_window_set_default_size(GTK_WINDOW(self), width, height);
562 g_signal_connect(self, "configure-event", G_CALLBACK(on_window_size_changed), nullptr);
563
564 /* search-entry-places-call setting */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500565 on_search_entry_places_call_changed(widgets->settings, "search-entry-places-call", self);
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500566 g_signal_connect(widgets->settings, "changed::search-entry-places-call",
567 G_CALLBACK(on_search_entry_places_call_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500568
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500569 /* set window icon */
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500570 GError *error = NULL;
571 GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error);
572 if (icon == NULL) {
573 g_debug("Could not load icon: %s", error->message);
574 g_clear_error(&error);
575 } else
576 gtk_window_set_icon(GTK_WINDOW(self), icon);
577
578 /* set menu icon */
579 GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue",
580 -1, 16, TRUE, &error);
581 if (image_ring == NULL) {
582 g_debug("Could not load icon: %s", error->message);
583 g_clear_error(&error);
584 } else
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500585 gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_ring), image_ring);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500586
587 /* ring menu */
588 GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui");
589 GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu"));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500590 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(widgets->ring_menu), menu);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500591 g_object_unref(builder);
592
593 /* settings icon */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500594 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
595 GTK_ICON_SIZE_SMALL_TOOLBAR);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500596
597 /* connect settings button signal */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500598 g_signal_connect_swapped(widgets->ring_settings, "clicked",
599 G_CALLBACK(on_settings_clicked), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500600
601 /* add the call view to the main stack */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500602 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500603 CALL_VIEW_NAME);
604
605 /* init the settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500606 widgets->account_settings_view = account_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500607 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->account_settings_view,
608 ACCOUNT_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500609
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500610 widgets->media_settings_view = media_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500611 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->media_settings_view,
612 MEDIA_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500613
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500614 widgets->general_settings_view = general_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500615 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view,
616 GENERAL_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500617
618 /* make the setting we will show first the active one */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500619 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE);
620 widgets->last_settings_view = widgets->general_settings_view;
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500621
622 /* connect the settings button signals to switch settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500623 g_signal_connect(widgets->radiobutton_media_settings, "toggled", G_CALLBACK(on_show_media_settings), self);
624 g_signal_connect(widgets->radiobutton_account_settings, "toggled", G_CALLBACK(on_show_account_settings), self);
625 g_signal_connect(widgets->radiobutton_general_settings, "toggled", G_CALLBACK(on_show_general_settings), self);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500626 g_signal_connect(widgets->notebook_contacts, "switch-page", G_CALLBACK(on_tab_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500627
628 /* welcome/default view */
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500629 widgets->welcome_view = ring_welcome_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500630 g_object_ref(widgets->welcome_view); // increase ref because don't want it to be destroyed when not displayed
631 gtk_container_add(GTK_CONTAINER(widgets->frame_call), widgets->welcome_view);
632 gtk_widget_show(widgets->welcome_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500633
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500634 g_signal_connect_swapped(widgets->search_entry, "activate", G_CALLBACK(on_search_entry_activated), self);
635 g_signal_connect_swapped(widgets->button_new_conversation, "clicked", G_CALLBACK(on_search_entry_activated), self);
636 g_signal_connect(widgets->search_entry, "search-changed", G_CALLBACK(on_search_entry_text_changed), self);
637 g_signal_connect(widgets->search_entry, "key-release-event", G_CALLBACK(on_search_entry_key_released), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500638
639 auto provider = gtk_css_provider_new();
640 gtk_css_provider_load_from_data(provider,
641 ".search-entry-style { border: 0; border-radius: 0; } \
642 .spinner-style { border: 0; background: white; } \
643 .new-conversation-style { border: 0; background: white; transition: all 0.3s ease; border-radius: 0; } \
644 .new-conversation-style:hover { background: #bae5f0; }",
645 -1, nullptr
646 );
647 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
648 GTK_STYLE_PROVIDER(provider),
649 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
650
651
652 /* react to digit key press events */
653 g_signal_connect(self, "key-press-event", G_CALLBACK(on_dtmf_pressed), nullptr);
654
655 /* set the search entry placeholder text */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500656 gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->search_entry),
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500657 C_("Please try to make the translation 50 chars or less so that it fits into the layout",
658 "Search contacts or enter number"));
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500659
660 /* init chat webkit container so that it starts loading before the first time we need it*/
661 (void)webkitChatContainer();
662
663 if (has_ring_account()) {
664 /* user has ring account, so show the call view right away */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500665 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500666
667 on_handle_account_migrations(self);
668 } else {
669 /* user has to create the ring account */
670 enterAccountCreationWizard();
671 }
672
673 // setup account selector and select the first account
674 auto store = gtk_list_store_new (2 /* # of cols */ ,
675 G_TYPE_STRING,
676 G_TYPE_STRING,
677 G_TYPE_UINT);
678 GtkTreeIter iter;
Guillaume Roguez7e238402017-12-13 19:40:05 -0500679 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500680 gtk_list_store_append (store, &iter);
681 gtk_list_store_set (store, &iter,
Guillaume Roguez7e238402017-12-13 19:40:05 -0500682 0 /* col # */ , acc_info.id.c_str() /* celldata */,
683 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500684 -1 /* end */);
Guillaume Roguez7e238402017-12-13 19:40:05 -0500685 });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500686
687 gtk_combo_box_set_model(
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500688 GTK_COMBO_BOX(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500689 GTK_TREE_MODEL (store)
690 );
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500691 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500692
693 /* set visibility */
694 showAccountSelectorWidget();
695
696 /* layout */
697 auto *renderer = gtk_cell_renderer_text_new();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500698 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, FALSE);
699 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, "text", 0, NULL);
700 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500701 renderer,
702 (GtkCellLayoutDataFunc)print_account_and_state,
703 nullptr, nullptr);
704
705 // we closing any view opened to avoid confusion (especially between SIP and Ring protocols).
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500706 g_signal_connect_swapped(widgets->combobox_account_selector, "changed", G_CALLBACK(on_account_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500707
708 // initialize the pending contact request icon.
709 setPendingContactRequestTabIcon();
710
711 if (isInitialized) {
712 auto& conversationModel = accountContainer_->info.conversationModel;
713 auto conversations = conversationModel->allFilteredConversations();
714 for (const auto& conversation: conversations) {
715 if (!conversation.callId.empty()) {
716 accountContainer_->info.conversationModel->selectConversation(conversation.uid);
717 }
718 }
719 }
720}
721
722CppImpl::~CppImpl()
723{
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500724 QObject::disconnect(selected_item_changed);
725 QObject::disconnect(selected_call_over);
726 QObject::disconnect(showChatViewConnection_);
727 QObject::disconnect(showIncomingViewConnection_);
728 QObject::disconnect(historyClearedConnection_);
729 QObject::disconnect(modelSortedConnection_);
730 QObject::disconnect(filterChangedConnection_);
731 QObject::disconnect(newConversationConnection_);
732 QObject::disconnect(conversationRemovedConnection_);
733 QObject::disconnect(changeAccountConnection_);
734 QObject::disconnect(newAccountConnection_);
735 QObject::disconnect(rmAccountConnection_);
736 QObject::disconnect(showCallViewConnection_);
737 QObject::disconnect(modelSortedConnection_);
738 QObject::disconnect(accountStatusChangedConnection_);
739
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500740 g_clear_object(&widgets->welcome_view);
741 g_clear_object(&widgets->webkit_chat_container);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500742}
743
744void
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500745CppImpl::changeView(GType type, lrc::api::conversation::Info conversation)
746{
Guillaume Roguez1d963272017-12-12 23:32:13 -0500747 leaveFullScreen();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500748 gtk_container_remove(GTK_CONTAINER(widgets->frame_call),
749 gtk_bin_get_child(GTK_BIN(widgets->frame_call)));
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500750
751 QObject::disconnect(selected_item_changed);
752 QObject::disconnect(selected_call_over);
753
754 GtkWidget* new_view;
755 if (g_type_is_a(INCOMING_CALL_VIEW_TYPE, type)) {
756 new_view = displayIncomingView(conversation);
757 } else if (g_type_is_a(CURRENT_CALL_VIEW_TYPE, type)) {
758 new_view = displayCurrentCallView(conversation);
759 } else if (g_type_is_a(CHAT_VIEW_TYPE, type)) {
760 new_view = displayChatView(conversation);
761 } else {
762 // TODO select first conversation?
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500763 new_view = widgets->welcome_view;
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500764 }
765
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500766 gtk_container_add(GTK_CONTAINER(widgets->frame_call), new_view);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500767 gtk_widget_show(new_view);
768}
769
770GtkWidget*
771CppImpl::displayIncomingView(lrc::api::conversation::Info conversation)
772{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500773 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
774 return incoming_call_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500775}
776
777GtkWidget*
778CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation)
779{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500780 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
Guillaume Roguez11339f82017-12-12 23:15:34 -0500781 auto* new_view = current_call_view_new(webkitChatContainer(),
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500782 accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500783
784 try {
785 auto contactUri = chatViewConversation_->participants.front();
786 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
787 if (auto chat_view = current_call_view_get_chat_view(CURRENT_CALL_VIEW(new_view))) {
788 chat_view_update_temporary(CHAT_VIEW(chat_view),
789 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
790 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
791 }
792 } catch(...) { }
793
Guillaume Roguez1d963272017-12-12 23:32:13 -0500794 g_signal_connect_swapped(new_view, "video-double-clicked",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500795 G_CALLBACK(on_video_double_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500796 return new_view;
797}
798
799GtkWidget*
800CppImpl::displayChatView(lrc::api::conversation::Info conversation)
801{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500802 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
803 auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500804 g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500805 return new_view;
806}
807
Guillaume Roguez11339f82017-12-12 23:15:34 -0500808WebKitChatContainer*
809CppImpl::webkitChatContainer() const
810{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500811 if (!widgets->webkit_chat_container) {
812 widgets->webkit_chat_container = webkit_chat_container_new();
Guillaume Roguez11339f82017-12-12 23:15:34 -0500813
814 // We don't want it to be deleted, ever.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500815 g_object_ref(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500816 }
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500817 return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500818}
819
Guillaume Roguez1d963272017-12-12 23:32:13 -0500820void
821CppImpl::enterFullScreen()
822{
823 if (!is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500824 gtk_widget_hide(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500825 gtk_window_fullscreen(GTK_WINDOW(self));
826 is_fullscreen = true;
827 }
828}
829
830void
831CppImpl::leaveFullScreen()
832{
833 if (is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500834 gtk_widget_show(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500835 gtk_window_unfullscreen(GTK_WINDOW(self));
836 is_fullscreen = false;
837 }
838}
839
840void
841CppImpl::toggleFullScreen()
842{
843 if (is_fullscreen)
844 leaveFullScreen();
845 else
846 enterFullScreen();
847}
848
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500849/// Clear selection and go to welcome page.
850void
851CppImpl::resetToWelcome()
852{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500853 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500854 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500855 auto selection_contact_request = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500856 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500857 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500858 lrc::api::conversation::Info current_item;
859 if (IS_CHAT_VIEW(old_view))
860 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
861 changeView(RING_WELCOME_VIEW_TYPE, current_item);
862}
863
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500864void
865CppImpl::setPendingContactRequestTabIcon()
866{
867 if (not accountContainer_)
868 return;
869
870 auto isRingAccount = accountContainer_->info.profileInfo.type == lrc::api::profile::Type::RING;
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500871 gtk_widget_set_visible(widgets->scrolled_window_contact_requests, isRingAccount);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500872
873 if (not isRingAccount)
874 return;
875
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500876 gtk_image_set_from_resource(GTK_IMAGE(widgets->image_contact_requests_list),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500877 (accountContainer_->info.contactModel->hasPendingRequests())
878 ? "/cx/ring/RingGnome/contact_requests_list_with_notification"
879 : "/cx/ring/RingGnome/contact_requests_list");
880}
881
882void
883CppImpl::showAccountSelectorWidget(bool show)
884{
885 // we only want to show the account selector when there is more than 1 enabled
886 // account; so every time we want to show it, we should preform this check
Guillaume Roguez7e238402017-12-13 19:40:05 -0500887 std::size_t activatedAccount = 0;
888 foreachEnabledLrcAccount(*lrc_, [&] (const auto&) { ++activatedAccount; });
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500889 gtk_widget_set_visible(widgets->combobox_account_selector, show && activatedAccount > 1);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500890}
891
892void
893CppImpl::enterAccountCreationWizard()
894{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500895 if (!widgets->account_creation_wizard) {
896 widgets->account_creation_wizard = account_creation_wizard_new(false);
897 g_object_add_weak_pointer(G_OBJECT(widgets->account_creation_wizard),
898 reinterpret_cast<gpointer*>(&widgets->account_creation_wizard));
899 g_signal_connect_swapped(widgets->account_creation_wizard, "account-creation-completed",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500900 G_CALLBACK(on_account_creation_completed), self);
901
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500902 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view),
903 widgets->account_creation_wizard,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500904 ACCOUNT_CREATION_WIZARD_VIEW_NAME);
905 }
906
907 /* hide settings button until account creation is complete */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500908 gtk_widget_hide(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500909 showAccountSelectorWidget(false);
910
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500911 gtk_widget_show(widgets->account_creation_wizard);
912 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->account_creation_wizard);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500913}
914
915void
916CppImpl::leaveAccountCreationWizard()
917{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500918 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500919
920 /* destroy the wizard */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500921 if (widgets->account_creation_wizard) {
922 gtk_container_remove(GTK_CONTAINER(widgets->stack_main_view), widgets->account_creation_wizard);
923 gtk_widget_destroy(widgets->account_creation_wizard);
924 widgets->account_creation_wizard = nullptr;
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500925 }
926
927 /* show the settings button */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500928 gtk_widget_show(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500929
930 /* show the account selector */
931 showAccountSelectorWidget();
932}
933
934void
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500935CppImpl::useAccount(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500936{
937 // Go to welcome view
938 changeView(RING_WELCOME_VIEW_TYPE);
939
940 // Change account selection widget
941 auto accounts = lrc_->getAccountModel().getAccountList();
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500942 auto it = std::find(accounts.begin(), accounts.end(), id );
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500943 if (it == accounts.end()) {
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500944 qDebug() << "useAccount, cannot find account " << id.c_str();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500945 return;
946 }
947
948 int row = it - accounts.begin();
949
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500950 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), row);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500951 // Show conversation panel
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500952 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500953 // Reinit LRC
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500954 updateLrc(std::string(id));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500955 // Update the welcome view
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500956 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500957}
958
959void
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500960CppImpl::onAccountAddedFromLrc(const std::string& id)
961{
962 (void)id;
963
964 // go to this account
965 auto accounts = lrc_->getAccountModel().getAccountList();
966 auto store = gtk_list_store_new (2 /* # of cols */ ,
967 G_TYPE_STRING,
968 G_TYPE_STRING,
969 G_TYPE_UINT);
970 auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
971 GtkTreeIter iter;
Guillaume Roguez7e238402017-12-13 19:40:05 -0500972 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500973 gtk_list_store_append (store, &iter);
974 gtk_list_store_set (store, &iter,
Guillaume Roguez7e238402017-12-13 19:40:05 -0500975 0 /* col # */ , acc_info.id.c_str() /* celldata */,
976 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500977 -1 /* end */);
Guillaume Roguez7e238402017-12-13 19:40:05 -0500978 });
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500979 // Redraw combobox
980 gtk_combo_box_set_model(
981 GTK_COMBO_BOX(widgets->combobox_account_selector),
982 GTK_TREE_MODEL (store)
983 );
984 // If no account selected, select the new account
985 if (currentIdx == -1) currentIdx = 0;
986 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx);
987 showAccountSelectorWidget();
988}
989
990void
991CppImpl::onAccountRemovedFromLrc(const std::string& id)
992{
993 (void)id;
994
995 auto accounts = lrc_->getAccountModel().getAccountList();
996 if (accounts.empty()) {
997 enterAccountCreationWizard();
998 return;
999 }
1000
1001 auto store = gtk_list_store_new (2 /* # of cols */ ,
1002 G_TYPE_STRING,
1003 G_TYPE_STRING,
1004 G_TYPE_UINT);
1005 GtkTreeIter iter;
Guillaume Roguez7e238402017-12-13 19:40:05 -05001006 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001007 gtk_list_store_append (store, &iter);
1008 gtk_list_store_set (store, &iter,
Guillaume Roguez7e238402017-12-13 19:40:05 -05001009 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1010 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001011 -1 /* end */);
Guillaume Roguez7e238402017-12-13 19:40:05 -05001012 });
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001013 gtk_combo_box_set_model(
1014 GTK_COMBO_BOX(widgets->combobox_account_selector),
1015 GTK_TREE_MODEL (store)
1016 );
1017 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0);
1018 showAccountSelectorWidget();
1019 // Show conversation panel
1020 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
1021 // Reinit LRC
1022 updateLrc(std::string(accounts.at(0)));
1023 // Update the welcome view
1024 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
1025}
1026
1027void
1028CppImpl::onAccountChangeFromLrc(const std::string& id)
1029{
1030 if (not accountContainer_ ) {
1031 updateLrc(id);
1032 if (accountContainer_)
1033 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view),
1034 accountContainer_.get());
1035 return;
1036 }
1037
1038 auto accounts = lrc_->getAccountModel().getAccountList();
1039 auto store = gtk_list_store_new (2 /* # of cols */ ,
1040 G_TYPE_STRING,
1041 G_TYPE_STRING,
1042 G_TYPE_UINT);
Guillaume Roguez7e238402017-12-13 19:40:05 -05001043
1044 gint currentIdx = 0;
1045 std::size_t enabledAccounts = 0;
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001046 GtkTreeIter iter;
Guillaume Roguez7e238402017-12-13 19:40:05 -05001047 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001048 ++enabledAccounts;
1049 gtk_list_store_append (store, &iter);
1050 gtk_list_store_set (store, &iter,
Guillaume Roguez7e238402017-12-13 19:40:05 -05001051 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1052 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001053 -1 /* end */);
Guillaume Roguez7e238402017-12-13 19:40:05 -05001054 if (id == acc_info.id) {
1055 // keep current selected account only if account status is enabled
1056 currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
1057 }
1058 });
1059 showAccountSelectorWidget();
1060
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001061 // Redraw combobox
1062 gtk_combo_box_set_model(
1063 GTK_COMBO_BOX(widgets->combobox_account_selector),
1064 GTK_TREE_MODEL (store)
1065 );
1066 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx);
1067 // if no account. reset the view.
1068 if (enabledAccounts == 0) {
1069 updateLrc("");
1070 changeView(RING_WELCOME_VIEW_TYPE);
1071 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), nullptr);
1072 }
1073}
1074
1075void
1076CppImpl::onAccountChangeFromUI(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001077{
1078 // Reinit view
1079 changeView(RING_WELCOME_VIEW_TYPE);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001080 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001081
1082 // Change account
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001083 updateLrc(id);
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001084 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001085}
1086
1087void
1088CppImpl::enterSettingsView()
1089{
1090 /* show the settings */
1091 show_settings = true;
1092
1093 /* show settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001094 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-ok-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001095 GTK_ICON_SIZE_SMALL_TOOLBAR);
1096
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001097 gtk_widget_show(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001098
1099 /* make sure to start preview if we're showing the video settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001100 if (widgets->last_settings_view == widgets->media_settings_view)
1101 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), TRUE);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001102
1103 /* make sure to show the profile if we're showing the general settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001104 if (widgets->last_settings_view == widgets->general_settings_view)
1105 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001106 TRUE);
1107
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001108 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->last_settings_view);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001109}
1110
1111void
1112CppImpl::leaveSettingsView()
1113{
1114 /* hide the settings */
1115 show_settings = false;
1116
1117 /* show working dialog in case save operation takes time */
1118 auto working = ring_dialog_working(GTK_WIDGET(self), nullptr);
1119 gtk_window_present(GTK_WINDOW(working));
1120
1121 /* now save after the time it takes to transition back to the call view (400ms)
1122 * the save doesn't happen before the "working" dialog is presented
1123 * the timeout function should destroy the "working" dialog when done saving
1124 */
1125 g_timeout_add_full(G_PRIORITY_DEFAULT, 400, GSourceFunc(on_save_accounts_timeout), working,
1126 nullptr);
1127
1128 /* show calls */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001129 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001130 GTK_ICON_SIZE_SMALL_TOOLBAR);
1131
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001132 gtk_widget_hide(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001133
1134 /* make sure video preview is stopped, in case it was started */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001135 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), FALSE);
1136 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001137 FALSE);
1138
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001139 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001140
1141 /* show the view which was selected previously */
1142}
1143
1144void
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001145CppImpl::updateLrc(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001146{
1147 // Disconnect old signals.
1148 QObject::disconnect(showChatViewConnection_);
1149 QObject::disconnect(showIncomingViewConnection_);
1150 QObject::disconnect(changeAccountConnection_);
1151 QObject::disconnect(showCallViewConnection_);
1152 QObject::disconnect(modelSortedConnection_);
1153 QObject::disconnect(historyClearedConnection_);
1154 QObject::disconnect(filterChangedConnection_);
1155 QObject::disconnect(newConversationConnection_);
1156 QObject::disconnect(conversationRemovedConnection_);
1157
1158 // Get the account selected
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001159 if (!id.empty())
1160 accountContainer_.reset(new AccountContainer(lrc_->getAccountModel().getAccountInfo(id)));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001161 else
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001162 accountContainer_.reset();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001163
1164 // Reinit tree views
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001165 if (widgets->treeview_conversations) {
1166 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001167 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001168 gtk_widget_destroy(widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001169 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001170 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001171 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001172
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001173 if (widgets->treeview_contact_requests) {
1174 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001175 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001176 gtk_widget_destroy(widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001177 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001178 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001179 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001180
1181 if (!accountContainer_) return;
1182
1183 // define slots (we are using this way because gtk is not a c++ lib)
1184 auto slotConversationCleared = [this] (const std::string& uid) {
1185 // Change the view when the history is cleared.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001186 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001187 lrc::api::conversation::Info current_item;
1188 current_item.uid = "-1"; // Because the Searching item has an empty uid
1189 if (IS_CHAT_VIEW(old_view))
1190 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1191 else
1192 // if incoming or call view we don't want to change the view
1193 return;
1194 if (current_item.uid == uid) {
1195 // We are on the conversation cleared.
1196 // Go to welcome view because user doesn't want this conversation
1197 // TODO go to first conversation?
1198 resetToWelcome();
1199 }
1200 };
1201
1202 auto slotModelSorted = [this] () {
1203 // Synchronize selection when sorted and update pending icon
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001204 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001205 lrc::api::conversation::Info current_item;
1206 current_item.uid = "-1";
1207 if (IS_CHAT_VIEW(old_view))
1208 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1209 else if (IS_CURRENT_CALL_VIEW(old_view))
1210 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1211 else if (IS_INCOMING_CALL_VIEW(old_view))
1212 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001213 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001214 setPendingContactRequestTabIcon();
1215 };
1216
1217 auto slotFilterChanged = [this] () {
1218 // Synchronize selection when filter changes
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001219 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001220 lrc::api::conversation::Info current_item;
1221 current_item.uid = "-1";
1222 if (IS_CHAT_VIEW(old_view))
1223 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1224 else if (IS_CURRENT_CALL_VIEW(old_view))
1225 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1226 else if (IS_INCOMING_CALL_VIEW(old_view))
1227 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001228 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001229 // Get if conversation still exists.
1230 auto& conversationModel = accountContainer_->info.conversationModel;
1231 auto conversations = conversationModel->allFilteredConversations();
1232 auto isInConv = std::find_if(
1233 conversations.begin(), conversations.end(),
1234 [current_item](const lrc::api::conversation::Info& conversation) {
1235 return current_item.uid == conversation.uid;
1236 });
1237 if (IS_CHAT_VIEW(old_view) && isInConv == conversations.end()) {
1238 changeView(RING_WELCOME_VIEW_TYPE);
1239 }
1240 };
1241
1242 auto slotNewConversation = [this] (const std::string& uid) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001243 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001244 accountContainer_->info.conversationModel->setFilter(lrc::api::profile::Type::RING);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001245 gtk_entry_set_text(GTK_ENTRY(widgets->search_entry), "");
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001246 accountContainer_->info.conversationModel->setFilter("");
1247 // Select new conversation if contact added
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001248 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001249 if (IS_RING_WELCOME_VIEW(old_view) || (IS_CHAT_VIEW(old_view) && chat_view_get_temporary(CHAT_VIEW(old_view)))) {
1250 accountContainer_->info.conversationModel->selectConversation(uid);
1251 try {
1252 auto contactUri = chatViewConversation_->participants.front();
1253 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001254 chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001255 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
1256 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
1257 } catch(...) { }
1258 }
1259 };
1260
1261 auto slotConversationRemoved = [this] (const std::string& uid) {
1262 // If contact is removed, go to welcome view
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001263 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001264 lrc::api::conversation::Info current_item;
1265 if (IS_CHAT_VIEW(old_view))
1266 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1267 else if (IS_CURRENT_CALL_VIEW(old_view))
1268 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1269 else if (IS_INCOMING_CALL_VIEW(old_view))
1270 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1271 if (current_item.uid == uid)
1272 changeView(RING_WELCOME_VIEW_TYPE);
1273 };
1274
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001275 auto slotShowChatView = [this] (const std::string& id, lrc::api::conversation::Info origin) {
1276 if (id != accountContainer_->info.id)
1277 useAccount(id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001278 // Show chat view if not in call (unless if it's the same conversation)
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001279 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001280 lrc::api::conversation::Info current_item;
1281 current_item.uid = "-1";
1282 if (IS_CHAT_VIEW(old_view))
1283 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1284 if (current_item.uid != origin.uid) {
1285 if (origin.participants.empty()) return;
1286 auto firstContactUri = origin.participants.front();
1287 auto contactInfo = accountContainer_->info.contactModel->getContact(firstContactUri);
1288 if (contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING && current_item.uid != "-1") return;
1289 changeView(CHAT_VIEW_TYPE, origin);
1290 }
1291 };
1292
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001293 auto slotShowCallView = [this] (const std::string& id, lrc::api::conversation::Info origin) {
1294 if (id != accountContainer_->info.id)
1295 useAccount(id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001296 // Change the view if we want a different view.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001297 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001298
1299 lrc::api::conversation::Info current_item;
1300 if (IS_CURRENT_CALL_VIEW(old_view))
1301 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1302
1303 if (current_item.uid != origin.uid)
1304 changeView(CURRENT_CALL_VIEW_TYPE, origin);
1305 };
1306
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001307 auto slotShowIncomingCallView = [this] (const std::string& id, lrc::api::conversation::Info origin) {
1308 if (id != accountContainer_->info.id)
1309 useAccount(id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001310 // Change the view if we want a different view.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001311 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001312
1313 lrc::api::conversation::Info current_item;
1314 if (IS_INCOMING_CALL_VIEW(old_view))
1315 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1316
1317 if (current_item.uid != origin.uid)
1318 changeView(INCOMING_CALL_VIEW_TYPE, origin);
1319 };
1320
1321 // Connect to signals from LRC
1322 historyClearedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
1323 &lrc::api::ConversationModel::conversationCleared,
1324 slotConversationCleared);
1325
1326 modelSortedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
1327 &lrc::api::ConversationModel::modelSorted,
1328 slotModelSorted);
1329
1330 filterChangedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
1331 &lrc::api::ConversationModel::filterChanged,
1332 slotFilterChanged);
1333
1334 newConversationConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
1335 &lrc::api::ConversationModel::newConversation,
1336 slotNewConversation);
1337
1338 conversationRemovedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
1339 &lrc::api::ConversationModel::conversationRemoved,
1340 slotConversationRemoved);
1341
1342 showChatViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
1343 &lrc::api::BehaviorController::showChatView,
1344 slotShowChatView);
1345
1346 showCallViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
1347 &lrc::api::BehaviorController::showCallView,
1348 slotShowCallView);
1349
1350 showIncomingViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
1351 &lrc::api::BehaviorController::showIncomingCallView,
1352 slotShowIncomingCallView);
1353
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001354 const gchar *text = gtk_entry_get_text(GTK_ENTRY(widgets->search_entry));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001355 currentTypeFilter_ = accountContainer_->info.profileInfo.type;
1356 accountContainer_->info.conversationModel->setFilter(text);
1357 accountContainer_->info.conversationModel->setFilter(currentTypeFilter_);
1358}
1359
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001360} // namespace details
1361
1362//==============================================================================
Guillaume Roguez0a411202017-05-25 15:27:26 -04001363
1364static void
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001365ring_main_window_init(RingMainWindow *win)
1366{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001367 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001368 gtk_widget_init_template(GTK_WIDGET(win));
1369
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001370 // CppImpl ctor
1371 priv->cpp = new details::CppImpl {*win};
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001372 priv->cpp->init();
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001373}
1374
1375static void
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001376ring_main_window_dispose(GObject *object)
1377{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001378 auto* self = RING_MAIN_WINDOW(object);
1379 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001380
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001381 delete priv->cpp;
1382 priv->cpp = nullptr;
1383
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001384 G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object);
1385}
1386
1387static void
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001388ring_main_window_finalize(GObject *object)
1389{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001390 auto* self = RING_MAIN_WINDOW(object);
1391 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichba87ae22016-09-13 14:27:20 -04001392
1393 g_clear_object(&priv->settings);
1394
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001395 G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001396}
1397
1398static void
1399ring_main_window_class_init(RingMainWindowClass *klass)
1400{
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001401 G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize;
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001402 G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001403
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001404 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
1405 "/cx/ring/RingGnome/ringmainwindow.ui");
1406
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001407 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane);
Sébastien Blin55bff9d2017-10-03 15:15:23 -04001408 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, notebook_contacts);
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -04001409 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001410 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu);
1411 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring);
1412 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings);
1413 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001414 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, hbox_settings);
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -05001415 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, search_entry);
Stepan Salenikovich69771842015-02-24 18:11:45 -05001416 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, stack_main_view);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001417 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_call_view);
Stepan Salenikovich3034d922015-10-09 10:11:42 -04001418 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, frame_call);
Stepan Salenikoviche9933242016-06-21 18:08:48 -04001419 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, button_new_conversation );
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001420 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_general_settings);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -04001421 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001422 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings);
Nicolas Jager15a8b902017-03-21 07:53:06 -04001423 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, combobox_account_selector);
Nicolas Jager0efc8432017-03-22 16:22:00 -04001424 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contact_requests);
Guillaume Roguez0a411202017-05-25 15:27:26 -04001425 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_contact_requests_list);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001426}
1427
1428GtkWidget *
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001429ring_main_window_new(GtkApplication *app)
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001430{
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001431 gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL);
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001432 return (GtkWidget *)win;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001433}