alexandria-book-collection-manager 0.6.9.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (293) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rubocop.yml +68 -0
  4. data/.rubocop_todo.yml +200 -0
  5. data/CHANGELOG.md +23 -0
  6. data/COPYING +339 -0
  7. data/ChangeLog.0 +3598 -0
  8. data/Gemfile +9 -0
  9. data/INSTALL.rdoc +156 -0
  10. data/PACKAGING +36 -0
  11. data/README.md +88 -0
  12. data/RELEASE_CHECKLIST +18 -0
  13. data/Rakefile +264 -0
  14. data/TODO +24 -0
  15. data/alexandria-book-collection-manager.gemspec +35 -0
  16. data/alexandria.desktop.in +10 -0
  17. data/bin/alexandria +82 -0
  18. data/doc/AUTHORS +60 -0
  19. data/doc/BUGS +31 -0
  20. data/doc/FAQ +369 -0
  21. data/doc/HACKING +19 -0
  22. data/doc/NEWS +341 -0
  23. data/doc/alexandria.1 +120 -0
  24. data/doc/cuecat_support.rdoc +67 -0
  25. data/lib/alexandria.rb +85 -0
  26. data/lib/alexandria/about.rb +82 -0
  27. data/lib/alexandria/book_providers.rb +411 -0
  28. data/lib/alexandria/book_providers/adlibris.rb +235 -0
  29. data/lib/alexandria/book_providers/amazon_aws.rb +261 -0
  30. data/lib/alexandria/book_providers/amazon_ecs_util.rb +405 -0
  31. data/lib/alexandria/book_providers/barnes_and_noble.rb +229 -0
  32. data/lib/alexandria/book_providers/bol_it.rb +162 -0
  33. data/lib/alexandria/book_providers/deastore.rb +277 -0
  34. data/lib/alexandria/book_providers/douban.rb +135 -0
  35. data/lib/alexandria/book_providers/ibs_it.rb +149 -0
  36. data/lib/alexandria/book_providers/mcu.rb +177 -0
  37. data/lib/alexandria/book_providers/proxis.rb +205 -0
  38. data/lib/alexandria/book_providers/pseudomarc.rb +185 -0
  39. data/lib/alexandria/book_providers/renaud.rb +142 -0
  40. data/lib/alexandria/book_providers/siciliano.rb +271 -0
  41. data/lib/alexandria/book_providers/thalia.rb +197 -0
  42. data/lib/alexandria/book_providers/web.rb +59 -0
  43. data/lib/alexandria/book_providers/webster_it.rb +173 -0
  44. data/lib/alexandria/book_providers/worldcat.rb +251 -0
  45. data/lib/alexandria/book_providers/z3950.rb +422 -0
  46. data/lib/alexandria/config.rb +8 -0
  47. data/lib/alexandria/console.rb +31 -0
  48. data/lib/alexandria/execution_queue.rb +96 -0
  49. data/lib/alexandria/export_library.rb +536 -0
  50. data/lib/alexandria/import_library.rb +316 -0
  51. data/lib/alexandria/import_library_csv.rb +270 -0
  52. data/lib/alexandria/logging.rb +159 -0
  53. data/lib/alexandria/models/book.rb +72 -0
  54. data/lib/alexandria/models/library.rb +714 -0
  55. data/lib/alexandria/net.rb +53 -0
  56. data/lib/alexandria/preferences.rb +324 -0
  57. data/lib/alexandria/scanners.rb +42 -0
  58. data/lib/alexandria/scanners/cuecat.rb +118 -0
  59. data/lib/alexandria/scanners/keyboard.rb +57 -0
  60. data/lib/alexandria/smart_library.rb +525 -0
  61. data/lib/alexandria/ui.rb +53 -0
  62. data/lib/alexandria/ui/builder_base.rb +43 -0
  63. data/lib/alexandria/ui/callbacks.rb +389 -0
  64. data/lib/alexandria/ui/completion_models.rb +228 -0
  65. data/lib/alexandria/ui/dialogs/about_dialog.rb +59 -0
  66. data/lib/alexandria/ui/dialogs/acquire_dialog.rb +640 -0
  67. data/lib/alexandria/ui/dialogs/alert_dialog.rb +68 -0
  68. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +43 -0
  69. data/lib/alexandria/ui/dialogs/barcode_animation.rb +159 -0
  70. data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +210 -0
  71. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +432 -0
  72. data/lib/alexandria/ui/dialogs/export_dialog.rb +172 -0
  73. data/lib/alexandria/ui/dialogs/import_dialog.rb +205 -0
  74. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +85 -0
  75. data/lib/alexandria/ui/dialogs/new_book_dialog.rb +639 -0
  76. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +153 -0
  77. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +67 -0
  78. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +587 -0
  79. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +56 -0
  80. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +432 -0
  81. data/lib/alexandria/ui/dndable.rb +81 -0
  82. data/lib/alexandria/ui/gtk_thread_help.rb +88 -0
  83. data/lib/alexandria/ui/icons.rb +100 -0
  84. data/lib/alexandria/ui/iconview.rb +91 -0
  85. data/lib/alexandria/ui/iconview_tooltips.rb +162 -0
  86. data/lib/alexandria/ui/init.rb +93 -0
  87. data/lib/alexandria/ui/libraries_combo.rb +75 -0
  88. data/lib/alexandria/ui/listview.rb +310 -0
  89. data/lib/alexandria/ui/main_app.rb +67 -0
  90. data/lib/alexandria/ui/multi_drag_treeview.rb +150 -0
  91. data/lib/alexandria/ui/sidepane.rb +194 -0
  92. data/lib/alexandria/ui/sound.rb +107 -0
  93. data/lib/alexandria/ui/ui_manager.rb +1308 -0
  94. data/lib/alexandria/undo_manager.rb +78 -0
  95. data/lib/alexandria/utils.rb +30 -0
  96. data/lib/alexandria/version.rb +24 -0
  97. data/lib/alexandria/web_themes.rb +75 -0
  98. data/misc/sounds/README +15 -0
  99. data/misc/sounds/bad_scan.csd +62 -0
  100. data/misc/sounds/good_scan.csd +61 -0
  101. data/misc/sounds/scanning.csd +46 -0
  102. data/po/ChangeLog +488 -0
  103. data/po/Makefile +44 -0
  104. data/po/README +29 -0
  105. data/po/commit-po +72 -0
  106. data/po/cs.po +1437 -0
  107. data/po/cy.po +1521 -0
  108. data/po/de.po +1400 -0
  109. data/po/el.po +1379 -0
  110. data/po/es.po +1376 -0
  111. data/po/fr.po +1420 -0
  112. data/po/ga.po +1359 -0
  113. data/po/gl.po +1397 -0
  114. data/po/it.po +1406 -0
  115. data/po/ja.po +1355 -0
  116. data/po/mk.po +1373 -0
  117. data/po/nb.po +1386 -0
  118. data/po/nl.po +1405 -0
  119. data/po/pl.po +1373 -0
  120. data/po/pt.po +1398 -0
  121. data/po/pt_BR.po +1409 -0
  122. data/po/ru.po +1372 -0
  123. data/po/sk.po +1380 -0
  124. data/po/sv.po +1402 -0
  125. data/po/uk.po +1423 -0
  126. data/po/zh_TW.po +1394 -0
  127. data/schemas/alexandria.schemas +300 -0
  128. data/share/alexandria/glade/acquire_dialog__builder.glade +201 -0
  129. data/share/alexandria/glade/book_properties_dialog__builder.glade +910 -0
  130. data/share/alexandria/glade/main_app__builder.glade +229 -0
  131. data/share/alexandria/glade/new_book_dialog__builder.glade +379 -0
  132. data/share/alexandria/glade/preferences_dialog__builder.glade +733 -0
  133. data/share/alexandria/icons/alexandria.png +0 -0
  134. data/share/alexandria/icons/alexandria_small.png +0 -0
  135. data/share/alexandria/icons/book.png +0 -0
  136. data/share/alexandria/icons/book_icon.png +0 -0
  137. data/share/alexandria/icons/book_small.png +0 -0
  138. data/share/alexandria/icons/cuecat.png +0 -0
  139. data/share/alexandria/icons/cuecat_inactive.png +0 -0
  140. data/share/alexandria/icons/favorite_tag.png +0 -0
  141. data/share/alexandria/icons/less.png +0 -0
  142. data/share/alexandria/icons/library.png +0 -0
  143. data/share/alexandria/icons/library_small.png +0 -0
  144. data/share/alexandria/icons/lookup.png +0 -0
  145. data/share/alexandria/icons/more.png +0 -0
  146. data/share/alexandria/icons/no_cover.png +0 -0
  147. data/share/alexandria/icons/smart_library.png +0 -0
  148. data/share/alexandria/icons/smart_library_small.png +0 -0
  149. data/share/alexandria/icons/star_set.png +0 -0
  150. data/share/alexandria/icons/star_unset.png +0 -0
  151. data/share/alexandria/icons/view_as_icons.png +0 -0
  152. data/share/alexandria/icons/view_as_list.png +0 -0
  153. data/share/alexandria/ui/menus.xml +91 -0
  154. data/share/alexandria/ui/popups.xml +91 -0
  155. data/share/alexandria/web-themes/clean/clean.css +85 -0
  156. data/share/alexandria/web-themes/clean/preview.jpg +0 -0
  157. data/share/alexandria/web-themes/list/list.css +105 -0
  158. data/share/alexandria/web-themes/list/preview.jpg +0 -0
  159. data/share/app-icon/16x16/alexandria.png +0 -0
  160. data/share/app-icon/16x16/alexandria.svg +263 -0
  161. data/share/app-icon/22x22/alexandria.png +0 -0
  162. data/share/app-icon/22x22/alexandria.svg +465 -0
  163. data/share/app-icon/24x24/alexandria.png +0 -0
  164. data/share/app-icon/32x32/alexandria.png +0 -0
  165. data/share/app-icon/32x32/alexandria.svg +813 -0
  166. data/share/app-icon/32x32/alexandria.xpm +241 -0
  167. data/share/app-icon/48x48/alexandria.png +0 -0
  168. data/share/app-icon/scalable/alexandria.svg +700 -0
  169. data/share/gnome/help/alexandria/C/about.xml +44 -0
  170. data/share/gnome/help/alexandria/C/adding-books.xml +339 -0
  171. data/share/gnome/help/alexandria/C/alexandria.xml +185 -0
  172. data/share/gnome/help/alexandria/C/bugs.xml +18 -0
  173. data/share/gnome/help/alexandria/C/editing-book-properties.xml +124 -0
  174. data/share/gnome/help/alexandria/C/exporting.xml +81 -0
  175. data/share/gnome/help/alexandria/C/figures/adding_books_acquire_from_scanner_process.png +0 -0
  176. data/share/gnome/help/alexandria/C/figures/adding_books_add_by_isbn.png +0 -0
  177. data/share/gnome/help/alexandria/C/figures/adding_books_isbn_import.png +0 -0
  178. data/share/gnome/help/alexandria/C/figures/adding_books_manual_details.png +0 -0
  179. data/share/gnome/help/alexandria/C/figures/adding_books_rename_library_after_import.png +0 -0
  180. data/share/gnome/help/alexandria/C/figures/adding_books_search_results.png +0 -0
  181. data/share/gnome/help/alexandria/C/figures/editing_book_properties_info.png +0 -0
  182. data/share/gnome/help/alexandria/C/figures/editing_book_properties_loaning.png +0 -0
  183. data/share/gnome/help/alexandria/C/figures/exporting_information_html.png +0 -0
  184. data/share/gnome/help/alexandria/C/figures/getting_started_first_launched.png +0 -0
  185. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view.png +0 -0
  186. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view_search.png +0 -0
  187. data/share/gnome/help/alexandria/C/figures/settings_providers_new_z3950.png +0 -0
  188. data/share/gnome/help/alexandria/C/figures/smart_libraries_new_smart_library.png +0 -0
  189. data/share/gnome/help/alexandria/C/figures/working_with_libraries_library_pane.png +0 -0
  190. data/share/gnome/help/alexandria/C/getting-started.xml +154 -0
  191. data/share/gnome/help/alexandria/C/gnu-fdl-1.2.xml +543 -0
  192. data/share/gnome/help/alexandria/C/introduction.xml +142 -0
  193. data/share/gnome/help/alexandria/C/searching.xml +90 -0
  194. data/share/gnome/help/alexandria/C/settings.xml +140 -0
  195. data/share/gnome/help/alexandria/C/smart-libraries.xml +160 -0
  196. data/share/gnome/help/alexandria/C/working-with-libraries.xml +76 -0
  197. data/share/gnome/help/alexandria/ChangeLog +99 -0
  198. data/share/gnome/help/alexandria/fr/alexandria.xml +2292 -0
  199. data/share/gnome/help/alexandria/fr/figures/alexandria_add_button.png +0 -0
  200. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_isbn_1.png +0 -0
  201. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_search_1.png +0 -0
  202. data/share/gnome/help/alexandria/fr/figures/alexandria_add_manually.png +0 -0
  203. data/share/gnome/help/alexandria/fr/figures/alexandria_add_z3950.png +0 -0
  204. data/share/gnome/help/alexandria/fr/figures/alexandria_close_button.png +0 -0
  205. data/share/gnome/help/alexandria/fr/figures/alexandria_edit_info.png +0 -0
  206. data/share/gnome/help/alexandria/fr/figures/alexandria_export_web_page.png +0 -0
  207. data/share/gnome/help/alexandria/fr/figures/alexandria_importing.png +0 -0
  208. data/share/gnome/help/alexandria/fr/figures/alexandria_library_pane.png +0 -0
  209. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view.png +0 -0
  210. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view_search.png +0 -0
  211. data/share/gnome/help/alexandria/fr/figures/alexandria_loaning.png +0 -0
  212. data/share/gnome/help/alexandria/fr/figures/alexandria_main_window.png +0 -0
  213. data/share/gnome/help/alexandria/fr/figures/alexandria_remove_button.png +0 -0
  214. data/share/gnome/help/alexandria/ja/about.xml +33 -0
  215. data/share/gnome/help/alexandria/ja/adding-books.xml +314 -0
  216. data/share/gnome/help/alexandria/ja/alexandria.xml +172 -0
  217. data/share/gnome/help/alexandria/ja/bugs.xml +11 -0
  218. data/share/gnome/help/alexandria/ja/editing-book-properties.xml +100 -0
  219. data/share/gnome/help/alexandria/ja/exporting.xml +98 -0
  220. data/share/gnome/help/alexandria/ja/figures/adding_books_acquire_from_scanner_process.png +0 -0
  221. data/share/gnome/help/alexandria/ja/figures/adding_books_add_by_isbn.png +0 -0
  222. data/share/gnome/help/alexandria/ja/figures/adding_books_isbn_import.png +0 -0
  223. data/share/gnome/help/alexandria/ja/figures/adding_books_manual_details.png +0 -0
  224. data/share/gnome/help/alexandria/ja/figures/adding_books_rename_library_after_import.png +0 -0
  225. data/share/gnome/help/alexandria/ja/figures/adding_books_search_results.png +0 -0
  226. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_info.png +0 -0
  227. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_loaning.png +0 -0
  228. data/share/gnome/help/alexandria/ja/figures/exporting_information_html.png +0 -0
  229. data/share/gnome/help/alexandria/ja/figures/getting_started_first_launched.png +0 -0
  230. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view.png +0 -0
  231. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view_search.png +0 -0
  232. data/share/gnome/help/alexandria/ja/figures/settings_providers_new_z3950.png +0 -0
  233. data/share/gnome/help/alexandria/ja/figures/smart_libraries_new_smart_library.png +0 -0
  234. data/share/gnome/help/alexandria/ja/figures/working_with_libraries_library_pane.png +0 -0
  235. data/share/gnome/help/alexandria/ja/getting-started.xml +144 -0
  236. data/share/gnome/help/alexandria/ja/gnu-fdl-1.2.xml +541 -0
  237. data/share/gnome/help/alexandria/ja/introduction.xml +134 -0
  238. data/share/gnome/help/alexandria/ja/searching.xml +104 -0
  239. data/share/gnome/help/alexandria/ja/settings.xml +129 -0
  240. data/share/gnome/help/alexandria/ja/smart-libraries.xml +140 -0
  241. data/share/gnome/help/alexandria/ja/working-with-libraries.xml +88 -0
  242. data/share/menu/alexandria +7 -0
  243. data/share/omf/alexandria/alexandria-C.omf.in +27 -0
  244. data/share/omf/alexandria/alexandria-fr.omf.in +30 -0
  245. data/share/sounds/alexandria/bad_scan.ogg +0 -0
  246. data/share/sounds/alexandria/bad_scan.wav +0 -0
  247. data/share/sounds/alexandria/good_scan.ogg +0 -0
  248. data/share/sounds/alexandria/good_scan.wav +0 -0
  249. data/share/sounds/alexandria/scanning.ogg +0 -0
  250. data/share/sounds/alexandria/scanning.wav +0 -0
  251. data/spec/alexandria/library_spec.rb +205 -0
  252. data/spec/alexandria/preferences_spec.rb +22 -0
  253. data/spec/alexandria/scanners/cuecat_spec.rb +68 -0
  254. data/spec/alexandria/smart_library_spec.rb +22 -0
  255. data/spec/alexandria/ui/dialogs_spec.rb +90 -0
  256. data/spec/alexandria/ui/iconview_spec.rb +27 -0
  257. data/spec/alexandria/ui/listview_spec.rb +28 -0
  258. data/spec/alexandria/ui/main_app_spec.rb +48 -0
  259. data/spec/alexandria/ui/sidepane_spec.rb +27 -0
  260. data/spec/alexandria/ui/ui_manager_spec.rb +26 -0
  261. data/spec/alexandria/ui/ui_utilities_spec.rb +60 -0
  262. data/spec/alexandria/utilities_spec.rb +50 -0
  263. data/spec/data/libraries/0.6.1-noisbn/My Library/0201398257.yaml +10 -0
  264. data/spec/data/libraries/0.6.1-noisbn/My Library/1565920007.yaml +10 -0
  265. data/spec/data/libraries/0.6.1/My Library/0192812173.yaml +9 -0
  266. data/spec/data/libraries/0.6.1/My Library/0201398257.cover +0 -0
  267. data/spec/data/libraries/0.6.1/My Library/0201398257.yaml +10 -0
  268. data/spec/data/libraries/0.6.1/My Library/1565920007.yaml +10 -0
  269. data/spec/data/libraries/0.6.2/My Library/9780140266146.cover +0 -0
  270. data/spec/data/libraries/0.6.2/My Library/9780140266146.yaml +16 -0
  271. data/spec/data/libraries/0.6.2/My Library/9780140278781.cover +0 -0
  272. data/spec/data/libraries/0.6.2/My Library/9780140278781.yaml +21 -0
  273. data/spec/data/libraries/0.6.2/My Library/9780571147168.cover +0 -0
  274. data/spec/data/libraries/0.6.2/My Library/9780571147168.yaml +20 -0
  275. data/spec/data/libraries/0.6.2/My Library/9780575079038.cover +0 -0
  276. data/spec/data/libraries/0.6.2/My Library/9780575079038.yaml +20 -0
  277. data/spec/data/libraries/0.6.2/My Library/9780755322800.cover +0 -0
  278. data/spec/data/libraries/0.6.2/My Library/9780755322800.yaml +20 -0
  279. data/spec/spec_helper.rb +46 -0
  280. data/tasks/rdoc.rake +6 -0
  281. data/tasks/setup.rb +30 -0
  282. data/tasks/spec.rake +29 -0
  283. data/tasks/test.rake +38 -0
  284. data/test/application_test.rb +39 -0
  285. data/test/book_test.rb +34 -0
  286. data/test/data/isbns.txt +3 -0
  287. data/test/isbn_test.rb +68 -0
  288. data/test/providers_test.rb +254 -0
  289. data/test/test_helper.rb +42 -0
  290. data/util/rake/fileinstall.rb +313 -0
  291. data/util/rake/gettextgenerate.rb +158 -0
  292. data/util/rake/omfgenerate.rb +79 -0
  293. metadata +452 -0
@@ -0,0 +1,228 @@
1
+ # Copyright (C) 2005-2006 Laurent Sansonetti
2
+ # Modifications Copyright (C) 2011 Matijs van Zuijlen
3
+ #
4
+ # Alexandria is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU General Public License as
6
+ # published by the Free Software Foundation; either version 2 of the
7
+ # License, or (at your option) any later version.
8
+ #
9
+ # Alexandria is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public
15
+ # License along with Alexandria; see the file COPYING. If not,
16
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
+ # Fifth Floor, Boston, MA 02110-1301 USA.
18
+
19
+ class Gtk::Entry
20
+ def complete_titles
21
+ complete(Alexandria::UI::CompletionModels::TITLE)
22
+ end
23
+
24
+ def complete_authors
25
+ complete(Alexandria::UI::CompletionModels::AUTHOR)
26
+ end
27
+
28
+ def complete_publishers
29
+ complete(Alexandria::UI::CompletionModels::PUBLISHER)
30
+ end
31
+
32
+ def complete_editions
33
+ complete(Alexandria::UI::CompletionModels::EDITION)
34
+ end
35
+
36
+ def complete_borrowers
37
+ complete(Alexandria::UI::CompletionModels::BORROWER)
38
+ end
39
+
40
+ def complete_tags
41
+ complete(Alexandria::UI::CompletionModels::TAG)
42
+ # min = self.completion.minimum_key_length
43
+ min = 2
44
+ completion.signal_connect('match-selected') do |c, model, iter|
45
+ cur_text = c.entry.text
46
+ new_tag = model.get_value(iter, 0)
47
+ cur_text_split = cur_text.split(',')
48
+ cur_text_split.delete_at(-1)
49
+ cur_text_split << new_tag
50
+ c.entry.text = cur_text_split.join(',')
51
+ true
52
+ end
53
+ completion.set_match_func do |_comp, key, iter|
54
+ cur_tag = key.split(',').last.strip
55
+ if cur_tag.size >= min
56
+ begin
57
+ if iter[0] =~ /^#{cur_tag}/
58
+ true
59
+ else
60
+ false
61
+ end
62
+ rescue
63
+ false
64
+ end
65
+ else
66
+ false
67
+ end
68
+ end
69
+ end
70
+
71
+ #######
72
+ private
73
+ #######
74
+
75
+ def complete(model_id)
76
+ completion = Gtk::EntryCompletion.new
77
+ model = Alexandria::UI::CompletionModels.instance.models[model_id]
78
+ completion.model = model
79
+ completion.text_column = 0
80
+ self.completion = completion
81
+ end
82
+ end
83
+
84
+ begin
85
+ require 'revolution'
86
+
87
+ EVOLUTION_CONTACTS =
88
+ Revolution::Revolution.new.get_all_contacts.map do |contact|
89
+ first, last = contact.first_name, contact.last_name
90
+
91
+ if first
92
+ first.strip!
93
+ first = nil if first.empty?
94
+ end
95
+
96
+ if last
97
+ last.strip!
98
+ last = nil if last.empty?
99
+ end
100
+
101
+ first and last ? first + ' ' + last : first ? first : last
102
+ end
103
+ rescue LoadError => e
104
+ Alexandria.log.debug { 'Could not find optional ruby-revolution; Evolution contacts will not be loaded' }
105
+ EVOLUTION_CONTACTS = []
106
+ rescue => e
107
+ Alexandria.log.warn { e.message }
108
+ EVOLUTION_CONTACTS = []
109
+ end
110
+
111
+ module Alexandria
112
+ module UI
113
+ class CompletionModels
114
+ include Singleton
115
+
116
+ TITLE, AUTHOR, PUBLISHER, EDITION, BORROWER, TAG = (0..6).to_a
117
+
118
+ def initialize
119
+ @models, @libraries = [], []
120
+ 5.times { @models << Gtk::ListStore.new(String) }
121
+ @models << Gtk::ListStore.new(String)
122
+ touch
123
+ end
124
+
125
+ def add_source(library)
126
+ @libraries << library
127
+ library.add_observer(self)
128
+ touch
129
+ end
130
+
131
+ def remove_source(library)
132
+ @libraries.delete_if { |x| x.name == library.name }
133
+ library.delete_observer(self)
134
+ touch
135
+ end
136
+
137
+ def update(_library, _kind, _book)
138
+ # FIXME: Do not rebuild all the models there.
139
+ touch
140
+ end
141
+
142
+ def models
143
+ rebuild_models if dirty?
144
+ @models
145
+ end
146
+
147
+ def title_model
148
+ rebuild_models if dirty?
149
+ @models[TITLE]
150
+ end
151
+
152
+ def author_model
153
+ rebuild_models if dirty?
154
+ @models[AUTHOR]
155
+ end
156
+
157
+ def publisher_model
158
+ rebuild_models if dirty?
159
+ @models[PUBLISHER]
160
+ end
161
+
162
+ def edition_model
163
+ rebuild_models if dirty?
164
+ @models[EDITION]
165
+ end
166
+
167
+ def borrower_model
168
+ rebuilds_models if dirty?
169
+ @models[BORROWER]
170
+ end
171
+
172
+ def tag_model
173
+ rebuilds_models if dirty?
174
+ @models[TAG]
175
+ end
176
+
177
+ #######
178
+ private
179
+ #######
180
+
181
+ def touch
182
+ @dirty = true
183
+ end
184
+
185
+ def dirty?
186
+ @dirty
187
+ end
188
+
189
+ def rebuild_models
190
+ titles, authors, publishers, editions, borrowers = [], [], [], [], []
191
+ tags = []
192
+ @libraries.each do |library|
193
+ library.each do |book|
194
+ titles << book.title
195
+ authors.concat(book.authors)
196
+ publishers << book.publisher
197
+ editions << book.edition
198
+ borrowers << book.loaned_to
199
+ book.tags.each { |tag| tags << tag }
200
+ end
201
+ end
202
+
203
+ borrowers.concat(EVOLUTION_CONTACTS)
204
+ borrowers.uniq!
205
+
206
+ tags.uniq!
207
+
208
+ fill_model(@models[TITLE], titles)
209
+ fill_model(@models[AUTHOR], authors)
210
+ fill_model(@models[EDITION], editions)
211
+ fill_model(@models[PUBLISHER], publishers)
212
+ fill_model(@models[BORROWER], borrowers)
213
+ fill_model(@models[TAG], tags)
214
+ @dirty = false
215
+ end
216
+
217
+ def fill_model(model, values)
218
+ model.clear
219
+ iter = nil
220
+ values.uniq.each do |value|
221
+ next if value.nil?
222
+ iter = iter ? model.insert_after(iter) : model.append
223
+ iter[0] = value
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end
@@ -0,0 +1,59 @@
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., 51 Franklin Street,
16
+ # Fifth Floor, Boston, MA 02110-1301 USA.
17
+
18
+ module Alexandria
19
+ module UI
20
+ class AboutDialog < Gtk::AboutDialog
21
+ include GetText
22
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
23
+
24
+ GPL = <<EOL
25
+ Alexandria is free software; you can redistribute it and/or
26
+ modify it under the terms of the GNU General Public License as
27
+ published by the Free Software Foundation; either version 2 of the
28
+ License, or (at your option) any later version.
29
+
30
+ Alexandria is distributed in the hope that it will be useful,
31
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
+ General Public License for more details.
34
+
35
+ You should have received a copy of the GNU General Public
36
+ License along with Alexandria; see the file COPYING. If not,
37
+ write to the Free Software Foundation, Inc., 51 Franklin Street,
38
+ Fifth Floor, Boston, MA 02110-1301 USA.
39
+ EOL
40
+
41
+ def initialize(parent)
42
+ super()
43
+ self.name = Alexandria::TITLE
44
+ self.version = Alexandria::DISPLAY_VERSION
45
+ self.copyright = Alexandria::COPYRIGHT
46
+ self.comments = Alexandria::DESCRIPTION
47
+ self.authors = Alexandria::AUTHORS
48
+ self.documenters = Alexandria::DOCUMENTERS
49
+ self.artists = Alexandria::ARTISTS
50
+ self.translator_credits = Alexandria::TRANSLATORS.join("\n")
51
+ self.logo = Icons::ALEXANDRIA
52
+ self.website = Alexandria::WEBSITE_URL
53
+ self.license = GPL
54
+ self.transient_for = parent
55
+ signal_connect('response') { destroy }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,640 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2007 Cathal Mc Ginley
3
+ # Modifications Copyright (C) 2011 Matijs van Zuijlen
4
+ #
5
+ # Alexandria is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as
7
+ # published by the Free Software Foundation; either version 2 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # Alexandria is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public
16
+ # License along with Alexandria; see the file COPYING. If not,
17
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
18
+ # Fifth Floor, Boston, MA 02110-1301 USA.
19
+
20
+ # require 'monitor'
21
+ require 'alexandria/scanners/cuecat'
22
+ require 'alexandria/scanners/keyboard'
23
+
24
+ require 'alexandria/ui/sound'
25
+ require 'alexandria/ui/dialogs/barcode_animation'
26
+
27
+ module Alexandria
28
+ module UI
29
+ require 'thread'
30
+ require 'monitor'
31
+
32
+ # assists in turning on progress bar when searching
33
+ # and turning it off when all search threads have completed...
34
+ class SearchThreadCounter < Monitor
35
+ attr_reader :count
36
+
37
+ def initialize
38
+ @count = 0
39
+ super
40
+ end
41
+
42
+ def new_search
43
+ synchronize do
44
+ @count += 1
45
+ end
46
+ end
47
+
48
+ def end_search
49
+ synchronize do
50
+ @count -= 1 unless (@count == 0)
51
+ end
52
+ end
53
+ end
54
+
55
+ class AcquireDialog < BuilderBase
56
+ include GetText
57
+ include Logging
58
+ extend GetText
59
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
60
+
61
+ def initialize(parent, selected_library = nil, &block)
62
+ super('acquire_dialog__builder.glade', widget_names)
63
+ @acquire_dialog.transient_for = @parent = parent
64
+ @block = block
65
+
66
+ libraries = Libraries.instance.all_regular_libraries
67
+ if selected_library.is_a?(SmartLibrary)
68
+ selected_library = libraries.first
69
+ end
70
+ @combo_libraries.populate_with_libraries(libraries,
71
+ selected_library)
72
+
73
+ @add_button.sensitive = false
74
+ @prefs = Alexandria::Preferences.instance
75
+ setup_scanner_area
76
+ init_treeview
77
+ @book_results = {}
78
+
79
+ @search_thread_counter = SearchThreadCounter.new
80
+ @search_threads_running = @search_thread_counter.new_cond
81
+ end
82
+
83
+ def widget_names
84
+ [:acquire_dialog, :dialog_vbox1, :dialog_action_area1,
85
+ :help_button, :cancel_button, :add_button, :vbox1,
86
+ :barcode_label, :scan_area, :scan_frame, :scrolledwindow1,
87
+ :barcodes_treeview, :hbox1, :label1, :combo_libraries]
88
+ end
89
+
90
+ def book_in_library(isbn10, library)
91
+ isbn13 = Library.canonicalise_ean(isbn10)
92
+ # puts "new book #{isbn10} (or #{isbn13})"
93
+ match = library.find do |book|
94
+ # puts "testing #{book.isbn}"
95
+ (book.isbn == isbn10 || book.isbn == isbn13)
96
+ # puts "book #{book.isbn}"
97
+ # book == new_book
98
+ end
99
+ # puts "book_in_library match #{match.inspect}"
100
+ !match.nil?
101
+ rescue
102
+ log.warn { "Failed to check for book #{isbn10} in library #{library}" }
103
+ true
104
+ end
105
+
106
+ def on_add
107
+ model = @barcodes_treeview.model
108
+
109
+ libraries = Libraries.instance.all_libraries
110
+ library, is_new_library =
111
+ @combo_libraries.selection_from_libraries(libraries)
112
+
113
+ # NOTE at this stage, the ISBN is 10-digit...
114
+ #
115
+
116
+ selection = @barcodes_treeview.selection
117
+ isbns = []
118
+ isbn_duplicates = []
119
+
120
+ adding_a_selection = false
121
+
122
+ if selection.count_selected_rows > 0
123
+
124
+ adding_a_selection = true
125
+
126
+ model.freeze_notify do
127
+ # capture isbns
128
+ selection.selected_each do |_mod, _path, iter|
129
+ isbn = iter[0]
130
+ if book_in_library(isbn, library)
131
+ isbn_duplicates << isbn
132
+ elsif isbns.include? isbn
133
+ log.info { "detected duplicate in scanned list #{isbn}" }
134
+ isbn_duplicates << isbn
135
+ else
136
+ isbns << isbn
137
+ end
138
+ end
139
+ # remove list items (complex, cf. tutorial...)
140
+ # http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-treeview-model-remove
141
+ # row_refs = []
142
+ # paths = selection.selected_rows
143
+ # paths.each do |path|
144
+ # row_refs << Gtk::TreeRowReference.new(model, path)
145
+ # end
146
+ # row_refs.each do |ref|
147
+ # model.remove(model.get_iter(ref.path))
148
+ # end
149
+
150
+ # try it this way... works because of persistent iters
151
+ row_iters = []
152
+ selection.selected_rows.each do |path|
153
+ iter = model.get_iter(path)
154
+ isbn = iter[0]
155
+ if book_in_library(isbn, library)
156
+ log.debug { "#{isbn} is a duplicate" }
157
+ # #elsif isbns.include? isbn
158
+ # this won't work since multiple scans of the same
159
+ # book have the same isbn (so we can't refrain from removing
160
+ # one, we'd end up not removing any)
161
+ ## TODO add another column in the iter, like "isbn/01"
162
+ # that would allow this kind of behaviour...
163
+
164
+ elsif !@book_results.key?(isbn) # HAX
165
+ log.debug { "no book found for #{isbn}, not adding" }
166
+
167
+ # good enough for now
168
+ else
169
+ log.debug { "scheduling #{isbn} for removal from list" }
170
+ row_iters << iter
171
+ end
172
+ end
173
+ row_iters.each do |iter|
174
+ log.debug { "removing iter #{iter[0]}" }
175
+ model.remove(iter)
176
+ end
177
+
178
+ end
179
+ else
180
+ model.freeze_notify do
181
+ # capture isbns
182
+ row_iters = []
183
+ model.each do |_mod, _path, iter|
184
+ isbn = iter[0]
185
+ if !@book_results.key?(isbn)
186
+ log.debug { "no book found for #{isbn}, not adding" }
187
+ adding_a_selection = true
188
+ elsif book_in_library(isbn, library)
189
+ log.info { "#{isbn} is a duplicate" }
190
+ isbn_duplicates << isbn
191
+ elsif isbns.include? isbn
192
+ log.info { "detected duplicate in scanned list #{isbn}" }
193
+ isbn_duplicates << isbn
194
+ else
195
+ log.info { "scheduling #{isbn} for removal from list" }
196
+ isbns << isbn
197
+ row_iters << iter
198
+ end
199
+ end
200
+ # remove list items
201
+ if isbn_duplicates.empty? and !adding_a_selection
202
+ model.clear # TODO unless!!!
203
+ row_iters.clear
204
+ else
205
+ row_iters.each do |iter|
206
+ log.debug { "removing iter #{iter[0]}" }
207
+ model.remove(iter)
208
+ end
209
+ end
210
+ end
211
+ end
212
+
213
+ books = []
214
+
215
+ isbns.each do |isbn|
216
+ log.debug { "Adding #{isbn}" }
217
+ result = @book_results[isbn]
218
+
219
+ if result.nil?
220
+ # used to crash if book was not found in online lookup!
221
+ adding_a_selection = true
222
+ # ISBN not found, so keep it in the list
223
+ # TODO (for 0.6.5) should offer to add this book manually
224
+ else
225
+
226
+ book = result[0]
227
+ cover_uri = result[1]
228
+
229
+ unless cover_uri.nil?
230
+ library.save_cover(book, cover_uri)
231
+ end
232
+ books << book
233
+ library << book
234
+ library.save(book)
235
+ end
236
+ end
237
+
238
+ if isbn_duplicates.empty?
239
+ @acquire_dialog.destroy unless adding_a_selection
240
+ else
241
+ message = n_('There was %d duplicate',
242
+ 'There were %d duplicates',
243
+ isbn_duplicates.size) % isbn_duplicates.size
244
+ title = n_("Couldn't add this book",
245
+ "Couldn't add these books",
246
+ isbn_duplicates.size)
247
+ ErrorDialog.new(@parent, title, message)
248
+ end
249
+
250
+ @block.call(books, library, is_new_library)
251
+ end
252
+
253
+ def on_cancel
254
+ @acquire_dialog.destroy
255
+ end
256
+
257
+ def on_help
258
+ end
259
+
260
+ def read_barcode_scan
261
+ @animation.start
262
+ play_sound('scanning') if @test_scan
263
+ log.debug { "reading scanner data #{@scanner_buffer}" }
264
+ barcode_text = nil
265
+ isbn = nil
266
+ begin
267
+ barcode_text = @scanner.decode(@scanner_buffer)
268
+ log.debug { "got barcode text #{barcode_text}" }
269
+ isbn = Library.canonicalise_isbn(barcode_text)
270
+ # TODO :: use an AppFacade
271
+ # isbn = LookupBook.get_isbn(barcode_text)
272
+ rescue StandardError => err
273
+ log.error { "Bad scan: #{@scanner_buffer} #{err}" }
274
+ ensure
275
+ @scanner_buffer = ''
276
+ end
277
+ if isbn
278
+ log.debug { "Got ISBN #{isbn}" }
279
+ play_sound('good_scan')
280
+
281
+ @barcodes_treeview.model.freeze_notify do
282
+ iter = @barcodes_treeview.model.append
283
+ iter[0] = isbn
284
+ iter[1] = Icons::BOOK
285
+ iter[2] = ''
286
+ end
287
+ lookup_book(isbn)
288
+ else
289
+ log.debug { 'was not an ISBN barcode' }
290
+ play_sound('bad_scan')
291
+ end
292
+ end
293
+
294
+ # begin copy-n-paste from new_book_dialog
295
+
296
+ def notify_start_add_by_isbn
297
+ Gtk.idle_add do
298
+ main_progress_bar = MainApp.instance.appbar.children.first
299
+ main_progress_bar.visible = true
300
+ @progress_pulsing = Gtk.timeout_add(100) do
301
+ if @destroyed
302
+ false
303
+ else
304
+ main_progress_bar.pulse
305
+ true
306
+ end
307
+ end
308
+ false
309
+ end
310
+ end
311
+
312
+ def notify_end_add_by_isbn
313
+ Gtk.idle_add do
314
+ MainApp.instance.appbar.children.first.visible = false
315
+ Gtk.timeout_remove(@progress_pulsing) if @progress_pulsing
316
+ false
317
+ end
318
+ end
319
+
320
+ def update(status, provider)
321
+ Gtk.idle_add do
322
+ messages = {
323
+ searching: _("Searching Provider '%s'..."),
324
+ error: _("Error while Searching Provider '%s'"),
325
+ not_found: _("Not Found at Provider '%s'"),
326
+ found: _("Found at Provider '%s'")
327
+ }
328
+ message = messages[status] % provider
329
+ log.debug { "update message : #{message}" }
330
+ # @parent.appbar.status = message
331
+ MainApp.instance.ui_manager.set_status_label(message)
332
+ false
333
+ end
334
+ end
335
+
336
+ # end copy-n-paste
337
+
338
+ private
339
+
340
+ def start_search
341
+ @search_thread_counter.synchronize do
342
+ if @search_thread_counter.count == 0
343
+ @search_thread_counter.new_search
344
+ @progress_bar_thread = Thread.new do
345
+ notify_start_add_by_isbn
346
+ Alexandria::BookProviders.instance.add_observer(self)
347
+ @search_thread_counter.synchronize do
348
+ @search_threads_running.wait_while do
349
+ @search_thread_counter.count > 0
350
+ end
351
+ end
352
+ notify_end_add_by_isbn
353
+ Alexandria::BookProviders.instance.add_observer(self)
354
+ end
355
+ else
356
+ @search_thread_counter.new_search
357
+ end
358
+ end
359
+ end
360
+
361
+ def stop_search
362
+ @search_thread_counter.synchronize do
363
+ @search_thread_counter.end_search
364
+ @search_threads_running.signal
365
+ end
366
+ end
367
+
368
+ def lookup_book(isbn)
369
+ Thread.new do
370
+ begin
371
+ start_search
372
+ results = Alexandria::BookProviders.isbn_search(isbn)
373
+ book = results[0]
374
+ cover_uri = results[1]
375
+ @book_results[isbn] = results
376
+ set_cover_image_async(isbn, cover_uri)
377
+ # TODO add this as a block to Gtk.queue (needs new overall gui design)
378
+ @barcodes_treeview.model.freeze_notify do
379
+ @barcodes_treeview.model.each do |model, path, iter|
380
+ if iter[0] == isbn
381
+ iter[2] = book.title
382
+ model.row_changed(path, iter)
383
+ end
384
+ end
385
+ end
386
+
387
+ @add_button.sensitive = true
388
+ rescue StandardError => err
389
+ log.error { "Book Search failed: #{err.message}" }
390
+ log << err if log.error?
391
+ ensure
392
+ stop_search
393
+ end
394
+ end
395
+ end
396
+
397
+ def set_cover_image_async(isbn, cover_uri)
398
+ Thread.new do
399
+ begin
400
+ pixbuf = nil
401
+ if cover_uri
402
+ image_data = nil
403
+ if URI.parse(cover_uri).scheme.nil?
404
+ File.open(cover_uri, 'r') do |io|
405
+ image_data = io.read
406
+ end
407
+ else
408
+ image_data = URI.parse(cover_uri).read
409
+ end
410
+ loader = Gdk::PixbufLoader.new
411
+ loader.last_write(image_data)
412
+ pixbuf = loader.pixbuf
413
+ else
414
+ pixbuf = Icons::BOOK
415
+ end
416
+
417
+ @barcodes_treeview.model.freeze_notify do
418
+ @barcodes_treeview.model.each do |model, path, iter|
419
+ if iter[0] == isbn
420
+ iter[1] = pixbuf
421
+ model.row_changed(path, iter)
422
+ end
423
+ end
424
+ end
425
+
426
+ rescue StandardError => err
427
+ log.error {
428
+ "Failed to load cover image icon: #{err.message}"
429
+ }
430
+ log << err if log.error?
431
+
432
+ end
433
+ end
434
+ end
435
+
436
+ def on_destroy
437
+ MainApp.instance.ui_manager.set_status_label('')
438
+ notify_end_add_by_isbn
439
+ # TODO possibly make sure all threads have stopped running
440
+ @animation.destroy
441
+ end
442
+
443
+ def setup_scanner_area
444
+ @scanner_buffer = ''
445
+ scanner_name = @prefs.barcode_scanner
446
+
447
+ @acanner = Alexandria::Scanners.find_scanner scanner_name ||
448
+ Alexandria::Scanners.default_scanner # CueCat is default
449
+
450
+ log.debug { "Using #{@scanner.name} scanner" }
451
+ message = _('Ready to use %s barcode scanner') % @scanner.name
452
+ MainApp.instance.ui_manager.set_status_label(message)
453
+
454
+ @prev_time = 0
455
+ @interval = 0
456
+
457
+ @animation = BarcodeAnimation.new
458
+ @scan_frame.add(@animation.canvas)
459
+
460
+ # attach signals
461
+ @scan_area.signal_connect('button-press-event') do |_widget, _event|
462
+ @scan_area.grab_focus
463
+ end
464
+ @scan_area.signal_connect('focus-in-event') do |_widget, _event|
465
+ @barcode_label.label = _('%s _Barcode Scanner Ready' % _(@scanner.display_name))
466
+ @scanner_buffer = ''
467
+ begin
468
+ @animation.set_active
469
+ rescue StandardError => err
470
+ log << err if log.error?
471
+ end
472
+ end
473
+ @scan_area.signal_connect('focus-out-event') do |_widget, _event|
474
+ @barcode_label.label = _('Click below to scan _barcodes')
475
+ @scanner_buffer = ''
476
+ @animation.set_passive
477
+ # @scanner_background.destroy
478
+ end
479
+
480
+ @@debug_index = 0
481
+ @scan_area.signal_connect('key-press-event') do |_button, event|
482
+ # log.debug { event.keyval }
483
+ # event.keyval == 65293 means Enter key
484
+ # HACK, this disallows numeric keypad entry of data...
485
+ if event.keyval < 255
486
+ if @scanner_buffer.empty?
487
+ if event.keyval.chr == '`' # backtick key for devs
488
+ developer_test_scan
489
+ next
490
+ else
491
+ # this is our first character, notify user
492
+ log.debug { 'Scanning! Received first character.' }
493
+ end
494
+ play_sound('scanning')
495
+ end
496
+ @scanner_buffer << event.keyval.chr
497
+
498
+ # calculating average interval between input characters
499
+ if @prev_time.zero?
500
+ @prev_time = Time.now.to_f
501
+ else
502
+ now = Time.now.to_f
503
+ if @interval.zero?
504
+ @interval = now - @prev_time
505
+ else
506
+ new_interval = now - @prev_time
507
+ @interval = (@interval + new_interval) / 2.0
508
+ end
509
+ @prev_time = now
510
+ end
511
+
512
+ # if average interval is greater than around 45 milliseconds,
513
+ # then it's probably a human typing characters
514
+
515
+ if @scanner.match? @scanner_buffer
516
+
517
+ Thread.new(@interval, @scanner_buffer) do |interval, buffer|
518
+ log.debug { 'Waiting for more scanner input...' }
519
+ Gtk.idle_add do
520
+ @animation.manual_input
521
+ false
522
+ end
523
+ time_to_wait = [3, interval * 4].min
524
+ sleep(time_to_wait)
525
+ if buffer == @scanner_buffer
526
+ log.debug { 'Buffer unchanged; scanning complete' }
527
+ Gtk.idle_add do
528
+ @animation.scanner_input
529
+ false
530
+ end
531
+ read_barcode_scan
532
+ log.debug { "Avg interval between chars: #{@interval}" }
533
+ @prev_time = 0
534
+ @interval = 0
535
+
536
+ else
537
+ log.debug { 'Buffer has changed while waiting, reading more characters...' }
538
+ end
539
+ end
540
+
541
+ end
542
+ end
543
+ end
544
+
545
+ # @sound_player = SoundEffectsPlayer.new
546
+ @sound_players = {}
547
+ @sound_players['scanning'] = SoundEffectsPlayer.new
548
+ @sound_players['good_scan'] = SoundEffectsPlayer.new
549
+ @sound_players['bad_scan'] = SoundEffectsPlayer.new
550
+ @test_scan = false
551
+ end
552
+
553
+ def play_sound(effect)
554
+ # HACK, do some thread waiting, if possible
555
+ puts "scanning sound : #{@prefs.play_scanning_sound}"
556
+ puts "scan sound: #{ @prefs.play_scan_sound}"
557
+ if effect == 'scanning'
558
+ puts effect
559
+ return unless @prefs.play_scanning_sound
560
+ Gtk.idle_add do
561
+ @sound_players['scanning'].play('scanning')
562
+ false
563
+ end
564
+ else
565
+ puts effect
566
+ return unless @prefs.play_scan_sound
567
+ Gtk.idle_add do
568
+ # sleep(0.5) # "scanning" effect lasts 0.5 seconds, wait for it to end
569
+ @sound_players[effect].play(effect)
570
+ false
571
+ end
572
+ end
573
+ end
574
+
575
+ def developer_test_scan
576
+ log.info { 'Developer test scan.' }
577
+ scans = ['.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3j3C3f1Dxj3Dq.',
578
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3z0CNj3Dhj1EW.',
579
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3r2DNbXCxTZCW.',
580
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGf2.ENr7C3z0DNn0ENnWE3nZDhP6.',
581
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7CNT2CxT2ChP0Dq.',
582
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7CNT6E3f7CNbWDa.',
583
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3b3ENjYDxv3EW.',
584
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3b2DxjZE3b3Dq.',
585
+ '.C3nZC3nZC3n2ChnWENz7DxnY.cGen.ENr7C3n6CNr6DxvYDa.']
586
+ @scanner_buffer = scans[@@debug_index % scans.size]
587
+ @@debug_index += 1
588
+ @test_scan = true
589
+ read_barcode_scan
590
+ @test_scan = false
591
+ end
592
+
593
+ def init_treeview
594
+ liststore = Gtk::ListStore.new(String, Gdk::Pixbuf, String)
595
+
596
+ @barcodes_treeview.selection.mode = Gtk::SELECTION_MULTIPLE
597
+
598
+ @barcodes_treeview.model = liststore
599
+
600
+ text_renderer = Gtk::CellRendererText.new
601
+ text_renderer.editable = false
602
+
603
+ # Add column using our renderer
604
+ col = Gtk::TreeViewColumn.new('ISBN', text_renderer, text: 0)
605
+ @barcodes_treeview.append_column(col)
606
+
607
+ # Middle colulmn is cover-image renderer
608
+ pixbuf_renderer = Gtk::CellRendererPixbuf.new
609
+ col = Gtk::TreeViewColumn.new('Cover', pixbuf_renderer)
610
+
611
+ col.set_cell_data_func(pixbuf_renderer) do |_column, cell, _model, iter|
612
+ pixbuf = iter[1]
613
+ if pixbuf
614
+ max_height = 25
615
+
616
+ if pixbuf.height > max_height
617
+ new_width = pixbuf.width * (max_height.to_f / pixbuf.height)
618
+ pixbuf = pixbuf.scale(new_width, max_height)
619
+ end
620
+
621
+ cell.pixbuf = pixbuf
622
+ end
623
+
624
+ end
625
+
626
+ @barcodes_treeview.append_column(col)
627
+
628
+ # Add column using the second renderer
629
+ col = Gtk::TreeViewColumn.new('Title', text_renderer, text: 2)
630
+ @barcodes_treeview.append_column(col)
631
+
632
+ @barcodes_treeview.model.signal_connect('row-deleted') do |model, _path|
633
+ unless model.iter_first
634
+ @add_button.sensitive = false
635
+ end
636
+ end
637
+ end
638
+ end
639
+ end
640
+ end