C0 code coverage information

Generated on Tue Oct 16 11:40:51 -0400 2007 with rcov 0.8.0


Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name Total lines Lines of code Total coverage Code coverage
lib/alexandria/ui/dialogs/preferences_dialog.rb 387 308
22.5% 
12.7% 
  1 # Copyright (C) 2004-2006 Laurent Sansonetti
  2 #
  3 # Alexandria is free software; you can redistribute it and/or
  4 # modify it under the terms of the GNU General Public License as
  5 # published by the Free Software Foundation; either version 2 of the
  6 # License, or (at your option) any later version.
  7 #
  8 # Alexandria is distributed in the hope that it will be useful,
  9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11 # General Public License for more details.
 12 #
 13 # You should have received a copy of the GNU General Public
 14 # License along with Alexandria; see the file COPYING.  If not,
 15 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 16 # Boston, MA 02111-1307, USA.
 17 
 18 class Gtk::Entry
 19     attr_writer :mandatory
 20     def mandatory?
 21         @mandatory
 22     end
 23 end
 24 
 25 module Alexandria
 26 module UI
 27     class ProviderPreferencesBaseDialog < Gtk::Dialog
 28         def initialize(*args)
 29             super(*args)
 30             
 31             self.has_separator = false
 32             self.resizable = false
 33             self.vbox.border_width = 12
 34             
 35             @controls = []
 36         end
 37 
 38         def fill_table(table, provider)
 39             i = table.n_rows
 40             table.resize(table.n_rows + provider.prefs.length,
 41                          table.n_columns)
 42             table.border_width = 12
 43             table.row_spacings = 6 
 44             table.column_spacings = 12
 45             
 46             @controls.clear
 47 
 48             provider.prefs.read.each do |variable|
 49                 label = Gtk::Label.new("_" + variable.description + ":")
 50                 label.use_underline = true
 51                 label.xalign = 0
 52                 table.attach_defaults(label, 0, 1, i, i + 1)
 53                
 54                 unless variable.possible_values.nil?
 55                     entry = Gtk::ComboBox.new
 56                     variable.possible_values.each do |value|
 57                         entry.append_text(value.to_s)
 58                     end
 59                     index = variable.possible_values.index(variable.value)
 60                     entry.active = index 
 61                 else
 62                     entry = Gtk::Entry.new
 63                     entry.text = variable.value.to_s
 64                     entry.mandatory = variable.mandatory?
 65                 end
 66                 label.mnemonic_widget = entry
 67 
 68                 @controls << [variable, entry]
 69 
 70                 table.attach_defaults(entry, 1, 2, i, i + 1)
 71                 i += 1
 72             end
 73             return table
 74         end
 75 
 76         def sync_variables
 77             @controls.each do |variable, entry|
 78                 variable.new_value = case entry
 79                     when Gtk::ComboBox
 80                         variable.possible_values[entry.active]
 81                     when Gtk::Entry
 82                         entry.text
 83                 end
 84             end
 85         end
 86     end
 87 
 88     class ProviderPreferencesDialog < ProviderPreferencesBaseDialog 
 89         include GetText
 90         GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
 91 
 92         def initialize(parent, provider)
 93             super(_("Preferences for %s") % provider.fullname,
 94                   parent,
 95                   Gtk::Dialog::MODAL,
 96                   [ Gtk::Stock::CLOSE, Gtk::Dialog::RESPONSE_CLOSE ])
 97             self.has_separator = false
 98             self.resizable = false
 99             self.vbox.border_width = 12
100             
101             table = Gtk::Table.new(0, 0)
102             fill_table(table, provider)
103             self.vbox.pack_start(table)
104            
105             self.signal_connect('destroy') { sync_variables }
106  
107             show_all
108             run
109             destroy
110         end
111     end
112     
113     class NewProviderDialog <  ProviderPreferencesBaseDialog
114         include GetText
115         GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
116 
117         def initialize(parent)
118             super(_("New Provider"),
119                   parent,
120                   Gtk::Dialog::MODAL,
121                   [ Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL ])
122             @add_button = add_button(Gtk::Stock::ADD, 
123                                      Gtk::Dialog::RESPONSE_ACCEPT)
124 
125             instances = BookProviders::abstract_classes.map { |x| x.new }
126             @selected_instance = nil
127  
128             @table = Gtk::Table.new(2, 2)
129             self.vbox.pack_start(@table)
130 
131             # Name.
132    
133             label_name = Gtk::Label.new(_("_Name:"))
134             label_name.use_underline = true
135             label_name.xalign = 0
136             @table.attach_defaults(label_name, 0, 1, 0, 1)
137             
138             entry_name = Gtk::Entry.new
139             entry_name.mandatory = true
140             label_name.mnemonic_widget = entry_name
141             @table.attach_defaults(entry_name, 1, 2, 0, 1)
142             
143             # Type.
144 
145             label_type = Gtk::Label.new(_("_Type:"))
146             label_type.use_underline = true
147             label_type.xalign = 0
148             @table.attach_defaults(label_type, 0, 1, 1, 2)
149             
150             combo_type = Gtk::ComboBox.new
151             instances.each do |instance|
152                 combo_type.append_text(instance.name)
153             end
154             combo_type.signal_connect('changed') do |cb|
155                 @selected_instance = instances[cb.active]
156                 fill_table(@table, @selected_instance)
157                 sensitize
158                 # FIXME this should be re-written once we have multiple
159                 # abstract providers.
160             end
161             combo_type.active = 0
162             label_type.mnemonic_widget = combo_type
163             @table.attach_defaults(combo_type, 1, 2, 1, 2)
164  
165             show_all
166             if run == Gtk::Dialog::RESPONSE_ACCEPT
167                 @selected_instance.reinitialize(entry_name.text)
168                 sync_variables
169             else
170                 @selected_instance = nil
171             end
172             destroy
173         end
174 
175         def instance
176             @selected_instance
177         end
178 
179         #######
180         private
181         #######
182 
183         def sensitize
184             entries = @table.children.select { |x| x.is_a?(Gtk::Entry) }
185             entries.each do |entry|
186                 entry.signal_connect('changed') do
187                     sensitive = true
188                     entries.each do |entry2|
189                         if entry2.mandatory?
190                             sensitive = !entry2.text.strip.empty?
191                             break unless sensitive
192                         end
193                     end
194                     @add_button.sensitive = sensitive
195                 end
196             end
197             @add_button.sensitive = false 
198         end
199     end
200 
201     class PreferencesDialog < GladeBase
202         include GetText
203         GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
204 
205         def initialize(parent, &changed_block)
206             super('preferences_dialog.glade')
207             @preferences_dialog.transient_for = parent
208             @changed_block = changed_block
209 
210             @cols = {
211                 @checkbutton_col_authors        => "col_authors_visible",
212                 @checkbutton_col_isbn           => "col_isbn_visible",
213                 @checkbutton_col_publisher      => "col_publisher_visible",
214                 @checkbutton_col_publish_date   => "col_publish_date_visible",
215                 @checkbutton_col_edition        => "col_edition_visible",
216                 @checkbutton_col_rating         => "col_rating_visible",
217 				@checkbutton_col_redd			=> "col_redd_visible",
218 				@checkbutton_col_own			=> "col_own_visible",
219 				@checkbutton_col_want			=> "col_want_visible"
220             }
221             @cols.each_pair do |checkbutton, pref_name|
222                 checkbutton.active = Preferences.instance.send(pref_name)
223             end           
224  
225             model = Gtk::ListStore.new(String, String)
226             @treeview_providers.model = model
227             reload_providers
228             model.signal_connect_after('row-changed') { update_priority }
229             column = Gtk::TreeViewColumn.new("Providers",
230                                              Gtk::CellRendererText.new,
231                                              :text => 0)
232             @treeview_providers.append_column(column)
233             @treeview_providers.selection.signal_connect('changed') \
234                 { sensitize_providers } 
235             
236             @button_prov_setup.sensitive = false
237             @button_prov_up.sensitive =  @button_prov_down.sensitive = 
238                 BookProviders.length > 1
239             
240             @buttonbox_prov.set_child_secondary(@button_prov_add, true)
241             @buttonbox_prov.set_child_secondary(@button_prov_remove, true)
242 
243             if BookProviders::abstract_classes.empty?
244                 @checkbutton_prov_advanced.visible = false
245             end
246         end
247 
248         def on_provider_setup
249             provider = selected_provider
250             unless provider.prefs.empty?
251                 ProviderPreferencesDialog.new(@preferences_dialog, provider)
252             end
253         end
254 
255         def on_provider_up
256             iter = @treeview_providers.selection.selected
257             previous_path = iter.path
258             previous_path.prev!
259             model = @treeview_providers.model
260             model.move_after(model.get_iter(previous_path), iter)
261             sensitize_providers
262             update_priority
263         end
264 
265         def on_provider_down
266             iter = @treeview_providers.selection.selected
267             next_iter = iter.dup
268             next_iter.next!
269             @treeview_providers.model.move_after(iter, next_iter)
270             sensitize_providers
271             update_priority
272         end
273 
274         def on_provider_advanced_toggled(checkbutton)
275             on = checkbutton.active?
276             @button_prov_add.visible = @button_prov_remove.visible = on
277         end
278 
279         def on_provider_add
280             dialog = NewProviderDialog.new(@preferences_dialog)
281             if new_provider = dialog.instance
282                 BookProviders.update_priority
283                 reload_providers
284             end
285         end
286 
287         def on_provider_remove
288             provider = selected_provider
289             dialog = AlertDialog.new(@main_app,
290                                      _("Are you sure you want to " +
291                                        "permanently delete the provider " +
292                                        "'%s'?") % provider.fullname, 
293                                      Gtk::Stock::DIALOG_QUESTION,
294                                      [[Gtk::Stock::CANCEL, 
295                                        Gtk::Dialog::RESPONSE_CANCEL],
296                                       [Gtk::Stock::DELETE, 
297                                        Gtk::Dialog::RESPONSE_OK]],
298                                      _("If you continue, the provider and " +
299                                        "all of its preferences will be " + 
300                                        "permanently deleted."))
301             dialog.default_response = Gtk::Dialog::RESPONSE_CANCEL
302             dialog.show_all
303             if dialog.run == Gtk::Dialog::RESPONSE_OK
304                 provider.remove
305                 BookProviders.update_priority
306                 reload_providers
307             end
308             dialog.destroy
309         end
310 
311         def on_column_toggled(checkbutton)
312             raise if @cols[checkbutton].nil?
313             Preferences.instance.send("#{@cols[checkbutton]}=", 
314                                       checkbutton.active?)
315             @changed_block.call
316         end
317 
318         def on_providers_button_press_event(widget, event)
319             # double left click
320             if event.event_type == Gdk::Event::BUTTON2_PRESS and
321                event.button == 1 
322 
323                 on_provider_setup
324             end
325         end
326         
327         def on_close
328             @preferences_dialog.destroy
329         end
330 
331         def on_help
332             begin
333                 Gnome::Help.display('alexandria', 'alexandria-preferences')
334             rescue => e 
335                 ErrorDialog.new(@preferences_dialog, e.message)
336             end
337         end
338 
339         #######
340         private
341         #######
342        
343         def reload_providers
344             model = @treeview_providers.model
345             model.clear
346             BookProviders.each do |x| 
347                 iter = model.append
348                 iter[0] = x.fullname
349                 iter[1] = x.name
350             end
351         end
352 
353         def selected_provider
354             iter = @treeview_providers.selection.selected
355             BookProviders.find { |x| x.name == iter[1] }
356         end
357 
358         def sensitize_providers 
359             model = @treeview_providers.model 
360             sel_iter = @treeview_providers.selection.selected
361             if sel_iter.nil?
362                 # No selection, we are probably called by ListStore#clear
363                 @button_prov_up.sensitive = false
364                 @button_prov_down.sensitive = false
365                 @button_prov_setup.sensitive = false
366                 @button_prov_remove.sensitive = false
367             else 
368                 last_iter = model.get_iter((BookProviders.length - 1).to_s)
369                 @button_prov_up.sensitive = sel_iter != model.iter_first
370                 @button_prov_down.sensitive = sel_iter != last_iter 
371                 provider = BookProviders.find { |x| x.name == sel_iter[1] }
372                 @button_prov_setup.sensitive = (not provider.prefs.empty?)
373                 @button_prov_remove.sensitive = provider.abstract?
374             end
375         end
376 
377         def update_priority
378             priority = []
379             @treeview_providers.model.each do |model, path, iter| 
380                 priority << iter[1]
381             end
382             Preferences.instance.providers_priority = priority
383             BookProviders.update_priority
384         end
385     end
386 end
387 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.

Valid XHTML 1.0! Valid CSS!