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,96 @@
1
+ # Copyright (C) 2005-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
+ require 'thread'
19
+
20
+ # Provides a way for two threads to communicate via Proc objects.
21
+ #
22
+ # Thread A can request calls, providing a Proc object and runtime arguments,
23
+ # and thread B can iterate through the queue and execute the first call it
24
+ # founds.
25
+ #
26
+ # It is also possible to synchronize the calls (useful if a return value is
27
+ # required from the receiving thread).
28
+ #
29
+ # This class does not depend of the GLib/GTK main loop idea.
30
+
31
+ module Alexandria
32
+ class ExecutionQueue
33
+ def initialize
34
+ @pending_calls = []
35
+ @pending_retvals = []
36
+ @protect_pending_calls = Mutex.new
37
+ @protect_pending_retvals = Mutex.new
38
+ @id = 0
39
+ @@current_queue = self
40
+ end
41
+
42
+ def self.current
43
+ @@current_queue rescue nil
44
+ end
45
+
46
+ # For the requesting thread.
47
+ def call(procedure, *args)
48
+ push(procedure, args, false)
49
+ end
50
+
51
+ def sync_call(procedure, *args)
52
+ push(procedure, args, true)
53
+ end
54
+
55
+ # For the executing thread.
56
+ def iterate
57
+ ary = @protect_pending_calls.synchronize do
58
+ break @pending_calls.pop
59
+ end
60
+ return if ary.nil?
61
+ id, procedure, args, need_retval = ary
62
+ retval = procedure.call(*args)
63
+ if need_retval
64
+ @protect_pending_retvals.synchronize do
65
+ @pending_retvals << [id, retval]
66
+ end
67
+ end
68
+ end
69
+
70
+ def stop
71
+ @@current_queue = nil
72
+ end
73
+
74
+ #######
75
+ private
76
+ #######
77
+
78
+ def push(procedure, args, need_retval = false)
79
+ @protect_pending_calls.synchronize do
80
+ @id += 1
81
+ @pending_calls << [@id, procedure, args, need_retval]
82
+ end
83
+ if need_retval
84
+ while true
85
+ @protect_pending_retvals.synchronize do
86
+ ary = @pending_retvals.find { |id, _retval| id == @id }
87
+ if ary
88
+ @pending_retvals.delete(ary)
89
+ return ary[1]
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,536 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2007 Cathal Mc Ginley
3
+ # Copyright (C) 2014 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
+ # Export sorting added 23 Oct 2007 by Cathal Mc Ginley
21
+ # Classes LibrarySortOrder and SortedLibrary, and changed ExportFormat#invoke
22
+ # iPod Notes support added 20 January 2008 by Tim Malone
23
+ # require 'cgi'
24
+
25
+ begin # image_size is optional
26
+ $IMAGE_SIZE_LOADED = true
27
+ require 'image_size'
28
+ rescue LoadError
29
+ $IMAGE_SIZE_LOADED = false
30
+ puts "Can't load image_size, hence exported libraries are not optimized" if $DEBUG
31
+ end
32
+
33
+ module Alexandria
34
+ class LibrarySortOrder
35
+ include Logging
36
+
37
+ def initialize(book_attribute, ascending = true)
38
+ @book_attribute = book_attribute
39
+ @ascending = ascending
40
+ end
41
+
42
+ def sort(library)
43
+ sorted = library.sort_by do |book|
44
+ book.send(@book_attribute)
45
+ end
46
+ unless @ascending
47
+ sorted.reverse!
48
+ end
49
+ sorted
50
+ rescue => ex
51
+ trace = ex.backtrace.join("\n> ")
52
+ log.warn { "Could not sort library by #{@book_attribute} #{ex.message} #{trace}" }
53
+ library
54
+ end
55
+
56
+ def to_s
57
+ "#{@book_attribute} #{@ascending ? '(ascending)' : '(descending)'}"
58
+ end
59
+
60
+ class Unsorted < LibrarySortOrder
61
+ def initialize
62
+ end
63
+
64
+ def sort(library)
65
+ library
66
+ end
67
+
68
+ def to_s
69
+ 'default order'
70
+ end
71
+ end
72
+ end
73
+
74
+ class SortedLibrary < Library
75
+ def initialize(library, sort_order)
76
+ super(library.name)
77
+ @library = library
78
+ sorted = sort_order.sort(library)
79
+ sorted.each do |book|
80
+ self << book
81
+ end
82
+ end
83
+
84
+ def cover(book)
85
+ @library.cover(book)
86
+ end
87
+
88
+ def final_cover(book)
89
+ @library.final_cover(book)
90
+ end
91
+
92
+ def copy_covers(dest)
93
+ @library.copy_covers(dest)
94
+ end
95
+ end
96
+
97
+ class ExportFormat
98
+ attr_reader :name, :ext, :message
99
+
100
+ include GetText
101
+ include Logging
102
+ extend GetText
103
+ bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
104
+
105
+ def self.all
106
+ [
107
+ new(_('Archived ONIX XML'), 'onix.tbz2', :export_as_onix_xml_archive),
108
+ new(_('Archived Tellico XML'), 'tc', :export_as_tellico_xml_archive),
109
+ new(_('BibTeX'), 'bib', :export_as_bibtex),
110
+ new(_('CSV list'), 'csv', :export_as_csv_list),
111
+ new(_('ISBN List'), 'txt', :export_as_isbn_list),
112
+ new(_('iPod Notes'), nil, :export_as_ipod_notes),
113
+ new(_('HTML Web Page'), nil, :export_as_html, true)
114
+ ]
115
+ end
116
+
117
+ def invoke(library, sort_order, filename, *args)
118
+ if sort_order
119
+ sorted = SortedLibrary.new(library, sort_order)
120
+ log.debug { "Exporting library sorted by #{sort_order}" }
121
+ sorted.send(@message, filename, *args)
122
+ else
123
+ library.send(@message, filename, *args)
124
+ end
125
+ end
126
+
127
+ def needs_preview?
128
+ @needs_preview
129
+ end
130
+
131
+ #######
132
+ private
133
+ #######
134
+
135
+ def initialize(name, ext, message, needs_preview = false)
136
+ @name = name
137
+ @ext = ext
138
+ @message = message
139
+ @needs_preview = needs_preview
140
+ end
141
+ end
142
+
143
+ module Exportable
144
+ def export_as_onix_xml_archive(filename)
145
+ File.open(File.join(Dir.tmpdir, 'onix.xml'), 'w') do |io|
146
+ to_onix_document.write(io, 0)
147
+ end
148
+ copy_covers(File.join(Dir.tmpdir, 'images'))
149
+ Dir.chdir(Dir.tmpdir) do
150
+ output = `tar -cjf \"#{filename}\" onix.xml images 2>&1`
151
+ raise output unless $CHILD_STATUS.success?
152
+ end
153
+ FileUtils.rm_rf(File.join(Dir.tmpdir, 'images'))
154
+ FileUtils.rm(File.join(Dir.tmpdir, 'onix.xml'))
155
+ end
156
+
157
+ def export_as_tellico_xml_archive(filename)
158
+ File.open(File.join(Dir.tmpdir, 'tellico.xml'), 'w') do |io|
159
+ begin
160
+ to_tellico_document.write(io, 0)
161
+ rescue => ex
162
+ puts ex.message
163
+ puts ex.backtrace
164
+ raise ex
165
+ end
166
+ end
167
+ copy_covers(File.join(Dir.tmpdir, 'images'))
168
+ Dir.chdir(Dir.tmpdir) do
169
+ output = `zip -q -r \"#{filename}\" tellico.xml images 2>&1`
170
+ raise output unless $CHILD_STATUS.success?
171
+ end
172
+ FileUtils.rm_rf(File.join(Dir.tmpdir, 'images'))
173
+ FileUtils.rm(File.join(Dir.tmpdir, 'tellico.xml'))
174
+ end
175
+
176
+ def export_as_isbn_list(filename)
177
+ File.open(filename, 'w') do |io|
178
+ each do |book|
179
+ io.puts((book.isbn or ''))
180
+ end
181
+ end
182
+ end
183
+
184
+ def export_as_html(filename, theme)
185
+ FileUtils.mkdir(filename) unless File.exist?(filename)
186
+ Dir.chdir(filename) do
187
+ copy_covers('pixmaps')
188
+ FileUtils.cp_r(theme.pixmaps_directory,
189
+ 'pixmaps') if theme.has_pixmaps?
190
+ FileUtils.cp(theme.css_file, '.')
191
+ File.open('index.html', 'w') do |io|
192
+ io << to_xhtml(File.basename(theme.css_file))
193
+ end
194
+ end
195
+ end
196
+
197
+ def export_as_bibtex(filename)
198
+ File.open(filename, 'w') do |io|
199
+ io << to_bibtex
200
+ end
201
+ end
202
+
203
+ def export_as_ipod_notes(filename, _theme)
204
+ FileUtils.mkdir(filename) unless File.exist?(filename)
205
+ tempdir = Dir.getwd
206
+ Dir.chdir(filename)
207
+ copy_covers('pixmaps')
208
+ File.open('index.linx', 'w') do |io|
209
+ io.puts '<TITLE>' + name + '</TITLE>'
210
+ each do |book|
211
+ io.puts '<A HREF="' + book.ident + '">' + book.title + '</A>'
212
+ end
213
+ io.close
214
+ end
215
+ each do |book|
216
+ File.open(book.ident, 'w') do |io|
217
+ io.puts "<TITLE>#{book.title} </TITLE>"
218
+ # put a link to the book's cover. only works on iPod 5G and above(?).
219
+ if File.exist?(cover(book))
220
+ io.puts '<A HREF="pixmaps/' + book.ident + '.jpg' + '">' + book.title + '</A>'
221
+ else
222
+ io.puts book.title
223
+ end
224
+ io.puts book.authors.join(', ')
225
+ io.puts book.edition
226
+ io.puts((book.isbn or ''))
227
+ # we need to close the files so the iPod can be ejected/unmounted without us closing Alexandria
228
+ io.close
229
+ end
230
+
231
+ end
232
+ # Again, allow the iPod to unmount
233
+ Dir.chdir(tempdir)
234
+ end
235
+
236
+ def export_as_csv_list(filename)
237
+ File.open(filename, 'w') do |io|
238
+ io.puts 'Title' + ';' + 'Authors' + ';' + 'Publisher' + ';' + 'Edition' + ';' + 'ISBN' + ';' + 'Year Published' + ';' + 'Rating' + "(0 to #{UI::MainApp::MAX_RATING_STARS})" + ';' + 'Notes' + ';' + 'Want?' + ';' + 'Read?' + ';' + 'Own?' + ';' + 'Tags'
239
+ each do |book|
240
+ io.puts book.title + ';' + book.authors.join(', ') + ';' + (book.publisher or '') + ';' + (book.edition or '') + ';' + (book.isbn or '') + ';' + (book.publishing_year.to_s or '') + ';' + (book.rating.to_s or '0') + ';' + (book.notes or '') + ';' + (book.want ? '1' : '0') + ';' + (book.redd ? '1' : '0') + ';' + (book.own ? '1' : '0') + ';' + (book.tags ? book.tags.join(', ') : '')
241
+ end
242
+ end
243
+ end
244
+
245
+ #######
246
+ private
247
+ #######
248
+
249
+ ONIX_DTD_URL = 'http://www.editeur.org/onix/2.1/reference/onix-international.dtd'
250
+ def to_onix_document
251
+ doc = REXML::Document.new
252
+ doc << REXML::XMLDecl.new
253
+ doc << REXML::DocType.new('ONIXMessage',
254
+ "SYSTEM \"#{ONIX_DTD_URL}\"")
255
+ msg = doc.add_element('ONIXMessage')
256
+ header = msg.add_element('Header')
257
+ header.add_element('FromCompany').text = 'Alexandria'
258
+ header.add_element('FromPerson').text = Etc.getlogin
259
+ now = Time.now
260
+ header.add_element('SentDate').text = '%.4d%.2d%.2d%.2d%.2d' % [
261
+ now.year, now.month, now.day, now.hour, now.min
262
+ ]
263
+ header.add_element('MessageNote').text = name
264
+ each_with_index do |book, idx|
265
+ # fields that are missing: edition and rating.
266
+ prod = msg.add_element('Product')
267
+ prod.add_element('RecordReference').text = idx
268
+ prod.add_element('NotificationType').text = '03' # confirmed
269
+ prod.add_element('RecordSourceName').text =
270
+ 'Alexandria ' + Alexandria::DISPLAY_VERSION
271
+ prod.add_element('ISBN').text = (book.isbn or '')
272
+ prod.add_element('ProductForm').text = 'BA' # book
273
+ prod.add_element('DistinctiveTitle').text = book.title
274
+ unless book.authors.empty?
275
+ book.authors.each do |author|
276
+ elem = prod.add_element('Contributor')
277
+ # author
278
+ elem.add_element('ContributorRole').text = 'A01'
279
+ elem.add_element('PersonName').text = author
280
+ end
281
+ end
282
+ if book.notes and !book.notes.empty?
283
+ elem = prod.add_element('OtherText')
284
+ # reader description
285
+ elem.add_element('TextTypeCode').text = '12'
286
+ elem.add_element('TextFormat').text = '00' # ASCII
287
+ elem.add_element('Text').text = book.notes
288
+ end
289
+ if File.exist?(cover(book))
290
+ elem = prod.add_element('MediaFile')
291
+ # front cover image
292
+ elem.add_element('MediaFileTypeCode').text = '04'
293
+ elem.add_element('MediaFileFormatCode').text =
294
+ (Library.jpeg?(cover(book)) ? '03' : '02')
295
+ # filename
296
+ elem.add_element('MediaFileLinkTypeCode').text = '06'
297
+ elem.add_element('MediaFileLink').text =
298
+ File.join('images', final_cover(book))
299
+ end
300
+ if book.isbn
301
+ BookProviders.each do |provider|
302
+ elem = prod.add_element('ProductWebsite')
303
+ elem.add_element('ProductWebsiteDescription').text =
304
+ provider.fullname
305
+ elem.add_element('ProductWebsiteLink').text =
306
+ provider.url(book)
307
+ end
308
+ end
309
+ elem = prod.add_element('Publisher')
310
+ elem.add_element('PublishingRole').text = '01'
311
+ elem.add_element('PublisherName').text = book.publisher
312
+ prod.add_element('PublicationDate').text = book.publishing_year
313
+ end
314
+ doc
315
+ end
316
+
317
+ def to_tellico_document
318
+ # For the Tellico format, see
319
+ # http://periapsis.org/tellico/doc/hacking.html
320
+ doc = REXML::Document.new
321
+ doc << REXML::XMLDecl.new
322
+ doc << REXML::DocType.new('tellico', "PUBLIC \"-//Robby Stephenson/DTD Tellico V7.0//EN\" \"http://periapsis.org/tellico/dtd/v7/tellico.dtd\"")
323
+ tellico = doc.add_element('tellico')
324
+ tellico.add_attribute('syntaxVersion', '7')
325
+ tellico.add_namespace('http://periapsis.org/tellico/')
326
+ collection = tellico.add_element('collection')
327
+ collection.add_attribute('title', name)
328
+ collection.add_attribute('type', '2')
329
+ fields = collection.add_element('fields')
330
+ field1 = fields.add_element('field')
331
+ # a field named _default implies adding all default book
332
+ # collection fields
333
+ field1.add_attribute('name', '_default')
334
+ images = collection.add_element('images')
335
+ each_with_index do |book, idx|
336
+ entry = collection.add_element('entry')
337
+ new_index = (idx + 1).to_s
338
+ entry.add_attribute('id', new_index)
339
+ # translate the binding
340
+ entry.add_element('title').text = book.title
341
+ entry.add_element('isbn').text = (book.isbn or '')
342
+ entry.add_element('pub_year').text = book.publishing_year
343
+ entry.add_element('binding').text = book.edition
344
+ entry.add_element('publisher').text = book.publisher
345
+ unless book.authors.empty?
346
+ authors = entry.add_element('authors')
347
+ book.authors.each do |author|
348
+ authors.add_element('author').text = author
349
+ end
350
+ end
351
+ entry.add_element('read').text = book.redd.to_s if book.redd
352
+ entry.add_element('loaned').text = book.loaned.to_s if book.loaned
353
+ unless book.rating == Book::DEFAULT_RATING
354
+ entry.add_element('rating').text = book.rating
355
+ end
356
+ if book.notes and !book.notes.empty?
357
+ entry.add_element('comments').text = book.notes
358
+ end
359
+ if File.exist?(cover(book))
360
+ entry.add_element('cover').text = final_cover(book)
361
+ image = images.add_element('image')
362
+ image.add_attribute('id', final_cover(book))
363
+ if $IMAGE_SIZE_LOADED
364
+ image_s = ImageSize.new(IO.read(cover(book)))
365
+ image.add_attribute('height', image_s.get_height.to_s)
366
+ image.add_attribute('width', image_s.get_width.to_s)
367
+ image.add_attribute('format', image_s.get_type)
368
+ else
369
+ image.add_attribute('format',
370
+ Library.jpeg?(cover(book)) ? 'JPEG' : 'GIF')
371
+ end
372
+ end
373
+ end
374
+ doc
375
+ end
376
+
377
+ def xhtml_escape(str)
378
+ escaped = str.dup
379
+ # used to occasionally use CGI.escapeHTML
380
+ escaped.gsub!(/&/, '&amp;')
381
+ escaped.gsub!(/</, '&lt;')
382
+ escaped.gsub!(/>/, '&gt;')
383
+ escaped.gsub!(/\"/, '&quot;')
384
+ escaped
385
+ end
386
+
387
+ def to_xhtml(css)
388
+ generator = 'Alexandria ' + Alexandria::DISPLAY_VERSION
389
+ xhtml = ''
390
+ xhtml << <<EOS
391
+ <?xml version="1.0" encoding="UTF-8"?>
392
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
393
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
394
+ <html>
395
+ <head>
396
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
397
+ <meta name="Author" content="#{Etc.getlogin}"/>
398
+ <meta name="Description" content="List of books"/>
399
+ <meta name="Keywords" content="books"/>
400
+ <meta name="Generator" content="#{xhtml_escape(generator)}"/>
401
+ <title>#{xhtml_escape(name)}</title>
402
+ <link rel="stylesheet" href="#{xhtml_escape(css)}" type="text/css"/>
403
+ </head>
404
+ <body>
405
+ <h1 class="library_name">#{xhtml_escape(name)}</h1>
406
+ EOS
407
+
408
+ each do |book|
409
+ xhtml << <<EOS
410
+ <div class="book">
411
+ <p class="book_isbn">#{book.isbn}</p>
412
+ EOS
413
+
414
+ if File.exist?(cover(book))
415
+ xhtml << <<EOS
416
+ <img class="book_cover"
417
+ src="#{File.join('pixmaps', final_cover(book))}"
418
+ alt="Cover file for '#{xhtml_escape(book.title)}'"
419
+ EOS
420
+ if $IMAGE_SIZE_LOADED
421
+ image_s = ImageSize.new(IO.read(cover(book)))
422
+ xhtml << <<EOS
423
+ height="#{image_s.get_height}" width="#{image_s.get_width}"
424
+ EOS
425
+ end
426
+ xhtml << <<EOS
427
+ />
428
+ EOS
429
+ else
430
+ xhtml << <<EOS
431
+ <div class="no_book_cover"></div>
432
+ EOS
433
+ end
434
+
435
+ unless book.title.nil?
436
+ xhtml << <<EOS
437
+ <p class="book_title">#{xhtml_escape(book.title)}</p>
438
+ EOS
439
+ end
440
+
441
+ unless book.authors.empty?
442
+ xhtml << "<ul class=\"book_authors\">"
443
+ book.authors.each do |author|
444
+ xhtml << <<EOS
445
+ <li class="book_author">#{xhtml_escape(author)}</li>
446
+ EOS
447
+ end
448
+ xhtml << '</ul>'
449
+ end
450
+
451
+ unless book.edition.nil?
452
+ xhtml << <<EOS
453
+ <p class="book_binding">#{xhtml_escape(book.edition)}</p>
454
+ EOS
455
+ end
456
+
457
+ unless book.publisher.nil?
458
+ xhtml << <<EOS
459
+ <p class="book_publisher">#{xhtml_escape(book.publisher)}</p>
460
+ EOS
461
+ end
462
+
463
+ xhtml << <<EOS
464
+ </div>
465
+ EOS
466
+ end
467
+ xhtml << <<EOS
468
+ <p class="copyright">
469
+ Generated on #{xhtml_escape(Date.today.to_s)} by <a href="#{xhtml_escape(Alexandria::WEBSITE_URL)}">#{xhtml_escape(generator)}</a>.
470
+ </p>
471
+ </body>
472
+ </html>
473
+ EOS
474
+ end
475
+
476
+ def to_bibtex
477
+ generator = 'Alexandria ' + Alexandria::DISPLAY_VERSION
478
+ bibtex = ''
479
+ bibtex << "\%Generated on #{Date.today} by: #{generator}\n"
480
+ bibtex << "\%\n"
481
+ bibtex << "\n"
482
+
483
+ auths = Hash.new(0)
484
+ each do |book|
485
+ k = (book.authors[0] or 'Anonymous').split[0]
486
+ if auths.key?(k)
487
+ auths[k] += 1
488
+ else
489
+ auths[k] = 1
490
+ end
491
+ cite_key = k + auths[k].to_s
492
+ bibtex << "@BOOK{#{cite_key},\n"
493
+ bibtex << "author = \""
494
+ if book.authors != []
495
+ bibtex << book.authors[0]
496
+ book.authors[1..-1].each do |author|
497
+ bibtex << " and #{latex_escape(author)}"
498
+ end
499
+ end
500
+ bibtex << "\",\n"
501
+ bibtex << "title = \"#{latex_escape(book.title)}\",\n"
502
+ bibtex << "publisher = \"#{latex_escape(book.publisher)}\",\n"
503
+ if book.notes and !book.notes.empty?
504
+ bibtex << "OPTnote = \"#{latex_escape(book.notes)}\",\n"
505
+ end
506
+ # year is a required field in bibtex @BOOK
507
+ bibtex << 'year = ' + (book.publishing_year or "\"n/a\"").to_s + "\n"
508
+ bibtex << "}\n\n"
509
+ end
510
+ bibtex
511
+ end
512
+
513
+ def latex_escape(str)
514
+ return '' if str.nil?
515
+ my_str = str.dup
516
+ my_str.gsub!(/%/, '\\%')
517
+ my_str.gsub!(/~/, '\\textasciitilde')
518
+ my_str.gsub!(/\&/, '\\\\&')
519
+ my_str.gsub!(/\#/, '\\\\#')
520
+ my_str.gsub!(/\{/, '\\{')
521
+ my_str.gsub!(/\}/, '\\}')
522
+ my_str.gsub!(/_/, '\\_')
523
+ my_str.gsub!(/\$/, "\\\$")
524
+ my_str.gsub!(/\"(.+)\"/, "``\1''")
525
+ my_str
526
+ end
527
+ end
528
+
529
+ class Library
530
+ include Exportable
531
+ end
532
+
533
+ class SmartLibrary
534
+ include Exportable
535
+ end
536
+ end