alexandria-book-collection-manager 0.7.1 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +5 -2
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +113 -45
  6. data/.rubocop_todo.yml +82 -170
  7. data/.simplecov +5 -1
  8. data/.travis.yml +45 -0
  9. data/.yardopts +1 -1
  10. data/CHANGELOG.md +60 -0
  11. data/ChangeLog.0 +33 -35
  12. data/Gemfile +6 -5
  13. data/INSTALL.md +164 -0
  14. data/README.md +52 -42
  15. data/Rakefile +95 -109
  16. data/TODO.md +9 -1
  17. data/alexandria-book-collection-manager.gemspec +52 -45
  18. data/bin/alexandria +31 -53
  19. data/doc/AUTHORS +61 -0
  20. data/doc/BUGS +31 -0
  21. data/doc/FAQ +365 -0
  22. data/doc/HACKING +19 -0
  23. data/doc/NEWS +341 -0
  24. data/doc/alexandria.1 +120 -0
  25. data/doc/cuecat_support.rdoc +67 -0
  26. data/doc/dependency_decisions.yml +80 -0
  27. data/lib/alexandria.rb +29 -37
  28. data/lib/alexandria/about.rb +52 -51
  29. data/lib/alexandria/book_providers.rb +94 -101
  30. data/lib/alexandria/book_providers/adlibris.rb +45 -85
  31. data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
  32. data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
  33. data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
  34. data/lib/alexandria/book_providers/douban.rb +29 -51
  35. data/lib/alexandria/book_providers/proxis.rb +42 -59
  36. data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
  37. data/lib/alexandria/book_providers/siciliano.rb +68 -70
  38. data/lib/alexandria/book_providers/thalia.rb +46 -45
  39. data/lib/alexandria/book_providers/web.rb +17 -33
  40. data/lib/alexandria/book_providers/worldcat.rb +74 -102
  41. data/lib/alexandria/book_providers/z3950.rb +170 -174
  42. data/lib/alexandria/config.rb +5 -3
  43. data/lib/alexandria/console.rb +10 -21
  44. data/lib/alexandria/default_preferences.rb +37 -0
  45. data/lib/alexandria/execution_queue.rb +17 -15
  46. data/lib/alexandria/export_format.rb +47 -0
  47. data/lib/alexandria/export_library.rb +188 -302
  48. data/lib/alexandria/import_library.rb +114 -155
  49. data/lib/alexandria/import_library_csv.rb +46 -96
  50. data/lib/alexandria/library_collection.rb +79 -0
  51. data/lib/alexandria/library_sort_order.rb +45 -0
  52. data/lib/alexandria/library_store.rb +233 -0
  53. data/lib/alexandria/logging.rb +15 -19
  54. data/lib/alexandria/models/book.rb +15 -20
  55. data/lib/alexandria/models/library.rb +81 -363
  56. data/lib/alexandria/net.rb +7 -6
  57. data/lib/alexandria/preferences.rb +73 -91
  58. data/lib/alexandria/scanners.rb +4 -2
  59. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
  60. data/lib/alexandria/scanners/keyboard.rb +10 -8
  61. data/lib/alexandria/smart_library.rb +135 -171
  62. data/lib/alexandria/ui.rb +17 -15
  63. data/lib/alexandria/ui/about_dialog.rb +49 -0
  64. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
  65. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  66. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  67. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
  68. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
  69. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
  70. data/lib/alexandria/ui/builder_base.rb +9 -27
  71. data/lib/alexandria/ui/callbacks.rb +188 -186
  72. data/lib/alexandria/ui/columns.rb +2 -0
  73. data/lib/alexandria/ui/completion_models.rb +12 -23
  74. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  75. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  76. data/lib/alexandria/ui/dndable.rb +10 -8
  77. data/lib/alexandria/ui/error_dialog.rb +25 -0
  78. data/lib/alexandria/ui/export_dialog.rb +139 -0
  79. data/lib/alexandria/ui/icons.rb +49 -65
  80. data/lib/alexandria/ui/iconview.rb +15 -13
  81. data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
  82. data/lib/alexandria/ui/import_dialog.rb +157 -0
  83. data/lib/alexandria/ui/init.rb +23 -33
  84. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  85. data/lib/alexandria/ui/libraries_combo.rb +18 -14
  86. data/lib/alexandria/ui/listview.rb +77 -88
  87. data/lib/alexandria/ui/main_app.rb +26 -26
  88. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  89. data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
  90. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
  91. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  92. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  93. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  94. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  95. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  96. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  97. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  98. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
  99. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  100. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  101. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
  102. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  103. data/lib/alexandria/ui/sound.rb +13 -13
  104. data/lib/alexandria/ui/ui_manager.rb +262 -283
  105. data/lib/alexandria/undo_manager.rb +3 -0
  106. data/lib/alexandria/version.rb +6 -19
  107. data/lib/alexandria/web_themes.rb +24 -21
  108. data/po/Makefile +2 -2
  109. data/po/cs.po +993 -880
  110. data/po/cy.po +957 -874
  111. data/po/de.po +990 -869
  112. data/po/el.po +989 -869
  113. data/po/es.po +985 -865
  114. data/po/fr.po +986 -870
  115. data/po/ga.po +907 -823
  116. data/po/gl.po +981 -865
  117. data/po/it.po +986 -868
  118. data/po/ja.po +969 -853
  119. data/po/mk.po +983 -863
  120. data/po/nb.po +979 -863
  121. data/po/nl.po +983 -864
  122. data/po/pl.po +1020 -969
  123. data/po/pt.po +988 -861
  124. data/po/pt_BR.po +984 -868
  125. data/po/ru.po +992 -873
  126. data/po/sk.po +987 -869
  127. data/po/sv.po +977 -861
  128. data/po/uk.po +975 -865
  129. data/po/zh_TW.po +976 -860
  130. data/schemas/alexandria.schemas +25 -3
  131. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  132. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  133. data/share/alexandria/glade/main_app__builder.glade +24 -33
  134. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  135. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  136. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  137. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  138. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  139. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  140. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  141. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  142. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  143. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  144. data/spec/alexandria/book_providers_spec.rb +77 -210
  145. data/spec/alexandria/book_spec.rb +16 -12
  146. data/spec/alexandria/console_spec.rb +27 -0
  147. data/spec/alexandria/export_library_spec.rb +130 -0
  148. data/spec/alexandria/library_spec.rb +130 -172
  149. data/spec/alexandria/library_store_spec.rb +37 -0
  150. data/spec/alexandria/preferences_spec.rb +46 -17
  151. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  152. data/spec/alexandria/smart_library_spec.rb +32 -25
  153. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  154. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  155. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  156. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  157. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  159. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  160. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  161. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  162. data/spec/alexandria/ui/icons_spec.rb +26 -0
  163. data/spec/alexandria/ui/iconview_spec.rb +9 -21
  164. data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
  165. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  166. data/spec/alexandria/ui/main_app_spec.rb +8 -33
  167. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  168. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  169. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  170. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  171. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  172. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  173. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  174. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  175. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  176. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
  177. data/spec/alexandria/ui/sound_spec.rb +4 -2
  178. data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
  179. data/spec/end_to_end/basic_run_spec.rb +57 -0
  180. data/spec/spec_helper.rb +66 -33
  181. data/tasks/setup.rb +5 -3
  182. data/tasks/spec.rake +18 -3
  183. data/util/rake/fileinstall.rb +38 -40
  184. data/util/rake/gettextgenerate.rb +15 -70
  185. data/util/rake/omfgenerate.rb +10 -10
  186. metadata +176 -60
  187. data/INSTALL.rdoc +0 -148
  188. data/dogtail/basic_run_test.py +0 -9
  189. data/lib/alexandria/book_providers/bol_it.rb +0 -160
  190. data/lib/alexandria/book_providers/deastore.rb +0 -273
  191. data/lib/alexandria/book_providers/ibs_it.rb +0 -147
  192. data/lib/alexandria/book_providers/mcu.rb +0 -169
  193. data/lib/alexandria/book_providers/renaud.rb +0 -140
  194. data/lib/alexandria/book_providers/webster_it.rb +0 -167
  195. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
  196. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
  197. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
  198. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  199. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  200. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
  201. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  202. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  203. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
  204. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
  205. data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
  206. data/spec/alexandria/ui/dialogs_spec.rb +0 -94
  207. data/spec/alexandria/ui/sidepane_spec.rb +0 -27
  208. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
  209. data/spec/alexandria/utilities_spec.rb +0 -50
  210. data/tasks/dogtail.rake +0 -4
@@ -1,578 +0,0 @@
1
- # Copyright (C) 2004-2006 Laurent Sansonetti
2
- # Copyright (C) 2011, 2016 Matijs van Zuijlen
3
- #
4
- # Alexandria is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU General Public License as
6
- # published by the Free Software Foundation; either version 2 of the
7
- # License, or (at your option) any later version.
8
- #
9
- # Alexandria is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public
15
- # License along with Alexandria; see the file COPYING. If not,
16
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
- # Fifth Floor, Boston, MA 02110-1301 USA.
18
-
19
- require 'alexandria/scanners/cuecat'
20
- require 'alexandria/scanners/keyboard'
21
-
22
- class Gtk::Entry
23
- attr_writer :mandatory
24
- def mandatory?
25
- @mandatory
26
- end
27
- end
28
-
29
- module Alexandria
30
- module UI
31
- class ProviderPreferencesBaseDialog < Gtk::Dialog
32
- def initialize(*args)
33
- super(*args)
34
-
35
- self.resizable = false
36
- child.border_width = 12
37
-
38
- @controls = []
39
- end
40
-
41
- def fill_table(table, provider)
42
- i = table.n_rows
43
- table.resize(table.n_rows + provider.prefs.length,
44
- table.n_columns)
45
- table.border_width = 12
46
- table.row_spacings = 6
47
- table.column_spacings = 12
48
-
49
- @controls.clear
50
-
51
- provider.prefs.read.each do |variable|
52
- if variable.name == 'piggyback'
53
- next
54
- # ULTRA-HACK!! for bug #13302
55
- # not displaying the visual choice, as its usually unnecessary
56
- # Either way, this is confusing to the user: FIX
57
- # - Cathal Mc Ginley 2008-02-18
58
- end
59
-
60
- if variable.name == 'enabled'
61
- # also don't display Enabled/Disabled
62
- next
63
- end
64
-
65
- label = Gtk::Label.new('_' + variable.description + ':')
66
- label.use_underline = true
67
- label.xalign = 0
68
- table.attach_defaults(label, 0, 1, i, i + 1)
69
-
70
- if variable.possible_values.nil?
71
- entry = Gtk::Entry.new
72
- entry.text = variable.value.to_s
73
- entry.mandatory = variable.mandatory?
74
- else
75
- entry = Gtk::ComboBoxText.new
76
- variable.possible_values.each do |value|
77
- entry.append_text(value.to_s)
78
- end
79
- index = variable.possible_values.index(variable.value)
80
- entry.active = index
81
- end
82
- label.mnemonic_widget = entry
83
-
84
- @controls << [variable, entry]
85
-
86
- table.attach_defaults(entry, 1, 2, i, i + 1)
87
- i += 1
88
- end
89
- table
90
- end
91
-
92
- def sync_variables
93
- @controls.each do |variable, entry|
94
- variable.new_value = case entry
95
- when Gtk::ComboBox
96
- variable.possible_values[entry.active]
97
- when Gtk::Entry
98
- entry.text
99
- end
100
- end
101
- end
102
- end
103
-
104
- class ProviderPreferencesDialog < ProviderPreferencesBaseDialog
105
- include GetText
106
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
107
-
108
- def initialize(parent, provider)
109
- super(title: _('Preferences for %s') % provider.fullname,
110
- parent: parent,
111
- flags: :modal,
112
- buttons: [[Gtk::Stock::CLOSE, :close]])
113
-
114
- table = Gtk::Table.new(0, 0)
115
- fill_table(table, provider)
116
- child.pack_start(table)
117
-
118
- signal_connect('destroy') { sync_variables }
119
-
120
- show_all
121
- run
122
- destroy
123
- end
124
- end
125
-
126
- class NewProviderDialog < ProviderPreferencesBaseDialog
127
- include GetText
128
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
129
-
130
- def initialize(parent)
131
- super(_('New Provider'),
132
- parent,
133
- Gtk::Dialog::MODAL,
134
- [Gtk::Stock::CANCEL, :cancel])
135
- @add_button = add_button(Gtk::Stock::ADD,
136
- :accept)
137
-
138
- instances = BookProviders.abstract_classes.map(&:new)
139
- @selected_instance = nil
140
-
141
- @table = Gtk::Table.new(2, 2)
142
- vbox.pack_start(@table)
143
-
144
- # Name.
145
-
146
- label_name = Gtk::Label.new(_('_Name:'))
147
- label_name.use_underline = true
148
- label_name.xalign = 0
149
- @table.attach_defaults(label_name, 0, 1, 0, 1)
150
-
151
- entry_name = Gtk::Entry.new
152
- entry_name.mandatory = true
153
- label_name.mnemonic_widget = entry_name
154
- @table.attach_defaults(entry_name, 1, 2, 0, 1)
155
-
156
- # Type.
157
-
158
- label_type = Gtk::Label.new(_('_Type:'))
159
- label_type.use_underline = true
160
- label_type.xalign = 0
161
- @table.attach_defaults(label_type, 0, 1, 1, 2)
162
-
163
- combo_type = Gtk::ComboBox.new
164
- instances.each do |instance|
165
- combo_type.append_text(instance.name)
166
- end
167
- combo_type.signal_connect('changed') do |cb|
168
- @selected_instance = instances[cb.active]
169
- fill_table(@table, @selected_instance)
170
- sensitize
171
- # FIXME: this should be re-written once we have multiple
172
- # abstract providers.
173
- end
174
- combo_type.active = 0
175
- label_type.mnemonic_widget = combo_type
176
- @table.attach_defaults(combo_type, 1, 2, 1, 2)
177
-
178
- show_all
179
- if run == :accept
180
- @selected_instance.reinitialize(entry_name.text)
181
- sync_variables
182
- else
183
- @selected_instance = nil
184
- end
185
- destroy
186
- end
187
-
188
- def instance
189
- @selected_instance
190
- end
191
-
192
- private
193
-
194
- def sensitize
195
- entries = @table.children.select { |x| x.is_a?(Gtk::Entry) }
196
- entries.each do |entry|
197
- entry.signal_connect('changed') do
198
- sensitive = true
199
- entries.each do |entry2|
200
- if entry2.mandatory?
201
- sensitive = !entry2.text.strip.empty?
202
- break unless sensitive
203
- end
204
- end
205
- @add_button.sensitive = sensitive
206
- end
207
- end
208
- @add_button.sensitive = false
209
- end
210
- end
211
-
212
- class PreferencesDialog < BuilderBase
213
- include Alexandria::Logging
214
- include GetText
215
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
216
-
217
- def initialize(parent, &changed_block)
218
- super('preferences_dialog__builder.glade', widget_names)
219
- @preferences_dialog.transient_for = parent
220
- @changed_block = changed_block
221
-
222
- @cols = {
223
- @checkbutton_col_authors => 'col_authors_visible',
224
- @checkbutton_col_isbn => 'col_isbn_visible',
225
- @checkbutton_col_publisher => 'col_publisher_visible',
226
- @checkbutton_col_publish_date => 'col_publish_date_visible',
227
- @checkbutton_col_edition => 'col_edition_visible',
228
- @checkbutton_col_redd => 'col_redd_visible',
229
- @checkbutton_col_own => 'col_own_visible',
230
- @checkbutton_col_want => 'col_want_visible',
231
- @checkbutton_col_rating => 'col_rating_visible',
232
- @checkbutton_col_tags => 'col_tags_visible',
233
- @checkbutton_col_loaned_to => 'col_loaned_to_visible'
234
- }
235
- @cols.each_pair do |checkbutton, pref_name|
236
- if checkbutton
237
- checkbutton.active = Preferences.instance.send(pref_name)
238
- else
239
- log.warn {
240
- "no CheckButton for property #{pref_name} " \
241
- '(probably conflicting versions of GUI and lib code)'
242
- }
243
- end
244
- end
245
-
246
- model = Gtk::ListStore.new(String, String, TrueClass, Integer)
247
- @treeview_providers.model = model
248
- reload_providers
249
- model.signal_connect_after('row-changed') { update_priority }
250
-
251
- renderer = Gtk::CellRendererToggle.new
252
- renderer.activatable = true
253
- renderer.signal_connect('toggled') do |_rndrr, path|
254
- tree_path = Gtk::TreePath.new(path)
255
- @treeview_providers.selection.select_path(tree_path)
256
- prov = selected_provider
257
- if prov
258
- prov.toggle_enabled
259
- adjust_selected_provider(prov)
260
- # reload_providers
261
- end
262
- end
263
-
264
- # renderer.active = true
265
- column = Gtk::TreeViewColumn.new('Enabled', renderer)
266
- column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
267
- value = iter[2]
268
- rndr.active = value
269
- end
270
-
271
- @treeview_providers.append_column(column)
272
-
273
- renderer = Gtk::CellRendererText.new
274
- column = Gtk::TreeViewColumn.new('Providers',
275
- renderer)
276
- # :text => 0)
277
- column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
278
- rndr.markup = iter[0]
279
- # enabled = iter[2]
280
- # unless enabled
281
- # rndr.foreground = "gray"
282
- # end
283
- # rndr.active = value
284
- end
285
- @treeview_providers.append_column(column)
286
- @treeview_providers.selection.signal_connect('changed') \
287
- { sensitize_providers }
288
-
289
- @button_prov_setup.sensitive = false
290
- @button_prov_up.sensitive = @button_prov_down.sensitive = BookProviders.length > 1
291
-
292
- @buttonbox_prov.set_child_secondary(@button_prov_add, true)
293
- @buttonbox_prov.set_child_secondary(@button_prov_remove, true)
294
-
295
- if BookProviders.abstract_classes.empty?
296
- @checkbutton_prov_advanced.sensitive = false
297
- else
298
- view_advanced = Preferences.instance.view_advanced_settings
299
- if view_advanced
300
- @checkbutton_prov_advanced.active = true
301
- end
302
- end
303
-
304
- setup_enable_disable_popup
305
- sensitize_providers
306
- setup_barcode_scanner_tab
307
- end
308
-
309
- def widget_names
310
- [:button_prov_add, :button_prov_down, :button_prov_remove,
311
- :button_prov_setup, :button_prov_up, :buttonbox_prov,
312
- :checkbutton_col_authors, :checkbutton_col_edition,
313
- :checkbutton_col_isbn, :checkbutton_col_loaned_to,
314
- :checkbutton_col_own, :checkbutton_col_publish_date,
315
- :checkbutton_col_publisher, :checkbutton_col_rating,
316
- :checkbutton_col_redd, :checkbutton_col_tags,
317
- :checkbutton_col_want, :checkbutton_prov_advanced,
318
- :preferences_dialog, :treeview_providers,
319
- :scanner_device_type, :use_scanning_sound, :use_scan_sound]
320
- end
321
-
322
- def setup_barcode_scanner_tab
323
- @scanner_device_model = Gtk::ListStore.new(String, String)
324
- chosen_scanner_name = Preferences.instance.barcode_scanner
325
- index = 0
326
- @scanner_device_type.model = @scanner_device_model
327
- renderer = Gtk::CellRendererText.new
328
- @scanner_device_type.pack_start(renderer, true)
329
- @scanner_device_type.add_attribute(renderer, 'text', 0)
330
-
331
- Alexandria::Scanners.each_scanner do |scanner|
332
- iter = @scanner_device_model.append
333
- iter[0] = scanner.display_name
334
- iter[1] = scanner.name
335
- if chosen_scanner_name == scanner.name
336
- @scanner_device_type.active = index
337
- end
338
- index += 1
339
- end
340
-
341
- @use_scanning_sound.active = Preferences.instance.play_scanning_sound
342
- @use_scan_sound.active = Preferences.instance.play_scan_sound
343
- end
344
-
345
- def setup_enable_disable_popup
346
- # New Enable/Disable pop-up menu...
347
- @enable_disable_providers_menu = Gtk::Menu.new
348
- @enable_item = Gtk::MenuItem.new(label: _('Disable Provider'))
349
- @enable_item.signal_connect('activate') {
350
- prov = selected_provider
351
- prov.toggle_enabled
352
- adjust_selected_provider(prov)
353
- }
354
- @enable_disable_providers_menu.append(@enable_item)
355
- @enable_disable_providers_menu.show_all
356
-
357
- @treeview_providers.signal_connect('button_press_event') do |widget, event|
358
- if event_is_right_click(event)
359
- if (path = widget.get_path_at_pos(event.x, event.y))
360
- widget.grab_focus
361
- obj = widget.selection
362
- path = path.first
363
- unless obj.path_is_selected?(path)
364
- widget.unselect_all
365
- obj.select_path(path)
366
- end
367
- sel = widget.selection.selected
368
- if sel
369
- already_enabled = sel[2]
370
- message = already_enabled ? _('Disable Provider') : _('Enable Provider')
371
- @enable_item.label = message
372
- GLib::Idle.add do
373
- @enable_disable_providers_menu.popup(nil, nil, event.button, event.time)
374
- false
375
- end
376
- end
377
- else
378
- puts 'not on a path'
379
- end
380
- end
381
- end
382
-
383
- # Popup the menu on Shift-F10
384
- @treeview_providers.signal_connect('popup_menu') {
385
- selected_prov = @treeview_providers.selection.selected
386
- puts selected_prov.inspect
387
- if selected_prov
388
- GLib::Idle.add do
389
- already_enabled = selected_prov[2]
390
- message = already_enabled ? _('Disable Provider') : _('Enable Provider')
391
- @enable_item.label = message
392
-
393
- @enable_disable_providers_menu.popup(nil, nil, 0, :current_time)
394
- false
395
- end
396
- else
397
- puts 'no action'
398
- end
399
- }
400
- end
401
-
402
- def event_is_right_click(event)
403
- (event.event_type == :button_press) && (event.button == 3)
404
- end
405
-
406
- def prefs_empty(prefs)
407
- prefs.empty? || ((prefs.size == 1) && (prefs.first.name == 'enabled'))
408
- end
409
-
410
- def on_provider_setup
411
- provider = selected_provider
412
- unless prefs_empty(provider.prefs)
413
- ProviderPreferencesDialog.new(@preferences_dialog, provider)
414
- end
415
- end
416
-
417
- def on_provider_up
418
- iter = @treeview_providers.selection.selected
419
- previous_path = iter.path
420
- previous_path.prev!
421
- model = @treeview_providers.model
422
- model.move_after(model.get_iter(previous_path), iter)
423
- sensitize_providers
424
- update_priority
425
- end
426
-
427
- def on_provider_down
428
- iter = @treeview_providers.selection.selected
429
- next_iter = iter.dup
430
- next_iter.next!
431
- @treeview_providers.model.move_after(iter, next_iter)
432
- sensitize_providers
433
- update_priority
434
- end
435
-
436
- def on_provider_advanced_toggled(checkbutton)
437
- on = checkbutton.active?
438
- Preferences.instance.view_advanced_settings = on
439
- @button_prov_add.visible = @button_prov_remove.visible = on
440
- end
441
-
442
- def on_provider_add
443
- dialog = NewProviderDialog.new(@preferences_dialog)
444
- if dialog.instance
445
- BookProviders.update_priority
446
- reload_providers
447
- end
448
- end
449
-
450
- def on_scanner_device_type(_combo)
451
- iter = @scanner_device_type.active_iter
452
- if iter && iter[1]
453
- Preferences.instance.barcode_scanner = iter[1]
454
- end
455
- end
456
-
457
- def on_use_scanning_sound(checkbox)
458
- Preferences.instance.play_scanning_sound = checkbox.active?
459
- end
460
-
461
- def on_use_scan_sound(checkbox)
462
- Preferences.instance.play_scan_sound = checkbox.active?
463
- end
464
-
465
- def on_provider_remove
466
- provider = selected_provider
467
- dialog = AlertDialog.new(@main_app,
468
- _('Are you sure you want to ' \
469
- 'permanently delete the provider ' \
470
- "'%s'?") % provider.fullname,
471
- Gtk::Stock::DIALOG_QUESTION,
472
- [[Gtk::Stock::CANCEL,
473
- :cancel],
474
- [Gtk::Stock::DELETE,
475
- :ok]],
476
- _('If you continue, the provider and ' \
477
- 'all of its preferences will be ' \
478
- 'permanently deleted.'))
479
- dialog.default_response = Gtk::ResponseType::CANCEL
480
- dialog.show_all
481
- if dialog.run == :ok
482
- provider.remove
483
- BookProviders.update_priority
484
- reload_providers
485
- end
486
- dialog.destroy
487
- end
488
-
489
- def on_column_toggled(checkbutton)
490
- raise if @cols[checkbutton].nil?
491
- Preferences.instance.send("#{@cols[checkbutton]}=",
492
- checkbutton.active?)
493
-
494
- @changed_block.call
495
- end
496
-
497
- def on_providers_button_press_event(_widget, event)
498
- # double left click
499
- if (event.event_type == :'2button_press') && (event.button == 1)
500
- on_provider_setup
501
- end
502
- end
503
-
504
- def on_close
505
- @preferences_dialog.destroy
506
- Alexandria::Preferences.instance.save!
507
- end
508
-
509
- def on_help
510
- Alexandria::UI.display_help(@preferences_dialog,
511
- 'alexandria-preferences')
512
- end
513
-
514
- private
515
-
516
- def reload_providers
517
- model = @treeview_providers.model
518
- model.clear
519
- BookProviders.each_with_index do |x, index|
520
- iter = model.append
521
- iter[0] = if x.enabled
522
- x.fullname
523
- else
524
- "<i>#{x.fullname}</i>"
525
- end
526
- iter[1] = x.name
527
- iter[2] = x.enabled
528
- iter[3] = index
529
- end
530
- end
531
-
532
- def selected_provider
533
- iter = @treeview_providers.selection.selected
534
- unless iter.nil?
535
- BookProviders.find { |x| x.name == iter[1] }
536
- end
537
- end
538
-
539
- def adjust_selected_provider(prov)
540
- iter = @treeview_providers.selection.selected
541
- iter[0] = if prov.enabled
542
- prov.fullname
543
- else
544
- "<i>#{prov.fullname}</i>"
545
- end
546
- iter[2] = prov.enabled
547
- end
548
-
549
- def sensitize_providers
550
- model = @treeview_providers.model
551
- sel_iter = @treeview_providers.selection.selected
552
- if sel_iter.nil?
553
- # No selection, we are probably called by ListStore#clear
554
- @button_prov_up.sensitive = false
555
- @button_prov_down.sensitive = false
556
- @button_prov_setup.sensitive = false
557
- @button_prov_remove.sensitive = false
558
- else
559
- last_iter = model.get_iter((BookProviders.length - 1).to_s)
560
- @button_prov_up.sensitive = sel_iter != model.iter_first
561
- @button_prov_down.sensitive = sel_iter != last_iter
562
- provider = BookProviders.find { |x| x.name == sel_iter[1] }
563
- @button_prov_setup.sensitive = !prefs_empty(provider.prefs)
564
- @button_prov_remove.sensitive = provider.abstract?
565
- end
566
- end
567
-
568
- def update_priority
569
- priority = []
570
- @treeview_providers.model.each do |_model, _path, iter|
571
- priority << iter[1]
572
- end
573
- Preferences.instance.providers_priority = priority
574
- BookProviders.update_priority
575
- end
576
- end
577
- end
578
- end