alexandria-book-collection-manager 0.7.3 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) 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 +4 -1
  5. data/.rubocop.yml +86 -36
  6. data/.rubocop_todo.yml +58 -161
  7. data/.simplecov +5 -2
  8. data/CHANGELOG.md +56 -2
  9. data/Gemfile +4 -3
  10. data/INSTALL.md +23 -11
  11. data/README.md +52 -41
  12. data/Rakefile +78 -75
  13. data/alexandria-book-collection-manager.gemspec +50 -44
  14. data/bin/alexandria +12 -22
  15. data/doc/FAQ +1 -2
  16. data/doc/dependency_decisions.yml +27 -8
  17. data/lib/alexandria.rb +25 -23
  18. data/lib/alexandria/about.rb +50 -50
  19. data/lib/alexandria/book_providers.rb +86 -91
  20. data/lib/alexandria/book_providers/adlibris.rb +37 -74
  21. data/lib/alexandria/book_providers/amazon_aws.rb +94 -100
  22. data/lib/alexandria/book_providers/amazon_ecs_util.rb +289 -324
  23. data/lib/alexandria/book_providers/barnes_and_noble.rb +42 -42
  24. data/lib/alexandria/book_providers/douban.rb +25 -41
  25. data/lib/alexandria/book_providers/proxis.rb +34 -29
  26. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  27. data/lib/alexandria/book_providers/siciliano.rb +60 -64
  28. data/lib/alexandria/book_providers/thalia_provider.rb +161 -0
  29. data/lib/alexandria/book_providers/web.rb +5 -5
  30. data/lib/alexandria/book_providers/worldcat.rb +66 -95
  31. data/lib/alexandria/book_providers/z3950.rb +153 -169
  32. data/lib/alexandria/config.rb +1 -1
  33. data/lib/alexandria/console.rb +3 -3
  34. data/lib/alexandria/default_preferences.rb +37 -0
  35. data/lib/alexandria/execution_queue.rb +13 -12
  36. data/lib/alexandria/export_format.rb +8 -8
  37. data/lib/alexandria/export_library.rb +128 -127
  38. data/lib/alexandria/import_library.rb +102 -126
  39. data/lib/alexandria/import_library_csv.rb +41 -41
  40. data/lib/alexandria/library_collection.rb +6 -5
  41. data/lib/alexandria/library_sort_order.rb +4 -2
  42. data/lib/alexandria/library_store.rb +39 -28
  43. data/lib/alexandria/logging.rb +10 -14
  44. data/lib/alexandria/models/book.rb +5 -4
  45. data/lib/alexandria/models/library.rb +63 -53
  46. data/lib/alexandria/net.rb +5 -6
  47. data/lib/alexandria/preferences.rb +66 -63
  48. data/lib/alexandria/scanners.rb +2 -2
  49. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +17 -17
  50. data/lib/alexandria/scanners/keyboard.rb +8 -8
  51. data/lib/alexandria/smart_library.rb +110 -112
  52. data/lib/alexandria/ui.rb +15 -15
  53. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +2 -2
  54. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +108 -109
  55. data/lib/alexandria/ui/alert_dialog.rb +66 -0
  56. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +13 -9
  57. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  58. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -38
  59. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +64 -157
  60. data/lib/alexandria/ui/builder_base.rb +1 -1
  61. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  62. data/lib/alexandria/ui/callbacks.rb +187 -155
  63. data/lib/alexandria/ui/completion_models.rb +8 -22
  64. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  65. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  66. data/lib/alexandria/ui/dndable.rb +7 -7
  67. data/lib/alexandria/ui/error_dialog.rb +25 -0
  68. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +37 -58
  69. data/lib/alexandria/ui/icons.rb +38 -43
  70. data/lib/alexandria/ui/iconview.rb +12 -10
  71. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  72. data/lib/alexandria/ui/import_dialog.rb +157 -0
  73. data/lib/alexandria/ui/init.rb +30 -41
  74. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +9 -6
  75. data/lib/alexandria/ui/libraries_combo.rb +15 -14
  76. data/lib/alexandria/ui/listview.rb +69 -67
  77. data/lib/alexandria/ui/main_app.rb +24 -26
  78. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  79. data/lib/alexandria/ui/multi_drag_treeview.rb +8 -9
  80. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +113 -114
  81. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +22 -19
  82. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  83. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  84. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  85. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  86. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  87. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +7 -28
  88. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +53 -48
  89. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  90. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  91. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  92. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  93. data/lib/alexandria/ui/sound.rb +11 -13
  94. data/lib/alexandria/ui/ui_manager.rb +216 -200
  95. data/lib/alexandria/version.rb +4 -19
  96. data/lib/alexandria/web_themes.rb +21 -21
  97. data/po/Makefile +2 -2
  98. data/po/cs.po +992 -875
  99. data/po/cy.po +961 -874
  100. data/po/de.po +990 -865
  101. data/po/el.po +989 -865
  102. data/po/es.po +985 -861
  103. data/po/fr.po +987 -867
  104. data/po/ga.po +908 -820
  105. data/po/gl.po +980 -860
  106. data/po/it.po +986 -864
  107. data/po/ja.po +969 -849
  108. data/po/mk.po +984 -860
  109. data/po/nb.po +979 -859
  110. data/po/nl.po +983 -860
  111. data/po/pl.po +1018 -971
  112. data/po/pt.po +988 -857
  113. data/po/pt_BR.po +983 -863
  114. data/po/ru.po +994 -871
  115. data/po/sk.po +989 -867
  116. data/po/sv.po +976 -856
  117. data/po/uk.po +972 -858
  118. data/po/zh_TW.po +974 -854
  119. data/schemas/alexandria.schemas +24 -2
  120. data/share/alexandria/glade/acquire_dialog__builder.glade +1 -1
  121. data/share/alexandria/glade/book_properties_dialog__builder.glade +1 -1
  122. data/share/alexandria/glade/main_app__builder.glade +6 -21
  123. data/share/alexandria/glade/new_book_dialog__builder.glade +1 -1
  124. data/share/alexandria/glade/preferences_dialog__builder.glade +1 -1
  125. data/share/gnome/help/alexandria/C/introduction.xml +0 -4
  126. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  127. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  128. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  129. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  130. data/share/gnome/help/alexandria/ja/introduction.xml +0 -4
  131. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  132. data/spec/alexandria/book_providers/thalia_provider_spec.rb +119 -0
  133. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  134. data/spec/alexandria/book_providers_spec.rb +62 -156
  135. data/spec/alexandria/book_spec.rb +12 -10
  136. data/spec/alexandria/console_spec.rb +6 -11
  137. data/spec/alexandria/export_library_spec.rb +47 -58
  138. data/spec/alexandria/library_spec.rb +121 -109
  139. data/spec/alexandria/library_store_spec.rb +8 -8
  140. data/spec/alexandria/preferences_spec.rb +44 -17
  141. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  142. data/spec/alexandria/smart_library_spec.rb +15 -15
  143. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  144. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  145. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  146. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/book_properties_dialog_spec.rb +59 -0
  148. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  150. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  152. data/spec/alexandria/ui/icons_spec.rb +26 -0
  153. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  154. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  155. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  156. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  157. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +51 -0
  158. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  159. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  160. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  161. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  162. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  163. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  164. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  165. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  166. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  167. data/spec/alexandria/ui/sound_spec.rb +2 -2
  168. data/spec/alexandria/ui/ui_manager_spec.rb +44 -20
  169. data/spec/end_to_end/basic_run_spec.rb +21 -38
  170. data/spec/fixtures/cover.jpg +0 -0
  171. data/spec/spec_helper.rb +54 -10
  172. data/tasks/setup.rb +2 -2
  173. data/tasks/spec.rake +11 -11
  174. data/util/rake/fileinstall.rb +38 -35
  175. data/util/rake/gettextgenerate.rb +7 -7
  176. data/util/rake/omfgenerate.rb +7 -7
  177. metadata +158 -45
  178. data/dogtail/basic_run_test.py +0 -9
  179. data/lib/alexandria/book_providers/renaud.rb +0 -155
  180. data/lib/alexandria/book_providers/thalia.rb +0 -198
  181. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -63
  182. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -176
  183. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -62
  184. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -563
  185. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -61
  186. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -423
  187. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  188. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  189. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  190. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  191. data/spec/alexandria/utilities_spec.rb +0 -52
  192. data/tasks/dogtail.rake +0 -6
@@ -0,0 +1,66 @@
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 "cgi"
8
+
9
+ module Alexandria
10
+ module UI
11
+ class AlertDialog
12
+ def initialize(parent, title, stock_icon, buttons, message = nil)
13
+ @dialog = Gtk::Dialog.new(title: "", parent: parent, flags: :destroy_with_parent,
14
+ buttons: buttons)
15
+ @dialog.border_width = 6
16
+ @dialog.resizable = false
17
+ @dialog.child.spacing = 12
18
+
19
+ hbox = Gtk::Box.new(:horizontal, 12)
20
+ hbox.homogeneous = false
21
+ hbox.border_width = 6
22
+
23
+ image = Gtk::Image.new(stock: stock_icon,
24
+ size: Gtk::IconSize::DIALOG)
25
+ image.set_alignment(0.5, 0)
26
+ hbox.pack_start(image)
27
+
28
+ vbox = Gtk::Box.new(:vertical, 6)
29
+ vbox.homogeneous = false
30
+ vbox.pack_start make_label("<b><big>#{title}</big></b>")
31
+ vbox.pack_start make_label CGI.escapeHTML(message.strip) if message
32
+ hbox.pack_start(vbox)
33
+
34
+ @dialog.child.pack_start(hbox)
35
+ end
36
+
37
+ def show_all
38
+ dialog.show_all
39
+ end
40
+
41
+ def run
42
+ dialog.run
43
+ end
44
+
45
+ def destroy
46
+ dialog.destroy
47
+ end
48
+
49
+ def default_response=(response)
50
+ dialog.default_response = response
51
+ end
52
+
53
+ private
54
+
55
+ attr_reader :dialog
56
+
57
+ def make_label(markup)
58
+ label = Gtk::Label.new
59
+ label.set_alignment(0, 0)
60
+ label.wrap = label.selectable = true
61
+ label.markup = markup
62
+ label
63
+ end
64
+ end
65
+ end
66
+ end
@@ -8,17 +8,16 @@ module Alexandria
8
8
  module UI
9
9
  # Generalized Dialog for lists of bad isbns. Used for on_import. Can also
10
10
  # be used for on_load library conversions.
11
- class BadIsbnsDialog < SimpleDelegator
11
+ class BadIsbnsDialog
12
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
- super(dialog)
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
19
 
20
20
  isbn_container = Gtk::Box.new :horizontal
21
- the_vbox = children.first
22
21
  the_vbox.pack_start(isbn_container)
23
22
  the_vbox.reorder_child(isbn_container, 3)
24
23
  scrolley = Gtk::ScrolledWindow.new
@@ -30,7 +29,12 @@ module Alexandria
30
29
  list.each do |li|
31
30
  textview.buffer.insert_at_cursor("#{li}\n")
32
31
  end
33
- show_all
32
+
33
+ @dialog.signal_connect("response") { @dialog.destroy }
34
+ end
35
+
36
+ def show
37
+ @dialog.show_all
34
38
  end
35
39
  end
36
40
  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,74 +1,61 @@
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
23
11
  class BookPropertiesDialog < BookPropertiesDialogBase
24
- include Logging
25
12
  include GetText
26
13
  extend GetText
27
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
14
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
28
15
 
29
16
  def initialize(parent, library, book)
30
17
  super(parent, library.cover(book))
31
- puts 'Initializing Book Properties Dialog...' if $DEBUG
18
+ log.debug { "Initializing Book Properties Dialog" }
32
19
 
33
20
  cancel_button = Gtk::Button.new(stock_id: Gtk::Stock::CANCEL)
34
- cancel_button.signal_connect('clicked') { on_cancel }
21
+ cancel_button.signal_connect("clicked") { on_cancel }
35
22
  cancel_button.show
36
23
  @button_box << cancel_button
37
24
 
38
25
  close_button = Gtk::Button.new(stock_id: Gtk::Stock::SAVE)
39
- close_button.signal_connect('clicked') { on_close }
26
+ close_button.signal_connect("clicked") { on_close }
40
27
  close_button.show
41
28
  @button_box << close_button
42
29
 
43
30
  help_button = Gtk::Button.new(stock_id: Gtk::Stock::HELP)
44
- help_button.signal_connect('clicked') { on_help }
31
+ help_button.signal_connect("clicked") { on_help }
45
32
  help_button.show
46
33
  @button_box << help_button
47
34
  @button_box.set_child_secondary(help_button, true)
48
35
 
49
36
  @entry_title.text = @book_properties_dialog.title = book.title
50
- @entry_isbn.text = (book.isbn || '')
37
+ @entry_isbn.text = (book.isbn || "")
51
38
  @entry_publisher.text = book.publisher
52
39
  @entry_publish_date.text = book.publishing_year.to_s
53
- @entry_publish_date.signal_connect('focus-out-event') do
40
+ @entry_publish_date.signal_connect("focus-out-event") do
54
41
  text = @entry_publish_date.text
55
42
  if text.empty?
56
43
  false
57
44
  else
58
45
  year = text.to_i
59
46
  if year.zero? || year > (Time.now.year + 10) || year < 10
60
- @entry_publish_date.text = ''
47
+ @entry_publish_date.text = ""
61
48
  @entry_publish_date.grab_focus
62
49
  true
63
50
  elsif year < 100
64
- @entry_publish_date.text = '19' + year.to_s
51
+ @entry_publish_date.text = "19" + year.to_s
65
52
  false
66
53
  end
67
54
  end
68
55
  end
69
56
  @entry_edition.text = book.edition
70
57
  if book.tags
71
- @entry_tags.text = book.tags.join(',') # tags are comma-separated
58
+ @entry_tags.text = book.tags.join(",") # tags are comma-separated
72
59
  end
73
60
 
74
61
  book.authors.each do |author|
@@ -78,7 +65,7 @@ module Alexandria
78
65
  end
79
66
 
80
67
  buffer = Gtk::TextBuffer.new
81
- buffer.text = (book.notes || '')
68
+ buffer.text = (book.notes || "")
82
69
  @textview_notes.buffer = buffer
83
70
 
84
71
  @library = library
@@ -87,7 +74,7 @@ module Alexandria
87
74
  self.rating = (book.rating || Book::DEFAULT_RATING)
88
75
 
89
76
  if (@checkbutton_loaned.active = book.loaned?)
90
- @entry_loaned_to.text = (book.loaned_to || '')
77
+ @entry_loaned_to.text = (book.loaned_to || "")
91
78
  self.loaned_since = book.loaned_since
92
79
  @date_loaned_since.sensitive = true
93
80
  else
@@ -98,7 +85,7 @@ module Alexandria
98
85
  if (@checkbutton_redd.active = book.redd?)
99
86
  @redd_date.sensitive = true
100
87
  if book.redd_when.nil?
101
- puts 'no redd_when'
88
+ log.debug { "no redd_when" }
102
89
  else
103
90
  @redd_date.text = format_date(book.redd_when)
104
91
  end
@@ -114,17 +101,17 @@ module Alexandria
114
101
  private
115
102
 
116
103
  def on_close
117
- if @entry_isbn.text == ''
104
+ if @entry_isbn.text == ""
118
105
  # If set to nil .to_yaml in library.save causes crash
119
- @book.isbn = ''
106
+ @book.isbn = ""
120
107
  else
121
108
  isbn = Library.canonicalise_ean(@entry_isbn.text)
122
109
  unless isbn
123
110
  ErrorDialog.new(@book_properties_dialog,
124
111
  _("Couldn't modify the book"),
125
112
  _("Couldn't validate the EAN/ISBN you " \
126
- 'provided. Make sure it is written ' \
127
- 'correcty, and try again.')).display
113
+ "provided. Make sure it is written " \
114
+ "correcty, and try again.")).display
128
115
  return
129
116
  end
130
117
 
@@ -132,8 +119,8 @@ module Alexandria
132
119
  unless ary.empty? || ((ary.length == 1) && (ary.first == @book))
133
120
  ErrorDialog.new(@book_properties_dialog,
134
121
  _("Couldn't modify the book"),
135
- _('The EAN/ISBN you provided is already ' \
136
- 'used in this library.')).display
122
+ _("The EAN/ISBN you provided is already " \
123
+ "used in this library.")).display
137
124
  return
138
125
  end
139
126
 
@@ -173,7 +160,7 @@ module Alexandria
173
160
  end
174
161
  @book.own = @checkbutton_own.active?
175
162
  @book.want = @checkbutton_want.active?
176
- @book.tags = @entry_tags.text.split(',') # tags are comma separated
163
+ @book.tags = @entry_tags.text.split(",") # tags are comma separated
177
164
 
178
165
  FileUtils.rm_f(@cover_file) if @delete_cover_file
179
166
 
@@ -191,7 +178,7 @@ module Alexandria
191
178
 
192
179
  def on_help
193
180
  Alexandria::UI.display_help(@preferences_dialog,
194
- 'editing-book-properties')
181
+ "editing-book-properties")
195
182
  end
196
183
  end
197
184
  end
@@ -4,21 +4,25 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
- require 'alexandria/ui/builder_base'
7
+ require "alexandria/ui/builder_base"
8
+ require "alexandria/ui/calendar_popup"
9
+ require "alexandria/ui/error_dialog"
8
10
 
9
11
  module Alexandria
10
12
  module UI
11
13
  class BookPropertiesDialogBase < BuilderBase
14
+ include CalendarPopup
15
+ include Logging
12
16
  include GetText
13
17
  extend GetText
14
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
18
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
15
19
 
16
20
  COVER_MAXWIDTH = 140 # pixels
17
21
 
18
22
  COVER_ABSOLUTE_MAXHEIGHT = 250 # pixels, above this we scale down...
19
23
 
20
24
  def initialize(parent, cover_file)
21
- super('book_properties_dialog__builder.glade', widget_names)
25
+ super("book_properties_dialog__builder.glade", widget_names)
22
26
  @setup_finished = false
23
27
  @book_properties_dialog.transient_for = parent
24
28
  @parent = parent
@@ -37,20 +41,20 @@ module Alexandria
37
41
  @treeview_authors.model = Gtk::ListStore.new(String, TrueClass)
38
42
  @treeview_authors.selection.mode = :single
39
43
  renderer = Gtk::CellRendererText.new
40
- renderer.signal_connect('edited') do |_cell, path_string, new_text|
44
+ renderer.signal_connect("edited") do |_cell, path_string, new_text|
41
45
  path = Gtk::TreePath.new(path_string)
42
46
  iter = @treeview_authors.model.get_iter(path)
43
47
  iter[0] = new_text
44
48
  end
45
- renderer.signal_connect('editing_started') do |_cell, entry, _path_string|
49
+ renderer.signal_connect("editing_started") do |_cell, entry, _path_string|
46
50
  entry.complete_authors
47
51
  end
48
- col = Gtk::TreeViewColumn.new('', renderer,
52
+ col = Gtk::TreeViewColumn.new("", renderer,
49
53
  text: 0,
50
54
  editable: 1)
51
55
  @treeview_authors.append_column(col)
52
56
 
53
- setup_calendar_widgets
57
+ setup_date_widgets
54
58
  GLib::Timeout.add(150) do
55
59
  @setup_finished = true
56
60
 
@@ -58,130 +62,31 @@ module Alexandria
58
62
  end
59
63
  end
60
64
 
61
- def setup_calendar_widgets
62
- @popup_displayed = false
63
- @calendar_popup = Gtk::Window.new # Gtk::Window::POPUP)
64
- # @calendar_popup.modal = true
65
- @calendar_popup.decorated = false
66
- @calendar_popup.skip_taskbar_hint = true
67
- @calendar_popup.skip_pager_hint = true
68
- @calendar_popup.events = [:focus_change_mask]
69
-
70
- @calendar_popup.set_transient_for(@book_properties_dialog)
71
- @calendar_popup.set_type_hint :dialog
72
- @calendar_popup.name = 'calendar-popup'
73
- @calendar_popup.resizable = false
74
- # @calendar_popup.border_width = 4
75
- # @calendar_popup.app_paintable = true
76
-
77
- @calendar_popup.signal_connect('focus-out-event') do |_popup, _event|
78
- hide_calendar_popup
79
- false
80
- end
81
-
82
- @calendar = Gtk::Calendar.new
83
- @calendar_popup.add(@calendar)
84
-
85
- @calendar.signal_connect('day-selected') do
86
- date_arr = @calendar.date
87
- year = date_arr[0]
88
- month = date_arr[1] # + 1 # gtk : months 0-indexed, Time.gm : 1-index
89
- day = date_arr[2]
90
- if @calendar_popup_for_entry
91
- time = Time.gm(year, month, day)
92
- @calendar_popup_for_entry.text = format_date(time)
93
- end
94
- end
95
-
96
- @calendar.signal_connect('day-selected-double-click') 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
- hide_calendar_popup
106
- end
65
+ def show
66
+ @book_properties_dialog.show
67
+ end
107
68
 
108
- @redd_date.signal_connect('icon-press') do |entry, primary, _icon|
109
- if primary.nick == 'primary'
69
+ def setup_date_widgets
70
+ @redd_date.signal_connect("icon-press") do |entry, primary, _icon|
71
+ case primary.nick
72
+ when "primary"
110
73
  display_calendar_popup(entry)
111
- elsif primary.nick == 'secondary'
74
+ when "secondary"
112
75
  clear_date_entry(entry)
113
76
  end
114
77
  end
115
78
 
116
- @date_loaned_since.signal_connect('icon-press') do |entry, primary, _icon|
117
- if primary.nick == 'primary'
79
+ @date_loaned_since.signal_connect("icon-press") do |entry, primary, _icon|
80
+ case primary.nick
81
+ when "primary"
118
82
  display_calendar_popup(entry)
119
- elsif primary.nick == 'secondary'
83
+ when "secondary"
120
84
  clear_date_entry(entry)
121
- @label_loaning_duration.label = ''
85
+ @label_loaning_duration.label = ""
122
86
  end
123
87
  end
124
88
  end
125
89
 
126
- def clear_date_entry(entry)
127
- entry.text = ''
128
- end
129
-
130
- def hide_calendar_popup
131
- @calendar_popup_for_entry = nil
132
-
133
- @calendar_popup.hide_all
134
- @book_properties_dialog.modal = true
135
-
136
- GLib::Timeout.add(150) do
137
- # If we set @popup_displayed=false immediately, then a click
138
- # event on the primary icon of the Entry simultaneous with
139
- # the focus-out-event of the Calendar causes the Calendar to
140
- # pop up again milliseconds after being closed.
141
- #
142
- # This is never what the user intends.
143
- #
144
- # So we add a small delay before the primary icon's event
145
- # handler is told to pop up the calendar in response to
146
- # clicks.
147
-
148
- @popup_displayed = false
149
- false
150
- end
151
- end
152
-
153
- def display_calendar_popup(entry)
154
- if @popup_displayed
155
- hide_calendar_popup
156
- else
157
- @calendar_popup_for_entry = entry
158
- unless entry.text.strip.empty?
159
- time = parse_date(entry.text)
160
- unless time.nil?
161
- @calendar.year = time.year
162
- @calendar.month = time.month - 1
163
- @calendar.day = time.day
164
- end
165
- end
166
- @book_properties_dialog.modal = false
167
- @calendar_popup.move(*get_entry_popup_coords(entry))
168
- @calendar_popup.show_all
169
- @popup_displayed = true
170
- end
171
- end
172
-
173
- def get_entry_popup_coords(entry)
174
- gdk_win = entry.parent_window
175
- x, y = gdk_win.origin
176
- alloc = entry.allocation
177
- x += alloc.x
178
- y += alloc.y
179
- y += alloc.height
180
- # x = [0, x].max
181
- # y = [0, y].max
182
- [x, y]
183
- end
184
-
185
90
  def widget_names
186
91
  [:book_properties_dialog, :button_box, :button_cover,
187
92
  :checkbutton_loaned, :checkbutton_own, :checkbutton_redd,
@@ -196,7 +101,7 @@ module Alexandria
196
101
  def on_title_changed
197
102
  title = @entry_title.text.strip
198
103
  @book_properties_dialog.title = if title.empty?
199
- _('Properties')
104
+ _("Properties")
200
105
  else
201
106
  _("Properties for '%s'") % title
202
107
  end
@@ -204,7 +109,7 @@ module Alexandria
204
109
 
205
110
  def on_add_author
206
111
  iter = @treeview_authors.model.append
207
- iter[0] = _('Author')
112
+ iter[0] = _("Author")
208
113
  iter[1] = true
209
114
  @treeview_authors.set_cursor(iter.path,
210
115
  @treeview_authors.get_column(0),
@@ -250,47 +155,47 @@ module Alexandria
250
155
 
251
156
  def want_toggled; end
252
157
 
253
- @@latest_filechooser_directory = ENV['HOME']
158
+ @@latest_filechooser_directory = ENV["HOME"]
254
159
  def on_change_cover
255
- backend = `uname`.chomp == 'FreeBSD' ? 'neant' : 'gnome-vfs'
256
- dialog = Gtk::FileChooserDialog.new(_('Select a cover image'),
257
- @book_properties_dialog,
258
- Gtk::FileChooser::ACTION_OPEN,
259
- backend,
260
- [_('No Cover'), Gtk::ResponseType::REJECT],
261
- [Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
262
- [Gtk::Stock::OPEN, Gtk::ResponseType::ACCEPT])
160
+ dialog = Gtk::FileChooserDialog.new(title: _("Select a cover image"),
161
+ parent: @book_properties_dialog,
162
+ action: :open,
163
+ buttons: [[_("No Cover"), :reject],
164
+ [Gtk::Stock::CANCEL, :cancel],
165
+ [Gtk::Stock::OPEN, :accept]])
263
166
  dialog.current_folder = @@latest_filechooser_directory
264
167
  response = dialog.run
265
- if response == Gtk::ResponseType::ACCEPT
168
+ case response
169
+ when Gtk::ResponseType::ACCEPT
266
170
  begin
267
171
  @delete_cover_file = false
268
172
  cover = GdkPixbuf::Pixbuf.new(file: dialog.filename)
269
173
  # At this stage the file format is recognized.
270
174
 
271
- if File.exist?(@cover_file)
272
- unless @original_cover_file
273
- # make a back up, but only of the original
274
- @original_cover_file = "#{@cover_file}~"
275
- FileUtils.cp(@cover_file, @original_cover_file)
276
- end
175
+ if File.exist?(@cover_file) && !@original_cover_file
176
+ # make a back up, but only of the original
177
+ @original_cover_file = "#{@cover_file}~"
178
+ FileUtils.cp(@cover_file, @original_cover_file)
277
179
  end
278
180
  if cover.height > COVER_ABSOLUTE_MAXHEIGHT
279
181
  FileUtils.cp(dialog.filename, "#{@cover_file}.orig")
280
182
  new_width = cover.width / (cover.height / COVER_ABSOLUTE_MAXHEIGHT.to_f)
281
- puts "Scaling large cover image to #{new_width.to_i} x #{COVER_ABSOLUTE_MAXHEIGHT}"
183
+ log.info do
184
+ "Scaling large cover image to" \
185
+ " #{new_width.to_i} x #{COVER_ABSOLUTE_MAXHEIGHT}"
186
+ end
282
187
  cover = cover.scale(new_width.to_i, COVER_ABSOLUTE_MAXHEIGHT)
283
- cover.save(@cover_file, 'jpeg')
188
+ cover.save(@cover_file, "jpeg")
284
189
  else
285
190
  FileUtils.cp(dialog.filename, @cover_file)
286
191
  end
287
192
 
288
193
  self.cover = cover
289
194
  @@latest_filechooser_directory = dialog.current_folder
290
- rescue RuntimeError => e
291
- ErrorDialog.new(@book_properties_dialog, e.message).display
195
+ rescue RuntimeError => ex
196
+ ErrorDialog.new(@book_properties_dialog, ex.message).display
292
197
  end
293
- elsif response == Gtk::ResponseType::REJECT
198
+ when Gtk::ResponseType::REJECT
294
199
  ## FileUtils.rm_f(@cover_file) # fixing bug #16707
295
200
  @delete_cover_file = true
296
201
 
@@ -313,7 +218,7 @@ module Alexandria
313
218
  end
314
219
 
315
220
  def on_loaned_date_changed
316
- date_regexes = [/[0123]?[0-9]\/[0123]?[0-9]\/[0-9]{4}/,
221
+ date_regexes = [%r{[0123]?[0-9]/[0123]?[0-9]/[0-9]{4}},
317
222
  /[0-9]{4}-[0123]?[0-9]-[0123]?[0-9]/]
318
223
  matches_regex = false
319
224
  date_regexes.each do |regex|
@@ -324,29 +229,30 @@ module Alexandria
324
229
 
325
230
  t = parse_date(@date_loaned_since.text)
326
231
  if t.nil?
327
- @label_loaning_duration.label = ''
232
+ @label_loaning_duration.label = ""
328
233
  return
329
234
  end
330
235
  loaned_time = Time.at(t)
331
236
  n_days = ((Time.now - loaned_time) / (3600 * 24)).to_i
332
237
  if n_days > 365_250 # 1,000 years
333
- @label_loaning_duration.label = ''
238
+ @label_loaning_duration.label = ""
334
239
  return
335
240
  end
336
241
  @label_loaning_duration.label = if n_days > 0
337
- n_('%d day', '%d days', n_days) % n_days
242
+ n_("%d day", "%d days", n_days) % n_days
338
243
  else
339
- ''
244
+ ""
340
245
  end
341
246
  end
342
247
 
343
248
  def redd_toggled
344
249
  redd_yes = @checkbutton_redd.active?
345
250
  @redd_date.sensitive = redd_yes
346
- if @setup_finished
347
- # don't do this when popping up the dialog for the first time
348
- display_calendar_popup(@redd_date) if redd_yes && @redd_date.text.strip.empty?
349
- end
251
+
252
+ return unless redd_yes && @redd_date.text.strip.empty?
253
+
254
+ # don't do this when popping up the dialog for the first time
255
+ display_calendar_popup(@redd_date) if @setup_finished
350
256
  end
351
257
 
352
258
  private
@@ -359,7 +265,7 @@ module Alexandria
359
265
  @image_rating4,
360
266
  @image_rating5
361
267
  ]
362
- raise 'out of range' if rating < 0 || rating > images.length
268
+ raise _("out of range") if rating < 0 || rating > images.length
363
269
 
364
270
  images[0..rating - 1].each { |x| x.pixbuf = Icons::STAR_SET }
365
271
  images[rating..-1].each { |x| x.pixbuf = Icons::STAR_UNSET }
@@ -378,8 +284,8 @@ module Alexandria
378
284
 
379
285
  def loaned_since=(time)
380
286
  if time.nil?
381
- @date_loaned_since.text = ''
382
- @label_loaning_duration.label = ''
287
+ @date_loaned_since.text = ""
288
+ @label_loaning_duration.label = ""
383
289
  else
384
290
  @date_loaned_since.text = format_date(time)
385
291
  on_loaned_date_changed
@@ -392,8 +298,9 @@ module Alexandria
392
298
  end
393
299
 
394
300
  def parse_date(datestring)
395
- date_format = '%d/%m/%Y' # or '%m/%d/%Y' for USA and Canada ; or '%Y-%m-%d' for most of Asia
396
- ## http://en.wikipedia.org/wiki/Calendar_date#Middle_endian_forms.2C_starting_with_the_month
301
+ # '%m/%d/%Y' for USA and Canada ; or '%Y-%m-%d' for most of Asia
302
+ # http://en.wikipedia.org/wiki/Calendar_date#Middle_endian_forms.2C_starting_with_the_month
303
+ date_format = "%d/%m/%Y"
397
304
  begin
398
305
  d = Date.strptime(datestring, date_format)
399
306
  Time.gm(d.year, d.month, d.day)
@@ -403,7 +310,7 @@ module Alexandria
403
310
  end
404
311
 
405
312
  def format_date(datetime)
406
- datetime.strftime('%d/%m/%Y')
313
+ datetime.strftime("%d/%m/%Y")
407
314
  end
408
315
  end
409
316
  end