Am Freitag, 8. Dezember 2006 18:28 schrieb Andre Poenitz:

> [I am doing Windows installers right now. Far from funny to say the
> least, and a complete waste of time as far as I am concerned.  One
> learns thing one never wanted to know of. Four weeks to get the
> graphical equivalent of 'rpm -i *.rpm' - without dependency tracking of
> course... And as a side note: I ended up using 'Windows Installer XML',
> not NSIS. This seems to get the most predictable results. Of course
> 'most predictable' does not mean 'predictable' at all...]

I really don't envy you ;-)

> Back to LyX/Qt. I had a sort of mental blockade earlier when I
> associated 'using the same library in frontend and backend' with
> 'blurring the line between frontend and backend'. Just because we use
> something in the frontend can't hardly outlaw its use in the backend if
> it is suited there as well.

Agreed.

> > > > Coincidentally I am seriously thinking to use QFile::encodeName
> > > > for the implementation of FileName::toFilesystemEncoding, because
> > > > it does exactly 
> > > > what is needed.
> > > 
> > > The whole file name business is pretty much reinventing the wheel,
> > > and so is the session stuff and preference management.  Same goes
> > > for external processes when I think about it, but that does not seem
> > > to suck much resources nowadays...
> > 
> > Now you ignore the fact that all this stuff (except sessions) exists
> > already from the multiple-frontend times, so I don't see much
> > reinventing the wheel here.
> 
> Well, there was work on sessions. Seems to work now, but it took a while
> to get right and it sucked not only resources from the person actually
> working on it. I doubt that a QSetting based solution ever would have
> led to a stage where _I_ can't even start up LyX because of a courrupted
> settings file.

I agree, and I explicitly excluded the sessions stuff from the list of 
existing code above.

> > I don't consider introducing the FileName
> > class reinventing the wheel either, since it only uses existing code.
> 
> And this code is made up of a third party library plus quite a bit of
> our own glue code which needs to be maintained and also requires
> knowledge about specific platforms.

There is no filename related platform knowledge in our code except in 
os::internal_path/os::external_path. And maintenance cost is close to 
zero, this code is old and works (except for getFormatFromContents, but 
that should be replaced by a mime-based soltuion anyway).

> > The difficult part was the correct conversion from string, considering
> > relative and absolute names.
> 
> And that we could get by using a third party library without glue code
> of our own.

No third party library could have cleaned up the mixture of relative and 
absolute path names, where relative could be relative to a dozen different 
directories. This task had to be done by hand, by examining the current 
directory.
Of course I could simply have replaced all filename strings by a QFileInfo 
without caring about relative/absolute paths, but that was not my goal, 
because I find it really confusing to mix relative and absolute paths if 
you have many possible base paths. At work I have some utilities that 
don't cxare at all about relative/absolute paths, and that works well, but 
these utilities never change their working directory, so it is always 
clear what file is meant.

> And note: It would have worked correctly immediately on the 
> Mac, too. Instead we are guessing at how different systems encode their
> filenames ourselves.

No, we don't do that. Yes, it took some time to find out what is required, 
but the result is that I simply used QFile::encodeName:

string const FileName::toFilesystemEncoding() const
{
        QByteArray const encoded = QFile::encodeName(toqstr(name_));
        return string(encoded.begin(), encoded.end());
}

In fact the guessing is in qt, if you look at the implementation. Of course 
the first thing I did when I searched for a solution to the non-ascii 
filename problem was to look in the qt documentation. Unfortunately it was 
not clear at all from the documentation that QFile::encodeName is the 
correct thing to do.

Anyway, while I certainly would use QFileInfo for a new implementation I 
don't think that now is the right time to switch, so I'll stop this 
discussion here.

> I'd go even so far to consider 'support Qt' as 'a library on par with
> boost or libz'. I.e. even non-Qt frontends would not be required to
> replace it.

Certainly not required, but I can't imagine a case where a non-qt frontend 
using QtCore would make sense. I already find it perverse that pkgconfig 
pulls in libglib (and even more gtk stuff depending on qt configuration) 
for qt4.

I updated the patch and made it cleaner. Now libQtCore is considered a 
support library that can be used like boost or libz. If anybody does not 
like this, speak up, but a simple "no" is not enough, I want to see a 
proposal for a different implementation of the 
FileName::toFilesystemEncoding, from_local8bit and to_local8bit functions 
that works as well as this one does.
If I don't get objections this will go in on tuesday (I'll allow some time 
because this is also a political decision).


Georg
Index: src/frontends/qt4/qt_helpers.C
===================================================================
--- src/frontends/qt4/qt_helpers.C	(Revision 16214)
+++ src/frontends/qt4/qt_helpers.C	(Arbeitskopie)
@@ -31,10 +31,7 @@
 
 namespace lyx {
 
-
-using lyx::support::isStrDbl;
-using lyx::char_type;
-using lyx::docstring;
+using support::isStrDbl;
 
 using std::vector;
 using std::make_pair;
@@ -111,36 +108,6 @@ void lengthToWidgets(QLineEdit * input, 
 }
 
 
-#if QT_VERSION < 0x040200
-// We use QString::fromUcs4 in Qt 4.2 and higher
-QString const toqstr(docstring const & str)
-{
-	QString s;
-	int i = static_cast<int>(str.size()); 
-	s.resize(i);
-	for (; --i >= 0;)
-		s[i] = ucs4_to_qchar(str[i]);
-	return s;
-}
-#endif
-
-
-docstring const qstring_to_ucs4(QString const & qstr)
-{
-#if QT_VERSION >= 0x040200
-	QVector<uint> const ucs4 = qstr.toUcs4();
-	return docstring(ucs4.begin(), ucs4.end());
-#else
-	// This does not properly convert surrogate pairs
-	int const ls = qstr.size();
-	docstring ucs4;
-	for (int i = 0; i < ls; ++i)
-		ucs4 += static_cast<char_type>(qstr[i].unicode());
-	return ucs4;
-#endif
-}
-
-
 QString const qt_(char const * str, const char *)
 {
 	return toqstr(_(str));
@@ -153,12 +120,6 @@ QString const qt_(string const & str)
 }
 
 
-string const fromqstr(QString const & str)
-{
-	return str.isEmpty() ? string() : string(str.toUtf8());
-}
-
-
 docstring const formatted(docstring const & text, int w)
 {
 	docstring sout;
Index: src/frontends/qt4/qt_helpers.h
===================================================================
--- src/frontends/qt4/qt_helpers.h	(Revision 16214)
+++ src/frontends/qt4/qt_helpers.h	(Arbeitskopie)
@@ -14,13 +14,11 @@
 
 #include "lyxlength.h"
 #include "support/docstring.h"
+#include "support/qstring_helpers.h"
 
-#include <QChar>
 #include <QString>
 
-#include <vector>
 #include <utility>
-#include <boost/assert.hpp>
 
 class QComboBox;
 class QLineEdit;
@@ -47,103 +45,6 @@ docstring const formatted(docstring cons
 
 
 /**
- * toqstr - convert a UTF8 encoded char * into a QString
- *
- * This should not be used, since all possibly non-ASCII stuff should be
- * stored in a docstring.
- */
-inline QString const toqstr(char const * str)
-{
-	return QString::fromUtf8(str);
-}
-
-
-/**
- * toqstr - convert a UTF8 encoded std::string into a QString
- *
- * This should not be used, since all possibly non-ASCII stuff should be
- * stored in a docstring.
- */
-inline QString const toqstr(std::string const & str)
-{
-	return toqstr(str.c_str());
-}
-
-
-/**
- * Convert a QChar into a UCS4 character.
- * This is a hack (it does only make sense for the common part of the UCS4
- * and UTF16 encodings) and should not be used.
- * This does only exist because of performance reasons (a real conversion
- * using iconv is too slow on windows).
- */
-inline char_type const qchar_to_ucs4(QChar const & qchar)
-{
-	return static_cast<char_type>(qchar.unicode());
-}
-
-
-/**
- * Convert a UCS4 character into a QChar.
- * This is a hack (it does only make sense for the common part of the UCS4
- * and UTF16 encodings) and should not be used.
- * This does only exist because of performance reasons (a real conversion
- * using iconv is too slow on windows).
- */
-inline QChar const ucs4_to_qchar(char_type const ucs4)
-{
-	// FIXME: The following cast is not a real conversion but it work
-	// for the ucs2 subrange of unicode. Instead of an assertion we should
-	// return some special characters that indicates that its display is
-	// not supported.
-	BOOST_ASSERT(ucs4 < 65536);
-	return QChar(static_cast<unsigned short>(ucs4));
-}
-
-
-/**
- * toqstr - convert a UCS4 encoded docstring into a QString
- *
- * This is the preferred method of converting anything that possibly
- * contains non-ASCII stuff to QString.
- */
-#if QT_VERSION >= 0x040200
-inline QString const toqstr(docstring const & ucs4)
-{
-	// If possible we let qt do the work, since this version does not
-	// need to be superfast.
-	return QString::fromUcs4(reinterpret_cast<uint const *>(ucs4.data()), ucs4.length());
-}
-#else
-QString const toqstr(docstring const & ucs4);
-#endif
-
-
-/**
- * ucs4_to_qstring - convert a UCS4 encoded char_type * into a QString
- *
- * This is a hack for the painter and font metrics and should not be used
- * elsewhere. Since it uses ucs4_to_qchar it has the same limitations.
- */
-inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
-{
-	int i = static_cast<int>(ls);
-	s.resize(i);
-	for (; --i >= 0;)
-		s[i] = ucs4_to_qchar(str[i]);
-}
-
-
-/**
- * qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
- *
- * This is the preferred method of converting anything that possibly
- * contains non-ASCII stuff to docstring.
- */
-docstring const qstring_to_ucs4(QString const & qstr);
-
-
-/**
  * qt_ - i18nize string and convert to QString
  *
  * Use this in qt4/ instead of _()
@@ -158,15 +59,6 @@ QString const qt_(char const * str, cons
  */
 QString const qt_(std::string const & str);
 
-
-/**
- * fromqstr - convert a QString into a UTF8 encoded std::string
- *
- * This should not be used except for output to lyxerr, since all possibly
- * non-ASCII stuff should be stored in a docstring.
- */
-std::string const fromqstr(QString const & str);
-
 } // namespace lyx
 
 #endif // QTHELPERS_H
Index: src/support/qstring_helpers.C
===================================================================
--- src/support/qstring_helpers.C	(Revision 16214)
+++ src/support/qstring_helpers.C	(Arbeitskopie)
@@ -1,5 +1,5 @@
 /**
- * \file qt_helpers.C
+ * \file qstring_helpers.C
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -11,105 +11,14 @@
 
 #include <config.h>
 
-#include "lengthcombo.h"
-#include "qt_helpers.h"
+#include "qstring_helpers.h"
 
-#include "lengthcommon.h"
-#include "gettext.h"
-
-#include "support/lstrings.h"
-#include "support/convert.h"
-
-#include "debug.h"
-
-#include <QComboBox>
-#include <qlineedit.h>
-#include <qtextcodec.h>
-
-#include <algorithm>
+#include <QVector>
 
 
 namespace lyx {
 
-
-using lyx::support::isStrDbl;
-using lyx::char_type;
-using lyx::docstring;
-
-using std::vector;
-using std::make_pair;
 using std::string;
-using std::pair;
-using std::endl;
-
-
-string makeFontName(string const & family, string const & foundry)
-{
-	if (foundry.empty())
-		return family;
-	return family + " [" + foundry + ']';
-}
-
-
-pair<string, string> parseFontName(string const & name)
-{
-	string::size_type const idx = name.find('[');
-	if (idx == string::npos || idx == 0)
-		return make_pair(name, string());
-	return make_pair(name.substr(0, idx - 1),
-			 name.substr(idx + 1, name.size() - idx - 2));
-}
-
-
-string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
-{
-	QString const length = input->text();
-	if (length.isEmpty())
-		return string();
-
-	// Don't return unit-from-choice if the input(field) contains a unit
-	if (isValidGlueLength(fromqstr(length)))
-		return fromqstr(length);
-
-	LyXLength::UNIT const unit = combo->currentLengthItem();
-
-	return LyXLength(length.toDouble(), unit).asString();
-}
-
-
-LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo)
-{
-	QString const length = input->text();
-	if (length.isEmpty())
-		return LyXLength();
-
-	// don't return unit-from-choice if the input(field) contains a unit
-	if (isValidGlueLength(fromqstr(length)))
-		return LyXLength(fromqstr(length));
-
-	LyXLength::UNIT const unit = unitFromString(fromqstr(combo->currentText()));
-
-	return LyXLength(length.toDouble(), unit);
-}
-
-
-void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
-	string const & len, LyXLength::UNIT defaultUnit)
-{
-	if (len.empty()) {
-		// no length (UNIT_NONE)
-		combo->setCurrentItem(defaultUnit);
-		input->setText("");
-	} else if (!isValidLength(len) && !isStrDbl(len)) {
-		// use input field only for gluelengths
-		combo->setCurrentItem(defaultUnit);
-		input->setText(toqstr(len));
-	} else {
-		combo->setCurrentItem(LyXLength(len).unit());
-		input->setText(toqstr(convert<string>(LyXLength(len).value())));
-	}
-}
-
 
 #if QT_VERSION < 0x040200
 // We use QString::fromUcs4 in Qt 4.2 and higher
@@ -141,81 +50,9 @@ docstring const qstring_to_ucs4(QString 
 }
 
 
-QString const qt_(char const * str, const char *)
-{
-	return toqstr(_(str));
-}
-
-
-QString const qt_(string const & str)
-{
-	return toqstr(_(str));
-}
-
-
 string const fromqstr(QString const & str)
 {
 	return str.isEmpty() ? string() : string(str.toUtf8());
 }
 
-
-docstring const formatted(docstring const & text, int w)
-{
-	docstring sout;
-
-	if (text.empty())
-		return sout;
-
-	docstring::size_type curpos = 0;
-	docstring line;
-
-	for (;;) {
-		docstring::size_type const nxtpos1 = text.find(' ',  curpos);
-		docstring::size_type const nxtpos2 = text.find('\n', curpos);
-		docstring::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
-
-		docstring const word =
-			nxtpos == docstring::npos ?
-			text.substr(curpos) :
-			text.substr(curpos, nxtpos - curpos);
-
-		bool const newline = (nxtpos2 != docstring::npos &&
-				      nxtpos2 < nxtpos1);
-
-		docstring const line_plus_word =
-			line.empty() ? word : line + lyx::char_type(' ') + word;
-
-		// FIXME: make w be size_t
-		if (int(line_plus_word.length()) >= w) {
-			sout += line + lyx::char_type('\n');
-			if (newline) {
-				sout += word + lyx::char_type('\n');
-				line.erase();
-			} else {
-				line = word;
-			}
-
-		} else if (newline) {
-			sout += line_plus_word + lyx::char_type('\n');
-			line.erase();
-
-		} else {
-			if (!line.empty())
-				line += lyx::char_type(' ');
-			line += word;
-		}
-
-		if (nxtpos == docstring::npos) {
-			if (!line.empty())
-				sout += line;
-			break;
-		}
-
-		curpos = nxtpos + 1;
-	}
-
-	return sout;
-}
-
-
 } // namespace lyx
Index: src/support/docstring.C
===================================================================
--- src/support/docstring.C	(Revision 16214)
+++ src/support/docstring.C	(Arbeitskopie)
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "docstring.h"
+#include "qstring_helpers.h"
 #include "unicode.h"
 
 #include <locale>
@@ -91,6 +92,19 @@ std::string const to_utf8(docstring cons
 }
 
 
+docstring const from_local8bit(std::string const & s)
+{
+	return qstring_to_ucs4(QString::fromLocal8Bit(s.data(), s.length()));
+}
+
+
+std::string const to_local8bit(docstring const & s)
+{
+	QByteArray const local = toqstr(s).toLocal8Bit();
+	return std::string(local.begin(), local.end());
+}
+
+
 bool operator==(lyx::docstring const & l, char const * r)
 {
 	int const len = l.length();
Index: src/support/qstring_helpers.h
===================================================================
--- src/support/qstring_helpers.h	(Revision 16214)
+++ src/support/qstring_helpers.h	(Arbeitskopie)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file qt_helpers.h
+ * \file qstring_helpers.h
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -9,43 +9,18 @@
  * Full author contact details are available in file CREDITS.
  */
 
-#ifndef QTHELPERS_H
-#define QTHELPERS_H
+#ifndef QSTRING_HELPERS_H
+#define QSTRING_HELPERS_H
 
-#include "lyxlength.h"
 #include "support/docstring.h"
 
 #include <QChar>
 #include <QString>
 
-#include <vector>
-#include <utility>
 #include <boost/assert.hpp>
 
-class QComboBox;
-class QLineEdit;
-
-class LengthCombo;
-
 namespace lyx {
 
-std::string makeFontName(std::string const & family, std::string const & foundry);
-
-std::pair<std::string,std::string> parseFontName(std::string const & name);
-
-/// method to get a LyXLength from widgets (LengthCombo)
-std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
-/// method to get a LyXLength from widgets (QComboBox)
-LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo);
-
-/// method to set widgets from a LyXLength
-void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
-	std::string const & len, LyXLength::UNIT default_unit);
-
-/// format a string to the given width
-docstring const formatted(docstring const & text, int w = 80);
-
-
 /**
  * toqstr - convert a UTF8 encoded char * into a QString
  *
@@ -144,22 +119,6 @@ docstring const qstring_to_ucs4(QString 
 
 
 /**
- * qt_ - i18nize string and convert to QString
- *
- * Use this in qt4/ instead of _()
- */
-QString const qt_(char const * str, const char * comment = 0);
-
-
-/**
- * qt_ - i18nize string and convert to QString
- *
- * Use this in qt4/ instead of _()
- */
-QString const qt_(std::string const & str);
-
-
-/**
  * fromqstr - convert a QString into a UTF8 encoded std::string
  *
  * This should not be used except for output to lyxerr, since all possibly
@@ -169,4 +128,4 @@ std::string const fromqstr(QString const
 
 } // namespace lyx
 
-#endif // QTHELPERS_H
+#endif // QSTRING_HELPERS_H
Index: src/support/filename.C
===================================================================
--- src/support/filename.C	(Revision 16214)
+++ src/support/filename.C	(Arbeitskopie)
@@ -14,6 +14,9 @@
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/os.h"
+#include "support/qstring_helpers.h"
+
+#include <QFile>
 
 #include <boost/assert.hpp>
 
@@ -62,8 +65,8 @@ void FileName::erase()
 
 string const FileName::toFilesystemEncoding() const
 {
-	// FIXME UNICODE: correct encoding not implemented yet
-	return name_;
+	QByteArray const encoded = QFile::encodeName(toqstr(name_));
+	return string(encoded.begin(), encoded.end());
 }
 
 
Index: src/support/docstring.h
===================================================================
--- src/support/docstring.h	(Revision 16214)
+++ src/support/docstring.h	(Arbeitskopie)
@@ -37,6 +37,12 @@ docstring const from_utf8(std::string co
 /// Creates a UTF8 string from a docstring. This should go eventually.
 std::string const to_utf8(docstring const &);
 
+/// convert \p s from the encoding of the locale to ucs4.
+docstring const from_local8bit(std::string const & s);
+
+/// convert \p s from ucs4 to the encoding of the locale.
+std::string const to_local8bit(docstring const & s);
+
 /// Compare a docstring with a C string of ASCII characters
 bool operator==(lyx::docstring const &, char const *);
 
Index: src/support/Makefile.am
===================================================================
--- src/support/Makefile.am	(Revision 16214)
+++ src/support/Makefile.am	(Arbeitskopie)
@@ -9,11 +9,13 @@ EXTRA_DIST = package.C.in pch.h \
 
 noinst_LTLIBRARIES = libsupport.la
 
-libsupport_la_LIBADD = $(LIBSHLWAPI)
+libsupport_la_LIBADD = $(LIBSHLWAPI) $(QT4_CORE_LIB)
+libsupport_la_LDFLAGS = $(QT4_CORE_LDFLAGS)
 
 BUILT_SOURCES = $(PCH_FILE) package.C
 
 AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
+AM_CPPFLAGS += $(QT4_CPPFLAGS) $(QT4_CORE_INCLUDES)
 
 libsupport_la_SOURCES = \
 	FileMonitor.h \
@@ -67,6 +69,8 @@ libsupport_la_SOURCES = \
 	path.h \
 	package.C \
 	package.h \
+	qstring_helpers.C \
+	qstring_helpers.h \
 	rename.C \
 	socktools.C \
 	socktools.h \
Index: src/client/client.C
===================================================================
--- src/client/client.C	(Revision 16214)
+++ src/client/client.C	(Arbeitskopie)
@@ -335,7 +335,7 @@ void LyXDataSocket::writeln(string const
 // Class CmdLineParser -------------------------------------------------------
 class CmdLineParser {
 public:
-	typedef int (*optfunc)(vector<char *> const & args);
+	typedef int (*optfunc)(vector<docstring> const & args);
 	std::map<string, optfunc> helper;
 	std::map<string, bool> isset;
 	bool parse(int, char * []);
@@ -347,12 +347,12 @@ bool CmdLineParser::parse(int argc, char
 {
 	int opt = 1;
 	while (opt < argc) {
-		vector<char *> args;
+		vector<docstring> args;
 		if (helper[argv[opt]]) {
 			isset[argv[opt]] = true;
 			int arg = opt + 1;
 			while ((arg < argc) && (!helper[argv[arg]])) {
-				args.push_back(argv[arg]);
+				args.push_back(from_local8bit(argv[arg]));
 				++arg;
 			}
 			int taken = helper[argv[opt]](args);
@@ -407,16 +407,16 @@ void usage()
 }
 
 
-int h(vector<char *> const &)
+int h(vector<docstring> const &)
 {
 	usage();
 	exit(0);
 }
 
 
-string clientName(support::itoa(::getppid()) + ">" + support::itoa(::getpid()));
+docstring clientName(from_ascii(support::itoa(::getppid()) + ">" + support::itoa(::getpid())));
 
-int n(vector<char *> const & arg)
+int n(vector<docstring> const & arg)
 {
 	if (arg.size() < 1) {
 		cerr << "lyxclient: The option -n requires 1 argument."
@@ -428,10 +428,10 @@ int n(vector<char *> const & arg)
 }
 
 
-string singleCommand;
+docstring singleCommand;
 
 
-int c(vector<char *> const & arg)
+int c(vector<docstring> const & arg)
 {
 	if (arg.size() < 1) {
 		cerr << "lyxclient: The option -c requires 1 argument."
@@ -443,7 +443,7 @@ int c(vector<char *> const & arg)
 }
 
 
-int g(vector<char *> const & arg)
+int g(vector<docstring> const & arg)
 {
 	if (arg.size() < 2) {
 		cerr << "lyxclient: The option -g requires 2 arguments."
@@ -451,17 +451,17 @@ int g(vector<char *> const & arg)
 		return -1;
 	}
 	singleCommand = "LYXCMD:server-goto-file-row "
-		+ string(arg[0]) + ' '
-		+ string(arg[1]);
+		+ arg[0] + ' '
+		+ arg[1];
 	return 2;
 }
 
 
-// 0 if LYXSOCKET is not set in the environment
-char * serverAddress = getenv("LYXSOCKET");
+// empty if LYXSOCKET is not set in the environment
+docstring serverAddress;
 
 
-int a(vector<char *> const & arg)
+int a(vector<docstring> const & arg)
 {
 	if (arg.size() < 1) {
 		cerr << "lyxclient: The option -a requires 1 argument."
@@ -474,10 +474,10 @@ int a(vector<char *> const & arg)
 }
 
 
-string mainTmp("/tmp");
+docstring mainTmp(from_ascii("/tmp"));
 
 
-int t(vector<char *> const & arg)
+int t(vector<docstring> const & arg)
 {
 	if (arg.size() < 1) {
 		cerr << "lyxclient: The option -t requires 1 argument."
@@ -492,14 +492,14 @@ int t(vector<char *> const & arg)
 string serverPid; // Init to empty string
 
 
-int p(vector<char *> const & arg)
+int p(vector<docstring> const & arg)
 {
 	if (arg.size() < 1) {
 		cerr << "lyxclient: The option -p requires 1 argument."
 		     << endl;
 		return -1;
 	}
-	serverPid = arg[0];
+	serverPid = to_ascii(arg[0]);
 	return 1;
 }
 
@@ -514,6 +514,10 @@ int main(int argc, char * argv[])
 	using namespace lyx;
 	lyxerr.rdbuf(cerr.rdbuf());
 
+	char const * const lyxsocket = getenv("LYXSOCKET");
+	if (lyxsocket)
+		cmdline::serverAddress = from_local8bit(lyxsocket);
+
 	CmdLineParser args;
 	args.helper["-h"] = cmdline::h;
 	args.helper["-c"] = cmdline::c;
@@ -533,17 +537,17 @@ int main(int argc, char * argv[])
 
 	scoped_ptr<LyXDataSocket> server;
 
-	if (cmdline::serverAddress) {
-		server.reset(new LyXDataSocket(cmdline::serverAddress));
+	if (!cmdline::serverAddress.empty()) {
+		server.reset(new LyXDataSocket(to_utf8(cmdline::serverAddress)));
 		if (!server->connected()) {
 			cerr << "lyxclient: " << "Could not connect to "
-			     << cmdline::serverAddress << endl;
+			     << to_utf8(cmdline::serverAddress) << endl;
 			return EXIT_FAILURE;
 		}
 	} else {
 		// We have to look for an address.
 		// serverPid can be empty.
-		vector<fs::path> addrs = support::lyxSockets(cmdline::mainTmp, cmdline::serverPid);
+		vector<fs::path> addrs = support::lyxSockets(to_utf8(cmdline::mainTmp), cmdline::serverPid);
 		vector<fs::path>::const_iterator addr = addrs.begin();
 		vector<fs::path>::const_iterator end = addrs.end();
 		for (; addr != end; ++addr) {
@@ -570,7 +574,7 @@ int main(int argc, char * argv[])
 	string answer;
 
 	// Send greeting
-	server->writeln("HELLO:" + cmdline::clientName);
+	server->writeln("HELLO:" + to_utf8(cmdline::clientName));
 	// wait at most 2 seconds until server responds
 	iowatch.wait(2.0);
 	if (iowatch.isset(serverfd) && server->readln(answer)) {
@@ -585,7 +589,7 @@ int main(int argc, char * argv[])
 	}
 
 	if (args.isset["-g"] || args.isset["-c"]) {
-		server->writeln(cmdline::singleCommand);
+		server->writeln(to_utf8(cmdline::singleCommand));
 		iowatch.wait(2.0);
 		if (iowatch.isset(serverfd) && server->readln(answer)) {
 			cout << answer;
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C	(Revision 16214)
+++ src/lyx_main.C	(Arbeitskopie)
@@ -332,8 +332,9 @@ int LyX::exec(int & argc, char * argv[])
 	// we need to parse for "-dbg" and "-help"
 	easyParse(argc, argv);
 
-	support::init_package(argv[0], cl_system_support, cl_user_support,
-				   support::top_build_dir_is_one_level_up);
+	support::init_package(to_utf8(from_local8bit(argv[0])),
+	                      cl_system_support, cl_user_support,
+	                      support::top_build_dir_is_one_level_up);
 
 	if (!use_gui) {
 		// FIXME: create a ConsoleApplication
@@ -481,7 +482,8 @@ int LyX::init(int & argc, char * argv[])
 	for (int argi = argc - 1; argi >= 1; --argi) {
 		// get absolute path of file and add ".lyx" to
 		// the filename if necessary
-		pimpl_->files_to_load_.push_back(fileSearch(string(), os::internal_path(argv[argi]), "lyx"));
+		pimpl_->files_to_load_.push_back(fileSearch(string(),
+			os::internal_path(to_utf8(from_local8bit(argv[argi]))), "lyx"));
 	}
 
 	if (first_start)
@@ -1333,8 +1335,8 @@ void LyX::easyParse(int & argc, char * a
 		if (it == cmdmap.end())
 			continue;
 
-		string arg((i + 1 < argc) ? argv[i + 1] : "");
-		string arg2((i + 2 < argc) ? argv[i + 2] : "");
+		string const arg((i + 1 < argc) ? to_utf8(from_local8bit(argv[i + 1])) : string());
+		string const arg2((i + 2 < argc) ? to_utf8(from_local8bit(argv[i + 2])) : string());
 
 		int const remove = 1 + it->second(arg, arg2);
 
Index: development/scons/scons_manifest.py
===================================================================
--- development/scons/scons_manifest.py	(Revision 16214)
+++ development/scons/scons_manifest.py	(Arbeitskopie)
@@ -117,6 +117,7 @@ src_support_header_files = Split('''
     os_win32.h
     package.h
     path.h
+    qstring_helpers.h
     socktools.h
     std_istream.h
     std_ostream.h
@@ -155,6 +156,7 @@ src_support_files = Split('''
     os.C
     package.C
     path.C
+    qstring_helpers.C
     rename.C
     socktools.C
     systemcall.C
Index: config/qt4.m4
===================================================================
--- config/qt4.m4	(Revision 16214)
+++ config/qt4.m4	(Arbeitskopie)
@@ -28,6 +28,14 @@ AC_DEFUN([QT4_CHECK_COMPILE],
 		AC_LANG_CPLUSPLUS
 		SAVE_CXXFLAGS=$CXXFLAGS
 		CXXFLAGS="$CXXFLAGS $QT4_INCLUDES $QT4_LDFLAGS"
+		for libname in '-lQtCore -lQtCore4'
+		do
+			QT4_TRY_LINK($libname)
+			if test -n "$qt4_cv_libname"; then
+				QT4_CORE_LIB="$qt4_cv_libname"
+				break;
+			fi
+		done
 		for libname in '-lQtCore -lQtGui' \
 		               '-lQtCore4 -lQtGui4'
 		do
@@ -142,6 +150,15 @@ AC_DEFUN([QT4_DO_PKG_CONFIG],
 	  PKG_CONFIG_PATH=$qt4_cv_dir/lib:$PKG_CONFIG_PATH
 	  export PKG_CONFIG_PATH
 	fi
+	PKG_CHECK_MODULES(QT4_CORE, QtCore)
+	if test "$pkg_failed" == "no" ; then
+		QT4_CORE_INCLUDES=$QT4_CORE_CFLAGS
+		AC_SUBST(QT4_CORE_INCLUDES)
+		QT4_CORE_LDFLAGS=`$PKG_CONFIG --libs-only-L QtCore`
+		AC_SUBST(QT4_CORE_LDFLAGS)
+		QT4_CORE_LIB=`$PKG_CONFIG --libs-only-l QtCore`
+		AC_SUBST(QT4_CORE_LIB)
+	fi
 	PKG_CHECK_MODULES(QT4_FRONTEND, QtCore QtGui)
 	if test "$pkg_failed" == "no" ; then
 		QT4_INCLUDES=$QT4_FRONTEND_CFLAGS
@@ -153,8 +170,6 @@ AC_DEFUN([QT4_DO_PKG_CONFIG],
 		AC_SUBST(QT4_VERSION)
 		QT4_LIB=`$PKG_CONFIG --libs-only-l QtCore QtGui`
 		AC_SUBST(QT4_LIB)
-	else
-		QT4_DO_MANUAL_CONFIG
 	fi
 	PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
 ])
@@ -164,22 +179,29 @@ AC_DEFUN([QT4_DO_MANUAL_CONFIG],
 	dnl flags for compilation
 	QT4_INCLUDES=
 	QT4_LDFLAGS=
+	QT4_CORE_INCLUDES=
+	QT4_CORE_LDFLAGS=
 	if test -n "$qt4_cv_includes"; then
 		QT4_INCLUDES="-I$qt4_cv_includes"
 		for i in Qt QtCore QtGui; do
 			QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i"
 		done
+		QT4_CORE_INCLUDES="-I$qt4_cv_includes -I$qt4_cv_includes/QtCore"
 	fi
 	if test -n "$qt4_cv_libraries"; then
 		QT4_LDFLAGS="-L$qt4_cv_libraries"
+		QT4_CORE_LDFLAGS="-L$qt4_cv_libraries"
 	fi
 	AC_SUBST(QT4_INCLUDES)
+	AC_SUBST(QT4_CORE_INCLUDES)
 	AC_SUBST(QT4_LDFLAGS)
+	AC_SUBST(QT4_CORE_LDFLAGS)
 
 	QT4_CHECK_COMPILE
 
 	QT4_LIB=$qt4_cv_libname;
 	AC_SUBST(QT4_LIB)
+	AC_SUBST(QT4_CORE_LIB)
 
 	if test -n "$qt4_cv_libname"; then
 		QT4_GET_VERSION

Reply via email to