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]
130 a.enabled = opts.fetch(:enabled, true)
138 def plug_action_list(name, actions)
139 plugActionList(name.to_s, actions)
142 def unplug_action_list(name)
143 unplugActionList(name.to_s)
148 def self.from_theme(name)
157 class KDE::ConfigGroup
159 group_list.each do |g|
166 def self.gui(name, &blk)
167 "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" +
168 GuiBuilder.new.gui({ :version => 2, :name => name }, &blk)
171 def self.with_xml_gui(xml, &blk)
172 tmp = TemporaryFile.new
175 ::File.open(tmp.file_name, 'w') do |f|
181 ::File.unlink(tmp.file_name)
184 class GuiBuilder < Builder::XmlMarkup
194 def menu(name, opts = {}, &blk)
195 Menu(:name => name) do |m|
196 m.text(opts[:text]) if opts[:text]
197 blk[m] if block_given?
201 def action(name, opts = {})
202 Action(opts.merge(@action_opts).merge(:name => name))
209 def tool_bar(name, opts = { }, &blk)
210 ToolBar(:name => name) do |tb|
211 tb.text(opts[:text]) if opts[:text]
212 blk[tb] if block_given?
216 def action_list(name)
217 ActionList(:name => name)
220 def group(name, &blk)
222 @action_opts = { :group => name }
226 DefineGroup(:name => name)
231 def self.active_color
232 scheme = KDE::ColorScheme.new(Qt::Palette::Active, KDE::ColorScheme::Window)
233 color = scheme.foreground(KDE::ColorScheme::PositiveText).color
236 def self.std_shortcut(name)
237 code = KDE::StandardShortcut.send(name.to_s.capitalize)
238 StandardShortcut::shortcut(code)
247 def output_channel_mode=(value)
248 c = self.class.const_get("#{value.to_s.capitalize.camelize}Channel")
249 setOutputChannelMode(c)
252 def self.split_args(str)
253 KDE::Shell.split_args(str)
257 set_program(path, args)
262 def KDE.download_tempfile(url, parent)
264 if KIO::NetAccess.download(url, result, parent)