? metacity_102547.patch
Index: src/theme-parser.c
===================================================================
RCS file: /cvs/gnome/metacity/src/theme-parser.c,v
retrieving revision 1.19
diff -u -r1.19 theme-parser.c
--- src/theme-parser.c	30 May 2003 04:52:12 -0000	1.19
+++ src/theme-parser.c	5 Jan 2004 21:20:06 -0000
@@ -83,6 +83,7 @@
   char *theme_dir;              /* dir the theme is inside */
   MetaTheme *theme;             /* theme being parsed */
   char *name;                   /* name of named thing being parsed */
+  char format_version;          /* theme version */
   MetaFrameLayout *layout;      /* layout being parsed if any */
   MetaDrawOpList *op_list;      /* op list being parsed if any */
   MetaDrawOp *op;               /* op being parsed if any */
@@ -2255,7 +2256,7 @@
                               "x", &x, "y", &y,
                               "width", &width, "height", &height,
                               "alpha", &alpha, "filename", &filename,
-			      "colorize", &colorize,
+                              "colorize", &colorize,
                               "fill_type", &fill_type,
                               NULL))
         return;
@@ -4250,8 +4251,9 @@
  */
 #define THEME_FILENAME "metacity-theme-1.xml"
 
-/* now this is versioned, /usr/share/themes/NAME/THEME_SUBDIR/THEME_FILENAME */
-#define THEME_SUBDIR "metacity-1"
+/* now this is versioned, /usr/share/themes/NAME/THEME_SUBDIR-THEME_VERSION/THEME_FILENAME */
+#define THEME_SUBDIR "metacity"
+#define THEME_VERSION 2
 
 MetaTheme*
 meta_theme_load (const char *theme_name,
@@ -4264,7 +4266,9 @@
   gsize length;
   char *theme_file;
   char *theme_dir;
+  char *theme_subdir;
   MetaTheme *retval;
+  char version;
 
   text = NULL;
   length = 0;
@@ -4296,70 +4300,85 @@
           g_free (theme_file);
           theme_file = NULL;
         }
+      version = THEME_VERSION;
     }
   
-  /* We try in home dir, then system dir for themes */
-  
-  if (text == NULL)
+  /* We try all supported versions from current to oldest */
+  for (version = THEME_VERSION; (version > 0) && (text == NULL); version--)
     {
-      theme_dir = g_build_filename (g_get_home_dir (),
-                                    ".themes",
-                                    theme_name,
-                                    THEME_SUBDIR,
-                                    NULL);
-      
-      theme_file = g_build_filename (theme_dir,
-                                     THEME_FILENAME,
-                                     NULL);
+      theme_subdir = g_strdup_printf("%s-%d", THEME_SUBDIR, version);
 
-      error = NULL;
-      if (!g_file_get_contents (theme_file,
-                                &text,
-                                &length,
-                                &error))
-        {
-          meta_topic (META_DEBUG_THEMES, "Failed to read theme from file %s: %s\n",
-                      theme_file, error->message);
-          g_error_free (error);
-          g_free (theme_dir);
-          g_free (theme_file);
-          theme_file = NULL;
-        }
-    }
+     /* We try in home dir, then system dir for themes */
+    if (text == NULL)
+      {
+        theme_dir = g_build_filename (g_get_home_dir (),
+                                      ".themes",
+                                      theme_name,
+                                      theme_subdir,
+                                      NULL);
+      
+        theme_file = g_build_filename (theme_dir,
+                                       THEME_FILENAME,
+                                       NULL);
+
+        error = NULL;
+        if (!g_file_get_contents (theme_file,
+                                  &text,
+                                  &length,
+                                  &error))
+          {
+            meta_topic (META_DEBUG_THEMES, "Failed to read theme from file %s: %s\n",
+                        theme_file, error->message);
+            g_error_free (error);
+            g_free (theme_dir);
+            g_free (theme_file);
+            theme_file = NULL;
+          }
+      }
+
+    if (text == NULL)
+      {
+        theme_dir = g_build_filename (METACITY_DATADIR,
+                                      "themes",
+                                      theme_name,
+                                      theme_subdir,
+                                      NULL);
+      
+        theme_file = g_build_filename (theme_dir,
+                                       THEME_FILENAME,
+                                       NULL);
+
+        error = NULL;
+        if (!g_file_get_contents (theme_file,
+                                  &text,
+                                  &length,
+                                  &error))
+          {
+            meta_topic (META_DEBUG_THEMES, "Failed to read theme from file %s: %s\n",
+                        theme_file, error->message);
+            g_error_free (error);
+            g_free (theme_dir);
+            g_free (theme_file);
+            theme_file = NULL;
+          }
+      }
+
+    g_free(theme_subdir);
+  }
 
   if (text == NULL)
     {
-      theme_dir = g_build_filename (METACITY_DATADIR,
-                                    "themes",
-                                    theme_name,
-                                    THEME_SUBDIR,
-                                    NULL);
-      
-      theme_file = g_build_filename (theme_dir,
-                                     THEME_FILENAME,
-                                     NULL);
-
-      error = NULL;
-      if (!g_file_get_contents (theme_file,
-                                &text,
-                                &length,
-                                &error))
-        {
-          meta_warning (_("Failed to read theme from file %s: %s\n"),
-                        theme_file, error->message);
-          g_propagate_error (err, error);
-          g_free (theme_file);
-          g_free (theme_dir);
-          return FALSE; /* all fallbacks failed */
-        }
+      meta_warning (_("Failed to find a valid file for theme %s\n"),
+                    theme_name);
+      g_propagate_error (err, error);
+      return FALSE; /* all fallbacks failed */
     }
 
-  g_assert (text);
-
   meta_topic (META_DEBUG_THEMES, "Parsing theme file %s\n", theme_file);
 
   parse_info_init (&info);
   info.theme_name = theme_name;
+  info.format_version = version;
   
   /* pass ownership to info so we free it with the info */
   info.theme_file = theme_file;
