blob: daa2663e1b58f6d40dd89885d968ca34d9f3ca54 [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
Guillaume Rogueza4911042017-12-14 16:11:18 -0500126inline namespace helpers
127{
128
129/**
130 * set the column value by printing the alias and the state of an account in combobox_account_selector.
131 */
132static void
133print_account_and_state(GtkCellLayout* cell_layout,
134 GtkCellRenderer* cell,
135 GtkTreeModel* model,
136 GtkTreeIter* iter,
137 gpointer* data)
138{
139 (void)cell_layout;
140 (void)data;
141
142 gchar *alias;
143 gchar *text;
144
145 gtk_tree_model_get (model, iter,
146 1 /* col# */, &alias /* data */,
147 -1);
148
149 text = g_markup_printf_escaped(
150 "<span fgcolor=\"gray\">%s</span>",
151 alias
152 );
153
154 g_object_set(G_OBJECT(cell), "markup", text, NULL);
155 g_free(alias);
156}
157
158inline static void
159foreachEnabledLrcAccount(const lrc::api::Lrc& lrc,
160 const std::function<void(const lrc::api::account::Info&)>& func)
161{
162 auto& acc_model = lrc.getAccountModel();
163 for (const auto& id : acc_model.getAccountList()) {
164 const auto& accountInfo = acc_model.getAccountInfo(id);
165 if (accountInfo.enabled)
166 func(accountInfo);
167 }
168}
169
170} // namespace helpers
171
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500172class CppImpl
173{
174public:
175 explicit CppImpl(RingMainWindow& widget);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500176 ~CppImpl();
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500177
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500178 void init();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500179 void updateLrc(const std::string& accountId);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500180 void changeView(GType type, lrc::api::conversation::Info conversation = {});
Guillaume Roguez11339f82017-12-12 23:15:34 -0500181 WebKitChatContainer* webkitChatContainer() const;
Guillaume Roguez1d963272017-12-12 23:32:13 -0500182 void enterFullScreen();
183 void leaveFullScreen();
184 void toggleFullScreen();
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500185 void resetToWelcome();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500186 void setPendingContactRequestTabIcon();
187 void showAccountSelectorWidget(bool show = true);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500188 void changeAccountSelection(const std::string& id);
189 void onAccountSelectionChange(const std::string& id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500190 void enterAccountCreationWizard();
191 void leaveAccountCreationWizard();
192 void enterSettingsView();
193 void leaveSettingsView();
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500194
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500195 RingMainWindow* self = nullptr; // The GTK widget itself
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500196 RingMainWindowPrivate* widgets = nullptr;
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500197
Guillaume Roguez6f431372017-12-12 21:15:39 -0500198 std::unique_ptr<lrc::api::Lrc> lrc_;
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500199 std::unique_ptr<AccountContainer> accountContainer_;
200 std::unique_ptr<lrc::api::conversation::Info> chatViewConversation_;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500201 lrc::api::profile::Type currentTypeFilter_;
202 bool show_settings = false;
203 bool is_fullscreen = false;
204
Guillaume Roguez6f431372017-12-12 21:15:39 -0500205 QMetaObject::Connection showChatViewConnection_;
206 QMetaObject::Connection showCallViewConnection_;
207 QMetaObject::Connection showIncomingViewConnection_;
208 QMetaObject::Connection changeAccountConnection_;
209 QMetaObject::Connection newAccountConnection_;
210 QMetaObject::Connection rmAccountConnection_;
211 QMetaObject::Connection historyClearedConnection_;
212 QMetaObject::Connection modelSortedConnection_;
213 QMetaObject::Connection filterChangedConnection_;
214 QMetaObject::Connection newConversationConnection_;
215 QMetaObject::Connection conversationRemovedConnection_;
216 QMetaObject::Connection accountStatusChangedConnection_;
217
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500218private:
Guillaume Roguez64236c22017-12-13 20:08:25 -0500219 CppImpl() = delete;
220 CppImpl(const CppImpl&) = delete;
221 CppImpl& operator=(const CppImpl&) = delete;
222
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500223 GtkWidget* displayIncomingView(lrc::api::conversation::Info);
224 GtkWidget* displayCurrentCallView(lrc::api::conversation::Info);
225 GtkWidget* displayChatView(lrc::api::conversation::Info);
226
Guillaume Roguez64236c22017-12-13 20:08:25 -0500227 // Callbacks used as LRC Qt slot
228 void slotAccountAddedFromLrc(const std::string& id);
229 void slotAccountRemovedFromLrc(const std::string& id);
230 void slotAccountStatusChanged(const std::string& id);
231 void slotConversationCleared(const std::string& uid);
232 void slotModelSorted();
233 void slotFilterChanged();
234 void slotNewConversation(const std::string& uid);
235 void slotConversationRemoved(const std::string& uid);
236 void slotShowChatView(const std::string& id, lrc::api::conversation::Info origin);
237 void slotShowCallView(const std::string& id, lrc::api::conversation::Info origin);
238 void slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin);
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500239};
240
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500241inline namespace gtk_callbacks
242{
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500243
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400244static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500245on_save_accounts_timeout(GtkWidget* working_dialog)
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400246{
247 /* save changes to accounts */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400248 AccountModel::instance().save();
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400249
250 if (working_dialog)
251 gtk_widget_destroy(working_dialog);
252
253 return G_SOURCE_REMOVE;
254}
255
Stepan Salenikovich15142182015-03-11 17:15:26 -0400256static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500257on_video_double_clicked(RingMainWindow* self)
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400258{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500259 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
260 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
261 priv->cpp->toggleFullScreen();
262}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400263
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500264static void
265on_hide_view_clicked(RingMainWindow* self)
266{
267 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
268 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
269 priv->cpp->resetToWelcome();
270}
Stepan Salenikovichbd4b3772015-12-13 23:28:06 -0500271
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500272static void
273on_account_creation_completed(RingMainWindow* self)
274{
275 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
276 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
277 priv->cpp->leaveAccountCreationWizard();
278}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400279
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500280static void
281on_account_changed(RingMainWindow* self)
282{
283 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
284 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400285
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500286 auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector);
287 auto model = gtk_combo_box_get_model(accountComboBox);
Stepan Salenikovich41118912015-05-01 11:25:46 -0400288
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500289 GtkTreeIter iter;
290 if (gtk_combo_box_get_active_iter(accountComboBox, &iter)) {
291 gchar* accountId;
292 gtk_tree_model_get(model, &iter, 0 /* col# */, &accountId /* data */, -1);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500293 priv->cpp->onAccountSelectionChange(accountId);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500294 g_free(accountId);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400295 }
296}
297
298static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500299on_settings_clicked(RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -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));
303
304 if (!priv->cpp->show_settings)
305 priv->cpp->enterSettingsView();
306 else
307 priv->cpp->leaveSettingsView();
308}
309
310static void
311on_show_media_settings(GtkToggleButton* navbutton, RingMainWindow* self)
312{
313 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
314 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400315
316 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400317 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -0400318 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), MEDIA_SETTINGS_VIEW_NAME);
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400319 priv->last_settings_view = priv->media_settings_view;
Stepan Salenikovich41118912015-05-01 11:25:46 -0400320 } else {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400321 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400322 }
323}
324
325static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500326on_show_account_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400327{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500328 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
329 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400330
331 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400332 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), ACCOUNT_SETTINGS_VIEW_NAME);
333 priv->last_settings_view = priv->account_settings_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400334 }
335}
336
Stepan Salenikovichde896112015-05-11 16:46:33 -0400337static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500338on_show_general_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichde896112015-05-11 16:46:33 -0400339{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500340 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
341 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichde896112015-05-11 16:46:33 -0400342
343 if (gtk_toggle_button_get_active(navbutton)) {
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400344 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400345 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME);
346 priv->last_settings_view = priv->general_settings_view;
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400347 } else {
348 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400349 }
350}
351
Stepan Salenikovichb8e41272015-03-27 14:31:54 -0400352static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500353on_search_entry_text_changed(GtkSearchEntry* search_entry, RingMainWindow* self)
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400354{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500355 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
356 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400357
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400358 // Filter model
359 const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry));
Guillaume Roguez6f431372017-12-12 21:15:39 -0500360 priv->cpp->accountContainer_->info.conversationModel->setFilter(text);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400361}
362
363static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500364on_search_entry_activated(RingMainWindow* self)
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400365{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500366 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
367 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
368
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400369 // Select the first conversation of the list
Guillaume Roguez6f431372017-12-12 21:15:39 -0500370 auto& conversationModel = priv->cpp->accountContainer_->info.conversationModel;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400371 auto conversations = conversationModel->allFilteredConversations();
372 if (!conversations.empty())
373 conversationModel->selectConversation(conversations[0].uid);
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400374}
375
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400376static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500377on_search_entry_key_released(G_GNUC_UNUSED GtkEntry* search_entry, GdkEventKey* key, RingMainWindow* self)
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400378{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500379 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
380 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400381
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400382 // if esc key pressed, clear the regex (keep the text, the user might not want to actually delete it)
383 if (key->keyval == GDK_KEY_Escape) {
Guillaume Roguez6f431372017-12-12 21:15:39 -0500384 priv->cpp->accountContainer_->info.conversationModel->setFilter("");
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400385 return GDK_EVENT_STOP;
386 }
387
388 return GDK_EVENT_PROPAGATE;
389}
390
391static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500392on_dtmf_pressed(RingMainWindow* self, GdkEventKey* event, gpointer user_data)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400393{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500394 (void)user_data;
395
396 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
397 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
398
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400399 g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400400 g_return_val_if_fail(priv, GDK_EVENT_PROPAGATE);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400401
402 /* we want to react to digit key presses, as long as a GtkEntry is not the
403 * input focus
404 */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500405 GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(self));
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400406 if (GTK_IS_ENTRY(focus))
407 return GDK_EVENT_PROPAGATE;
408
Guillaume Roguez6f431372017-12-12 21:15:39 -0500409 if (priv->cpp->accountContainer_ &&
410 priv->cpp->accountContainer_->info.profileInfo.type != lrc::api::profile::Type::SIP)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400411 return GDK_EVENT_PROPAGATE;
412
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400413 /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c'
414 * does not result in a 'c' being played.
415 * we filter Ctrl, Alt, and SUPER/HYPER/META keys */
416 if ( event->state
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400417 & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ))
418 return GDK_EVENT_PROPAGATE;
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400419
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400420 // Get current conversation
421 auto current_view = gtk_bin_get_child(GTK_BIN(priv->frame_call));
422 lrc::api::conversation::Info current_item;
423 if (IS_CURRENT_CALL_VIEW(current_view))
424 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(current_view));
425 else
426 return GDK_EVENT_PROPAGATE;
427
428 if (current_item.callId.empty())
429 return GDK_EVENT_PROPAGATE;
430
431 // pass the character that was entered to be played by the daemon;
432 // the daemon will filter out invalid DTMF characters
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400433 guint32 unicode_val = gdk_keyval_to_unicode(event->keyval);
434 QString val = QString::fromUcs4(&unicode_val, 1);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400435 g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData());
Guillaume Roguez6f431372017-12-12 21:15:39 -0500436 priv->cpp->accountContainer_->info.callModel->playDTMF(current_item.callId, val.toStdString());
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400437 // always propogate the key, so we don't steal accelerators/shortcuts
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400438 return GDK_EVENT_PROPAGATE;
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400439}
440
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400441static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500442on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainWindow* self)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400443{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500444 (void)notebook;
445 (void)page;
446
447 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
448 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
449
Guillaume Roguez6f431372017-12-12 21:15:39 -0500450 auto newType = page_num == 0 ? priv->cpp->accountContainer_->info.profileInfo.type : lrc::api::profile::Type::PENDING;
451 if (priv->cpp->currentTypeFilter_ != newType) {
452 priv->cpp->currentTypeFilter_ = newType;
453 priv->cpp->accountContainer_->info.conversationModel->setFilter(priv->cpp->currentTypeFilter_);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400454 }
Nicolas Jager0efc8432017-03-22 16:22:00 -0400455}
456
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400457static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500458on_window_size_changed(GtkWidget* self, GdkEventConfigure* event, gpointer user_data)
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400459{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500460 (void)user_data;
461
462 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
463 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400464
465 g_settings_set_int(priv->settings, "window-width", event->width);
466 g_settings_set_int(priv->settings, "window-height", event->height);
467
468 return GDK_EVENT_PROPAGATE;
469}
470
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400471static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500472on_search_entry_places_call_changed(GSettings* settings, const gchar* key, RingMainWindow* self)
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400473{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500474 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
475 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400476
477 if (g_settings_get_boolean(settings, key)) {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500478 gtk_widget_set_tooltip_text(priv->button_new_conversation,
479 C_("button next to search entry will place a new call",
480 "place call"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400481 } else {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500482 gtk_widget_set_tooltip_text(priv->button_new_conversation,
483 C_("button next to search entry will open chat", "open chat"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400484 }
485}
486
487static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500488on_handle_account_migrations(RingMainWindow* self)
aviau6aeb4852016-08-18 16:01:09 -0400489{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500490 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
491 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
aviau6aeb4852016-08-18 16:01:09 -0400492
493 /* If there is an existing migration view, remove it */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500494 if (priv->account_migration_view) {
Stepan Salenikovich56530b12016-10-20 17:51:34 -0400495 gtk_widget_destroy(priv->account_migration_view);
496 priv->account_migration_view = nullptr;
aviau6aeb4852016-08-18 16:01:09 -0400497 }
498
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500499 auto accounts = AccountModel::instance().accountsToMigrate();
500 if (!accounts.isEmpty()) {
501 auto* account = accounts.first();
aviau6aeb4852016-08-18 16:01:09 -0400502
aviau69081842016-10-14 14:51:54 -0400503 priv->account_migration_view = account_migration_view_new(account);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500504 g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed",
505 G_CALLBACK(on_handle_account_migrations), self);
506 g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed",
507 G_CALLBACK(on_handle_account_migrations), self);
aviau6aeb4852016-08-18 16:01:09 -0400508
509 gtk_widget_hide(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500510 priv->cpp->showAccountSelectorWidget(false);
aviau69081842016-10-14 14:51:54 -0400511 gtk_widget_show(priv->account_migration_view);
aviau6aeb4852016-08-18 16:01:09 -0400512 gtk_stack_add_named(
513 GTK_STACK(priv->stack_main_view),
aviau69081842016-10-14 14:51:54 -0400514 priv->account_migration_view,
aviau6aeb4852016-08-18 16:01:09 -0400515 ACCOUNT_MIGRATION_VIEW_NAME
516 );
517 gtk_stack_set_visible_child_name(
518 GTK_STACK(priv->stack_main_view),
519 ACCOUNT_MIGRATION_VIEW_NAME
520 );
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500521 } else {
aviau6aeb4852016-08-18 16:01:09 -0400522 gtk_widget_show(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500523 priv->cpp->showAccountSelectorWidget();
aviau6aeb4852016-08-18 16:01:09 -0400524 }
525}
526
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500527} // namespace gtk_callbacks
528
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500529CppImpl::CppImpl(RingMainWindow& widget)
530 : self {&widget}
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500531 , widgets {RING_MAIN_WINDOW_GET_PRIVATE(&widget)}
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500532 , lrc_ {std::make_unique<lrc::api::Lrc>()}
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500533{}
534
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500535void
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500536CppImpl::init()
537{
538 // NOTE: When new models will be fully implemented, we need to move this
539 // in rign_client.cpp->
540 // Init LRC and the vew
541 const auto accountIds = lrc_->getAccountModel().getAccountList();
542 auto isInitialized = false;
543 if (not accountIds.empty()) {
544 for (const auto& accountId : accountIds) {
545 const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId);
546 if (accountInfo.enabled) {
547 updateLrc(accountId);
548 isInitialized = true;
549 break;
550 }
551 }
552 if (!isInitialized) {
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500553 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500554 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500555 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500556 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500557 }
558 }
559
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500560 accountStatusChangedConnection_ = QObject::connect(&lrc_->getAccountModel(),
561 &lrc::api::NewAccountModel::accountStatusChanged,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500562 [this](const std::string& id){ slotAccountStatusChanged(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500563 newAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500564 &lrc::api::NewAccountModel::accountAdded,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500565 [this](const std::string& id){ slotAccountAddedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500566 rmAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez64236c22017-12-13 20:08:25 -0500567 &lrc::api::NewAccountModel::accountRemoved,
568 [this](const std::string& id){ slotAccountRemovedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500569
570 /* bind to window size settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500571 widgets->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr);
572 auto width = g_settings_get_int(widgets->settings, "window-width");
573 auto height = g_settings_get_int(widgets->settings, "window-height");
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500574 gtk_window_set_default_size(GTK_WINDOW(self), width, height);
575 g_signal_connect(self, "configure-event", G_CALLBACK(on_window_size_changed), nullptr);
576
577 /* search-entry-places-call setting */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500578 on_search_entry_places_call_changed(widgets->settings, "search-entry-places-call", self);
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500579 g_signal_connect(widgets->settings, "changed::search-entry-places-call",
580 G_CALLBACK(on_search_entry_places_call_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500581
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500582 /* set window icon */
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500583 GError *error = NULL;
584 GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error);
585 if (icon == NULL) {
586 g_debug("Could not load icon: %s", error->message);
587 g_clear_error(&error);
588 } else
589 gtk_window_set_icon(GTK_WINDOW(self), icon);
590
591 /* set menu icon */
592 GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue",
593 -1, 16, TRUE, &error);
594 if (image_ring == NULL) {
595 g_debug("Could not load icon: %s", error->message);
596 g_clear_error(&error);
597 } else
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500598 gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_ring), image_ring);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500599
600 /* ring menu */
601 GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui");
602 GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu"));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500603 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(widgets->ring_menu), menu);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500604 g_object_unref(builder);
605
606 /* settings icon */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500607 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
608 GTK_ICON_SIZE_SMALL_TOOLBAR);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500609
610 /* connect settings button signal */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500611 g_signal_connect_swapped(widgets->ring_settings, "clicked",
612 G_CALLBACK(on_settings_clicked), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500613
614 /* add the call view to the main stack */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500615 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500616 CALL_VIEW_NAME);
617
618 /* init the settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500619 widgets->account_settings_view = account_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500620 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->account_settings_view,
621 ACCOUNT_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500622
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500623 widgets->media_settings_view = media_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500624 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->media_settings_view,
625 MEDIA_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500626
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500627 widgets->general_settings_view = general_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500628 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view,
629 GENERAL_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500630
631 /* make the setting we will show first the active one */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500632 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE);
633 widgets->last_settings_view = widgets->general_settings_view;
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500634
635 /* connect the settings button signals to switch settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500636 g_signal_connect(widgets->radiobutton_media_settings, "toggled", G_CALLBACK(on_show_media_settings), self);
637 g_signal_connect(widgets->radiobutton_account_settings, "toggled", G_CALLBACK(on_show_account_settings), self);
638 g_signal_connect(widgets->radiobutton_general_settings, "toggled", G_CALLBACK(on_show_general_settings), self);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500639 g_signal_connect(widgets->notebook_contacts, "switch-page", G_CALLBACK(on_tab_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500640
641 /* welcome/default view */
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500642 widgets->welcome_view = ring_welcome_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500643 g_object_ref(widgets->welcome_view); // increase ref because don't want it to be destroyed when not displayed
644 gtk_container_add(GTK_CONTAINER(widgets->frame_call), widgets->welcome_view);
645 gtk_widget_show(widgets->welcome_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500646
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500647 g_signal_connect_swapped(widgets->search_entry, "activate", G_CALLBACK(on_search_entry_activated), self);
648 g_signal_connect_swapped(widgets->button_new_conversation, "clicked", G_CALLBACK(on_search_entry_activated), self);
649 g_signal_connect(widgets->search_entry, "search-changed", G_CALLBACK(on_search_entry_text_changed), self);
650 g_signal_connect(widgets->search_entry, "key-release-event", G_CALLBACK(on_search_entry_key_released), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500651
652 auto provider = gtk_css_provider_new();
653 gtk_css_provider_load_from_data(provider,
654 ".search-entry-style { border: 0; border-radius: 0; } \
655 .spinner-style { border: 0; background: white; } \
656 .new-conversation-style { border: 0; background: white; transition: all 0.3s ease; border-radius: 0; } \
657 .new-conversation-style:hover { background: #bae5f0; }",
658 -1, nullptr
659 );
660 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
661 GTK_STYLE_PROVIDER(provider),
662 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
663
664
665 /* react to digit key press events */
666 g_signal_connect(self, "key-press-event", G_CALLBACK(on_dtmf_pressed), nullptr);
667
668 /* set the search entry placeholder text */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500669 gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->search_entry),
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500670 C_("Please try to make the translation 50 chars or less so that it fits into the layout",
671 "Search contacts or enter number"));
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500672
673 /* init chat webkit container so that it starts loading before the first time we need it*/
674 (void)webkitChatContainer();
675
676 if (has_ring_account()) {
677 /* user has ring account, so show the call view right away */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500678 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500679
680 on_handle_account_migrations(self);
681 } else {
682 /* user has to create the ring account */
683 enterAccountCreationWizard();
684 }
685
686 // setup account selector and select the first account
687 auto store = gtk_list_store_new (2 /* # of cols */ ,
688 G_TYPE_STRING,
689 G_TYPE_STRING,
690 G_TYPE_UINT);
691 GtkTreeIter iter;
Guillaume Roguez7e238402017-12-13 19:40:05 -0500692 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500693 gtk_list_store_append (store, &iter);
694 gtk_list_store_set (store, &iter,
Guillaume Roguez7e238402017-12-13 19:40:05 -0500695 0 /* col # */ , acc_info.id.c_str() /* celldata */,
696 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500697 -1 /* end */);
Guillaume Roguez7e238402017-12-13 19:40:05 -0500698 });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500699
700 gtk_combo_box_set_model(
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500701 GTK_COMBO_BOX(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500702 GTK_TREE_MODEL (store)
703 );
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500704 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500705
706 /* set visibility */
707 showAccountSelectorWidget();
708
709 /* layout */
710 auto *renderer = gtk_cell_renderer_text_new();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500711 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, FALSE);
712 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, "text", 0, NULL);
713 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500714 renderer,
715 (GtkCellLayoutDataFunc)print_account_and_state,
716 nullptr, nullptr);
717
718 // we closing any view opened to avoid confusion (especially between SIP and Ring protocols).
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500719 g_signal_connect_swapped(widgets->combobox_account_selector, "changed", G_CALLBACK(on_account_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500720
721 // initialize the pending contact request icon.
722 setPendingContactRequestTabIcon();
723
724 if (isInitialized) {
725 auto& conversationModel = accountContainer_->info.conversationModel;
726 auto conversations = conversationModel->allFilteredConversations();
727 for (const auto& conversation: conversations) {
728 if (!conversation.callId.empty()) {
729 accountContainer_->info.conversationModel->selectConversation(conversation.uid);
730 }
731 }
732 }
733}
734
735CppImpl::~CppImpl()
736{
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500737 QObject::disconnect(showChatViewConnection_);
738 QObject::disconnect(showIncomingViewConnection_);
739 QObject::disconnect(historyClearedConnection_);
740 QObject::disconnect(modelSortedConnection_);
741 QObject::disconnect(filterChangedConnection_);
742 QObject::disconnect(newConversationConnection_);
743 QObject::disconnect(conversationRemovedConnection_);
744 QObject::disconnect(changeAccountConnection_);
745 QObject::disconnect(newAccountConnection_);
746 QObject::disconnect(rmAccountConnection_);
747 QObject::disconnect(showCallViewConnection_);
748 QObject::disconnect(modelSortedConnection_);
749 QObject::disconnect(accountStatusChangedConnection_);
750
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500751 g_clear_object(&widgets->welcome_view);
752 g_clear_object(&widgets->webkit_chat_container);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500753}
754
755void
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500756CppImpl::changeView(GType type, lrc::api::conversation::Info conversation)
757{
Guillaume Roguez1d963272017-12-12 23:32:13 -0500758 leaveFullScreen();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500759 gtk_container_remove(GTK_CONTAINER(widgets->frame_call),
760 gtk_bin_get_child(GTK_BIN(widgets->frame_call)));
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500761
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500762 GtkWidget* new_view;
763 if (g_type_is_a(INCOMING_CALL_VIEW_TYPE, type)) {
764 new_view = displayIncomingView(conversation);
765 } else if (g_type_is_a(CURRENT_CALL_VIEW_TYPE, type)) {
766 new_view = displayCurrentCallView(conversation);
767 } else if (g_type_is_a(CHAT_VIEW_TYPE, type)) {
768 new_view = displayChatView(conversation);
769 } else {
770 // TODO select first conversation?
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500771 new_view = widgets->welcome_view;
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500772 }
773
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500774 gtk_container_add(GTK_CONTAINER(widgets->frame_call), new_view);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500775 gtk_widget_show(new_view);
776}
777
778GtkWidget*
779CppImpl::displayIncomingView(lrc::api::conversation::Info conversation)
780{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500781 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
782 return incoming_call_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500783}
784
785GtkWidget*
786CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation)
787{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500788 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
Guillaume Roguez11339f82017-12-12 23:15:34 -0500789 auto* new_view = current_call_view_new(webkitChatContainer(),
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500790 accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500791
792 try {
793 auto contactUri = chatViewConversation_->participants.front();
794 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
795 if (auto chat_view = current_call_view_get_chat_view(CURRENT_CALL_VIEW(new_view))) {
796 chat_view_update_temporary(CHAT_VIEW(chat_view),
797 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
798 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
799 }
800 } catch(...) { }
801
Guillaume Roguez1d963272017-12-12 23:32:13 -0500802 g_signal_connect_swapped(new_view, "video-double-clicked",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500803 G_CALLBACK(on_video_double_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500804 return new_view;
805}
806
807GtkWidget*
808CppImpl::displayChatView(lrc::api::conversation::Info conversation)
809{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500810 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
811 auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500812 g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500813 return new_view;
814}
815
Guillaume Roguez11339f82017-12-12 23:15:34 -0500816WebKitChatContainer*
817CppImpl::webkitChatContainer() const
818{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500819 if (!widgets->webkit_chat_container) {
820 widgets->webkit_chat_container = webkit_chat_container_new();
Guillaume Roguez11339f82017-12-12 23:15:34 -0500821
822 // We don't want it to be deleted, ever.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500823 g_object_ref(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500824 }
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500825 return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500826}
827
Guillaume Roguez1d963272017-12-12 23:32:13 -0500828void
829CppImpl::enterFullScreen()
830{
831 if (!is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500832 gtk_widget_hide(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500833 gtk_window_fullscreen(GTK_WINDOW(self));
834 is_fullscreen = true;
835 }
836}
837
838void
839CppImpl::leaveFullScreen()
840{
841 if (is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500842 gtk_widget_show(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500843 gtk_window_unfullscreen(GTK_WINDOW(self));
844 is_fullscreen = false;
845 }
846}
847
848void
849CppImpl::toggleFullScreen()
850{
851 if (is_fullscreen)
852 leaveFullScreen();
853 else
854 enterFullScreen();
855}
856
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500857/// Clear selection and go to welcome page.
858void
859CppImpl::resetToWelcome()
860{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500861 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500862 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500863 auto selection_contact_request = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500864 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500865 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500866 lrc::api::conversation::Info current_item;
867 if (IS_CHAT_VIEW(old_view))
868 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
869 changeView(RING_WELCOME_VIEW_TYPE, current_item);
870}
871
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500872void
873CppImpl::setPendingContactRequestTabIcon()
874{
875 if (not accountContainer_)
876 return;
877
878 auto isRingAccount = accountContainer_->info.profileInfo.type == lrc::api::profile::Type::RING;
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500879 gtk_widget_set_visible(widgets->scrolled_window_contact_requests, isRingAccount);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500880
881 if (not isRingAccount)
882 return;
883
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500884 gtk_image_set_from_resource(GTK_IMAGE(widgets->image_contact_requests_list),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500885 (accountContainer_->info.contactModel->hasPendingRequests())
886 ? "/cx/ring/RingGnome/contact_requests_list_with_notification"
887 : "/cx/ring/RingGnome/contact_requests_list");
888}
889
890void
891CppImpl::showAccountSelectorWidget(bool show)
892{
893 // we only want to show the account selector when there is more than 1 enabled
894 // account; so every time we want to show it, we should preform this check
Guillaume Roguez7e238402017-12-13 19:40:05 -0500895 std::size_t activatedAccount = 0;
896 foreachEnabledLrcAccount(*lrc_, [&] (const auto&) { ++activatedAccount; });
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500897 gtk_widget_set_visible(widgets->combobox_account_selector, show && activatedAccount > 1);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500898}
899
900void
901CppImpl::enterAccountCreationWizard()
902{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500903 if (!widgets->account_creation_wizard) {
904 widgets->account_creation_wizard = account_creation_wizard_new(false);
905 g_object_add_weak_pointer(G_OBJECT(widgets->account_creation_wizard),
906 reinterpret_cast<gpointer*>(&widgets->account_creation_wizard));
907 g_signal_connect_swapped(widgets->account_creation_wizard, "account-creation-completed",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500908 G_CALLBACK(on_account_creation_completed), self);
909
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500910 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view),
911 widgets->account_creation_wizard,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500912 ACCOUNT_CREATION_WIZARD_VIEW_NAME);
913 }
914
915 /* hide settings button until account creation is complete */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500916 gtk_widget_hide(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500917 showAccountSelectorWidget(false);
918
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500919 gtk_widget_show(widgets->account_creation_wizard);
920 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->account_creation_wizard);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500921}
922
923void
924CppImpl::leaveAccountCreationWizard()
925{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500926 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500927
928 /* destroy the wizard */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500929 if (widgets->account_creation_wizard) {
930 gtk_container_remove(GTK_CONTAINER(widgets->stack_main_view), widgets->account_creation_wizard);
931 gtk_widget_destroy(widgets->account_creation_wizard);
932 widgets->account_creation_wizard = nullptr;
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500933 }
934
935 /* show the settings button */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500936 gtk_widget_show(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500937
938 /* show the account selector */
939 showAccountSelectorWidget();
940}
941
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500942/// Change the selection of the account ComboBox by account Id.
943/// Find in displayed accounts with one corresponding to the given id, then select it
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500944void
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500945CppImpl::changeAccountSelection(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500946{
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500947 // already selected?
948 if (id == accountContainer_->info.id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500949 return;
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500950
951 if (auto* model = gtk_combo_box_get_model(GTK_COMBO_BOX(widgets->combobox_account_selector))) {
952 GtkTreeIter iter;
953 auto valid = gtk_tree_model_get_iter_first(model, &iter);
954 while (valid) {
955 const gchar* account_id;
956 gtk_tree_model_get(model, &iter, 0 /* col# */, &account_id /* data */, -1);
957 if (id == account_id) {
958 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->combobox_account_selector), &iter);
959 return;
960 }
961 valid = gtk_tree_model_iter_next(model, &iter);
962 }
963
964 g_debug("BUGS: account not listed: %s", id.c_str());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500965 }
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500966}
967
968void
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500969CppImpl::onAccountSelectionChange(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500970{
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500971 // Go to welcome view
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500972 changeView(RING_WELCOME_VIEW_TYPE);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500973 // Show conversation panel
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500974 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500975 // Reinit LRC
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500976 updateLrc(id);
Guillaume Rogueza04f4422017-12-14 13:52:34 -0500977 // Update the welcome view
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500978 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500979}
980
981void
982CppImpl::enterSettingsView()
983{
984 /* show the settings */
985 show_settings = true;
986
987 /* show settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500988 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-ok-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500989 GTK_ICON_SIZE_SMALL_TOOLBAR);
990
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500991 gtk_widget_show(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500992
993 /* make sure to start preview if we're showing the video settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500994 if (widgets->last_settings_view == widgets->media_settings_view)
995 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), TRUE);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500996
997 /* make sure to show the profile if we're showing the general settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500998 if (widgets->last_settings_view == widgets->general_settings_view)
999 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001000 TRUE);
1001
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001002 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->last_settings_view);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001003}
1004
1005void
1006CppImpl::leaveSettingsView()
1007{
1008 /* hide the settings */
1009 show_settings = false;
1010
1011 /* show working dialog in case save operation takes time */
1012 auto working = ring_dialog_working(GTK_WIDGET(self), nullptr);
1013 gtk_window_present(GTK_WINDOW(working));
1014
1015 /* now save after the time it takes to transition back to the call view (400ms)
1016 * the save doesn't happen before the "working" dialog is presented
1017 * the timeout function should destroy the "working" dialog when done saving
1018 */
1019 g_timeout_add_full(G_PRIORITY_DEFAULT, 400, GSourceFunc(on_save_accounts_timeout), working,
1020 nullptr);
1021
1022 /* show calls */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001023 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001024 GTK_ICON_SIZE_SMALL_TOOLBAR);
1025
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001026 gtk_widget_hide(widgets->hbox_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001027
1028 /* make sure video preview is stopped, in case it was started */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001029 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(widgets->media_settings_view), FALSE);
1030 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(widgets->general_settings_view),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001031 FALSE);
1032
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001033 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001034
1035 /* show the view which was selected previously */
1036}
1037
1038void
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001039CppImpl::updateLrc(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001040{
1041 // Disconnect old signals.
1042 QObject::disconnect(showChatViewConnection_);
1043 QObject::disconnect(showIncomingViewConnection_);
1044 QObject::disconnect(changeAccountConnection_);
1045 QObject::disconnect(showCallViewConnection_);
1046 QObject::disconnect(modelSortedConnection_);
1047 QObject::disconnect(historyClearedConnection_);
1048 QObject::disconnect(filterChangedConnection_);
1049 QObject::disconnect(newConversationConnection_);
1050 QObject::disconnect(conversationRemovedConnection_);
1051
1052 // Get the account selected
Guillaume Roguez5121fd62017-12-13 18:51:52 -05001053 if (!id.empty())
1054 accountContainer_.reset(new AccountContainer(lrc_->getAccountModel().getAccountInfo(id)));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001055 else
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001056 accountContainer_.reset();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001057
1058 // Reinit tree views
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001059 if (widgets->treeview_conversations) {
1060 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001061 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001062 gtk_widget_destroy(widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001063 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001064 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001065 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001066
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001067 if (widgets->treeview_contact_requests) {
1068 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001069 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001070 gtk_widget_destroy(widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001071 }
Guillaume Roguezb96d6532017-12-13 14:31:39 -05001072 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001073 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001074
1075 if (!accountContainer_) return;
1076
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001077 // Connect to signals from LRC
1078 historyClearedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001079 &lrc::api::ConversationModel::conversationCleared,
1080 [this] (const std::string& id) { slotConversationCleared(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001081
1082 modelSortedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001083 &lrc::api::ConversationModel::modelSorted,
1084 [this] { slotModelSorted(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001085
1086 filterChangedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001087 &lrc::api::ConversationModel::filterChanged,
1088 [this] { slotFilterChanged(); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001089
1090 newConversationConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001091 &lrc::api::ConversationModel::newConversation,
1092 [this] (const std::string& id) { slotNewConversation(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001093
1094 conversationRemovedConnection_ = QObject::connect(&*accountContainer_->info.conversationModel,
Guillaume Roguez64236c22017-12-13 20:08:25 -05001095 &lrc::api::ConversationModel::conversationRemoved,
1096 [this] (const std::string& id) { slotConversationRemoved(id); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001097
1098 showChatViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001099 &lrc::api::BehaviorController::showChatView,
1100 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowChatView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001101
1102 showCallViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001103 &lrc::api::BehaviorController::showCallView,
1104 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001105
1106 showIncomingViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
Guillaume Roguez64236c22017-12-13 20:08:25 -05001107 &lrc::api::BehaviorController::showIncomingCallView,
1108 [this] (const std::string& id, lrc::api::conversation::Info origin) { slotShowIncomingCallView(id, origin); });
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001109
Guillaume Roguez3ea37de2017-12-13 14:13:54 -05001110 const gchar *text = gtk_entry_get_text(GTK_ENTRY(widgets->search_entry));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -05001111 currentTypeFilter_ = accountContainer_->info.profileInfo.type;
1112 accountContainer_->info.conversationModel->setFilter(text);
1113 accountContainer_->info.conversationModel->setFilter(currentTypeFilter_);
1114}
1115
Guillaume Roguez64236c22017-12-13 20:08:25 -05001116void
1117CppImpl::slotAccountAddedFromLrc(const std::string& id)
1118{
1119 (void)id;
1120
1121 // go to this account
1122 auto accounts = lrc_->getAccountModel().getAccountList();
1123 auto store = gtk_list_store_new (2 /* # of cols */ ,
1124 G_TYPE_STRING,
1125 G_TYPE_STRING,
1126 G_TYPE_UINT);
1127 auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
1128 GtkTreeIter iter;
1129 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
1130 gtk_list_store_append (store, &iter);
1131 gtk_list_store_set (store, &iter,
1132 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1133 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
1134 -1 /* end */);
1135 });
1136 // Redraw combobox
1137 gtk_combo_box_set_model(
1138 GTK_COMBO_BOX(widgets->combobox_account_selector),
1139 GTK_TREE_MODEL (store)
1140 );
1141 // If no account selected, select the new account
1142 if (currentIdx == -1) currentIdx = 0;
1143 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx);
1144 showAccountSelectorWidget();
1145}
1146
1147void
1148CppImpl::slotAccountRemovedFromLrc(const std::string& id)
1149{
1150 (void)id;
1151
1152 auto accounts = lrc_->getAccountModel().getAccountList();
1153 if (accounts.empty()) {
1154 enterAccountCreationWizard();
1155 return;
1156 }
1157
1158 auto store = gtk_list_store_new (2 /* # of cols */ ,
1159 G_TYPE_STRING,
1160 G_TYPE_STRING,
1161 G_TYPE_UINT);
1162 GtkTreeIter iter;
1163 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
1164 gtk_list_store_append (store, &iter);
1165 gtk_list_store_set (store, &iter,
1166 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1167 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
1168 -1 /* end */);
1169 });
1170 gtk_combo_box_set_model(
1171 GTK_COMBO_BOX(widgets->combobox_account_selector),
1172 GTK_TREE_MODEL (store)
1173 );
1174 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0);
1175 showAccountSelectorWidget();
1176 // Show conversation panel
1177 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
1178 // Reinit LRC
1179 updateLrc(std::string(accounts.at(0)));
1180 // Update the welcome view
1181 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
1182}
1183
1184void
1185CppImpl::slotAccountStatusChanged(const std::string& id)
1186{
1187 if (not accountContainer_ ) {
1188 updateLrc(id);
1189 if (accountContainer_)
1190 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view),
1191 accountContainer_.get());
1192 return;
1193 }
1194
1195 auto accounts = lrc_->getAccountModel().getAccountList();
1196 auto store = gtk_list_store_new (2 /* # of cols */ ,
1197 G_TYPE_STRING,
1198 G_TYPE_STRING,
1199 G_TYPE_UINT);
1200
1201 gint currentIdx = 0;
1202 std::size_t enabledAccounts = 0;
1203 GtkTreeIter iter;
1204 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
1205 ++enabledAccounts;
1206 gtk_list_store_append (store, &iter);
1207 gtk_list_store_set (store, &iter,
1208 0 /* col # */ , acc_info.id.c_str() /* celldata */,
1209 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
1210 -1 /* end */);
1211 if (id == acc_info.id) {
1212 // keep current selected account only if account status is enabled
1213 currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
1214 }
1215 });
1216 showAccountSelectorWidget();
1217
1218 // Redraw combobox
1219 gtk_combo_box_set_model(
1220 GTK_COMBO_BOX(widgets->combobox_account_selector),
1221 GTK_TREE_MODEL (store)
1222 );
1223 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), currentIdx);
1224 // if no account. reset the view.
1225 if (enabledAccounts == 0) {
1226 updateLrc("");
1227 changeView(RING_WELCOME_VIEW_TYPE);
1228 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), nullptr);
1229 }
1230}
1231
1232void
1233CppImpl::slotConversationCleared(const std::string& uid)
1234{
1235 // Change the view when the history is cleared.
1236 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1237 lrc::api::conversation::Info current_item;
1238 current_item.uid = "-1"; // Because the Searching item has an empty uid
1239 if (IS_CHAT_VIEW(old_view))
1240 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1241 else
1242 // if incoming or call view we don't want to change the view
1243 return;
1244 if (current_item.uid == uid) {
1245 // We are on the conversation cleared.
1246 // Go to welcome view because user doesn't want this conversation
1247 // TODO go to first conversation?
1248 resetToWelcome();
1249 }
1250}
1251
1252void
1253CppImpl::slotModelSorted()
1254{
1255 // Synchronize selection when sorted and update pending icon
1256 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1257 lrc::api::conversation::Info current_item;
1258 current_item.uid = "-1";
1259 if (IS_CHAT_VIEW(old_view))
1260 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1261 else if (IS_CURRENT_CALL_VIEW(old_view))
1262 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1263 else if (IS_INCOMING_CALL_VIEW(old_view))
1264 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1265 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
1266 setPendingContactRequestTabIcon();
1267}
1268
1269void
1270CppImpl::slotFilterChanged()
1271{
1272 // Synchronize selection when filter changes
1273 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1274 lrc::api::conversation::Info current_item;
1275 current_item.uid = "-1";
1276 if (IS_CHAT_VIEW(old_view))
1277 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1278 else if (IS_CURRENT_CALL_VIEW(old_view))
1279 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1280 else if (IS_INCOMING_CALL_VIEW(old_view))
1281 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1282 conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
1283 // Get if conversation still exists.
1284 auto& conversationModel = accountContainer_->info.conversationModel;
1285 auto conversations = conversationModel->allFilteredConversations();
1286 auto isInConv = std::find_if(
1287 conversations.begin(), conversations.end(),
1288 [current_item](const lrc::api::conversation::Info& conversation) {
1289 return current_item.uid == conversation.uid;
1290 });
1291 if (IS_CHAT_VIEW(old_view) && isInConv == conversations.end()) {
1292 changeView(RING_WELCOME_VIEW_TYPE);
1293 }
1294}
1295
1296void
1297CppImpl::slotNewConversation(const std::string& uid)
1298{
1299 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
1300 accountContainer_->info.conversationModel->setFilter(lrc::api::profile::Type::RING);
1301 gtk_entry_set_text(GTK_ENTRY(widgets->search_entry), "");
1302 accountContainer_->info.conversationModel->setFilter("");
1303 // Select new conversation if contact added
1304 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1305 if (IS_RING_WELCOME_VIEW(old_view) || (IS_CHAT_VIEW(old_view) && chat_view_get_temporary(CHAT_VIEW(old_view)))) {
1306 accountContainer_->info.conversationModel->selectConversation(uid);
1307 try {
1308 auto contactUri = chatViewConversation_->participants.front();
1309 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
1310 chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))),
1311 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
1312 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
1313 } catch(...) { }
1314 }
1315}
1316
1317void
1318CppImpl::slotConversationRemoved(const std::string& uid)
1319{
1320 // If contact is removed, go to welcome view
1321 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1322 lrc::api::conversation::Info current_item;
1323 if (IS_CHAT_VIEW(old_view))
1324 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1325 else if (IS_CURRENT_CALL_VIEW(old_view))
1326 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1327 else if (IS_INCOMING_CALL_VIEW(old_view))
1328 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1329 if (current_item.uid == uid)
1330 changeView(RING_WELCOME_VIEW_TYPE);
1331}
1332
1333void
1334CppImpl::slotShowChatView(const std::string& id, lrc::api::conversation::Info origin)
1335{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001336 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001337 // Show chat view if not in call (unless if it's the same conversation)
1338 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1339 lrc::api::conversation::Info current_item;
1340 current_item.uid = "-1";
1341 if (IS_CHAT_VIEW(old_view))
1342 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1343 if (current_item.uid != origin.uid) {
1344 if (origin.participants.empty()) return;
1345 auto firstContactUri = origin.participants.front();
1346 auto contactInfo = accountContainer_->info.contactModel->getContact(firstContactUri);
1347 if (contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING && current_item.uid != "-1") return;
1348 changeView(CHAT_VIEW_TYPE, origin);
1349 }
1350}
1351
1352void
1353CppImpl::slotShowCallView(const std::string& id, lrc::api::conversation::Info origin)
1354{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001355 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001356 // Change the view if we want a different view.
1357 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1358
1359 lrc::api::conversation::Info current_item;
1360 if (IS_CURRENT_CALL_VIEW(old_view))
1361 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1362
1363 if (current_item.uid != origin.uid)
1364 changeView(CURRENT_CALL_VIEW_TYPE, origin);
1365}
1366
1367void
1368CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin)
1369{
Guillaume Rogueza04f4422017-12-14 13:52:34 -05001370 changeAccountSelection(id);
Guillaume Roguez64236c22017-12-13 20:08:25 -05001371 // Change the view if we want a different view.
1372 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1373
1374 lrc::api::conversation::Info current_item;
1375 if (IS_INCOMING_CALL_VIEW(old_view))
1376 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1377
1378 if (current_item.uid != origin.uid)
1379 changeView(INCOMING_CALL_VIEW_TYPE, origin);
1380}
1381
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001382} // namespace details
1383
1384//==============================================================================
Guillaume Roguez0a411202017-05-25 15:27:26 -04001385
1386static void
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001387ring_main_window_init(RingMainWindow *win)
1388{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001389 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001390 gtk_widget_init_template(GTK_WIDGET(win));
1391
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001392 // CppImpl ctor
1393 priv->cpp = new details::CppImpl {*win};
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001394 priv->cpp->init();
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001395}
1396
1397static void
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001398ring_main_window_dispose(GObject *object)
1399{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001400 auto* self = RING_MAIN_WINDOW(object);
1401 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001402
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001403 delete priv->cpp;
1404 priv->cpp = nullptr;
1405
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001406 G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object);
1407}
1408
1409static void
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001410ring_main_window_finalize(GObject *object)
1411{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001412 auto* self = RING_MAIN_WINDOW(object);
1413 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichba87ae22016-09-13 14:27:20 -04001414
1415 g_clear_object(&priv->settings);
1416
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001417 G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001418}
1419
1420static void
1421ring_main_window_class_init(RingMainWindowClass *klass)
1422{
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001423 G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize;
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001424 G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001425
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001426 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
1427 "/cx/ring/RingGnome/ringmainwindow.ui");
1428
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001429 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane);
Sébastien Blin55bff9d2017-10-03 15:15:23 -04001430 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, notebook_contacts);
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -04001431 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001432 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu);
1433 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring);
1434 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings);
1435 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001436 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, hbox_settings);
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -05001437 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, search_entry);
Stepan Salenikovich69771842015-02-24 18:11:45 -05001438 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, stack_main_view);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001439 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_call_view);
Stepan Salenikovich3034d922015-10-09 10:11:42 -04001440 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, frame_call);
Stepan Salenikoviche9933242016-06-21 18:08:48 -04001441 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, button_new_conversation );
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001442 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_general_settings);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -04001443 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001444 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings);
Nicolas Jager15a8b902017-03-21 07:53:06 -04001445 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, combobox_account_selector);
Nicolas Jager0efc8432017-03-22 16:22:00 -04001446 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contact_requests);
Guillaume Roguez0a411202017-05-25 15:27:26 -04001447 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_contact_requests_list);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001448}
1449
1450GtkWidget *
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001451ring_main_window_new(GtkApplication *app)
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001452{
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001453 gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL);
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001454 return (GtkWidget *)win;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001455}