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 module Alexandria
19 module UI
20 class NewBookDialogManual < BookPropertiesDialogBase
21 include GetText
22 extend GetText
23 GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
24
25 TMP_COVER_FILE = File.join(Dir.tmpdir, "tmp_cover")
26 def initialize(parent, library, &on_add_cb)
27 super(parent, TMP_COVER_FILE)
28
29 @library, @on_add_cb = library, on_add_cb
30 FileUtils.rm_f(TMP_COVER_FILE)
31
32 cancel_button = Gtk::Button.new(Gtk::Stock::CANCEL)
33 cancel_button.signal_connect('clicked') { on_cancel }
34 cancel_button.show
35 @button_box << cancel_button
36
37 add_button = Gtk::Button.new(Gtk::Stock::ADD)
38 add_button.signal_connect('clicked') { on_add }
39 add_button.show
40 @button_box << add_button
41
42 help_button = Gtk::Button.new(Gtk::Stock::HELP)
43 help_button.signal_connect('clicked') { on_help }
44 help_button.show
45 @button_box << help_button
46 @button_box.set_child_secondary(help_button, true)
47
48 self.rating = Book::DEFAULT_RATING
49 self.cover = Icons::BOOK_ICON
50
51 on_title_changed
52 end
53
54 def on_title_changed
55 title = @entry_title.text.strip
56 begin
57 @book_properties_dialog.title = unless title.empty?
58 _("Adding '%s'") % title
59 else
60 _("Adding a Book")
61 end
62 rescue
63 raise "There's a problem with a book somewhere"
64 end
65 end
66
67 #######
68 private
69 #######
70
71 def on_cancel
72 @book_properties_dialog.destroy
73 end
74
75 class AddError < StandardError
76 end
77
78 def on_add
79 begin
80 if (title = @entry_title.text.strip).empty?
81 raise AddError.new(_("A title must be provided."))
82 end
83
84 isbn = nil
85 if @entry_isbn.text != ""
86 ary = @library.select { |book| book.ident ==
87 @entry_isbn.text }
88 raise AddError.new(_("The EAN/ISBN you provided is " +
89 "already used in this library.")) \
90 unless ary.empty?
91 isbn = begin
92 Library.canonicalise_isbn(@entry_isbn.text)
93 rescue Alexandria::Library::InvalidISBNError
94 raise AddError.new(_("Couldn't validate the " +
95 "EAN/ISBN you provided. Make " +
96 "sure it is written correcty, " +
97 "and try again."))
98 end
99 end
100
101 if (publisher = @entry_publisher.text.strip).empty?
102 raise AddError.new(_("A publisher must be provided."))
103 end
104
105 publishing_year = @entry_publish_date.text.to_i
106
107 if (edition = @entry_edition.text.strip).empty?
108 raise AddError.new(_("A binding must be provided."))
109 end
110
111 authors = []
112 @treeview_authors.model.each { |m, p, i| authors << i[0] }
113 if authors.empty?
114 raise AddError.new(_("At least one author must be " +
115 "provided."))
116 end
117
118 book = Book.new(title, authors, isbn, publisher,
119 publishing_year == 0 ? nil : publishing_year,
120 edition)
121 book.rating = @current_rating
122 book.notes = @textview_notes.buffer.text
123 book.loaned = @checkbutton_loaned.active?
124 book.loaned_to = @entry_loaned_to.text
125 book.loaned_since = Time.at(@date_loaned_since.time)
126
127 @library << book
128 @library.save(book)
129 if File.exists?(TMP_COVER_FILE)
130 FileUtils.cp(TMP_COVER_FILE, @library.cover(book))
131 end
132
133 @on_add_cb.call(book)
134 @book_properties_dialog.destroy
135 rescue AddError => e
136 ErrorDialog.new(@parent, _("Couldn't add the book"),
137 e.message)
138 end
139 end
140
141 def on_help
142 begin
143 Gnome::Help.display('alexandria', 'add-book-manually')
144 rescue => e
145 ErrorDialog.new(@preferences_dialog, e.message)
146 end
147 end
148 end
149 end
150 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.