add more spacing
[personal-kdebase.git] / workspace / plasma / scriptengines / ruby / data_engine.rb
blob856db4caf3ce472cbb09778c8811236371d06158
1 =begin
2  *   Copyright 2008 by Richard Dale <richard.j.dale@gmail.com>
3  *
4  *   This program is free software; you can redistribute it and/or modify
5  *   it under the terms of the GNU Library General Public License as
6  *   published by the Free Software Foundation; either version 2, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *   GNU General Public License for more details
13  *
14  *   You should have received a copy of the GNU Library General Public
15  *   License along with this program; if not, write to the
16  *   Free Software Foundation, Inc.,
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 =end
20 require 'plasma_applet'
22 module PlasmaScripting
23   class DataEngine < Qt::Object
24     slots :updateAllSources, "removeSource(QString)"
25     signals "sourceAdded(QString)", "sourceRemoved(QString)"
27     attr_accessor :data_engine_script
29     def initialize(parent, args = nil)
30       super(parent)
31       @data_engine_script = parent
32       connect(@data_engine_script.dataEngine, SIGNAL("sourceAdded(QString)"), self, SIGNAL("sourceAdded(QString)"))
33       connect(@data_engine_script.dataEngine, SIGNAL("sourceRemoved(QString)"), self, SIGNAL("sourceRemoved(QString)"))
34     end
36     def init
37     end
39     def sourceRequestEvent(name)
40     end
42     def updateSourceEvent(source)
43     end
45     def setData(*args)
46       if args.length == 2 && !args[1].kind_of?(Qt::Variant)
47         args[1] = Qt::Variant.fromValue(args[1])
48       elsif args.length == 3 && !args[2].kind_of?(Qt::Variant)
49         args[2] = Qt::Variant.fromValue(args[2])
50       end
51       @data_engine_script.setData(*args)
52     end
54     def removeAllData(source)
55       @data_engine_script.removeAllData(source)
56     end
58     def removeData(source, key)
59       @data_engine_script.removeData(source, key)
60     end
62     def setMaxSourceCount(limit)
63       @data_engine_script.setMaxSourceCount(limit)
64     end
66     def maxSourceCount=(limit)
67       setMaxSourceCount(limit)
68     end
70     def setMinimumPollingInterval(minimumMs)
71       @data_engine_script.setMinimumPollingInterval(minimumMs)
72     end
74     def minimumPollingInterval=(minimumMs)
75       setMinimumPollingInterval(minimumMs)
76     end
78     def minimumPollingInterval
79       @data_engine_script.minimumPollingInterval
80     end
82     def setPollingInterval(frequency)
83       @data_engine_script.setPollingInterval(frequency)
84     end
86     def pollingInterval=(frequency)
87       setPollingInterval(frequency)
88     end
90     def removeAllSources
91       @data_engine_script.removeAllSources
92     end
94     def sources
95       return []
96     end
98     def removeSource(source)
99       @data_engine_script.dataEngine.removeSource(source)
100     end
102     def updateAllSources
103       @data_engine_script.dataEngine.updateAllSources
104     end
105   end
108 module PlasmaScriptengineRuby
109   class DataEngine < Plasma::DataEngineScript
110     def initialize(parent, args)
111       super(parent)
112     end
114     def camelize(str)
115       str.gsub(/(^|[_-])(.)/) { $2.upcase }
116     end
118     def init
119       puts "RubyAppletScript::DataEngine#init mainScript: #{mainScript}"
120       program = Qt::FileInfo.new(mainScript)
121       $: << program.path
122       load Qt::File.encodeName(program.filePath).to_s
123       moduleName = camelize(Qt::Dir.new(package.path).dirName)
124       className = camelize(program.baseName)
125       puts "RubyAppletScript::DataEngine#init instantiating: #{moduleName}::#{className}"
126       klass = Object.const_get(moduleName.to_sym).const_get(className.to_sym)
127       @data_engine_script = klass.new(self)
128       @data_engine_script.init
129       return true
130     end
132     def sources
133       @data_engine_script.sources
134     end
136     def sourceRequestEvent(name)
137       @data_engine_script.sourceRequestEvent(name)
138     end
140     def updateSourceEvent(source)
141       @data_engine_script.updateSourceEvent(source)
142     end
143   end
146 # kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;