lib/alexandria/ui/dialogs/book_properties_dialog.rb in alexandria-book-collection-manager-0.6.9 vs lib/alexandria/ui/dialogs/book_properties_dialog.rb in alexandria-book-collection-manager-0.7.0
- old
+ new
@@ -1,6 +1,7 @@
# Copyright (C) 2004-2006 Laurent Sansonetti
+# Copyright (C) 2016 Matijs van Zuijlen
#
# Alexandria is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
@@ -25,37 +26,37 @@
def initialize(parent, library, book)
super(parent, library.cover(book))
puts 'Initializing Book Properties Dialog...' if $DEBUG
- cancel_button = Gtk::Button.new(Gtk::Stock::CANCEL)
+ cancel_button = Gtk::Button.new(stock_id: Gtk::Stock::CANCEL)
cancel_button.signal_connect('clicked') { on_cancel }
cancel_button.show
@button_box << cancel_button
- close_button = Gtk::Button.new(Gtk::Stock::SAVE)
+ close_button = Gtk::Button.new(stock_id: Gtk::Stock::SAVE)
close_button.signal_connect('clicked') { on_close }
close_button.show
@button_box << close_button
- help_button = Gtk::Button.new(Gtk::Stock::HELP)
+ help_button = Gtk::Button.new(stock_id: Gtk::Stock::HELP)
help_button.signal_connect('clicked') { on_help }
help_button.show
@button_box << help_button
@button_box.set_child_secondary(help_button, true)
@entry_title.text = @book_properties_dialog.title = book.title
- @entry_isbn.text = (book.isbn or '')
+ @entry_isbn.text = (book.isbn || '')
@entry_publisher.text = book.publisher
@entry_publish_date.text = book.publishing_year.to_s
@entry_publish_date.signal_connect('focus-out-event') do
text = @entry_publish_date.text
if text.empty?
false
else
year = text.to_i
- if year == 0 or year > (Time.now.year + 10) or year < 10
+ if year.zero? || year > (Time.now.year + 10) || year < 10
@entry_publish_date.text = ''
@entry_publish_date.grab_focus
true
elsif year < 100
@entry_publish_date.text = '19' + year.to_s
@@ -73,19 +74,20 @@
iter[0] = author
iter[1] = true
end
buffer = Gtk::TextBuffer.new
- buffer.text = (book.notes or '')
+ buffer.text = (book.notes || '')
@textview_notes.buffer = buffer
- @library, @book = library, book
+ @library = library
+ @book = book
self.cover = Icons.cover(library, book)
- self.rating = (book.rating or Book::DEFAULT_RATING)
+ self.rating = (book.rating || Book::DEFAULT_RATING)
if (@checkbutton_loaned.active = book.loaned?)
- @entry_loaned_to.text = (book.loaned_to or '')
+ @entry_loaned_to.text = (book.loaned_to || '')
self.loaned_since = book.loaned_since
@date_loaned_since.sensitive = true
else
@date_loaned_since.sensitive = false
end
@@ -115,11 +117,11 @@
if @entry_isbn.text == ''
# If set to nil .to_yaml in library.save causes crash
@book.isbn = ''
else
ary = @library.select { |book| book.ident == @entry_isbn.text }
- unless ary.empty? or (ary.length == 1 and ary.first == @book)
+ unless ary.empty? || ((ary.length == 1) && (ary.first == @book))
ErrorDialog.new(@parent,
_("Couldn't modify the book"),
_('The EAN/ISBN you provided is already ' \
'used in this library.'))
return
@@ -136,11 +138,11 @@
end
end
@book.title = @entry_title.text
@book.publisher = @entry_publisher.text
year = @entry_publish_date.text.to_i
- @book.publishing_year = year == 0 ? nil : year
+ @book.publishing_year = year.zero? ? nil : year
@book.edition = @entry_edition.text
@book.authors = []
@treeview_authors.model.each { |_m, _p, i| @book.authors << i[0] }
@book.notes = @textview_notes.buffer.text
@book.rating = @current_rating
@@ -162,27 +164,20 @@
if @book.redd
redd_date = @redd_date.text
if redd_date.strip.empty?
@book.redd_when = nil
else
- begin
- t = parse_date(redd_date)
- @book.redd_when = t
- rescue => err
- puts err
- puts err.backtrace
- end
+ t = parse_date(redd_date)
+ @book.redd_when = t
end
else
@book.redd_when = nil
end
@book.own = @checkbutton_own.active?
@book.want = @checkbutton_want.active?
@book.tags = @entry_tags.text.split(',') # tags are comma separated
- if @delete_cover_file
- FileUtils.rm_f(@cover_file)
- end
+ FileUtils.rm_f(@cover_file) if @delete_cover_file
if @original_cover_file
FileUtils.rm_f(@original_cover_file)
end