alexandria-book-collection-manager 0.7.2 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +77 -0
  4. data/.gitignore +5 -1
  5. data/.hound.yml +2 -0
  6. data/.rubocop.yml +87 -37
  7. data/.rubocop_todo.yml +62 -191
  8. data/.simplecov +5 -2
  9. data/CHANGELOG.md +63 -0
  10. data/Gemfile +4 -3
  11. data/INSTALL.md +26 -14
  12. data/README.md +52 -42
  13. data/Rakefile +93 -109
  14. data/TODO.md +9 -1
  15. data/alexandria-book-collection-manager.gemspec +50 -43
  16. data/bin/alexandria +30 -53
  17. data/doc/FAQ +2 -6
  18. data/doc/dependency_decisions.yml +27 -8
  19. data/lib/alexandria.rb +27 -37
  20. data/lib/alexandria/about.rb +50 -50
  21. data/lib/alexandria/book_providers.rb +90 -97
  22. data/lib/alexandria/book_providers/adlibris.rb +41 -76
  23. data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
  24. data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
  25. data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
  26. data/lib/alexandria/book_providers/douban.rb +26 -42
  27. data/lib/alexandria/book_providers/proxis.rb +44 -55
  28. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  29. data/lib/alexandria/book_providers/siciliano.rb +64 -65
  30. data/lib/alexandria/book_providers/thalia.rb +42 -41
  31. data/lib/alexandria/book_providers/web.rb +15 -33
  32. data/lib/alexandria/book_providers/worldcat.rb +70 -97
  33. data/lib/alexandria/book_providers/z3950.rb +160 -173
  34. data/lib/alexandria/config.rb +1 -1
  35. data/lib/alexandria/console.rb +8 -21
  36. data/lib/alexandria/default_preferences.rb +37 -0
  37. data/lib/alexandria/execution_queue.rb +15 -13
  38. data/lib/alexandria/export_format.rb +47 -0
  39. data/lib/alexandria/export_library.rb +193 -300
  40. data/lib/alexandria/import_library.rb +108 -141
  41. data/lib/alexandria/import_library_csv.rb +43 -46
  42. data/lib/alexandria/library_collection.rb +79 -0
  43. data/lib/alexandria/library_sort_order.rb +45 -0
  44. data/lib/alexandria/library_store.rb +233 -0
  45. data/lib/alexandria/logging.rb +11 -13
  46. data/lib/alexandria/models/book.rb +13 -20
  47. data/lib/alexandria/models/library.rb +81 -353
  48. data/lib/alexandria/net.rb +5 -6
  49. data/lib/alexandria/preferences.rb +73 -87
  50. data/lib/alexandria/scanners.rb +2 -2
  51. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
  52. data/lib/alexandria/scanners/keyboard.rb +8 -8
  53. data/lib/alexandria/smart_library.rb +133 -170
  54. data/lib/alexandria/ui.rb +15 -15
  55. data/lib/alexandria/ui/about_dialog.rb +49 -0
  56. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
  57. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  58. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  59. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  60. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
  61. data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
  62. data/lib/alexandria/ui/builder_base.rb +7 -27
  63. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  64. data/lib/alexandria/ui/callbacks.rb +189 -183
  65. data/lib/alexandria/ui/completion_models.rb +10 -23
  66. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  67. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  68. data/lib/alexandria/ui/dndable.rb +7 -7
  69. data/lib/alexandria/ui/error_dialog.rb +25 -0
  70. data/lib/alexandria/ui/export_dialog.rb +142 -0
  71. data/lib/alexandria/ui/icons.rb +47 -63
  72. data/lib/alexandria/ui/iconview.rb +12 -10
  73. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  74. data/lib/alexandria/ui/import_dialog.rb +157 -0
  75. data/lib/alexandria/ui/init.rb +21 -33
  76. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  77. data/lib/alexandria/ui/libraries_combo.rb +16 -14
  78. data/lib/alexandria/ui/listview.rb +73 -87
  79. data/lib/alexandria/ui/main_app.rb +24 -26
  80. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  81. data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
  82. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
  83. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  84. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  85. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  86. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  87. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  88. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  89. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  90. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
  91. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  92. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  93. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  94. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  95. data/lib/alexandria/ui/sound.rb +11 -13
  96. data/lib/alexandria/ui/ui_manager.rb +236 -251
  97. data/lib/alexandria/undo_manager.rb +1 -0
  98. data/lib/alexandria/version.rb +4 -19
  99. data/lib/alexandria/web_themes.rb +22 -21
  100. data/po/Makefile +2 -2
  101. data/po/cs.po +993 -880
  102. data/po/cy.po +957 -874
  103. data/po/de.po +990 -869
  104. data/po/el.po +989 -869
  105. data/po/es.po +985 -865
  106. data/po/fr.po +986 -870
  107. data/po/ga.po +907 -823
  108. data/po/gl.po +981 -865
  109. data/po/it.po +986 -868
  110. data/po/ja.po +969 -853
  111. data/po/mk.po +983 -863
  112. data/po/nb.po +979 -863
  113. data/po/nl.po +983 -864
  114. data/po/pl.po +1017 -974
  115. data/po/pt.po +988 -861
  116. data/po/pt_BR.po +984 -868
  117. data/po/ru.po +992 -873
  118. data/po/sk.po +987 -869
  119. data/po/sv.po +977 -861
  120. data/po/uk.po +975 -865
  121. data/po/zh_TW.po +976 -860
  122. data/schemas/alexandria.schemas +25 -3
  123. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  124. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  125. data/share/alexandria/glade/main_app__builder.glade +24 -33
  126. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  127. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  128. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  129. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  130. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  131. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  132. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  133. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  134. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  135. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  136. data/spec/alexandria/book_providers_spec.rb +75 -171
  137. data/spec/alexandria/book_spec.rb +12 -10
  138. data/spec/alexandria/console_spec.rb +27 -0
  139. data/spec/alexandria/export_library_spec.rb +130 -0
  140. data/spec/alexandria/library_spec.rb +128 -172
  141. data/spec/alexandria/library_store_spec.rb +37 -0
  142. data/spec/alexandria/preferences_spec.rb +44 -17
  143. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  144. data/spec/alexandria/smart_library_spec.rb +30 -25
  145. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  146. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  148. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  150. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  152. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  153. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  154. data/spec/alexandria/ui/icons_spec.rb +26 -0
  155. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  156. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  157. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  159. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  160. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  161. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  162. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  163. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  164. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  165. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  166. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  167. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  168. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  169. data/spec/alexandria/ui/sound_spec.rb +2 -2
  170. data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
  171. data/spec/end_to_end/basic_run_spec.rb +52 -0
  172. data/spec/spec_helper.rb +65 -33
  173. data/tasks/setup.rb +2 -2
  174. data/tasks/spec.rake +16 -3
  175. data/util/rake/fileinstall.rb +39 -35
  176. data/util/rake/gettextgenerate.rb +7 -7
  177. data/util/rake/omfgenerate.rb +7 -7
  178. metadata +178 -45
  179. data/dogtail/basic_run_test.py +0 -9
  180. data/lib/alexandria/book_providers/deastore.rb +0 -265
  181. data/lib/alexandria/book_providers/mcu.rb +0 -182
  182. data/lib/alexandria/book_providers/renaud.rb +0 -149
  183. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
  184. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
  185. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
  186. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
  187. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  188. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  189. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
  190. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  191. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  192. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
  193. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
  194. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
  195. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  196. data/spec/alexandria/ui/dialogs_spec.rb +0 -96
  197. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  198. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  199. data/spec/alexandria/utilities_spec.rb +0 -52
  200. data/tasks/dogtail.rake +0 -6
@@ -1,171 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (C) 2004-2006 Laurent Sansonetti
4
- # Copyright (C) 2014, 2016 Matijs van Zuijlen
5
- #
6
- # Alexandria is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU General Public License as
8
- # published by the Free Software Foundation; either version 2 of the
9
- # License, or (at your option) any later version.
10
- #
11
- # Alexandria is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public
17
- # License along with Alexandria; see the file COPYING. If not,
18
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
- # Fifth Floor, Boston, MA 02110-1301 USA.
20
-
21
- module Alexandria
22
- module UI
23
- class ConfirmEraseDialog < AlertDialog
24
- include GetText
25
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
26
-
27
- def initialize(parent, filename)
28
- super(parent, _('File already exists'),
29
- Gtk::Stock::DIALOG_QUESTION,
30
- [[Gtk::Stock::CANCEL, :cancel],
31
- [_('_Replace'), :ok]],
32
- _("A file named '%s' already exists. Do you want " \
33
- 'to replace it with the one you are generating?') % filename)
34
- # FIXME: Should accept just :cancel
35
- self.default_response = Gtk::ResponseType::CANCEL
36
- show_all && (@response = run)
37
- destroy
38
- end
39
-
40
- def erase?
41
- @response == :ok
42
- end
43
- end
44
-
45
- class ExportDialog < Gtk::FileChooserDialog
46
- include GetText
47
- extend GetText
48
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
49
-
50
- FORMATS = Alexandria::ExportFormat.all
51
- THEMES = Alexandria::WebTheme.all
52
-
53
- def initialize(parent, library, sort_order)
54
- super(title: _("Export '%s'") % library.name,
55
- action: :save,
56
- buttons: [[Gtk::Stock::HELP, :help],
57
- [Gtk::Stock::CANCEL, :cancel],
58
- [_('_Export'), :accept]])
59
-
60
- self.transient_for = parent
61
- self.current_name = library.name
62
- signal_connect('destroy') { hide }
63
-
64
- @parent = parent
65
- @library = library
66
- @sort_order = sort_order
67
-
68
- preview_image = Gtk::Image.new
69
-
70
- theme_combo = Gtk::ComboBoxText.new
71
- theme_combo.valign = :center
72
- theme_combo.vexpand = false
73
- THEMES.each do |theme|
74
- theme_combo.append_text(theme.name)
75
- end
76
- theme_combo.signal_connect('changed') do
77
- file = THEMES[theme_combo.active].preview_file
78
- preview_image.pixbuf = GdkPixbuf::Pixbuf.new(file: file)
79
- end
80
- theme_combo.active = 0
81
- theme_label = Gtk::Label.new(_('_Theme:'), use_underline: true)
82
- theme_label.xalign = 0
83
- theme_label.mnemonic_widget = theme_combo
84
-
85
- types_combo = Gtk::ComboBoxText.new
86
- types_combo.vexpand = false
87
- types_combo.valign = :center
88
- FORMATS.each do |format|
89
- text = format.name + ' ('
90
- text += if format.ext
91
- '*.' + format.ext
92
- else
93
- _('directory')
94
- end
95
- text += ')'
96
- types_combo.append_text(text)
97
- end
98
- types_combo.active = 0
99
- types_combo.signal_connect('changed') do
100
- visible = FORMATS[types_combo.active].needs_preview?
101
- theme_label.visible = theme_combo.visible = preview_image.visible = visible
102
- end
103
- types_combo.show
104
-
105
- types_label = Gtk::Label.new(_('Export for_mat:'), use_underline: true)
106
- types_label.xalign = 0
107
- types_label.mnemonic_widget = types_combo
108
- types_label.show
109
-
110
- # TODO: Re-design extra widget layout
111
- grid = Gtk::Grid.new
112
- grid.column_spacing = 6
113
- grid.attach types_label, 0, 0, 1, 1
114
- grid.attach types_combo, 1, 0, 1, 1
115
- grid.attach theme_label, 0, 1, 1, 1
116
- grid.attach theme_combo, 1, 1, 1, 1
117
- grid.attach preview_image, 2, 0, 1, 3
118
- set_extra_widget grid
119
-
120
- while ((response = run) != :cancel) &&
121
- (response != :delete_event)
122
-
123
- if response == :help
124
- Alexandria::UI.display_help(self, 'exporting')
125
- else
126
- begin
127
- break if on_export(FORMATS[types_combo.active],
128
- THEMES[theme_combo.active])
129
- rescue => e
130
- raise
131
- ErrorDialog.new(self, _('Export failed'), e.message)
132
- end
133
- end
134
- end
135
- destroy
136
- end
137
-
138
- private
139
-
140
- def on_export(format, theme)
141
- raise NotImplementedError unless @library.respond_to?(format.message)
142
- filename = self.filename
143
- if format.ext
144
- filename += '.' + format.ext if File.extname(filename).empty?
145
- if File.exist?(filename)
146
- dialog = ConfirmEraseDialog.new(@parent, filename)
147
- return unless dialog.erase?
148
- FileUtils.rm(filename)
149
- end
150
- args = []
151
- else
152
- if File.exist?(filename)
153
- unless File.directory?(filename)
154
- msg = _("The target, named '%s', is a regular " \
155
- 'file. A directory is needed for this ' \
156
- 'operation. Please select a directory and ' \
157
- 'try again.') % filename
158
- ErrorDialog.new(@parent, _('Not a directory'), msg)
159
- return
160
- end
161
- else
162
- Dir.mkdir(filename)
163
- end
164
- args = [theme]
165
- end
166
- format.invoke(@library, @sort_order, filename, *args)
167
- true
168
- end
169
- end
170
- end
171
- end
@@ -1,196 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (C) 2004-2006 Laurent Sansonetti
4
- # Copyright (C) 2011, 2016 Matijs van Zuijlen
5
- #
6
- # Alexandria is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU General Public License as
8
- # published by the Free Software Foundation; either version 2 of the
9
- # License, or (at your option) any later version.
10
- #
11
- # Alexandria is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public
17
- # License along with Alexandria; see the file COPYING. If not,
18
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
- # Fifth Floor, Boston, MA 02110-1301 USA.
20
-
21
- class Alexandria::ImportFilter
22
- def to_filefilter
23
- filefilter = Gtk::FileFilter.new
24
- filefilter.name = name
25
- patterns.each { |x| filefilter.add_pattern(x) }
26
- filefilter
27
- end
28
- end
29
-
30
- module Alexandria
31
- module UI
32
- class SkipEntryDialog < AlertDialog
33
- include GetText
34
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
35
-
36
- def initialize(parent, message)
37
- super(parent, _('Error while importing'),
38
- Gtk::Stock::DIALOG_QUESTION,
39
- [[Gtk::Stock::CANCEL, :cancel],
40
- [_('_Continue'), :ok]],
41
- message)
42
- puts "Opened SkipEntryDialog #{inspect}" if $DEBUG
43
- self.default_response = Gtk::ResponseType::CANCEL
44
- show_all && (@response = run)
45
- destroy
46
- end
47
-
48
- def continue?
49
- @response == :ok
50
- end
51
- end
52
-
53
- class ImportDialog < Gtk::FileChooserDialog
54
- include GetText
55
- include Logging
56
-
57
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
58
-
59
- FILTERS = Alexandria::ImportFilter.all
60
-
61
- def initialize(parent)
62
- super()
63
- puts 'ImportDialog opened.' if $DEBUG
64
- @destroyed = false
65
- self.title = _('Import a Library')
66
- self.action = :open
67
- self.transient_for = parent
68
- # self.deletable = false
69
- running = false
70
- add_button(Gtk::Stock::HELP, :help)
71
- add_button(Gtk::Stock::CANCEL, :cancel)
72
- import_button = add_button(_('_Import'),
73
- :accept)
74
- import_button.sensitive = false
75
-
76
- signal_connect('destroy') {
77
- if running
78
- @destroyed = true
79
-
80
- else
81
- destroy
82
- end
83
- # self.destroy unless running
84
- }
85
-
86
- filters = {}
87
- FILTERS.each do |filter|
88
- filefilter = filter.to_filefilter
89
- add_filter(filefilter)
90
- puts "Added ImportFilter #{filefilter} -- #{filefilter.name}" if $DEBUG
91
- filters[filefilter] = filter
92
- end
93
-
94
- signal_connect('selection_changed') do
95
- import_button.sensitive = filename && File.file?(filename)
96
- end
97
-
98
- # before adding the (hidden) progress bar, we must re-set the
99
- # packing of the button box (currently packed at the end),
100
- # because the progressbar will be *after* the button box.
101
- buttonbox = child.children.last
102
- child.set_child_packing(buttonbox, pack_type: :start)
103
- child.reorder_child(buttonbox, 1)
104
-
105
- pbar = Gtk::ProgressBar.new
106
- pbar.show_text = true
107
- child.pack_start(pbar, expand: false)
108
-
109
- on_progress = proc do |fraction|
110
- begin
111
- pbar.show unless pbar.visible?
112
- pbar.fraction = fraction
113
- rescue
114
- # TODO: check if destroyed instead...
115
- end
116
- end
117
-
118
- on_error = proc do |message|
119
- SkipEntryDialog.new(parent, message).continue?
120
- end
121
-
122
- exec_queue = ExecutionQueue.new
123
-
124
- while !@destroyed &&
125
- ((response = run) != :cancel) &&
126
- (response != :delete_event)
127
-
128
- if response == :help
129
- Alexandria::UI.display_help(self, 'import-library')
130
- next
131
- end
132
- file = File.basename(filename, '.*')
133
- base = GLib.locale_to_utf8(file)
134
- new_library_name = Library.generate_new_name(
135
- Libraries.instance.all_libraries,
136
- base)
137
-
138
- filter = filters[self.filter]
139
- puts "Going forward with filter: #{filter.name}" if $DEBUG
140
- self.sensitive = false
141
-
142
- filter.on_iterate do |n, total|
143
- unless @destroyed
144
- fraction = n * 1.0 / total
145
- puts "#{inspect} fraction: #{fraction}" if $DEBUG
146
- exec_queue.call(on_progress, fraction)
147
- end
148
- end
149
-
150
- not_cancelled = true
151
- filter.on_error do |message|
152
- not_cancelled = exec_queue.sync_call(on_error, message)
153
- puts "#{inspect} cancel state: #{not_cancelled}" if $DEBUG
154
- end
155
-
156
- library = nil
157
- @bad_isbns = nil
158
- @failed_isbns = nil
159
- thread = Thread.start do
160
- begin
161
- library, @bad_isbns, @failed_isbns = filter.invoke(new_library_name,
162
- filename)
163
- rescue => ex
164
- trace = ex.backtrace.join("\n> ")
165
- log.error { "Import failed: #{ex.message} #{trace}" }
166
- end
167
- end
168
-
169
- while thread.alive? && !@destroyed
170
- # puts "Thread #{thread} still alive."
171
- running = true
172
- exec_queue.iterate
173
- Gtk.main_iteration_do(false)
174
- end
175
-
176
- unless @destroyed
177
- if library
178
- yield(library, @bad_isbns, @failed_isbns)
179
- break
180
- elsif not_cancelled
181
- puts "Raising ErrorDialog because not_cancelled is #{not_cancelled}" if $DEBUG
182
- ErrorDialog.new(parent,
183
- _("Couldn't import the library"),
184
- _('The format of the file you ' \
185
- 'provided is unknown. Please ' \
186
- 'retry with another file.'))
187
- end
188
- pbar.hide
189
- self.sensitive = true
190
- end
191
- end
192
- destroy unless @destroyed
193
- end
194
- end
195
- end
196
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (C) 2007 Joseph Method
4
- #
5
- # Alexandria is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU General Public License as
7
- # published by the Free Software Foundation; either version 2 of the
8
- # License, or (at your option) any later version.
9
- #
10
- # Alexandria is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public
16
- # License along with Alexandria; see the file COPYING. If not,
17
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
18
- # Fifth Floor, Boston, MA 02110-1301 USA.
19
-
20
- module Alexandria
21
- module UI
22
- class ConflictWhileCopyingDialog < AlertDialog
23
- include GetText
24
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
25
-
26
- def initialize(parent, library, book)
27
- super(parent,
28
- format(_("The book '%s' already exists in '%s'. Would you like " \
29
- 'to replace it?'), book.title, library.name),
30
- Gtk::Stock::DIALOG_QUESTION,
31
- [[_('_Skip'), :cancel],
32
- [_('_Replace'), :ok]],
33
- _('If you replace the existing book, its contents will ' \
34
- 'be overwritten.'))
35
- self.default_response = Gtk::ResponseType::CANCEL
36
- show_all && (@response = run)
37
- destroy
38
- end
39
-
40
- def replace?
41
- @response == :ok
42
- end
43
- end
44
-
45
- class ReallyDeleteDialog < AlertDialog
46
- include GetText
47
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
48
-
49
- def initialize(parent, library, books = nil)
50
- # Deleting a library.
51
- if books.nil?
52
- message = _("Are you sure you want to delete '%s'?") % library.name
53
- description = if library.is_a?(SmartLibrary) || library.empty?
54
- nil
55
- else
56
- n_('If you continue, %d book will be deleted.',
57
- 'If you continue, %d books will be deleted.',
58
- library.size) % library.size
59
- end
60
- # Deleting books.
61
- else
62
- message = if books.length == 1
63
- format(_("Are you sure you want to delete '%s' " \
64
- "from '%s'?"), books.first.title, library.name)
65
- else
66
- _('Are you sure you want to delete the ' \
67
- "selected books from '%s'?") % library.name
68
- end
69
- description = nil
70
- end
71
-
72
- super(parent, message, Gtk::Stock::DIALOG_QUESTION,
73
- [[Gtk::Stock::CANCEL, :cancel],
74
- [Gtk::Stock::DELETE, :ok]],
75
- description)
76
-
77
- self.default_response = Gtk::ResponseType::CANCEL
78
- show_all && (@response = run)
79
- destroy
80
- end
81
-
82
- def ok?
83
- @response == :ok
84
- end
85
- end
86
- end
87
- end