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,432 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2011, 2014 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
+ # require 'alexandria/ui/glade_base'
20
+
21
+ module Alexandria
22
+ module UI
23
+ class BookPropertiesDialogBase < BuilderBase
24
+ include GetText
25
+ extend GetText
26
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
27
+
28
+ COVER_MAXWIDTH = 140 # pixels
29
+
30
+ COVER_ABSOLUTE_MAXHEIGHT = 250 # pixels, above this we scale down...
31
+
32
+ def initialize(parent, cover_file)
33
+ super('book_properties_dialog__builder.glade', widget_names)
34
+ @setup_finished = false
35
+ @book_properties_dialog.transient_for = parent
36
+ @parent, @cover_file = parent, cover_file
37
+ @original_cover_file = nil
38
+ @delete_cover_file = false # fixing bug #16707
39
+
40
+ @entry_title.complete_titles
41
+ @entry_title.grab_focus
42
+ @entry_publisher.complete_publishers
43
+ @entry_edition.complete_editions
44
+ @entry_loaned_to.complete_borrowers
45
+
46
+ @entry_tags.complete_tags
47
+
48
+ @treeview_authors.model = Gtk::ListStore.new(String, TrueClass)
49
+ @treeview_authors.selection.mode = Gtk::SELECTION_SINGLE
50
+ renderer = Gtk::CellRendererText.new
51
+ renderer.signal_connect('edited') do |_cell, path_string, new_text|
52
+ path = Gtk::TreePath.new(path_string)
53
+ iter = @treeview_authors.model.get_iter(path)
54
+ iter[0] = new_text
55
+ end
56
+ renderer.signal_connect('editing_started') do |_cell, entry, _path_string|
57
+ entry.complete_authors
58
+ end
59
+ col = Gtk::TreeViewColumn.new('', renderer,
60
+ text: 0,
61
+ editable: 1)
62
+ @treeview_authors.append_column(col)
63
+
64
+ setup_calendar_widgets
65
+ Gtk.timeout_add(150) do
66
+ @setup_finished = true
67
+
68
+ false
69
+ end
70
+ end
71
+
72
+ def setup_calendar_widgets
73
+ @popup_displayed = false
74
+ @calendar_popup = Gtk::Window.new # Gtk::Window::POPUP)
75
+ # @calendar_popup.modal = true
76
+ @calendar_popup.decorated = false
77
+ @calendar_popup.skip_taskbar_hint = true
78
+ @calendar_popup.skip_pager_hint = true
79
+ @calendar_popup.events = [Gdk::Event::FOCUS_CHANGE_MASK]
80
+
81
+ @calendar_popup.set_transient_for(@book_properties_dialog)
82
+ @calendar_popup.set_type_hint(Gdk::Window::TYPE_HINT_DIALOG)
83
+ @calendar_popup.name = 'calendar-popup'
84
+ @calendar_popup.resizable = false
85
+ # @calendar_popup.border_width = 4
86
+ # @calendar_popup.app_paintable = true
87
+
88
+ @calendar_popup.signal_connect('focus-out-event') do |_popup, _event|
89
+ hide_calendar_popup
90
+ false
91
+ end
92
+
93
+ @calendar = Gtk::Calendar.new
94
+ @calendar_popup.add(@calendar)
95
+
96
+ @calendar.signal_connect('day-selected') do
97
+ date_arr = @calendar.date
98
+ year = date_arr[0]
99
+ month = date_arr[1] # + 1 # gtk : months 0-indexed, Time.gm : 1-index
100
+ day = date_arr[2]
101
+ if @calendar_popup_for_entry
102
+ time = Time.gm(year, month, day)
103
+ @calendar_popup_for_entry.text = format_date(time)
104
+ end
105
+
106
+ end
107
+
108
+ @calendar.signal_connect('day-selected-double-click') do
109
+ date_arr = @calendar.date
110
+ year = date_arr[0]
111
+ month = date_arr[1] # + 1 # gtk : months 0-indexed, Time.gm : 1-index
112
+ day = date_arr[2]
113
+ if @calendar_popup_for_entry
114
+ time = Time.gm(year, month, day)
115
+ @calendar_popup_for_entry.text = format_date(time)
116
+ end
117
+ hide_calendar_popup
118
+ end
119
+
120
+ @redd_date.signal_connect('icon-press') do |entry, primary, _icon|
121
+ if primary.nick == 'primary'
122
+ display_calendar_popup(entry)
123
+ elsif primary.nick == 'secondary'
124
+ clear_date_entry(entry)
125
+ end
126
+ end
127
+
128
+ @date_loaned_since.signal_connect('icon-press') do |entry, primary, _icon|
129
+ if primary.nick == 'primary'
130
+ display_calendar_popup(entry)
131
+ elsif primary.nick == 'secondary'
132
+ clear_date_entry(entry)
133
+ @label_loaning_duration.label = ''
134
+ end
135
+ end
136
+ end
137
+
138
+ def clear_date_entry(entry)
139
+ entry.text = ''
140
+ end
141
+
142
+ def hide_calendar_popup
143
+ @calendar_popup_for_entry = nil
144
+
145
+ @calendar_popup.hide_all
146
+ @book_properties_dialog.modal = true
147
+
148
+ Gtk.timeout_add(150) do
149
+
150
+ # If we set @popup_displayed=false immediately, then a click
151
+ # event on the primary icon of the Entry simultaneous with
152
+ # the focus-out-event of the Calendar causes the Calendar to
153
+ # pop up again milliseconds after being closed.
154
+ #
155
+ # This is never what the user intends.
156
+ #
157
+ # So we add a small delay before the primary icon's event
158
+ # handler is told to pop up the calendar in response to
159
+ # clicks.
160
+
161
+ @popup_displayed = false
162
+ false
163
+ end
164
+ end
165
+
166
+ def display_calendar_popup(entry)
167
+ if @popup_displayed
168
+ hide_calendar_popup
169
+ else
170
+ @calendar_popup_for_entry = entry
171
+ unless entry.text.strip.empty?
172
+ time = parse_date(entry.text)
173
+ unless time.nil?
174
+ @calendar.year = time.year
175
+ @calendar.month = time.month - 1
176
+ @calendar.day = time.day
177
+ end
178
+ end
179
+ @book_properties_dialog.modal = false
180
+ @calendar_popup.move(*get_entry_popup_coords(entry))
181
+ @calendar_popup.show_all
182
+ @popup_displayed = true
183
+ end
184
+ end
185
+
186
+ def get_entry_popup_coords(entry)
187
+ gdk_win = entry.parent_window
188
+ x, y = gdk_win.origin
189
+ alloc = entry.allocation
190
+ x += alloc.x
191
+ y += alloc.y
192
+ y += alloc.height
193
+ # x = [0, x].max
194
+ # y = [0, y].max
195
+ [x, y]
196
+ end
197
+
198
+ def widget_names
199
+ [:book_properties_dialog, :dialog_vbox1, :button_box,
200
+ :notebook1, :hbox1, :table1, :label1, :label7, :entry_title,
201
+ :entry_publisher, :label5, :entry_isbn, :hbox3,
202
+ :scrolledwindow2, :treeview_authors, :vbox2, :button3,
203
+ :image2, :button4, :image3, :label3, :label9, :entry_edition,
204
+ :label16, :entry_publish_date, :label17, :entry_tags,
205
+ :vseparator1, :vbox1, :label12, :button_cover, :image_cover,
206
+ :vbox4, :vbox5, :checkbutton_own, :vbox6, :checkbutton_redd,
207
+ :redd_date, :checkbutton_want, :eventbox8, :hbox2,
208
+ :eventbox6, :image5, :eventbox1, :image_rating1, :eventbox5,
209
+ :image_rating2, :eventbox4, :image_rating3, :eventbox3,
210
+ :image_rating4, :eventbox2, :image_rating5, :eventbox7,
211
+ :image4, :label11, :label9, :vbox3, :checkbutton_loaned,
212
+ :table2, :entry_loaned_to, :label_loaning_duration, :label15,
213
+ :label14, :date_loaned_since, :label13, :scrolledwindow1,
214
+ :textview_notes, :label10]
215
+ end
216
+
217
+ def on_title_changed
218
+ title = @entry_title.text.strip
219
+ @book_properties_dialog.title = if title.empty?
220
+ _('Properties')
221
+ else
222
+ _("Properties for '%s'") % title
223
+ end
224
+ end
225
+
226
+ def on_add_author
227
+ iter = @treeview_authors.model.append
228
+ iter[0] = _('Author')
229
+ iter[1] = true
230
+ @treeview_authors.set_cursor(iter.path,
231
+ @treeview_authors.get_column(0),
232
+ true)
233
+ end
234
+
235
+ def on_remove_author
236
+ iter = @treeview_authors.selection.selected
237
+ @treeview_authors.model.remove(iter) if iter
238
+ end
239
+
240
+ def on_image_rating1_press
241
+ self.rating = 1
242
+ end
243
+
244
+ def on_image_rating2_press
245
+ self.rating = 2
246
+ end
247
+
248
+ def on_image_rating3_press
249
+ self.rating = 3
250
+ end
251
+
252
+ def on_image_rating4_press
253
+ self.rating = 4
254
+ end
255
+
256
+ def on_image_rating5_press
257
+ self.rating = 5
258
+ end
259
+
260
+ def on_image_no_rating_press
261
+ self.rating = 0
262
+ end
263
+
264
+ def own_toggled
265
+ if @checkbutton_own.active?
266
+ @checkbutton_want.inconsistent = true
267
+ else
268
+ @checkbutton_want.inconsistent = false
269
+ end
270
+ end
271
+
272
+ def want_toggled
273
+ end
274
+
275
+ @@latest_filechooser_directory = ENV['HOME']
276
+ def on_change_cover
277
+ backend = `uname`.chomp == 'FreeBSD' ? 'neant' : 'gnome-vfs'
278
+ dialog = Gtk::FileChooserDialog.new(_('Select a cover image'),
279
+ @book_properties_dialog,
280
+ Gtk::FileChooser::ACTION_OPEN,
281
+ backend,
282
+ [_('No Cover'), Gtk::Dialog::RESPONSE_REJECT],
283
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
284
+ [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT])
285
+ dialog.current_folder = @@latest_filechooser_directory
286
+ response = dialog.run
287
+ if response == Gtk::Dialog::RESPONSE_ACCEPT
288
+ begin
289
+ @delete_cover_file = false
290
+ cover = Gdk::Pixbuf.new(dialog.filename)
291
+ # At this stage the file format is recognized.
292
+
293
+ if File.exist?(@cover_file)
294
+ unless @original_cover_file
295
+ # make a back up, but only of the original
296
+ @original_cover_file = "#{@cover_file}~"
297
+ FileUtils.cp(@cover_file, @original_cover_file)
298
+ end
299
+ end
300
+ if cover.height > COVER_ABSOLUTE_MAXHEIGHT
301
+ FileUtils.cp(dialog.filename, "#{@cover_file}.orig")
302
+ new_width = cover.width / (cover.height / COVER_ABSOLUTE_MAXHEIGHT.to_f)
303
+ puts "Scaling large cover image to #{new_width.to_i} x #{COVER_ABSOLUTE_MAXHEIGHT}"
304
+ cover = cover.scale(new_width.to_i, COVER_ABSOLUTE_MAXHEIGHT)
305
+ cover.save(@cover_file, 'jpeg')
306
+ else
307
+ FileUtils.cp(dialog.filename, @cover_file)
308
+ end
309
+
310
+ self.cover = cover
311
+ @@latest_filechooser_directory = dialog.current_folder
312
+ rescue RuntimeError => e
313
+ ErrorDialog.new(@book_properties_dialog, e.message)
314
+ end
315
+ elsif response == Gtk::Dialog::RESPONSE_REJECT
316
+ ## FileUtils.rm_f(@cover_file) # fixing bug #16707
317
+ @delete_cover_file = true
318
+
319
+ self.cover = Icons::BOOK_ICON
320
+ end
321
+ dialog.destroy
322
+ end
323
+
324
+ def on_destroy; end # no action by default
325
+
326
+ def on_loaned
327
+ loaned = @checkbutton_loaned.active?
328
+ @entry_loaned_to.sensitive = loaned
329
+ @date_loaned_since.sensitive = loaned
330
+ @label_loaning_duration.visible = loaned
331
+ end
332
+
333
+ def on_loaned_date_changed
334
+ date_regexes = [/[0123]?[0-9]\/[0123]?[0-9]\/[0-9]{4}/,
335
+ /[0-9]{4}-[0123]?[0-9]-[0123]?[0-9]/]
336
+ matches_regex = false
337
+ date_regexes.each do |regex|
338
+ matches_regex = regex.match(@date_loaned_since.text)
339
+ break if matches_regex
340
+ end
341
+ unless matches_regex
342
+ return
343
+ end
344
+ t = parse_date(@date_loaned_since.text)
345
+ if t.nil?
346
+ @label_loaning_duration.label = ''
347
+ return
348
+ end
349
+ loaned_time = Time.at(t)
350
+ n_days = ((Time.now - loaned_time) / (3600 * 24)).to_i
351
+ if n_days > 365_250 # 1,000 years
352
+ @label_loaning_duration.label = ''
353
+ return
354
+ end
355
+ @label_loaning_duration.label = if n_days > 0
356
+ n_('%d day', '%d days', n_days) % n_days
357
+ else
358
+ ''
359
+ end
360
+ end
361
+
362
+ def redd_toggled
363
+ redd_yes = @checkbutton_redd.active?
364
+ @redd_date.sensitive = redd_yes
365
+ if @setup_finished
366
+ # don't do this when popping up the dialog for the first time
367
+ if redd_yes && @redd_date.text.strip.empty?
368
+ display_calendar_popup(@redd_date)
369
+ end
370
+ end
371
+ end
372
+
373
+ #######
374
+ private
375
+ #######
376
+
377
+ def rating=(rating)
378
+ images = [
379
+ @image_rating1,
380
+ @image_rating2,
381
+ @image_rating3,
382
+ @image_rating4,
383
+ @image_rating5
384
+ ]
385
+ raise 'out of range' if rating < 0 or rating > images.length
386
+ images[0..rating - 1].each { |x| x.pixbuf = Icons::STAR_SET }
387
+ images[rating..-1].each { |x| x.pixbuf = Icons::STAR_UNSET }
388
+ @current_rating = rating
389
+ end
390
+
391
+ def cover=(pixbuf)
392
+ if pixbuf.width > COVER_MAXWIDTH
393
+ new_height = pixbuf.height / (pixbuf.width / COVER_MAXWIDTH.to_f)
394
+ # We don't want to modify in place the given pixbuf,
395
+ # that's why we make a copy.
396
+ pixbuf = pixbuf.scale(COVER_MAXWIDTH, new_height)
397
+ end
398
+ @image_cover.pixbuf = pixbuf
399
+ end
400
+
401
+ def loaned_since=(time)
402
+ if time.nil?
403
+ @date_loaned_since.text = ''
404
+ @label_loaning_duration.label = ''
405
+ else
406
+ @date_loaned_since.text = format_date(time)
407
+ on_loaned_date_changed
408
+ end
409
+ # XXX 'date_changed' signal not automatically called after #time=.
410
+ end
411
+
412
+ def redd_when=(time)
413
+ @redd_date.text = format_date(time)
414
+ end
415
+
416
+ def parse_date(datestring)
417
+ date_format = '%d/%m/%Y' # or '%m/%d/%Y' for USA and Canada ; or '%Y-%m-%d' for most of Asia
418
+ ## http://en.wikipedia.org/wiki/Calendar_date#Middle_endian_forms.2C_starting_with_the_month
419
+ begin
420
+ d = Date.strptime(datestring, date_format)
421
+ Time.gm(d.year, d.month, d.day)
422
+ rescue
423
+ nil
424
+ end
425
+ end
426
+
427
+ def format_date(datetime)
428
+ datetime.strftime('%d/%m/%Y')
429
+ end
430
+ end
431
+ end
432
+ end
@@ -0,0 +1,172 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2014 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
+ module Alexandria
20
+ module UI
21
+ class ConfirmEraseDialog < AlertDialog
22
+ include GetText
23
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
24
+
25
+ def initialize(parent, filename)
26
+ super(parent, _('File already exists'),
27
+ Gtk::Stock::DIALOG_QUESTION,
28
+ [[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
29
+ [_('_Replace'), Gtk::Dialog::RESPONSE_OK]],
30
+ _("A file named '%s' already exists. Do you want " \
31
+ 'to replace it with the one you are generating?') % filename)
32
+ self.default_response = Gtk::Dialog::RESPONSE_CANCEL
33
+ show_all and @response = run
34
+ destroy
35
+ end
36
+
37
+ def erase?
38
+ @response == Gtk::Dialog::RESPONSE_OK
39
+ end
40
+ end
41
+
42
+ class ExportDialog < Gtk::FileChooserDialog
43
+ include GetText
44
+ extend GetText
45
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
46
+
47
+ FORMATS = Alexandria::ExportFormat.all
48
+ THEMES = Alexandria::WebTheme.all
49
+
50
+ def initialize(parent, library, sort_order)
51
+ backend = `uname`.chomp == 'FreeBSD' ? 'neant' : 'gnome-vfs'
52
+ super(_("Export '%s'") % library.name,
53
+ nil,
54
+ Gtk::FileChooser::ACTION_SAVE,
55
+ backend,
56
+ [Gtk::Stock::HELP, Gtk::Dialog::RESPONSE_HELP],
57
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
58
+ [_('_Export'), Gtk::Dialog::RESPONSE_ACCEPT])
59
+
60
+ self.transient_for = parent
61
+ self.current_name = library.name
62
+ signal_connect('destroy') { hide }
63
+
64
+ @parent, @library, @sort_order = parent, library, sort_order
65
+
66
+ preview_image = Gtk::Image.new
67
+
68
+ theme_combo = Gtk::ComboBox.new
69
+ THEMES.each do |theme|
70
+ theme_combo.append_text(theme.name)
71
+ end
72
+ theme_combo.signal_connect('changed') do
73
+ file = THEMES[theme_combo.active].preview_file
74
+ preview_image.pixbuf = Gdk::Pixbuf.new(file)
75
+ end
76
+ theme_combo.active = 0
77
+ theme_label = Gtk::Label.new(_('_Theme:'), true)
78
+ theme_label.xalign = 0
79
+ theme_label.mnemonic_widget = theme_combo
80
+
81
+ types_combo = Gtk::ComboBox.new
82
+ FORMATS.each do |format|
83
+ text = format.name + ' ('
84
+ if format.ext
85
+ text += '*.' + format.ext
86
+ else
87
+ text += _('directory')
88
+ end
89
+ text += ')'
90
+ types_combo.append_text(text)
91
+ end
92
+ types_combo.active = 0
93
+ types_combo.signal_connect('changed') do
94
+ theme_label.visible = theme_combo.visible =
95
+ preview_image.visible =
96
+ FORMATS[types_combo.active].needs_preview?
97
+ end
98
+ types_combo.show
99
+
100
+ types_label = Gtk::Label.new(_('Export for_mat:'), true)
101
+ types_label.xalign = 0
102
+ types_label.mnemonic_widget = types_combo
103
+ types_label.show
104
+
105
+ # Ugly hack to add more rows in the internal Gtk::Table of the
106
+ # widget, which is needed because we want the export type to be
107
+ # aligned against the other widgets, and #extra_widget doesn't do
108
+ # that...
109
+ internal_table =
110
+ children[0].children[0].children[0].children[0].children[0]
111
+ internal_table.resize(4, 3)
112
+ internal_table.attach(types_label, 0, 1, 2, 3)
113
+ internal_table.attach(types_combo, 1, 2, 2, 3)
114
+ internal_table.attach(theme_label, 0, 1, 3, 4)
115
+ internal_table.attach(theme_combo, 1, 2, 3, 4)
116
+ internal_table.attach(preview_image, 2, 3, 0, 4)
117
+
118
+ while (response = run) != Gtk::Dialog::RESPONSE_CANCEL and
119
+ response != Gtk::Dialog::RESPONSE_DELETE_EVENT
120
+
121
+ if response == Gtk::Dialog::RESPONSE_HELP
122
+ Alexandria::UI.display_help(self, 'exporting')
123
+ else
124
+ begin
125
+ break if on_export(FORMATS[types_combo.active],
126
+ THEMES[theme_combo.active])
127
+ rescue => e
128
+ ErrorDialog.new(self, _('Export failed'), e.message)
129
+ end
130
+ end
131
+ end
132
+ destroy
133
+ end
134
+
135
+ #######
136
+ private
137
+ #######
138
+
139
+ def on_export(format, theme)
140
+ unless @library.respond_to?(format.message)
141
+ raise NotImplementedError
142
+ end
143
+ filename = self.filename
144
+ if format.ext
145
+ filename += '.' + format.ext if File.extname(filename).empty?
146
+ if File.exist?(filename)
147
+ dialog = ConfirmEraseDialog.new(@parent, filename)
148
+ return unless dialog.erase?
149
+ FileUtils.rm(filename)
150
+ end
151
+ args = []
152
+ else
153
+ if File.exist?(filename)
154
+ unless File.directory?(filename)
155
+ msg = _("The target, named '%s', is a regular " \
156
+ 'file. A directory is needed for this ' \
157
+ 'operation. Please select a directory and ' \
158
+ 'try again.') % filename
159
+ ErrorDialog.new(@parent, _('Not a directory'), msg)
160
+ return
161
+ end
162
+ else
163
+ Dir.mkdir(filename)
164
+ end
165
+ args = [theme]
166
+ end
167
+ format.invoke(@library, @sort_order, filename, *args)
168
+ true
169
+ end
170
+ end
171
+ end
172
+ end