blob: cbb8457e14f7de0ff20ab38e8c4ac7c7fbd8b4c5 [file] [log] [blame]
Stepan Salenikovichd81ef292015-02-17 18:47:37 -05001/*
Guillaume Roguez2a6150d2017-07-19 18:24:47 -04002 * Copyright (C) 2015-2017 Savoir-faire Linux Inc.
Stepan Salenikovichd81ef292015-02-17 18:47:37 -05003 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050018 */
19
20#include "ring_client.h"
21
Stepan Salenikovich472c9052016-07-20 19:16:02 -040022// system
23#include <memory>
Victor Nikulshin167bbb62017-03-15 20:44:27 +000024#include <regex>
Stepan Salenikovich472c9052016-07-20 19:16:02 -040025
26// GTK+ related
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050027#include <gtk/gtk.h>
28#include <glib/gi18n.h>
Stepan Salenikovich472c9052016-07-20 19:16:02 -040029#include <clutter-gtk/clutter-gtk.h>
30
31// Qt
Stepan Salenikovich67c5dd32015-09-14 12:27:36 -040032#include <QtCore/QTranslator>
Stepan Salenikovichd2dbcee2015-02-27 16:52:28 -050033#include <QtCore/QCoreApplication>
34#include <QtCore/QString>
35#include <QtCore/QByteArray>
Stepan Salenikovichd2dbcee2015-02-27 16:52:28 -050036#include <QtCore/QItemSelectionModel>
Stepan Salenikovich472c9052016-07-20 19:16:02 -040037#include <QtCore/QStandardPaths>
38
39// LRC
40#include <callmodel.h>
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050041#include <useractionmodel.h>
Stepan Salenikovichdd84cf92015-03-19 21:38:19 -040042#include <categorizedhistorymodel.h>
Stepan Salenikovich6f687072015-03-26 10:43:37 -040043#include <personmodel.h>
44#include <fallbackpersoncollection.h>
Stepan Salenikovich1e131a42015-05-27 14:12:21 -040045#include <localhistorycollection.h>
Stepan Salenikovich67112d12015-06-16 16:57:06 -040046#include <media/text.h>
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040047#include <numbercategorymodel.h>
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -040048#include <globalinstances.h>
Stepan Salenikovich472c9052016-07-20 19:16:02 -040049#include <profilemodel.h>
50#include <profile.h>
51#include <peerprofilecollection.h>
52#include <localprofilecollection.h>
53#include <accountmodel.h>
Olivier Gregoire66e4df72016-06-17 18:39:05 -040054#include <smartinfohub.h>
Stepan Salenikovich5a127672016-09-13 11:19:50 -040055#include <media/textrecording.h>
56#include <media/recordingmodel.h>
Stepan Salenikovich509670b2017-04-24 15:18:06 -040057#include <availableaccountmodel.h>
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050058
Stepan Salenikovich472c9052016-07-20 19:16:02 -040059// Ring client
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050060#include "ring_client_options.h"
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050061#include "ringmainwindow.h"
Stepan Salenikovich24dcd5c2015-03-26 17:40:34 -040062#include "dialogs.h"
Stepan Salenikovich6f687072015-03-26 10:43:37 -040063#include "backends/edscontactbackend.h"
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -040064#include "native/pixbufmanipulator.h"
Stepan Salenikovichbe6550c2015-08-21 16:16:03 -040065#include "native/dbuserrorhandler.h"
Stepan Salenikovich76c33e62015-05-22 12:24:07 -040066#include "ringnotify.h"
Stepan Salenikovich76350582015-05-25 14:56:32 -040067#include "config.h"
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -040068#include "utils/files.h"
Stepan Salenikovich4f9bb982015-06-23 14:26:30 -040069#include "revision.h"
Stepan Salenikovich75a39172015-07-10 13:21:08 -040070#include "utils/accounts.h"
Victor Nikulshin167bbb62017-03-15 20:44:27 +000071#include "utils/calling.h"
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050072
Stepan Salenikovich72d812f2017-01-05 12:16:25 -050073#if HAVE_APPINDICATOR
Stepan Salenikovich982b2882016-06-15 13:13:37 -040074#include <libappindicator/app-indicator.h>
75#endif
76
Stepan Salenikovich472c9052016-07-20 19:16:02 -040077#if USE_LIBNM
Stepan Salenikovich28ca3172016-07-22 17:29:11 -040078#include <libnm-glib/nm-client.h>
Stepan Salenikovich472c9052016-07-20 19:16:02 -040079#endif
80
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050081struct _RingClientClass
82{
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -040083 GtkApplicationClass parent_class;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050084};
85
86struct _RingClient
87{
88 GtkApplication parent;
89};
90
91typedef struct _RingClientPrivate RingClientPrivate;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050092
93struct _RingClientPrivate {
Stepan Salenikovich0d515e52015-05-19 16:31:05 -040094 /* args */
95 int argc;
96 char **argv;
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -040097
98 GSettings *settings;
99
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500100 /* main window */
101 GtkWidget *win;
102 /* for libRingclient */
103 QCoreApplication *qtapp;
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400104 /* UAM */
105 QMetaObject::Connection uam_updated;
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400106
Guillaume Roguez884ef732017-07-14 12:53:35 -0400107 std::unique_ptr<QTranslator> translator_lang;
108 std::unique_ptr<QTranslator> translator_full;
Stepan Salenikovich6c39b102015-09-15 14:24:45 -0400109
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400110 GCancellable *cancellable;
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400111
112 gboolean restore_window_state;
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400113
114 gpointer systray_icon;
115 GtkWidget *icon_menu;
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400116
117#if USE_LIBNM
118 /* NetworkManager */
119 NMClient *nm_client;
Stepan Salenikovich221beae2016-10-12 11:29:56 -0400120 NMActiveConnection *primary_connection;
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400121#endif
Stepan Salenikovich5a127672016-09-13 11:19:50 -0400122
123 /* notifications */
124 QMetaObject::Connection call_notification;
125 QMetaObject::Connection chat_notification;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500126};
127
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400128/* this union is used to pass ints as pointers and vice versa for GAction parameters*/
129typedef union _int_ptr_t
130{
131 int value;
132 gint64 value64;
133 gpointer ptr;
134} int_ptr_t;
135
Stepan Salenikovich434b88f2015-02-19 17:49:08 -0500136G_DEFINE_TYPE_WITH_PRIVATE(RingClient, ring_client, GTK_TYPE_APPLICATION);
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500137
138#define RING_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_CLIENT_TYPE, RingClientPrivate))
139
140static void
Stepan Salenikovich541a40a2016-08-17 11:33:47 -0400141exception_dialog(const char* msg)
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500142{
Stepan Salenikovich541a40a2016-08-17 11:33:47 -0400143 g_critical("%s", msg);
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500144 GtkWidget *dialog = gtk_message_dialog_new(NULL,
145 (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
146 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
147 _("Unable to initialize.\nMake sure the Ring daemon (dring) is running.\nError: %s"),
148 msg);
149
150 gtk_window_set_title(GTK_WINDOW(dialog), _("Ring Error"));
151 gtk_dialog_run(GTK_DIALOG(dialog));
152 gtk_widget_destroy(dialog);
153}
154
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400155static void
156ring_accelerators(RingClient *client)
157{
Stepan Salenikovich39ee49a2015-03-24 12:44:55 -0400158#if GTK_CHECK_VERSION(3,12,0)
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400159 const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
160 gtk_application_set_accels_for_action(GTK_APPLICATION(client), "app.quit", quit_accels);
161#else
Stepan Salenikovich870d7392015-09-08 11:18:46 -0400162 gtk_application_add_accelerator(GTK_APPLICATION(client), "<Control>Q", "app.quit", NULL);
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400163#endif
164}
165
166static void
167action_quit(G_GNUC_UNUSED GSimpleAction *simple,
168 G_GNUC_UNUSED GVariant *parameter,
169 gpointer user_data)
170{
171 g_return_if_fail(G_IS_APPLICATION(user_data));
172
173#if GLIB_CHECK_VERSION(2,32,0)
174 g_application_quit(G_APPLICATION(user_data));
175#else
176 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(user_data);
177 gtk_widget_destroy(priv->win);
178#endif
179}
180
Stepan Salenikovich24dcd5c2015-03-26 17:40:34 -0400181static void
182action_about(G_GNUC_UNUSED GSimpleAction *simple,
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400183 G_GNUC_UNUSED GVariant *parameter,
184 gpointer user_data)
Stepan Salenikovich24dcd5c2015-03-26 17:40:34 -0400185{
186 g_return_if_fail(G_IS_APPLICATION(user_data));
187 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(user_data);
188
189 ring_about_dialog(priv->win);
190}
191
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400192static void
193toggle_smartinfo(GSimpleAction *action, GVariant *parameter, gpointer)
194{
195 g_simple_action_set_state(action, parameter);
196 if (g_variant_get_boolean(parameter)) {
197 SmartInfoHub::instance().start();
198 } else {
199 SmartInfoHub::instance().stop();
200 }
201}
202
Stepan Salenikovich69771842015-02-24 18:11:45 -0500203static const GActionEntry ring_actions[] =
204{
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400205 { "accept", NULL, NULL, NULL, NULL, {0} },
206 { "hangup", NULL, NULL, NULL, NULL, {0} },
207 { "hold", NULL, NULL, "false", NULL, {0} },
208 { "quit", action_quit, NULL, NULL, NULL, {0} },
209 { "about", action_about, NULL, NULL, NULL, {0} },
210 { "mute_audio", NULL, NULL, "false", NULL, {0} },
211 { "mute_video", NULL, NULL, "false", NULL, {0} },
212 { "record", NULL, NULL, "false", NULL, {0} },
213 { "display-smartinfo", NULL, NULL, "false", toggle_smartinfo, {0} },
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500214 /* TODO implement the other actions */
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500215 // { "transfer", NULL, NULL, "flase", NULL, {0} },
Stepan Salenikovich69771842015-02-24 18:11:45 -0500216};
217
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500218static void
219activate_action(GSimpleAction *action, G_GNUC_UNUSED GVariant *parameter, gpointer user_data)
220{
221 g_debug("activating action: %s", g_action_get_name(G_ACTION(action)));
222
223 int_ptr_t key;
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400224
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500225 key.ptr = user_data;
226 UserActionModel::Action a = static_cast<UserActionModel::Action>(key.value);
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400227 UserActionModel* uam = CallModel::instance().userActionModel();
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500228
229 uam << a;
230}
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500231
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400232static void
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400233autostart_toggled(GSettings *settings, G_GNUC_UNUSED gchar *key, G_GNUC_UNUSED gpointer user_data)
234{
235 autostart_symlink(g_settings_get_boolean(settings, "start-on-login"));
236}
237
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400238
239static void
240show_main_window_toggled(RingClient *client)
241{
242 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
243
244 if (g_settings_get_boolean(priv->settings, "show-main-window")) {
245 gtk_window_present(GTK_WINDOW(priv->win));
246 } else {
247 gtk_widget_hide(priv->win);
248 }
249}
250
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400251static void
252ring_window_show(RingClient *client)
253{
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400254 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400255 g_settings_set_boolean(priv->settings, "show-main-window", TRUE);
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400256}
257
258static void
259ring_window_hide(RingClient *client)
260{
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400261 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400262 g_settings_set_boolean(priv->settings, "show-main-window", FALSE);
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400263}
264
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400265static gboolean
266on_close_window(GtkWidget *window, G_GNUC_UNUSED GdkEvent *event, RingClient *client)
267{
268 g_return_val_if_fail(GTK_IS_WINDOW(window) && IS_RING_CLIENT(client), FALSE);
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400269 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
270
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400271 if (g_settings_get_boolean(priv->settings, "show-status-icon")) {
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400272 /* we want to simply hide the window and keep the client running */
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400273 ring_window_hide(client);
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400274 return TRUE; /* do not propogate event */
275 } else {
276 /* we want to quit the application, so just propogate the event */
277 return FALSE;
278 }
279}
280
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400281static void
282popup_menu(GtkStatusIcon *self,
283 guint button,
284 guint when,
285 RingClient *client)
286{
287 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
288 G_GNUC_BEGIN_IGNORE_DEPRECATIONS // GtkStatusIcon is deprecated since 3.14, but we fallback on it
289 gtk_menu_popup(GTK_MENU(priv->icon_menu), NULL, NULL, gtk_status_icon_position_menu, self, button, when);
290 G_GNUC_END_IGNORE_DEPRECATIONS
291}
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400292
293static void
294init_systray(RingClient *client)
295{
296 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
297
298 // init menu
299 if (!priv->icon_menu) {
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400300
Stepan Salenikovich97177362016-06-22 18:38:24 -0400301 /* for some reason AppIndicator doesn't like the menu being built from a GMenuModel and/or
302 * the GMenuModel being built from an xml resource. So we build the menu in code.
303 */
304 priv->icon_menu = gtk_menu_new();
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400305 g_object_ref_sink(priv->icon_menu);
Stepan Salenikovich97177362016-06-22 18:38:24 -0400306
307 auto item = gtk_check_menu_item_new_with_label(C_("In the status icon menu, toggle action to show or hide the Ring main window", "Show Ring"));
308 gtk_actionable_set_action_name(GTK_ACTIONABLE(item), "app.show-main-window");
309 gtk_menu_shell_append(GTK_MENU_SHELL(priv->icon_menu), item);
310
311 item = gtk_menu_item_new_with_label(_("Quit"));
312 gtk_actionable_set_action_name(GTK_ACTIONABLE(item), "app.quit");
313 gtk_menu_shell_append(GTK_MENU_SHELL(priv->icon_menu), item);
314
315 gtk_widget_insert_action_group(priv->icon_menu, "app", G_ACTION_GROUP(client));
316 gtk_widget_show_all(priv->icon_menu);
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400317 }
318
Stepan Salenikovich72d812f2017-01-05 12:16:25 -0500319 gboolean use_appinidcator = FALSE;
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400320
Stepan Salenikovich72d812f2017-01-05 12:16:25 -0500321#if HAVE_APPINDICATOR
322 /* only use AppIndicator in Unity (Tuleap: #1440) */
323 const auto desktop = g_getenv("XDG_CURRENT_DESKTOP");
Marco Martin7f2b5ab2017-03-23 12:13:02 +0100324 if (g_strcmp0("Unity", desktop) == 0 || g_strcmp0("KDE", desktop) == 0) {
Stepan Salenikovich72d812f2017-01-05 12:16:25 -0500325 use_appinidcator = TRUE;
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400326
Stepan Salenikovich72d812f2017-01-05 12:16:25 -0500327 auto indicator = app_indicator_new("ring", "ring", APP_INDICATOR_CATEGORY_COMMUNICATIONS);
328 app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
329 app_indicator_set_title(indicator, "ring");
330 /* app indicator requires a menu */
331 app_indicator_set_menu(indicator, GTK_MENU(priv->icon_menu));
332 priv->systray_icon = indicator;
333 }
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400334#endif
Stepan Salenikovich72d812f2017-01-05 12:16:25 -0500335
336 if (!use_appinidcator) {
337G_GNUC_BEGIN_IGNORE_DEPRECATIONS // GtkStatusIcon is deprecated since 3.14, but we fallback on it
338 auto status_icon = gtk_status_icon_new_from_icon_name("ring");
339 gtk_status_icon_set_title(status_icon, "ring");
340G_GNUC_END_IGNORE_DEPRECATIONS
341 g_signal_connect_swapped(status_icon, "activate", G_CALLBACK(ring_window_show), client);
342 g_signal_connect(status_icon, "popup-menu", G_CALLBACK(popup_menu), client);
343
344 priv->systray_icon = status_icon;
345 }
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400346}
347
348static void
349systray_toggled(GSettings *settings, const gchar *key, RingClient *client)
350{
351 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
352
353 if (g_settings_get_boolean(settings, key)) {
354 if (!priv->systray_icon)
355 init_systray(client);
356 } else {
357 if (priv->systray_icon)
358 g_clear_object(&priv->systray_icon);
359 }
360}
361
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400362static void
363ring_client_activate(GApplication *app)
364{
365 RingClient *client = RING_CLIENT(app);
366 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
367
368 if (priv->win == NULL) {
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400369 // activate being called for the first time
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400370 priv->win = ring_main_window_new(GTK_APPLICATION(app));
371
372 /* make sure win is set to NULL when the window is destroyed */
373 g_object_add_weak_pointer(G_OBJECT(priv->win), (gpointer *)&priv->win);
374
375 /* check if the window should be destoryed or not on close */
376 g_signal_connect(priv->win, "delete-event", G_CALLBACK(on_close_window), client);
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400377
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400378 /* if we didn't launch with the '-r' (--restore-last-window-state) option then force the
379 * show-main-window to true */
380 if (!priv->restore_window_state)
381 ring_window_show(client);
Stepan Salenikovich3f27dc92016-06-22 18:08:01 -0400382 show_main_window_toggled(client);
383 g_signal_connect_swapped(priv->settings, "changed::show-main-window", G_CALLBACK(show_main_window_toggled), client);
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400384
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400385 // track sys icon state
386 g_signal_connect(priv->settings, "changed::show-status-icon", G_CALLBACK(systray_toggled), client);
387 systray_toggled(priv->settings, "show-status-icon", client);
388 } else {
389 // activate not being called for the first time, force showing of main window
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400390 ring_window_show(client);
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400391 }
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400392}
393
Victor Nikulshin167bbb62017-03-15 20:44:27 +0000394static void
395ring_client_open(GApplication *app, GFile **file, gint /*arg3*/, const gchar* /*arg4*/)
396{
397 ring_client_activate(app);
398
399 if (strcmp(g_file_get_uri_scheme(*file), "ring") == 0) {
400 const char * call_id = g_file_get_basename(*file);
401 std::regex format {"^[[:xdigit:]]{40}$"};
402
403 if (std::regex_match(call_id, format)) {
404 auto cm = std::unique_ptr<TemporaryContactMethod>(new TemporaryContactMethod);
405 cm->setUri(URI(QString::fromStdString(call_id)));
406
407 place_new_call(cm.get());
408 cm.release();
409 }
410 }
411}
412
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400413#if USE_LIBNM
414
415static void
416log_connection_info(NMActiveConnection *connection)
417{
418 if (connection) {
Stepan Salenikovich02b283d2016-07-27 18:09:21 -0400419 g_debug("primary network connection: %s, default: %s",
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400420 nm_active_connection_get_uuid(connection),
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400421 nm_active_connection_get_default(connection) ? "yes" : "no");
422 } else {
423 g_warning("no primary network connection detected, check network settings");
424 }
425}
426
427static void
Stepan Salenikovich221beae2016-10-12 11:29:56 -0400428primary_connection_changed(NMClient *nm, GParamSpec*, RingClient *self)
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400429{
Stepan Salenikovich221beae2016-10-12 11:29:56 -0400430 auto priv = RING_CLIENT_GET_PRIVATE(self);
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400431 auto connection = nm_client_get_primary_connection(nm);
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400432
Stepan Salenikovich221beae2016-10-12 11:29:56 -0400433 if (priv->primary_connection != connection) {
434 /* make sure the connection really changed
435 * on client start it seems to always emit the notify::primary-connection signal though it
436 * hasn't changed */
437 log_connection_info(connection);
438 priv->primary_connection = connection;
439 AccountModel::instance().slotConnectivityChanged();
440 }
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400441}
442
443static void
444nm_client_cb(G_GNUC_UNUSED GObject *source_object, GAsyncResult *result, RingClient *self)
445{
446 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self);
447
448 GError* error = nullptr;
449 if (auto nm_client = nm_client_new_finish(result, &error)) {
450 priv->nm_client = nm_client;
Stepan Salenikovich28ca3172016-07-22 17:29:11 -0400451 g_debug("NetworkManager client initialized, version: %s\ndaemon running: %s\nnnetworking enabled: %s",
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400452 nm_client_get_version(nm_client),
Stepan Salenikovich28ca3172016-07-22 17:29:11 -0400453 nm_client_get_manager_running(nm_client) ? "yes" : "no",
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400454 nm_client_networking_get_enabled(nm_client) ? "yes" : "no");
455
456 auto connection = nm_client_get_primary_connection(nm_client);
457 log_connection_info(connection);
Stepan Salenikovich221beae2016-10-12 11:29:56 -0400458 priv->primary_connection = connection;
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400459
460 /* We monitor the primary connection and notify the daemon to re-load its connections
461 * (accounts, UPnP, ...) when it changes. For example, on most systems, if we have an
462 * ethernet connection and then also connect to wifi, the primary connection will not change;
463 * however it will change in the opposite case because an ethernet connection is preferred.
464 */
Stepan Salenikovich221beae2016-10-12 11:29:56 -0400465 g_signal_connect(nm_client, "notify::primary-connection", G_CALLBACK(primary_connection_changed), self);
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400466
467 } else {
468 g_warning("error initializing NetworkManager client: %s", error->message);
469 g_clear_error(&error);
470 }
471}
472
473#endif /* USE_LIBNM */
474
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400475static void
Stepan Salenikovich5a127672016-09-13 11:19:50 -0400476call_notifications_toggled(RingClient *self)
477{
478 auto priv = RING_CLIENT_GET_PRIVATE(self);
479
480 if (g_settings_get_boolean(priv->settings, "enable-call-notifications")) {
481 priv->call_notification = QObject::connect(
482 &CallModel::instance(),
483 &CallModel::incomingCall,
484 [] (Call *call) { ring_notify_incoming_call(call); }
485 );
486 } else {
487 QObject::disconnect(priv->call_notification);
488 }
489}
490
491static void
492chat_notifications_toggled(RingClient *self)
493{
494 auto priv = RING_CLIENT_GET_PRIVATE(self);
495
496 if (g_settings_get_boolean(priv->settings, "enable-chat-notifications")) {
497 priv->chat_notification = QObject::connect(
498 &Media::RecordingModel::instance(),
499 &Media::RecordingModel::newTextMessage,
500 [self] (Media::TextRecording* t, ContactMethod* cm)
501 { ring_notify_message(cm, t, self); }
502 );
503 } else {
504 QObject::disconnect(priv->chat_notification);
505 }
506}
507
508static void
Stepan Salenikovich509670b2017-04-24 15:18:06 -0400509selected_account_changed(RingClient *self)
510{
511 auto priv = RING_CLIENT_GET_PRIVATE(self);
512
513 QByteArray account_id;
514
515 const auto idx = AvailableAccountModel::instance().selectionModel()->currentIndex();
516 if (idx.isValid()) {
517 account_id = idx.data(static_cast<int>(Account::Role::Id)).toByteArray();
518 if (account_id.isEmpty())
519 g_warning("selected account id is empty; possibly newly created account");
520 }
521
522 g_settings_set_string(priv->settings, "selected-account", account_id.constData());
523}
524
525static void
526restore_selected_account(RingClient *self)
527{
528 auto priv = RING_CLIENT_GET_PRIVATE(self);
529
530 gchar *saved_account_id = g_settings_get_string(priv->settings, "selected-account");
531
532 QModelIndex saved_idx;
533
534 // try to find this account
535 if (strlen(saved_account_id) > 0) {
536 if (auto account = AccountModel::instance().getById(saved_account_id)) {
537 saved_idx = AvailableAccountModel::instance().mapFromSource(account->index());
538 if (!saved_idx.isValid())
539 g_warning("could not select saved selected-account; it is possibly not enabled");
540 } else {
541 g_warning("could not find saved selected-account; it has possibly been deleted");
542 }
543 }
544
545 g_free(saved_account_id);
546
547 /* if no account selected; lets pick in the order of priority:
548 * 1. the first available Ring account
549 * 2. the first available SIP account
550 * 5. none (can't pick not enabled accounts)
551 */
552 if (!saved_idx.isValid()) {
553 if (auto account = AvailableAccountModel::instance().currentDefaultAccount(URI::SchemeType::RING)) {
554 saved_idx = AvailableAccountModel::instance().mapFromSource(account->index());
555 }
556 }
557 if (!saved_idx.isValid()) {
558 if (auto account = AvailableAccountModel::instance().currentDefaultAccount(URI::SchemeType::SIP)) {
559 saved_idx = AvailableAccountModel::instance().mapFromSource(account->index());
560 }
561 }
562
563 AvailableAccountModel::instance().selectionModel()->setCurrentIndex(saved_idx, QItemSelectionModel::ClearAndSelect);
564}
565
566static void
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400567ring_client_startup(GApplication *app)
Stepan Salenikovich69771842015-02-24 18:11:45 -0500568{
Stepan Salenikovich69771842015-02-24 18:11:45 -0500569 RingClient *client = RING_CLIENT(app);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400570 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
Stepan Salenikovich69771842015-02-24 18:11:45 -0500571
Stepan Salenikovich4f9bb982015-06-23 14:26:30 -0400572 g_message("Ring GNOME client version: %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
573 g_message("git ref: %s", RING_CLIENT_REVISION);
574
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400575 /* make sure that the system corresponds to the autostart setting */
576 autostart_symlink(g_settings_get_boolean(priv->settings, "start-on-login"));
577 g_signal_connect(priv->settings, "changed::start-on-login", G_CALLBACK(autostart_toggled), NULL);
578
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400579 /* init clutter */
580 int clutter_error;
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400581 if ((clutter_error = gtk_clutter_init(&priv->argc, &priv->argv)) != CLUTTER_INIT_SUCCESS) {
582 g_error("Could not init clutter : %d\n", clutter_error);
583 exit(1); /* the g_error above should normally cause the applicaiton to exit */
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400584 }
585
586 /* init libRingClient and make sure its connected to the dbus */
587 try {
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400588 priv->qtapp = new QCoreApplication(priv->argc, priv->argv);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400589 /* the call model will try to connect to dring via dbus */
590 CallModel::instance();
Stepan Salenikovich541a40a2016-08-17 11:33:47 -0400591 } catch(const char * msg) {
592 exception_dialog(msg);
593 exit(1);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400594 } catch(QString& msg) {
Stepan Salenikovich541a40a2016-08-17 11:33:47 -0400595 exception_dialog(msg.toLocal8Bit().constData());
596 exit(1);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400597 }
598
Stepan Salenikovich67c5dd32015-09-14 12:27:36 -0400599 /* load translations from LRC */
Guillaume Roguez884ef732017-07-14 12:53:35 -0400600 const auto locale_name = QLocale::system().name();
601 const auto locale_lang = locale_name.split('_')[0];
602
603 if (locale_name != locale_lang) {
604 /* Install language first to have lowest priority */
605 priv->translator_lang.reset(new QTranslator);
606 if (priv->translator_lang->load(RING_CLIENT_INSTALL "/share/libringclient/translations/lrc_" + locale_lang)) {
607 g_debug("installed translations for %s", locale_lang.toUtf8().constData());
608 priv->qtapp->installTranslator(priv->translator_lang.get());
609 }
610 }
611
612 priv->translator_full.reset(new QTranslator);
613 if (priv->translator_full->load(RING_CLIENT_INSTALL "/share/libringclient/translations/lrc_" + locale_name)) {
614 g_debug("installed translations for %s", locale_name.toUtf8().constData());
615 }
616
617 if (not priv->translator_lang and not priv->translator_full) {
Stepan Salenikovich67c5dd32015-09-14 12:27:36 -0400618 g_debug("could not load LRC translations for %s, %s",
Guillaume Roguez884ef732017-07-14 12:53:35 -0400619 QLocale::languageToString(QLocale::system().language()).toUtf8().constData(),
620 QLocale::countryToString(QLocale::system().country()).toUtf8().constData()
Stepan Salenikovich67c5dd32015-09-14 12:27:36 -0400621 );
622 }
623
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400624 /* init delegates */
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -0400625 GlobalInstances::setPixmapManipulator(std::unique_ptr<Interfaces::PixbufManipulator>(new Interfaces::PixbufManipulator()));
Stepan Salenikovichbe6550c2015-08-21 16:16:03 -0400626 GlobalInstances::setDBusErrorHandler(std::unique_ptr<Interfaces::DBusErrorHandler>(new Interfaces::DBusErrorHandler()));
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400627
Stepan Salenikovich75a39172015-07-10 13:21:08 -0400628 /* make sure all RING accounts have a display name... this basically makes sure
629 * that all accounts created before the display name patch have a display name
630 * set... a bit of a hack as this should maybe be done in LRC */
631 force_ring_display_name();
632
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400633 /* make sure basic number categories exist, in case user has no contacts
634 * from which these would be automatically created
635 */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400636 NumberCategoryModel::instance().addCategory("work", QVariant());
637 NumberCategoryModel::instance().addCategory("home", QVariant());
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400638
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400639 /* add backends */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400640 CategorizedHistoryModel::instance().addCollection<LocalHistoryCollection>(LoadOptions::FORCE_ENABLED);
Nicolas Jagerb413b302016-05-06 11:41:32 -0400641 PersonModel::instance().addCollection<PeerProfileCollection>(LoadOptions::FORCE_ENABLED);
642 ProfileModel::instance().addCollection<LocalProfileCollection>(LoadOptions::FORCE_ENABLED);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400643
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400644 /* fallback backend for vcards */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400645 PersonModel::instance().addCollection<FallbackPersonCollection>(LoadOptions::FORCE_ENABLED);
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400646
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400647 /* EDS backend(s) */
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400648 load_eds_sources(priv->cancellable);
649
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400650 /* Override theme since we don't have appropriate icons for a dark them (yet) */
651 GtkSettings *gtk_settings = gtk_settings_get_default();
652 g_object_set(G_OBJECT(gtk_settings), "gtk-application-prefer-dark-theme",
653 FALSE, NULL);
654 /* enable button icons */
655 g_object_set(G_OBJECT(gtk_settings), "gtk-button-images",
656 TRUE, NULL);
657
658 /* add GActions */
Stepan Salenikovich69771842015-02-24 18:11:45 -0500659 g_action_map_add_action_entries(
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400660 G_ACTION_MAP(app), ring_actions, G_N_ELEMENTS(ring_actions), app);
661
Stepan Salenikovich982b2882016-06-15 13:13:37 -0400662 /* GActions for settings */
663 auto action_window_visible = g_settings_create_action(priv->settings, "show-main-window");
664 g_action_map_add_action(G_ACTION_MAP(app), action_window_visible);
665
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400666 /* add accelerators */
667 ring_accelerators(RING_CLIENT(app));
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500668
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400669 /* Bind GActions to the UserActionModel */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400670 UserActionModel* uam = CallModel::instance().userActionModel();
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400671 QHash<int, GSimpleAction*> actionHash;
672 actionHash[ (int)UserActionModel::Action::ACCEPT ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "accept"));
673 actionHash[ (int)UserActionModel::Action::HOLD ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "hold"));
Stepan Salenikovich7d75eab2015-06-12 12:11:45 -0400674 actionHash[ (int)UserActionModel::Action::MUTE_AUDIO ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "mute_audio"));
675 actionHash[ (int)UserActionModel::Action::MUTE_VIDEO ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "mute_video"));
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400676 /* TODO: add commented actions when ready */
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400677 // actionHash[ (int)UserActionModel::Action::SERVER_TRANSFER ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "transfer"));
Stepan Salenikovich943bd052015-09-04 17:42:08 -0400678 actionHash[ (int)UserActionModel::Action::RECORD ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "record"));
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400679 actionHash[ (int)UserActionModel::Action::HANGUP ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "hangup"));
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500680
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400681 for (QHash<int,GSimpleAction*>::const_iterator i = actionHash.begin(); i != actionHash.end(); ++i) {
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -0400682 GSimpleAction* sa = i.value();
683 int_ptr_t user_data;
684 user_data.value = i.key();
685 g_signal_connect(G_OBJECT(sa), "activate", G_CALLBACK(activate_action), user_data.ptr);
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400686 }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500687
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400688 /* change the state of the GActions based on the UserActionModel */
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400689 priv->uam_updated = QObject::connect(uam,&UserActionModel::dataChanged, [actionHash,uam](const QModelIndex& tl, const QModelIndex& br) {
Stepan Salenikovich5fd97bc2016-08-30 09:40:38 -0400690 const int first(tl.row()),last(br.row());
691 for(int i = first; i <= last;i++) {
692 const QModelIndex& idx = uam->index(i,0);
693 GSimpleAction* sa = actionHash[(int)qvariant_cast<UserActionModel::Action>(idx.data(UserActionModel::Role::ACTION))];
694 if (sa) {
695 /* enable/disable GAction based on UserActionModel */
696 g_simple_action_set_enabled(sa, idx.flags() & Qt::ItemIsEnabled);
697 /* set the state of the action if its stateful */
698 if (g_action_get_state_type(G_ACTION(sa)) != NULL)
699 g_simple_action_set_state(sa, g_variant_new_boolean(idx.data(Qt::CheckStateRole) == Qt::Checked));
700 }
701 }
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400702 });
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400703
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400704 /* show window on incoming calls (if the option is set)*/
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400705 QObject::connect(&CallModel::instance(), &CallModel::incomingCall,
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400706 [app] (G_GNUC_UNUSED Call *call) {
707 RingClient *client = RING_CLIENT(app);
708 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
709 if (g_settings_get_boolean(priv->settings, "bring-window-to-front"))
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400710 ring_window_show(client);
Stepan Salenikovichbc6c4be2015-07-31 16:07:54 -0400711 }
712 );
713
Stepan Salenikovich5a127672016-09-13 11:19:50 -0400714 /* enable notifications based on settings */
Stepan Salenikovich76c33e62015-05-22 12:24:07 -0400715 ring_notify_init();
Stepan Salenikovich5a127672016-09-13 11:19:50 -0400716 call_notifications_toggled(client);
717 chat_notifications_toggled(client);
718 g_signal_connect_swapped(priv->settings, "changed::enable-call-notifications", G_CALLBACK(call_notifications_toggled), client);
719 g_signal_connect_swapped(priv->settings, "changed::enable-chat-notifications", G_CALLBACK(chat_notifications_toggled), client);
Stepan Salenikovich67112d12015-06-16 16:57:06 -0400720
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400721#if USE_LIBNM
722 /* monitor the network using libnm to notify the daemon about connectivity chagnes */
723 nm_client_new_async(priv->cancellable, (GAsyncReadyCallback)nm_client_cb, client);
724#endif
725
Stepan Salenikovich509670b2017-04-24 15:18:06 -0400726 /* keep track of the selected account */
727 QObject::connect(AvailableAccountModel::instance().selectionModel(),
728 &QItemSelectionModel::currentChanged,
729 [app] () { selected_account_changed(RING_CLIENT(app)); }
730 );
731 restore_selected_account(RING_CLIENT(app));
732
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400733 G_APPLICATION_CLASS(ring_client_parent_class)->startup(app);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400734}
735
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400736static void
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500737ring_client_shutdown(GApplication *app)
738{
739 RingClient *self = RING_CLIENT(app);
740 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self);
741
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400742 g_debug("quitting");
743
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400744 /* cancel any pending cancellable operations */
745 g_cancellable_cancel(priv->cancellable);
746 g_object_unref(priv->cancellable);
747
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400748 QObject::disconnect(priv->uam_updated);
Stepan Salenikovich5a127672016-09-13 11:19:50 -0400749 QObject::disconnect(priv->call_notification);
750 QObject::disconnect(priv->chat_notification);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400751
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500752 /* free the QCoreApplication, which will destroy all libRingClient models
753 * and thus send the Unregister signal over dbus to dring */
754 delete priv->qtapp;
755
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400756 /* free the copied cmd line args */
757 g_strfreev(priv->argv);
758
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400759 g_clear_object(&priv->settings);
760
Stepan Salenikovich76c33e62015-05-22 12:24:07 -0400761 ring_notify_uninit();
762
Stepan Salenikovich472c9052016-07-20 19:16:02 -0400763#if USE_LIBNM
764 /* clear NetworkManager client if it was used */
765 g_clear_object(&priv->nm_client);
766#endif
767
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500768 /* Chain up to the parent class */
769 G_APPLICATION_CLASS(ring_client_parent_class)->shutdown(app);
770}
771
772static void
773ring_client_init(RingClient *self)
774{
775 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self);
776
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500777 priv->win = NULL;
778 priv->qtapp = NULL;
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400779 priv->cancellable = g_cancellable_new();
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400780 priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400781
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400782 /* add custom cmd line options */
783 ring_client_add_options(G_APPLICATION(self));
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500784}
785
786static void
787ring_client_class_init(RingClientClass *klass)
788{
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400789 G_APPLICATION_CLASS(klass)->startup = ring_client_startup;
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400790 G_APPLICATION_CLASS(klass)->activate = ring_client_activate;
Victor Nikulshin167bbb62017-03-15 20:44:27 +0000791 G_APPLICATION_CLASS(klass)->open = ring_client_open;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500792 G_APPLICATION_CLASS(klass)->shutdown = ring_client_shutdown;
793}
794
795RingClient *
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400796ring_client_new(int argc, char *argv[])
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500797{
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400798 RingClient *client = (RingClient *)g_object_new(ring_client_get_type(),
Stepan Salenikovich76350582015-05-25 14:56:32 -0400799 "application-id", RING_CLIENT_APP_ID,
Victor Nikulshin167bbb62017-03-15 20:44:27 +0000800 "flags", G_APPLICATION_HANDLES_OPEN ,
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400801 NULL);
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400802
803 /* copy the cmd line args before they get processed by the GApplication*/
804 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
805 priv->argc = argc;
806 priv->argv = g_strdupv((gchar **)argv);
807
808 return client;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500809}
Stepan Salenikovich67112d12015-06-16 16:57:06 -0400810
811GtkWindow *
Stepan Salenikovichbe6550c2015-08-21 16:16:03 -0400812ring_client_get_main_window(RingClient *client)
Stepan Salenikovich67112d12015-06-16 16:57:06 -0400813{
814 g_return_val_if_fail(IS_RING_CLIENT(client), NULL);
815 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
816
817 return (GtkWindow *)priv->win;
818}
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -0400819
820void
821ring_client_set_restore_main_window_state(RingClient *client, gboolean restore)
822{
823 g_return_if_fail(IS_RING_CLIENT(client));
824 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
825
826 priv->restore_window_state = restore;
827}