C0 code coverage information
Generated on Tue Oct 16 11:40:50 -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.
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 require 'thread'
19
20 class Alexandria::ImportFilter
21 def to_filefilter
22 filefilter = Gtk::FileFilter.new
23 filefilter.name = name
24 patterns.each { |x| filefilter.add_pattern(x) }
25 return filefilter
26 end
27 end
28
29 module Alexandria
30 module UI
31 class SkipEntryDialog < AlertDialog
32 include GetText
33 GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
34
35 def initialize(parent, message)
36 super(parent, _("Error while importing"),
37 Gtk::Stock::DIALOG_QUESTION,
38 [[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
39 [_("_Continue"), Gtk::Dialog::RESPONSE_OK]],
40 message)
41 puts "Opened SkipEntryDialog #{self.inspect}" if $DEBUG
42 self.default_response = Gtk::Dialog::RESPONSE_CANCEL
43 show_all and @response = run
44 destroy
45 end
46
47 def continue?
48 @response == Gtk::Dialog::RESPONSE_OK
49 end
50 end
51
52 class ImportDialog < Gtk::FileChooserDialog
53 include GetText
54 GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
55
56 FILTERS = Alexandria::ImportFilter.all
57
58 def initialize(parent, &on_accept_cb)
59 super()
60 puts "ImportDialog opened." if $DEBUG
61 self.title = _("Import a Library")
62 self.action = Gtk::FileChooser::ACTION_OPEN
63 self.transient_for = parent
64 # self.deletable = false
65 running = false
66 add_button(Gtk::Stock::HELP, Gtk::Dialog::RESPONSE_HELP)
67 add_button(Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL)
68 import_button = add_button(_("_Import"),
69 Gtk::Dialog::RESPONSE_ACCEPT)
70 import_button.sensitive = false
71
72 self.signal_connect('destroy') { self.destroy unless running }
73
74 filters = {}
75 FILTERS.each do |filter|
76 filefilter = filter.to_filefilter
77 self.add_filter(filefilter)
78 puts "Added ImportFilter #{filefilter} -- #{filefilter.name}" if $DEBUG
79 filters[filefilter] = filter
80 end
81
82 self.signal_connect('selection_changed') do
83 import_button.sensitive =
84 self.filename and File.file?(self.filename)
85 end
86
87 # before adding the (hidden) progress bar, we must re-set the
88 # packing of the button box (currently packed at the end),
89 # because the progressbar will be *after* the button box.
90 buttonbox = self.vbox.children.last
91 options = self.vbox.query_child_packing(buttonbox)
92 options[-1] = Gtk::PACK_START
93 self.vbox.set_child_packing(buttonbox, *options)
94 self.vbox.reorder_child(buttonbox, 1)
95
96 pbar = Gtk::ProgressBar.new
97 pbar.show_text = true
98 self.vbox.pack_start(pbar, false)
99
100 on_progress = proc do |fraction|
101 pbar.show unless pbar.visible?
102 pbar.fraction = fraction
103 end
104
105 on_error = proc do |message|
106 SkipEntryDialog.new(parent, message).continue?
107 end
108
109 exec_queue = ExecutionQueue.new
110
111 while (response = run) != Gtk::Dialog::RESPONSE_CANCEL and
112 response != Gtk::Dialog::RESPONSE_DELETE_EVENT
113
114 if response == Gtk::Dialog::RESPONSE_HELP
115 begin
116 Gnome::Help.display('alexandria', 'import-library')
117 rescue => e
118 ErrorDialog.new(self, e.message)
119 end
120 next
121 end
122 file = File.basename(self.filename, '.*')
123 base = GLib.locale_to_utf8(file)
124 new_library_name = Library.generate_new_name(
125 Libraries.instance.all_libraries,
126 base)
127
128 filter = filters[self.filter]
129 puts "Going forward with filter: #{filter.name}" if $DEBUG
130 self.sensitive = false
131
132 filter.on_iterate do |n, total|
133 # convert to percents
134 coeff = total / 100.0
135 percent = n / coeff
136 # fraction between 0 and 1
137 fraction = percent / 100
138 puts "#{self.inspect} Percentage: #{fraction}" if $DEBUG
139 exec_queue.call(on_progress, fraction)
140 end
141
142 not_cancelled = true
143 filter.on_error do |message|
144 not_cancelled = exec_queue.sync_call(on_error, message)
145 puts "#{self.inspect} cancel state: #{not_cancelled}" if $DEBUG
146 end
147
148 library = nil
149 @bad_isbns = nil
150 thread = Thread.start do
151 library, @bad_isbns = filter.invoke(new_library_name,
152 self.filename)
153 end
154
155 while thread.alive?
156 #puts "Thread #{thread} still alive."
157 running = true
158 exec_queue.iterate
159 Gtk.main_iteration_do(false)
160 end
161
162 if library
163 on_accept_cb.call(library, @bad_isbns)
164 break
165 elsif not_cancelled
166 puts "Raising ErrorDialog because not_cancelled is #{not_cancelled}" if $DEBUG
167 ErrorDialog.new(parent,
168 _("Couldn't import the library"),
169 _("The format of the file you " +
170 "provided is unknown. Please " +
171 "retry with another file."))
172 end
173 pbar.hide
174 self.sensitive = true
175 end
176 destroy
177 end
178 end
179 end
180 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.