Index: src/gnome-terminal.glade2
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/gnome-terminal.glade2,v
retrieving revision 1.34
diff -u -p -u -r1.34 gnome-terminal.glade2
--- src/gnome-terminal.glade2	8 Dec 2002 05:00:24 -0000	1.34
+++ src/gnome-terminal.glade2	21 Apr 2003 19:23:21 -0000
@@ -217,7 +217,7 @@
 		  <child>
 		    <widget class="GtkTable" id="table19">
 		      <property name="visible">True</property>
-		      <property name="n_rows">3</property>
+		      <property name="n_rows">5</property>
 		      <property name="n_columns">2</property>
 		      <property name="homogeneous">False</property>
 		      <property name="row_spacing">12</property>
@@ -300,6 +300,53 @@
 		      </child>
 
 		      <child>
+			<widget class="GtkLabel" id="encoding-entry-label">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">_Encoding:</property>
+			  <property name="use_underline">True</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_CENTER</property>
+			  <property name="wrap">False</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			  <property name="mnemonic_widget">encoding-optionmenu</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">1</property>
+			  <property name="top_attach">3</property>
+			  <property name="bottom_attach">4</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkOptionMenu" id="encoding-optionmenu">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="history">-1</property>
+
+			  <child internal-child="menu">
+			    <widget class="GtkMenu" id="encoding-optionmenu-menu">
+			      <property name="visible">True</property>
+			    </widget>
+			  </child>
+			</widget>
+			<packing>
+			  <property name="left_attach">1</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">3</property>
+			  <property name="bottom_attach">4</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
 			<widget class="GtkAlignment" id="alignment10">
 			  <property name="visible">True</property>
 			  <property name="xalign">1.49012e-08</property>
@@ -817,8 +864,8 @@
 			  <property name="invisible_char" translatable="yes">*</property>
 			  <property name="activates_default">False</property>
 			  <accessibility>
-			    <atkrelation target="custom-command-entry-label" type="labelled-by"/>
 			    <atkrelation target="use-custom-command-checkbutton" type="controlled-by"/>
+			    <atkrelation target="custom-command-entry-label" type="labelled-by"/>
 			  </accessibility>
 			</widget>
 			<packing>
Index: src/gnome-terminal.schemas
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/gnome-terminal.schemas,v
retrieving revision 1.31
diff -u -p -u -r1.31 gnome-terminal.schemas
--- src/gnome-terminal.schemas	3 Dec 2002 04:05:56 -0000	1.31
+++ src/gnome-terminal.schemas	21 Apr 2003 19:23:21 -0000
@@ -260,6 +260,22 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/gnome-terminal/profiles/Default/encoding</key>
+      <applyto>/apps/gnome-terminal/profiles/Default/encoding</applyto>
+      <owner>gnome-terminal</owner>
+      <type>string</type>
+      <default></default>
+      <locale name="C">
+         <short>Character encoding</short>
+         <long>
+           The character encoding to be used by screens using this profile.
+           If set to the empty string, the encoding will be set from the
+           current locale.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/gnome-terminal/profiles/Default/scrollbar_position</key>
       <applyto>/apps/gnome-terminal/profiles/Default/scrollbar_position</applyto>
       <owner>gnome-terminal</owner>
Index: src/profile-editor.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/profile-editor.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 profile-editor.c
--- src/profile-editor.c	8 Dec 2002 16:04:57 -0000	1.40
+++ src/profile-editor.c	21 Apr 2003 19:23:21 -0000
@@ -33,6 +33,8 @@
 #include <math.h>
 #include "simple-x-font-selector.h"
 #include "terminal-widget.h"
+#include "terminal-profile.h"
+#include "encoding.h"
 
 #define BYTES_PER_LINE (terminal_widget_get_estimated_bytes_per_scrollback_line ())
 
@@ -99,6 +101,8 @@ static void       profile_editor_update_
                                                               TerminalProfile *profile);
 static void       profile_editor_update_word_chars           (GtkWidget       *widget,
                                                               TerminalProfile *profile);
+static void       profile_editor_update_encoding             (GtkWidget       *widget,
+                                                              TerminalProfile *profile);
 static void       profile_editor_update_scrollbar_position   (GtkWidget       *widget,
                                                               TerminalProfile *profile);
 static void       profile_editor_update_scrollback_lines     (GtkWidget       *widget,
@@ -289,6 +293,9 @@ profile_changed (TerminalProfile        
   if (mask->word_chars)
     profile_editor_update_word_chars (editor, profile);
 
+  if (mask->encoding)
+    profile_editor_update_encoding (editor, profile);
+
   if (mask->scrollbar_position)
     profile_editor_update_scrollbar_position (editor, profile);
 
@@ -503,7 +510,21 @@ word_chars_changed (GtkWidget       *ent
 
   g_free (text);
 }
+ 
+static void
+encoding_changed (GtkWidget       *option_menu,
+                  TerminalProfile *profile)
+{
+  GtkWidget *active;
+  char *encoding;
+
+  active = gtk_menu_get_active (GTK_MENU (gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu))));
 
+  encoding = g_object_get_data (G_OBJECT (active), "encoding");
+
+  terminal_profile_set_encoding (profile, encoding);
+}
+      
 static void 
 font_changed (EggXFontSelector *selector, TerminalProfile *profile)
 {
@@ -906,6 +927,79 @@ editor_response_cb (GtkDialog *editor,
     }
 }
 
+static void
+fill_in_encoding_option_menu (TerminalProfile *profile, 
+                              GtkWidget *w)
+{
+  GSList *encodings, *tmp;
+  GtkWidget *menu, *item;
+  int selected = -1, i;
+
+  menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (w));
+  encodings = terminal_get_active_encodings ();
+
+  i = 0;
+
+  item = gtk_menu_item_new_with_label ("Use locale");
+  g_object_set_data_full (G_OBJECT (item),
+                          "encoding",
+                          g_strdup (""),
+                          (GDestroyNotify) g_free);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+  gtk_widget_show (item);
+
+  if (!strcmp (terminal_profile_get_encoding (profile), ""))
+    selected = 0;
+
+  i++;
+
+  item = gtk_separator_menu_item_new ();
+  g_object_set_data_full (G_OBJECT (item),
+                          "encoding",
+                          g_strdup(""),
+                          (GDestroyNotify) g_free);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); 
+  gtk_widget_show (item);
+
+  i++;
+
+  for (tmp = encodings; tmp; tmp = tmp->next)
+    {
+      TerminalEncoding *e = tmp->data;
+      char *name;
+
+      if (e->index == TERMINAL_ENCODING_CURRENT_LOCALE)
+        continue;
+
+      name = g_strdup_printf ("%s (%s)", e->name, e->charset);
+
+      if (selected < 0 && !strcmp(e->charset, terminal_profile_get_encoding (profile)))
+        selected = i;
+
+      item = gtk_menu_item_new_with_label (name);
+      g_object_set_data_full (G_OBJECT (item),
+                              "encoding",
+                              g_strdup (e->charset),
+                              (GDestroyNotify) g_free);
+
+      gtk_widget_show (item);
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+      g_free (name);
+    }
+
+  g_slist_foreach (encodings,
+                   (GFunc) terminal_encoding_free,
+                   NULL);
+  g_slist_free (encodings);
+
+  if (selected < 0)
+    selected = 0;
+
+  gtk_option_menu_set_history (GTK_OPTION_MENU (w), selected);
+  gtk_widget_show (w);
+}
+
 void
 terminal_profile_edit (TerminalProfile *profile,
                        GtkWindow       *transient_parent)
@@ -1055,6 +1149,13 @@ terminal_profile_edit (TerminalProfile *
                         G_CALLBACK (word_chars_changed),
                         profile);
       
+      w = glade_xml_get_widget (xml, "encoding-optionmenu");
+      fill_in_encoding_option_menu (profile, w);
+      profile_editor_update_encoding (editor, profile);
+      g_signal_connect (G_OBJECT (w), "changed",
+                        G_CALLBACK (encoding_changed),
+                        profile);
+
       w = glade_xml_get_widget (xml, "scrollbar-position-optionmenu");
       profile_editor_update_scrollbar_position (editor, profile);
       g_signal_connect (G_OBJECT (w), "changed",
@@ -1384,7 +1485,6 @@ profile_editor_update_sensitivity (GtkWi
       gtk_widget_set_sensitive (w, FALSE);
     }
 
-
   if (terminal_profile_get_use_theme_colors (profile))
     {
       set_insensitive (editor, "foreground-colorpicker", TRUE);
@@ -1674,6 +1774,35 @@ profile_editor_update_word_chars (GtkWid
 
   entry_set_text_if_changed (GTK_ENTRY (w),
                              terminal_profile_get_word_chars (profile));
+}
+
+static void
+profile_editor_update_encoding (GtkWidget       *editor,
+                                TerminalProfile *profile)
+{
+  GList *items, *tmp;
+  GtkWidget *option_menu, *menu;
+  const char *new_encoding;
+  int i;
+
+  option_menu = profile_editor_get_widget (editor, "encoding-optionmenu");
+  menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
+  items = GTK_MENU_SHELL(menu)->children;
+
+  new_encoding = terminal_profile_get_encoding (profile);
+
+  for ((i = 0), tmp = items; tmp; i++, tmp = tmp->next)
+    {
+      GtkMenuItem *item = tmp->data;
+      char *encoding;
+
+      encoding = g_object_get_data (G_OBJECT (item), "encoding");
+      if (!strcmp (encoding, new_encoding)) 
+        {
+          gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), i);
+          return;
+        }
+    }
 }
 
 static void
Index: src/terminal-profile.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-profile.c,v
retrieving revision 1.25
diff -u -p -u -r1.25 terminal-profile.c
--- src/terminal-profile.c	21 Jan 2003 23:37:45 -0000	1.25
+++ src/terminal-profile.c	21 Apr 2003 19:23:21 -0000
@@ -29,10 +29,11 @@
 
 /* If you add a key, you need to update code:
  * 
+ *  - in the function that gets the key
  *  - in the function that sets the key
- *  - in the update function that reads all keys on startup
- *  - in the profile_change_notify function
- *  - in the function that copies base profiles to new profiles
+ *  - in the terminal_profile_update function that reads all keys on startup
+ *  - in the profile_change_notify function (and probably add a field in TerminalSettingMask...)
+ *  - in the function terminal_profile_create that copies base profiles to new profiles
  *  - in terminal_profile_init() initial value, sometimes
  *    (only e.g. if the item is non-null by invariant)
  *
@@ -48,6 +49,7 @@
 #define KEY_ALLOW_BOLD "allow_bold"
 #define KEY_SILENT_BELL "silent_bell"
 #define KEY_WORD_CHARS "word_chars"
+#define KEY_ENCODING "encoding"
 #define KEY_SCROLLBAR_POSITION "scrollbar_position"
 #define KEY_SCROLLBACK_LINES "scrollback_lines"
 #define KEY_SCROLL_ON_KEYSTROKE "scroll_on_keystroke"
@@ -92,6 +94,7 @@ struct _TerminalProfilePrivate
   char *title;
   TerminalTitleMode title_mode;
   char *word_chars;
+  char *encoding;
   TerminalScrollbarPosition scrollbar_position;
   int scrollback_lines;
   TerminalExitAction exit_action;
@@ -277,6 +280,7 @@ terminal_profile_init (TerminalProfile *
   profile->priv->scrollback_lines = 1000;
   profile->priv->allow_bold = TRUE;
   profile->priv->word_chars = g_strdup ("");
+  profile->priv->encoding = g_strdup("");
   profile->priv->custom_command = g_strdup ("");
   profile->priv->icon_file = g_strdup ("gnome-terminal.png");
   memcpy (profile->priv->palette,
@@ -346,6 +350,7 @@ terminal_profile_finalize (GObject *obje
   g_free (profile->priv->title);
   g_free (profile->priv->profile_dir);
   g_free (profile->priv->icon_file);
+  g_free (profile->priv->encoding);
   if (profile->priv->icon)
     g_object_unref (G_OBJECT (profile->priv->icon));
   g_free (profile->priv->x_font);
@@ -720,6 +725,33 @@ terminal_profile_set_word_chars (Termina
 }
 
 const char*
+terminal_profile_get_encoding (TerminalProfile *profile)
+{
+  g_return_val_if_fail (TERMINAL_IS_PROFILE (profile), NULL);
+
+  return profile->priv->encoding;
+}
+
+void
+terminal_profile_set_encoding (TerminalProfile *profile,
+                               const char      *encoding)
+{
+  char *key;
+
+  RETURN_IF_NOTIFYING (profile);
+
+  key = gconf_concat_dir_and_key (profile->priv->profile_dir,
+                                  KEY_ENCODING);
+
+  gconf_client_set_string (profile->priv->conf,
+                           key,
+                           encoding,
+                           NULL);
+
+  g_free (key);
+}
+
+const char*
 terminal_profile_get_title (TerminalProfile  *profile)
 {
   g_return_val_if_fail (TERMINAL_IS_PROFILE (profile), NULL);
@@ -1613,6 +1645,26 @@ set_word_chars (TerminalProfile *profile
 }
 
 static gboolean
+set_encoding (TerminalProfile *profile,
+              const char      *candidate_encoding)
+{
+  if (candidate_encoding &&
+      strcmp (profile->priv->encoding, candidate_encoding) == 0)
+    return FALSE;
+  
+  if (candidate_encoding != NULL)
+    {
+      g_free (profile->priv->encoding);
+      profile->priv->encoding = g_strdup (candidate_encoding);
+      return TRUE;
+    }
+
+  /* otherwise just leave the old encoding */
+
+  return FALSE;
+}
+
+static gboolean
 set_scrollbar_position (TerminalProfile *profile,
                         const char      *str_val)
 {
@@ -1961,6 +2013,7 @@ terminal_profile_update (TerminalProfile
   UPDATE_BOOLEAN (KEY_ALLOW_BOLD,           allow_bold);
   UPDATE_BOOLEAN (KEY_SILENT_BELL,          silent_bell);
   UPDATE_STRING  (KEY_WORD_CHARS,           word_chars);
+  UPDATE_STRING  (KEY_ENCODING,             encoding);
   UPDATE_STRING  (KEY_SCROLLBAR_POSITION,   scrollbar_position);
   UPDATE_INTEGER (KEY_SCROLLBACK_LINES,     scrollback_lines);
   UPDATE_BOOLEAN (KEY_SCROLL_ON_KEYSTROKE,  scroll_on_keystroke);
@@ -2093,8 +2146,9 @@ else if (strcmp (key, KName) == 0)      
                                                                         \
     profile->priv->locked.FName = !gconf_entry_get_is_writable (entry);
 
+ 
 
- if (0)
+ if (0) /* yuks */
    {
      ;
      UPDATE_BOOLEAN (KEY_CURSOR_BLINK,           cursor_blink,           FALSE);
@@ -2107,6 +2161,7 @@ else if (strcmp (key, KName) == 0)      
      UPDATE_BOOLEAN (KEY_ALLOW_BOLD,             allow_bold,             FALSE);
      UPDATE_BOOLEAN (KEY_SILENT_BELL,            silent_bell,            FALSE);
      UPDATE_STRING  (KEY_WORD_CHARS,             word_chars,             NULL);
+     UPDATE_STRING  (KEY_ENCODING,               encoding,               NULL);
      UPDATE_STRING  (KEY_SCROLLBAR_POSITION,     scrollbar_position,     NULL);
      UPDATE_INTEGER (KEY_SCROLLBACK_LINES,       scrollback_lines,       profile->priv->scrollback_lines);
      UPDATE_BOOLEAN (KEY_SCROLL_ON_KEYSTROKE, 	 scroll_on_keystroke,    FALSE);
@@ -2669,7 +2724,17 @@ terminal_profile_create (TerminalProfile
                            key, base_profile->priv->word_chars,
                            &err);
   BAIL_OUT_CHECK ();
-  
+ 
+  g_free (key);
+  key = gconf_concat_dir_and_key (profile_dir,
+                                  KEY_ENCODING);
+
+  gconf_client_set_string (base_profile->priv->conf,
+                           key, base_profile->priv->encoding,
+                           &err);
+
+  BAIL_OUT_CHECK ();
+
   g_free (key);
   key = gconf_concat_dir_and_key (profile_dir,
                                   KEY_SCROLLBAR_POSITION);
Index: src/terminal-profile.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-profile.h,v
retrieving revision 1.21
diff -u -p -u -r1.21 terminal-profile.h
--- src/terminal-profile.h	8 Dec 2002 05:00:25 -0000	1.21
+++ src/terminal-profile.h	21 Apr 2003 19:23:21 -0000
@@ -44,6 +44,7 @@ typedef struct
   unsigned int allow_bold : 1;
   unsigned int silent_bell : 1;
   unsigned int word_chars : 1;
+  unsigned int encoding : 1;
   unsigned int scrollbar_position : 1;
   unsigned int scrollback_lines : 1;
   unsigned int scroll_on_keystroke : 1;
@@ -152,6 +153,7 @@ int                       terminal_profi
 void                      terminal_profile_get_color_scheme         (TerminalProfile *profile,
                                                                      GdkColor        *foreground,
                                                                      GdkColor        *background);
+const char*               terminal_profile_get_encoding             (TerminalProfile *profile);
 const char*               terminal_profile_get_word_chars           (TerminalProfile *profile);
 const char*               terminal_profile_get_title                (TerminalProfile *profile);
 TerminalTitleMode         terminal_profile_get_title_mode           (TerminalProfile *profile);
@@ -207,6 +209,8 @@ void terminal_profile_set_title_mode    
                                                 TerminalTitleMode          mode);
 void terminal_profile_set_word_chars           (TerminalProfile           *profile,
                                                 const char                *word_class);
+void terminal_profile_set_encoding             (TerminalProfile           *profile,
+                                                const char                *encoding);
 void terminal_profile_set_default_show_menubar (TerminalProfile           *profile,
                                                 gboolean                   setting);
 void terminal_profile_set_scroll_on_keystroke  (TerminalProfile           *profile,
Index: src/terminal-screen.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.c,v
retrieving revision 1.72
diff -u -p -u -r1.72 terminal-screen.c
--- src/terminal-screen.c	7 Apr 2003 12:34:44 -0000	1.72
+++ src/terminal-screen.c	21 Apr 2003 19:23:21 -0000
@@ -398,6 +398,9 @@ reread_profile (TerminalScreen *screen)
   terminal_widget_set_word_characters (term,
                                        terminal_profile_get_word_chars (profile));
 
+  terminal_widget_set_encoding (term, 
+                                terminal_profile_get_encoding (profile));
+
   terminal_widget_set_scroll_on_keystroke (term,
                                            terminal_profile_get_scroll_on_keystroke (profile));
   
Index: src/terminal-widget-vte.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-widget-vte.c,v
retrieving revision 1.26
diff -u -p -u -r1.26 terminal-widget-vte.c
--- src/terminal-widget-vte.c	3 Dec 2002 04:07:17 -0000	1.26
+++ src/terminal-widget-vte.c	21 Apr 2003 19:23:21 -0000
@@ -549,7 +549,7 @@ terminal_widget_set_encoding (GtkWidget 
     return;
   
   vte_terminal_set_encoding (VTE_TERMINAL (widget),
-                             encoding);
+                             *encoding ? encoding : NULL);
 }
 
 gboolean
