alexandria-book-collection-manager 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -25
  3. data/.rubocop_todo.yml +87 -67
  4. data/CHANGELOG.md +12 -1
  5. data/Gemfile +4 -3
  6. data/README.md +16 -6
  7. data/Rakefile +71 -72
  8. data/alexandria-book-collection-manager.gemspec +44 -44
  9. data/bin/alexandria +12 -12
  10. data/lib/alexandria.rb +22 -22
  11. data/lib/alexandria/about.rb +50 -50
  12. data/lib/alexandria/book_providers.rb +50 -50
  13. data/lib/alexandria/book_providers/adlibris.rb +28 -44
  14. data/lib/alexandria/book_providers/amazon_aws.rb +64 -64
  15. data/lib/alexandria/book_providers/amazon_ecs_util.rb +52 -78
  16. data/lib/alexandria/book_providers/barnes_and_noble.rb +34 -34
  17. data/lib/alexandria/book_providers/douban.rb +21 -37
  18. data/lib/alexandria/book_providers/proxis.rb +24 -24
  19. data/lib/alexandria/book_providers/pseudomarc.rb +19 -19
  20. data/lib/alexandria/book_providers/renaud.rb +44 -57
  21. data/lib/alexandria/book_providers/siciliano.rb +39 -39
  22. data/lib/alexandria/book_providers/thalia.rb +33 -33
  23. data/lib/alexandria/book_providers/web.rb +5 -5
  24. data/lib/alexandria/book_providers/worldcat.rb +44 -69
  25. data/lib/alexandria/book_providers/z3950.rb +94 -109
  26. data/lib/alexandria/config.rb +1 -1
  27. data/lib/alexandria/console.rb +3 -3
  28. data/lib/alexandria/export_format.rb +8 -8
  29. data/lib/alexandria/export_library.rb +112 -113
  30. data/lib/alexandria/import_library.rb +45 -45
  31. data/lib/alexandria/import_library_csv.rb +30 -30
  32. data/lib/alexandria/library_collection.rb +4 -4
  33. data/lib/alexandria/library_sort_order.rb +1 -1
  34. data/lib/alexandria/library_store.rb +14 -14
  35. data/lib/alexandria/logging.rb +5 -5
  36. data/lib/alexandria/models/book.rb +1 -1
  37. data/lib/alexandria/models/library.rb +36 -36
  38. data/lib/alexandria/net.rb +5 -5
  39. data/lib/alexandria/preferences.rb +32 -32
  40. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +13 -13
  41. data/lib/alexandria/scanners/keyboard.rb +5 -5
  42. data/lib/alexandria/smart_library.rb +53 -53
  43. data/lib/alexandria/ui.rb +15 -15
  44. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +1 -1
  45. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +66 -65
  46. data/lib/alexandria/ui/{dialogs/alert_dialog.rb → alert_dialog.rb} +1 -16
  47. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +0 -0
  48. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +7 -7
  49. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -37
  50. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +38 -37
  51. data/lib/alexandria/ui/builder_base.rb +1 -1
  52. data/lib/alexandria/ui/callbacks.rb +95 -91
  53. data/lib/alexandria/ui/completion_models.rb +7 -21
  54. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  55. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  56. data/lib/alexandria/ui/dndable.rb +7 -7
  57. data/lib/alexandria/ui/error_dialog.rb +25 -0
  58. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +22 -42
  59. data/lib/alexandria/ui/icons.rb +6 -6
  60. data/lib/alexandria/ui/iconview.rb +7 -7
  61. data/lib/alexandria/ui/iconview_tooltips.rb +6 -6
  62. data/lib/alexandria/ui/{dialogs/import_dialog.rb → import_dialog.rb} +14 -32
  63. data/lib/alexandria/ui/init.rb +16 -29
  64. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +6 -4
  65. data/lib/alexandria/ui/libraries_combo.rb +7 -7
  66. data/lib/alexandria/ui/listview.rb +40 -40
  67. data/lib/alexandria/ui/main_app.rb +22 -24
  68. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  69. data/lib/alexandria/ui/multi_drag_treeview.rb +4 -4
  70. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +46 -45
  71. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +20 -19
  72. data/lib/alexandria/ui/new_provider_dialog.rb +99 -0
  73. data/lib/alexandria/ui/{dialogs/new_smart_library_dialog.rb → new_smart_library_dialog.rb} +4 -4
  74. data/lib/alexandria/ui/{dialogs/preferences_dialog.rb → preferences_dialog.rb} +44 -235
  75. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +90 -0
  76. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  77. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +6 -27
  78. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +27 -25
  79. data/lib/alexandria/ui/skip_entry_dialog.rb +32 -0
  80. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog.rb → smart_library_properties_dialog.rb} +2 -2
  81. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +30 -30
  82. data/lib/alexandria/ui/sound.rb +8 -8
  83. data/lib/alexandria/ui/ui_manager.rb +136 -135
  84. data/lib/alexandria/version.rb +4 -19
  85. data/lib/alexandria/web_themes.rb +8 -8
  86. data/po/cs.po +97 -97
  87. data/po/cy.po +97 -97
  88. data/po/de.po +97 -97
  89. data/po/el.po +97 -97
  90. data/po/es.po +97 -97
  91. data/po/fr.po +97 -97
  92. data/po/ga.po +97 -97
  93. data/po/gl.po +97 -97
  94. data/po/it.po +97 -97
  95. data/po/ja.po +97 -97
  96. data/po/mk.po +97 -97
  97. data/po/nb.po +97 -97
  98. data/po/nl.po +97 -97
  99. data/po/pl.po +97 -97
  100. data/po/pt.po +97 -97
  101. data/po/pt_BR.po +97 -97
  102. data/po/ru.po +97 -97
  103. data/po/sk.po +97 -97
  104. data/po/sv.po +97 -97
  105. data/po/uk.po +97 -97
  106. data/po/zh_TW.po +97 -97
  107. data/schemas/alexandria.schemas +24 -2
  108. data/spec/alexandria/book_providers_spec.rb +65 -82
  109. data/spec/alexandria/book_spec.rb +12 -10
  110. data/spec/alexandria/console_spec.rb +9 -9
  111. data/spec/alexandria/export_library_spec.rb +31 -31
  112. data/spec/alexandria/library_spec.rb +86 -86
  113. data/spec/alexandria/library_store_spec.rb +8 -8
  114. data/spec/alexandria/preferences_spec.rb +18 -17
  115. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  116. data/spec/alexandria/smart_library_spec.rb +15 -15
  117. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  118. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  119. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  120. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  121. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  122. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  123. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  124. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  125. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  126. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  127. data/spec/alexandria/ui/import_dialog_spec.rb +14 -0
  128. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  129. data/spec/alexandria/ui/main_app_spec.rb +6 -6
  130. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  131. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  132. data/spec/alexandria/ui/new_provider_dialog_spec.rb +14 -0
  133. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +14 -0
  134. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  135. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +19 -0
  136. data/spec/alexandria/ui/really_delete_dialog_spec.rb +15 -0
  137. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  138. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  139. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +18 -0
  140. data/spec/alexandria/ui/sound_spec.rb +2 -2
  141. data/spec/alexandria/ui/ui_manager_spec.rb +6 -20
  142. data/spec/alexandria/ui/ui_utilities_spec.rb +9 -9
  143. data/spec/alexandria/utilities_spec.rb +6 -6
  144. data/spec/end_to_end/basic_run_spec.rb +24 -36
  145. data/spec/spec_helper.rb +9 -9
  146. data/tasks/dogtail.rake +1 -1
  147. data/tasks/setup.rb +2 -2
  148. data/tasks/spec.rake +11 -11
  149. data/util/rake/fileinstall.rb +25 -25
  150. data/util/rake/gettextgenerate.rb +7 -7
  151. data/util/rake/omfgenerate.rb +7 -7
  152. metadata +59 -33
  153. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  154. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  155. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
@@ -18,7 +18,7 @@
18
18
  # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
19
  # Fifth Floor, Boston, MA 02110-1301 USA.
20
20
 
21
- require 'alexandria/scanners'
21
+ require "alexandria/scanners"
22
22
 
23
23
  module Alexandria
24
24
  module Scanners
@@ -27,22 +27,22 @@ module Alexandria
27
27
  # like this.)
28
28
  class KeyboardWedge
29
29
  def name
30
- 'KeyboardWedge'
30
+ "KeyboardWedge"
31
31
  end
32
32
 
33
33
  def display_name
34
- 'Keyboard Wedge'
34
+ "Keyboard Wedge"
35
35
  end
36
36
 
37
37
  # Checks if data looks like a completed scan
38
38
  def match?(data)
39
- data.gsub!(/\s/, '')
39
+ data.gsub!(/\s/, "")
40
40
  (data =~ /[0-9]{12,18}/) || (data =~ /[0-9]{9}[0-9Xx]/)
41
41
  end
42
42
 
43
43
  # Gets the essential 13-digits from an ISBN barcode (EAN-13)
44
44
  def decode(data)
45
- data.gsub!(/\s/, '')
45
+ data.gsub!(/\s/, "")
46
46
  if data.length == 10
47
47
  return data
48
48
  elsif data.length >= 13
@@ -5,27 +5,27 @@
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
7
  # require 'date'
8
- require 'time'
8
+ require "time"
9
9
 
10
10
  module Alexandria
11
11
  class SmartLibrary < Array
12
12
  include Logging
13
13
  include GetText
14
14
  extend GetText
15
- bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
15
+ bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
16
16
 
17
17
  ALL_RULES = 1
18
18
  ANY_RULE = 2
19
19
  attr_reader :name
20
20
  attr_accessor :rules, :predicate_operator_rule, :deleted_books
21
21
 
22
- EXT = '.yaml'
22
+ EXT = ".yaml"
23
23
 
24
24
  def initialize(name, rules, predicate_operator_rule, store = nil)
25
25
  super()
26
26
  raise if name.nil? || rules.nil? || predicate_operator_rule.nil?
27
27
 
28
- @name = name.dup.force_encoding('UTF-8')
28
+ @name = name.dup.force_encoding("UTF-8")
29
29
  @rules = rules
30
30
  @predicate_operator_rule = predicate_operator_rule
31
31
  @store = store
@@ -46,25 +46,25 @@ module Alexandria
46
46
  rule = Rule.new(operands.find { |x| x.book_selector == :rating },
47
47
  Rule::Operators::IS,
48
48
  Book::MAX_RATING_STARS.to_s)
49
- a << new(_('Favorite'), [rule], ALL_RULES, store)
49
+ a << new(_("Favorite"), [rule], ALL_RULES, store)
50
50
 
51
51
  # Loaned books.
52
52
  rule = Rule.new(operands.find { |x| x.book_selector == :loaned },
53
53
  Rule::Operators::IS_TRUE,
54
54
  nil)
55
- a << new(_('Loaned'), [rule], ALL_RULES, store)
55
+ a << new(_("Loaned"), [rule], ALL_RULES, store)
56
56
 
57
57
  # Redd books.
58
58
  rule = Rule.new(operands.find { |x| x.book_selector == :redd },
59
59
  Rule::Operators::IS_TRUE,
60
60
  nil)
61
- a << new(_('Read'), [rule], ALL_RULES, store)
61
+ a << new(_("Read"), [rule], ALL_RULES, store)
62
62
 
63
63
  # Own books.
64
64
  rule = Rule.new(operands.find { |x| x.book_selector == :own },
65
65
  Rule::Operators::IS_TRUE,
66
66
  nil)
67
- a << new(_('Owned'), [rule], ALL_RULES, store)
67
+ a << new(_("Owned"), [rule], ALL_RULES, store)
68
68
 
69
69
  # Want books.
70
70
  rule = Rule.new(operands.find { |x| x.book_selector == :want },
@@ -73,7 +73,7 @@ module Alexandria
73
73
  rule2 = Rule.new(operands.find { |x| x.book_selector == :own },
74
74
  Rule::Operators::IS_NOT_TRUE,
75
75
  nil)
76
- a << new(_('Wishlist'), [rule, rule2], ALL_RULES, store)
76
+ a << new(_("Wishlist"), [rule, rule2], ALL_RULES, store)
77
77
 
78
78
  a
79
79
  end
@@ -148,7 +148,7 @@ module Alexandria
148
148
  @cache[book].save(book)
149
149
  else
150
150
  FileUtils.mkdir_p(base_dir) unless File.exist? base_dir
151
- File.open(yaml, 'w') { |io| io.puts to_hash.to_yaml }
151
+ File.open(yaml, "w") { |io| io.puts to_hash.to_yaml }
152
152
  end
153
153
  end
154
154
 
@@ -197,8 +197,8 @@ module Alexandria
197
197
 
198
198
  def delete
199
199
  if @@deleted_libraries.include?(self)
200
- puts 'Already deleted a SmartLibrary with this name'
201
- puts '(this might mess up undeletes...)'
200
+ puts "Already deleted a SmartLibrary with this name"
201
+ puts "(this might mess up undeletes...)"
202
202
  FileUtils.rm_rf(yaml)
203
203
  # so we just delete the old smart library, and
204
204
  # 'pending' delete the new one of the same name...
@@ -233,7 +233,7 @@ module Alexandria
233
233
  class Rule
234
234
  include GetText
235
235
  extend GetText
236
- bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
236
+ bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
237
237
 
238
238
  attr_accessor :operand, :operation, :value
239
239
 
@@ -289,78 +289,78 @@ module Alexandria
289
289
  module Operands
290
290
  include GetText
291
291
  extend GetText
292
- bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
292
+ bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
293
293
 
294
294
  LEFT = [
295
- LeftOperand.new(:title, _('Title'), String),
296
- LeftOperand.new(:isbn, _('ISBN'), String),
297
- LeftOperand.new(:authors, _('Authors'), String),
298
- LeftOperand.new(:publisher, _('Publisher'), String),
299
- LeftOperand.new(:publishing_year, _('Publish Year'), Integer),
300
- LeftOperand.new(:edition, _('Binding'), String),
301
- LeftOperand.new(:rating, _('Rating'), Integer),
302
- LeftOperand.new(:notes, _('Notes'), String),
303
- LeftOperand.new(:tags, _('Tags'), Array),
304
- LeftOperand.new(:loaned, _('Loaning State'), TrueClass),
305
- LeftOperand.new(:loaned_since, _('Loaning Date'), Time),
306
- LeftOperand.new(:loaned_to, _('Loaning Person'), String),
307
- LeftOperand.new(:redd, _('Read'), TrueClass),
308
- LeftOperand.new(:redd_when, _('Date Read'), Time),
309
- LeftOperand.new(:own, _('Own'), TrueClass),
310
- LeftOperand.new(:want, _('Want'), TrueClass),
295
+ LeftOperand.new(:title, _("Title"), String),
296
+ LeftOperand.new(:isbn, _("ISBN"), String),
297
+ LeftOperand.new(:authors, _("Authors"), String),
298
+ LeftOperand.new(:publisher, _("Publisher"), String),
299
+ LeftOperand.new(:publishing_year, _("Publish Year"), Integer),
300
+ LeftOperand.new(:edition, _("Binding"), String),
301
+ LeftOperand.new(:rating, _("Rating"), Integer),
302
+ LeftOperand.new(:notes, _("Notes"), String),
303
+ LeftOperand.new(:tags, _("Tags"), Array),
304
+ LeftOperand.new(:loaned, _("Loaning State"), TrueClass),
305
+ LeftOperand.new(:loaned_since, _("Loaning Date"), Time),
306
+ LeftOperand.new(:loaned_to, _("Loaning Person"), String),
307
+ LeftOperand.new(:redd, _("Read"), TrueClass),
308
+ LeftOperand.new(:redd_when, _("Date Read"), Time),
309
+ LeftOperand.new(:own, _("Own"), TrueClass),
310
+ LeftOperand.new(:want, _("Want"), TrueClass),
311
311
  ].sort
312
312
 
313
313
  STRING = Operand.new(nil, String)
314
314
  STRING_ARRAY = Operand.new(nil, String)
315
315
  INTEGER = Operand.new(nil, Integer)
316
316
  TIME = Operand.new(nil, Time)
317
- DAYS = Operand.new(_('days'), Integer)
317
+ DAYS = Operand.new(_("days"), Integer)
318
318
  end
319
319
 
320
320
  module Operators
321
321
  include Logging
322
322
  include GetText
323
323
  extend GetText
324
- bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
324
+ bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
325
325
 
326
326
  IS_TRUE = Operator.new(:is_true,
327
- _('is set'),
327
+ _("is set"),
328
328
  proc { |x| x })
329
329
  IS_NOT_TRUE = Operator.new(:is_not_true,
330
- _('is not set'),
330
+ _("is not set"),
331
331
  proc { |x| !x })
332
332
  IS = Operator.new(:is,
333
- _('is'),
333
+ _("is"),
334
334
  proc { |x, y| x == y })
335
335
  IS_NOT = Operator.new(:is_not,
336
- _('is not'),
336
+ _("is not"),
337
337
  proc { |x, y| x != y })
338
338
  CONTAINS = Operator.new(:contains,
339
- _('contains'),
339
+ _("contains"),
340
340
  proc { |x, y| x.include?(y) })
341
341
  DOES_NOT_CONTAIN = Operator.new(:does_not_contain,
342
- _('does not contain'),
342
+ _("does not contain"),
343
343
  proc { |x, y| !x.include?(y) })
344
344
  STARTS_WITH = Operator.new(:starts_with,
345
- _('starts with'),
345
+ _("starts with"),
346
346
  proc { |x, y| /^#{y}/.match(x) })
347
347
  ENDS_WITH = Operator.new(:ends_with,
348
- _('ends with'),
348
+ _("ends with"),
349
349
  proc { |x, y| /#{y}$/.match(x) })
350
350
  IS_GREATER_THAN = Operator.new(:is_greater_than,
351
- _('is greater than'),
351
+ _("is greater than"),
352
352
  proc { |x, y| x > y })
353
353
  IS_LESS_THAN = Operator.new(:is_less_than,
354
- _('is less than'),
354
+ _("is less than"),
355
355
  proc { |x, y| x < y })
356
356
  IS_AFTER = Operator.new(:is_after,
357
- _('is after'),
357
+ _("is after"),
358
358
  proc { |x, y| x.to_i > y.to_i && !x.nil? })
359
359
  IS_BEFORE = Operator.new(:is_before,
360
- _('is before'),
360
+ _("is before"),
361
361
  proc { |x, y| x.to_i < y.to_i && !x.nil? })
362
362
  IS_IN_LAST = Operator.new(:is_in_last_days,
363
- _('is in last'),
363
+ _("is in last"),
364
364
  proc { |x, y|
365
365
  begin
366
366
  if x.nil? || x.empty?
@@ -379,7 +379,7 @@ module Alexandria
379
379
  end
380
380
  })
381
381
  IS_NOT_IN_LAST = Operator.new(:is_not_in_last_days,
382
- _('is not in last'),
382
+ _("is not in last"),
383
383
  proc { |x, y|
384
384
  begin
385
385
  if x.nil? || x.empty?
@@ -441,15 +441,15 @@ module Alexandria
441
441
 
442
442
  def self.operations_for_operand(operand)
443
443
  case operand.klass.name
444
- when 'String'
444
+ when "String"
445
445
  STRING_OPERATORS.map { |x| [x, Operands::STRING] }
446
- when 'Array'
446
+ when "Array"
447
447
  STRING_ARRAY_OPERATORS.map { |x| [x, Operands::STRING] }
448
- when 'Integer'
448
+ when "Integer"
449
449
  INTEGER_OPERATORS.map { |x| [x, Operands::INTEGER] }
450
- when 'TrueClass'
450
+ when "TrueClass"
451
451
  BOOLEAN_OPERATORS.map { |x| [x, nil] }
452
- when 'Time'
452
+ when "Time"
453
453
  TIME_OPERATORS.map do |x|
454
454
  if (x == Operators::IS_IN_LAST) ||
455
455
  (x == Operators::IS_NOT_IN_LAST)
@@ -468,8 +468,8 @@ module Alexandria
468
468
  proc do |book|
469
469
  begin
470
470
  left_value = book.send(@operand.book_selector)
471
- rescue StandardError => e
472
- puts e.message
471
+ rescue StandardError => ex
472
+ puts ex.message
473
473
  end
474
474
  right_value = @value
475
475
  if right_value.is_a?(String)
@@ -17,35 +17,35 @@
17
17
  # write to the Free Software Foundation, Inc., 51 Franklin Street,
18
18
  # Fifth Floor, Boston, MA 02110-1301 USA.
19
19
 
20
- require 'gdk_pixbuf2'
21
- require 'gtk3'
20
+ require "gdk_pixbuf2"
21
+ require "gtk3"
22
22
 
23
- require 'alexandria/ui/icons'
24
- require 'alexandria/ui/builder_base'
25
- require 'alexandria/ui/completion_models'
26
- require 'alexandria/ui/libraries_combo'
27
- require 'alexandria/ui/multi_drag_treeview'
28
- require 'alexandria/ui/main_app'
23
+ require "alexandria/ui/icons"
24
+ require "alexandria/ui/builder_base"
25
+ require "alexandria/ui/completion_models"
26
+ require "alexandria/ui/libraries_combo"
27
+ require "alexandria/ui/multi_drag_treeview"
28
+ require "alexandria/ui/main_app"
29
29
 
30
30
  module Alexandria
31
31
  module UI
32
32
  include Logging
33
33
  def self.init_icons
34
- log.info { 'Initializing Icons...' }
34
+ log.info { "Initializing Icons..." }
35
35
  Icons.init
36
36
  end
37
37
 
38
38
  def self.start_main_app
39
- puts '==========================' if $DEBUG
40
- log.info { 'Starting MainApp...' }
41
- puts '==========================' if $DEBUG
39
+ puts "==========================" if $DEBUG
40
+ log.info { "Starting MainApp..." }
41
+ puts "==========================" if $DEBUG
42
42
  MainApp.instance
43
43
  end
44
44
 
45
45
  def self.start_gtk
46
- puts '====================================' if $DEBUG
47
- log.info { 'Starting Gtk...' }
48
- puts '====================================' if $DEBUG
46
+ puts "====================================" if $DEBUG
47
+ log.info { "Starting Gtk..." }
48
+ puts "====================================" if $DEBUG
49
49
  Gtk.main
50
50
  end
51
51
 
@@ -38,7 +38,7 @@ module Alexandria
38
38
  @dialog.website = Alexandria::WEBSITE_URL
39
39
  @dialog.license = GPL
40
40
  @dialog.transient_for = parent
41
- @dialog.signal_connect('response') { @dialog.destroy }
41
+ @dialog.signal_connect("response") { @dialog.destroy }
42
42
  end
43
43
 
44
44
  def show
@@ -4,13 +4,14 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
- require 'monitor'
8
- require 'alexandria/scanners/cuecat'
9
- require 'alexandria/scanners/keyboard'
7
+ require "monitor"
8
+ require "alexandria/scanners/cue_cat"
9
+ require "alexandria/scanners/keyboard"
10
10
 
11
- require 'alexandria/ui/builder_base'
12
- require 'alexandria/ui/dialogs/barcode_animation'
13
- require 'alexandria/ui/sound'
11
+ require "alexandria/ui/builder_base"
12
+ require "alexandria/ui/barcode_animation"
13
+ require "alexandria/ui/error_dialog"
14
+ require "alexandria/ui/sound"
14
15
 
15
16
  module Alexandria
16
17
  module UI
@@ -41,10 +42,10 @@ module Alexandria
41
42
  include GetText
42
43
  include Logging
43
44
  extend GetText
44
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
45
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
45
46
 
46
47
  def initialize(parent, selected_library = nil, &block)
47
- super('acquire_dialog__builder.glade', widget_names)
48
+ super("acquire_dialog__builder.glade", widget_names)
48
49
  @acquire_dialog.transient_for = @parent = parent
49
50
  @block = block
50
51
 
@@ -199,8 +200,8 @@ module Alexandria
199
200
  if isbn_duplicates.empty?
200
201
  @acquire_dialog.destroy unless adding_a_selection
201
202
  else
202
- message = n_('There was %d duplicate',
203
- 'There were %d duplicates',
203
+ message = n_("There was %d duplicate",
204
+ "There were %d duplicates",
204
205
  isbn_duplicates.size) % isbn_duplicates.size
205
206
  title = n_("Couldn't add this book",
206
207
  "Couldn't add these books",
@@ -219,7 +220,7 @@ module Alexandria
219
220
 
220
221
  def read_barcode_scan
221
222
  @animation.start
222
- play_sound('scanning') if @test_scan
223
+ play_sound("scanning") if @test_scan
223
224
  log.debug { "reading scanner data #{@scanner_buffer}" }
224
225
  barcode_text = nil
225
226
  isbn = nil
@@ -229,25 +230,25 @@ module Alexandria
229
230
  isbn = Library.canonicalise_isbn(barcode_text)
230
231
  # TODO: : use an AppFacade
231
232
  # isbn = LookupBook.get_isbn(barcode_text)
232
- rescue StandardError => err
233
- log.error { "Bad scan: #{@scanner_buffer} #{err}" }
233
+ rescue StandardError => ex
234
+ log.error { "Bad scan: #{@scanner_buffer} #{ex}" }
234
235
  ensure
235
- @scanner_buffer = ''
236
+ @scanner_buffer = ""
236
237
  end
237
238
  if isbn
238
239
  log.debug { "Got ISBN #{isbn}" }
239
- play_sound('good_scan')
240
+ play_sound("good_scan")
240
241
 
241
242
  @barcodes_treeview.model.freeze_notify do
242
243
  iter = @barcodes_treeview.model.append
243
244
  iter[0] = isbn
244
245
  iter[1] = Icons::BOOK
245
- iter[2] = ''
246
+ iter[2] = ""
246
247
  end
247
248
  lookup_book(isbn)
248
249
  else
249
- log.debug { 'was not an ISBN barcode' }
250
- play_sound('bad_scan')
250
+ log.debug { "was not an ISBN barcode" }
251
+ play_sound("bad_scan")
251
252
  end
252
253
  end
253
254
 
@@ -346,9 +347,9 @@ module Alexandria
346
347
  end
347
348
 
348
349
  @add_button.sensitive = true
349
- rescue StandardError => err
350
- log.error { "Book Search failed: #{err.message}" }
351
- log << err if log.error?
350
+ rescue StandardError => ex
351
+ log.error { "Book Search failed: #{ex.message}" }
352
+ log << ex if log.error?
352
353
  ensure
353
354
  stop_search
354
355
  end
@@ -362,7 +363,7 @@ module Alexandria
362
363
  if cover_uri
363
364
  image_data = nil
364
365
  if URI.parse(cover_uri).scheme.nil?
365
- File.open(cover_uri, 'r') do |io|
366
+ File.open(cover_uri, "r") do |io|
366
367
  image_data = io.read
367
368
  end
368
369
  else
@@ -383,31 +384,31 @@ module Alexandria
383
384
  end
384
385
  end
385
386
  end
386
- rescue StandardError => err
387
- log.error {
388
- "Failed to load cover image icon: #{err.message}"
389
- }
390
- log << err if log.error?
387
+ rescue StandardError => ex
388
+ log.error do
389
+ "Failed to load cover image icon: #{ex.message}"
390
+ end
391
+ log << ex if log.error?
391
392
  end
392
393
  end
393
394
  end
394
395
 
395
396
  def on_destroy
396
- MainApp.instance.ui_manager.set_status_label('')
397
+ MainApp.instance.ui_manager.set_status_label("")
397
398
  notify_end_add_by_isbn
398
399
  # TODO: possibly make sure all threads have stopped running
399
400
  @animation.destroy
400
401
  end
401
402
 
402
403
  def setup_scanner_area
403
- @scanner_buffer = ''
404
+ @scanner_buffer = ""
404
405
  scanner_name = @prefs.barcode_scanner
405
406
 
406
407
  @scanner = Alexandria::Scanners.find_scanner(scanner_name) ||
407
408
  Alexandria::Scanners.default_scanner # CueCat is default
408
409
 
409
410
  log.debug { "Using #{@scanner.name} scanner" }
410
- message = _('Ready to use %s barcode scanner') % @scanner.name
411
+ message = _("Ready to use %s barcode scanner") % @scanner.name
411
412
  MainApp.instance.ui_manager.set_status_label(message)
412
413
 
413
414
  @prev_time = 0
@@ -417,40 +418,40 @@ module Alexandria
417
418
  @scan_frame.add(@animation.canvas)
418
419
 
419
420
  # attach signals
420
- @scan_area.signal_connect('button-press-event') do |_widget, _event|
421
+ @scan_area.signal_connect("button-press-event") do |_widget, _event|
421
422
  @scan_area.grab_focus
422
423
  end
423
- @scan_area.signal_connect('focus-in-event') do |_widget, _event|
424
- @barcode_label.label = _(format('%s _Barcode Scanner Ready', _(@scanner.display_name)))
425
- @scanner_buffer = ''
424
+ @scan_area.signal_connect("focus-in-event") do |_widget, _event|
425
+ @barcode_label.label = _(format("%s _Barcode Scanner Ready", _(@scanner.display_name)))
426
+ @scanner_buffer = ""
426
427
  begin
427
428
  @animation.set_active
428
- rescue StandardError => err
429
- log << err if log.error?
429
+ rescue StandardError => ex
430
+ log << ex if log.error?
430
431
  end
431
432
  end
432
- @scan_area.signal_connect('focus-out-event') do |_widget, _event|
433
- @barcode_label.label = _('Click below to scan _barcodes')
434
- @scanner_buffer = ''
433
+ @scan_area.signal_connect("focus-out-event") do |_widget, _event|
434
+ @barcode_label.label = _("Click below to scan _barcodes")
435
+ @scanner_buffer = ""
435
436
  @animation.set_passive
436
437
  # @scanner_background.destroy
437
438
  end
438
439
 
439
440
  @@debug_index = 0
440
- @scan_area.signal_connect('key-press-event') do |_button, event|
441
+ @scan_area.signal_connect("key-press-event") do |_button, event|
441
442
  # log.debug { event.keyval }
442
443
  # event.keyval == 65293 means Enter key
443
444
  # HACK, this disallows numeric keypad entry of data...
444
445
  if event.keyval < 255
445
446
  if @scanner_buffer.empty?
446
- if event.keyval.chr == '`' # backtick key for devs
447
+ if event.keyval.chr == "`" # backtick key for devs
447
448
  developer_test_scan
448
449
  next
449
450
  else
450
451
  # this is our first character, notify user
451
- log.debug { 'Scanning! Received first character.' }
452
+ log.debug { "Scanning! Received first character." }
452
453
  end
453
- play_sound('scanning')
454
+ play_sound("scanning")
454
455
  end
455
456
  @scanner_buffer << event.keyval.chr
456
457
 
@@ -474,7 +475,7 @@ module Alexandria
474
475
  if @scanner.match? @scanner_buffer
475
476
 
476
477
  Thread.new(@interval, @scanner_buffer) do |interval, buffer|
477
- log.debug { 'Waiting for more scanner input...' }
478
+ log.debug { "Waiting for more scanner input..." }
478
479
  GLib::Idle.add do
479
480
  @animation.manual_input
480
481
  false
@@ -482,7 +483,7 @@ module Alexandria
482
483
  time_to_wait = [3, interval * 4].min
483
484
  sleep(time_to_wait)
484
485
  if buffer == @scanner_buffer
485
- log.debug { 'Buffer unchanged; scanning complete' }
486
+ log.debug { "Buffer unchanged; scanning complete" }
486
487
  GLib::Idle.add do
487
488
  @animation.scanner_input
488
489
  false
@@ -493,7 +494,7 @@ module Alexandria
493
494
  @interval = 0
494
495
 
495
496
  else
496
- log.debug { 'Buffer has changed while waiting, reading more characters...' }
497
+ log.debug { "Buffer has changed while waiting, reading more characters..." }
497
498
  end
498
499
  end
499
500
 
@@ -503,18 +504,18 @@ module Alexandria
503
504
 
504
505
  # @sound_player = SoundEffectsPlayer.new
505
506
  @sound_players = {}
506
- @sound_players['scanning'] = SoundEffectsPlayer.new
507
- @sound_players['good_scan'] = SoundEffectsPlayer.new
508
- @sound_players['bad_scan'] = SoundEffectsPlayer.new
507
+ @sound_players["scanning"] = SoundEffectsPlayer.new
508
+ @sound_players["good_scan"] = SoundEffectsPlayer.new
509
+ @sound_players["bad_scan"] = SoundEffectsPlayer.new
509
510
  @test_scan = false
510
511
  end
511
512
 
512
513
  def play_sound(effect)
513
- if effect == 'scanning'
514
+ if effect == "scanning"
514
515
  puts "Effect: #{effect}, playing: #{@prefs.play_scanning_sound}" if $DEBUG
515
516
  return unless @prefs.play_scanning_sound
516
517
 
517
- @sound_players['scanning'].play('scanning')
518
+ @sound_players["scanning"].play("scanning")
518
519
  else
519
520
  puts "Effect: #{effect}, playing: #{@prefs.play_scan_sound}" if $DEBUG
520
521
  return unless @prefs.play_scan_sound
@@ -525,16 +526,16 @@ module Alexandria
525
526
  end
526
527
 
527
528
  def developer_test_scan
528
- log.info { 'Developer test scan.' }
529
- scans = ['.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3j3C3f1Dxj3Dq.',
530
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3z0CNj3Dhj1EW.',
531
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3r2DNbXCxTZCW.',
532
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGf2.ENr7C3z0DNn0ENnWE3nZDhP6.',
533
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7CNT2CxT2ChP0Dq.',
534
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7CNT6E3f7CNbWDa.',
535
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3b3ENjYDxv3EW.',
536
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3b2DxjZE3b3Dq.',
537
- '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3n6CNr6DxvYDa.']
529
+ log.info { "Developer test scan." }
530
+ scans = [".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3j3C3f1Dxj3Dq.",
531
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3z0CNj3Dhj1EW.",
532
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3r2DNbXCxTZCW.",
533
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGf2.ENr7C3z0DNn0ENnWE3nZDhP6.",
534
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7CNT2CxT2ChP0Dq.",
535
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7CNT6E3f7CNbWDa.",
536
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3b3ENjYDxv3EW.",
537
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3b2DxjZE3b3Dq.",
538
+ ".C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3n6CNr6DxvYDa."]
538
539
  @scanner_buffer = scans[@@debug_index % scans.size]
539
540
  @@debug_index += 1
540
541
  @test_scan = true
@@ -553,12 +554,12 @@ module Alexandria
553
554
  text_renderer.editable = false
554
555
 
555
556
  # Add column using our renderer
556
- col = Gtk::TreeViewColumn.new('ISBN', text_renderer, text: 0)
557
+ col = Gtk::TreeViewColumn.new("ISBN", text_renderer, text: 0)
557
558
  @barcodes_treeview.append_column(col)
558
559
 
559
560
  # Middle colulmn is cover-image renderer
560
561
  pixbuf_renderer = Gtk::CellRendererPixbuf.new
561
- col = Gtk::TreeViewColumn.new('Cover', pixbuf_renderer)
562
+ col = Gtk::TreeViewColumn.new("Cover", pixbuf_renderer)
562
563
 
563
564
  col.set_cell_data_func(pixbuf_renderer) do |_column, cell, _model, iter|
564
565
  pixbuf = iter[1]
@@ -577,10 +578,10 @@ module Alexandria
577
578
  @barcodes_treeview.append_column(col)
578
579
 
579
580
  # Add column using the second renderer
580
- col = Gtk::TreeViewColumn.new('Title', text_renderer, text: 2)
581
+ col = Gtk::TreeViewColumn.new("Title", text_renderer, text: 2)
581
582
  @barcodes_treeview.append_column(col)
582
583
 
583
- @barcodes_treeview.model.signal_connect('row-deleted') do |model, _path|
584
+ @barcodes_treeview.model.signal_connect("row-deleted") do |model, _path|
584
585
  @add_button.sensitive = false unless model.iter_first
585
586
  end
586
587
  end