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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/ruby.yml +77 -0
- data/.gitignore +5 -1
- data/.hound.yml +2 -0
- data/.rubocop.yml +87 -37
- data/.rubocop_todo.yml +62 -191
- data/.simplecov +5 -2
- data/CHANGELOG.md +63 -0
- data/Gemfile +4 -3
- data/INSTALL.md +26 -14
- data/README.md +52 -42
- data/Rakefile +93 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +50 -43
- data/bin/alexandria +30 -53
- data/doc/FAQ +2 -6
- data/doc/dependency_decisions.yml +27 -8
- data/lib/alexandria.rb +27 -37
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +90 -97
- data/lib/alexandria/book_providers/adlibris.rb +41 -76
- data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
- data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
- data/lib/alexandria/book_providers/douban.rb +26 -42
- data/lib/alexandria/book_providers/proxis.rb +44 -55
- data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
- data/lib/alexandria/book_providers/siciliano.rb +64 -65
- data/lib/alexandria/book_providers/thalia.rb +42 -41
- data/lib/alexandria/book_providers/web.rb +15 -33
- data/lib/alexandria/book_providers/worldcat.rb +70 -97
- data/lib/alexandria/book_providers/z3950.rb +160 -173
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +8 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +15 -13
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +193 -300
- data/lib/alexandria/import_library.rb +108 -141
- data/lib/alexandria/import_library_csv.rb +43 -46
- data/lib/alexandria/library_collection.rb +79 -0
- data/lib/alexandria/library_sort_order.rb +45 -0
- data/lib/alexandria/library_store.rb +233 -0
- data/lib/alexandria/logging.rb +11 -13
- data/lib/alexandria/models/book.rb +13 -20
- data/lib/alexandria/models/library.rb +81 -353
- data/lib/alexandria/net.rb +5 -6
- data/lib/alexandria/preferences.rb +73 -87
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
- data/lib/alexandria/scanners/keyboard.rb +8 -8
- data/lib/alexandria/smart_library.rb +133 -170
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
- data/lib/alexandria/ui/alert_dialog.rb +64 -0
- data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
- data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
- data/lib/alexandria/ui/builder_base.rb +7 -27
- data/lib/alexandria/ui/calendar_popup.rb +58 -0
- data/lib/alexandria/ui/callbacks.rb +189 -183
- data/lib/alexandria/ui/completion_models.rb +10 -23
- data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
- data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
- data/lib/alexandria/ui/dndable.rb +7 -7
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/export_dialog.rb +142 -0
- data/lib/alexandria/ui/icons.rb +47 -63
- data/lib/alexandria/ui/iconview.rb +12 -10
- data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +21 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +16 -14
- data/lib/alexandria/ui/listview.rb +73 -87
- data/lib/alexandria/ui/main_app.rb +24 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
- data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
- data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
- data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
- data/lib/alexandria/ui/preferences_dialog.rb +313 -0
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
- data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
- data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
- data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +11 -13
- data/lib/alexandria/ui/ui_manager.rb +236 -251
- data/lib/alexandria/undo_manager.rb +1 -0
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +22 -21
- data/po/Makefile +2 -2
- data/po/cs.po +993 -880
- data/po/cy.po +957 -874
- data/po/de.po +990 -869
- data/po/el.po +989 -869
- data/po/es.po +985 -865
- data/po/fr.po +986 -870
- data/po/ga.po +907 -823
- data/po/gl.po +981 -865
- data/po/it.po +986 -868
- data/po/ja.po +969 -853
- data/po/mk.po +983 -863
- data/po/nb.po +979 -863
- data/po/nl.po +983 -864
- data/po/pl.po +1017 -974
- data/po/pt.po +988 -861
- data/po/pt_BR.po +984 -868
- data/po/ru.po +992 -873
- data/po/sk.po +987 -869
- data/po/sv.po +977 -861
- data/po/uk.po +975 -865
- data/po/zh_TW.po +976 -860
- data/schemas/alexandria.schemas +25 -3
- data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
- data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
- data/share/alexandria/glade/main_app__builder.glade +24 -33
- data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
- data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
- data/share/gnome/help/alexandria/C/introduction.xml +0 -8
- data/share/gnome/help/alexandria/C/searching.xml +1 -1
- data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
- data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
- data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +75 -171
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +128 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/preferences_spec.rb +44 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +30 -25
- data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +7 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +7 -34
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
- data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
- data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
- data/spec/alexandria/ui/sound_spec.rb +2 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
- data/spec/end_to_end/basic_run_spec.rb +52 -0
- data/spec/spec_helper.rb +65 -33
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +16 -3
- data/util/rake/fileinstall.rb +39 -35
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +178 -45
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/deastore.rb +0 -265
- data/lib/alexandria/book_providers/mcu.rb +0 -182
- data/lib/alexandria/book_providers/renaud.rb +0 -149
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
- data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -96
- data/spec/alexandria/ui/sidepane_spec.rb +0 -29
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
- data/spec/alexandria/utilities_spec.rb +0 -52
- data/tasks/dogtail.rake +0 -6
@@ -1,62 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright (C) 2011, 2015, 2016 Matijs van Zuijlen
|
3
|
+
# This file is part of Alexandria.
|
5
4
|
#
|
6
|
-
#
|
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.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
20
6
|
|
21
|
-
require
|
7
|
+
require "gdk_pixbuf2"
|
8
|
+
require "alexandria/ui/builder_base"
|
9
|
+
require "alexandria/ui/error_dialog"
|
10
|
+
require "alexandria/ui/keep_bad_isbn_dialog"
|
22
11
|
|
23
12
|
module Alexandria
|
24
13
|
class DuplicateBookException < NameError
|
25
14
|
end
|
26
15
|
|
27
16
|
module UI
|
28
|
-
class KeepBadISBNDialog < AlertDialog
|
29
|
-
include GetText
|
30
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
|
31
|
-
|
32
|
-
def initialize(parent, book)
|
33
|
-
super(parent, _("Invalid ISBN '%s'") % book.isbn,
|
34
|
-
Gtk::Stock::DIALOG_QUESTION,
|
35
|
-
[[Gtk::Stock::CANCEL, :cancel],
|
36
|
-
[_('_Keep'), :ok]],
|
37
|
-
_("The book titled '%s' has an invalid ISBN, but still " \
|
38
|
-
'exists in the providers libraries. Do you want to ' \
|
39
|
-
'keep the book but change the ISBN or cancel the addition?') % book.title)
|
40
|
-
self.default_response = Gtk::ResponseType::OK
|
41
|
-
show_all && (@response = run)
|
42
|
-
destroy
|
43
|
-
end
|
44
|
-
|
45
|
-
def keep?
|
46
|
-
@response == :ok
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
17
|
class NewBookDialog < BuilderBase
|
51
18
|
include Logging
|
52
19
|
include GetText
|
53
20
|
extend GetText
|
54
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
21
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
55
22
|
@@last_criterion_was_not_isbn = false
|
56
23
|
|
57
24
|
def initialize(parent, selected_library = nil, &block)
|
58
|
-
super(
|
59
|
-
log.info {
|
25
|
+
super("new_book_dialog__builder.glade", widget_names)
|
26
|
+
log.info { "New Book Dialog" }
|
60
27
|
@new_book_dialog.transient_for = @parent = parent
|
61
28
|
@block = block
|
62
29
|
@destroyed = false
|
@@ -65,32 +32,33 @@ module Alexandria
|
|
65
32
|
@progressbar.hide
|
66
33
|
end
|
67
34
|
|
35
|
+
def show
|
36
|
+
@new_book_dialog.show
|
37
|
+
end
|
38
|
+
|
68
39
|
def widget_names
|
69
|
-
[:
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:cellrenderertext2, :eventbox_entry_search, :entry_search,
|
75
|
-
:button_find, :scrolledwindow, :treeview_results,
|
76
|
-
:title_radiobutton, :isbn_radiobutton, :progressbar]
|
40
|
+
[:new_book_dialog, :button_add, :button_cancel, :button_find,
|
41
|
+
:button_help, :combo_libraries, :combo_search, :entry_isbn,
|
42
|
+
:entry_search, :eventbox_combo_search, :eventbox_entry_isbn,
|
43
|
+
:eventbox_entry_search, :isbn_radiobutton, :keep_open, :progressbar,
|
44
|
+
:scrolledwindow, :title_radiobutton, :treeview_results]
|
77
45
|
end
|
78
46
|
|
79
47
|
def setup_dialog_gui
|
80
|
-
libraries =
|
48
|
+
libraries = LibraryCollection.instance.all_regular_libraries
|
81
49
|
@selected_library = libraries.first if @selected_library.is_a?(SmartLibrary)
|
82
50
|
@combo_libraries.populate_with_libraries(libraries,
|
83
51
|
@selected_library)
|
84
52
|
|
85
53
|
@treeview_results.model = Gtk::ListStore.new(String, String,
|
86
54
|
GdkPixbuf::Pixbuf)
|
87
|
-
@treeview_results.selection.mode =
|
88
|
-
@treeview_results.selection.signal_connect(
|
55
|
+
@treeview_results.selection.mode = :multiple
|
56
|
+
@treeview_results.selection.signal_connect("changed") do
|
89
57
|
@button_add.sensitive = true
|
90
58
|
end
|
91
59
|
|
92
60
|
renderer = Gtk::CellRendererPixbuf.new
|
93
|
-
col = Gtk::TreeViewColumn.new(
|
61
|
+
col = Gtk::TreeViewColumn.new("", renderer)
|
94
62
|
col.set_cell_data_func(renderer) do |_column, cell, _model, iter|
|
95
63
|
pixbuf = iter[2]
|
96
64
|
max_height = 25
|
@@ -104,7 +72,7 @@ module Alexandria
|
|
104
72
|
end
|
105
73
|
@treeview_results.append_column(col)
|
106
74
|
|
107
|
-
col = Gtk::TreeViewColumn.new(
|
75
|
+
col = Gtk::TreeViewColumn.new("", Gtk::CellRendererText.new,
|
108
76
|
text: 0)
|
109
77
|
@treeview_results.append_column(col)
|
110
78
|
|
@@ -123,14 +91,14 @@ module Alexandria
|
|
123
91
|
@find_thread = nil
|
124
92
|
@image_thread = nil
|
125
93
|
|
126
|
-
@new_book_dialog.signal_connect(
|
94
|
+
@new_book_dialog.signal_connect("destroy") do
|
127
95
|
@new_book_dialog.destroy
|
128
96
|
@destroyed = true
|
129
|
-
|
97
|
+
end
|
130
98
|
end
|
131
99
|
|
132
100
|
def on_criterion_toggled(item)
|
133
|
-
log.debug {
|
101
|
+
log.debug { "on_criterion_toggled" }
|
134
102
|
return unless item.active?
|
135
103
|
|
136
104
|
# There used to be a strange effect here (pre SVN r1022).
|
@@ -175,19 +143,19 @@ module Alexandria
|
|
175
143
|
|
176
144
|
def on_changed(entry)
|
177
145
|
ok = !entry.text.strip.empty?
|
178
|
-
decode_cuecat
|
146
|
+
decode_cuecat(@entry_isbn) if entry == @entry_isbn
|
179
147
|
(entry == @entry_isbn ? @button_add : @button_find).sensitive = ok
|
180
148
|
end
|
181
149
|
|
182
150
|
def image_error_dialog(error)
|
183
151
|
ErrorDialog.new(
|
184
152
|
@parent,
|
185
|
-
_(
|
153
|
+
_("A problem occurred while downloading images"),
|
186
154
|
error)
|
187
155
|
end
|
188
156
|
|
189
157
|
def get_images_async
|
190
|
-
log.info {
|
158
|
+
log.info { "get_images_async" }
|
191
159
|
@images = {}
|
192
160
|
@image_error = nil
|
193
161
|
@image_thread = Thread.new do
|
@@ -197,7 +165,7 @@ module Alexandria
|
|
197
165
|
uri = result[1]
|
198
166
|
if uri
|
199
167
|
if URI.parse(uri).scheme.nil?
|
200
|
-
File.open(uri,
|
168
|
+
File.open(uri, "r") do |io|
|
201
169
|
@images[i] = io.read
|
202
170
|
end
|
203
171
|
else
|
@@ -205,33 +173,32 @@ module Alexandria
|
|
205
173
|
end
|
206
174
|
end
|
207
175
|
end
|
208
|
-
rescue =>
|
209
|
-
@image_error =
|
176
|
+
rescue StandardError => ex
|
177
|
+
@image_error = ex.message
|
210
178
|
end
|
211
179
|
end
|
212
180
|
|
213
181
|
GLib::Timeout.add(100) do
|
214
182
|
if @image_error
|
215
|
-
image_error_dialog(@image_error)
|
183
|
+
image_error_dialog(@image_error).display
|
216
184
|
else
|
217
185
|
@images.each_pair do |key, value|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
raise format('Iter is invalid! %s', iter)
|
227
|
-
end
|
228
|
-
iter[2] = pixbuf # I bet you this is it!
|
186
|
+
loader = GdkPixbuf::PixbufLoader.new
|
187
|
+
loader.last_write(value)
|
188
|
+
pixbuf = loader.pixbuf
|
189
|
+
|
190
|
+
if pixbuf.width > 1
|
191
|
+
iter = @treeview_results.model.get_iter(key.to_s)
|
192
|
+
unless @treeview_results.model.iter_is_valid?(iter)
|
193
|
+
raise format(_("Iter is invalid! %s"), iter)
|
229
194
|
end
|
230
195
|
|
231
|
-
|
232
|
-
rescue => e
|
233
|
-
image_error_dialog(e.message)
|
196
|
+
iter[2] = pixbuf # I bet you this is it!
|
234
197
|
end
|
198
|
+
|
199
|
+
@images.delete(key)
|
200
|
+
rescue StandardError => ex
|
201
|
+
image_error_dialog(ex.message).display
|
235
202
|
end
|
236
203
|
end
|
237
204
|
|
@@ -247,7 +214,7 @@ module Alexandria
|
|
247
214
|
end
|
248
215
|
|
249
216
|
def on_find
|
250
|
-
log.info {
|
217
|
+
log.info { "on_find" }
|
251
218
|
mode = case @combo_search.active
|
252
219
|
when 0
|
253
220
|
BookProviders::SEARCH_BY_TITLE
|
@@ -257,23 +224,13 @@ module Alexandria
|
|
257
224
|
BookProviders::SEARCH_BY_KEYWORD
|
258
225
|
end
|
259
226
|
|
260
|
-
# @progressbar.show
|
261
|
-
# progress_pulsing = GLib::Timeout.add(100) do
|
262
|
-
# if @destroyed
|
263
|
-
# false
|
264
|
-
# else
|
265
|
-
# @progressbar.pulse
|
266
|
-
# true
|
267
|
-
# end
|
268
|
-
# end
|
269
|
-
|
270
227
|
criterion = @entry_search.text.strip
|
271
228
|
@treeview_results.model.clear
|
272
|
-
log.info
|
273
|
-
format(
|
229
|
+
log.info do
|
230
|
+
format("TreeStore Model: %s columns; ref_counts: %s",
|
274
231
|
@treeview_results.model.n_columns,
|
275
232
|
@treeview_results.model.ref_count)
|
276
|
-
|
233
|
+
end
|
277
234
|
|
278
235
|
@find_error = nil
|
279
236
|
@results = nil
|
@@ -290,8 +247,8 @@ module Alexandria
|
|
290
247
|
@results = Alexandria::BookProviders.search(criterion, mode)
|
291
248
|
|
292
249
|
log.info { "got #{@results.length} results" }
|
293
|
-
rescue =>
|
294
|
-
@find_error =
|
250
|
+
rescue StandardError => ex
|
251
|
+
@find_error = ex.message
|
295
252
|
ensure
|
296
253
|
Alexandria::BookProviders.instance.delete_observer(self)
|
297
254
|
# notify_end_add_by_isbn
|
@@ -306,25 +263,13 @@ module Alexandria
|
|
306
263
|
|
307
264
|
# Err... continue == false if @find_error
|
308
265
|
continue = if @find_error
|
309
|
-
ErrorDialog.new(@
|
310
|
-
_(
|
311
|
-
@find_error)
|
266
|
+
ErrorDialog.new(@new_book_dialog,
|
267
|
+
_("Unable to find matches for your search"),
|
268
|
+
@find_error).display
|
312
269
|
false
|
313
270
|
elsif @results
|
314
271
|
log.info { "Got results: #{@results[0]}..." }
|
315
|
-
@results.
|
316
|
-
s = format(_('%s, by %s'), book.title, book.authors.join(', '))
|
317
|
-
similar_books = @results.find { |book2, _cover2|
|
318
|
-
(book.title == book2.title) &&
|
319
|
-
(book.authors == book2.authors)
|
320
|
-
}
|
321
|
-
s += " (#{book.edition}, #{book.publisher})" if similar_books.length > 1
|
322
|
-
log.info { format('Copying %s into tree view.', book.title) }
|
323
|
-
iter = @treeview_results.model.append
|
324
|
-
iter[0] = s
|
325
|
-
iter[1] = book.ident
|
326
|
-
iter[2] = Icons::BOOK
|
327
|
-
end
|
272
|
+
copy_results_to_treeview_model(@results, @treeview_results.model)
|
328
273
|
|
329
274
|
# Kick off the image download thread.
|
330
275
|
if @find_thread.alive?
|
@@ -343,31 +288,42 @@ module Alexandria
|
|
343
288
|
# continue == false if @find_error OR if results are returned
|
344
289
|
# timeout ends if continue is false!
|
345
290
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
# @progressbar.hide
|
351
|
-
notify_end_add_by_isbn
|
352
|
-
@button_add.sensitive = false
|
353
|
-
end
|
354
|
-
end
|
291
|
+
# @find_thread.alive? happens after find_thread is done
|
292
|
+
unless continue || @find_thread.alive? || @destroyed
|
293
|
+
notify_end_add_by_isbn
|
294
|
+
@button_add.sensitive = false
|
355
295
|
end
|
356
296
|
|
357
297
|
continue # timeout loop condition
|
358
298
|
end
|
359
299
|
end
|
360
300
|
|
361
|
-
def
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
301
|
+
def copy_results_to_treeview_model(results, model)
|
302
|
+
results.each do |book, _cover_url|
|
303
|
+
s = format(_("%s, by %s"), book.title, book.authors.join(", "))
|
304
|
+
similar_books = results.find do |book2, _cover2|
|
305
|
+
(book.title == book2.title) &&
|
306
|
+
(book.authors == book2.authors)
|
307
|
+
end
|
308
|
+
s += " (#{book.edition}, #{book.publisher})" if similar_books.length > 1
|
309
|
+
log.info { format(_("Copying %s into tree view."), book.title) }
|
310
|
+
iter = model.append
|
311
|
+
iter[0] = s
|
312
|
+
iter[1] = book.ident
|
313
|
+
iter[2] = Icons::BOOK
|
368
314
|
end
|
369
315
|
end
|
370
316
|
|
317
|
+
def decode_cuecat(entry)
|
318
|
+
return unless entry.text =~ /^\..*?\..*?\.(.*?)\.$/
|
319
|
+
|
320
|
+
tmp = Regexp.last_match[1].tr("a-zA-Z0-9+-", " -_")
|
321
|
+
tmp = ((32 + tmp.length * 3 / 4).to_i.chr << tmp).unpack1("u")
|
322
|
+
tmp.chomp!("\000")
|
323
|
+
entry.text = tmp.gsub!(/./) { |c| (c[0] ^ 67).chr }
|
324
|
+
entry.text = "Bad scan result" if entry.text.count("^ -~") > 0
|
325
|
+
end
|
326
|
+
|
371
327
|
def on_results_button_press_event(_widget, event)
|
372
328
|
# double left click
|
373
329
|
on_add if (event.event_type == :'2button_press') && (event.button == 1)
|
@@ -377,10 +333,10 @@ module Alexandria
|
|
377
333
|
# Perform the ISBN search via the providers.
|
378
334
|
isbn = begin
|
379
335
|
Library.canonicalise_isbn(@entry_isbn.text)
|
380
|
-
rescue
|
336
|
+
rescue StandardError
|
381
337
|
raise _("Couldn't validate the EAN/ISBN you " \
|
382
|
-
|
383
|
-
|
338
|
+
"provided. Make sure it is written " \
|
339
|
+
"correctly, and try again.")
|
384
340
|
end
|
385
341
|
assert_not_exist(library, @entry_isbn.text)
|
386
342
|
@button_add.sensitive = false
|
@@ -392,24 +348,20 @@ module Alexandria
|
|
392
348
|
# MAJOR HACK, add this again...
|
393
349
|
Alexandria::BookProviders.instance.add_observer(self)
|
394
350
|
book, cover_url = Alexandria::BookProviders.isbn_search(isbn)
|
395
|
-
# prov = FakeBookProviders.new()
|
396
|
-
# prov.add_observer(self)
|
397
|
-
# book, cover_url = prov.isbn_search(isbn)
|
398
351
|
|
399
352
|
notify_end_add_by_isbn
|
400
353
|
|
401
354
|
if book
|
402
|
-
|
403
|
-
puts "adding book #{book} to library"
|
355
|
+
log.debug { "adding book #{book} to library" }
|
404
356
|
add_book_to_library(library, book, cover_url)
|
405
|
-
@entry_isbn.text =
|
357
|
+
@entry_isbn.text = ""
|
406
358
|
|
407
359
|
post_addition([book], library, is_new)
|
408
360
|
else
|
409
361
|
post_addition([], library, is_new)
|
410
362
|
end
|
411
|
-
rescue Alexandria::BookProviders::NoResultsError =>
|
412
|
-
@find_error =
|
363
|
+
rescue Alexandria::BookProviders::NoResultsError => ex
|
364
|
+
@find_error = ex.message
|
413
365
|
@button_add.sensitive = true
|
414
366
|
notify_end_add_by_isbn
|
415
367
|
ensure
|
@@ -424,22 +376,28 @@ module Alexandria
|
|
424
376
|
|
425
377
|
def add_selected_books(library, _is_new)
|
426
378
|
books_to_add = []
|
427
|
-
@treeview_results.selection.
|
379
|
+
@treeview_results.selection.each do |_model, _path, iter|
|
428
380
|
@results.each do |book, cover|
|
429
381
|
next unless book.ident == iter[1]
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
382
|
+
|
383
|
+
isbn = book.isbn
|
384
|
+
if isbn.nil? || isbn.empty?
|
385
|
+
log.debug { "noisbn" }
|
434
386
|
book.isbn = book.saved_ident = nil
|
435
387
|
books_to_add << [book, cover]
|
436
388
|
next
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
389
|
+
end
|
390
|
+
|
391
|
+
isbn = Library.canonicalise_ean(isbn)
|
392
|
+
unless isbn
|
393
|
+
log.debug { "invalidisbn #{book.isbn}" }
|
394
|
+
next unless KeepBadISBNDialog.new(@new_book_dialog, book).keep?
|
395
|
+
|
441
396
|
book.isbn = book.saved_ident = nil
|
442
397
|
end
|
398
|
+
|
399
|
+
book.isbn = isbn
|
400
|
+
assert_not_exist(library, isbn)
|
443
401
|
books_to_add << [book, cover]
|
444
402
|
end
|
445
403
|
end
|
@@ -456,7 +414,7 @@ module Alexandria
|
|
456
414
|
end
|
457
415
|
|
458
416
|
def post_addition(books, library, is_new_library)
|
459
|
-
|
417
|
+
log.debug { "post_addition #{books.size}" }
|
460
418
|
return if books.empty?
|
461
419
|
|
462
420
|
# books, a 1d array of Alexandria::Book
|
@@ -470,7 +428,7 @@ module Alexandria
|
|
470
428
|
@entry_search.grab_focus
|
471
429
|
else
|
472
430
|
@button_add.sensitive = true #
|
473
|
-
@entry_isbn.text =
|
431
|
+
@entry_isbn.text = "" # blank ISBN field
|
474
432
|
@entry_isbn.grab_focus
|
475
433
|
end
|
476
434
|
|
@@ -483,11 +441,12 @@ module Alexandria
|
|
483
441
|
|
484
442
|
def on_add
|
485
443
|
return unless @button_add.sensitive?
|
444
|
+
|
486
445
|
@find_thread&.kill
|
487
446
|
@image_thread&.kill
|
488
447
|
|
489
448
|
begin
|
490
|
-
libraries =
|
449
|
+
libraries = LibraryCollection.instance.all_libraries
|
491
450
|
library, is_new_library =
|
492
451
|
@combo_libraries.selection_from_libraries(libraries)
|
493
452
|
|
@@ -502,8 +461,9 @@ module Alexandria
|
|
502
461
|
|
503
462
|
# Do not destroy if there is no addition.
|
504
463
|
# return unless book_was_added
|
505
|
-
rescue =>
|
506
|
-
|
464
|
+
rescue StandardError => ex
|
465
|
+
# FIXME: Message containing <> should be displayed correctly.
|
466
|
+
ErrorDialog.new(@new_book_dialog, _("Couldn't add the book"), ex.message).display
|
507
467
|
end
|
508
468
|
# books_to_add
|
509
469
|
end
|
@@ -529,10 +489,10 @@ module Alexandria
|
|
529
489
|
|
530
490
|
def notify_end_add_by_isbn
|
531
491
|
MainApp.instance.appbar.children.first.visible = false
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
492
|
+
return unless @progress_pulsing
|
493
|
+
|
494
|
+
GLib::Source.remove(@progress_pulsing)
|
495
|
+
@progress_pulsing = nil
|
536
496
|
end
|
537
497
|
|
538
498
|
def update(status, provider)
|
@@ -548,25 +508,26 @@ module Alexandria
|
|
548
508
|
end
|
549
509
|
|
550
510
|
def on_focus
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
puts text # required, strangely, to prevent GUI strangeness
|
565
|
-
# above last checked with ruby-gnome2 0.17.1 2009-12-09
|
566
|
-
# if this puts is commented out, the cursor disappears
|
567
|
-
# from the @entry_isbn box... weird, ne? - CathalMagus
|
568
|
-
end
|
511
|
+
return unless @isbn_radiobutton.active? && @entry_isbn.text.strip.empty?
|
512
|
+
|
513
|
+
clipboard = Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD)
|
514
|
+
text = clipboard.wait_for_text or return
|
515
|
+
|
516
|
+
if Library.valid_isbn?(text) || Library.valid_ean?(text) ||
|
517
|
+
Library.valid_upc?(text)
|
518
|
+
GLib::Idle.add do
|
519
|
+
@entry_isbn.text = text
|
520
|
+
@entry_isbn.grab_focus
|
521
|
+
@entry_isbn.select_region(0, -1) # select all...
|
522
|
+
# @button_add.grab_focus
|
523
|
+
false
|
569
524
|
end
|
525
|
+
log.debug { "Setting ISBN field to #{text}" }
|
526
|
+
# FIXME: Get rid of this puts!
|
527
|
+
puts text # required, strangely, to prevent GUI strangeness
|
528
|
+
# above last checked with ruby-gnome2 0.17.1 2009-12-09
|
529
|
+
# if this puts is commented out, the cursor disappears
|
530
|
+
# from the @entry_isbn box... weird, ne? - CathalMagus
|
570
531
|
end
|
571
532
|
end
|
572
533
|
|
@@ -574,19 +535,18 @@ module Alexandria
|
|
574
535
|
if (event.event_type == :button_press) &&
|
575
536
|
(event.button == 1)
|
576
537
|
|
577
|
-
radio, target_widget, box2, box3 =
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
end
|
538
|
+
radio, target_widget, box2, box3 =
|
539
|
+
case widget
|
540
|
+
when @eventbox_entry_search
|
541
|
+
[@title_radiobutton, @entry_search,
|
542
|
+
@eventbox_combo_search, @eventbox_entry_isbn]
|
543
|
+
when @eventbox_combo_search
|
544
|
+
[@title_radiobutton, @combo_search,
|
545
|
+
@eventbox_entry_search, @eventbox_entry_isbn]
|
546
|
+
when @eventbox_entry_isbn
|
547
|
+
[@isbn_radiobutton, @entry_isbn,
|
548
|
+
@eventbox_entry_search, @eventbox_combo_search]
|
549
|
+
end
|
590
550
|
radio.active = true
|
591
551
|
target_widget.grab_focus
|
592
552
|
widget.above_child = false
|
@@ -595,7 +555,7 @@ module Alexandria
|
|
595
555
|
end
|
596
556
|
|
597
557
|
def on_help
|
598
|
-
Alexandria::UI.display_help(@preferences_dialog,
|
558
|
+
Alexandria::UI.display_help(@preferences_dialog, "add-book-by-isbn")
|
599
559
|
end
|
600
560
|
|
601
561
|
private
|
@@ -603,12 +563,14 @@ module Alexandria
|
|
603
563
|
def assert_not_exist(library, isbn)
|
604
564
|
# Check that the book doesn't already exist in the library.
|
605
565
|
isbn13 = Library.canonicalise_ean(isbn)
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
566
|
+
return unless isbn13
|
567
|
+
|
568
|
+
book = library.find { |bk| bk.isbn == isbn13 }
|
569
|
+
return unless book
|
570
|
+
|
571
|
+
raise DuplicateBookException,
|
572
|
+
format(_("'%s' already exists in '%s' (titled '%s')."),
|
573
|
+
isbn, library.name, book.title.sub("&", "&"))
|
612
574
|
end
|
613
575
|
end
|
614
576
|
end
|