From: Davor Ocelic <docelic@spinlocksolutions.com>
To: KDE bindings for other programming languages <kde-bindings@kde.org>

Oi folks,

Attached is a patch that applies to current SVN HEAD (rev. 898663, Dec 18, 2008)
and enables you to build qtruby on Ruby 1.9.

Update: applies to SVN HEAD of Feb 1, 2009.

***

UPDATE: as of CVS HEAD Feb 2, 2009, QtRuby builds for both Ruby 1.8 and
Ruby 1.9 out of the box, and this patch is no longer needed. The
simple Ruby 1.9 build tweaks listed below still apply though.

***

Note that the patch also improves CMakeLists.txt.qtruby a bit, by making
the previous instructions more copy-paste friendly.

To build for Ruby 1.9, follow build instructions in CMakeLists.txt.qtruby. Just
keep in mind that the location of header files changed a little from 1.8
to 1.9, so simple tweak will be needed as follows:

1) Find your ruby 1.9's config.h. Example:
  /usr/local/ruby191p2/include/ruby-1.9.1/x86_64-linux/ruby/config.h

2) Symlink the file to ruby/config.h in the include path. Example:
  ln -sf /usr/local/ruby191p2/include/ruby-1.9.1/x86_64-linux/ruby/config.h \
	  /usr/local/ruby191p2/include/ruby-1.9.1/ruby/config.h

3) When running cmake, change -DRUBY_INCLUDE_PATH to suit 1.9 include
path instead of 1.8. Example:
  cmake .....                                                 \
	-DRUBY_INCLUDE_PATH=/usr/local/ruby191p2/include/ruby-1.9.1 \
	....

> From there, either I'll get a chance to adjust the patch
> for 1.8/1.9 compatibility so it can be committed to SVN, or someone else more
> familiar with the thing will be able to do it in 30 mins after seeing
> the patch.

The patch is not ready for commit to SVN as it builds for 1.9
unconditionally and breaks 1.8.

So as said, if someone else feels comfortable with making the attached
short patch working on both 1.8 and 1.9, please preempt me on the task.

Thanks Jan Dvorak (Mr Napalm) for providing initial qtruby-ruby 1.9
patches.

Regards,
-doc


Index: ruby/qtruby/src/handlers.cpp
===================================================================
--- ruby/qtruby/src/handlers.cpp	(revision 898652)
+++ ruby/qtruby/src/handlers.cpp	(working copy)
@@ -875,33 +875,23 @@
 	}
 }
 
-static const char * KCODE = 0;
 static QTextCodec *codec = 0;
 
-static void 
-init_codec() {
-	VALUE temp = rb_gv_get("$KCODE");
-	KCODE = StringValuePtr(temp);
-	if (qstrcmp(KCODE, "EUC") == 0) {
-		codec = QTextCodec::codecForName("eucJP");
-	} else if (qstrcmp(KCODE, "SJIS") == 0) {
-		codec = QTextCodec::codecForName("Shift-JIS");
-	}
-}
-
 QString* 
 qstringFromRString(VALUE rstring) {
-	if (KCODE == 0) {
-		init_codec();
-	}
-	
-	if (qstrcmp(KCODE, "UTF8") == 0)
+	VALUE encoding = rb_funcall(rstring, rb_intern("encoding"), 0);
+	encoding = rb_funcall(encoding, rb_intern("to_s"), 0);
+	const char * enc_s = RSTRING_PTR(encoding);
+
+	if (qstrcmp(enc_s, "UTF8") == 0)
 		return new QString(QString::fromUtf8(StringValuePtr(rstring), RSTRING_LEN(rstring)));
-	else if (qstrcmp(KCODE, "EUC") == 0)
+	else if (qstrcmp(enc_s, "EUC-JP") == 0) {
+		codec = QTextCodec::codecForName("eucJP");
 		return new QString(codec->toUnicode(StringValuePtr(rstring)));
-	else if (qstrcmp(KCODE, "SJIS") == 0)
+	}	else if (qstrcmp(enc_s, "Shift-JIS") == 0) {
+		codec = QTextCodec::codecForName("Shift-JIS");
 		return new QString(codec->toUnicode(StringValuePtr(rstring)));
-	else if(qstrcmp(KCODE, "NONE") == 0)
+	} else if(qstrcmp(enc_s, "ISO-8859-1") == 0 || qstrcmp(enc_s, "US-ASCII") == 0)
 		return new QString(QString::fromLatin1(StringValuePtr(rstring)));
 
 	return new QString(QString::fromLocal8Bit(StringValuePtr(rstring), RSTRING_LEN(rstring)));
@@ -914,20 +904,7 @@
 
 VALUE 
 rstringFromQString(QString * s) {
-	if (KCODE == 0) {
-		init_codec();
-	}
-	
-	if (qstrcmp(KCODE, "UTF8") == 0)
-		return rb_str_new2(s->toUtf8());
-	else if (qstrcmp(KCODE, "EUC") == 0)
-		return rb_str_new2(codec->fromUnicode(*s));
-	else if (qstrcmp(KCODE, "SJIS") == 0)
-		return rb_str_new2(codec->fromUnicode(*s));
-	else if (qstrcmp(KCODE, "NONE") == 0)
-		return rb_str_new2(s->toLatin1());
-	else
-		return rb_str_new2(s->toLocal8Bit());
+	return rb_str_new2(s->toUtf8());
 }
 
 VALUE
Index: ruby/qtruby/src/qtruby.cpp
===================================================================
--- ruby/qtruby/src/qtruby.cpp	(revision 898652)
+++ ruby/qtruby/src/qtruby.cpp	(working copy)
@@ -1365,7 +1365,7 @@
 		return Qfalse;
 	}
 
-	QLatin1String signalname(rb_id2name(rb_frame_last_func()));
+	QLatin1String signalname(rb_id2name(rb_frame_callee()));
 	VALUE metaObject_value = rb_funcall(qt_internal_module, rb_intern("getMetaObject"), 2, Qnil, self);
 
 	smokeruby_object *ometa = value_obj_info(metaObject_value);
Index: ruby/qtruby/src/marshall_types.cpp
===================================================================
--- ruby/qtruby/src/marshall_types.cpp	(revision 898652)
+++ ruby/qtruby/src/marshall_types.cpp	(working copy)
@@ -17,7 +17,7 @@
  ***************************************************************************/
 
 #include "marshall_types.h"
-#include <rubysig.h>
+#include <ruby/ruby.h>
 #include <smoke/qt_smoke.h>
 #include <QtDBus>
 
Index: CMakeLists.txt.qtruby
===================================================================
--- CMakeLists.txt.qtruby	(revision 898652)
+++ CMakeLists.txt.qtruby	(working copy)
@@ -1,50 +1,56 @@
 # Use this file to build a Qt only version of QtRuby.
-# 1. Copy this file to kdebindings/CMakeLists.txt
-# 2. Copy the following files to kdebindings/cmake/modules/:
-#      kdelibs/cmake/modules/FindQt4.cmake
-#      kdelibs/cmake/modules/FindRUBY.cmake
-#      kdelibs/cmake/modules/MacroOptionalFindPackage.cmake
-#      kdelibs/cmake/modules/MacroPushRequiredVars.cmake
-# 3. Build kdebindings with command like:
-#      cmake
-#        -DCMAKE_INSTALL_PREFIX=/opt/ruby1.8.7                          \
-#        -DRUBY_EXECUTABLE=/opt/ruby1.8.7/bin/ruby                      \
-#        -DRUBY_INCLUDE_PATH=/opt/ruby1.8.7/lib/ruby/1.8/i686-linux/    \
-#        -Wno-dev                                                       \
-#        -DENABLE_SMOKE=on                                              \
-#        -DENABLE_QTRUBY=on                                             \
-#        -DENABLE_QTWEBKIT_SMOKE=off                                    \
-#        -DENABLE_QTSCRIPT_SMOKE=off                                    \
-#        -DENABLE_QTUITOOLS_SMOKE=off                                   \
-#        -DENABLE_QTTEST_SMOKE=off                                      \
-#        -DENABLE_PHONON_SMOKE=off                                      \
-#        -DENABLE_QSCI_SMOKE=off                                        \
-#        -DENABLE_QWT_SMOKE=off                                         \
-#        -DENABLE_KDE_SMOKE=off                                         \
-#        -DENABLE_KDEVPLATFORM_SMOKE=off                                \
-#        -DENABLE_KHTML_SMOKE=off                                       \
-#        -DENABLE_KTEXTEDITOR_SMOKE=off                                 \
-#        -DENABLE_SOLID_SMOKE=off                                       \
-#        -DENABLE_PLASMA_SMOKE=off                                      \
-#        -DENABLE_QTWEBKIT_RUBY=off                                     \
-#        -DENABLE_QTUITOOLS_RUBY=off                                    \
-#        -DENABLE_QTSCRIPT=off                                          \
-#        -DENABLE_QTTEST=off                                            \
-#        -DENABLE_PHONON_RUBY=off                                       \
-#        -DENABLE_QSCINTILLA_RUBY=off                                   \
-#        -DENABLE_QWT_RUBY=off                                          \
-#        -DENABLE_SOPRANO_RUBY=off                                      \
-#        -DENABLE_KDEVPLATFORM_RUBY=off                                 \
-#        -DENABLE_KORUNDUM_RUBY=off                                     \
-#        -DENABLE_KHTML_RUBY=off                                        \
-#        -DENABLE_KTEXTEDITOR_RUBY=off                                  \
-#        -DENABLE_SOLID_RUBY=off                                        \
-#        -DENABLE_KROSSRUBY=off                                         \
-#        -DENABLE_PLASMA_RUBY=off
-# 4. If you need to clean the tree, use:
-#      make clean
-#      rm CMakeCache.txt CMakeFiles/*log
 #
+# 1. Copy this file to ./CMakeLists.txt
+#
+# 2. Copy files neede by cmake from ../kdelibs/ to ./cmake/modules/:
+#
+#  cp ../kdelibs/cmake/modules/FindQt4.cmake                  ./cmake/modules/
+#  cp ../kdelibs/cmake/modules/FindRUBY.cmake                 ./cmake/modules/
+#  cp ../kdelibs/cmake/modules/MacroOptionalFindPackage.cmake ./cmake/modules/
+#  cp ../kdelibs/cmake/modules/MacroPushRequiredVars.cmake    ./cmake/modules/
+#
+# 3. Build kdebindings with a set of commands like:
+#
+#  test -r Makefile && make clean
+#  rm -f CMakeCache.txt CMakeFiles/*log
+#  cmake                                                         \
+#    -DCMAKE_INSTALL_PREFIX=/opt/ruby1.8.7                       \
+#    -DRUBY_EXECUTABLE=/opt/ruby1.8.7/bin/ruby                   \
+#    -DRUBY_INCLUDE_PATH=/opt/ruby1.8.7/lib/ruby/1.8/i686-linux/ \
+#    -Wno-dev                                                    \
+#    -DENABLE_SMOKE=on                                           \
+#    -DENABLE_QTRUBY=on                                          \
+#    -DENABLE_QTWEBKIT_SMOKE=off                                 \
+#    -DENABLE_QTSCRIPT_SMOKE=off                                 \
+#    -DENABLE_QTUITOOLS_SMOKE=off                                \
+#    -DENABLE_QTTEST_SMOKE=off                                   \
+#    -DENABLE_PHONON_SMOKE=off                                   \
+#    -DENABLE_QSCI_SMOKE=off                                     \
+#    -DENABLE_QWT_SMOKE=off                                      \
+#    -DENABLE_KDE_SMOKE=off                                      \
+#    -DENABLE_KDEVPLATFORM_SMOKE=off                             \
+#    -DENABLE_KHTML_SMOKE=off                                    \
+#    -DENABLE_KTEXTEDITOR_SMOKE=off                              \
+#    -DENABLE_SOLID_SMOKE=off                                    \
+#    -DENABLE_PLASMA_SMOKE=off                                   \
+#    -DENABLE_QTWEBKIT_RUBY=off                                  \
+#    -DENABLE_QTUITOOLS_RUBY=off                                 \
+#    -DENABLE_QTSCRIPT=off                                       \
+#    -DENABLE_QTTEST=off                                         \
+#    -DENABLE_PHONON_RUBY=off                                    \
+#    -DENABLE_QSCINTILLA_RUBY=off                                \
+#    -DENABLE_QWT_RUBY=off                                       \
+#    -DENABLE_SOPRANO_RUBY=off                                   \
+#    -DENABLE_KDEVPLATFORM_RUBY=off                              \
+#    -DENABLE_KORUNDUM_RUBY=off                                  \
+#    -DENABLE_KHTML_RUBY=off                                     \
+#    -DENABLE_KTEXTEDITOR_RUBY=off                               \
+#    -DENABLE_SOLID_RUBY=off                                     \
+#    -DENABLE_KROSSRUBY=off                                      \
+#    -DENABLE_PLASMA_RUBY=off
+#  make
+#  make install
+#
 
 project(kdebindings)
 
