blob: e9e5a4d5e79d594c1f2069abc846a4c7c3719adb [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);
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500143 void onAccountChangeFromUI(const std::string& id);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500144 void enterAccountCreationWizard();
145 void leaveAccountCreationWizard();
146 void enterSettingsView();
147 void leaveSettingsView();
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500148
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500149 RingMainWindow* self = nullptr; // The GTK widget itself
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500150 RingMainWindowPrivate* widgets = nullptr;
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500151
Guillaume Roguez6f431372017-12-12 21:15:39 -0500152 std::unique_ptr<lrc::api::Lrc> lrc_;
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500153 std::unique_ptr<AccountContainer> accountContainer_;
154 std::unique_ptr<lrc::api::conversation::Info> chatViewConversation_;
Guillaume Roguez6f431372017-12-12 21:15:39 -0500155 lrc::api::profile::Type currentTypeFilter_;
156 bool show_settings = false;
157 bool is_fullscreen = false;
158
159 QMetaObject::Connection selected_item_changed;
160 QMetaObject::Connection selected_call_over;
161 QMetaObject::Connection showChatViewConnection_;
162 QMetaObject::Connection showCallViewConnection_;
163 QMetaObject::Connection showIncomingViewConnection_;
164 QMetaObject::Connection changeAccountConnection_;
165 QMetaObject::Connection newAccountConnection_;
166 QMetaObject::Connection rmAccountConnection_;
167 QMetaObject::Connection historyClearedConnection_;
168 QMetaObject::Connection modelSortedConnection_;
169 QMetaObject::Connection filterChangedConnection_;
170 QMetaObject::Connection newConversationConnection_;
171 QMetaObject::Connection conversationRemovedConnection_;
172 QMetaObject::Connection accountStatusChangedConnection_;
173
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500174private:
Guillaume Roguez64236c22017-12-13 20:08:25 -0500175 CppImpl() = delete;
176 CppImpl(const CppImpl&) = delete;
177 CppImpl& operator=(const CppImpl&) = delete;
178
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500179 GtkWidget* displayIncomingView(lrc::api::conversation::Info);
180 GtkWidget* displayCurrentCallView(lrc::api::conversation::Info);
181 GtkWidget* displayChatView(lrc::api::conversation::Info);
182
Guillaume Roguez64236c22017-12-13 20:08:25 -0500183 // Callbacks used as LRC Qt slot
184 void slotAccountAddedFromLrc(const std::string& id);
185 void slotAccountRemovedFromLrc(const std::string& id);
186 void slotAccountStatusChanged(const std::string& id);
187 void slotConversationCleared(const std::string& uid);
188 void slotModelSorted();
189 void slotFilterChanged();
190 void slotNewConversation(const std::string& uid);
191 void slotConversationRemoved(const std::string& uid);
192 void slotShowChatView(const std::string& id, lrc::api::conversation::Info origin);
193 void slotShowCallView(const std::string& id, lrc::api::conversation::Info origin);
194 void slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin);
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500195};
196
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500197inline namespace gtk_callbacks
198{
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500199
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400200static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500201on_save_accounts_timeout(GtkWidget* working_dialog)
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400202{
203 /* save changes to accounts */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400204 AccountModel::instance().save();
Stepan Salenikovichbd029582015-03-24 11:00:56 -0400205
206 if (working_dialog)
207 gtk_widget_destroy(working_dialog);
208
209 return G_SOURCE_REMOVE;
210}
211
Stepan Salenikovich15142182015-03-11 17:15:26 -0400212static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500213on_video_double_clicked(RingMainWindow* self)
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400214{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500215 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
216 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
217 priv->cpp->toggleFullScreen();
218}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400219
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500220static void
221on_hide_view_clicked(RingMainWindow* self)
222{
223 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
224 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
225 priv->cpp->resetToWelcome();
226}
Stepan Salenikovichbd4b3772015-12-13 23:28:06 -0500227
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500228static void
229on_account_creation_completed(RingMainWindow* self)
230{
231 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
232 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
233 priv->cpp->leaveAccountCreationWizard();
234}
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400235
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500236static void
237on_account_changed(RingMainWindow* self)
238{
239 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
240 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400241
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500242 auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector);
243 auto model = gtk_combo_box_get_model(accountComboBox);
Stepan Salenikovich41118912015-05-01 11:25:46 -0400244
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500245 GtkTreeIter iter;
246 if (gtk_combo_box_get_active_iter(accountComboBox, &iter)) {
247 gchar* accountId;
248 gtk_tree_model_get(model, &iter, 0 /* col# */, &accountId /* data */, -1);
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500249 priv->cpp->onAccountChangeFromUI(accountId);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500250 g_free(accountId);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400251 }
252}
253
254static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500255on_settings_clicked(RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400256{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500257 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
258 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
259
260 if (!priv->cpp->show_settings)
261 priv->cpp->enterSettingsView();
262 else
263 priv->cpp->leaveSettingsView();
264}
265
266static void
267on_show_media_settings(GtkToggleButton* navbutton, RingMainWindow* self)
268{
269 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
270 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400271
272 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400273 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -0400274 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), MEDIA_SETTINGS_VIEW_NAME);
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400275 priv->last_settings_view = priv->media_settings_view;
Stepan Salenikovich41118912015-05-01 11:25:46 -0400276 } else {
Stepan Salenikovich0bd53492015-05-11 14:28:52 -0400277 media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE);
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400278 }
279}
280
281static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500282on_show_account_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400283{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500284 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
285 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400286
287 if (gtk_toggle_button_get_active(navbutton)) {
Stepan Salenikovichf903d1b2015-03-25 14:51:45 -0400288 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), ACCOUNT_SETTINGS_VIEW_NAME);
289 priv->last_settings_view = priv->account_settings_view;
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400290 }
291}
292
Stepan Salenikovichde896112015-05-11 16:46:33 -0400293static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500294on_show_general_settings(GtkToggleButton* navbutton, RingMainWindow* self)
Stepan Salenikovichde896112015-05-11 16:46:33 -0400295{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500296 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
297 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichde896112015-05-11 16:46:33 -0400298
299 if (gtk_toggle_button_get_active(navbutton)) {
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400300 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400301 gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME);
302 priv->last_settings_view = priv->general_settings_view;
Nicolas Jager6f5e04a2016-05-18 15:04:59 -0400303 } else {
304 general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE);
Stepan Salenikovichde896112015-05-11 16:46:33 -0400305 }
306}
307
Stepan Salenikovichb8e41272015-03-27 14:31:54 -0400308static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500309on_search_entry_text_changed(GtkSearchEntry* search_entry, RingMainWindow* self)
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400310{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500311 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
312 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400313
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400314 // Filter model
315 const gchar *text = gtk_entry_get_text(GTK_ENTRY(search_entry));
Guillaume Roguez6f431372017-12-12 21:15:39 -0500316 priv->cpp->accountContainer_->info.conversationModel->setFilter(text);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400317}
318
319static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500320on_search_entry_activated(RingMainWindow* self)
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400321{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500322 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
323 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
324
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400325 // Select the first conversation of the list
Guillaume Roguez6f431372017-12-12 21:15:39 -0500326 auto& conversationModel = priv->cpp->accountContainer_->info.conversationModel;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400327 auto conversations = conversationModel->allFilteredConversations();
328 if (!conversations.empty())
329 conversationModel->selectConversation(conversations[0].uid);
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400330}
331
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400332static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500333on_search_entry_key_released(G_GNUC_UNUSED GtkEntry* search_entry, GdkEventKey* key, RingMainWindow* self)
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400334{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500335 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
336 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400337
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400338 // if esc key pressed, clear the regex (keep the text, the user might not want to actually delete it)
339 if (key->keyval == GDK_KEY_Escape) {
Guillaume Roguez6f431372017-12-12 21:15:39 -0500340 priv->cpp->accountContainer_->info.conversationModel->setFilter("");
Stepan Salenikovichcac35042016-10-28 12:07:38 -0400341 return GDK_EVENT_STOP;
342 }
343
344 return GDK_EVENT_PROPAGATE;
345}
346
347static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500348on_dtmf_pressed(RingMainWindow* self, GdkEventKey* event, gpointer user_data)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400349{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500350 (void)user_data;
351
352 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
353 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
354
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400355 g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400356 g_return_val_if_fail(priv, GDK_EVENT_PROPAGATE);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400357
358 /* we want to react to digit key presses, as long as a GtkEntry is not the
359 * input focus
360 */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500361 GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(self));
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400362 if (GTK_IS_ENTRY(focus))
363 return GDK_EVENT_PROPAGATE;
364
Guillaume Roguez6f431372017-12-12 21:15:39 -0500365 if (priv->cpp->accountContainer_ &&
366 priv->cpp->accountContainer_->info.profileInfo.type != lrc::api::profile::Type::SIP)
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400367 return GDK_EVENT_PROPAGATE;
368
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400369 /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c'
370 * does not result in a 'c' being played.
371 * we filter Ctrl, Alt, and SUPER/HYPER/META keys */
372 if ( event->state
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400373 & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ))
374 return GDK_EVENT_PROPAGATE;
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400375
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400376 // Get current conversation
377 auto current_view = gtk_bin_get_child(GTK_BIN(priv->frame_call));
378 lrc::api::conversation::Info current_item;
379 if (IS_CURRENT_CALL_VIEW(current_view))
380 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(current_view));
381 else
382 return GDK_EVENT_PROPAGATE;
383
384 if (current_item.callId.empty())
385 return GDK_EVENT_PROPAGATE;
386
387 // pass the character that was entered to be played by the daemon;
388 // the daemon will filter out invalid DTMF characters
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400389 guint32 unicode_val = gdk_keyval_to_unicode(event->keyval);
390 QString val = QString::fromUcs4(&unicode_val, 1);
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400391 g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData());
Guillaume Roguez6f431372017-12-12 21:15:39 -0500392 priv->cpp->accountContainer_->info.callModel->playDTMF(current_item.callId, val.toStdString());
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400393 // always propogate the key, so we don't steal accelerators/shortcuts
Stepan Salenikovich447f4a72015-04-29 11:09:28 -0400394 return GDK_EVENT_PROPAGATE;
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400395}
396
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400397static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500398on_tab_changed(GtkNotebook* notebook, GtkWidget* page, guint page_num, RingMainWindow* self)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400399{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500400 (void)notebook;
401 (void)page;
402
403 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
404 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
405
Guillaume Roguez6f431372017-12-12 21:15:39 -0500406 auto newType = page_num == 0 ? priv->cpp->accountContainer_->info.profileInfo.type : lrc::api::profile::Type::PENDING;
407 if (priv->cpp->currentTypeFilter_ != newType) {
408 priv->cpp->currentTypeFilter_ = newType;
409 priv->cpp->accountContainer_->info.conversationModel->setFilter(priv->cpp->currentTypeFilter_);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400410 }
Nicolas Jager0efc8432017-03-22 16:22:00 -0400411}
412
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400413static gboolean
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500414on_window_size_changed(GtkWidget* self, GdkEventConfigure* event, gpointer user_data)
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400415{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500416 (void)user_data;
417
418 g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), GDK_EVENT_PROPAGATE);
419 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikovichba87ae22016-09-13 14:27:20 -0400420
421 g_settings_set_int(priv->settings, "window-width", event->width);
422 g_settings_set_int(priv->settings, "window-height", event->height);
423
424 return GDK_EVENT_PROPAGATE;
425}
426
Stepan Salenikovicheafc3dd2015-04-16 18:38:01 -0400427static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500428on_search_entry_places_call_changed(GSettings* settings, const gchar* key, RingMainWindow* self)
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400429{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500430 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
431 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400432
433 if (g_settings_get_boolean(settings, key)) {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500434 gtk_widget_set_tooltip_text(priv->button_new_conversation,
435 C_("button next to search entry will place a new call",
436 "place call"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400437 } else {
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500438 gtk_widget_set_tooltip_text(priv->button_new_conversation,
439 C_("button next to search entry will open chat", "open chat"));
Stepan Salenikoviche9933242016-06-21 18:08:48 -0400440 }
441}
442
443static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500444on_handle_account_migrations(RingMainWindow* self)
aviau6aeb4852016-08-18 16:01:09 -0400445{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500446 g_return_if_fail(IS_RING_MAIN_WINDOW(self));
447 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
aviau6aeb4852016-08-18 16:01:09 -0400448
449 /* If there is an existing migration view, remove it */
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500450 if (priv->account_migration_view) {
Stepan Salenikovich56530b12016-10-20 17:51:34 -0400451 gtk_widget_destroy(priv->account_migration_view);
452 priv->account_migration_view = nullptr;
aviau6aeb4852016-08-18 16:01:09 -0400453 }
454
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500455 auto accounts = AccountModel::instance().accountsToMigrate();
456 if (!accounts.isEmpty()) {
457 auto* account = accounts.first();
aviau6aeb4852016-08-18 16:01:09 -0400458
aviau69081842016-10-14 14:51:54 -0400459 priv->account_migration_view = account_migration_view_new(account);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500460 g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed",
461 G_CALLBACK(on_handle_account_migrations), self);
462 g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed",
463 G_CALLBACK(on_handle_account_migrations), self);
aviau6aeb4852016-08-18 16:01:09 -0400464
465 gtk_widget_hide(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500466 priv->cpp->showAccountSelectorWidget(false);
aviau69081842016-10-14 14:51:54 -0400467 gtk_widget_show(priv->account_migration_view);
aviau6aeb4852016-08-18 16:01:09 -0400468 gtk_stack_add_named(
469 GTK_STACK(priv->stack_main_view),
aviau69081842016-10-14 14:51:54 -0400470 priv->account_migration_view,
aviau6aeb4852016-08-18 16:01:09 -0400471 ACCOUNT_MIGRATION_VIEW_NAME
472 );
473 gtk_stack_set_visible_child_name(
474 GTK_STACK(priv->stack_main_view),
475 ACCOUNT_MIGRATION_VIEW_NAME
476 );
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500477 } else {
aviau6aeb4852016-08-18 16:01:09 -0400478 gtk_widget_show(priv->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500479 priv->cpp->showAccountSelectorWidget();
aviau6aeb4852016-08-18 16:01:09 -0400480 }
481}
482
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500483} // namespace gtk_callbacks
484
Nicolas Jager5e2be732017-03-18 21:35:50 -0400485/**
486 * set the column value by printing the alias and the state of an account in combobox_account_selector.
487 */
488static void
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500489print_account_and_state(GtkCellLayout* cell_layout,
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400490 GtkCellRenderer* cell,
491 GtkTreeModel* model,
Nicolas Jager5e2be732017-03-18 21:35:50 -0400492 GtkTreeIter* iter,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500493 gpointer* data)
Nicolas Jager5e2be732017-03-18 21:35:50 -0400494{
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500495 (void)cell_layout;
496 (void)data;
497
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400498 gchar *alias;
499 gchar *text;
Nicolas Jager5e2be732017-03-18 21:35:50 -0400500
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400501 gtk_tree_model_get (model, iter,
502 1 /* col# */, &alias /* data */,
503 -1);
Nicolas Jager5e2be732017-03-18 21:35:50 -0400504
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400505 text = g_markup_printf_escaped(
506 "<span fgcolor=\"gray\">%s</span>",
507 alias
508 );
Nicolas Jager5e2be732017-03-18 21:35:50 -0400509
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400510 g_object_set(G_OBJECT(cell), "markup", text, NULL);
511 g_free(alias);
Nicolas Jager5e2be732017-03-18 21:35:50 -0400512}
513
Guillaume Roguez7e238402017-12-13 19:40:05 -0500514inline static void
515foreachEnabledLrcAccount(const lrc::api::Lrc& lrc,
516 const std::function<void(const lrc::api::account::Info&)>& func)
517{
518 auto& acc_model = lrc.getAccountModel();
519 for (const auto& id : acc_model.getAccountList()) {
520 const auto& accountInfo = acc_model.getAccountInfo(id);
521 if (accountInfo.enabled)
522 func(accountInfo);
523 }
524}
525
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500526CppImpl::CppImpl(RingMainWindow& widget)
527 : self {&widget}
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500528 , widgets {RING_MAIN_WINDOW_GET_PRIVATE(&widget)}
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500529 , lrc_ {std::make_unique<lrc::api::Lrc>()}
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -0500530{}
531
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500532void
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500533CppImpl::init()
534{
535 // NOTE: When new models will be fully implemented, we need to move this
536 // in rign_client.cpp->
537 // Init LRC and the vew
538 const auto accountIds = lrc_->getAccountModel().getAccountList();
539 auto isInitialized = false;
540 if (not accountIds.empty()) {
541 for (const auto& accountId : accountIds) {
542 const auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId);
543 if (accountInfo.enabled) {
544 updateLrc(accountId);
545 isInitialized = true;
546 break;
547 }
548 }
549 if (!isInitialized) {
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500550 widgets->treeview_conversations = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500551 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_smartview), widgets->treeview_conversations);
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500552 widgets->treeview_contact_requests = conversations_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500553 gtk_container_add(GTK_CONTAINER(widgets->scrolled_window_contact_requests), widgets->treeview_contact_requests);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500554 }
555 }
556
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500557 accountStatusChangedConnection_ = QObject::connect(&lrc_->getAccountModel(),
558 &lrc::api::NewAccountModel::accountStatusChanged,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500559 [this](const std::string& id){ slotAccountStatusChanged(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500560 newAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500561 &lrc::api::NewAccountModel::accountAdded,
Guillaume Roguez64236c22017-12-13 20:08:25 -0500562 [this](const std::string& id){ slotAccountAddedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500563 rmAccountConnection_ = QObject::connect(&lrc_->getAccountModel(),
Guillaume Roguez64236c22017-12-13 20:08:25 -0500564 &lrc::api::NewAccountModel::accountRemoved,
565 [this](const std::string& id){ slotAccountRemovedFromLrc(id); });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500566
567 /* bind to window size settings */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500568 widgets->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr);
569 auto width = g_settings_get_int(widgets->settings, "window-width");
570 auto height = g_settings_get_int(widgets->settings, "window-height");
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500571 gtk_window_set_default_size(GTK_WINDOW(self), width, height);
572 g_signal_connect(self, "configure-event", G_CALLBACK(on_window_size_changed), nullptr);
573
574 /* search-entry-places-call setting */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500575 on_search_entry_places_call_changed(widgets->settings, "search-entry-places-call", self);
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500576 g_signal_connect(widgets->settings, "changed::search-entry-places-call",
577 G_CALLBACK(on_search_entry_places_call_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500578
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500579 /* set window icon */
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500580 GError *error = NULL;
581 GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error);
582 if (icon == NULL) {
583 g_debug("Could not load icon: %s", error->message);
584 g_clear_error(&error);
585 } else
586 gtk_window_set_icon(GTK_WINDOW(self), icon);
587
588 /* set menu icon */
589 GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue",
590 -1, 16, TRUE, &error);
591 if (image_ring == NULL) {
592 g_debug("Could not load icon: %s", error->message);
593 g_clear_error(&error);
594 } else
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500595 gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_ring), image_ring);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500596
597 /* ring menu */
598 GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui");
599 GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu"));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500600 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(widgets->ring_menu), menu);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500601 g_object_unref(builder);
602
603 /* settings icon */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500604 gtk_image_set_from_icon_name(GTK_IMAGE(widgets->image_settings), "emblem-system-symbolic",
605 GTK_ICON_SIZE_SMALL_TOOLBAR);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500606
607 /* connect settings button signal */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500608 g_signal_connect_swapped(widgets->ring_settings, "clicked",
609 G_CALLBACK(on_settings_clicked), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500610
611 /* add the call view to the main stack */
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500612 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500613 CALL_VIEW_NAME);
614
615 /* init the settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500616 widgets->account_settings_view = account_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500617 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->account_settings_view,
618 ACCOUNT_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500619
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500620 widgets->media_settings_view = media_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500621 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->media_settings_view,
622 MEDIA_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500623
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500624 widgets->general_settings_view = general_settings_view_new();
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500625 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view,
626 GENERAL_SETTINGS_VIEW_NAME);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500627
628 /* make the setting we will show first the active one */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500629 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE);
630 widgets->last_settings_view = widgets->general_settings_view;
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500631
632 /* connect the settings button signals to switch settings views */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500633 g_signal_connect(widgets->radiobutton_media_settings, "toggled", G_CALLBACK(on_show_media_settings), self);
634 g_signal_connect(widgets->radiobutton_account_settings, "toggled", G_CALLBACK(on_show_account_settings), self);
635 g_signal_connect(widgets->radiobutton_general_settings, "toggled", G_CALLBACK(on_show_general_settings), self);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500636 g_signal_connect(widgets->notebook_contacts, "switch-page", G_CALLBACK(on_tab_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500637
638 /* welcome/default view */
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500639 widgets->welcome_view = ring_welcome_view_new(accountContainer_.get());
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500640 g_object_ref(widgets->welcome_view); // increase ref because don't want it to be destroyed when not displayed
641 gtk_container_add(GTK_CONTAINER(widgets->frame_call), widgets->welcome_view);
642 gtk_widget_show(widgets->welcome_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500643
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500644 g_signal_connect_swapped(widgets->search_entry, "activate", G_CALLBACK(on_search_entry_activated), self);
645 g_signal_connect_swapped(widgets->button_new_conversation, "clicked", G_CALLBACK(on_search_entry_activated), self);
646 g_signal_connect(widgets->search_entry, "search-changed", G_CALLBACK(on_search_entry_text_changed), self);
647 g_signal_connect(widgets->search_entry, "key-release-event", G_CALLBACK(on_search_entry_key_released), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500648
649 auto provider = gtk_css_provider_new();
650 gtk_css_provider_load_from_data(provider,
651 ".search-entry-style { border: 0; border-radius: 0; } \
652 .spinner-style { border: 0; background: white; } \
653 .new-conversation-style { border: 0; background: white; transition: all 0.3s ease; border-radius: 0; } \
654 .new-conversation-style:hover { background: #bae5f0; }",
655 -1, nullptr
656 );
657 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
658 GTK_STYLE_PROVIDER(provider),
659 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
660
661
662 /* react to digit key press events */
663 g_signal_connect(self, "key-press-event", G_CALLBACK(on_dtmf_pressed), nullptr);
664
665 /* set the search entry placeholder text */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500666 gtk_entry_set_placeholder_text(GTK_ENTRY(widgets->search_entry),
Guillaume Roguez1eb30c62017-12-13 19:40:47 -0500667 C_("Please try to make the translation 50 chars or less so that it fits into the layout",
668 "Search contacts or enter number"));
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500669
670 /* init chat webkit container so that it starts loading before the first time we need it*/
671 (void)webkitChatContainer();
672
673 if (has_ring_account()) {
674 /* user has ring account, so show the call view right away */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500675 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->vbox_call_view);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500676
677 on_handle_account_migrations(self);
678 } else {
679 /* user has to create the ring account */
680 enterAccountCreationWizard();
681 }
682
683 // setup account selector and select the first account
684 auto store = gtk_list_store_new (2 /* # of cols */ ,
685 G_TYPE_STRING,
686 G_TYPE_STRING,
687 G_TYPE_UINT);
688 GtkTreeIter iter;
Guillaume Roguez7e238402017-12-13 19:40:05 -0500689 foreachEnabledLrcAccount(*lrc_, [&] (const auto& acc_info) {
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500690 gtk_list_store_append (store, &iter);
691 gtk_list_store_set (store, &iter,
Guillaume Roguez7e238402017-12-13 19:40:05 -0500692 0 /* col # */ , acc_info.id.c_str() /* celldata */,
693 1 /* col # */ , acc_info.profileInfo.alias.c_str() /* celldata */,
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500694 -1 /* end */);
Guillaume Roguez7e238402017-12-13 19:40:05 -0500695 });
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500696
697 gtk_combo_box_set_model(
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500698 GTK_COMBO_BOX(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500699 GTK_TREE_MODEL (store)
700 );
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500701 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), 0);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500702
703 /* set visibility */
704 showAccountSelectorWidget();
705
706 /* layout */
707 auto *renderer = gtk_cell_renderer_text_new();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500708 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, FALSE);
709 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widgets->combobox_account_selector), renderer, "text", 0, NULL);
710 gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(widgets->combobox_account_selector),
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500711 renderer,
712 (GtkCellLayoutDataFunc)print_account_and_state,
713 nullptr, nullptr);
714
715 // we closing any view opened to avoid confusion (especially between SIP and Ring protocols).
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500716 g_signal_connect_swapped(widgets->combobox_account_selector, "changed", G_CALLBACK(on_account_changed), self);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500717
718 // initialize the pending contact request icon.
719 setPendingContactRequestTabIcon();
720
721 if (isInitialized) {
722 auto& conversationModel = accountContainer_->info.conversationModel;
723 auto conversations = conversationModel->allFilteredConversations();
724 for (const auto& conversation: conversations) {
725 if (!conversation.callId.empty()) {
726 accountContainer_->info.conversationModel->selectConversation(conversation.uid);
727 }
728 }
729 }
730}
731
732CppImpl::~CppImpl()
733{
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500734 QObject::disconnect(selected_item_changed);
735 QObject::disconnect(selected_call_over);
736 QObject::disconnect(showChatViewConnection_);
737 QObject::disconnect(showIncomingViewConnection_);
738 QObject::disconnect(historyClearedConnection_);
739 QObject::disconnect(modelSortedConnection_);
740 QObject::disconnect(filterChangedConnection_);
741 QObject::disconnect(newConversationConnection_);
742 QObject::disconnect(conversationRemovedConnection_);
743 QObject::disconnect(changeAccountConnection_);
744 QObject::disconnect(newAccountConnection_);
745 QObject::disconnect(rmAccountConnection_);
746 QObject::disconnect(showCallViewConnection_);
747 QObject::disconnect(modelSortedConnection_);
748 QObject::disconnect(accountStatusChangedConnection_);
749
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500750 g_clear_object(&widgets->welcome_view);
751 g_clear_object(&widgets->webkit_chat_container);
Guillaume Roguez47cd8b52017-12-13 14:06:01 -0500752}
753
754void
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500755CppImpl::changeView(GType type, lrc::api::conversation::Info conversation)
756{
Guillaume Roguez1d963272017-12-12 23:32:13 -0500757 leaveFullScreen();
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500758 gtk_container_remove(GTK_CONTAINER(widgets->frame_call),
759 gtk_bin_get_child(GTK_BIN(widgets->frame_call)));
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500760
761 QObject::disconnect(selected_item_changed);
762 QObject::disconnect(selected_call_over);
763
764 GtkWidget* new_view;
765 if (g_type_is_a(INCOMING_CALL_VIEW_TYPE, type)) {
766 new_view = displayIncomingView(conversation);
767 } else if (g_type_is_a(CURRENT_CALL_VIEW_TYPE, type)) {
768 new_view = displayCurrentCallView(conversation);
769 } else if (g_type_is_a(CHAT_VIEW_TYPE, type)) {
770 new_view = displayChatView(conversation);
771 } else {
772 // TODO select first conversation?
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500773 new_view = widgets->welcome_view;
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500774 }
775
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500776 gtk_container_add(GTK_CONTAINER(widgets->frame_call), new_view);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500777 gtk_widget_show(new_view);
778}
779
780GtkWidget*
781CppImpl::displayIncomingView(lrc::api::conversation::Info conversation)
782{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500783 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
784 return incoming_call_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500785}
786
787GtkWidget*
788CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation)
789{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500790 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
Guillaume Roguez11339f82017-12-12 23:15:34 -0500791 auto* new_view = current_call_view_new(webkitChatContainer(),
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500792 accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500793
794 try {
795 auto contactUri = chatViewConversation_->participants.front();
796 auto contactInfo = accountContainer_->info.contactModel->getContact(contactUri);
797 if (auto chat_view = current_call_view_get_chat_view(CURRENT_CALL_VIEW(new_view))) {
798 chat_view_update_temporary(CHAT_VIEW(chat_view),
799 contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING
800 || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY);
801 }
802 } catch(...) { }
803
Guillaume Roguez1d963272017-12-12 23:32:13 -0500804 g_signal_connect_swapped(new_view, "video-double-clicked",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500805 G_CALLBACK(on_video_double_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500806 return new_view;
807}
808
809GtkWidget*
810CppImpl::displayChatView(lrc::api::conversation::Info conversation)
811{
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500812 chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
813 auto* new_view = chat_view_new(webkitChatContainer(), accountContainer_.get(), chatViewConversation_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500814 g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self);
Guillaume Roguez527dc6b2017-12-12 22:58:51 -0500815 return new_view;
816}
817
Guillaume Roguez11339f82017-12-12 23:15:34 -0500818WebKitChatContainer*
819CppImpl::webkitChatContainer() const
820{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500821 if (!widgets->webkit_chat_container) {
822 widgets->webkit_chat_container = webkit_chat_container_new();
Guillaume Roguez11339f82017-12-12 23:15:34 -0500823
824 // We don't want it to be deleted, ever.
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500825 g_object_ref(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500826 }
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500827 return WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container);
Guillaume Roguez11339f82017-12-12 23:15:34 -0500828}
829
Guillaume Roguez1d963272017-12-12 23:32:13 -0500830void
831CppImpl::enterFullScreen()
832{
833 if (!is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500834 gtk_widget_hide(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500835 gtk_window_fullscreen(GTK_WINDOW(self));
836 is_fullscreen = true;
837 }
838}
839
840void
841CppImpl::leaveFullScreen()
842{
843 if (is_fullscreen) {
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500844 gtk_widget_show(widgets->vbox_left_pane);
Guillaume Roguez1d963272017-12-12 23:32:13 -0500845 gtk_window_unfullscreen(GTK_WINDOW(self));
846 is_fullscreen = false;
847 }
848}
849
850void
851CppImpl::toggleFullScreen()
852{
853 if (is_fullscreen)
854 leaveFullScreen();
855 else
856 enterFullScreen();
857}
858
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500859/// Clear selection and go to welcome page.
860void
861CppImpl::resetToWelcome()
862{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500863 auto selection_conversations = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_conversations));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500864 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_conversations));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500865 auto selection_contact_request = gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->treeview_contact_requests));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500866 gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection_contact_request));
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500867 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
Guillaume Roguez6ee8df62017-12-12 23:54:18 -0500868 lrc::api::conversation::Info current_item;
869 if (IS_CHAT_VIEW(old_view))
870 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
871 changeView(RING_WELCOME_VIEW_TYPE, current_item);
872}
873
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500874void
875CppImpl::setPendingContactRequestTabIcon()
876{
877 if (not accountContainer_)
878 return;
879
880 auto isRingAccount = accountContainer_->info.profileInfo.type == lrc::api::profile::Type::RING;
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500881 gtk_widget_set_visible(widgets->scrolled_window_contact_requests, isRingAccount);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500882
883 if (not isRingAccount)
884 return;
885
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500886 gtk_image_set_from_resource(GTK_IMAGE(widgets->image_contact_requests_list),
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500887 (accountContainer_->info.contactModel->hasPendingRequests())
888 ? "/cx/ring/RingGnome/contact_requests_list_with_notification"
889 : "/cx/ring/RingGnome/contact_requests_list");
890}
891
892void
893CppImpl::showAccountSelectorWidget(bool show)
894{
895 // we only want to show the account selector when there is more than 1 enabled
896 // account; so every time we want to show it, we should preform this check
Guillaume Roguez7e238402017-12-13 19:40:05 -0500897 std::size_t activatedAccount = 0;
898 foreachEnabledLrcAccount(*lrc_, [&] (const auto&) { ++activatedAccount; });
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500899 gtk_widget_set_visible(widgets->combobox_account_selector, show && activatedAccount > 1);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500900}
901
902void
903CppImpl::enterAccountCreationWizard()
904{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500905 if (!widgets->account_creation_wizard) {
906 widgets->account_creation_wizard = account_creation_wizard_new(false);
907 g_object_add_weak_pointer(G_OBJECT(widgets->account_creation_wizard),
908 reinterpret_cast<gpointer*>(&widgets->account_creation_wizard));
909 g_signal_connect_swapped(widgets->account_creation_wizard, "account-creation-completed",
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500910 G_CALLBACK(on_account_creation_completed), self);
911
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500912 gtk_stack_add_named(GTK_STACK(widgets->stack_main_view),
913 widgets->account_creation_wizard,
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500914 ACCOUNT_CREATION_WIZARD_VIEW_NAME);
915 }
916
917 /* hide settings button until account creation is complete */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500918 gtk_widget_hide(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500919 showAccountSelectorWidget(false);
920
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500921 gtk_widget_show(widgets->account_creation_wizard);
922 gtk_stack_set_visible_child(GTK_STACK(widgets->stack_main_view), widgets->account_creation_wizard);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500923}
924
925void
926CppImpl::leaveAccountCreationWizard()
927{
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500928 gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500929
930 /* destroy the wizard */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500931 if (widgets->account_creation_wizard) {
932 gtk_container_remove(GTK_CONTAINER(widgets->stack_main_view), widgets->account_creation_wizard);
933 gtk_widget_destroy(widgets->account_creation_wizard);
934 widgets->account_creation_wizard = nullptr;
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500935 }
936
937 /* show the settings button */
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500938 gtk_widget_show(widgets->ring_settings);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500939
940 /* show the account selector */
941 showAccountSelectorWidget();
942}
943
944void
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500945CppImpl::useAccount(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500946{
947 // Go to welcome view
948 changeView(RING_WELCOME_VIEW_TYPE);
949
950 // Change account selection widget
951 auto accounts = lrc_->getAccountModel().getAccountList();
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500952 auto it = std::find(accounts.begin(), accounts.end(), id );
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500953 if (it == accounts.end()) {
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500954 qDebug() << "useAccount, cannot find account " << id.c_str();
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500955 return;
956 }
957
958 int row = it - accounts.begin();
959
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500960 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->combobox_account_selector), row);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500961 // Show conversation panel
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500962 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500963 // Reinit LRC
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500964 updateLrc(std::string(id));
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500965 // Update the welcome view
Guillaume Roguezb96d6532017-12-13 14:31:39 -0500966 ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view), accountContainer_.get());
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500967}
968
969void
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500970CppImpl::onAccountChangeFromUI(const std::string& id)
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500971{
972 // Reinit view
973 changeView(RING_WELCOME_VIEW_TYPE);
Guillaume Roguez3ea37de2017-12-13 14:13:54 -0500974 gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->notebook_contacts), 0);
Guillaume Roguezdbefafd2017-12-12 23:54:49 -0500975
976 // Change account
Guillaume Roguez5121fd62017-12-13 18:51:52 -0500977 updateLrc(id);
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{
1336 if (id != accountContainer_->info.id)
1337 useAccount(id);
1338 // Show chat view if not in call (unless if it's the same conversation)
1339 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1340 lrc::api::conversation::Info current_item;
1341 current_item.uid = "-1";
1342 if (IS_CHAT_VIEW(old_view))
1343 current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
1344 if (current_item.uid != origin.uid) {
1345 if (origin.participants.empty()) return;
1346 auto firstContactUri = origin.participants.front();
1347 auto contactInfo = accountContainer_->info.contactModel->getContact(firstContactUri);
1348 if (contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING && current_item.uid != "-1") return;
1349 changeView(CHAT_VIEW_TYPE, origin);
1350 }
1351}
1352
1353void
1354CppImpl::slotShowCallView(const std::string& id, lrc::api::conversation::Info origin)
1355{
1356 if (id != accountContainer_->info.id)
1357 useAccount(id);
1358 // Change the view if we want a different view.
1359 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1360
1361 lrc::api::conversation::Info current_item;
1362 if (IS_CURRENT_CALL_VIEW(old_view))
1363 current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
1364
1365 if (current_item.uid != origin.uid)
1366 changeView(CURRENT_CALL_VIEW_TYPE, origin);
1367}
1368
1369void
1370CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin)
1371{
1372 if (id != accountContainer_->info.id)
1373 useAccount(id);
1374 // Change the view if we want a different view.
1375 auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
1376
1377 lrc::api::conversation::Info current_item;
1378 if (IS_INCOMING_CALL_VIEW(old_view))
1379 current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
1380
1381 if (current_item.uid != origin.uid)
1382 changeView(INCOMING_CALL_VIEW_TYPE, origin);
1383}
1384
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001385} // namespace details
1386
1387//==============================================================================
Guillaume Roguez0a411202017-05-25 15:27:26 -04001388
1389static void
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001390ring_main_window_init(RingMainWindow *win)
1391{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001392 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001393 gtk_widget_init_template(GTK_WIDGET(win));
1394
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001395 // CppImpl ctor
1396 priv->cpp = new details::CppImpl {*win};
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001397 priv->cpp->init();
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001398}
1399
1400static void
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001401ring_main_window_dispose(GObject *object)
1402{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001403 auto* self = RING_MAIN_WINDOW(object);
1404 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001405
Guillaume Roguez1e50f0b2017-12-12 20:58:30 -05001406 delete priv->cpp;
1407 priv->cpp = nullptr;
1408
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001409 G_OBJECT_CLASS(ring_main_window_parent_class)->dispose(object);
1410}
1411
1412static void
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001413ring_main_window_finalize(GObject *object)
1414{
Guillaume Roguez6f431372017-12-12 21:15:39 -05001415 auto* self = RING_MAIN_WINDOW(object);
1416 auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(self);
Stepan Salenikovichba87ae22016-09-13 14:27:20 -04001417
1418 g_clear_object(&priv->settings);
1419
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001420 G_OBJECT_CLASS(ring_main_window_parent_class)->finalize(object);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001421}
1422
1423static void
1424ring_main_window_class_init(RingMainWindowClass *klass)
1425{
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001426 G_OBJECT_CLASS(klass)->finalize = ring_main_window_finalize;
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001427 G_OBJECT_CLASS(klass)->dispose = ring_main_window_dispose;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001428
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001429 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
1430 "/cx/ring/RingGnome/ringmainwindow.ui");
1431
Stepan Salenikovichbbb10d82015-05-13 12:26:44 -04001432 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_left_pane);
Sébastien Blin55bff9d2017-10-03 15:15:23 -04001433 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, notebook_contacts);
Stepan Salenikovich2f8b4492015-09-21 17:10:36 -04001434 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_smartview);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001435 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_menu);
1436 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_ring);
1437 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, ring_settings);
1438 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001439 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, hbox_settings);
Stepan Salenikovich45d25aa2015-02-20 17:39:09 -05001440 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, search_entry);
Stepan Salenikovich69771842015-02-24 18:11:45 -05001441 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, stack_main_view);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001442 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, vbox_call_view);
Stepan Salenikovich3034d922015-10-09 10:11:42 -04001443 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, frame_call);
Stepan Salenikoviche9933242016-06-21 18:08:48 -04001444 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, button_new_conversation );
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001445 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_general_settings);
Stepan Salenikovich5d3506e2015-03-30 11:01:29 -04001446 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -04001447 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings);
Nicolas Jager15a8b902017-03-21 07:53:06 -04001448 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, combobox_account_selector);
Nicolas Jager0efc8432017-03-22 16:22:00 -04001449 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, scrolled_window_contact_requests);
Guillaume Roguez0a411202017-05-25 15:27:26 -04001450 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, image_contact_requests_list);
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001451}
1452
1453GtkWidget *
Guillaume Roguez47cd8b52017-12-13 14:06:01 -05001454ring_main_window_new(GtkApplication *app)
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001455{
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001456 gpointer win = g_object_new(RING_MAIN_WINDOW_TYPE, "application", app, NULL);
Stepan Salenikovich61cbab02015-03-16 18:35:10 -04001457 return (GtkWidget *)win;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -05001458}