summaryrefslogtreecommitdiffstats
path: root/korundum/rubylib/examples/dcop
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /korundum/rubylib/examples/dcop
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'korundum/rubylib/examples/dcop')
-rwxr-xr-xkorundum/rubylib/examples/dcop/dcopcall.rb37
-rwxr-xr-xkorundum/rubylib/examples/dcop/dcoppredicate.rb41
-rwxr-xr-xkorundum/rubylib/examples/dcop/dcopsend.rb35
-rwxr-xr-xkorundum/rubylib/examples/dcop/dcopsignal.rb26
-rwxr-xr-xkorundum/rubylib/examples/dcop/dcopslot.rb88
-rwxr-xr-xkorundum/rubylib/examples/dcop/dcoptest.rb129
-rwxr-xr-xkorundum/rubylib/examples/dcop/petshop.rb91
7 files changed, 447 insertions, 0 deletions
diff --git a/korundum/rubylib/examples/dcop/dcopcall.rb b/korundum/rubylib/examples/dcop/dcopcall.rb
new file mode 100755
index 00000000..f3b532ef
--- /dev/null
+++ b/korundum/rubylib/examples/dcop/dcopcall.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+
+require 'Korundum'
+include KDE
+
+class SenderWidget < PushButton
+ def initialize(parent, name)
+ super
+ connect(self, SIGNAL('clicked()'), self, SLOT('doit()'))
+ end
+
+ slots 'doit()'
+
+ def doit()
+ dcopRef = DCOPRef.new("dcopslot", "MyWidget")
+ #
+ # Note that there are three different ways to make a DCOP call():
+ # 1) result = dcopRef.call("getPoint(QString)", "Hello from dcopcall")
+ # 2) result = dcopRef.call("getPoint", "Hello from dcopcall")
+ # 3) result = dcopRef.getPoint("Hello from dcopcall")
+ #
+ result = dcopRef.getPoint("Hello from dcopcall")
+ if result.nil?
+ puts "DCOP call failed"
+ else
+ puts "result class: #{result.class.name} x: #{result.x} y: #{result.y}"
+ end
+ end
+end
+
+about = AboutData.new("dcopcall", "DCOP Call Test", "0.1")
+CmdLineArgs.init(ARGV, about)
+a = UniqueApplication.new
+calltest = SenderWidget.new(nil, "calltest") { setText 'DCOP Call Test' }
+a.mainWidget = calltest
+calltest.show
+a.exec
diff --git a/korundum/rubylib/examples/dcop/dcoppredicate.rb b/korundum/rubylib/examples/dcop/dcoppredicate.rb
new file mode 100755
index 00000000..82a9c8b4
--- /dev/null
+++ b/korundum/rubylib/examples/dcop/dcoppredicate.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+
+require 'Korundum'
+include KDE
+
+class SenderWidget < PushButton
+ def initialize(parent, name)
+ super
+ connect(self, SIGNAL('clicked()'), self, SLOT('doit()'))
+ end
+
+ slots 'doit()'
+
+ def doit()
+ dcopRef = DCOPRef.new("dcopslot", "MyWidget")
+ #
+ # A synonym for isFoo()
+ result = dcopRef.foo?
+ if result.nil?
+ puts "DCOP predicate failed"
+ else
+ puts "foo? is #{result}"
+ end
+
+ # A synonym for hasBar()
+ result = dcopRef.bar?
+ if result.nil?
+ puts "DCOP predicate failed"
+ else
+ puts "bar? is #{result}"
+ end
+ end
+end
+
+about = AboutData.new("dcoppredicate", "DCOP Predicate Test", "0.1")
+CmdLineArgs.init(ARGV, about)
+a = UniqueApplication.new
+calltest = SenderWidget.new(nil, "predicatetest") { setText 'DCOP Predicate Test' }
+a.mainWidget = calltest
+calltest.show
+a.exec
diff --git a/korundum/rubylib/examples/dcop/dcopsend.rb b/korundum/rubylib/examples/dcop/dcopsend.rb
new file mode 100755
index 00000000..9365473b
--- /dev/null
+++ b/korundum/rubylib/examples/dcop/dcopsend.rb
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+
+require 'Korundum'
+
+class SenderWidget < KDE::PushButton
+ def initialize(parent, name)
+ super
+ Qt::Object::connect(self, SIGNAL('clicked()'), self, SLOT('doit()'))
+ end
+
+ slots 'doit()'
+
+ def doit()
+ #
+ # Note that there are three different ways to make a DCOP send():
+ # 1) dcopRef.send("mySlot(QString)", "Hello from dcopsend")
+ # 2) dcopRef.send("mySlot", "Hello from dcopsend")
+ #
+ dcopRef = KDE::DCOPRef.new("dcopslot", "MyWidget")
+ res = dcopRef.send("mySlot", "Hello from dcopsend")
+ if res
+ puts "Sent dcop message"
+ else
+ puts "DCOP send failed"
+ end
+ end
+end
+
+about = KDE::AboutData.new("dcopsend", "DCOPSendTest", "0.1")
+KDE::CmdLineArgs.init(ARGV, about)
+a = KDE::Application.new()
+sender = SenderWidget.new(nil, "senderwidget") { setText 'DCOP Send Test' }
+a.setMainWidget(sender)
+sender.show()
+a.exec()
diff --git a/korundum/rubylib/examples/dcop/dcopsignal.rb b/korundum/rubylib/examples/dcop/dcopsignal.rb
new file mode 100755
index 00000000..07a6dfee
--- /dev/null
+++ b/korundum/rubylib/examples/dcop/dcopsignal.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+require 'Korundum'
+
+class SenderWidget < KDE::PushButton
+ k_dcop_signals 'void testEmitSignal(QString)'
+
+ def initialize(parent, name)
+ super
+ Qt::Object::connect(self, SIGNAL('clicked()'), self, SLOT('doit()'))
+ end
+
+ slots 'doit()'
+
+ def doit()
+ emit testEmitSignal("Hello DCOP Slot")
+ end
+end
+
+about = KDE::AboutData.new("dcopsignal", "DCOPSignalTest", "0.1")
+KDE::CmdLineArgs.init(ARGV, about)
+a = KDE::UniqueApplication.new()
+signaltest = SenderWidget.new(nil, "foobar") { setText 'DCOP Signal Test' }
+a.mainWidget = signaltest
+signaltest.show()
+a.exec()
diff --git a/korundum/rubylib/examples/dcop/dcopslot.rb b/korundum/rubylib/examples/dcop/dcopslot.rb
new file mode 100755
index 00000000..e600dfdb
--- /dev/null
+++ b/korundum/rubylib/examples/dcop/dcopslot.rb
@@ -0,0 +1,88 @@
+#!/usr/bin/env ruby
+
+require 'Korundum'
+
+# This is an example of a KDE class that has 'k_dcop' slots declarations, but
+# isn't a subclass of DCOPObject. The following four methods are added to your
+# class:
+#
+# interfaces()
+# functions()
+# connectDCOPSignal()
+# disconnectDCOPSignal()
+#
+# See the call to connectDCOPSignal() towards the end of the code as
+# an example. The name of the dcop object is always the name of the
+# ruby class, and they are Singletons - you can only instantiate one
+# of them.
+#
+# The petshop.rb example in this directory demonstrates more complex
+# use of korundum dcop by subclassing a DCOPObject.
+#
+class MyWidget < KDE::PushButton
+
+ k_dcop 'void mySlot(QString)',
+ 'QPoint getPoint(QString)',
+ 'QMap<QCString,DCOPRef> actionMap()',
+ 'QValueList<DCOPRef> windowList()',
+ 'QValueList<QCString> propertyNames(bool)',
+ 'KURL::List urlList()',
+ 'bool isFoo()',
+ 'bool hasBar()'
+
+ def initialize(parent, name)
+ super
+ end
+
+ def mySlot(greeting)
+ puts "greeting: #{greeting}"
+ end
+
+ def getPoint(msg)
+ puts "message: #{msg}"
+ return Qt::Point.new(50, 100)
+ end
+
+ def actionMap()
+ map = {}
+ map['foobar'] = KDE::DCOPRef.new("myapp", "myobj")
+ return map
+ end
+
+ def windowList()
+ list = []
+ list[0] = KDE::DCOPRef.new("myapp", "myobj")
+ return list
+ end
+
+ def propertyNames(b)
+ return ["thisProperty", "thatProperty"]
+ end
+
+ def urlList()
+ list = []
+ list << KDE::URL.new("http://www.kde.org/") << KDE::URL.new("http://dot.kde.org/")
+ return list
+ end
+
+ def isFoo
+ true
+ end
+
+ def hasBar
+ true
+ end
+end
+
+about = KDE::AboutData.new("dcopslot", "dcopSlotTest", "0.1")
+KDE::CmdLineArgs.init(ARGV, about)
+a = KDE::UniqueApplication.new()
+slottest = MyWidget.new(nil, "mywidget") { setText "DCOP Slot Test" }
+a.mainWidget = slottest
+slottest.caption = a.makeStdCaption("DCOP Slot Test")
+result = slottest.connectDCOPSignal("dcopsignal", "SenderWidget", "testEmitSignal(QString)", "mySlot(QString)", true)
+puts "result: #{result}"
+
+slottest.show()
+# Qt::Internal::setDebug Qt::QtDebugChannel::QTDB_ALL
+a.exec()
diff --git a/korundum/rubylib/examples/dcop/dcoptest.rb b/korundum/rubylib/examples/dcop/dcoptest.rb
new file mode 100755
index 00000000..7d42f76e
--- /dev/null
+++ b/korundum/rubylib/examples/dcop/dcoptest.rb
@@ -0,0 +1,129 @@
+#!/usr/bin/env ruby
+=begin
+This is a ruby version of Jim Bublitz's pykde program, translated by Richard Dale
+=end
+
+=begin
+Copyright 2003 Jim Bublitz
+
+Terms and Conditions
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+Except as contained in this notice, the name of the copyright holder shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from the
+copyright holder.
+=end
+
+
+require 'Korundum'
+
+module DCOPTest
+
+ def DCOPTest.getAnyApplication(client, appName)
+ client.registeredApplications().each do |app|
+ if app == appName or app =~ Regexp.new("^#{appName}-")
+ puts app
+ puts
+ objList = client.remoteObjects(app)
+ objList.each do |obj|
+ puts " #{obj}"
+ funcs = client.remoteFunctions(app, obj)
+ funcs.each { |f| puts " #{f}" }
+ end
+ end
+ end
+ end
+
+end
+
+#-------------------- main ------------------------------------------------
+
+description = "A basic application template"
+version = "1.0"
+aboutData = KDE::AboutData.new("testdcopext", "testdcopext",
+ version, description, KDE::AboutData::License_GPL,
+ "(C) 2003 whoever the author is")
+
+aboutData.addAuthor("author1", "whatever they did", "email@somedomain")
+aboutData.addAuthor("author2", "they did something else", "another@email.address")
+
+KDE::CmdLineArgs.init(ARGV, aboutData)
+
+KDE::CmdLineArgs.addCmdLineOptions([["+files", "File to open", ""]])
+
+app = KDE::Application.new
+dcop = app.dcopClient
+puts "DCOP Application: #{dcop.appId} starting"
+
+# DCOPTest.getAnyApplication(dcop, "konqueror")
+
+puts "--------------------------"
+puts "The DCOPObjects for kicker:"
+
+d = KDE::DCOPRef.new('kicker')
+objs = d.interfaces()
+objs.each { |obj| puts obj }
+
+puts
+puts "get kicker panel size via DCOP"
+res = d.panelSize()
+puts res
+puts "--------------------------"
+
+puts
+puts "Call a method that doesn't exist"
+res = d.junk()
+puts (res.nil? ? "Call failed" : "Call succeeded")
+puts "--------------------------"
+
+puts
+puts
+puts "Start a kwrite instance"
+
+error = ""
+dcopService = ""
+pid = Qt::Integer.new
+
+errcode = KDE::Application.startServiceByDesktopName("kwrite", "", error, dcopService, pid)
+dcopService = "kwrite-" + pid.to_s
+puts "errcode: #{errcode.to_s} error: #{error} dcopService: #{dcopService} pid: #{pid.to_s}"
+puts "--------------------------"
+sleep(2)
+
+o1 = KDE::DCOPRef.new(dcopService, "EditInterface#1")
+#puts "Check if insertLine is a valid function"
+#puts "valid", o1.insertLine.valid
+#puts "--------------------------"
+#puts "insertLine's arg types and names"
+# puts o1.insertLine.argtypes, o1.insertLine.argnames
+puts "--------------------------"
+puts "Insert a line into the kwrite instance we launched"
+
+res = o1.insertLine(0, 'Now is the time for all good men to come to the aid of their party')
+if res.nil?
+ puts "call returns: failed"
+else
+ puts "call returns: #{res.to_s}"
+end
+
+app.exec
+
+
diff --git a/korundum/rubylib/examples/dcop/petshop.rb b/korundum/rubylib/examples/dcop/petshop.rb
new file mode 100755
index 00000000..0cce6277
--- /dev/null
+++ b/korundum/rubylib/examples/dcop/petshop.rb
@@ -0,0 +1,91 @@
+#!/usr/bin/env ruby
+
+# This is an example of a DCOP enabled application written in Ruby, using
+# Korundum. Taken from the PyKDE example_dcopexport.py example which was
+# derived from server.py example in kdebindings written by Torben Weis
+# and Julian Rockey
+
+require 'Korundum'
+
+# An object with DCOP slots needn't be a subclass of DCOPObject, but
+# this DeadParrotObject is one
+
+class DeadParrotObject < KDE::DCOPObject
+
+ k_dcop 'QString getParrotType()', 'void setParrotType(QString)',
+ 'QString squawk()', 'QStringList adjectives()',
+ 'int age()', 'void setAge(int)'
+
+ def initialize(id = 'dead parrot')
+ super(id)
+ @parrot_type = "Norwegian Blue"
+ @age = 7
+ end
+
+ def getParrotType()
+ @parrot_type
+ end
+
+ def setParrotType(parrot_type)
+ @parrot_type = parrot_type
+ end
+
+ def age()
+ @age
+ end
+
+ def setAge(a)
+ @age = a
+ end
+
+ def squawk
+ if rand(2) == 0
+ "This parrot, a #{@parrot_type}, is pining for the fjords"
+ else
+ "This parrot, #{@age} months old, is a #{@parrot_type}"
+ end
+ end
+
+ def adjectives
+ return ["passed on", "is no more", "ceased to be", "expired", "gone to meet his maker",
+ "a stiff", "bereft of life", "rests in peace", "metabolic processes are now history",
+ "off the twig", "kicked the bucket", "shuffled off his mortal coil",
+ "run down his curtain", "joined the bleedin' choir invisible", "THIS IS AN EX-PARROT"]
+ end
+end
+
+description = "A basic application template"
+version = "1.0"
+aboutData = KDE::AboutData.new("petshop", "Dead Parrot Test",
+ version, description, KDE::AboutData::License_GPL,
+ "(C) 2003 whoever the author is")
+
+aboutData.addAuthor("author1", "whatever they did", "email@somedomain")
+aboutData.addAuthor("author2", "they did something else", "another@email.address")
+
+KDE::CmdLineArgs.init(ARGV, aboutData)
+
+KDE::CmdLineArgs.addCmdLineOptions([["+files", "File to open", ""]])
+
+app = KDE::UniqueApplication.new
+dcop = app.dcopClient
+puts "DCOP Application: #{dcop.appId} starting"
+
+parrot = DeadParrotObject.new
+another_parrot = DeadParrotObject.new('polly')
+
+message = <<EOS
+Run kdcop and look for the 'petshop' application instance.
+
+This program exports the DeadParrotObject object.
+Double-clicking those object's methods will allow you to get or set data.
+
+To end the application, in kdcop choose the MainApplication-Interface
+object and double-click the quit() method.
+EOS
+
+print message
+
+app.exec
+
+