[Kde-bindings] KDE/kdebindings/ruby/korundum

Richard Dale Richard_Dale at tipitina.demon.co.uk
Wed Apr 23 09:38:43 UTC 2008


SVN commit 800093 by rdale:

* Made KDE::CmdLineArgs Enumerable so that it is easy to iterate through
  the args. For example:

	args = KDE::CmdLineArgs.parsedArgs
	args.each {|arg| puts arg}

* Allow args["formfactor"] as an alternative to args.getOption("formfactor"),
  and args[1] as an alternative to args.arg(1)

* Improved the KDE::MainWindow.kRestoreMainWindows method so that you
  no longer need to pass it a list of classes, and you can give it an
  optional block to execute for each newly created window. For example:

  KDE::MainWindow.kRestoreMainWindows {|window| window.caption = "foo"}

CCMAIL: kde-bindings at kde.org



 M  +17 -0     ChangeLog  
 M  +67 -7     src/lib/KDE/korundum4.rb  


--- trunk/KDE/kdebindings/ruby/korundum/ChangeLog #800092:800093
@@ -1,3 +1,20 @@
+2008-04-23  Richard Dale  <richard.j.dale at gmail.com>
+
+	* Made KDE::CmdLineArgs Enumerable so that it is easy to iterate through
+	  the args. For example:
+
+		args = KDE::CmdLineArgs.parsedArgs
+		args.each {|arg| puts arg}
+
+	* Allow args["formfactor"] as an alternative to args.getOption("formfactor"),
+	  and args[1] as an alternative to args.arg(1)
+
+	* Improved the KDE::MainWindow.kRestoreMainWindows method so that you
+	  no longer need to pass it a list of classes, and you can give it an
+	  optional block to execute for each newly created window. For example:
+
+		KDE::MainWindow.kRestoreMainWindows {|window| window.caption = "foo"}
+
 2008-04-22  Richard Dale  <rdale at foton.es>
 
 	* Made the krubyapplication executable work with args to be passed to the
--- trunk/KDE/kdebindings/ruby/korundum/src/lib/KDE/korundum4.rb #800092:800093
@@ -161,6 +161,8 @@
 	end
 
 	class CmdLineArgs < Qt::Base
+		include Enumerable
+
 		def CmdLineArgs.init(*k)
 			if k.length > 0
 				if k[0].kind_of? Array
@@ -176,6 +178,38 @@
 			end
 		end
 
+		def each
+			i = 0
+			while i < count do
+				yield arg(i)
+				i += 1
+			end
+		end
+
+		def length
+			count
+		end
+
+		def size
+			count
+		end
+
+		# Allows args["formfactor"] as an alternative to args.getOption("formfactor"),
+		# and args[1] as an alternative to args.arg(1)
+		def [](arg)
+			if arg.kind_of?(String)
+				getOption(arg)
+			elsif arg.kind_of?(Integer)
+				arg(arg)
+			else
+				nil
+			end
+		end
+
+		def set?(arg)
+			isSet(arg)
+		end
+
 		def isSet(arg)
 			super(arg.kind_of?(String) ? Qt::ByteArray.new(arg) : arg)
 		end
@@ -183,6 +217,10 @@
 		def getOption(arg)
 			super(arg.kind_of?(String) ? Qt::ByteArray.new(arg) : arg)
 		end
+
+		def getOptionList(arg)
+			super(arg.kind_of?(String) ? Qt::ByteArray.new(arg) : arg)
+		end
 	end
 
 	class CmdLineOptions
@@ -254,20 +292,42 @@
 	end
 
 	class MainWindow
-		# A sane alternative to the strange looking C++ template version,
-		# this takes a variable number of ruby args as classes to restore
-		def self.kRestoreMainWindows(*k)
+		# A sane alternative to the strange looking C++ template version.
+		# There is no need to pass a list of classes, as the Ruby classes
+		# of the main windows to be restored are derived from 
+		# KDE::MainWindow#classNameOfToplevel
+		# Takes an optional block, so a newly created window can be passed
+		# into the block. For example:
+		#
+		# KDE::MainWindow.kRestoreMainWindows {|window| window.caption = "foobar"}
+		#
+		def self.kRestoreMainWindows(&block)
 			n = 1
 			while MainWindow.canBeRestored(n)
 				className = MainWindow.classNameOfToplevel(n)
-				k.each do |klass|
-					if klass.name == className
-						klass.new.restore(n)
-					end
+				if className =~ /(.*)::(.*)/
+					namespace = Object.const_get($1)
+					klass = namespace.const_get($2)
+				else
+					klass = Object.const_get(className)
 				end
+				obj = klass.new.restore(n)
+				if block_given?
+					yield obj
+				end
 				n += 1
 			end
 		end
+
+		# Yield the numbers of the windows that can be restored
+		# in turn
+		def self.each_restore
+			n = 1
+			while MainWindow.canBeRestored(n)
+				yield n
+				n += 1
+			end
+		end
 	end
 
 	class PageWidgetItem



More information about the Kde-bindings mailing list