Index: /pykoticon/trunk/bin/pykoticon
===================================================================
--- /pykoticon/trunk/bin/pykoticon (revision 111)
+++ /pykoticon/trunk/bin/pykoticon (revision 112)
@@ -112,7 +112,7 @@
         for (k, v) in varvalues.items() :
             values[k] = v.data
-        wx.CallAfter(self.frame.askDatas, [ v.data for v in labels ], \
+        wx.CallAfter(self.frame.askDatas, [ self.frame.UTF8ToUserCharset(v.data) for v in labels ], \
                                           varnames, \
-                                          values)
+                                          [ self.frame.UTF8ToUserCharset(v.data) for v in values])
         # ugly, isn't it ?
         while self.frame.dialogAnswer is None :
@@ -121,5 +121,5 @@
         for (k, v) in retcode.items() :
             if k != "isValid" :
-                retcode[k] = xmlrpclib.Binary(v)
+                retcode[k] = xmlrpclib.Binary(self.frame.userCharsetToUTF8(v))
         self.frame.dialogAnswer = None # prepare for next call, just in case
         return retcode
@@ -127,5 +127,5 @@
     def export_showDialog(self, message, yesno) :
         """Opens a notification or confirmation dialog."""
-        wx.CallAfter(self.frame.showDialog, message.data, yesno)
+        wx.CallAfter(self.frame.showDialog, self.frame.UTF8ToUserCharset(message.data), yesno)
         # ugly, isn't it ?
         while self.frame.dialogAnswer is None :
@@ -333,10 +333,36 @@
             pass
         
-    def postInit(self, printserver, localport) :    
+    def postInit(self, charset, printserver, localport) :    
         """Starts the XML-RPC server."""
         self.quitEvent = threading.Event()
+        self.charset = charset
         self.port = localport
         self.server = MyXMLRPCServer(self, printserver, localport)
-    
+        
+    def UTF8ToUserCharset(self, text) :
+        """Converts from UTF-8 to user's charset."""
+        if text is not None :
+            try :
+                return unicode(text, "UTF-8").encode(self.charset) 
+            except UnicodeError :    
+                try :
+                    # Incorrect locale settings ?
+                    return unicode(text, "UTF-8").encode("ISO-8859-15") 
+                except UnicodeError :    
+                    pass
+        return text
+        
+    def userCharsetToUTF8(self, text) :
+        """Converts from user's charset to UTF-8."""
+        if text is not None :
+            try :
+                return unicode(text, self.charset).encode("UTF-8") 
+            except UnicodeError :    
+                try :
+                    # Incorrect locale settings ?
+                    return unicode(text, "ISO-8859-15").encode("UTF-8") 
+                except UnicodeError :    
+                    pass
+        return text
 
 class PyKotIconApp(wx.App):
@@ -347,7 +373,7 @@
         return True
         
-    def postInit(self, printserver, localport) :    
+    def postInit(self, charset, printserver, localport) :    
         """Continues processing."""
-        self.frame.postInit(printserver, localport)
+        self.frame.postInit(charset, printserver, localport)
         
 def main(printserver, localport):
@@ -361,4 +387,22 @@
     except :
         gettext.NullTranslations().install()
+        
+    localecharset = None
+    try :
+        try :
+            localecharset = locale.nl_langinfo(locale.CODESET)
+        except AttributeError :    
+            try :
+                localecharset = locale.getpreferredencoding()
+            except AttributeError :    
+                try :
+                    localecharset = locale.getlocale()[1]
+                    localecharset = localecharset or locale.getdefaultlocale()[1]
+                except ValueError :    
+                    pass        # Unknown locale, strange...
+    except locale.Error :            
+        pass
+    charset = os.environ.get("CHARSET") or localecharset or "ISO-8859-15"
+    
     app = PyKotIconApp()
     try :
@@ -366,5 +410,5 @@
     except (TypeError, ValueError) :    
         raise ValueError, "Invalid TCP port parameter %s\n" % localport
-    app.postInit(printserver, localport)
+    app.postInit(charset, printserver, localport)
     app.MainLoop()
     
