From bc6c4bed32f9ce2144cd650c4562e270623c19a1 Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich Date: Fri, 31 Jul 2015 16:07:54 -0400 Subject: [PATCH] gnome: allow client to keep running on close Two options have been added to the client: - hide on close (true by default) - bring to foreground (true by default) The client will now continue running by default in the background after the user closes the main window and thus be able to receive calls and messages. By default the client will also be brought to the foreground when a new call is incoming. Issue: #78461 Change-Id: I3658cd60d2df0a3e1a8c2a4f5d1173824244a3d4 --- data/cx.ring.RingGnome.gschema.xml | 10 +++++ src/generalsettingsview.cpp | 12 +++++- src/ring_client.cpp | 61 +++++++++++++++++++++++------- ui/generalsettingsview.ui | 19 +++++++++- 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/data/cx.ring.RingGnome.gschema.xml b/data/cx.ring.RingGnome.gschema.xml index 71f52910..68c8e14b 100644 --- a/data/cx.ring.RingGnome.gschema.xml +++ b/data/cx.ring.RingGnome.gschema.xml @@ -6,5 +6,15 @@ Start Ring on login. Start Ring on login. Only supported on XDG compliant desktop environments. + + true + Hide on close instead of quitting. + Hide the main window on close instead of quitting the application. If set to true, Ring will continue to run and be able to receive calls and messages if the main window is closed. + + + true + Bring window to foreground on incoming calls. + Bring window to foreground on incoming calls. + diff --git a/src/generalsettingsview.cpp b/src/generalsettingsview.cpp index 9e5f0167..95354be9 100644 --- a/src/generalsettingsview.cpp +++ b/src/generalsettingsview.cpp @@ -52,6 +52,8 @@ struct _GeneralSettingsViewPrivate /* Rint settings */ GtkWidget *checkbutton_autostart; + GtkWidget *checkbutton_hideonclose; + GtkWidget *checkbutton_bringtofront; /* history settings */ GtkWidget *adjustment_history_duration; @@ -130,10 +132,16 @@ general_settings_view_init(GeneralSettingsView *self) priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL); - /* bind auto startup option to gsettings */ + /* bind client option to gsettings */ g_settings_bind(priv->settings, "start-on-login", priv->checkbutton_autostart, "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(priv->settings, "hide-on-close", + priv->checkbutton_hideonclose, "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind(priv->settings, "bring-window-to-front", + priv->checkbutton_bringtofront, "active", + G_SETTINGS_BIND_DEFAULT); /* history limit */ gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_history_duration), @@ -154,6 +162,8 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass) "/cx/ring/RingGnome/generalsettingsview.ui"); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_autostart); + gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_hideonclose); + gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_bringtofront); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_history_duration); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, button_clear_history); } diff --git a/src/ring_client.cpp b/src/ring_client.cpp index c411c061..31ea81df 100644 --- a/src/ring_client.cpp +++ b/src/ring_client.cpp @@ -185,6 +185,44 @@ autostart_toggled(GSettings *settings, G_GNUC_UNUSED gchar *key, G_GNUC_UNUSED g autostart_symlink(g_settings_get_boolean(settings, "start-on-login")); } +static gboolean +on_close_window(GtkWidget *window, G_GNUC_UNUSED GdkEvent *event, RingClient *client) +{ + g_return_val_if_fail(GTK_IS_WINDOW(window) && IS_RING_CLIENT(client), FALSE); + + RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); + + if (g_settings_get_boolean(priv->settings, "hide-on-close")) { + /* we want to simply hide the window and keep the client running */ + g_debug("hiding main window"); + gtk_widget_hide(window); + return TRUE; /* do not propogate event */ + } else { + /* we want to quit the application, so just propogate the event */ + return FALSE; + } +} + +static void +ring_client_activate(GApplication *app) +{ + RingClient *client = RING_CLIENT(app); + RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); + + if (priv->win == NULL) { + priv->win = ring_main_window_new(GTK_APPLICATION(app)); + + /* make sure win is set to NULL when the window is destroyed */ + g_object_add_weak_pointer(G_OBJECT(priv->win), (gpointer *)&priv->win); + + /* check if the window should be destoryed or not on close */ + g_signal_connect(priv->win, "delete-event", G_CALLBACK(on_close_window), client); + } + + g_debug("show window"); + gtk_window_present(GTK_WINDOW(priv->win)); +} + static void ring_client_startup(GApplication *app) { @@ -296,6 +334,16 @@ ring_client_startup(GApplication *app) } }); + /* show window on incoming calls (if the option is set)*/ + QObject::connect(CallModel::instance(), &CallModel::incomingCall, + [app] (G_GNUC_UNUSED Call *call) { + RingClient *client = RING_CLIENT(app); + RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); + if (g_settings_get_boolean(priv->settings, "bring-window-to-front")) + ring_client_activate(app); + } + ); + /* send call notifications */ ring_notify_init(); QObject::connect(CallModel::instance(), &CallModel::incomingCall, @@ -344,19 +392,6 @@ ring_client_command_line(GApplication *app, GApplicationCommandLine *cmdline) } #endif -static void -ring_client_activate(GApplication *app) -{ - RingClient *client = RING_CLIENT(app); - RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); - - if (priv->win == NULL) { - priv->win = ring_main_window_new(GTK_APPLICATION(app)); - } - - gtk_window_present(GTK_WINDOW(priv->win)); -} - static void ring_client_shutdown(GApplication *app) { diff --git a/ui/generalsettingsview.ui b/ui/generalsettingsview.ui index 5cefeeae..e7e00450 100644 --- a/ui/generalsettingsview.ui +++ b/ui/generalsettingsview.ui @@ -46,7 +46,24 @@ Start Ring on login True True - False + 0 + True + + + + + Hide Ring on close instead of quitting. + True + True + 0 + True + + + + + Bring Ring to the foreground on incoming calls. + True + True 0 True -- GitLab