Description: Enable themes to provide a prefered button layout option:
 X-GNOME-Metatheme/ButtonLayout.
 .
 When selecting the theme, the ButtonLayout provided (if any) is applied,
 otherwise, menu:maximize,minimize,close is choosed as a default.
 We still provide a button for the user to revert the change if the user changed
 the previous theme button layout.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=614014
Bug-Ubuntu: https://bugs.launchpad.net/bugs/535322
Author: Didier Roche <didrocks@ubuntu.com>
Index: gnome-control-center-2.29.92/capplets/common/gnome-theme-info.c
===================================================================
--- gnome-control-center-2.29.92.orig/capplets/common/gnome-theme-info.c	2009-05-03 20:30:56.000000000 +0200
+++ gnome-control-center-2.29.92/capplets/common/gnome-theme-info.c	2010-03-26 15:48:39.318148337 +0100
@@ -36,6 +36,9 @@
 #define MONOSPACE_FONT_KEY "X-GNOME-Metatheme/MonospaceFont"
 #define BACKGROUND_IMAGE_KEY "X-GNOME-Metatheme/BackgroundImage"
 #define HIDDEN_KEY "X-GNOME-Metatheme/Hidden"
+#define BUTTON_LAYOUT_KEY "X-GNOME-Metatheme/ButtonLayout"
+
+#define DEFAULT_BUTTON_LAYOUT "menu:minimize,maximize,close"
 
 /* Terminology used in this lib:
  *
@@ -383,6 +386,12 @@
   meta_theme_info->hidden = gnome_desktop_item_get_boolean (meta_theme_ditem,
                                                             HIDDEN_KEY);
 
+  str = gnome_desktop_item_get_string (meta_theme_ditem, BUTTON_LAYOUT_KEY);
+  if (str == NULL)
+      str = DEFAULT_BUTTON_LAYOUT;
+  meta_theme_info->button_layout = g_strdup (str);
+
+
   gnome_desktop_item_unref (meta_theme_ditem);
 
   return meta_theme_info;
@@ -1605,6 +1614,7 @@
   g_free (meta_theme_info->icon_theme_name);
   g_free (meta_theme_info->metacity_theme_name);
   g_free (meta_theme_info->notification_theme_name);
+  g_free (meta_theme_info->button_layout);
   g_free (meta_theme_info);
 }
 
@@ -1727,6 +1737,9 @@
   cmp = safe_strcmp (a->monospace_font, b->monospace_font);
   if (cmp != 0) return cmp;
 
+  cmp = safe_strcmp (a->button_layout, b->button_layout);
+  if (cmp != 0) return cmp;
+
   return safe_strcmp (a->background_image, b->background_image);
 }
 
Index: gnome-control-center-2.29.92/capplets/common/gnome-theme-info.h
===================================================================
--- gnome-control-center-2.29.92.orig/capplets/common/gnome-theme-info.h	2009-05-03 20:30:56.000000000 +0200
+++ gnome-control-center-2.29.92/capplets/common/gnome-theme-info.h	2010-03-26 15:48:39.322148357 +0100
@@ -115,6 +115,7 @@
   gchar *windowtitle_font;
   gchar *monospace_font;
   gchar *background_image;
+  gchar *button_layout;
 };
 
 enum {
Index: gnome-control-center-2.29.92/capplets/appearance/appearance-themes.c
===================================================================
--- gnome-control-center-2.29.92.orig/capplets/appearance/appearance-themes.c	2010-01-26 09:46:31.000000000 +0100
+++ gnome-control-center-2.29.92/capplets/appearance/appearance-themes.c	2010-03-26 15:49:41.818147150 +0100
@@ -39,7 +39,8 @@
   RESPONSE_APPLY_BG,
   RESPONSE_REVERT_FONT,
   RESPONSE_APPLY_FONT,
-  RESPONSE_INSTALL_ENGINE
+  RESPONSE_INSTALL_ENGINE,
+  RESPONSE_REVERT_BUTTON_LAYOUT,
 };
 
 enum
@@ -56,6 +57,8 @@
 
 static void theme_message_area_update (AppearanceData *data);
 
+GnomeThemeMetaInfo *previoustheme = NULL;
+
 static time_t
 theme_get_mtime (const char *name)
 {
@@ -579,6 +582,16 @@
       }
       theme_message_area_update (data);
       break;
+
+    case RESPONSE_REVERT_BUTTON_LAYOUT:
+      if (data->revert_button_layout != NULL) {
+        gconf_client_set_string (data->client, BUTTON_LAYOUT_KEY,
+                                 data->revert_button_layout, NULL);
+        g_free (data->revert_button_layout);
+        data->revert_button_layout = NULL;
+      }
+      break;
+
   }
 }
 
@@ -589,9 +602,11 @@
   gboolean show_apply_background = FALSE;
   gboolean show_apply_font = FALSE;
   gboolean show_revert_font = FALSE;
+  gboolean show_revert_button_layout = FALSE;
   gboolean show_error;
   const gchar *message;
   gchar *font;
+  gchar *button_layout;
   GError *error = NULL;
 
   theme = theme_get_selected (GTK_ICON_VIEW (appearance_capplet_get_widget (data, "theme_list")), data);
@@ -652,6 +667,11 @@
     show_revert_font = (data->revert_application_font != NULL ||
       data->revert_documents_font != NULL || data->revert_desktop_font != NULL ||
       data->revert_windowtitle_font != NULL || data->revert_monospace_font != NULL);
+
+    button_layout = gconf_client_get_string (data->client, BUTTON_LAYOUT_KEY, NULL);
+    show_revert_button_layout =
+         (!button_layout || data->revert_button_layout != NULL);
+    g_free (button_layout);
   }
 
   if (data->theme_message_area == NULL) {
@@ -659,7 +679,7 @@
     GtkWidget *parent;
     GtkWidget *content;
 
-    if (!show_apply_background && !show_revert_font && !show_apply_font && !show_error)
+    if (!show_apply_background && !show_revert_font && !show_apply_font && !show_error && !show_revert_button_layout)
       return;
 
     data->theme_message_area = gtk_info_bar_new ();
@@ -684,6 +704,10 @@
         GTK_INFO_BAR (data->theme_message_area),
         _("Install"),
         RESPONSE_INSTALL_ENGINE);
+    data->revert_button_layout_button = gtk_info_bar_add_button (
+        GTK_INFO_BAR (data->theme_message_area),
+        _("Revert Button Layout"),
+        RESPONSE_REVERT_BUTTON_LAYOUT);
 
     data->theme_message_label = gtk_label_new (NULL);
     gtk_widget_show (data->theme_message_label);
@@ -708,20 +732,30 @@
 
   if (show_error)
     message = error->message;
+  else if (show_apply_background && show_apply_font && show_revert_font && show_revert_button_layout)
+    message = _("The current theme suggests a background, a font and a button layout. Also, the last applied font and button layout suggestion can be reverted.");
   else if (show_apply_background && show_apply_font && show_revert_font)
     message = _("The current theme suggests a background and a font. Also, the last applied font suggestion can be reverted.");
+  else if (show_apply_background && show_apply_font && show_revert_button_layout)
+    message = _("The current theme suggests a background, a font and a button layout. Also, the last applied button layout suggestion can be reverted.");
+  else if (show_apply_background && show_revert_font && show_revert_button_layout)
+    message = _("The current theme suggests a background and a button layout. Also, the last applied font and button layout suggestion can be reverted.");
   else if (show_apply_background && show_revert_font)
     message = _("The current theme suggests a background. Also, the last applied font suggestion can be reverted.");
   else if (show_apply_background && show_apply_font)
     message = _("The current theme suggests a background and a font.");
   else if (show_apply_font && show_revert_font)
     message = _("The current theme suggests a font. Also, the last applied font suggestion can be reverted.");
+  else if (show_apply_font && show_revert_button_layout)
+    message = _("The current theme suggests a font and a button layout. Also, the last applied button_layout suggestion can be reverted.");
   else if (show_apply_background)
     message = _("The current theme suggests a background.");
   else if (show_revert_font)
     message = _("The last applied font suggestion can be reverted.");
   else if (show_apply_font)
     message = _("The current theme suggests a font.");
+  else if (show_revert_button_layout)
+    message = _("The current theme suggests a button layout. Also, the last button layout suggestion can be reverted.");
   else
     message = NULL;
 
@@ -740,6 +774,11 @@
   else
     gtk_widget_hide (data->revert_font_button);
 
+  if (show_revert_button_layout)
+    gtk_widget_show (data->revert_button_layout_button);
+  else
+    gtk_widget_hide (data->revert_button_layout_button);
+
   if (show_error
       && g_error_matches (error, GNOME_THEME_ERROR, GNOME_THEME_ERROR_GTK_ENGINE_NOT_AVAILABLE)
       && packagekit_available ())
@@ -747,7 +786,7 @@
   else
     gtk_widget_hide (data->install_button);
 
-  if (show_error || show_apply_background || show_apply_font || show_revert_font) {
+  if (show_error || show_apply_background || show_apply_font || show_revert_font || show_revert_button_layout) {
     gtk_widget_show (data->theme_message_area);
     gtk_widget_queue_draw (data->theme_message_area);
 
@@ -767,6 +806,29 @@
 }
 
 static void
+update_button_layout (GnomeThemeMetaInfo *theme, AppearanceData *data)
+{
+  gchar *tmpbutton_layout = NULL;
+
+  if (theme->button_layout) {
+    tmpbutton_layout = gconf_client_get_string (data->client, BUTTON_LAYOUT_KEY, NULL);
+    if (tmpbutton_layout != NULL) {
+      g_free (data->revert_button_layout);
+      data->revert_button_layout = NULL;
+      if (strcmp (theme->button_layout, tmpbutton_layout) == 0)
+        g_free (tmpbutton_layout);
+      else {
+        if (previoustheme && strcmp (previoustheme->button_layout, tmpbutton_layout) != 0)
+          data->revert_button_layout = tmpbutton_layout;
+      }
+    }
+    if (previoustheme)
+      gconf_client_set_string (data->client, BUTTON_LAYOUT_KEY,
+                               theme->button_layout, NULL);
+  }
+}
+
+static void
 theme_selection_changed_cb (GtkWidget *icon_view, AppearanceData *data)
 {
   GList *selection;
@@ -794,6 +856,8 @@
     if (theme) {
       gnome_meta_theme_set (theme);
       theme_message_area_update (data);
+      update_button_layout (theme, data);
+      previoustheme = theme;
     }
 
     g_free (name);
@@ -998,7 +1062,7 @@
 }
 
 static void
-background_or_font_changed (GConfEngine *conf,
+background_button_or_font_changed (GConfEngine *conf,
                             guint cnxn_id,
                             GConfEntry *entry,
                             AppearanceData *data)
@@ -1027,6 +1091,7 @@
   data->revert_documents_font = NULL;
   data->revert_desktop_font = NULL;
   data->revert_windowtitle_font = NULL;
+  data->revert_button_layout = NULL;
   data->revert_monospace_font = NULL;
   data->theme_save_dialog = NULL;
   data->theme_message_area = NULL;
@@ -1147,12 +1212,13 @@
 #ifdef HAVE_XCURSOR
   gconf_client_notify_add (data->client, CURSOR_SIZE_KEY, (GConfClientNotifyFunc) theme_gconf_changed, data, NULL, NULL);
 #endif
-  gconf_client_notify_add (data->client, BACKGROUND_KEY, (GConfClientNotifyFunc) background_or_font_changed, data, NULL, NULL);
-  gconf_client_notify_add (data->client, APPLICATION_FONT_KEY, (GConfClientNotifyFunc) background_or_font_changed, data, NULL, NULL);
-  gconf_client_notify_add (data->client, DOCUMENTS_FONT_KEY, (GConfClientNotifyFunc) background_or_font_changed, data, NULL, NULL);
-  gconf_client_notify_add (data->client, DESKTOP_FONT_KEY, (GConfClientNotifyFunc) background_or_font_changed, data, NULL, NULL);
-  gconf_client_notify_add (data->client, WINDOWTITLE_FONT_KEY, (GConfClientNotifyFunc) background_or_font_changed, data, NULL, NULL);
-  gconf_client_notify_add (data->client, MONOSPACE_FONT_KEY, (GConfClientNotifyFunc) background_or_font_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, BACKGROUND_KEY, (GConfClientNotifyFunc) background_button_or_font_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, APPLICATION_FONT_KEY, (GConfClientNotifyFunc) background_button_or_font_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, DOCUMENTS_FONT_KEY, (GConfClientNotifyFunc) background_button_or_font_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, DESKTOP_FONT_KEY, (GConfClientNotifyFunc) background_button_or_font_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, WINDOWTITLE_FONT_KEY, (GConfClientNotifyFunc) background_button_or_font_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, MONOSPACE_FONT_KEY, (GConfClientNotifyFunc) background_button_or_font_changed, data, NULL, NULL);
+  gconf_client_notify_add (data->client, BUTTON_LAYOUT_KEY, (GConfClientNotifyFunc) background_button_or_font_changed, data, NULL, NULL);
 
   settings = gtk_settings_get_default ();
   g_signal_connect (settings, "notify::gtk-color-scheme", (GCallback) theme_setting_changed_cb, data);
@@ -1187,4 +1253,5 @@
   g_free (data->revert_desktop_font);
   g_free (data->revert_windowtitle_font);
   g_free (data->revert_monospace_font);
+  g_free (data->revert_button_layout);
 }
Index: gnome-control-center-2.29.92/capplets/appearance/appearance.h
===================================================================
--- gnome-control-center-2.29.92.orig/capplets/appearance/appearance.h	2010-01-26 09:46:31.000000000 +0100
+++ gnome-control-center-2.29.92/capplets/appearance/appearance.h	2010-03-26 15:48:39.322148357 +0100
@@ -73,11 +73,13 @@
   GtkWidget *install_button;
   GtkWidget *theme_info_icon;
   GtkWidget *theme_error_icon;
+  GtkWidget *revert_button_layout_button;
   gchar *revert_application_font;
   gchar *revert_documents_font;
   gchar *revert_desktop_font;
   gchar *revert_windowtitle_font;
   gchar *revert_monospace_font;
+  gchar *revert_button_layout;
 
   /* style */
   GdkPixbuf *gtk_theme_icon;
Index: gnome-control-center-2.29.92/capplets/appearance/theme-util.h
===================================================================
--- gnome-control-center-2.29.92.orig/capplets/appearance/theme-util.h	2009-05-03 20:30:56.000000000 +0200
+++ gnome-control-center-2.29.92/capplets/appearance/theme-util.h	2010-03-26 15:48:39.322148357 +0100
@@ -30,6 +30,7 @@
 #define DESKTOP_FONT_KEY "/apps/nautilus/preferences/desktop_font"
 #define WINDOWTITLE_FONT_KEY "/apps/metacity/general/titlebar_font"
 #define MONOSPACE_FONT_KEY "/desktop/gnome/interface/monospace_font_name"
+#define BUTTON_LAYOUT_KEY "/apps/metacity/general/button_layout"
 
 #ifdef HAVE_XCURSOR
 # define CURSOR_THEME_KEY "/desktop/gnome/peripherals/mouse/cursor_theme"
