1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
19 self.caption = gui.opts[:caption]
20 widget = Qt::Widget.new(self)
23 self.main_widget = widget
27 class KDE::Application
29 # Initialize an application.
32 about = KDE::AboutData.new(
35 data[:name] || KDE::ki18n(data[:id]),
36 data[:version] || "0.1",
37 data[:description] || KDE::ki18n(""),
38 KDE::AboutData::License_GPL,
39 data[:copyright] || KDE::ki18n(""))
40 (data[:authors] || []).each do |name, email|
41 about.addAuthor(name, KDE::LocalizedString.new, email)
43 (data[:contributors] || []).each do |name, contribution|
44 about.addCredit(name, contribution)
46 about.bug_address = Qt::ByteArray.new(data[:bug_tracker] || "")
48 KDE::CmdLineArgs.init(ARGV, about)
49 KDE::CmdLineOptions.new.tap do |opts|
50 (data[:options] || []).each do |args|
53 opts.add(args[0], args[1])
55 opts.add(args[0], args[1], args[2])
58 KDE::CmdLineArgs.add_cmd_line_options opts
65 class KDE::CmdLineArgs
71 isSet(Qt::ByteArray.new(name))
75 class KDE::ActionCollection
77 unless action.is_a? KDE::Action
79 action = KDE::Action.new(action.text, action.parent)
80 action.icon = orig_action.icon
81 action.checkable = orig_action.checkable
82 action.checked = orig_action.checked
83 action.on(:triggered) { orig_action.trigger }
84 orig_action.on(:changed) { action.checked = orig_action.checked }
86 add_action(name.to_s, action)
90 class KDE::XmlGuiWindow
92 KDE::with_xml_gui(gui) do |file|
93 setupGUI(KDE::XmlGuiWindow::Default, file)
101 class KDE::XMLGUIClient
103 KDE::with_xml_gui(gui) do |file|
110 def std_action(action, opts = {}, &blk)
111 target, slot = get_slot(opts[:slot], &blk)
112 KDE::StandardAction.method_missing(action, target, slot, action_collection)
115 def get_slot(s = nil, &blk)
116 target, slot = if block_given?
117 [Qt::SignalBlockInvocation.new(action_parent, blk, 'invoke()'), SLOT('invoke()')]
119 [action_parent, SLOT(s)]
123 def regular_action(name, opts, &blk)
124 KDE::Action.new(KDE::Icon.from_theme(opts[:icon]),
125 opts[:text], action_parent).tap do |a|
126 action_collection.add_action(name.to_s, a)
127 a.connect(SIGNAL('triggered(bool)'), &blk)
128 a.tool_tip = opts[:tooltip] if opts[:tooltip]
129 a.shortcut = opts[:shortcut] if opts[:shortcut]
137 def plug_action_list(name, actions)
138 plugActionList(name.to_s, actions)
141 def unplug_action_list(name)
142 unplugActionList(name.to_s)
147 def self.from_theme(name)
156 class KDE::ConfigGroup
158 group_list.each do |g|
165 def self.gui(name, &blk)
166 "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" +
167 GuiBuilder.new.gui({ :version => 2, :name => name }, &blk)
170 def self.with_xml_gui(xml, &blk)
171 tmp = TemporaryFile.new
174 ::File.open(tmp.file_name, 'w') do |f|
180 ::File.unlink(tmp.file_name)
183 class GuiBuilder < Builder::XmlMarkup
193 def menu(name, opts = {}, &blk)
194 Menu(:name => name) do |m|
195 m.text(opts[:text]) if opts[:text]
196 blk[m] if block_given?
200 def action(name, opts = {})
201 Action(opts.merge(@action_opts).merge(:name => name))
208 def tool_bar(name, opts = { }, &blk)
209 ToolBar(:name => name) do |tb|
210 tb.text(opts[:text]) if opts[:text]
211 blk[tb] if block_given?
215 def action_list(name)
216 ActionList(:name => name)
219 def group(name, &blk)
221 @action_opts = { :group => name }
225 DefineGroup(:name => name)
230 def self.active_color
231 scheme = KDE::ColorScheme.new(Qt::Palette::Active, KDE::ColorScheme::Window)
232 color = scheme.foreground(KDE::ColorScheme::PositiveText).color
235 def self.std_shortcut(name)
236 code = KDE::StandardShortcut.send(name.to_s.capitalize)
237 StandardShortcut::shortcut(code)
246 def output_channel_mode=(value)
247 c = self.class.const_get("#{value.to_s.capitalize.camelize}Channel")
248 setOutputChannelMode(c)
251 def self.split_args(str)
252 KDE::Shell.split_args(str)
256 set_program(path, args)
261 def KDE.download_tempfile(url, parent)
263 if KIO::NetAccess.download(url, result, parent)