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.
10 class ThemePrefs < KDE::Dialog
13 def initialize(loader, theme_loader, parent)
17 @theme_loader = theme_loader
19 [:pieces, KDE::i18n("&Pieces:")],
20 [:board, KDE::i18n("&Board:")],
21 [:layout, KDE::i18n("&Layout:")],
22 [:clock, KDE::i18n("&Clock:")]]
24 :game => Factory.new {|p| Game.new_list(p) },
25 :category => Factory.new {|p| Qt::ListWidget.from_a(p, Game.categories) }
28 @gui = KDE::autogui(:themes,
29 :caption => KDE::i18n("Configure themes")) do |g|
30 g.layout(:type => :horizontal) do |l|
31 l.tab_widget(:tabs) do |tabs|
32 tabs.tab(:text => KDE::i18n("&Games")) do |t|
33 t.widget(:game, :factory => @lists[:game])
35 tabs.tab(:text => KDE::i18n("&Categories")) do |t|
36 t.widget(:category, :factory => @lists[:category])
39 l.layout(:type => :vertical) do |info|
40 @combos.each do |name, text|
41 info.label(:text => text, :buddy => name)
42 info.widget(name, :factory => combo_factory(name))
50 tabs.current_index = 0
51 game.current_index = 0
54 tabs.on(:current_changed) { update }
55 @lists.each_key {|name| send(name).on(:item_selection_changed) { update(name) } }
65 if tabs.current_widget == game
72 def item_name(type, data)
73 type == :game ? data.class.data(:id) : data
76 def combo_factory(name)
77 Factory.new do |parent|
78 themes = @loader.get_all_matching(name).map do |plugin|
79 [plugin.plugin_name, plugin]
81 themes = [['', nil]] + themes
82 KDE::ComboBox.from_a(parent, themes).tap do |combo|
83 combo.on(:current_index_changed, ["int"]) do |i|
85 item = send(type).current_item
86 @theme_loader.set(type, item_name(type, item.get),
87 name, combo.current_item.get) if item
93 def update(type = nil)
95 item = send(type).current_item
97 @combos.each do |component, _|
98 send(component).enabled = !!item
102 theme = @theme_loader.load_spec(type => item.get)
103 @combos.each do |component, _|
104 klass = theme[component]
105 send(component).select_item do |data|