Class: Alexandria::UI::AcquireDialog
- Inherits:
-
BuilderBase
- Object
- BuilderBase
- Alexandria::UI::AcquireDialog
- Extended by:
- GetText
- Includes:
- ImageFetcher, Logging, GetText
- Defined in:
- lib/alexandria/ui/acquire_dialog.rb
Instance Attribute Summary collapse
-
#ui_manager ⇒ Object
readonly
end copy-n-paste.
Instance Method Summary collapse
- #book_in_library(isbn10, library) ⇒ Object
- #destroyed? ⇒ Boolean
-
#initialize(parent, ui_manager, selected_library, &block) ⇒ AcquireDialog
constructor
A new instance of AcquireDialog.
- #notify_end_add_by_isbn ⇒ Object
-
#notify_start_add_by_isbn ⇒ Object
begin copy-n-paste from new_book_dialog.
- #on_add ⇒ Object
- #on_cancel ⇒ Object
- #on_help ⇒ Object
- #read_barcode_scan ⇒ Object
- #show ⇒ Object
- #update(status, provider) ⇒ Object
- #widget_names ⇒ Object
Methods included from Logging
Methods included from ImageFetcher
Constructor Details
#initialize(parent, ui_manager, selected_library, &block) ⇒ AcquireDialog
Returns a new instance of AcquireDialog.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 58 def initialize(parent, ui_manager, selected_library, &block) super("acquire_dialog__builder.glade", ) @ui_manager = ui_manager @acquire_dialog.transient_for = @parent = parent @block = block 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 @prefs = Alexandria::Preferences.instance setup_scanner_area init_treeview @book_results = {} @search_thread_monitor = SearchThreadMonitor.new @search_threads_running = @search_thread_monitor.new_cond end |
Instance Attribute Details
#ui_manager ⇒ Object (readonly)
end copy-n-paste
298 299 300 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 298 def ui_manager @ui_manager end |
Instance Method Details
#book_in_library(isbn10, library) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 88 def book_in_library(isbn10, library) isbn13 = Library.canonicalise_ean(isbn10) isbns = [isbn10, isbn13] match = library.find do |book| isbns.include?(book.isbn) end !match.nil? rescue StandardError log.warn { "Failed to check for book #{isbn10} in library #{library}" } true end |
#destroyed? ⇒ Boolean
292 293 294 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 292 def destroyed? @acquire_dialog.destroyed? end |
#notify_end_add_by_isbn ⇒ Object
273 274 275 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 273 def notify_end_add_by_isbn ui_manager. end |
#notify_start_add_by_isbn ⇒ Object
begin copy-n-paste from new_book_dialog
269 270 271 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 269 def notify_start_add_by_isbn ui_manager.(self) end |
#on_add ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 100 def on_add model = @barcodes_treeview.model libraries = LibraryCollection.instance.all_libraries library, is_new_library = @combo_libraries.selection_from_libraries(libraries) # NOTE: at this stage, the ISBN is 10-digit... # selection = @barcodes_treeview.selection isbns = [] isbn_duplicates = [] adding_a_selection = false if selection.count_selected_rows > 0 adding_a_selection = true model.freeze_notify do # capture isbns selection.selected_each do |_mod, _path, iter| isbn = iter[0] if book_in_library(isbn, library) isbn_duplicates << isbn elsif isbns.include? isbn log.info { "detected duplicate in scanned list #{isbn}" } isbn_duplicates << isbn else isbns << isbn end end # try it this way... works because of persistent iters row_iters = [] selection.selected_rows.each do |path| iter = model.get_iter(path) isbn = iter[0] if book_in_library(isbn, library) log.debug { "#{isbn} is a duplicate" } elsif !@book_results.key?(isbn) # HAX log.debug { "no book found for #{isbn}, not adding" } # good enough for now else log.debug { "scheduling #{isbn} for removal from list" } row_iters << iter end end row_iters.each do |iter| log.debug { "removing iter #{iter[0]}" } model.remove(iter) end end else model.freeze_notify do # capture isbns row_iters = [] model.each do |_mod, _path, iter| isbn = iter[0] if !@book_results.key?(isbn) log.debug { "no book found for #{isbn}, not adding" } adding_a_selection = true elsif book_in_library(isbn, library) log.info { "#{isbn} is a duplicate" } isbn_duplicates << isbn elsif isbns.include? isbn log.info { "detected duplicate in scanned list #{isbn}" } isbn_duplicates << isbn else log.info { "scheduling #{isbn} for removal from list" } isbns << isbn row_iters << iter end end # remove list items if isbn_duplicates.empty? && !adding_a_selection model.clear # TODO: unless!!! row_iters.clear else row_iters.each do |iter| log.debug { "removing iter #{iter[0]}" } model.remove(iter) end end end end books = [] isbns.each do |isbn| log.debug { "Adding #{isbn}" } result = @book_results[isbn] if result.nil? # used to crash if book was not found in online lookup! adding_a_selection = true # ISBN not found, so keep it in the list # TODO (for 0.6.5) should offer to add this book manually else book = result[0] cover_uri = result[1] library.save_cover(book, cover_uri) unless cover_uri.nil? books << book library << book library.save(book) end end if isbn_duplicates.empty? @acquire_dialog.destroy unless adding_a_selection else = n_("There was %d duplicate", "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(@acquire_dialog, title, ).display end @block.call(books, library, is_new_library) end |
#on_cancel ⇒ Object
227 228 229 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 227 def on_cancel @acquire_dialog.destroy end |
#on_help ⇒ Object
231 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 231 def on_help; end |
#read_barcode_scan ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 233 def @animation.start play_sound("scanning") if @test_scan log.debug { "reading scanner data #{@scanner_buffer}" } = nil isbn = nil begin = @scanner.decode(@scanner_buffer) log.debug { "got barcode text #{}" } isbn = Library.canonicalise_isbn() # TODO: : use an AppFacade # isbn = LookupBook.get_isbn(barcode_text) rescue StandardError => ex log.error { "Bad scan: #{@scanner_buffer} #{ex}" } ensure @scanner_buffer = "" end if isbn log.debug { "Got ISBN #{isbn}" } play_sound("good_scan") @barcodes_treeview.model.freeze_notify do iter = @barcodes_treeview.model.append iter[0] = isbn iter[1] = Icons::BOOK iter[2] = "" end lookup_book(isbn) else log.debug { "was not an ISBN barcode" } play_sound("bad_scan") end end |
#show ⇒ Object
79 80 81 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 79 def show @acquire_dialog.show end |
#update(status, provider) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 277 def update(status, provider) GLib::Idle.add do = { searching: _("Searching Provider '%s'..."), error: _("Error while Searching Provider '%s'"), not_found: _("Not Found at Provider '%s'"), found: _("Found at Provider '%s'") } = [status] % provider log.debug { "update message : #{}" } ui_manager.set_status_label() false end end |
#widget_names ⇒ Object
83 84 85 86 |
# File 'lib/alexandria/ui/acquire_dialog.rb', line 83 def [:acquire_dialog, :add_button, :barcodes_treeview, :barcode_label, :scan_area, :scan_frame, :combo_libraries] end |