User configuration update patch



Greetings,

I've attached a patch against gnome-core (CVS branch GNOME_CORE_1_2_0) as
well as an additional file to be placed in gnome-core/gsm/update.c. These
together add a new feature to gnome-session.

With these modifications, the first time gnome-session is run under
a particular version of GNOME, it probes a user's personal configuration
when it starts up, checking if he has the configuration files from an old
version. If he does, it prompts the user to see if he wishes to have his
configuration updated with the new defaults. If he responds `yes', then it
removes his panel configuration file and the old session so that they are
loaded from the defaults. If he responds `no', it marks the session so
that it will never prompt him again. This is to be included in Helix GNOME
so that users who upgrade from older versions of GNOME will have the
opportunity to update their configurations to take full advantage of the
new default setup.

Please have a look at the patch and source file and let me know whether I 
have implemented things correctly.

-- 
-Bradford Hovinen

"If the fool would persist in his folly he would become wise."

        - William Blake, "Proverbs of Hell," 1793
? session-update.diff
? gsm/update.c
? gsm/update.h
? gsm/ChangeLog.flc
? gsm/make.output
? gsm/save.diff
? gsm/update-helper
? help-browser/help/gl/Makefile.in
? help-browser/help/gl/Makefile
? po/ChangeLog.flc
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-core/configure.in,v
retrieving revision 1.253
diff -u -r1.253 configure.in
--- configure.in	2000/05/22 07:42:37	1.253
+++ configure.in	2000/08/04 20:19:36
@@ -346,6 +346,10 @@
 
 AC_DEFINE_UNQUOTED(GNOME_ICONDIR, "${prefix}/${DATADIRNAME}/pixmaps")
 
+dnl Configuration file version
+CONFIG_VERSION=100
+AC_SUBST(CONFIG_VERSION)
+
 AC_OUTPUT([
 Makefile
 gnome-core.spec
Index: gsm/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-core/gsm/ChangeLog,v
retrieving revision 1.154
diff -u -r1.154 ChangeLog
--- gsm/ChangeLog	2000/05/18 18:44:55	1.154
+++ gsm/ChangeLog	2000/08/04 20:19:37
@@ -1,3 +1,43 @@
+2000-08-04  Bradford Hovinen  <hovinen@helixcode.com>
+
+	* update.c (main): Set config_version to CONFIG_VERSION if
+	necessary
+	(delete_session): Implement -- just copy the code to clean out the
+	section from the corresponding function in save.c
+	(reply_cb): Delete the session if the user chooses yes
+
+	* save.c (read_clients): Check return code on system and issue
+	appropriate error
+	(read_clients): Use fork() and exec() rather than system()
+	(run_update_helper): Implement, code taken from read_clients
+	
+	* update.c (check_running_program): Implement. Looks through a
+	list of clients for a particular program.
+
+	* Makefile.am (bin_PROGRAMS): New program update-helper
+
+2000-08-03  Bradford Hovinen  <hovinen@helixcode.com>
+
+	* update.c (has_old_config): Implement
+
+	* save.c (write_session): Set configuration version
+
+	* update.c (check_config_update): Implement. Checks configuration
+	version supplied against that compiled in. If the supplied version 
+	is older, displays a dialog asking the user if he wishes to update 
+	his configuration with the new defaults.
+	(reply_cb): Implement
+
+	* Makefile.am (INCLUDES): Define CONFIG_VERSION
+
+	* save.c (read_clients): Invoke system ("update-helper") on
+	configuration file version if reading a personal configuration and
+	config version id found is less than compiled CONFIG_VERSION
+
+	* default.in (ConfigVersion): Added key; should be incremented
+	whenever there is a significant update to the default session or
+	configuration
+
 2000-05-18  Mark Crichton <crichton@gimp.org>
 
         * session-properties.c: Made it use a better default visual.
Index: gsm/Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-core/gsm/Makefile.am,v
retrieving revision 1.40
diff -u -r1.40 Makefile.am
--- gsm/Makefile.am	2000/04/14 04:58:56	1.40
+++ gsm/Makefile.am	2000/08/04 20:19:37
@@ -7,7 +7,9 @@
 INCLUDES = -I$(includedir) $(GNOME_INCLUDEDIR) \
 	-I$(top_srcdir)/intl -I$(top_builddir)/intl	\
 	-DGNOMELOCALEDIR=\""$(datadir)/locale\"" \
-	-DDEFAULTDIR="\"$(defaultdir)\""
+	-DDEFAULTDIR="\"$(defaultdir)\"" \
+	-DCONFIG_VERSION=$(CONFIG_VERSION) \
+	-DUPDATE_HELPER="\"$(bindir)/update-helper\""
 
 LDADD = $(GNOME_LIBDIR) $(GNOMEUI_LIBS) $(INTLLIBS)
 
@@ -15,7 +17,7 @@
 
 if SESSION
 noinst_DATA = session.desktop
-bin_PROGRAMS = gnome-session save-session gnome-login-check session-properties
+bin_PROGRAMS = gnome-session save-session gnome-login-check session-properties update-helper
 endif
 
 gnome_session_SOURCES = manager.c manager.h ice.c main.c prop.c save.c \
@@ -31,6 +33,10 @@
 session.h
 
 gnome_login_check_SOURCES = gnome-login-check.c
+
+update_helper_SOURCES = update.c prop.c
+
+update_helper_LDADD=$(GNOME_LIBDIR) $(GNOMEUI_LIBS) $(INTLLIBS) @LIBWRAP_LIBS@
 
 bin_SCRIPTS = gnome-wm
 
Index: gsm/manager.h
===================================================================
RCS file: /cvs/gnome/gnome-core/gsm/manager.h,v
retrieving revision 1.29
diff -u -r1.29 manager.h
--- gsm/manager.h	2000/04/03 23:03:27	1.29
+++ gsm/manager.h	2000/08/04 20:19:38
@@ -55,6 +55,9 @@
 /* Name of key used to store the current session name. */
 #define CURRENT_SESSION_KEY "Current Session"
 
+/* Name of key used to store configuration version */
+#define CONFIG_VERSION_KEY "config_version"
+
 /* Name of key used to store number of clients in a session. */
 #define CLIENT_COUNT_KEY "num_clients"
 
Index: gsm/save.c
===================================================================
RCS file: /cvs/gnome/gnome-core/gsm/save.c,v
retrieving revision 1.55
diff -u -r1.55 save.c
--- gsm/save.c	2000/02/29 00:46:30	1.55
+++ gsm/save.c	2000/08/04 20:19:38
@@ -20,6 +20,10 @@
 #include <config.h>
 #include <glib.h>
 #include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <gtk/gtk.h>
 
 #include "libgnome/libgnome.h"
@@ -245,6 +249,9 @@
       g_snprintf (prefix, sizeof(prefix), 
 		  CONFIG_PREFIX "%s/" CLIENT_COUNT_KEY, session_name);
       gnome_config_set_int (prefix, i);
+      g_snprintf (prefix, sizeof(prefix), 
+		  CONFIG_PREFIX "%s/" CONFIG_VERSION_KEY, session_name);
+      gnome_config_set_int (prefix, CONFIG_VERSION);
       gnome_config_sync ();
     }
 }
@@ -350,22 +357,63 @@
     }
 }
 
+/* Run the update helper to see if the user requests that the session
+ * be updated with the new defaults. Return TRUE if so and FALSE otherwise.
+ */
+
+static gboolean
+run_update_helper (const char *file, const char *session) 
+{
+  int retcode;
+  pid_t pid;
+
+  pid = fork ();
+
+  if (pid == (pid_t) -1)
+    {
+      g_warning ("gnome-session: fork: %s", g_strerror (errno));
+      return FALSE;
+    }
+  else if (pid == 0)
+    {
+      execl (UPDATE_HELPER, UPDATE_HELPER, session, NULL);
+      g_error ("gnome-session: Could not run update-helper: %s",
+	       g_strerror (errno));
+    }
+  else
+    {
+      waitpid (pid, &retcode, 0);
+    }
 
+  if (WEXITSTATUS (retcode) == 1)
+    return TRUE;
+  else
+    return FALSE;
+}
 
 /* Read the session clients recorded in a config file section */
 static GSList *
-read_clients (const char* file, const char *session, MatchRule match_rule)
+read_clients (const char* file, const char *session, MatchRule match_rule,
+	      gboolean is_personal)
 {
   int i, num_clients;
   char prefix[1024];
   GSList* list = 0;
+  gint config_version;
 
   g_snprintf (prefix, sizeof(prefix), "%s%s/", file, session);
 
   gnome_config_push_prefix (prefix);
   num_clients = gnome_config_get_int (CLIENT_COUNT_KEY "=0");
+  config_version = gnome_config_get_int (CONFIG_VERSION_KEY "=0");
   gnome_config_pop_prefix ();
 
+  if (is_personal && CONFIG_VERSION > config_version &&
+      run_update_helper (file, session))
+    return NULL;
+  else
+    g_message ("gnome-session: Config version is up to date.");
+
   for (i = 0; i < num_clients; ++i)
     {
       Client *client = (Client*)calloc (1, sizeof(Client));
@@ -378,6 +426,7 @@
       client->match_rule = match_rule;
       APPEND (list, client);
     }
+
   return list;
 }
 
@@ -481,10 +530,12 @@
 
   while (name)
     {
-      if (!failsafe && (list = read_clients (CONFIG_PREFIX, name, MATCH_ID)))
+      if (!failsafe && (list = read_clients (CONFIG_PREFIX, name,
+					     MATCH_ID, TRUE)))
 	break;
 	  
-      if ((list = read_clients (DEFAULT_CONFIG_PREFIX, name, MATCH_FAKE_ID)))
+      if ((list = read_clients (DEFAULT_CONFIG_PREFIX, name,
+				MATCH_FAKE_ID, FALSE)))
 	break;
 
       try_last = try_last && (strcmp (name, last) != 0);
@@ -499,7 +550,7 @@
   /* See if there is a list of clients that the user has manually
    * created from the session-properties capplet
    */
-  list = read_clients (MANUAL_CONFIG_PREFIX, name, MATCH_PROP);
+  list = read_clients (MANUAL_CONFIG_PREFIX, name, MATCH_PROP, FALSE);
   if (list)
 	  session->client_list = g_slist_concat (session->client_list, list);
 
Index: po/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-core/po/ChangeLog,v
retrieving revision 1.291
diff -u -r1.291 ChangeLog
--- po/ChangeLog	2000/05/20 07:02:20	1.291
+++ po/ChangeLog	2000/08/04 20:19:38
@@ -1,3 +1,7 @@
+2000-08-04  Bradford Hovinen  <hovinen@helixcode.com>
+
+	* POTFILES.in: Added gsm/update.c
+
 2000-05-20  Karl Eichwalder  <ke@suse.de>
 
 	* de.po: New translation for "deskguide" according to
Index: po/Makefile.in.in
===================================================================
RCS file: /cvs/gnome/gnome-core/po/Makefile.in.in,v
retrieving revision 1.8
diff -u -r1.8 Makefile.in.in
--- po/Makefile.in.in	2000/05/22 07:42:38	1.8
+++ po/Makefile.in.in	2000/08/04 20:19:38
@@ -62,7 +62,7 @@
 	$(COMPILE) $<
 
 .po.pox:
-	$(MAKE) $(srcdir)/$(PACKAGE).pot
+	$(MAKE) $(PACKAGE).pot
 	$(MSGMERGE) $< $(srcdir)/$(PACKAGE).pot -o $*.pox
 
 .po.mo:
@@ -79,7 +79,7 @@
 
 all: all-@USE_NLS@
 
-all-yes: $(srcdir)/cat-id-tbl.c $(CATALOGS)
+all-yes: cat-id-tbl.c $(CATALOGS)
 all-no:
 
 $(srcdir)/$(PACKAGE).pot: $(POTFILES)
@@ -90,8 +90,8 @@
 	   || ( rm -f $(srcdir)/$(PACKAGE).pot \
 		&& mv $(PACKAGE).po $(srcdir)/$(PACKAGE).pot )
 
-$(srcdir)/cat-id-tbl.c: $(srcdir)/stamp-cat-id; @:
-$(srcdir)/stamp-cat-id: $(srcdir)/$(PACKAGE).pot
+$(srcdir)/cat-id-tbl.c: stamp-cat-id; @:
+$(srcdir)/stamp-cat-id: $(PACKAGE).pot
 	rm -f cat-id-tbl.tmp
 	sed -f ../intl/po2tbl.sed $(srcdir)/$(PACKAGE).pot \
 		| sed -e "s/@PACKAGE NAME@/$(PACKAGE)/" > cat-id-tbl.tmp
@@ -180,8 +180,7 @@
 
 check: all
 
-cat-id-tbl.o: $(srcdir)/cat-id-tbl.c $(top_srcdir)/intl/libgettext.h
-	$(COMPILE) $(srcdir)/cat-id-tbl.c
+cat-id-tbl.o: ../intl/libgettext.h
 
 dvi info tags TAGS ID:
 
@@ -197,7 +196,7 @@
 maintainer-clean: distclean
 	@echo "This command is intended for maintainers to use;"
 	@echo "it deletes files that may require special tools to rebuild."
-	rm -f $(GMOFILES) cat-id-tbl.c stamp-cat-id
+	rm -f $(GMOFILES)
 
 distdir = ../$(PACKAGE)-$(VERSION)/$(subdir)
 dist distdir: update-po $(DISTFILES)
@@ -208,7 +207,7 @@
 	done
 
 update-po: Makefile
-	$(MAKE) $(srcdir)/$(PACKAGE).pot
+	$(MAKE) $(PACKAGE).pot
 	PATH=`pwd`/../src:$$PATH; \
 	cd $(srcdir); \
 	catalogs='$(CATALOGS)'; \
Index: po/POTFILES.in
===================================================================
RCS file: /cvs/gnome/gnome-core/po/POTFILES.in,v
retrieving revision 1.75
diff -u -r1.75 POTFILES.in
--- po/POTFILES.in	2000/05/06 23:55:07	1.75
+++ po/POTFILES.in	2000/08/04 20:19:38
@@ -144,6 +144,7 @@
 gsm/gsm-client-editor.c
 gsm/gnome-login-check.c
 gsm/command.c
+gsm/update.c
 gnome-terminal/gnome-terminal.h
 gnome-terminal/gnome-terminal.c
 gnome-terminal/corba.c
/* -*- mode: c; style: linux -*- */

/* update.c
 * Copyright (C) 2000 Helix Code, Inc.
 *
 * Written by Bradford Hovinen <hovinen@helixcode.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <unistd.h>
#include <errno.h>
#include <gnome.h>

#include "manager.h"
#include "session.h"

static gboolean retval;
static gchar *session;

/* Used to save xsm style string valued SmDiscardCommand properties. */
#define XsmDiscardCommand SmDiscardCommand "[string]"

typedef enum
{
  VECTOR,
  STRING,
  NUMBER
} prop_type;

/* This is used to hold a table of all properties we care to save.  */
typedef struct
{
  const char *name;	      /* Name of property per protocol  */
  prop_type type;	      
  gboolean required;	      /* TRUE if required (by us, not by the spec). */
  const char *save_name;      /* Name of property in config file */
} propsave;

/* These are the only ones which we use at present but eventually we
 * will need to save all the properties (when they have been set)
 * because clients are not obliged to set their properties every time
 * that they run. */
static propsave properties[] =
{
  { SmRestartStyleHint, NUMBER, 0, SmRestartStyleHint },
  { GsmPriority,        NUMBER, 0, "Priority" },
  { GsmRestartService,  STRING, 0, "RestartService" },
  { SmProgram,          STRING, 0, SmProgram },
  { SmCurrentDirectory, STRING, 0, SmCurrentDirectory },
  { SmDiscardCommand,   STRING, 0, XsmDiscardCommand }, /* for legacy apps */
  { SmDiscardCommand,   VECTOR, 0, SmDiscardCommand },
  { SmCloneCommand,     VECTOR, 0, SmCloneCommand },
  { SmRestartCommand,   VECTOR, 1, SmRestartCommand },
  { SmEnvironment,      VECTOR, 0, SmEnvironment }
};

#define NUM_PROPERTIES (sizeof (properties) / sizeof (propsave))

/* We need to read clients as well as writing them because the
 * protocol does not oblige clients to specify thier properties
 * every time that they run. */
static void
read_one_client (Client *client)
{
  int i, j;
  gboolean def;
  gchar* id;

  client->id = NULL;
  client->properties = NULL;
  client->priority = DEFAULT_PRIORITY;
  client->handle = NULL;
  client->warning = FALSE;
  client->get_prop_replies = NULL;
  client->get_prop_requests = 0;
  client->command_data = NULL;

  id = gnome_config_get_string ("id");
  if (id)
    {
      client->id = strdup(id);
      g_free (id);
    }
  /* Read each property that we save.  */
  for (i = 0; i < NUM_PROPERTIES; ++i)
    {
      gint  argc;
      gchar **vector;
      gchar *string;
      gint  number;

      switch (properties[i].type)
	{
	case VECTOR:
	  gnome_config_get_vector_with_default (properties[i].save_name, 
						&argc, &vector, &def);
	  if (!def)
	    {
	      SmProp *prop = (SmProp*) malloc (sizeof (SmProp));
	      prop->name = strdup (properties[i].name);
	      prop->type = strdup (SmLISTofARRAY8);
	      prop->num_vals = argc;
	      prop->vals = (SmPropValue*) malloc (sizeof (SmPropValue) * argc);
	      for (j = 0; j < argc; j++)
		{
		  prop->vals[j].length = vector[j] ? strlen (vector[j]) : 0;
		  prop->vals[j].value  = vector[j] ? strdup (vector[j]) : NULL;
		  g_free (vector[j]);
		}
	      APPEND (client->properties, prop);      
	      g_free (vector);
	    }
	  break;

	case STRING:
	  string =
	    gnome_config_get_string_with_default (properties[i].save_name, 
						  &def);
	  if (!def)
	    {
	      SmProp *prop = (SmProp*) malloc (sizeof (SmProp));
	      prop->name = strdup (properties[i].name);
	      prop->type = strdup (SmARRAY8);
	      prop->num_vals = 1;
	      prop->vals = (SmPropValue*) malloc (sizeof (SmPropValue));
	      prop->vals[0].length = strlen (string);
	      prop->vals[0].value = strdup(string);
	      g_free (string);
	      APPEND (client->properties, prop);      
	    }
	  break;

	case NUMBER:
	  number =
	    gnome_config_get_int_with_default (properties[i].save_name, 
					       &def);
	  if (!def)
	    {
	      SmProp *prop = (SmProp*) malloc (sizeof (SmProp));
	      gchar* value = (gchar*) calloc (sizeof(gchar), 2);
	      value[0] = (gchar) number;
	      prop->name = strdup (properties[i].name);
	      prop->type = strdup (SmCARD8);
	      prop->num_vals = 1;
	      prop->vals = (SmPropValue*) malloc (sizeof (SmPropValue));
	      prop->vals[0].length = 1;
	      prop->vals[0].value = (SmPointer) value;
	      APPEND (client->properties, prop);      

	      if (!strcmp(properties[i].name, GsmPriority))
		client->priority = number;
	    }
	  break;
	default:
	  break;
	}
    }
}

/* Read the session clients recorded in a config file section */
static GSList *
read_clients (const char* file, const char *session, MatchRule match_rule)
{
  int i, num_clients;
  char prefix[1024];
  GSList* list = 0;

  g_snprintf (prefix, sizeof(prefix), "%s%s/", file, session);

  gnome_config_push_prefix (prefix);
  num_clients = gnome_config_get_int (CLIENT_COUNT_KEY "=0");
  gnome_config_pop_prefix ();

  for (i = 0; i < num_clients; ++i)
    {
      Client *client = (Client*)calloc (1, sizeof(Client));

      g_snprintf (prefix, sizeof(prefix), "%s%s/%d,", file, session, i);

      gnome_config_push_prefix (prefix);
      read_one_client (client);
      gnome_config_pop_prefix ();
      client->match_rule = match_rule;
      APPEND (list, client);
    }

  return list;
}

Client *
find_client_by_id (const GSList *list, const char *id)
{
  for (; list; list = list->next)
    {
      Client *client = (Client *) list->data;

      if (client->match_rule != MATCH_PROP)
	{
	  if (client->id && ! strcmp (client->id, id))
	    return client;
	}
    }
  return NULL;
}

/* Delete a session. 
 * This needs to be done carefully because we have to discard stale
 * session data and only a few of the clients may have conducted
 * a save since the session was last written */
void
delete_session (const char *name)
{
  char prefix[1024];

  g_snprintf (prefix, sizeof(prefix), CONFIG_PREFIX "%s", name);
  gnome_config_clean_section (prefix);
  gnome_config_sync ();
}

/* Check if the current list of clients runs a particular program, and 
 * if so, return a pointer to the program's command line
 *
 * This leaks memory like a screen door, but we're only running this
 * process once, so oh well...
 */

static gchar *
check_running_program (GSList *clients, char *name)
{
	Client *client;
	char *result;
	int argc;
	char **argv;

	while (clients) {
		client = (Client *) clients->data;
		if (find_string_property (client, SmProgram, &result) &&
		    !strcmp (result, name))
		{
			find_vector_property (client, SmRestartCommand,
					      &argc, &argv);
			argv = realloc (argv, (argc + 1) * sizeof (char *));
			argv[argc] = NULL;
			return g_strjoinv (" ", argv);
		}

		clients = clients->next;
	}

	return NULL;
}

/* Check if the user has the configuration for Helix GNOME or an
 * older version of GNOME. Return FALSE in the former case and TRUE in
 * the latter case.
 *
 * This is the hard part (and, thankfully, will not be needed in the
 * future). It's implemented with a set of if/then heuristics that try 
 * to guess what the user has.
 */

static gboolean
has_old_config (GSList *clients, gchar *session) 
{
	char *cli, *key;

	/* No one in their right mind would want to run Enlightenment
	 * when Sawfish is available... */
	if (check_running_program (clients, "enlightenment"))
		return TRUE;

	/* gnome-splash with the Red Hat logo is a dead giveaway */
	cli = check_running_program (clients, "gnome-splash");
	if (cli && strstr (cli, "redhat/gnome-startup.png")) 
		return TRUE;

	/* Check for old config */
	key = g_strconcat ("/panel.d/", session, 
			   "/panel/Config/tiles_enabled_0", NULL);
	if (gnome_config_get_bool (key))
		return TRUE;
	g_free (key);

	/* Can't find any good clues, so we'll assume not */
	return FALSE;
}

static void
reply_cb (GtkWidget *widget, gint button, gpointer data) 
{
	char *path;

	if (button == 0) {
		/* Destroy the user's panel config file and then just
		 * set the return value */
		g_strdown (session);
		path = g_strconcat (g_get_home_dir (), 
				    "/.gnome/panel.d/", session,
				    "/panel", NULL);
		unlink (path);
		g_free (path);

		delete_session (session);

		retval = TRUE;
	} else {
		retval = FALSE;
	}

	gtk_main_quit ();
}

/* Check the supplied configuration version number with that which was 
 * compiled in. If it is older, then the user has an old version of
 * the configuration. The value is read from the session file (see
 * save.c read_clients), and the default is 0. The current initial
 * value is 100 (for Helix GNOME 1.0, following the convention
 * major * 100 + minor).
 *
 * If the user has an old version, display a dialog asking him if he
 * wishes to update his configuration files to the new defaults. So,
 * if he has, for example, Red Hat 6.2, and just installed Helix
 * GNOME, he will not be stuck with the boring Red Hat default. It is
 * also designed so that we can change the configuration at a later
 * time and update the value CONFIG_VERSION (which is defined in
 * configure.in just before all the AC_OUTPUTs) to get the same
 * behavior.
 *
 * The one potential problem with this is that, if the user simply has 
 * Helix GNOME Preview 2, it will assume he has an old version of
 * GNOME and respond accordingly. The solution to that is to run a set 
 * of heuristics that attempt to differentiate between Helix GNOME
 * Preview 2 and previous versions of GNOME. This will be removed next 
 * time we change CONFIG_VERSION, as it will no longer be necessary at 
 * that point.
 *
 * Returns TRUE if configuration was updated, FALSE if not.
 */

int 
main (int argc, char **argv) 
{
	GSList *clients;
	gchar *name;

	bindtextdomain (PACKAGE, GNOMELOCALEDIR);
	textdomain (PACKAGE);

	if (argc < 2) {
		g_message ("Usage: update-helper <session name>");
		return 0;
	}

	session = argv[1];
	argv[1] = "--sm-disable";
	gnome_init ("update-helper", VERSION, argc, argv);

	clients = read_clients (CONFIG_PREFIX, session, MATCH_ID);

	if (has_old_config (clients, session)) {
		GtkWidget *dialog;

		dialog = gnome_message_box_new
			(_("You do not appear to have run this version " \
			   "of Helix GNOME before on this user account. \n" \
			   "Helix GNOME provides an updated default " \
			   "configuration that takes advantage of many \n" \
			   "new features. Would you like to change your " \
			   "configuration to the new defaults?"),
			 GNOME_MESSAGE_BOX_QUESTION,
			 GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO,
			 NULL);

		gtk_window_set_position (GTK_WINDOW (dialog),
					 GTK_WIN_POS_CENTER);

		gtk_signal_connect (GTK_OBJECT (dialog), "clicked",
				    GTK_SIGNAL_FUNC (reply_cb), NULL);

  		gtk_widget_show_all (dialog);

		gtk_main ();

		name = g_strconcat ("/" CONFIG_PREFIX, session,
				    "/" CONFIG_VERSION_KEY, NULL);
		gnome_config_set_int (name, CONFIG_VERSION);
		gnome_config_sync ();
		g_free (name);

		if (retval) exit (1);
	} else {
		g_message ("update-helper: Configuration is up to date");
	}

	return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]