alexandria-book-collection-manager 0.7.2 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +77 -0
  4. data/.gitignore +5 -1
  5. data/.hound.yml +2 -0
  6. data/.rubocop.yml +87 -37
  7. data/.rubocop_todo.yml +62 -191
  8. data/.simplecov +5 -2
  9. data/CHANGELOG.md +63 -0
  10. data/Gemfile +4 -3
  11. data/INSTALL.md +26 -14
  12. data/README.md +52 -42
  13. data/Rakefile +93 -109
  14. data/TODO.md +9 -1
  15. data/alexandria-book-collection-manager.gemspec +50 -43
  16. data/bin/alexandria +30 -53
  17. data/doc/FAQ +2 -6
  18. data/doc/dependency_decisions.yml +27 -8
  19. data/lib/alexandria.rb +27 -37
  20. data/lib/alexandria/about.rb +50 -50
  21. data/lib/alexandria/book_providers.rb +90 -97
  22. data/lib/alexandria/book_providers/adlibris.rb +41 -76
  23. data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
  24. data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
  25. data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
  26. data/lib/alexandria/book_providers/douban.rb +26 -42
  27. data/lib/alexandria/book_providers/proxis.rb +44 -55
  28. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  29. data/lib/alexandria/book_providers/siciliano.rb +64 -65
  30. data/lib/alexandria/book_providers/thalia.rb +42 -41
  31. data/lib/alexandria/book_providers/web.rb +15 -33
  32. data/lib/alexandria/book_providers/worldcat.rb +70 -97
  33. data/lib/alexandria/book_providers/z3950.rb +160 -173
  34. data/lib/alexandria/config.rb +1 -1
  35. data/lib/alexandria/console.rb +8 -21
  36. data/lib/alexandria/default_preferences.rb +37 -0
  37. data/lib/alexandria/execution_queue.rb +15 -13
  38. data/lib/alexandria/export_format.rb +47 -0
  39. data/lib/alexandria/export_library.rb +193 -300
  40. data/lib/alexandria/import_library.rb +108 -141
  41. data/lib/alexandria/import_library_csv.rb +43 -46
  42. data/lib/alexandria/library_collection.rb +79 -0
  43. data/lib/alexandria/library_sort_order.rb +45 -0
  44. data/lib/alexandria/library_store.rb +233 -0
  45. data/lib/alexandria/logging.rb +11 -13
  46. data/lib/alexandria/models/book.rb +13 -20
  47. data/lib/alexandria/models/library.rb +81 -353
  48. data/lib/alexandria/net.rb +5 -6
  49. data/lib/alexandria/preferences.rb +73 -87
  50. data/lib/alexandria/scanners.rb +2 -2
  51. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
  52. data/lib/alexandria/scanners/keyboard.rb +8 -8
  53. data/lib/alexandria/smart_library.rb +133 -170
  54. data/lib/alexandria/ui.rb +15 -15
  55. data/lib/alexandria/ui/about_dialog.rb +49 -0
  56. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
  57. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  58. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  59. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  60. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
  61. data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
  62. data/lib/alexandria/ui/builder_base.rb +7 -27
  63. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  64. data/lib/alexandria/ui/callbacks.rb +189 -183
  65. data/lib/alexandria/ui/completion_models.rb +10 -23
  66. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  67. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  68. data/lib/alexandria/ui/dndable.rb +7 -7
  69. data/lib/alexandria/ui/error_dialog.rb +25 -0
  70. data/lib/alexandria/ui/export_dialog.rb +142 -0
  71. data/lib/alexandria/ui/icons.rb +47 -63
  72. data/lib/alexandria/ui/iconview.rb +12 -10
  73. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  74. data/lib/alexandria/ui/import_dialog.rb +157 -0
  75. data/lib/alexandria/ui/init.rb +21 -33
  76. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  77. data/lib/alexandria/ui/libraries_combo.rb +16 -14
  78. data/lib/alexandria/ui/listview.rb +73 -87
  79. data/lib/alexandria/ui/main_app.rb +24 -26
  80. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  81. data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
  82. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
  83. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  84. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  85. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  86. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  87. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  88. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  89. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  90. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
  91. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  92. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  93. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  94. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  95. data/lib/alexandria/ui/sound.rb +11 -13
  96. data/lib/alexandria/ui/ui_manager.rb +236 -251
  97. data/lib/alexandria/undo_manager.rb +1 -0
  98. data/lib/alexandria/version.rb +4 -19
  99. data/lib/alexandria/web_themes.rb +22 -21
  100. data/po/Makefile +2 -2
  101. data/po/cs.po +993 -880
  102. data/po/cy.po +957 -874
  103. data/po/de.po +990 -869
  104. data/po/el.po +989 -869
  105. data/po/es.po +985 -865
  106. data/po/fr.po +986 -870
  107. data/po/ga.po +907 -823
  108. data/po/gl.po +981 -865
  109. data/po/it.po +986 -868
  110. data/po/ja.po +969 -853
  111. data/po/mk.po +983 -863
  112. data/po/nb.po +979 -863
  113. data/po/nl.po +983 -864
  114. data/po/pl.po +1017 -974
  115. data/po/pt.po +988 -861
  116. data/po/pt_BR.po +984 -868
  117. data/po/ru.po +992 -873
  118. data/po/sk.po +987 -869
  119. data/po/sv.po +977 -861
  120. data/po/uk.po +975 -865
  121. data/po/zh_TW.po +976 -860
  122. data/schemas/alexandria.schemas +25 -3
  123. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  124. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  125. data/share/alexandria/glade/main_app__builder.glade +24 -33
  126. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  127. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  128. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  129. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  130. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  131. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  132. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  133. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  134. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  135. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  136. data/spec/alexandria/book_providers_spec.rb +75 -171
  137. data/spec/alexandria/book_spec.rb +12 -10
  138. data/spec/alexandria/console_spec.rb +27 -0
  139. data/spec/alexandria/export_library_spec.rb +130 -0
  140. data/spec/alexandria/library_spec.rb +128 -172
  141. data/spec/alexandria/library_store_spec.rb +37 -0
  142. data/spec/alexandria/preferences_spec.rb +44 -17
  143. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  144. data/spec/alexandria/smart_library_spec.rb +30 -25
  145. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  146. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  148. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  150. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  152. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  153. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  154. data/spec/alexandria/ui/icons_spec.rb +26 -0
  155. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  156. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  157. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  159. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  160. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  161. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  162. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  163. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  164. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  165. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  166. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  167. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  168. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  169. data/spec/alexandria/ui/sound_spec.rb +2 -2
  170. data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
  171. data/spec/end_to_end/basic_run_spec.rb +52 -0
  172. data/spec/spec_helper.rb +65 -33
  173. data/tasks/setup.rb +2 -2
  174. data/tasks/spec.rake +16 -3
  175. data/util/rake/fileinstall.rb +39 -35
  176. data/util/rake/gettextgenerate.rb +7 -7
  177. data/util/rake/omfgenerate.rb +7 -7
  178. metadata +178 -45
  179. data/dogtail/basic_run_test.py +0 -9
  180. data/lib/alexandria/book_providers/deastore.rb +0 -265
  181. data/lib/alexandria/book_providers/mcu.rb +0 -182
  182. data/lib/alexandria/book_providers/renaud.rb +0 -149
  183. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
  184. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
  185. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
  186. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
  187. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  188. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  189. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
  190. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  191. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  192. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
  193. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
  194. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
  195. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  196. data/spec/alexandria/ui/dialogs_spec.rb +0 -96
  197. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  198. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  199. data/spec/alexandria/utilities_spec.rb +0 -52
  200. data/tasks/dogtail.rake +0 -6
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ require "tmpdir"
8
+ require "alexandria/ui/error_dialog"
9
+
10
+ module Alexandria
11
+ module UI
12
+ class NewBookDialogManual < BookPropertiesDialogBase
13
+ include GetText
14
+ extend GetText
15
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
16
+
17
+ TMP_COVER_FILE = File.join(Dir.tmpdir, "tmp_cover")
18
+ def initialize(parent, library, &on_add_cb)
19
+ super(parent, TMP_COVER_FILE)
20
+
21
+ @library = library
22
+ @on_add_cb = on_add_cb
23
+ FileUtils.rm_f(TMP_COVER_FILE)
24
+
25
+ cancel_button = Gtk::Button.new(stock_id: Gtk::Stock::CANCEL)
26
+ cancel_button.signal_connect("clicked") { on_cancel }
27
+ cancel_button.show
28
+ @button_box << cancel_button
29
+
30
+ add_button = Gtk::Button.new(stock_id: Gtk::Stock::ADD)
31
+ add_button.signal_connect("clicked") { on_add }
32
+ add_button.show
33
+ @button_box << add_button
34
+
35
+ help_button = Gtk::Button.new(stock_id: Gtk::Stock::HELP)
36
+ help_button.signal_connect("clicked") { on_help }
37
+ help_button.show
38
+ @button_box << help_button
39
+ @button_box.set_child_secondary(help_button, true)
40
+
41
+ self.rating = Book::DEFAULT_RATING
42
+ self.cover = Icons::BOOK_ICON
43
+
44
+ on_title_changed
45
+ end
46
+
47
+ def on_title_changed
48
+ title = @entry_title.text.strip
49
+ @book_properties_dialog.title = if title.empty?
50
+ _("Adding a Book")
51
+ else
52
+ _("Adding '%s'") % title
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def on_cancel
59
+ @book_properties_dialog.destroy
60
+ end
61
+
62
+ class AddError < StandardError
63
+ end
64
+
65
+ def on_add
66
+ if (title = @entry_title.text.strip).empty?
67
+ raise AddError, _("A title must be provided.")
68
+ end
69
+
70
+ isbn = nil
71
+ if @entry_isbn.text != ""
72
+ isbn = Library.canonicalise_ean(@entry_isbn.text)
73
+ unless isbn
74
+ raise AddError, _("Couldn't validate the EAN/ISBN you provided. Make " \
75
+ "sure it is written correcty, and try again.")
76
+ end
77
+ ary = @library.select { |book| book.ident == isbn }
78
+ unless ary.empty?
79
+ raise AddError, _("The EAN/ISBN you provided is already used in this library.")
80
+ end
81
+ end
82
+ if (publisher = @entry_publisher.text.strip).empty?
83
+ raise AddError, _("A publisher must be provided.")
84
+ end
85
+
86
+ publishing_year = @entry_publish_date.text.to_i
87
+ # TODO: Get rid of this silly requirement
88
+ if (edition = @entry_edition.text.strip).empty?
89
+ raise AddError, _("A binding must be provided.")
90
+ end
91
+
92
+ authors = []
93
+ @treeview_authors.model.each { |_m, _p, i| authors << i[0] }
94
+ if authors.empty?
95
+ raise AddError, _("At least one author must be " \
96
+ "provided.")
97
+ end
98
+ book = Book.new(title, authors, isbn, publisher,
99
+ publishing_year.zero? ? nil : publishing_year,
100
+ edition)
101
+ book.rating = @current_rating
102
+ book.notes = @textview_notes.buffer.text
103
+ book.loaned = @checkbutton_loaned.active?
104
+ book.loaned_to = @entry_loaned_to.text
105
+ # book.loaned_since = Time.at(@date_loaned_since.time)
106
+ book.loaned_since = parse_date(@date_loaned_since.text)
107
+ book.redd = @checkbutton_redd.active?
108
+ book.own = @checkbutton_own.active?
109
+ book.want = @checkbutton_want.active?
110
+ book.tags = @entry_tags.text.split
111
+ @library << book
112
+ @library.save(book)
113
+ if File.exist?(TMP_COVER_FILE) && !@delete_cover_file
114
+ FileUtils.cp(TMP_COVER_FILE, @library.cover(book))
115
+ end
116
+ @on_add_cb.call(book)
117
+ @book_properties_dialog.destroy
118
+ rescue AddError => ex
119
+ ErrorDialog.new(@book_properties_dialog, _("Couldn't add the book"),
120
+ ex.message).display
121
+ end
122
+
123
+ # COPIED from book_properties_dialog_base
124
+ def parse_date(datestring)
125
+ date_format = "%d/%m/%Y"
126
+ begin
127
+ d = Date.strptime(datestring, date_format)
128
+ Time.gm(d.year, d.month, d.day)
129
+ rescue StandardError
130
+ nil
131
+ end
132
+ end
133
+
134
+ def on_help
135
+ Alexandria::UI.display_help(@preferences_dialog, "add-book-manually")
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ require "alexandria/ui/provider_preferences_base_dialog"
8
+
9
+ module Alexandria
10
+ module UI
11
+ class NewProviderDialog < ProviderPreferencesBaseDialog
12
+ include GetText
13
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
14
+
15
+ def initialize(parent)
16
+ super(title: _("New Provider"),
17
+ parent: parent,
18
+ flags: :modal,
19
+ buttons: [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL]])
20
+ @add_button = dialog.add_button(Gtk::Stock::ADD,
21
+ Gtk::ResponseType::ACCEPT)
22
+
23
+ instances = BookProviders.abstract_classes.map(&:new)
24
+ @selected_instance = nil
25
+
26
+ @table = Gtk::Table.new(2, 2)
27
+ dialog.child.pack_start(@table)
28
+
29
+ # Name.
30
+
31
+ label_name = Gtk::Label.new(_("_Name:"))
32
+ label_name.use_underline = true
33
+ label_name.xalign = 0
34
+ @table.attach_defaults(label_name, 0, 1, 0, 1)
35
+
36
+ @entry_name = Gtk::Entry.new
37
+ @entry_name.mandatory = true
38
+ label_name.mnemonic_widget = @entry_name
39
+ @table.attach_defaults(@entry_name, 1, 2, 0, 1)
40
+
41
+ # Type.
42
+
43
+ label_type = Gtk::Label.new(_("_Type:"))
44
+ label_type.use_underline = true
45
+ label_type.xalign = 0
46
+ @table.attach_defaults(label_type, 0, 1, 1, 2)
47
+
48
+ combo_type = Gtk::ComboBoxText.new
49
+ instances.each do |instance|
50
+ combo_type.append_text(instance.name)
51
+ end
52
+ combo_type.signal_connect("changed") do |cb|
53
+ @selected_instance = instances[cb.active]
54
+ fill_table(@table, @selected_instance)
55
+ sensitize
56
+ # FIXME: this should be re-written once we have multiple
57
+ # abstract providers.
58
+ end
59
+ combo_type.active = 0
60
+ label_type.mnemonic_widget = combo_type
61
+ @table.attach_defaults(combo_type, 1, 2, 1, 2)
62
+ end
63
+
64
+ def acquire
65
+ dialog.show_all
66
+ if dialog.run == Gtk::ResponseType::ACCEPT
67
+ @selected_instance.reinitialize(@entry_name.text)
68
+ sync_variables
69
+ else
70
+ @selected_instance = nil
71
+ end
72
+ dialog.destroy
73
+ instance
74
+ end
75
+
76
+ def instance
77
+ @selected_instance
78
+ end
79
+
80
+ private
81
+
82
+ def sensitize
83
+ entries = @table.children.select { |x| x.is_a?(Gtk::Entry) }
84
+ entries.each do |entry|
85
+ entry.signal_connect("changed") do
86
+ sensitive = true
87
+ entries.each do |entry2|
88
+ if entry2.mandatory?
89
+ sensitive = !entry2.text.strip.empty?
90
+ break unless sensitive
91
+ end
92
+ end
93
+ @add_button.sensitive = sensitive
94
+ end
95
+ end
96
+ @add_button.sensitive = false
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ module Alexandria
8
+ module UI
9
+ class NewSmartLibraryDialog < SmartLibraryPropertiesDialogBase
10
+ include GetText
11
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
12
+
13
+ def initialize(parent)
14
+ super(parent)
15
+
16
+ dialog.add_buttons([Gtk::Stock::CANCEL, :cancel],
17
+ [Gtk::Stock::NEW, :ok])
18
+
19
+ dialog.title = _("New Smart Library")
20
+ # FIXME: Should accept just :cancel
21
+ dialog.default_response = Gtk::ResponseType::CANCEL
22
+ insert_new_rule
23
+ end
24
+
25
+ def acquire
26
+ dialog.show_all
27
+
28
+ result = nil
29
+ while ((response = dialog.run) != Gtk::ResponseType::CANCEL) &&
30
+ (response != Gtk::ResponseType::DELETE_EVENT)
31
+
32
+ case response
33
+ when Gtk::ResponseType::HELP
34
+ handle_help_response
35
+ when Gtk::ResponseType::OK
36
+ result = handle_ok_response
37
+ break if result
38
+ end
39
+ end
40
+
41
+ dialog.destroy
42
+ result
43
+ end
44
+
45
+ private
46
+
47
+ def handle_help_response
48
+ Alexandria::UI.display_help(self, "new-smart-library")
49
+ end
50
+
51
+ def handle_ok_response
52
+ user_confirms_possible_weirdnesses_before_saving? or return
53
+
54
+ rules = smart_library_rules
55
+ basename = smart_library_base_name(rules) || _("Smart Library")
56
+ name = Library.generate_new_name(
57
+ LibraryCollection.instance.all_libraries,
58
+ basename)
59
+ library_store = LibraryCollection.instance.library_store
60
+ SmartLibrary.new(name,
61
+ rules,
62
+ predicate_operator_rule,
63
+ library_store)
64
+ end
65
+
66
+ def smart_library_base_name(rules)
67
+ return unless rules.length == 1
68
+
69
+ value = rules.first.value
70
+ value if value.is_a?(String) && !value.strip.empty?
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,313 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ require "alexandria/scanners/cue_cat"
8
+ require "alexandria/scanners/keyboard"
9
+ require "alexandria/ui/builder_base"
10
+ require "alexandria/ui/provider_preferences_dialog"
11
+ require "alexandria/ui/new_provider_dialog"
12
+
13
+ module Alexandria
14
+ module UI
15
+ class PreferencesDialog < BuilderBase
16
+ include Logging
17
+ include GetText
18
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
19
+
20
+ def initialize(parent, &changed_block)
21
+ super("preferences_dialog__builder.glade", widget_names)
22
+ @preferences_dialog.transient_for = parent
23
+ @changed_block = changed_block
24
+
25
+ @cols = {
26
+ @checkbutton_col_authors => "col_authors_visible",
27
+ @checkbutton_col_isbn => "col_isbn_visible",
28
+ @checkbutton_col_publisher => "col_publisher_visible",
29
+ @checkbutton_col_publish_date => "col_publish_date_visible",
30
+ @checkbutton_col_edition => "col_edition_visible",
31
+ @checkbutton_col_redd => "col_redd_visible",
32
+ @checkbutton_col_own => "col_own_visible",
33
+ @checkbutton_col_want => "col_want_visible",
34
+ @checkbutton_col_rating => "col_rating_visible",
35
+ @checkbutton_col_tags => "col_tags_visible",
36
+ @checkbutton_col_loaned_to => "col_loaned_to_visible"
37
+ }
38
+ @cols.each_pair do |checkbutton, pref_name|
39
+ if checkbutton
40
+ checkbutton.active = Preferences.instance.get_variable(pref_name)
41
+ else
42
+ log.warn do
43
+ "no CheckButton for property #{pref_name} " \
44
+ "(probably conflicting versions of GUI and lib code)"
45
+ end
46
+ end
47
+ end
48
+
49
+ model = Gtk::ListStore.new(String, String, TrueClass, Integer)
50
+ @treeview_providers.model = model
51
+ reload_providers
52
+ model.signal_connect_after("row-changed") { update_priority }
53
+
54
+ renderer = Gtk::CellRendererToggle.new
55
+ renderer.activatable = true
56
+ renderer.signal_connect("toggled") do |_rndrr, path|
57
+ tree_path = Gtk::TreePath.new(path)
58
+ @treeview_providers.selection.select_path(tree_path)
59
+ prov = selected_provider
60
+ if prov
61
+ prov.toggle_enabled
62
+ adjust_selected_provider(prov)
63
+ # reload_providers
64
+ end
65
+ end
66
+
67
+ # renderer.active = true
68
+ column = Gtk::TreeViewColumn.new("Enabled", renderer)
69
+ column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
70
+ value = iter[2]
71
+ rndr.active = value
72
+ end
73
+
74
+ @treeview_providers.append_column(column)
75
+
76
+ renderer = Gtk::CellRendererText.new
77
+ column = Gtk::TreeViewColumn.new("Providers",
78
+ renderer)
79
+ column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
80
+ rndr.markup = iter[0]
81
+ end
82
+ @treeview_providers.append_column(column)
83
+ @treeview_providers.selection
84
+ .signal_connect("changed") { sensitize_providers }
85
+
86
+ @button_prov_setup.sensitive = false
87
+
88
+ @button_prov_up.sensitive =
89
+ @button_prov_down.sensitive = BookProviders.list.length > 1
90
+
91
+ @buttonbox_prov.set_child_secondary(@button_prov_add, true)
92
+ @buttonbox_prov.set_child_secondary(@button_prov_remove, true)
93
+
94
+ if BookProviders.abstract_classes.empty?
95
+ @checkbutton_prov_advanced.sensitive = false
96
+ else
97
+ view_advanced = Preferences.instance.view_advanced_settings
98
+ @checkbutton_prov_advanced.active = true if view_advanced
99
+ end
100
+
101
+ sensitize_providers
102
+ setup_barcode_scanner_tab
103
+ end
104
+
105
+ def show
106
+ @preferences_dialog.show
107
+ end
108
+
109
+ def widget_names
110
+ [:button_prov_add, :button_prov_down, :button_prov_remove,
111
+ :button_prov_setup, :button_prov_up, :buttonbox_prov,
112
+ :checkbutton_col_authors, :checkbutton_col_edition,
113
+ :checkbutton_col_isbn, :checkbutton_col_loaned_to,
114
+ :checkbutton_col_own, :checkbutton_col_publish_date,
115
+ :checkbutton_col_publisher, :checkbutton_col_rating,
116
+ :checkbutton_col_redd, :checkbutton_col_tags,
117
+ :checkbutton_col_want, :checkbutton_prov_advanced,
118
+ :preferences_dialog, :treeview_providers,
119
+ :scanner_device_type, :use_scanning_sound, :use_scan_sound]
120
+ end
121
+
122
+ def setup_barcode_scanner_tab
123
+ @scanner_device_model = Gtk::ListStore.new(String, String)
124
+ chosen_scanner_name = Preferences.instance.barcode_scanner
125
+ index = 0
126
+ @scanner_device_type.model = @scanner_device_model
127
+ renderer = Gtk::CellRendererText.new
128
+ @scanner_device_type.pack_start(renderer, true)
129
+ @scanner_device_type.add_attribute(renderer, "text", 0)
130
+
131
+ Alexandria::Scanners.each_scanner do |scanner|
132
+ iter = @scanner_device_model.append
133
+ iter[0] = scanner.display_name
134
+ iter[1] = scanner.name
135
+ @scanner_device_type.active = index if chosen_scanner_name == scanner.name
136
+ index += 1
137
+ end
138
+
139
+ @use_scanning_sound.active = Preferences.instance.play_scanning_sound
140
+ @use_scan_sound.active = Preferences.instance.play_scan_sound
141
+ end
142
+
143
+ def event_is_right_click(event)
144
+ (event.event_type == :button_press) && (event.button == 3)
145
+ end
146
+
147
+ def prefs_empty(prefs)
148
+ prefs.empty? || ((prefs.size == 1) && (prefs.first.name == "enabled"))
149
+ end
150
+
151
+ def on_provider_setup
152
+ provider = selected_provider
153
+ unless prefs_empty(provider.prefs)
154
+ ProviderPreferencesDialog.new(@preferences_dialog, provider).acquire
155
+ end
156
+ end
157
+
158
+ def on_provider_up
159
+ iter = @treeview_providers.selection.selected
160
+ previous_path = iter.path
161
+ previous_path.prev!
162
+ model = @treeview_providers.model
163
+ model.move_after(model.get_iter(previous_path), iter)
164
+ sensitize_providers
165
+ update_priority
166
+ end
167
+
168
+ def on_provider_down
169
+ iter = @treeview_providers.selection.selected
170
+ next_iter = iter.dup
171
+ next_iter.next!
172
+ @treeview_providers.model.move_after(iter, next_iter)
173
+ sensitize_providers
174
+ update_priority
175
+ end
176
+
177
+ def on_provider_advanced_toggled(checkbutton)
178
+ on = checkbutton.active?
179
+ Preferences.instance.view_advanced_settings = on
180
+ @button_prov_add.visible = @button_prov_remove.visible = on
181
+ end
182
+
183
+ def on_provider_add
184
+ provider = NewProviderDialog.new(@preferences_dialog).acquire
185
+ return unless provider
186
+
187
+ BookProviders.instance.update_priority
188
+ reload_providers
189
+ end
190
+
191
+ def on_scanner_device_type(_combo)
192
+ iter = @scanner_device_type.active_iter
193
+ Preferences.instance.barcode_scanner = iter[1] if iter && iter[1]
194
+ end
195
+
196
+ def on_use_scanning_sound(checkbox)
197
+ Preferences.instance.play_scanning_sound = checkbox.active?
198
+ end
199
+
200
+ def on_use_scan_sound(checkbox)
201
+ Preferences.instance.play_scan_sound = checkbox.active?
202
+ end
203
+
204
+ def on_provider_remove
205
+ provider = selected_provider
206
+ dialog = AlertDialog.new(@main_app,
207
+ _("Are you sure you want to " \
208
+ "permanently delete the provider " \
209
+ "'%s'?") % provider.fullname,
210
+ Gtk::Stock::DIALOG_QUESTION,
211
+ [[Gtk::Stock::CANCEL,
212
+ Gtk::ResponseType::CANCEL],
213
+ [Gtk::Stock::DELETE,
214
+ Gtk::ResponseType::OK]],
215
+ _("If you continue, the provider and " \
216
+ "all of its preferences will be " \
217
+ "permanently deleted."))
218
+ dialog.default_response = Gtk::ResponseType::CANCEL
219
+ dialog.show_all
220
+ if dialog.run == Gtk::ResponseType::OK
221
+ provider.remove
222
+ BookProviders.instance.update_priority
223
+ reload_providers
224
+ end
225
+ dialog.destroy
226
+ end
227
+
228
+ def on_column_toggled(checkbutton)
229
+ raise if @cols[checkbutton].nil?
230
+
231
+ Preferences.instance.set_variable(@cols[checkbutton], checkbutton.active?)
232
+
233
+ @changed_block.call
234
+ end
235
+
236
+ def on_providers_button_press_event(_widget, event)
237
+ # double left click
238
+ on_provider_setup if (event.event_type == :'2button_press') && (event.button == 1)
239
+ end
240
+
241
+ def on_close
242
+ @preferences_dialog.destroy
243
+ Alexandria::Preferences.instance.save!
244
+ end
245
+
246
+ def on_help
247
+ Alexandria::UI.display_help(@preferences_dialog,
248
+ "alexandria-preferences")
249
+ end
250
+
251
+ private
252
+
253
+ def reload_providers
254
+ model = @treeview_providers.model
255
+ model.clear
256
+ BookProviders.list.each_with_index do |x, index|
257
+ iter = model.append
258
+ iter[0] = if x.enabled
259
+ x.fullname
260
+ else
261
+ "<i>#{x.fullname}</i>"
262
+ end
263
+ iter[1] = x.name
264
+ iter[2] = x.enabled
265
+ iter[3] = index
266
+ end
267
+ end
268
+
269
+ def selected_provider
270
+ iter = @treeview_providers.selection.selected
271
+ BookProviders.list.find { |x| x.name == iter[1] } unless iter.nil?
272
+ end
273
+
274
+ def adjust_selected_provider(prov)
275
+ iter = @treeview_providers.selection.selected
276
+ iter[0] = if prov.enabled
277
+ prov.fullname
278
+ else
279
+ "<i>#{prov.fullname}</i>"
280
+ end
281
+ iter[2] = prov.enabled
282
+ end
283
+
284
+ def sensitize_providers
285
+ model = @treeview_providers.model
286
+ sel_iter = @treeview_providers.selection.selected
287
+ if sel_iter.nil?
288
+ # No selection, we are probably called by ListStore#clear
289
+ @button_prov_up.sensitive = false
290
+ @button_prov_down.sensitive = false
291
+ @button_prov_setup.sensitive = false
292
+ @button_prov_remove.sensitive = false
293
+ else
294
+ last_iter = model.get_iter((BookProviders.list.length - 1).to_s)
295
+ @button_prov_up.sensitive = sel_iter != model.iter_first
296
+ @button_prov_down.sensitive = sel_iter != last_iter
297
+ provider = BookProviders.list.find { |x| x.name == sel_iter[1] }
298
+ @button_prov_setup.sensitive = !prefs_empty(provider.prefs)
299
+ @button_prov_remove.sensitive = provider.abstract?
300
+ end
301
+ end
302
+
303
+ def update_priority
304
+ priority = []
305
+ @treeview_providers.model.each do |_model, _path, iter|
306
+ priority << iter[1]
307
+ end
308
+ Preferences.instance.providers_priority = priority
309
+ BookProviders.instance.update_priority
310
+ end
311
+ end
312
+ end
313
+ end