alexandria-book-collection-manager 0.7.2 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +77 -0
  4. data/.gitignore +5 -1
  5. data/.hound.yml +2 -0
  6. data/.rubocop.yml +87 -37
  7. data/.rubocop_todo.yml +62 -191
  8. data/.simplecov +5 -2
  9. data/CHANGELOG.md +63 -0
  10. data/Gemfile +4 -3
  11. data/INSTALL.md +26 -14
  12. data/README.md +52 -42
  13. data/Rakefile +93 -109
  14. data/TODO.md +9 -1
  15. data/alexandria-book-collection-manager.gemspec +50 -43
  16. data/bin/alexandria +30 -53
  17. data/doc/FAQ +2 -6
  18. data/doc/dependency_decisions.yml +27 -8
  19. data/lib/alexandria.rb +27 -37
  20. data/lib/alexandria/about.rb +50 -50
  21. data/lib/alexandria/book_providers.rb +90 -97
  22. data/lib/alexandria/book_providers/adlibris.rb +41 -76
  23. data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
  24. data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
  25. data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
  26. data/lib/alexandria/book_providers/douban.rb +26 -42
  27. data/lib/alexandria/book_providers/proxis.rb +44 -55
  28. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  29. data/lib/alexandria/book_providers/siciliano.rb +64 -65
  30. data/lib/alexandria/book_providers/thalia.rb +42 -41
  31. data/lib/alexandria/book_providers/web.rb +15 -33
  32. data/lib/alexandria/book_providers/worldcat.rb +70 -97
  33. data/lib/alexandria/book_providers/z3950.rb +160 -173
  34. data/lib/alexandria/config.rb +1 -1
  35. data/lib/alexandria/console.rb +8 -21
  36. data/lib/alexandria/default_preferences.rb +37 -0
  37. data/lib/alexandria/execution_queue.rb +15 -13
  38. data/lib/alexandria/export_format.rb +47 -0
  39. data/lib/alexandria/export_library.rb +193 -300
  40. data/lib/alexandria/import_library.rb +108 -141
  41. data/lib/alexandria/import_library_csv.rb +43 -46
  42. data/lib/alexandria/library_collection.rb +79 -0
  43. data/lib/alexandria/library_sort_order.rb +45 -0
  44. data/lib/alexandria/library_store.rb +233 -0
  45. data/lib/alexandria/logging.rb +11 -13
  46. data/lib/alexandria/models/book.rb +13 -20
  47. data/lib/alexandria/models/library.rb +81 -353
  48. data/lib/alexandria/net.rb +5 -6
  49. data/lib/alexandria/preferences.rb +73 -87
  50. data/lib/alexandria/scanners.rb +2 -2
  51. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
  52. data/lib/alexandria/scanners/keyboard.rb +8 -8
  53. data/lib/alexandria/smart_library.rb +133 -170
  54. data/lib/alexandria/ui.rb +15 -15
  55. data/lib/alexandria/ui/about_dialog.rb +49 -0
  56. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
  57. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  58. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  59. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  60. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
  61. data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
  62. data/lib/alexandria/ui/builder_base.rb +7 -27
  63. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  64. data/lib/alexandria/ui/callbacks.rb +189 -183
  65. data/lib/alexandria/ui/completion_models.rb +10 -23
  66. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  67. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  68. data/lib/alexandria/ui/dndable.rb +7 -7
  69. data/lib/alexandria/ui/error_dialog.rb +25 -0
  70. data/lib/alexandria/ui/export_dialog.rb +142 -0
  71. data/lib/alexandria/ui/icons.rb +47 -63
  72. data/lib/alexandria/ui/iconview.rb +12 -10
  73. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  74. data/lib/alexandria/ui/import_dialog.rb +157 -0
  75. data/lib/alexandria/ui/init.rb +21 -33
  76. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  77. data/lib/alexandria/ui/libraries_combo.rb +16 -14
  78. data/lib/alexandria/ui/listview.rb +73 -87
  79. data/lib/alexandria/ui/main_app.rb +24 -26
  80. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  81. data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
  82. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
  83. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  84. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  85. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  86. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  87. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  88. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  89. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  90. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
  91. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  92. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  93. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  94. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  95. data/lib/alexandria/ui/sound.rb +11 -13
  96. data/lib/alexandria/ui/ui_manager.rb +236 -251
  97. data/lib/alexandria/undo_manager.rb +1 -0
  98. data/lib/alexandria/version.rb +4 -19
  99. data/lib/alexandria/web_themes.rb +22 -21
  100. data/po/Makefile +2 -2
  101. data/po/cs.po +993 -880
  102. data/po/cy.po +957 -874
  103. data/po/de.po +990 -869
  104. data/po/el.po +989 -869
  105. data/po/es.po +985 -865
  106. data/po/fr.po +986 -870
  107. data/po/ga.po +907 -823
  108. data/po/gl.po +981 -865
  109. data/po/it.po +986 -868
  110. data/po/ja.po +969 -853
  111. data/po/mk.po +983 -863
  112. data/po/nb.po +979 -863
  113. data/po/nl.po +983 -864
  114. data/po/pl.po +1017 -974
  115. data/po/pt.po +988 -861
  116. data/po/pt_BR.po +984 -868
  117. data/po/ru.po +992 -873
  118. data/po/sk.po +987 -869
  119. data/po/sv.po +977 -861
  120. data/po/uk.po +975 -865
  121. data/po/zh_TW.po +976 -860
  122. data/schemas/alexandria.schemas +25 -3
  123. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  124. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  125. data/share/alexandria/glade/main_app__builder.glade +24 -33
  126. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  127. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  128. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  129. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  130. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  131. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  132. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  133. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  134. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  135. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  136. data/spec/alexandria/book_providers_spec.rb +75 -171
  137. data/spec/alexandria/book_spec.rb +12 -10
  138. data/spec/alexandria/console_spec.rb +27 -0
  139. data/spec/alexandria/export_library_spec.rb +130 -0
  140. data/spec/alexandria/library_spec.rb +128 -172
  141. data/spec/alexandria/library_store_spec.rb +37 -0
  142. data/spec/alexandria/preferences_spec.rb +44 -17
  143. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  144. data/spec/alexandria/smart_library_spec.rb +30 -25
  145. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  146. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  148. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  150. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  152. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  153. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  154. data/spec/alexandria/ui/icons_spec.rb +26 -0
  155. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  156. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  157. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  159. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  160. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  161. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  162. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  163. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  164. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  165. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  166. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  167. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  168. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  169. data/spec/alexandria/ui/sound_spec.rb +2 -2
  170. data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
  171. data/spec/end_to_end/basic_run_spec.rb +52 -0
  172. data/spec/spec_helper.rb +65 -33
  173. data/tasks/setup.rb +2 -2
  174. data/tasks/spec.rake +16 -3
  175. data/util/rake/fileinstall.rb +39 -35
  176. data/util/rake/gettextgenerate.rb +7 -7
  177. data/util/rake/omfgenerate.rb +7 -7
  178. metadata +178 -45
  179. data/dogtail/basic_run_test.py +0 -9
  180. data/lib/alexandria/book_providers/deastore.rb +0 -265
  181. data/lib/alexandria/book_providers/mcu.rb +0 -182
  182. data/lib/alexandria/book_providers/renaud.rb +0 -149
  183. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
  184. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
  185. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
  186. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
  187. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  188. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  189. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
  190. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  191. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  192. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
  193. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
  194. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
  195. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  196. data/spec/alexandria/ui/dialogs_spec.rb +0 -96
  197. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  198. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  199. data/spec/alexandria/utilities_spec.rb +0 -52
  200. data/tasks/dogtail.rake +0 -6
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ module Alexandria
8
+ module UI
9
+ class AlertDialog
10
+ def initialize(parent, title, stock_icon, buttons, message = nil)
11
+ @dialog = Gtk::Dialog.new(title: "", parent: parent, flags: :destroy_with_parent,
12
+ buttons: buttons)
13
+ @dialog.border_width = 6
14
+ @dialog.resizable = false
15
+ @dialog.child.spacing = 12
16
+
17
+ hbox = Gtk::Box.new(:horizontal, 12)
18
+ hbox.homogeneous = false
19
+ hbox.border_width = 6
20
+
21
+ image = Gtk::Image.new(stock: stock_icon,
22
+ size: Gtk::IconSize::DIALOG)
23
+ image.set_alignment(0.5, 0)
24
+ hbox.pack_start(image)
25
+
26
+ vbox = Gtk::Box.new(:vertical, 6)
27
+ vbox.homogeneous = false
28
+ vbox.pack_start make_label("<b><big>#{title}</big></b>")
29
+ vbox.pack_start make_label(message.strip) unless message
30
+ hbox.pack_start(vbox)
31
+
32
+ @dialog.child.pack_start(hbox)
33
+ end
34
+
35
+ def show_all
36
+ dialog.show_all
37
+ end
38
+
39
+ def run
40
+ dialog.run
41
+ end
42
+
43
+ def destroy
44
+ dialog.destroy
45
+ end
46
+
47
+ def default_response=(response)
48
+ dialog.default_response = response
49
+ end
50
+
51
+ private
52
+
53
+ attr_reader :dialog
54
+
55
+ def make_label(markup)
56
+ label = Gtk::Label.new
57
+ label.set_alignment(0, 0)
58
+ label.wrap = label.selectable = true
59
+ label.markup = markup
60
+ label
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ module Alexandria
8
+ module UI
9
+ # Generalized Dialog for lists of bad isbns. Used for on_import. Can also
10
+ # be used for on_load library conversions.
11
+ class BadIsbnsDialog
12
+ def initialize(parent, message, list)
13
+ @dialog = Gtk::MessageDialog.new(parent: parent,
14
+ flags: :modal,
15
+ type: :warning,
16
+ buttons: :close,
17
+ message: message)
18
+ the_vbox = @dialog.children.first
19
+
20
+ isbn_container = Gtk::Box.new :horizontal
21
+ the_vbox.pack_start(isbn_container)
22
+ the_vbox.reorder_child(isbn_container, 3)
23
+ scrolley = Gtk::ScrolledWindow.new
24
+ isbn_container.pack_start(scrolley)
25
+ textview = Gtk::TextView.new(Gtk::TextBuffer.new)
26
+ textview.editable = false
27
+ textview.cursor_visible = false
28
+ scrolley.add(textview)
29
+ list.each do |li|
30
+ textview.buffer.insert_at_cursor("#{li}\n")
31
+ end
32
+
33
+ @dialog.signal_connect("response") { @dialog.destroy }
34
+ end
35
+
36
+ def show
37
+ @dialog.show_all
38
+ end
39
+ end
40
+ end
41
+ end
@@ -23,7 +23,7 @@
23
23
  # Boston, MA 02110-1301 USA.
24
24
  #++
25
25
 
26
- require 'gobject-introspection'
26
+ require "gobject-introspection"
27
27
 
28
28
  module GooCanvas
29
29
  class << self
@@ -42,7 +42,7 @@ module GooCanvas
42
42
  remove_method(:const_missing)
43
43
  end
44
44
  loader = GObjectIntrospection::Loader.new(self)
45
- loader.load('GooCanvas')
45
+ loader.load("GooCanvas")
46
46
  end
47
47
  end
48
48
  end
@@ -91,16 +91,16 @@ module Alexandria
91
91
  end
92
92
 
93
93
  def set_active
94
- @canvas.set_property(:background_color, 'white')
95
- @barcode_bars.each { |rect| rect.set_property(:fill_color, 'white') }
94
+ @canvas.set_property(:background_color, "white")
95
+ @barcode_bars.each { |rect| rect.set_property(:fill_color, "white") }
96
96
  end
97
97
 
98
98
  def set_passive
99
- if @canvas
100
- passive_bg = '#F4F4F4'
101
- @canvas.set_property(:background_color, passive_bg)
102
- @barcode_bars.each { |rect| rect.set_property(:fill_color, passive_bg) }
103
- end
99
+ @canvas or return
100
+
101
+ passive_bg = "#F4F4F4"
102
+ @canvas.set_property(:background_color, passive_bg)
103
+ @barcode_bars.each { |rect| rect.set_property(:fill_color, passive_bg) }
104
104
  end
105
105
 
106
106
  def manual_input
@@ -116,7 +116,7 @@ module Alexandria
116
116
  private
117
117
 
118
118
  def create_ean_barcode_data
119
- d = '211113123121112331122131113211111123122211132321112311231111'
119
+ d = "211113123121112331122131113211111123122211132321112311231111"
120
120
  # ####911113... but that's too much padding on the left...
121
121
  until d.empty?
122
122
  space_width = d[0].chr.to_i
@@ -129,11 +129,12 @@ module Alexandria
129
129
  def draw_barcode_bars
130
130
  @barcode_data.each do |space_width, bar_width|
131
131
  @hpos += space_width
132
- rect_item = GooCanvas::CanvasRect.new(parent: @root,
133
- x: @bar_left_edge + @scale * @hpos, y: @bar_top,
134
- width: @scale * bar_width, height: @bar_height,
135
- line_width: 0,
136
- fill_color: 'white')
132
+ rect_item =
133
+ GooCanvas::CanvasRect.new(parent: @root,
134
+ x: @bar_left_edge + @scale * @hpos, y: @bar_top,
135
+ width: @scale * bar_width, height: @bar_height,
136
+ line_width: 0,
137
+ fill_color: "white")
137
138
  @hpos += bar_width
138
139
  @barcode_bars << rect_item
139
140
  end
@@ -1,22 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2004-2006 Laurent Sansonetti
4
- # Copyright (C) 2016 Matijs van Zuijlen
3
+ # This file is part of Alexandria.
5
4
  #
6
- # Alexandria is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU General Public License as
8
- # published by the Free Software Foundation; either version 2 of the
9
- # License, or (at your option) any later version.
10
- #
11
- # Alexandria is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public
17
- # License along with Alexandria; see the file COPYING. If not,
18
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ require "alexandria/ui/error_dialog"
20
8
 
21
9
  module Alexandria
22
10
  module UI
@@ -24,51 +12,51 @@ module Alexandria
24
12
  include Logging
25
13
  include GetText
26
14
  extend GetText
27
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
15
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
28
16
 
29
17
  def initialize(parent, library, book)
30
18
  super(parent, library.cover(book))
31
- puts 'Initializing Book Properties Dialog...' if $DEBUG
19
+ log.debug { "Initializing Book Properties Dialog" }
32
20
 
33
21
  cancel_button = Gtk::Button.new(stock_id: Gtk::Stock::CANCEL)
34
- cancel_button.signal_connect('clicked') { on_cancel }
22
+ cancel_button.signal_connect("clicked") { on_cancel }
35
23
  cancel_button.show
36
24
  @button_box << cancel_button
37
25
 
38
26
  close_button = Gtk::Button.new(stock_id: Gtk::Stock::SAVE)
39
- close_button.signal_connect('clicked') { on_close }
27
+ close_button.signal_connect("clicked") { on_close }
40
28
  close_button.show
41
29
  @button_box << close_button
42
30
 
43
31
  help_button = Gtk::Button.new(stock_id: Gtk::Stock::HELP)
44
- help_button.signal_connect('clicked') { on_help }
32
+ help_button.signal_connect("clicked") { on_help }
45
33
  help_button.show
46
34
  @button_box << help_button
47
35
  @button_box.set_child_secondary(help_button, true)
48
36
 
49
37
  @entry_title.text = @book_properties_dialog.title = book.title
50
- @entry_isbn.text = (book.isbn || '')
38
+ @entry_isbn.text = (book.isbn || "")
51
39
  @entry_publisher.text = book.publisher
52
40
  @entry_publish_date.text = book.publishing_year.to_s
53
- @entry_publish_date.signal_connect('focus-out-event') do
41
+ @entry_publish_date.signal_connect("focus-out-event") do
54
42
  text = @entry_publish_date.text
55
43
  if text.empty?
56
44
  false
57
45
  else
58
46
  year = text.to_i
59
47
  if year.zero? || year > (Time.now.year + 10) || year < 10
60
- @entry_publish_date.text = ''
48
+ @entry_publish_date.text = ""
61
49
  @entry_publish_date.grab_focus
62
50
  true
63
51
  elsif year < 100
64
- @entry_publish_date.text = '19' + year.to_s
52
+ @entry_publish_date.text = "19" + year.to_s
65
53
  false
66
54
  end
67
55
  end
68
56
  end
69
57
  @entry_edition.text = book.edition
70
58
  if book.tags
71
- @entry_tags.text = book.tags.join(',') # tags are comma-separated
59
+ @entry_tags.text = book.tags.join(",") # tags are comma-separated
72
60
  end
73
61
 
74
62
  book.authors.each do |author|
@@ -78,7 +66,7 @@ module Alexandria
78
66
  end
79
67
 
80
68
  buffer = Gtk::TextBuffer.new
81
- buffer.text = (book.notes || '')
69
+ buffer.text = (book.notes || "")
82
70
  @textview_notes.buffer = buffer
83
71
 
84
72
  @library = library
@@ -87,7 +75,7 @@ module Alexandria
87
75
  self.rating = (book.rating || Book::DEFAULT_RATING)
88
76
 
89
77
  if (@checkbutton_loaned.active = book.loaned?)
90
- @entry_loaned_to.text = (book.loaned_to || '')
78
+ @entry_loaned_to.text = (book.loaned_to || "")
91
79
  self.loaned_since = book.loaned_since
92
80
  @date_loaned_since.sensitive = true
93
81
  else
@@ -98,7 +86,7 @@ module Alexandria
98
86
  if (@checkbutton_redd.active = book.redd?)
99
87
  @redd_date.sensitive = true
100
88
  if book.redd_when.nil?
101
- puts 'no redd_when'
89
+ log.debug { "no redd_when" }
102
90
  else
103
91
  @redd_date.text = format_date(book.redd_when)
104
92
  end
@@ -114,28 +102,30 @@ module Alexandria
114
102
  private
115
103
 
116
104
  def on_close
117
- if @entry_isbn.text == ''
105
+ if @entry_isbn.text == ""
118
106
  # If set to nil .to_yaml in library.save causes crash
119
- @book.isbn = ''
107
+ @book.isbn = ""
120
108
  else
121
- ary = @library.select { |book| book.ident == @entry_isbn.text }
109
+ isbn = Library.canonicalise_ean(@entry_isbn.text)
110
+ unless isbn
111
+ ErrorDialog.new(@book_properties_dialog,
112
+ _("Couldn't modify the book"),
113
+ _("Couldn't validate the EAN/ISBN you " \
114
+ "provided. Make sure it is written " \
115
+ "correcty, and try again.")).display
116
+ return
117
+ end
118
+
119
+ ary = @library.select { |book| book.ident == isbn }
122
120
  unless ary.empty? || ((ary.length == 1) && (ary.first == @book))
123
- ErrorDialog.new(@parent,
121
+ ErrorDialog.new(@book_properties_dialog,
124
122
  _("Couldn't modify the book"),
125
- _('The EAN/ISBN you provided is already ' \
126
- 'used in this library.'))
123
+ _("The EAN/ISBN you provided is already " \
124
+ "used in this library.")).display
127
125
  return
128
126
  end
129
- @book.isbn = begin
130
- Library.canonicalise_ean(@entry_isbn.text)
131
- rescue Alexandria::Library::InvalidISBNError
132
- ErrorDialog.new(@parent,
133
- _("Couldn't modify the book"),
134
- _("Couldn't validate the EAN/ISBN you " \
135
- 'provided. Make sure it is written ' \
136
- 'correcty, and try again.'))
137
- return
138
- end
127
+
128
+ @book.isbn = isbn
139
129
  end
140
130
  @book.title = @entry_title.text
141
131
  @book.publisher = @entry_publisher.text
@@ -153,11 +143,8 @@ module Alexandria
153
143
  if loaned_since.strip.empty?
154
144
  @book.loaned_since = nil
155
145
  else
156
- begin
157
- t = parse_date(loaned_since)
158
- @book.loaned_since = t
159
- rescue
160
- end
146
+ t = parse_date(loaned_since)
147
+ @book.loaned_since = t
161
148
  end
162
149
 
163
150
  @book.redd = @checkbutton_redd.active?
@@ -174,7 +161,7 @@ module Alexandria
174
161
  end
175
162
  @book.own = @checkbutton_own.active?
176
163
  @book.want = @checkbutton_want.active?
177
- @book.tags = @entry_tags.text.split(',') # tags are comma separated
164
+ @book.tags = @entry_tags.text.split(",") # tags are comma separated
178
165
 
179
166
  FileUtils.rm_f(@cover_file) if @delete_cover_file
180
167
 
@@ -192,7 +179,7 @@ module Alexandria
192
179
 
193
180
  def on_help
194
181
  Alexandria::UI.display_help(@preferences_dialog,
195
- 'editing-book-properties')
182
+ "editing-book-properties")
196
183
  end
197
184
  end
198
185
  end
@@ -0,0 +1,318 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ require "alexandria/ui/builder_base"
8
+ require "alexandria/ui/calendar_popup"
9
+ require "alexandria/ui/error_dialog"
10
+
11
+ module Alexandria
12
+ module UI
13
+ class BookPropertiesDialogBase < BuilderBase
14
+ include CalendarPopup
15
+ include GetText
16
+ extend GetText
17
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
18
+
19
+ COVER_MAXWIDTH = 140 # pixels
20
+
21
+ COVER_ABSOLUTE_MAXHEIGHT = 250 # pixels, above this we scale down...
22
+
23
+ def initialize(parent, cover_file)
24
+ super("book_properties_dialog__builder.glade", widget_names)
25
+ @setup_finished = false
26
+ @book_properties_dialog.transient_for = parent
27
+ @parent = parent
28
+ @cover_file = cover_file
29
+ @original_cover_file = nil
30
+ @delete_cover_file = false # fixing bug #16707
31
+
32
+ @entry_title.complete_titles
33
+ @entry_title.grab_focus
34
+ @entry_publisher.complete_publishers
35
+ @entry_edition.complete_editions
36
+ @entry_loaned_to.complete_borrowers
37
+
38
+ @entry_tags.complete_tags
39
+
40
+ @treeview_authors.model = Gtk::ListStore.new(String, TrueClass)
41
+ @treeview_authors.selection.mode = :single
42
+ renderer = Gtk::CellRendererText.new
43
+ renderer.signal_connect("edited") do |_cell, path_string, new_text|
44
+ path = Gtk::TreePath.new(path_string)
45
+ iter = @treeview_authors.model.get_iter(path)
46
+ iter[0] = new_text
47
+ end
48
+ renderer.signal_connect("editing_started") do |_cell, entry, _path_string|
49
+ entry.complete_authors
50
+ end
51
+ col = Gtk::TreeViewColumn.new("", renderer,
52
+ text: 0,
53
+ editable: 1)
54
+ @treeview_authors.append_column(col)
55
+
56
+ setup_date_widgets
57
+ GLib::Timeout.add(150) do
58
+ @setup_finished = true
59
+
60
+ false
61
+ end
62
+ end
63
+
64
+ def show
65
+ @book_properties_dialog.show
66
+ end
67
+
68
+ def setup_date_widgets
69
+ @redd_date.signal_connect("icon-press") do |entry, primary, _icon|
70
+ case primary.nick
71
+ when "primary"
72
+ display_calendar_popup(entry)
73
+ when "secondary"
74
+ clear_date_entry(entry)
75
+ end
76
+ end
77
+
78
+ @date_loaned_since.signal_connect("icon-press") do |entry, primary, _icon|
79
+ case primary.nick
80
+ when "primary"
81
+ display_calendar_popup(entry)
82
+ when "secondary"
83
+ clear_date_entry(entry)
84
+ @label_loaning_duration.label = ""
85
+ end
86
+ end
87
+ end
88
+
89
+ def widget_names
90
+ [:book_properties_dialog, :button_box, :button_cover,
91
+ :checkbutton_loaned, :checkbutton_own, :checkbutton_redd,
92
+ :checkbutton_want, :date_loaned_since, :entry_edition,
93
+ :entry_loaned_to, :entry_publish_date, :entry_publisher, :entry_isbn,
94
+ :entry_tags, :entry_title, :image_cover, :image_rating1,
95
+ :image_rating2, :image_rating3, :image_rating4, :image_rating5,
96
+ :label_loaning_duration, :notebook, :redd_date, :textview_notes,
97
+ :treeview_authors]
98
+ end
99
+
100
+ def on_title_changed
101
+ title = @entry_title.text.strip
102
+ @book_properties_dialog.title = if title.empty?
103
+ _("Properties")
104
+ else
105
+ _("Properties for '%s'") % title
106
+ end
107
+ end
108
+
109
+ def on_add_author
110
+ iter = @treeview_authors.model.append
111
+ iter[0] = _("Author")
112
+ iter[1] = true
113
+ @treeview_authors.set_cursor(iter.path,
114
+ @treeview_authors.get_column(0),
115
+ true)
116
+ end
117
+
118
+ def on_remove_author
119
+ iter = @treeview_authors.selection.selected
120
+ @treeview_authors.model.remove(iter) if iter
121
+ end
122
+
123
+ def on_image_rating1_press
124
+ self.rating = 1
125
+ end
126
+
127
+ def on_image_rating2_press
128
+ self.rating = 2
129
+ end
130
+
131
+ def on_image_rating3_press
132
+ self.rating = 3
133
+ end
134
+
135
+ def on_image_rating4_press
136
+ self.rating = 4
137
+ end
138
+
139
+ def on_image_rating5_press
140
+ self.rating = 5
141
+ end
142
+
143
+ def on_image_no_rating_press
144
+ self.rating = 0
145
+ end
146
+
147
+ def own_toggled
148
+ @checkbutton_want.inconsistent = if @checkbutton_own.active?
149
+ true
150
+ else
151
+ false
152
+ end
153
+ end
154
+
155
+ def want_toggled; end
156
+
157
+ @@latest_filechooser_directory = ENV["HOME"]
158
+ def on_change_cover
159
+ backend = `uname`.chomp == "FreeBSD" ? "neant" : "gnome-vfs"
160
+ dialog = Gtk::FileChooserDialog.new(_("Select a cover image"),
161
+ @book_properties_dialog,
162
+ Gtk::FileChooser::ACTION_OPEN,
163
+ backend,
164
+ [_("No Cover"), Gtk::ResponseType::REJECT],
165
+ [Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
166
+ [Gtk::Stock::OPEN, Gtk::ResponseType::ACCEPT])
167
+ dialog.current_folder = @@latest_filechooser_directory
168
+ response = dialog.run
169
+ case response
170
+ when Gtk::ResponseType::ACCEPT
171
+ begin
172
+ @delete_cover_file = false
173
+ cover = GdkPixbuf::Pixbuf.new(file: dialog.filename)
174
+ # At this stage the file format is recognized.
175
+
176
+ if File.exist?(@cover_file) && !@original_cover_file
177
+ # make a back up, but only of the original
178
+ @original_cover_file = "#{@cover_file}~"
179
+ FileUtils.cp(@cover_file, @original_cover_file)
180
+ end
181
+ if cover.height > COVER_ABSOLUTE_MAXHEIGHT
182
+ FileUtils.cp(dialog.filename, "#{@cover_file}.orig")
183
+ new_width = cover.width / (cover.height / COVER_ABSOLUTE_MAXHEIGHT.to_f)
184
+ log.info do
185
+ "Scaling large cover image to" \
186
+ " #{new_width.to_i} x #{COVER_ABSOLUTE_MAXHEIGHT}"
187
+ end
188
+ cover = cover.scale(new_width.to_i, COVER_ABSOLUTE_MAXHEIGHT)
189
+ cover.save(@cover_file, "jpeg")
190
+ else
191
+ FileUtils.cp(dialog.filename, @cover_file)
192
+ end
193
+
194
+ self.cover = cover
195
+ @@latest_filechooser_directory = dialog.current_folder
196
+ rescue RuntimeError => ex
197
+ ErrorDialog.new(@book_properties_dialog, ex.message).display
198
+ end
199
+ when Gtk::ResponseType::REJECT
200
+ ## FileUtils.rm_f(@cover_file) # fixing bug #16707
201
+ @delete_cover_file = true
202
+
203
+ self.cover = Icons::BOOK_ICON
204
+ end
205
+ dialog.destroy
206
+ end
207
+
208
+ def on_destroy
209
+ @book_properties_dialog.hide
210
+ # Stop notebook trying to set tab labels at this time
211
+ @notebook.show_tabs = false
212
+ end
213
+
214
+ def on_loaned
215
+ loaned = @checkbutton_loaned.active?
216
+ @entry_loaned_to.sensitive = loaned
217
+ @date_loaned_since.sensitive = loaned
218
+ @label_loaning_duration.visible = loaned
219
+ end
220
+
221
+ def on_loaned_date_changed
222
+ date_regexes = [%r{[0123]?[0-9]/[0123]?[0-9]/[0-9]{4}},
223
+ /[0-9]{4}-[0123]?[0-9]-[0123]?[0-9]/]
224
+ matches_regex = false
225
+ date_regexes.each do |regex|
226
+ matches_regex = regex.match(@date_loaned_since.text)
227
+ break if matches_regex
228
+ end
229
+ return unless matches_regex
230
+
231
+ t = parse_date(@date_loaned_since.text)
232
+ if t.nil?
233
+ @label_loaning_duration.label = ""
234
+ return
235
+ end
236
+ loaned_time = Time.at(t)
237
+ n_days = ((Time.now - loaned_time) / (3600 * 24)).to_i
238
+ if n_days > 365_250 # 1,000 years
239
+ @label_loaning_duration.label = ""
240
+ return
241
+ end
242
+ @label_loaning_duration.label = if n_days > 0
243
+ n_("%d day", "%d days", n_days) % n_days
244
+ else
245
+ ""
246
+ end
247
+ end
248
+
249
+ def redd_toggled
250
+ redd_yes = @checkbutton_redd.active?
251
+ @redd_date.sensitive = redd_yes
252
+
253
+ return unless redd_yes && @redd_date.text.strip.empty?
254
+
255
+ # don't do this when popping up the dialog for the first time
256
+ display_calendar_popup(@redd_date) if @setup_finished
257
+ end
258
+
259
+ private
260
+
261
+ def rating=(rating)
262
+ images = [
263
+ @image_rating1,
264
+ @image_rating2,
265
+ @image_rating3,
266
+ @image_rating4,
267
+ @image_rating5
268
+ ]
269
+ raise _("out of range") if rating < 0 || rating > images.length
270
+
271
+ images[0..rating - 1].each { |x| x.pixbuf = Icons::STAR_SET }
272
+ images[rating..-1].each { |x| x.pixbuf = Icons::STAR_UNSET }
273
+ @current_rating = rating
274
+ end
275
+
276
+ def cover=(pixbuf)
277
+ if pixbuf.width > COVER_MAXWIDTH
278
+ new_height = pixbuf.height / (pixbuf.width / COVER_MAXWIDTH.to_f)
279
+ # We don't want to modify in place the given pixbuf,
280
+ # that's why we make a copy.
281
+ pixbuf = pixbuf.scale(COVER_MAXWIDTH, new_height)
282
+ end
283
+ @image_cover.pixbuf = pixbuf
284
+ end
285
+
286
+ def loaned_since=(time)
287
+ if time.nil?
288
+ @date_loaned_since.text = ""
289
+ @label_loaning_duration.label = ""
290
+ else
291
+ @date_loaned_since.text = format_date(time)
292
+ on_loaned_date_changed
293
+ end
294
+ # XXX 'date_changed' signal not automatically called after #time=.
295
+ end
296
+
297
+ def redd_when=(time)
298
+ @redd_date.text = format_date(time)
299
+ end
300
+
301
+ def parse_date(datestring)
302
+ # '%m/%d/%Y' for USA and Canada ; or '%Y-%m-%d' for most of Asia
303
+ # http://en.wikipedia.org/wiki/Calendar_date#Middle_endian_forms.2C_starting_with_the_month
304
+ date_format = "%d/%m/%Y"
305
+ begin
306
+ d = Date.strptime(datestring, date_format)
307
+ Time.gm(d.year, d.month, d.day)
308
+ rescue StandardError
309
+ nil
310
+ end
311
+ end
312
+
313
+ def format_date(datetime)
314
+ datetime.strftime("%d/%m/%Y")
315
+ end
316
+ end
317
+ end
318
+ end