--- gnome-terminal-2.6.1-orig/src/gnome-terminal.glade2	2006-02-07 21:46:28.942650000 +0900
+++ gnome-terminal-2.6.1/src/gnome-terminal.glade2	2006-02-08 10:32:29.333762000 +0900
@@ -227,13 +227,87 @@
 		  <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>
 		      <property name="column_spacing">12</property>
 
 		      <child>
+			<widget class="GtkCheckButton" id="use-terminal-encoding-checkbutton">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">Use the _terminal encoding</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="focus_on_click">True</property>
+			  <property name="active">False</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			  <accessibility>
+			    <atkrelation target="default-encoding-optionmenu" type="controller-for"/>
+			  </accessibility>
+			</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="GtkLabel" id="default-encoding-optionmenu-label">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">Default _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">default-encoding-optionmenu</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">1</property>
+			  <property name="top_attach">4</property>
+			  <property name="bottom_attach">5</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkOptionMenu" id="default-encoding-optionmenu">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="history">-1</property>
+			  <accessibility>
+			    <atkrelation target="default-encoding-optionmenu-label" type="labelled-by"/>
+			    <atkrelation target="use-terminal-encoding-checkbutton" type="controlled-by"/>
+			  </accessibility>
+			  <child internal-child="menu">
+			    <widget class="GtkMenu" id="convertwidget9">
+			      <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">4</property>
+			  <property name="bottom_attach">5</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
 			<widget class="GtkLabel" id="word-chars-entry-label">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes">Select-by-_word characters:</property>
--- gnome-terminal-2.6.1-orig/src/gnome-terminal.schemas.in	2006-02-07 21:46:48.721834000 +0900
+++ gnome-terminal-2.6.1/src/gnome-terminal.schemas.in	2006-02-08 10:38:06.792473000 +0900
@@ -618,6 +618,24 @@
       </locale>
     </schema>
 
+    <schema>
+      <key>/schemas/apps/gnome-terminal/profiles/Default/default_encoding</key>
+      <applyto>/apps/gnome-terminal/profiles/Default/default_encoding</applyto>
+      <owner>gnome-terminal</owner>
+      <type>string</type>
+      <default>current</default>
+      <locale name="C">
+         <default><!-- Translators: The "current" should not be translated because it is a keyword for the encoding. Normally the msgstr is "current".-->current</default>
+         <short>Specify the default encoding</short>
+         <long>
+         Sets what character encoding by default. Possible values are
+         "current", "UTF-8", "EUC-JP", "SHIFT_JIS" and so on.
+         The special encoding name "current" means to specify the encoding
+         of the current locale.
+         </long>
+      </locale>
+    </schema>
+
     <!-- Keybindings -->
 
     <schema>
--- gnome-terminal-2.6.1-orig/src/profile-editor.c	2006-02-07 21:47:02.773252000 +0900
+++ gnome-terminal-2.6.1/src/profile-editor.c	2006-02-08 10:40:00.857447000 +0900
@@ -30,9 +30,12 @@
 #include <math.h>
 #include "simple-x-font-selector.h"
 #include "terminal-widget.h"
+#include "encoding.h"
 
 #define BYTES_PER_LINE (terminal_widget_get_estimated_bytes_per_scrollback_line ())
 
+static GSList *default_encodings;
+
 typedef struct _TerminalColorScheme TerminalColorScheme;
 
 struct _TerminalColorScheme
@@ -96,6 +99,10 @@ static void       profile_editor_update_
                                                               TerminalProfile *profile);
 static void       profile_editor_update_word_chars           (GtkWidget       *widget,
                                                               TerminalProfile *profile);
+static void       profile_editor_update_use_terminal_encoding(GtkWidget       *widget,
+                                                              TerminalProfile *profile);
+static void       profile_editor_update_default_encoding_menu(GtkWidget       *widget,
+                                                              TerminalProfile *profile);
 static void       profile_editor_update_scrollbar_position   (GtkWidget       *widget,
                                                               TerminalProfile *profile);
 static void       profile_editor_update_scrollback_lines     (GtkWidget       *widget,
@@ -486,6 +493,48 @@ word_chars_changed (GtkWidget       *ent
   g_free (text);
 }
 
+static void
+default_encoding_changed (GtkWidget       *option_menu,
+                          TerminalProfile *profile)
+{
+  int i;
+  GSList *tmp = default_encodings;
+  TerminalEncoding *e;
+  
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (option_menu));
+  
+  if (i < g_slist_length (tmp))
+    {
+      tmp = g_slist_nth (tmp, i);
+      e = tmp->data;
+      terminal_profile_set_default_encoding (profile, e->charset);
+    }
+  else
+    ; /* "custom" selected, no change */
+}
+
+static void
+use_terminal_encoding_toggled (GtkWidget       *checkbutton,
+                               TerminalProfile *profile)
+{
+  GtkWidget *editor;
+  GtkWidget *w;  
+
+  editor = g_object_get_data (G_OBJECT (profile), "editor-window");
+  w = profile_editor_get_widget (editor, "default-encoding-optionmenu");
+
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton)))
+    {
+      gtk_widget_set_sensitive (w, FALSE);
+      terminal_profile_set_default_encoding (profile, "current");
+    }
+  else
+    {
+      gtk_widget_set_sensitive (w, TRUE);
+      default_encoding_changed (w, profile);
+    }
+}
+
 static void 
 font_changed (EggXFontSelector *selector, TerminalProfile *profile)
 {
@@ -768,6 +817,56 @@ font_set (GtkWidget       *fontpicker,
  */
 
 static void
+init_default_encoding_menu (GtkWidget *option_menu, const char *encoding)
+{
+  GtkWidget *menu;
+  GtkWidget *menu_item;
+  GSList *tmp;
+  TerminalEncoding *e;
+  char *name;
+  int i, n;
+  
+  menu = gtk_menu_new ();
+
+  if (default_encodings)
+    {
+      g_slist_foreach (default_encodings,
+                       (GFunc) terminal_encoding_free,
+                       NULL);
+      g_slist_free (default_encodings);
+    }
+
+  n = i = 0;
+  tmp = default_encodings = terminal_get_active_encodings ();
+  while (tmp != NULL)
+    {
+      e = tmp->data;
+
+      if (encoding && !strcmp (encoding, e->charset))
+        n = i;
+
+      name = g_strdup_printf ("%s (%s)", e->name, e->charset);
+
+      menu_item = gtk_menu_item_new_with_label (name);
+      gtk_widget_show (menu_item);
+      
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+                             menu_item);
+      
+      g_free (name);
+
+      tmp = tmp->next;
+      i++;
+    }
+
+  gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu),
+                            menu);
+
+  if (n)
+    gtk_option_menu_set_history (option_menu, n);
+}
+
+static void
 init_color_scheme_menu (GtkWidget *option_menu)
 {
   GtkWidget *menu;
@@ -1004,6 +1103,19 @@ terminal_profile_edit (TerminalProfile *
                         G_CALLBACK (word_chars_changed),
                         profile);
       
+      w = glade_xml_get_widget (xml, "use-terminal-encoding-checkbutton");
+      profile_editor_update_use_terminal_encoding (editor, profile);
+      g_signal_connect (G_OBJECT (w), "toggled",
+                        G_CALLBACK (use_terminal_encoding_toggled),
+                        profile);
+      
+      w = glade_xml_get_widget (xml, "default-encoding-optionmenu");
+      init_default_encoding_menu (w, terminal_profile_get_default_encoding (profile));
+      profile_editor_update_default_encoding_menu (editor, profile);
+      g_signal_connect (G_OBJECT (w), "changed",
+                        G_CALLBACK (default_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",
@@ -1391,6 +1503,19 @@ profile_editor_update_sensitivity (GtkWi
   set_insensitive (editor, "word-chars-entry",
                    mask->word_chars);
 
+  if (!strcmp (terminal_profile_get_default_encoding (profile), "current"))
+    {
+      w = profile_editor_get_widget (editor, "use-terminal-encoding-checkbutton");
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
+      set_insensitive (editor, "default-encoding-optionmenu", TRUE);
+    }
+  else
+    {
+      w = profile_editor_get_widget (editor, "use-terminal-encoding-checkbutton");
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), FALSE);
+      set_insensitive (editor, "default-encoding-optionmenu", FALSE);
+    }
+      
   set_insensitive (editor, "scrollbar-position-optionmenu",
                    mask->scrollbar_position);
 
@@ -1630,6 +1755,42 @@ profile_editor_update_word_chars (GtkWid
 }
 
 static void
+profile_editor_update_use_terminal_encoding (GtkWidget       *editor,
+                                             TerminalProfile *profile)
+{
+  GtkWidget *w;
+
+  w = profile_editor_get_widget (editor, "use-terminal-encoding-checkbutton");
+
+  if (!strcmp (terminal_profile_get_default_encoding (profile), "current"))
+    {
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
+    }
+  else
+    {
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), FALSE);
+    }
+}
+
+static void
+profile_editor_update_default_encoding_menu (GtkWidget       *editor,
+                                             TerminalProfile *profile)
+{
+  int i;
+  GtkWidget *w;
+  GSList *tmp = default_encodings;
+
+  w = profile_editor_get_widget (editor, "default-encoding-optionmenu");
+  
+  i = g_slist_length (tmp);
+
+  /* If we didn't find a match, then we want the last option
+   * menu item which is "custom"
+   */
+  gtk_option_menu_set_history (GTK_OPTION_MENU (w), i);
+}
+
+static void
 profile_editor_update_scrollbar_position   (GtkWidget       *editor,
                                             TerminalProfile *profile)
 {
--- gnome-terminal-2.6.1-orig/src/terminal-profile.c	2006-02-07 21:47:22.965087000 +0900
+++ gnome-terminal-2.6.1/src/terminal-profile.c	2006-02-08 10:35:46.877077000 +0900
@@ -48,6 +48,7 @@
 #define KEY_ALLOW_BOLD "allow_bold"
 #define KEY_SILENT_BELL "silent_bell"
 #define KEY_WORD_CHARS "word_chars"
+#define KEY_DEFAULT_ENCODING "default_encoding"
 #define KEY_SCROLLBAR_POSITION "scrollbar_position"
 #define KEY_SCROLLBACK_LINES "scrollback_lines"
 #define KEY_SCROLL_ON_KEYSTROKE "scroll_on_keystroke"
@@ -92,6 +93,7 @@ struct _TerminalProfilePrivate
   char *title;
   TerminalTitleMode title_mode;
   char *word_chars;
+  char *default_encoding;
   TerminalScrollbarPosition scrollbar_position;
   int scrollback_lines;
   TerminalExitAction exit_action;
@@ -277,6 +279,7 @@ terminal_profile_init (TerminalProfile *
   profile->priv->scrollback_lines = 1000;
   profile->priv->allow_bold = TRUE;
   profile->priv->word_chars = g_strdup ("");
+  profile->priv->default_encoding = g_strdup ("");
   profile->priv->custom_command = g_strdup ("");
   profile->priv->icon_file = g_strdup ("gnome-terminal.png");
   memcpy (profile->priv->palette,
@@ -720,6 +723,33 @@ terminal_profile_set_word_chars (Termina
 }
 
 const char*
+terminal_profile_get_default_encoding (TerminalProfile *profile)
+{
+  g_return_val_if_fail (TERMINAL_IS_PROFILE (profile), NULL);
+  
+  return profile->priv->default_encoding;
+}
+
+void
+terminal_profile_set_default_encoding (TerminalProfile *profile,
+                                       const char *encoding)
+{
+  char *key;
+
+  RETURN_IF_NOTIFYING (profile);
+  
+  key = gconf_concat_dir_and_key (profile->priv->profile_dir,
+                                  KEY_DEFAULT_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 +1643,25 @@ set_word_chars (TerminalProfile *profile
 }
 
 static gboolean
+set_default_encoding (TerminalProfile *profile,
+                      const char      *candidate_encoding)
+{
+  if (candidate_encoding &&
+      strcmp (profile->priv->default_encoding, candidate_encoding) == 0)
+    return FALSE;
+  
+  if (candidate_encoding != NULL)
+    {
+      g_free (profile->priv->default_encoding);
+      profile->priv->default_encoding = g_strdup (candidate_encoding);
+      return TRUE;
+    }
+  /* otherwise just leave the old command */
+  
+  return FALSE;
+}
+
+static gboolean
 set_scrollbar_position (TerminalProfile *profile,
                         const char      *str_val)
 {
@@ -1961,6 +2010,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_DEFAULT_ENCODING,     default_encoding);
   UPDATE_STRING  (KEY_SCROLLBAR_POSITION,   scrollbar_position);
   UPDATE_INTEGER (KEY_SCROLLBACK_LINES,     scrollback_lines);
   UPDATE_BOOLEAN (KEY_SCROLL_ON_KEYSTROKE,  scroll_on_keystroke);
@@ -2107,6 +2157,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_DEFAULT_ENCODING,       default_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);
--- gnome-terminal-2.6.1-orig/src/terminal-profile.h	2006-02-07 21:47:47.075354000 +0900
+++ gnome-terminal-2.6.1/src/terminal-profile.h	2006-02-08 10:37:11.297059000 +0900
@@ -44,6 +44,7 @@ typedef struct
   unsigned int allow_bold : 1;
   unsigned int silent_bell : 1;
   unsigned int word_chars : 1;
+  unsigned int default_encoding: 1;
   unsigned int scrollbar_position : 1;
   unsigned int scrollback_lines : 1;
   unsigned int scroll_on_keystroke : 1;
@@ -153,6 +154,7 @@ void                      terminal_profi
                                                                      GdkColor        *foreground,
                                                                      GdkColor        *background);
 const char*               terminal_profile_get_word_chars           (TerminalProfile *profile);
+const char*               terminal_profile_get_default_encoding     (TerminalProfile *profile);
 const char*               terminal_profile_get_title                (TerminalProfile *profile);
 TerminalTitleMode         terminal_profile_get_title_mode           (TerminalProfile *profile);
 gboolean                  terminal_profile_get_forgotten            (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_default_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,
--- gnome-terminal-2.6.1-orig/src/terminal-screen.c	2006-02-07 21:48:09.679464000 +0900
+++ gnome-terminal-2.6.1/src/terminal-screen.c	2006-02-08 10:42:36.399549000 +0900
@@ -477,6 +477,7 @@ reread_profile (TerminalScreen *screen)
   TerminalProfile *profile;
   GtkWidget *term;
   TerminalBackgroundType bg_type;
+  char *encoding = NULL;
   
   profile = screen->priv->profile;  
   
@@ -558,6 +559,11 @@ reread_profile (TerminalScreen *screen)
   
   terminal_widget_set_delete_binding (term,
                                       terminal_profile_get_delete_binding (profile));
+
+  encoding = terminal_profile_get_default_encoding (profile);
+
+  if (encoding && strcmp (encoding, "current"))
+    terminal_widget_set_encoding (term, encoding);
 }
 
 /**
