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
@@ -8,7 +8,7 @@ module Alexandria
8
8
  module UI
9
9
  class BuilderBase
10
10
  def initialize(filename, widget_names)
11
- file = File.join(Alexandria::Config::DATA_DIR, 'glade', filename)
11
+ file = File.join(Alexandria::Config::DATA_DIR, "glade", filename)
12
12
  builder = Gtk::Builder.new
13
13
  # TODO: This emits the warning 'GtkDialog mapped without a transient
14
14
  # parent. This is discouraged.'
@@ -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
@@ -4,6 +4,8 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
+ require "alexandria/ui/really_delete_dialog"
8
+
7
9
  module Alexandria
8
10
  module UI
9
11
  module Callbacks
@@ -11,7 +13,7 @@ module Alexandria
11
13
 
12
14
  def on_new(*)
13
15
  name = Library.generate_new_name(@libraries.all_libraries)
14
- library = Library.load(name)
16
+ library = @libraries.library_store.load_library(name)
15
17
  @libraries.add_library(library)
16
18
  append_library(library, true)
17
19
  setup_move_actions
@@ -19,17 +21,17 @@ module Alexandria
19
21
  end
20
22
 
21
23
  def on_new_smart(*)
22
- NewSmartLibraryDialog.new(@main_app).acquire do |smart_library|
23
- smart_library.refilter
24
- @libraries.add_library(smart_library)
25
- append_library(smart_library, true)
26
- smart_library.save
27
- 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
28
30
  end
29
31
 
30
32
  def on_add_book(*)
31
- log.info { 'on_add_book' }
32
- 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|
33
35
  if is_new
34
36
  append_library(library, true)
35
37
  setup_move_actions
@@ -37,28 +39,28 @@ module Alexandria
37
39
  select_library(library)
38
40
  end
39
41
  end
42
+ dialog.show
40
43
  end
41
44
 
42
45
  def on_add_book_manual(*)
43
46
  library = selected_library
44
- NewBookDialogManual.new(@main_app, library) { |_book|
47
+ dialog = NewBookDialogManual.new(@main_app, library) do |_book|
45
48
  refresh_books
46
- }
49
+ end
50
+ dialog.show
47
51
  end
48
52
 
49
53
  def on_import(*)
50
54
  ImportDialog.new(@main_app).acquire do |library, bad_isbns, failed_isbns|
51
55
  unless bad_isbns.empty?
52
- log.debug { 'bad_isbn' }
53
- message = _('The following lines are not valid ISBNs and were not imported:')
54
- bad_isbn_warn = BadIsbnsDialog.new(@main_app, message, bad_isbns)
55
- 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
56
59
  end
57
60
  unless failed_isbns.nil? || failed_isbns.empty?
58
61
  log.debug { "failed lookup of #{failed_isbns.size} ISBNs" }
59
- message = _('Books could not be found for the following ISBNs:')
60
- failed_lookup = BadIsbnsDialog.new(@main_app, message, failed_isbns)
61
- 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
62
64
  end
63
65
  @libraries.add_library(library)
64
66
  append_library(library, true)
@@ -67,38 +69,40 @@ module Alexandria
67
69
  end
68
70
 
69
71
  def on_window_state_event(_window, event)
70
- log.debug { 'window-state-event' }
71
- @maximized = event.new_window_state == :maximized if event.is_a?(Gdk::EventWindowState)
72
- 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" }
73
77
  end
74
78
 
75
- def on_toolbar_view_as_changed(cb)
76
- log.debug { 'changed' }
77
- action = case cb.active
79
+ def on_toolbar_view_as_changed(widget)
80
+ log.debug { "changed" }
81
+ action = case widget.active
78
82
  when 0
79
- @actiongroup['AsIcons']
83
+ @actiongroup["AsIcons"]
80
84
  when 1
81
- @actiongroup['AsList']
85
+ @actiongroup["AsList"]
82
86
  end
83
87
  action.active = true
84
88
  end
85
89
 
86
90
  def on_window_destroy(_window)
87
- log.debug { 'destroy' }
88
- @actiongroup['Quit'].activate
91
+ log.debug { "destroy" }
92
+ @actiongroup["Quit"].activate
89
93
  end
90
94
 
91
95
  def on_toolbar_filter_entry_changed(_entry)
92
- log.debug { 'changed' }
96
+ log.debug { "changed" }
93
97
  @filter_entry.text.strip!
94
98
  @iconview.freeze
95
99
  @filtered_model.refilter
96
100
  @iconview.unfreeze
97
101
  end
98
102
 
99
- def on_criterion_combobox_changed(cb)
100
- log.debug { 'changed' }
101
- @filter_books_mode = cb.active
103
+ def on_criterion_combobox_changed(widget)
104
+ log.debug { "changed" }
105
+ @filter_books_mode = widget.active
102
106
  @filter_entry.text.strip!
103
107
  @iconview.freeze
104
108
  @filtered_model.refilter
@@ -110,22 +114,25 @@ module Alexandria
110
114
  end
111
115
 
112
116
  def on_acquire(*)
113
- AcquireDialog.new(@main_app,
114
- selected_library) do |_books, library, is_new|
115
- if is_new
116
- append_library(library, true)
117
- setup_move_actions
118
- elsif selected_library != library
119
- select_library(library)
120
- end
121
- 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
122
127
  end
123
128
 
124
129
  def on_properties(*)
125
130
  if @library_listview.focus? || selected_books.empty?
126
131
  library = selected_library
127
132
  if library.is_a?(SmartLibrary)
128
- SmartLibraryPropertiesDialog.new(@main_app, library).acquire do
133
+ success = SmartLibraryPropertiesDialog.new(@main_app, library).acquire
134
+
135
+ if success
129
136
  library.refilter
130
137
  refresh_books
131
138
  end
@@ -134,9 +141,10 @@ module Alexandria
134
141
  books = selected_books
135
142
  if books.length == 1
136
143
  book = books.first
137
- BookPropertiesDialog.new(@main_app,
138
- selected_library,
139
- book) # { |modified_book| }
144
+ dialog = BookPropertiesDialog.new(@main_app,
145
+ selected_library,
146
+ book)
147
+ dialog.show
140
148
  end
141
149
  end
142
150
  end
@@ -158,7 +166,7 @@ module Alexandria
158
166
  end
159
167
 
160
168
  def on_select_all(*)
161
- log.debug { 'on_select_all' }
169
+ log.debug { "on_select_all" }
162
170
  case @notebook.page
163
171
  when 0
164
172
  @iconview.select_all
@@ -168,7 +176,7 @@ module Alexandria
168
176
  end
169
177
 
170
178
  def on_deselect_all(*)
171
- log.debug { 'on_deselect_all' }
179
+ log.debug { "on_deselect_all" }
172
180
  case @notebook.page
173
181
  when 0
174
182
  @iconview.unselect_all
@@ -193,9 +201,9 @@ module Alexandria
193
201
 
194
202
  def on_rename(*)
195
203
  iter = @library_listview.selection.selected
196
- @library_listview.set_cursor(iter.path,
197
- @library_listview.get_column(0),
198
- true)
204
+ column = @library_listview.get_column(0)
205
+ cell = column.cells.last
206
+ @library_listview.set_cursor_on_cell(iter.path, column, cell, true)
199
207
  end
200
208
 
201
209
  def on_delete(*)
@@ -210,7 +218,7 @@ module Alexandria
210
218
  is_smart = library.is_a?(SmartLibrary)
211
219
  last_library = (@libraries.all_regular_libraries.length == 1)
212
220
  if books.nil? && !is_smart && last_library
213
- log.warn { 'Attempted to delete last library, fix GUI' }
221
+ log.warn { "Attempted to delete last library, fix GUI" }
214
222
  return
215
223
  end
216
224
  if library.empty? || ReallyDeleteDialog.new(@main_app,
@@ -221,7 +229,7 @@ module Alexandria
221
229
  end
222
230
 
223
231
  def on_clear_search_results(*)
224
- @filter_entry.text = ''
232
+ @filter_entry.text = ""
225
233
  @iconview.freeze
226
234
  @filtered_model.refilter
227
235
  @iconview.unfreeze
@@ -232,9 +240,10 @@ module Alexandria
232
240
  end
233
241
 
234
242
  def on_preferences(*)
235
- PreferencesDialog.new(@main_app) do
243
+ dialog = PreferencesDialog.new(@main_app) do
236
244
  @listview_manager.setup_listview_columns_visibility
237
245
  end
246
+ dialog.show
238
247
  end
239
248
 
240
249
  def on_submit_bug_report(*)
@@ -250,151 +259,174 @@ module Alexandria
250
259
  end
251
260
 
252
261
  def on_view_sidepane(action)
253
- log.debug { 'on_view_sidepane' }
262
+ log.debug { "on_view_sidepane" }
254
263
  @paned.child1.visible = action.active?
255
264
  end
256
265
 
257
266
  def on_view_toolbar(action)
258
- log.debug { 'on_view_toolbar' }
267
+ log.debug { "on_view_toolbar" }
259
268
  @toolbar.visible = action.active?
260
269
  end
261
270
 
262
271
  def on_view_statusbar(action)
263
- log.debug { 'on_view_statusbar' }
272
+ log.debug { "on_view_statusbar" }
264
273
  @appbar.visible = action.active?
265
274
  end
266
275
 
267
276
  def on_reverse_order(action)
268
- log.debug { 'on_reverse_order' }
277
+ log.debug { "on_reverse_order" }
269
278
  Preferences.instance.reverse_icons = action.active?
270
279
  Preferences.instance.save!
271
280
  setup_books_iconview_sorting
272
281
  end
273
282
 
274
283
  def connect_signals
275
- # rubocop:disable LineLength
276
- standard_actions = [
277
- ['LibraryMenu', nil, _('_Library')],
278
- ['New', Gtk::Stock::NEW, _('_New Library'), '<control>L', _('Create a new library'), method(:on_new)],
279
- ['NewSmart', nil, _('New _Smart Library...'), '<control><shift>L', _('Create a new smart library'), method(:on_new_smart)],
280
- ['AddBook', Gtk::Stock::ADD, _('_Add Book...'), '<control>N', _('Add a new book from the Internet'), method(:on_add_book)],
281
- ['AddBookManual', nil, _('Add Book _Manually...'), '<control><shift>N', _('Add a new book manually'), method(:on_add_book_manual)],
282
- ['Import', nil, _('_Import...'), '<control>I', _('Import a library'), method(:on_import)],
283
- ['Export', nil, _('_Export...'), '<control><shift>E', _('Export the selected library'), method(:on_export)],
284
- ['Acquire', nil, _('A_cquire from Scanner...'), '<control><shift>S', _('Acquire books from a scanner'), method(:on_acquire)],
285
- ['Properties', Gtk::Stock::PROPERTIES, _('_Properties'), nil, _('Edit the properties of the selected book'), method(:on_properties)],
286
- ['Quit', Gtk::Stock::QUIT, _('_Quit'), '<control>Q', _('Quit the program'), method(:on_quit)],
287
- ['EditMenu', nil, _('_Edit')],
288
- ['Undo', Gtk::Stock::UNDO, _('_Undo'), '<control>Z', _('Undo the last action'), method(:on_undo)],
289
- ['Redo', Gtk::Stock::REDO, _('_Redo'), '<control><shift>Z', _('Redo the undone action'), method(:on_redo)],
290
- ['SelectAll', nil, _('_Select All'), '<control>A', _('Select all visible books'), method(:on_select_all)],
291
- ['DeselectAll', nil, _('Dese_lect All'), '<control><shift>A', _('Deselect everything'), method(:on_deselect_all)],
292
- ['SetRating', nil, _('My _Rating')],
293
- ['SetRating0', nil, _('None'), nil, nil, proc { on_set_rating[0].call }],
294
- ['SetRating1', nil, _('One Star'), nil, nil, proc { on_set_rating[1].call }],
295
- ['SetRating2', nil, _('Two Stars'), nil, nil, proc { on_set_rating[2].call }],
296
- ['SetRating3', nil, _('Three Stars'), nil, nil, proc { on_set_rating[3].call }],
297
- ['SetRating4', nil, _('Four Stars'), nil, nil, proc { on_set_rating[4].call }],
298
- ['SetRating5', nil, _('Five Stars'), nil, nil, proc { on_set_rating[5].call }],
299
- ['Move', nil, _('_Move')],
300
- ['Rename', nil, _('_Rename'), nil, nil, method(:on_rename)],
301
- ['Delete', Gtk::Stock::DELETE, _('_Delete'), 'Delete', _('Delete the selected books or library'), method(:on_delete)],
302
- ['Search', Gtk::Stock::FIND, _('_Search'), '<control>F', _('Filter books'), method(:on_search)],
303
- ['ClearSearchResult', Gtk::Stock::CLEAR, _('_Clear Results'), '<control><alt>B', _('Clear the search results'), method(:on_clear_search_results)],
304
- ['Preferences', Gtk::Stock::PREFERENCES, _('_Preferences'), '<control>O', _("Change Alexandria's settings"), method(:on_preferences)],
305
- ['ViewMenu', nil, _('_View')],
306
- ['ArrangeIcons', nil, _('Arran_ge Icons')],
307
- ['OnlineInformation', nil, _('Display Online _Information')],
308
-
309
- ['HelpMenu', nil, _('_Help')],
310
- ['SubmitBugReport', Gtk::Stock::EDIT, _('Submit _Bug Report'), nil, _('Submit a bug report to the developers'), method(:on_submit_bug_report)],
311
- ['Help', Gtk::Stock::HELP, _('Contents'), 'F1', _("View Alexandria's manual"), method(:on_help)],
312
- ['About', Gtk::Stock::ABOUT, _('_About'), nil, _('Show information about Alexandria'), method(:on_about)],
313
- ]
314
- # rubocop:enable LineLength
315
-
316
- toggle_actions = [
317
- ['Sidepane', nil, _('Side _Pane'), 'F9', nil, method(:on_view_sidepane), true],
318
- ['Toolbar', nil, _('_Toolbar'), nil, nil, method(:on_view_toolbar), true],
319
- ['Statusbar', nil, _('_Statusbar'), nil, nil, method(:on_view_statusbar), true],
320
- ['ReversedOrder', nil, _('Re_versed Order'), nil, nil, method(:on_reverse_order), false],
321
- ]
322
-
323
- view_as_actions = [
324
- ['AsIcons', nil, _('View as _Icons'), nil, nil, 0],
325
- ['AsList', nil, _('View as _List'), nil, nil, 1]
326
- ]
327
-
328
- arrange_icons_actions = [
329
- ['ByTitle', nil, _('By _Title'), nil, nil, 0],
330
- ['ByAuthors', nil, _('By _Authors'), nil, nil, 1],
331
- ['ByISBN', nil, _('By _ISBN'), nil, nil, 2],
332
- ['ByPublisher', nil, _('By _Publisher'), nil, nil, 3],
333
- ['ByEdition', nil, _('By _Binding'), nil, nil, 4],
334
- ['ByRating', nil, _('By _Rating'), nil, nil, 5]
335
- ]
336
- providers_actions = BookProviders.map do |provider|
337
- [provider.action_name, Gtk::Stock::JUMP_TO,
338
- _('At _%s') % provider.fullname, nil, nil,
339
- proc { open_web_browser(provider.url(selected_books.first)) }]
340
- end
284
+ log.debug { "Adding actions to @actiongroup" }
341
285
 
342
- log.debug { 'Adding actions to @actiongroup' }
286
+ @actiongroup = Gtk::ActionGroup.new("actions")
343
287
 
344
- @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
345
294
 
346
- standard_actions.each do |name, stock_id, label, accelerator, tooltip, callback|
347
- action = Gtk::Action.new(name, label: label, tooltip: tooltip, stock_id: stock_id)
348
- @actiongroup.add_action_with_accel(action, accelerator)
349
- action.signal_connect('activate', &callback) if callback
350
- end
295
+ private
296
+
297
+ def connect_standard_actions
298
+ connect_actions standard_actions
299
+ end
351
300
 
352
- providers_actions.each do |name, stock_id, label, accelerator, tooltip, callback|
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|
353
307
  action = Gtk::Action.new(name, label: label, tooltip: tooltip, stock_id: stock_id)
354
308
  @actiongroup.add_action_with_accel(action, accelerator)
355
- action.signal_connect('activate', &callback) if callback
309
+ action.signal_connect("activate", &callback) if callback
356
310
  end
311
+ end
357
312
 
358
- toggle_actions.each do |name, stock_id, label, accelerator, tooltip, callback, is_active|
359
- 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)
360
318
  action.set_active is_active
361
319
  @actiongroup.add_action_with_accel(action, accelerator)
362
- action.signal_connect('toggled', &callback) if callback
320
+ action.signal_connect("toggled", &callback) if callback
363
321
  end
322
+ end
364
323
 
365
- group = nil
366
- first_action = nil
367
- view_as_actions.each do |name, stock_id, label, accelerator, tooltip, value|
368
- action = Gtk::RadioAction.new(name, value, label: label, tooltip: tooltip, stock_id: stock_id)
369
- first_action = action unless group
370
- action.set_group group
371
- group = action.group
372
- @actiongroup.add_action_with_accel(action, accelerator)
373
- end
324
+ def connect_view_actions
325
+ first_action = connect_radio_actions view_as_actions
374
326
 
375
- first_action.signal_connect 'changed' do |_action, current, _user_data|
327
+ first_action.signal_connect "changed" do |_action, current, _user_data|
376
328
  @notebook.page = current.current_value
377
329
  hid = @toolbar_view_as_signal_hid
378
330
  @toolbar_view_as.signal_handler_block(hid) do
379
331
  @toolbar_view_as.active = current.current_value
380
332
  end
381
333
  end
334
+ end
382
335
 
383
- group = nil
384
- first_action = nil
385
- arrange_icons_actions.each do |name, stock_id, label, accelerator, tooltip, value|
386
- action = Gtk::RadioAction.new(name, value, label: label, tooltip: tooltip, stock_id: stock_id)
387
- first_action = action unless group
388
- action.set_group group
389
- group = action.group
390
- @actiongroup.add_action_with_accel(action, accelerator)
391
- end
336
+ def connect_arrange_icons_actions
337
+ first_action = connect_radio_actions arrange_icons_actions
392
338
 
393
- first_action.signal_connect 'changed' do |_action, current, _user_data|
339
+ first_action.signal_connect "changed" do |_action, current, _user_data|
394
340
  @prefs.arrange_icons_mode = current.current_value
395
341
  setup_books_iconview_sorting
396
342
  end
397
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
398
430
  end
399
431
  end
400
432
  end