Commit bc6c4bed authored by Stepan Salenikovich's avatar Stepan Salenikovich

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
parent 75a3917f
......@@ -6,5 +6,15 @@
<summary>Start Ring on login.</summary>
<description>Start Ring on login. Only supported on XDG compliant desktop environments.</description>
</key>
<key name="hide-on-close" type="b">
<default>true</default>
<summary>Hide on close instead of quitting.</summary>
<description>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.</description>
</key>
<key name="bring-window-to-front" type="b">
<default>true</default>
<summary>Bring window to foreground on incoming calls.</summary>
<description>Bring window to foreground on incoming calls.</description>
</key>
</schema>
</schemalist>
......@@ -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);
}
......
......@@ -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)
{
......
......@@ -46,7 +46,24 @@
<property name="label" translatable="yes">Start Ring on login</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_hideonclose">
<property name="label" translatable="yes">Hide Ring on close instead of quitting.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_bringtofront">
<property name="label" translatable="yes">Bring Ring to the foreground on incoming calls.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment