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
@@ -1,43 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2011 Cathal Mc Ginley
3
+ # This file is part of Alexandria.
4
4
  #
5
- # Alexandria is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU General Public License as
7
- # published by the Free Software Foundation; either version 2 of the
8
- # License, or (at your option) any later version.
9
- #
10
- # Alexandria is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public
16
- # License along with Alexandria; see the file COPYING. If not,
17
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
18
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
19
6
 
20
7
  module Alexandria
21
8
  module UI
22
9
  class BuilderBase
23
10
  def initialize(filename, widget_names)
24
- file = File.join(Alexandria::Config::DATA_DIR, 'glade', filename)
11
+ file = File.join(Alexandria::Config::DATA_DIR, "glade", filename)
25
12
  builder = Gtk::Builder.new
13
+ # TODO: This emits the warning 'GtkDialog mapped without a transient
14
+ # parent. This is discouraged.'
26
15
  builder.add_from_file(file)
27
16
  builder.connect_signals do |handler|
28
- begin
29
- method(handler)
30
- rescue => ex
31
- puts "Error: #{ex}" if $DEBUG
32
- nil
33
- end
17
+ method(handler)
34
18
  end
35
19
  widget_names.each do |name|
36
- begin
37
- instance_variable_set("@#{name}".intern, builder[name.to_s])
38
- rescue => err
39
- puts "Error: #{err}" if $DEBUG
40
- end
20
+ instance_variable_set("@#{name}".intern, builder[name.to_s])
41
21
  end
42
22
  end
43
23
  end
@@ -0,0 +1,58 @@
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
+ module CalendarPopup
10
+ def setup_calendar_widgets
11
+ @calendar_popup = Gtk::Popover.new
12
+ @calendar_popup.position = :bottom
13
+
14
+ @calendar = Gtk::Calendar.new
15
+ @calendar.show
16
+ @calendar_popup.add(@calendar)
17
+
18
+ @calendar.signal_connect("day-selected") do
19
+ assign_selected_date
20
+ end
21
+
22
+ @calendar.signal_connect("day-selected-double-click") do
23
+ assign_selected_date
24
+ @calendar_popup.hide
25
+ end
26
+ end
27
+
28
+ def assign_selected_date
29
+ date_arr = @calendar.date
30
+ year = date_arr[0]
31
+ month = date_arr[1] # + 1 # gtk : months 0-indexed, Time.gm : 1-index
32
+ day = date_arr[2]
33
+ time = Time.gm(year, month, day)
34
+ @calendar_popup_for_entry.text = format_date(time)
35
+ end
36
+
37
+ def clear_date_entry(entry)
38
+ entry.text = ""
39
+ end
40
+
41
+ def display_calendar_popup(entry)
42
+ setup_calendar_widgets unless defined? @calendar_popup
43
+
44
+ @calendar_popup_for_entry = entry
45
+ unless entry.text.strip.empty?
46
+ time = parse_date(entry.text)
47
+ unless time.nil?
48
+ @calendar.year = time.year
49
+ @calendar.month = time.month - 1
50
+ @calendar.day = time.day
51
+ end
52
+ end
53
+ @calendar_popup.set_relative_to(entry)
54
+ @calendar_popup.popup
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,23 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2004-2006 Laurent Sansonetti
4
- # Copyright (C) 2008 Joseph Method
5
- # Copyright (C) 2011, 2014, 2016 Matijs van Zuijlen
3
+ # This file is part of Alexandria.
6
4
  #
7
- # Alexandria is free software; you can redistribute it and/or
8
- # modify it under the terms of the GNU General Public License as
9
- # published by the Free Software Foundation; either version 2 of the
10
- # License, or (at your option) any later version.
11
- #
12
- # Alexandria is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- # General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public
18
- # License along with Alexandria; see the file COPYING. If not,
19
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
20
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ require "alexandria/ui/really_delete_dialog"
21
8
 
22
9
  module Alexandria
23
10
  module UI
@@ -26,7 +13,7 @@ module Alexandria
26
13
 
27
14
  def on_new(*)
28
15
  name = Library.generate_new_name(@libraries.all_libraries)
29
- library = Library.load(name)
16
+ library = @libraries.library_store.load_library(name)
30
17
  @libraries.add_library(library)
31
18
  append_library(library, true)
32
19
  setup_move_actions
@@ -34,17 +21,17 @@ module Alexandria
34
21
  end
35
22
 
36
23
  def on_new_smart(*)
37
- NewSmartLibraryDialog.new(@main_app) do |smart_library|
38
- smart_library.refilter
39
- @libraries.add_library(smart_library)
40
- append_library(smart_library, true)
41
- smart_library.save
42
- end
24
+ smart_library = NewSmartLibraryDialog.new(@main_app).acquire or return
25
+
26
+ smart_library.refilter
27
+ @libraries.add_library(smart_library)
28
+ append_library(smart_library, true)
29
+ smart_library.save
43
30
  end
44
31
 
45
32
  def on_add_book(*)
46
- log.info { 'on_add_book' }
47
- NewBookDialog.new(@main_app, selected_library) do |_books, library, is_new|
33
+ log.info { "on_add_book" }
34
+ dialog = NewBookDialog.new(@main_app, selected_library) do |_books, library, is_new|
48
35
  if is_new
49
36
  append_library(library, true)
50
37
  setup_move_actions
@@ -52,28 +39,28 @@ module Alexandria
52
39
  select_library(library)
53
40
  end
54
41
  end
42
+ dialog.show
55
43
  end
56
44
 
57
45
  def on_add_book_manual(*)
58
46
  library = selected_library
59
- NewBookDialogManual.new(@main_app, library) { |_book|
47
+ dialog = NewBookDialogManual.new(@main_app, library) do |_book|
60
48
  refresh_books
61
- }
49
+ end
50
+ dialog.show
62
51
  end
63
52
 
64
53
  def on_import(*)
65
- ImportDialog.new(@main_app) do |library, bad_isbns, failed_isbns|
54
+ ImportDialog.new(@main_app).acquire do |library, bad_isbns, failed_isbns|
66
55
  unless bad_isbns.empty?
67
- log.debug { 'bad_isbn' }
68
- message = _('The following lines are not valid ISBNs and were not imported:')
69
- bad_isbn_warn = BadIsbnsDialog.new(@main_app, message, bad_isbns)
70
- bad_isbn_warn.signal_connect('response') { bad_isbn_warn.destroy }
56
+ log.debug { "bad_isbn" }
57
+ message = _("The following lines are not valid ISBNs and were not imported:")
58
+ BadIsbnsDialog.new(@main_app, message, bad_isbns).show
71
59
  end
72
60
  unless failed_isbns.nil? || failed_isbns.empty?
73
61
  log.debug { "failed lookup of #{failed_isbns.size} ISBNs" }
74
- message = _('Books could not be found for the following ISBNs:')
75
- failed_lookup = BadIsbnsDialog.new(@main_app, message, failed_isbns)
76
- failed_lookup.signal_connect('response') { failed_lookup.destroy }
62
+ message = _("Books could not be found for the following ISBNs:")
63
+ BadIsbnsDialog.new(@main_app, message, failed_isbns).show
77
64
  end
78
65
  @libraries.add_library(library)
79
66
  append_library(library, true)
@@ -82,38 +69,40 @@ module Alexandria
82
69
  end
83
70
 
84
71
  def on_window_state_event(_window, event)
85
- log.debug { 'window-state-event' }
86
- @maximized = event.new_window_state == :maximized if event.is_a?(Gdk::EventWindowState)
87
- log.debug { 'end window-state-event' }
72
+ log.debug { "window-state-event" }
73
+ if event.is_a?(Gdk::EventWindowState)
74
+ @maximized = event.new_window_state == :maximized
75
+ end
76
+ log.debug { "end window-state-event" }
88
77
  end
89
78
 
90
- def on_toolbar_view_as_changed(cb)
91
- log.debug { 'changed' }
92
- action = case cb.active
79
+ def on_toolbar_view_as_changed(widget)
80
+ log.debug { "changed" }
81
+ action = case widget.active
93
82
  when 0
94
- @actiongroup['AsIcons']
83
+ @actiongroup["AsIcons"]
95
84
  when 1
96
- @actiongroup['AsList']
85
+ @actiongroup["AsList"]
97
86
  end
98
87
  action.active = true
99
88
  end
100
89
 
101
90
  def on_window_destroy(_window)
102
- log.debug { 'destroy' }
103
- @actiongroup['Quit'].activate
91
+ log.debug { "destroy" }
92
+ @actiongroup["Quit"].activate
104
93
  end
105
94
 
106
95
  def on_toolbar_filter_entry_changed(_entry)
107
- log.debug { 'changed' }
96
+ log.debug { "changed" }
108
97
  @filter_entry.text.strip!
109
98
  @iconview.freeze
110
99
  @filtered_model.refilter
111
100
  @iconview.unfreeze
112
101
  end
113
102
 
114
- def on_criterion_combobox_changed(cb)
115
- log.debug { 'changed' }
116
- @filter_books_mode = cb.active
103
+ def on_criterion_combobox_changed(widget)
104
+ log.debug { "changed" }
105
+ @filter_books_mode = widget.active
117
106
  @filter_entry.text.strip!
118
107
  @iconview.freeze
119
108
  @filtered_model.refilter
@@ -121,32 +110,29 @@ module Alexandria
121
110
  end
122
111
 
123
112
  def on_export(*)
124
- ExportDialog.new(@main_app, selected_library, library_sort_order)
125
- # FIXME: Remove this hack and fix the underlying problem.
126
- rescue => ex
127
- log.error { "problem with immediate export #{ex} try again" }
128
- ErrorDialog.new(@main_app, _('Export failed'),
129
- _('Try letting this library load ' \
130
- 'completely before exporting.'))
113
+ ExportDialog.new(@main_app, selected_library, library_sort_order).perform
131
114
  end
132
115
 
133
116
  def on_acquire(*)
134
- AcquireDialog.new(@main_app,
135
- selected_library) do |_books, library, is_new|
136
- if is_new
137
- append_library(library, true)
138
- setup_move_actions
139
- elsif selected_library != library
140
- select_library(library)
141
- end
142
- end
117
+ dialog =
118
+ AcquireDialog.new(@main_app, selected_library) do |_books, library, is_new|
119
+ if is_new
120
+ append_library(library, true)
121
+ setup_move_actions
122
+ elsif selected_library != library
123
+ select_library(library)
124
+ end
125
+ end
126
+ dialog.show
143
127
  end
144
128
 
145
129
  def on_properties(*)
146
130
  if @library_listview.focus? || selected_books.empty?
147
131
  library = selected_library
148
132
  if library.is_a?(SmartLibrary)
149
- SmartLibraryPropertiesDialog.new(@main_app, library) do
133
+ success = SmartLibraryPropertiesDialog.new(@main_app, library).acquire
134
+
135
+ if success
150
136
  library.refilter
151
137
  refresh_books
152
138
  end
@@ -155,9 +141,10 @@ module Alexandria
155
141
  books = selected_books
156
142
  if books.length == 1
157
143
  book = books.first
158
- BookPropertiesDialog.new(@main_app,
159
- selected_library,
160
- book) # { |modified_book| }
144
+ dialog = BookPropertiesDialog.new(@main_app,
145
+ selected_library,
146
+ book)
147
+ dialog.show
161
148
  end
162
149
  end
163
150
  end
@@ -179,7 +166,7 @@ module Alexandria
179
166
  end
180
167
 
181
168
  def on_select_all(*)
182
- log.debug { 'on_select_all' }
169
+ log.debug { "on_select_all" }
183
170
  case @notebook.page
184
171
  when 0
185
172
  @iconview.select_all
@@ -189,7 +176,7 @@ module Alexandria
189
176
  end
190
177
 
191
178
  def on_deselect_all(*)
192
- log.debug { 'on_deselect_all' }
179
+ log.debug { "on_deselect_all" }
193
180
  case @notebook.page
194
181
  when 0
195
182
  @iconview.unselect_all
@@ -231,7 +218,7 @@ module Alexandria
231
218
  is_smart = library.is_a?(SmartLibrary)
232
219
  last_library = (@libraries.all_regular_libraries.length == 1)
233
220
  if books.nil? && !is_smart && last_library
234
- log.warn { 'Attempted to delete last library, fix GUI' }
221
+ log.warn { "Attempted to delete last library, fix GUI" }
235
222
  return
236
223
  end
237
224
  if library.empty? || ReallyDeleteDialog.new(@main_app,
@@ -242,7 +229,7 @@ module Alexandria
242
229
  end
243
230
 
244
231
  def on_clear_search_results(*)
245
- @filter_entry.text = ''
232
+ @filter_entry.text = ""
246
233
  @iconview.freeze
247
234
  @filtered_model.refilter
248
235
  @iconview.unfreeze
@@ -253,9 +240,10 @@ module Alexandria
253
240
  end
254
241
 
255
242
  def on_preferences(*)
256
- PreferencesDialog.new(@main_app) do
243
+ dialog = PreferencesDialog.new(@main_app) do
257
244
  @listview_manager.setup_listview_columns_visibility
258
245
  end
246
+ dialog.show
259
247
  end
260
248
 
261
249
  def on_submit_bug_report(*)
@@ -267,160 +255,178 @@ module Alexandria
267
255
  end
268
256
 
269
257
  def on_about(*)
270
- ad = AboutDialog.new(@main_app)
271
- ad.signal_connect('response') do
272
- log.debug { 'destroy about' }
273
- ad.destroy
274
- end
275
- ad.show
258
+ AboutDialog.new(@main_app).show
276
259
  end
277
260
 
278
261
  def on_view_sidepane(action)
279
- log.debug { 'on_view_sidepane' }
262
+ log.debug { "on_view_sidepane" }
280
263
  @paned.child1.visible = action.active?
281
264
  end
282
265
 
283
266
  def on_view_toolbar(action)
284
- log.debug { 'on_view_toolbar' }
267
+ log.debug { "on_view_toolbar" }
285
268
  @toolbar.visible = action.active?
286
269
  end
287
270
 
288
271
  def on_view_statusbar(action)
289
- log.debug { 'on_view_statusbar' }
272
+ log.debug { "on_view_statusbar" }
290
273
  @appbar.visible = action.active?
291
274
  end
292
275
 
293
276
  def on_reverse_order(action)
294
- log.debug { 'on_reverse_order' }
277
+ log.debug { "on_reverse_order" }
295
278
  Preferences.instance.reverse_icons = action.active?
296
279
  Preferences.instance.save!
297
280
  setup_books_iconview_sorting
298
281
  end
299
282
 
300
283
  def connect_signals
301
- # rubocop:disable LineLength
302
- standard_actions = [
303
- ['LibraryMenu', nil, _('_Library')],
304
- ['New', Gtk::Stock::NEW, _('_New Library'), '<control>L', _('Create a new library'), method(:on_new)],
305
- ['NewSmart', nil, _('New _Smart Library...'), '<control><shift>L', _('Create a new smart library'), method(:on_new_smart)],
306
- ['AddBook', Gtk::Stock::ADD, _('_Add Book...'), '<control>N', _('Add a new book from the Internet'), method(:on_add_book)],
307
- ['AddBookManual', nil, _('Add Book _Manually...'), '<control><shift>N', _('Add a new book manually'), method(:on_add_book_manual)],
308
- ['Import', nil, _('_Import...'), '<control>I', _('Import a library'), method(:on_import)],
309
- ['Export', nil, _('_Export...'), '<control><shift>E', _('Export the selected library'), method(:on_export)],
310
- ['Acquire', nil, _('A_cquire from Scanner...'), '<control><shift>S', _('Acquire books from a scanner'), method(:on_acquire)],
311
- ['Properties', Gtk::Stock::PROPERTIES, _('_Properties'), nil, _('Edit the properties of the selected book'), method(:on_properties)],
312
- ['Quit', Gtk::Stock::QUIT, _('_Quit'), '<control>Q', _('Quit the program'), method(:on_quit)],
313
- ['EditMenu', nil, _('_Edit')],
314
- ['Undo', Gtk::Stock::UNDO, _('_Undo'), '<control>Z', _('Undo the last action'), method(:on_undo)],
315
- ['Redo', Gtk::Stock::REDO, _('_Redo'), '<control><shift>Z', _('Redo the undone action'), method(:on_redo)],
316
- ['SelectAll', nil, _('_Select All'), '<control>A', _('Select all visible books'), method(:on_select_all)],
317
- ['DeselectAll', nil, _('Dese_lect All'), '<control><shift>A', _('Deselect everything'), method(:on_deselect_all)],
318
- ['SetRating', nil, _('My _Rating')],
319
- ['SetRating0', nil, _('None'), nil, nil, proc { on_set_rating[0].call }],
320
- ['SetRating1', nil, _('One Star'), nil, nil, proc { on_set_rating[1].call }],
321
- ['SetRating2', nil, _('Two Stars'), nil, nil, proc { on_set_rating[2].call }],
322
- ['SetRating3', nil, _('Three Stars'), nil, nil, proc { on_set_rating[3].call }],
323
- ['SetRating4', nil, _('Four Stars'), nil, nil, proc { on_set_rating[4].call }],
324
- ['SetRating5', nil, _('Five Stars'), nil, nil, proc { on_set_rating[5].call }],
325
- ['Move', nil, _('_Move')],
326
- ['Rename', nil, _('_Rename'), nil, nil, method(:on_rename)],
327
- ['Delete', Gtk::Stock::DELETE, _('_Delete'), 'Delete', _('Delete the selected books or library'), method(:on_delete)],
328
- ['Search', Gtk::Stock::FIND, _('_Search'), '<control>F', _('Filter books'), method(:on_search)],
329
- ['ClearSearchResult', Gtk::Stock::CLEAR, _('_Clear Results'), '<control><alt>B', _('Clear the search results'), method(:on_clear_search_results)],
330
- ['Preferences', Gtk::Stock::PREFERENCES, _('_Preferences'), '<control>O', _("Change Alexandria's settings"), method(:on_preferences)],
331
- ['ViewMenu', nil, _('_View')],
332
- ['ArrangeIcons', nil, _('Arran_ge Icons')],
333
- ['OnlineInformation', nil, _('Display Online _Information')],
334
-
335
- ['HelpMenu', nil, _('_Help')],
336
- ['SubmitBugReport', Gtk::Stock::EDIT, _('Submit _Bug Report'), nil, _('Submit a bug report to the developers'), method(:on_submit_bug_report)],
337
- ['Help', Gtk::Stock::HELP, _('Contents'), 'F1', _("View Alexandria's manual"), method(:on_help)],
338
- ['About', Gtk::Stock::ABOUT, _('_About'), nil, _('Show information about Alexandria'), method(:on_about)],
339
- ]
340
- # rubocop:enable LineLength
341
-
342
- toggle_actions = [
343
- ['Sidepane', nil, _('Side _Pane'), 'F9', nil, method(:on_view_sidepane), true],
344
- ['Toolbar', nil, _('_Toolbar'), nil, nil, method(:on_view_toolbar), true],
345
- ['Statusbar', nil, _('_Statusbar'), nil, nil, method(:on_view_statusbar), true],
346
- ['ReversedOrder', nil, _('Re_versed Order'), nil, nil, method(:on_reverse_order)],
347
- ]
348
-
349
- view_as_actions = [
350
- ['AsIcons', nil, _('View as _Icons'), nil, nil, 0],
351
- ['AsList', nil, _('View as _List'), nil, nil, 1]
352
- ]
353
-
354
- arrange_icons_actions = [
355
- ['ByTitle', nil, _('By _Title'), nil, nil, 0],
356
- ['ByAuthors', nil, _('By _Authors'), nil, nil, 1],
357
- ['ByISBN', nil, _('By _ISBN'), nil, nil, 2],
358
- ['ByPublisher', nil, _('By _Publisher'), nil, nil, 3],
359
- ['ByEdition', nil, _('By _Binding'), nil, nil, 4],
360
- ['ByRating', nil, _('By _Rating'), nil, nil, 5]
361
- ]
362
- providers_actions = BookProviders.map do |provider|
363
- [provider.action_name, Gtk::Stock::JUMP_TO,
364
- _('At _%s') % provider.fullname, nil, nil,
365
- proc { open_web_browser(provider.url(selected_books.first)) }]
366
- end
284
+ log.debug { "Adding actions to @actiongroup" }
367
285
 
368
- log.debug { 'Adding actions to @actiongroup' }
286
+ @actiongroup = Gtk::ActionGroup.new("actions")
369
287
 
370
- @actiongroup = Gtk::ActionGroup.new('actions')
288
+ connect_standard_actions
289
+ connect_providers_actions
290
+ connect_toggle_actions
291
+ connect_view_actions
292
+ connect_arrange_icons_actions
293
+ end
371
294
 
372
- standard_actions.each do |name, stock_id, label, accelerator, tooltip, callback|
373
- action = Gtk::Action.new(name, label: label, tooltip: tooltip, stock_id: stock_id)
374
- @actiongroup.add_action_with_accel(action, accelerator)
375
- action.signal_connect('activate', &callback) if callback
376
- end
295
+ private
377
296
 
378
- providers_actions.each do |name, stock_id, label, accelerator, tooltip, callback|
297
+ def connect_standard_actions
298
+ connect_actions standard_actions
299
+ end
300
+
301
+ def connect_providers_actions
302
+ connect_actions providers_actions
303
+ end
304
+
305
+ def connect_actions(actions)
306
+ actions.each do |name, stock_id, label, accelerator, tooltip, callback|
379
307
  action = Gtk::Action.new(name, label: label, tooltip: tooltip, stock_id: stock_id)
380
308
  @actiongroup.add_action_with_accel(action, accelerator)
381
- action.signal_connect('activate', &callback) if callback
309
+ action.signal_connect("activate", &callback) if callback
382
310
  end
311
+ end
383
312
 
384
- toggle_actions.each do |name, stock_id, label, accelerator, tooltip, callback, is_active|
385
- action = Gtk::ToggleAction.new(name, label: label, tooltip: tooltip, stock_id: stock_id)
313
+ def connect_toggle_actions
314
+ toggle_actions
315
+ .each do |name, stock_id, label, accelerator, tooltip, callback, is_active|
316
+ action = Gtk::ToggleAction.new(name, label: label, tooltip: tooltip,
317
+ stock_id: stock_id)
386
318
  action.set_active is_active
387
319
  @actiongroup.add_action_with_accel(action, accelerator)
388
- action.signal_connect('toggled', &callback) if callback
320
+ action.signal_connect("toggled", &callback) if callback
389
321
  end
322
+ end
390
323
 
391
- group = nil
392
- first_action = nil
393
- view_as_actions.each do |name, stock_id, label, accelerator, tooltip, value|
394
- action = Gtk::RadioAction.new(name, value, label: label, tooltip: tooltip, stock_id: stock_id)
395
- first_action = action unless group
396
- action.set_group group
397
- group = action.group
398
- @actiongroup.add_action_with_accel(action, accelerator)
399
- end
324
+ def connect_view_actions
325
+ first_action = connect_radio_actions view_as_actions
400
326
 
401
- first_action.signal_connect 'changed' do |_action, current, _user_data|
327
+ first_action.signal_connect "changed" do |_action, current, _user_data|
402
328
  @notebook.page = current.current_value
403
329
  hid = @toolbar_view_as_signal_hid
404
330
  @toolbar_view_as.signal_handler_block(hid) do
405
331
  @toolbar_view_as.active = current.current_value
406
332
  end
407
333
  end
334
+ end
408
335
 
409
- group = nil
410
- first_action = nil
411
- arrange_icons_actions.each do |name, stock_id, label, accelerator, tooltip, value|
412
- action = Gtk::RadioAction.new(name, value, label: label, tooltip: tooltip, stock_id: stock_id)
413
- first_action = action unless group
414
- action.set_group group
415
- group = action.group
416
- @actiongroup.add_action_with_accel(action, accelerator)
417
- end
336
+ def connect_arrange_icons_actions
337
+ first_action = connect_radio_actions arrange_icons_actions
418
338
 
419
- first_action.signal_connect 'changed' do |_action, current, _user_data|
339
+ first_action.signal_connect "changed" do |_action, current, _user_data|
420
340
  @prefs.arrange_icons_mode = current.current_value
421
341
  setup_books_iconview_sorting
422
342
  end
423
343
  end
344
+
345
+ def connect_radio_actions(actions)
346
+ first_action = nil
347
+ actions.each do |name, stock_id, label, accelerator, tooltip, value|
348
+ action = Gtk::RadioAction.new(name, value, label: label, tooltip: tooltip,
349
+ stock_id: stock_id)
350
+ if first_action
351
+ action.join_group first_action
352
+ else
353
+ first_action = action
354
+ end
355
+ @actiongroup.add_action_with_accel(action, accelerator)
356
+ end
357
+ first_action
358
+ end
359
+
360
+ def standard_actions
361
+ # rubocop:disable Layout/LineLength
362
+ [["LibraryMenu", nil, _("_Library")],
363
+ ["New", Gtk::Stock::NEW, _("_New Library"), "<control>L", _("Create a new library"), method(:on_new)],
364
+ ["NewSmart", nil, _("New _Smart Library..."), "<control><shift>L", _("Create a new smart library"), method(:on_new_smart)],
365
+ ["AddBook", Gtk::Stock::ADD, _("_Add Book..."), "<control>N", _("Add a new book from the Internet"), method(:on_add_book)],
366
+ ["AddBookManual", nil, _("Add Book _Manually..."), "<control><shift>N", _("Add a new book manually"), method(:on_add_book_manual)],
367
+ ["Import", nil, _("_Import..."), "<control>I", _("Import a library"), method(:on_import)],
368
+ ["Export", nil, _("_Export..."), "<control><shift>E", _("Export the selected library"), method(:on_export)],
369
+ ["Acquire", nil, _("A_cquire from Scanner..."), "<control><shift>S", _("Acquire books from a scanner"), method(:on_acquire)],
370
+ ["Properties", Gtk::Stock::PROPERTIES, _("_Properties"), nil, _("Edit the properties of the selected book"), method(:on_properties)],
371
+ ["Quit", Gtk::Stock::QUIT, _("_Quit"), "<control>Q", _("Quit the program"), method(:on_quit)],
372
+ ["EditMenu", nil, _("_Edit")],
373
+ ["Undo", Gtk::Stock::UNDO, _("_Undo"), "<control>Z", _("Undo the last action"), method(:on_undo)],
374
+ ["Redo", Gtk::Stock::REDO, _("_Redo"), "<control><shift>Z", _("Redo the undone action"), method(:on_redo)],
375
+ ["SelectAll", nil, _("_Select All"), "<control>A", _("Select all visible books"), method(:on_select_all)],
376
+ ["DeselectAll", nil, _("Dese_lect All"), "<control><shift>A", _("Deselect everything"), method(:on_deselect_all)],
377
+ ["SetRating", nil, _("My _Rating")],
378
+ ["SetRating0", nil, _("None"), nil, nil, proc { on_set_rating[0].call }],
379
+ ["SetRating1", nil, _("One Star"), nil, nil, proc { on_set_rating[1].call }],
380
+ ["SetRating2", nil, _("Two Stars"), nil, nil, proc { on_set_rating[2].call }],
381
+ ["SetRating3", nil, _("Three Stars"), nil, nil, proc { on_set_rating[3].call }],
382
+ ["SetRating4", nil, _("Four Stars"), nil, nil, proc { on_set_rating[4].call }],
383
+ ["SetRating5", nil, _("Five Stars"), nil, nil, proc { on_set_rating[5].call }],
384
+ ["Move", nil, _("_Move")],
385
+ ["Rename", nil, _("_Rename"), nil, nil, method(:on_rename)],
386
+ ["Delete", Gtk::Stock::DELETE, _("_Delete"), "Delete", _("Delete the selected books or library"), method(:on_delete)],
387
+ ["Search", Gtk::Stock::FIND, _("_Search"), "<control>F", _("Filter books"), method(:on_search)],
388
+ ["ClearSearchResult", Gtk::Stock::CLEAR, _("_Clear Results"), "<control><alt>B", _("Clear the search results"), method(:on_clear_search_results)],
389
+ ["Preferences", Gtk::Stock::PREFERENCES, _("_Preferences"), "<control>O", _("Change Alexandria's settings"), method(:on_preferences)],
390
+ ["ViewMenu", nil, _("_View")],
391
+ ["ArrangeIcons", nil, _("Arran_ge Icons")],
392
+ ["OnlineInformation", nil, _("Display Online _Information")],
393
+
394
+ ["HelpMenu", nil, _("_Help")],
395
+ ["SubmitBugReport", Gtk::Stock::EDIT, _("Submit _Bug Report"), nil, _("Submit a bug report to the developers"), method(:on_submit_bug_report)],
396
+ ["Help", Gtk::Stock::HELP, _("Contents"), "F1", _("View Alexandria's manual"), method(:on_help)],
397
+ ["About", Gtk::Stock::ABOUT, _("_About"), nil, _("Show information about Alexandria"), method(:on_about)]]
398
+ # rubocop:enable Layout/LineLength
399
+ end
400
+
401
+ def providers_actions
402
+ BookProviders.list.map do |provider|
403
+ [provider.action_name, Gtk::Stock::JUMP_TO,
404
+ _("At _%s") % provider.fullname, nil, nil,
405
+ proc { open_web_browser(provider.url(selected_books.first)) }]
406
+ end
407
+ end
408
+
409
+ def toggle_actions
410
+ [["Sidepane", nil, _("Side_pane"), "F9", nil, method(:on_view_sidepane), true],
411
+ ["Toolbar", nil, _("_Toolbar"), nil, nil, method(:on_view_toolbar), true],
412
+ ["Statusbar", nil, _("_Statusbar"), nil, nil, method(:on_view_statusbar), true],
413
+ ["ReversedOrder", nil, _("Re_versed Order"), nil, nil,
414
+ method(:on_reverse_order), false]]
415
+ end
416
+
417
+ def view_as_actions
418
+ [["AsIcons", nil, _("View as _Icons"), nil, nil, 0],
419
+ ["AsList", nil, _("View as _List"), nil, nil, 1]]
420
+ end
421
+
422
+ def arrange_icons_actions
423
+ [["ByTitle", nil, _("By _Title"), nil, nil, 0],
424
+ ["ByAuthors", nil, _("By _Authors"), nil, nil, 1],
425
+ ["ByISBN", nil, _("By _ISBN"), nil, nil, 2],
426
+ ["ByPublisher", nil, _("By _Publisher"), nil, nil, 3],
427
+ ["ByEdition", nil, _("By _Binding"), nil, nil, 4],
428
+ ["ByRating", nil, _("By _Rating"), nil, nil, 5]]
429
+ end
424
430
  end
425
431
  end
426
432
  end