lib/alexandria/ui/dialogs/acquire_dialog.rb in alexandria-book-collection-manager-0.7.2 vs lib/alexandria/ui/dialogs/acquire_dialog.rb in alexandria-book-collection-manager-0.7.3
- old
+ new
@@ -1,37 +1,21 @@
# frozen_string_literal: true
-# Copyright (C) 2004-2006 Laurent Sansonetti
-# Copyright (C) 2007 Cathal Mc Ginley
-# Copyright (C) 2011, 2016 Matijs van Zuijlen
+# This file is part of Alexandria.
#
-# 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.
-#
-# Alexandria is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with Alexandria; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 51 Franklin Street,
-# Fifth Floor, Boston, MA 02110-1301 USA.
+# See the file README.md for authorship and licensing information.
-# require 'monitor'
+require 'monitor'
require 'alexandria/scanners/cuecat'
require 'alexandria/scanners/keyboard'
-require 'alexandria/ui/sound'
+require 'alexandria/ui/builder_base'
require 'alexandria/ui/dialogs/barcode_animation'
+require 'alexandria/ui/sound'
module Alexandria
module UI
- require 'monitor'
-
# assists in turning on progress bar when searching
# and turning it off when all search threads have completed...
class SearchThreadCounter < Monitor
attr_reader :count
@@ -62,11 +46,11 @@
def initialize(parent, selected_library = nil, &block)
super('acquire_dialog__builder.glade', widget_names)
@acquire_dialog.transient_for = @parent = parent
@block = block
- libraries = Libraries.instance.all_regular_libraries
+ libraries = LibraryCollection.instance.all_regular_libraries
selected_library = libraries.first if selected_library.is_a?(SmartLibrary)
@combo_libraries.populate_with_libraries(libraries,
selected_library)
@add_button.sensitive = false
@@ -78,14 +62,12 @@
@search_thread_counter = SearchThreadCounter.new
@search_threads_running = @search_thread_counter.new_cond
end
def widget_names
- [:acquire_dialog, :dialog_vbox1, :dialog_action_area1,
- :help_button, :cancel_button, :add_button, :vbox1,
- :barcode_label, :scan_area, :scan_frame, :scrolledwindow1,
- :barcodes_treeview, :hbox1, :label1, :combo_libraries]
+ [:acquire_dialog, :add_button, :barcodes_treeview, :barcode_label,
+ :scan_area, :scan_frame, :combo_libraries]
end
def book_in_library(isbn10, library)
isbn13 = Library.canonicalise_ean(isbn10)
# puts "new book #{isbn10} (or #{isbn13})"
@@ -95,19 +77,19 @@
# puts "book #{book.isbn}"
# book == new_book
end
# puts "book_in_library match #{match.inspect}"
!match.nil?
- rescue
+ rescue StandardError
log.warn { "Failed to check for book #{isbn10} in library #{library}" }
true
end
def on_add
model = @barcodes_treeview.model
- libraries = Libraries.instance.all_libraries
+ libraries = LibraryCollection.instance.all_libraries
library, is_new_library =
@combo_libraries.selection_from_libraries(libraries)
# NOTE at this stage, the ISBN is 10-digit...
#
@@ -221,11 +203,11 @@
'There were %d duplicates',
isbn_duplicates.size) % isbn_duplicates.size
title = n_("Couldn't add this book",
"Couldn't add these books",
isbn_duplicates.size)
- ErrorDialog.new(@parent, title, message)
+ ErrorDialog.new(@acquire_dialog, title, message).display
end
@block.call(books, library, is_new_library)
end
@@ -419,11 +401,11 @@
def setup_scanner_area
@scanner_buffer = ''
scanner_name = @prefs.barcode_scanner
- @scanner = Alexandria::Scanners.find_scanner scanner_name ||
+ @scanner = Alexandria::Scanners.find_scanner(scanner_name) ||
Alexandria::Scanners.default_scanner # CueCat is default
log.debug { "Using #{@scanner.name} scanner" }
message = _('Ready to use %s barcode scanner') % @scanner.name
MainApp.instance.ui_manager.set_status_label(message)
@@ -529,13 +511,15 @@
def play_sound(effect)
if effect == 'scanning'
puts "Effect: #{effect}, playing: #{@prefs.play_scanning_sound}" if $DEBUG
return unless @prefs.play_scanning_sound
+
@sound_players['scanning'].play('scanning')
else
puts "Effect: #{effect}, playing: #{@prefs.play_scan_sound}" if $DEBUG
return unless @prefs.play_scan_sound
+
# sleep(0.5) # "scanning" effect lasts 0.5 seconds, wait for it to end
@sound_players[effect].play(effect)
end
end