gnome: add autostart functionality

Autostart is enabled by creating a symlink to gnome-ring.desktop
in $XDG_CONFIG_HOME/autostart (this is supported by all XDG
compliant desktop environments.
This is enabled by default and will be done the first time the
client is launched and the setting is checked on every launch.
This patch also adds a GSettings schema for the client to keep
track of the client settings (for now just the autostart enabled).

To support non-installed builds, the gschema is compiled to the
directory of the binary by default. The client first checks for
the .desktop and the compiled gschema in the local directory of
the binary.

A patch is required in the packaging branch to support the new
functionality.

Refs #74056

Change-Id: Ife9c8149e3225ab765dc1d2472ca0fd44ad35691
diff --git a/src/ring_client.cpp b/src/ring_client.cpp
index 76e2b18..9e71448 100644
--- a/src/ring_client.cpp
+++ b/src/ring_client.cpp
@@ -52,10 +52,11 @@
 #include "delegates/pixbufdelegate.h"
 #include "ringnotify.h"
 #include "config.h"
+#include "utils/files.h"
 
 struct _RingClientClass
 {
-  GtkApplicationClass parent_class;
+    GtkApplicationClass parent_class;
 };
 
 struct _RingClient
@@ -69,6 +70,9 @@
     /* args */
     int    argc;
     char **argv;
+
+    GSettings *settings;
+
     /* main window */
     GtkWidget        *win;
     /* for libRingclient */
@@ -172,11 +176,21 @@
 }
 
 static void
+autostart_toggled(GSettings *settings, G_GNUC_UNUSED gchar *key, G_GNUC_UNUSED gpointer user_data)
+{
+    autostart_symlink(g_settings_get_boolean(settings, "start-on-login"));
+}
+
+static void
 ring_client_startup(GApplication *app)
 {
     RingClient *client = RING_CLIENT(app);
     RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
 
+    /* make sure that the system corresponds to the autostart setting */
+    autostart_symlink(g_settings_get_boolean(priv->settings, "start-on-login"));
+    g_signal_connect(priv->settings, "changed::start-on-login", G_CALLBACK(autostart_toggled), NULL);
+
     /* init clutter */
     int clutter_error;
     if ((clutter_error = gtk_clutter_init(&priv->argc, &priv->argv)) != CLUTTER_INIT_SUCCESS) {
@@ -346,6 +360,8 @@
     /* free the copied cmd line args */
     g_strfreev(priv->argv);
 
+    g_clear_object(&priv->settings);
+
     ring_notify_uninit();
 
     /* Chain up to the parent class */
@@ -357,10 +373,10 @@
 {
     RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self);
 
-    /* init widget */
     priv->win = NULL;
     priv->qtapp = NULL;
     priv->cancellable = g_cancellable_new();
+    priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
 
 #if GLIB_CHECK_VERSION(2,40,0)
     /* add custom cmd line options */