[Pkg-kde-talk] Re: [Kde-bindings] qtruby.rb: backporting the 'Module includes Qt' bug to 3.3

Richard Dale Richard_Dale@tipitina.demon.co.uk
Sun, 10 Apr 2005 09:29:51 +0000


--Boundary-00=_PIPWCSrRkjLwTCd
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

On Saturday 09 April 2005 21:50, Adeodato Simó wrote:
> Hello Richard,
>
>   I'm one of the KDE packagers in Debian. Our next release, Sarge, will
>   be shipping with KDE 3.3, and a user has requested [1] that we
>   backport the "include 'Qt' in Module pollutes its namespace" fix from
>   KDE_3_4_BRANCH.
>
>     [1] http://bugs.debian.org/303608
>
>   I've digged into it today and backported the CVS commit. I've tested
>   the resulting package and seems to work, but I'd really appreciate if
>   you could have a quick look at the patch we'll be applying (attached).
>
>   I'm asking this because, although the patch came from CVS, I've needed
>   to do a bit of tweaking to it, and I fear having left something out,
>   or having included something that will have some nasty effects that my
>   testing hasn't discovered.
>
>   The changes are explained at the top of the diff, the involved CVS
>   revisions are listed in it too.
I've had a look at the changes, and they look ok. I did reformat some code at 
the same time as making the fix which makes it a bit less backporting 
friendly - sorry about that.

I fixed a couple of small regressions yesterday, Qt::version and 
Qt::ruby_version shouldn't have been moved to the Qt::Internal module, so 
these lines should be removed from the patch:

-    rb_define_method(qt_internal_module, "version", (VALUE (*) (...)) 
version, 0);
-    rb_define_method(qt_internal_module, "qtruby_version", (VALUE (*) (...)) 
qtruby_version, 0);

+    rb_define_module_function(qt_internal_module, "version", (VALUE (*) 
(...)) version, 0);
+    rb_define_module_function(qt_internal_module, "qtruby_version", (VALUE 
(*) (...)) 

The rbqtapi script in qtruby/bin also need changing to work with the methods 
moved to the Internal module. I've attached the current version.

Also a similar change was needed for korunudum.rb, otherwise ruby dcop won't 
work, I've attached a patch of that change. So please make sure that the 
examples in korundum/rubylib/examples/dcop still work ok after the fix.

Regards
-- Richard



--Boundary-00=_PIPWCSrRkjLwTCd
Content-Type: text/x-diff;
  charset="utf-8";
  name="korunundum-namespace.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="korunundum-namespace.patch"

Index: rubylib/korundum/lib/KDE/korundum.rb
===================================================================
RCS file: /home/kde/kdebindings/korundum/rubylib/korundum/lib/KDE/korundum.rb,v
retrieving revision 1.45
retrieving revision 1.45.2.1
diff -U3 -r1.45 -r1.45.2.1
--- rubylib/korundum/lib/KDE/korundum.rb	29 Dec 2004 13:49:06 -0000	1.45
+++ rubylib/korundum/lib/KDE/korundum.rb	31 Mar 2005 08:39:28 -0000	1.45.2.1
@@ -18,8 +18,6 @@
 =end
 
 module KDE
-	include Qt
-	
 	DCOPMeta = {}
 
 	# An entry for each dcop signal or slot
@@ -68,27 +66,27 @@
 				end
 			end
 		end
-	end
+	end # DCOPMetaInfo
 
-	def hasDCOPSignals(aClass)
+	def KDE.hasDCOPSignals(aClass)
 		classname = aClass.name if aClass.is_a? Module
 		meta = DCOPMeta[classname]
 		return !meta.nil? && meta.k_dcop_signals.length > 0
 	end
 
-	def hasDCOPSlots(aClass)
+	def KDE.hasDCOPSlots(aClass)
 		classname = aClass.name if aClass.is_a? Module
 		meta = DCOPMeta[classname]
 		return !meta.nil? && meta.k_dcop.length > 0
 	end
 
-	def getDCOPSignalNames(aClass)
+	def KDE.getDCOPSignalNames(aClass)
 		classname = aClass.name if aClass.is_a? Module
 		signals = DCOPMeta[classname].k_dcop_signals
 		return signals.keys
 	end
 
-	def fullSignalName(instance, signalName)
+	def KDE.fullSignalName(instance, signalName)
 		classname = instance.class.name if instance.class.is_a? Module
 		signals = DCOPMeta[classname].k_dcop_signals
 		return signals[signalName].full_name
@@ -114,10 +112,10 @@
 			replyType << dcop_slot.reply_type
 			KDE::dcop_process(	@client, 
 								dcop_slot.name, 
-								Qt::getMocArguments(fun), 
+								Qt::Internal::getMocArguments(fun), 
 								data,
 								replyType, 
-								(replyType == 'void' or replyType == 'ASYNC') ? nil : Qt::getMocArguments(replyType), 
+								(replyType == 'void' or replyType == 'ASYNC') ? nil : Qt::Internal::getMocArguments(replyType), 
 								replyData )
 		end
 
@@ -158,7 +156,7 @@
 
 	# If a class contains a k_dcop slots list declaration, then create a DCOPObject
 	# associated with it	
-	def createDCOPObject(instance)
+	def KDE.createDCOPObject(instance)
 		meta = DCOPMeta[instance.class.name]
 		return nil if meta.nil?
 
@@ -309,7 +307,7 @@
 			end
 			return KDE::dcop_call(	self, 
 									full_name, 
-									Qt::getMocArguments(full_name),
+									Qt::Internal::getMocArguments(full_name),
 									*k )
 		end
 
@@ -332,7 +330,7 @@
 			end
 			return KDE::dcop_send(	self, 
 									fun, 
-									Qt::getMocArguments(sig),
+									Qt::Internal::getMocArguments(sig),
 									*k )
 		end
 		
@@ -511,16 +509,14 @@
 end
 
 class Module
-	include KDE
-
 	def k_dcop_signals(*signal_list)
-		meta = DCOPMeta[self.name] || DCOPMetaInfo.new(self)
+		meta = KDE::DCOPMeta[self.name] || KDE::DCOPMetaInfo.new(self)
 		meta.add_signals(signal_list)
 		meta.changed = true
 	end
 
 	def k_dcop(*slot_list)
-		meta = DCOPMeta[self.name] || DCOPMetaInfo.new(self)
+		meta = KDE::DCOPMeta[self.name] || KDE::DCOPMetaInfo.new(self)
 		meta.add_slots(slot_list)
 		meta.changed = true
 	end

--Boundary-00=_PIPWCSrRkjLwTCd
Content-Type: application/x-ruby;
  name="rbqtapi"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="rbqtapi"

#!/usr/bin/env ruby

# Note: this program is part of qtruby and makes use of its internal functions.
#       You should not rely on those in your own programs.

require 'getopts'
getopts('r:hvimp')

case File.basename $0
when "rbqtapi"
   require 'Qt'
when "rbkdeapi"
   require 'Korundum'
end

if $OPT_v
    # TODO add and use version number #{Qt::VERSION}
    print "qtruby using Qt-#{Qt::version}\n"
    exit 0 
elsif $OPT_h
    print $usage
    exit 0
end

if $OPT_m
    while 1
        line = STDIN.readline.chomp
        line.gsub!(/^Q(?=[A-Z])/,'Qt::')
        line.gsub!(/^K/,'KDE::') unless line =~ /^(KDE)|(KIO)|(KParts)/
        classid = Qt::Internal::find_pclassid($_)
        puts "__START__"
        if classid
            a = Qt::Internal::findAllMethods(classid)
            ids = (a.keys.sort.map{|k|a[k]}).flatten
            candidates = Qt::dumpCandidates(ids)
            sup = []
            Qt::Internal::getAllParents(classid, sup)
            sup.each {
                |sup_item|
                a = Qt::Internal::findAllMethods(sup_item)
                ids = (a.keys.sort.map{|k|a[k]}).flatten
                candidates << Qt::Internal::dumpCandidates(ids)
            }
            candidates.gsub("\t","") # erm. whats the "s" mean on s/\t//gs ?
            print candidates
        end
        puts "__END__"
    end
end

search_string = ARGV[0] ? ARGV[0].dup : nil
search_string.gsub!(/^Q(?=[A-Z])/,'Qt::') if search_string
# search_string.gsub!(/^K(?=[^D][^E])/,'KDE::') if search_string
search_string.gsub!(/^K/,'KDE::') unless search_string.nil? or search_string =~ /^(KDE)|(KIO)|(KParts)/
classid = search_string ? Qt::Internal::find_pclassid(search_string) : 1
if classid == 0
    puts "Class #{search_string} not found"
    exit 1
end
regexp = nil
regexp = ( $OPT_i ? Regexp.new($OPT_r, Regexp::IGNORECASE) : Regexp.new($OPT_r) ) if $OPT_r
candidates = ""
while true
    a = Qt::Internal::findAllMethods(classid)
    break if a.nil? 
    ids = (a.keys.sort.map{|k|a[k]}).flatten
    candidates = Qt::Internal::dumpCandidates(ids)
    if $OPT_p and !search_string.empty? and classid
	sup = []
        Qt::Internal::getAllParents(classid, sup)
	sup.each {
	    |sup_item|
            a = Qt::Internal::findAllMethods(sup_item)
            ids = (a.keys.sort.map{|k|a[k]}).flatten
            candidates << Qt::Internal::dumpCandidates(ids)
        }
    end
    if regexp
	candidates.split("\n").each {
	    |candidate|
	    puts candidate if candidate =~ regexp
	}
    else
	print candidates
    end
    break unless search_string.nil?
    classid += 1
end

BEGIN {
$usage = <<USAGE
rbqtapi - a qtruby introspection tool\t(c) Germain Garand 2003 <germain\@ebooksfrance.org>

usage: rbqtapi [-r <re>] [<class>]

options:
\t-r <re> : find all functions matching regular expression/keyword <re>
\t-i : together with -r, performs a case insensitive search
\t-p : display also inherited methods for <class>.
\t-v : print qtruby and Qt versions
\t-h : print this help message
USAGE
}

--Boundary-00=_PIPWCSrRkjLwTCd--