On Fri, 15 Jul 2005 13:05:03 +0200 Georg Baum <[EMAIL PROTECTED]>
wrote:

> Lars Gullik Bjønnes wrote:
> 
> > Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> > | I tested 1.4CVS with a variety of locale strings, english and
> french and
> > | german and with and without UTF-8. I tested typing umlauted chars
> into
> > | the buffer, into labels and cross-references and latexing, etc.
> 
> That does work here, too (SuSE 9.2, LANG=de_DE.UTF-8). What does not
> work is
> the interaction to the "outside world" (e. g. spell checking). ASCII
> export
> is of course also in latin1. The other thing that does not work is the
> exchange of buffer text to the frontend, see the attached screenshot.
> BTW,
> I see no difference to 1.3.
> 
> The screenshot shows another bug: "2 ä" should be "1 ä". I created the
> 2 by
> splitting a headline with enter and then deleting the first one. It
> seems
> that a counter update is missing.
> 
> > | Question: is this indeed the case? Or can someone come up with a
> problem
> > | case where system Unicode causes trouble? If so, I want to hear
> about
> > | it.
> 
> Related bugs are http://bugzilla.lyx.org/show_bug.cgi?id=1276,
> http://bugzilla.lyx.org/show_bug.cgi?id=1755 and
> http://bugzilla.lyx.org/show_bug.cgi?id=1770 IMHO.
> 
> > It is the case I showed you yesterday.... I get à instead of the char
> > I really wanted (f.ex. ä)
> 
> I don't have this problem, but then I am using an US keyboard and
> inserting
> umlauts with an xmodmap trick. I don't know if that makes a difference.
> 
> 
> Georg

Thanks Georg, this helped us forward.

Attached a tentative patch mainly by Andreas with moral support from me which
solves the problem for label, ref, index, URL. In order to see the error, you
need to have a locale of type ll_CC.UTF-8. Set LC_CTYPE to this locale.

Please folks try this in different environments.

- Martin
Index: lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lyx_gui.C,v
retrieving revision 1.84
diff -u -p -r1.84 lyx_gui.C
--- lyx_gui.C	12 Jul 2005 11:33:56 -0000	1.84
+++ lyx_gui.C	15 Jul 2005 23:04:03 -0000
@@ -212,8 +212,6 @@ void parse_init(int & argc, char * argv[
 	// needs to be done before reading lyxrc
 	lyxrc.dpi = getDPI();
 
-	initEncodings();
-
 	LoaderQueue::setPriority(10,100);
 }
 
@@ -224,6 +222,8 @@ void parse_lyxrc()
 
 void start(string const & batch, vector<string> const & files)
 {
+	initEncodings();
+
 	// initial geometry
 	unsigned int width = 690;
 	unsigned int height = 510;
Index: QIndex.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QIndex.C,v
retrieving revision 1.28
diff -u -p -r1.28 QIndex.C
--- QIndex.C	19 May 2004 15:11:33 -0000	1.28
+++ QIndex.C	15 Jul 2005 23:04:03 -0000
@@ -51,7 +51,7 @@ void QIndex::build_dialog()
 void QIndex::update_contents()
 {
 	string const contents = controller().params().getContents();
-	dialog_->keywordED->setText(toqstr(contents));
+	dialog_->keywordED->setText((contents));
 
 	bc().valid(!contents.empty());
 }
@@ -59,7 +59,7 @@ void QIndex::update_contents()
 
 void QIndex::apply()
 {
-	controller().params().setContents(fromqstr(dialog_->keywordED->text()));
+	controller().params().setContents((dialog_->keywordED->text()));
 }
 
 
Index: QLPopupMenu.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLPopupMenu.C,v
retrieving revision 1.40
diff -u -p -r1.40 QLPopupMenu.C
--- QLPopupMenu.C	12 May 2005 09:34:14 -0000	1.40
+++ QLPopupMenu.C	15 Jul 2005 23:04:03 -0000
@@ -72,7 +72,7 @@ createMenu(QMenuData * parent, MenuItem 
 	   bool is_toplevel)
 {
 	QLPopupMenu * pm = new QLPopupMenu(owner, item->submenuname(), is_toplevel);
-	int const id = parent->insertItem(toqstr(getLabel(*item)), pm);
+	int const id = parent->insertItem((getLabel(*item)), pm);
 	return make_pair(id, pm);
 }
 
@@ -123,7 +123,7 @@ void QLPopupMenu::populate(Menu * menu)
 				funcs_.insert(funcs_.end(), m->func());
 			int const index = distance(funcs_.begin(), fit);
 
-			QString label = toqstr(getLabel(*m));
+			QString label = (getLabel(*m));
 #ifdef Q_WS_MACX
 			/* There are two constraints on Qt/Mac: (1)
 			   the bindings require a unicode string to be
@@ -143,7 +143,7 @@ void QLPopupMenu::populate(Menu * menu)
 #else
 			string const binding(m->binding());
 			if (!binding.empty()) {
-				label += '\t' + toqstr(binding);
+				label += '\t' + (binding);
 			}
 #endif
 
@@ -178,7 +178,7 @@ void QLPopupMenu::showing()
 		Menu::size_type i = 0;
 		for (Menu::const_iterator cit = special.begin();
 		     cit != end ; ++cit, ++i)
-			insertItem(toqstr(cit->label()), indexOffset + i);
+			insertItem((cit->label()), indexOffset + i);
 	}
 #endif
 }
Index: QLyXKeySym.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLyXKeySym.C,v
retrieving revision 1.32
diff -u -p -r1.32 QLyXKeySym.C
--- QLyXKeySym.C	7 Jul 2004 09:32:19 -0000	1.32
+++ QLyXKeySym.C	15 Jul 2005 23:04:03 -0000
@@ -22,10 +22,14 @@
 #include <qtextcodec.h>
 
 #include <map>
+#include "support/lstrings.h"
+#include "encoding.h"
+#include "language.h"
 
 using std::endl;
 using std::string;
 using std::map;
+using lyx::support::contains;
 
 
 namespace {
@@ -42,18 +46,11 @@ char const encode(string const & encodin
 		if (lyxerr.debugging())
 			lyxerr[Debug::KEY] << "Unrecognised encoding "
 				<< encoding << endl;
-		codec = QTextCodec::codecForLocale();
+		codec = encoding_map.find("")->second;
 	} else {
 		codec = cit->second;
 	}
 
-	if (!codec) {
-		if (lyxerr.debugging())
-			lyxerr[Debug::KEY] << "No codec exists for encoding "
-				<< encoding << endl;
-		codec = QTextCodec::codecForLocale();
-	}
-
 	if (lyxerr.debugging())
 		lyxerr[Debug::KEY] << "Using codec " << fromqstr(codec->name()) << endl;
 
@@ -73,9 +70,14 @@ char const encode(string const & encodin
 
 void initEncodings()
 {
-	// when no document open
-	encoding_map[""] = QTextCodec::codecForLocale();
-
+	const char * c = QTextCodec::locale();
+	string s = c;
+	if (contains(c, "UTF") || contains(c, "utf")) {
+		int i = s.find(".");
+		s = s.substr(0, i);
+		lyxerr << "Warning: this system's locale uses Unicode." << endl;
+		lyxerr << "Setting new locale for Qt:" << s << endl;
+	}									       
 	encoding_map["iso8859-1"] = QTextCodec::codecForName("ISO 8859-1");
 	encoding_map["iso8859-2"] = QTextCodec::codecForName("ISO 8859-2");
 	encoding_map["iso8859-3"] = QTextCodec::codecForName("ISO 8859-3");
@@ -95,6 +97,25 @@ void initEncodings()
 	encoding_map["pt154"] = 0;
 
 	// There are lots more codecs in Qt too ...
+	
+	// when no document open
+	for (Languages::const_iterator it=languages.begin(); it != languages.end(); ++it) {
+		lyxerr << it->second.code() << ":" << it->second.encodingStr() << ":" << it->second.encoding() << endl;
+		if (it->second.code() == s)
+			{
+				s = it->second.encodingStr();
+				break;
+			}
+	}
+	lyxerr << "default encoding = " << s << endl;
+	QTextCodec * defaultCodec = encoding_map[s];
+	encoding_map[""] = defaultCodec;
+
+	QTextCodec::setCodecForCStrings(defaultCodec);
+
+	lyxerr << "system locale: " << QTextCodec::locale() << endl;
+	lyxerr << " setting cstring locale to: " << defaultCodec->name() << endl;
+
 }
 
 
Index: QRef.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QRef.C,v
retrieving revision 1.40
diff -u -p -r1.40 QRef.C
--- QRef.C	12 May 2005 23:12:43 -0000	1.40
+++ QRef.C	15 Jul 2005 23:04:03 -0000
@@ -68,9 +68,9 @@ void QRef::update_contents()
 
 	int orig_type = dialog_->typeCO->currentItem();
 
-	dialog_->referenceED->setText(toqstr(params.getContents()));
+	dialog_->referenceED->setText((params.getContents()));
 
-	dialog_->nameED->setText(toqstr(params.getOptions()));
+	dialog_->nameED->setText((params.getOptions()));
 	dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
 
 	// restore type settings for new insets
@@ -89,7 +89,7 @@ void QRef::update_contents()
 	vector<string> const buffers = controller().getBufferList();
 	for (vector<string>::const_iterator it = buffers.begin();
 		it != buffers.end(); ++it) {
-		dialog_->bufferCO->insertItem(toqstr(*it));
+		dialog_->bufferCO->insertItem((*it));
 	}
 	// restore the buffer combo setting for new insets
 	if (params.getContents().empty() && restored_buffer_ != -1
@@ -107,8 +107,8 @@ void QRef::apply()
 	InsetCommandParams & params = controller().params();
 
 	params.setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
-	params.setContents(fromqstr(dialog_->referenceED->text()));
-	params.setOptions(fromqstr(dialog_->nameED->text()));
+	params.setContents((dialog_->referenceED->text()));
+	params.setOptions((dialog_->nameED->text()));
 
 	restored_buffer_ = dialog_->bufferCO->currentItem();
 }
@@ -148,7 +148,7 @@ void QRef::setGotoRef()
 
 void QRef::gotoRef()
 {
-	string ref(fromqstr(dialog_->referenceED->text()));
+	string ref((const char *)(dialog_->referenceED->text()));
 
 	if (at_ref_) {
 		// go back
@@ -181,7 +181,7 @@ void QRef::redoRefs()
 
 	for (std::vector<string>::const_iterator iter = refs_.begin();
 		iter != refs_.end(); ++iter) {
-		dialog_->refsLB->insertItem(toqstr(*iter));
+		dialog_->refsLB->insertItem((*iter));
 	}
 
 	if (sort_)
Index: QURL.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QURL.C,v
retrieving revision 1.28
diff -u -p -r1.28 QURL.C
--- QURL.C	12 May 2005 23:12:43 -0000	1.28
+++ QURL.C	15 Jul 2005 23:04:03 -0000
@@ -51,8 +51,8 @@ void QURL::update_contents()
 {
 	InsetCommandParams const & params = controller().params();
 
-	dialog_->urlED->setText(toqstr(params.getContents()));
-	dialog_->nameED->setText(toqstr(params.getOptions()));
+	dialog_->urlED->setText((params.getContents()));
+	dialog_->nameED->setText((params.getOptions()));
 	dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
 
 	bc().valid(isValid());
@@ -63,8 +63,8 @@ void QURL::apply()
 {
 	InsetCommandParams & params = controller().params();
 
-	params.setContents(fromqstr(dialog_->urlED->text()));
-	params.setOptions(fromqstr(dialog_->nameED->text()));
+	params.setContents((dialog_->urlED->text()));
+	params.setOptions((dialog_->nameED->text()));
 
 	if (dialog_->hyperlinkCB->isChecked())
 		params.setCmdName("htmlurl");

Reply via email to