alexandria-book-collection-manager 0.7.3 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +77 -0
  4. data/.gitignore +4 -1
  5. data/.rubocop.yml +86 -36
  6. data/.rubocop_todo.yml +58 -161
  7. data/.simplecov +5 -2
  8. data/CHANGELOG.md +56 -2
  9. data/Gemfile +4 -3
  10. data/INSTALL.md +23 -11
  11. data/README.md +52 -41
  12. data/Rakefile +78 -75
  13. data/alexandria-book-collection-manager.gemspec +50 -44
  14. data/bin/alexandria +12 -22
  15. data/doc/FAQ +1 -2
  16. data/doc/dependency_decisions.yml +27 -8
  17. data/lib/alexandria.rb +25 -23
  18. data/lib/alexandria/about.rb +50 -50
  19. data/lib/alexandria/book_providers.rb +86 -91
  20. data/lib/alexandria/book_providers/adlibris.rb +37 -74
  21. data/lib/alexandria/book_providers/amazon_aws.rb +94 -100
  22. data/lib/alexandria/book_providers/amazon_ecs_util.rb +289 -324
  23. data/lib/alexandria/book_providers/barnes_and_noble.rb +42 -42
  24. data/lib/alexandria/book_providers/douban.rb +25 -41
  25. data/lib/alexandria/book_providers/proxis.rb +34 -29
  26. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  27. data/lib/alexandria/book_providers/siciliano.rb +60 -64
  28. data/lib/alexandria/book_providers/thalia_provider.rb +161 -0
  29. data/lib/alexandria/book_providers/web.rb +5 -5
  30. data/lib/alexandria/book_providers/worldcat.rb +66 -95
  31. data/lib/alexandria/book_providers/z3950.rb +153 -169
  32. data/lib/alexandria/config.rb +1 -1
  33. data/lib/alexandria/console.rb +3 -3
  34. data/lib/alexandria/default_preferences.rb +37 -0
  35. data/lib/alexandria/execution_queue.rb +13 -12
  36. data/lib/alexandria/export_format.rb +8 -8
  37. data/lib/alexandria/export_library.rb +128 -127
  38. data/lib/alexandria/import_library.rb +102 -126
  39. data/lib/alexandria/import_library_csv.rb +41 -41
  40. data/lib/alexandria/library_collection.rb +6 -5
  41. data/lib/alexandria/library_sort_order.rb +4 -2
  42. data/lib/alexandria/library_store.rb +39 -28
  43. data/lib/alexandria/logging.rb +10 -14
  44. data/lib/alexandria/models/book.rb +5 -4
  45. data/lib/alexandria/models/library.rb +63 -53
  46. data/lib/alexandria/net.rb +5 -6
  47. data/lib/alexandria/preferences.rb +66 -63
  48. data/lib/alexandria/scanners.rb +2 -2
  49. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +17 -17
  50. data/lib/alexandria/scanners/keyboard.rb +8 -8
  51. data/lib/alexandria/smart_library.rb +110 -112
  52. data/lib/alexandria/ui.rb +15 -15
  53. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +2 -2
  54. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +108 -109
  55. data/lib/alexandria/ui/alert_dialog.rb +66 -0
  56. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +13 -9
  57. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  58. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -38
  59. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +64 -157
  60. data/lib/alexandria/ui/builder_base.rb +1 -1
  61. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  62. data/lib/alexandria/ui/callbacks.rb +187 -155
  63. data/lib/alexandria/ui/completion_models.rb +8 -22
  64. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  65. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  66. data/lib/alexandria/ui/dndable.rb +7 -7
  67. data/lib/alexandria/ui/error_dialog.rb +25 -0
  68. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +37 -58
  69. data/lib/alexandria/ui/icons.rb +38 -43
  70. data/lib/alexandria/ui/iconview.rb +12 -10
  71. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  72. data/lib/alexandria/ui/import_dialog.rb +157 -0
  73. data/lib/alexandria/ui/init.rb +30 -41
  74. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +9 -6
  75. data/lib/alexandria/ui/libraries_combo.rb +15 -14
  76. data/lib/alexandria/ui/listview.rb +69 -67
  77. data/lib/alexandria/ui/main_app.rb +24 -26
  78. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  79. data/lib/alexandria/ui/multi_drag_treeview.rb +8 -9
  80. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +113 -114
  81. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +22 -19
  82. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  83. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  84. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  85. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  86. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  87. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +7 -28
  88. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +53 -48
  89. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  90. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  91. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  92. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  93. data/lib/alexandria/ui/sound.rb +11 -13
  94. data/lib/alexandria/ui/ui_manager.rb +216 -200
  95. data/lib/alexandria/version.rb +4 -19
  96. data/lib/alexandria/web_themes.rb +21 -21
  97. data/po/Makefile +2 -2
  98. data/po/cs.po +992 -875
  99. data/po/cy.po +961 -874
  100. data/po/de.po +990 -865
  101. data/po/el.po +989 -865
  102. data/po/es.po +985 -861
  103. data/po/fr.po +987 -867
  104. data/po/ga.po +908 -820
  105. data/po/gl.po +980 -860
  106. data/po/it.po +986 -864
  107. data/po/ja.po +969 -849
  108. data/po/mk.po +984 -860
  109. data/po/nb.po +979 -859
  110. data/po/nl.po +983 -860
  111. data/po/pl.po +1018 -971
  112. data/po/pt.po +988 -857
  113. data/po/pt_BR.po +983 -863
  114. data/po/ru.po +994 -871
  115. data/po/sk.po +989 -867
  116. data/po/sv.po +976 -856
  117. data/po/uk.po +972 -858
  118. data/po/zh_TW.po +974 -854
  119. data/schemas/alexandria.schemas +24 -2
  120. data/share/alexandria/glade/acquire_dialog__builder.glade +1 -1
  121. data/share/alexandria/glade/book_properties_dialog__builder.glade +1 -1
  122. data/share/alexandria/glade/main_app__builder.glade +6 -21
  123. data/share/alexandria/glade/new_book_dialog__builder.glade +1 -1
  124. data/share/alexandria/glade/preferences_dialog__builder.glade +1 -1
  125. data/share/gnome/help/alexandria/C/introduction.xml +0 -4
  126. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  127. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  128. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  129. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  130. data/share/gnome/help/alexandria/ja/introduction.xml +0 -4
  131. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  132. data/spec/alexandria/book_providers/thalia_provider_spec.rb +119 -0
  133. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  134. data/spec/alexandria/book_providers_spec.rb +62 -156
  135. data/spec/alexandria/book_spec.rb +12 -10
  136. data/spec/alexandria/console_spec.rb +6 -11
  137. data/spec/alexandria/export_library_spec.rb +47 -58
  138. data/spec/alexandria/library_spec.rb +121 -109
  139. data/spec/alexandria/library_store_spec.rb +8 -8
  140. data/spec/alexandria/preferences_spec.rb +44 -17
  141. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  142. data/spec/alexandria/smart_library_spec.rb +15 -15
  143. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  144. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  145. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  146. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/book_properties_dialog_spec.rb +59 -0
  148. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  150. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  152. data/spec/alexandria/ui/icons_spec.rb +26 -0
  153. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  154. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  155. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  156. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  157. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +51 -0
  158. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  159. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  160. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  161. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  162. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  163. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  164. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  165. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  166. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  167. data/spec/alexandria/ui/sound_spec.rb +2 -2
  168. data/spec/alexandria/ui/ui_manager_spec.rb +44 -20
  169. data/spec/end_to_end/basic_run_spec.rb +21 -38
  170. data/spec/fixtures/cover.jpg +0 -0
  171. data/spec/spec_helper.rb +54 -10
  172. data/tasks/setup.rb +2 -2
  173. data/tasks/spec.rake +11 -11
  174. data/util/rake/fileinstall.rb +38 -35
  175. data/util/rake/gettextgenerate.rb +7 -7
  176. data/util/rake/omfgenerate.rb +7 -7
  177. metadata +158 -45
  178. data/dogtail/basic_run_test.py +0 -9
  179. data/lib/alexandria/book_providers/renaud.rb +0 -155
  180. data/lib/alexandria/book_providers/thalia.rb +0 -198
  181. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -63
  182. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -176
  183. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -62
  184. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -563
  185. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -61
  186. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -423
  187. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  188. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  189. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  190. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  191. data/spec/alexandria/utilities_spec.rb +0 -52
  192. data/tasks/dogtail.rake +0 -6
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- from dogtail.tree import *
4
- from dogtail.utils import run
5
-
6
- run('bin/alexandria', appName = 'alexandria')
7
- app = root.application('alexandria')
8
- quit_item = app.menuItem('Quit')
9
- quit_item.doActionNamed('click')
@@ -1,155 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (C) 2005-2006-2006 Mathieu Leduc-Hamel
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
- # http://en.wikipedia.org/wiki/Renaud-Bray
21
-
22
- require 'net/http'
23
- require 'cgi'
24
-
25
- module Alexandria
26
- class BookProviders
27
- class RENAUDProvider < GenericProvider
28
- include GetText
29
- # GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
30
- BASE_URI = 'http://www.renaud-bray.com/'
31
- ACCENTUATED_CHARS = 'áàâäçéèêëíìîïóòôöúùûü'
32
-
33
- def initialize
34
- super('RENAUD', 'Renaud-Bray (Canada)')
35
- end
36
-
37
- def search(criterion, type)
38
- criterion = criterion.encode('ISO-8859-1')
39
- req = BASE_URI +
40
- 'francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre' \
41
- '&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri='
42
- req += case type
43
- when SEARCH_BY_ISBN
44
- 'ISBN'
45
- when SEARCH_BY_TITLE
46
- 'Titre'
47
- when SEARCH_BY_AUTHORS
48
- 'Auteur'
49
- when SEARCH_BY_KEYWORD
50
- ''
51
- else
52
- raise InvalidSearchTypeError
53
- end
54
- req += '&Phrase='
55
-
56
- req += CGI.escape(criterion)
57
- p req if $DEBUG
58
- data = transport.get(URI.parse(req))
59
- begin
60
- if type == SEARCH_BY_ISBN
61
- return to_books(data).pop
62
- else
63
- results = []
64
- to_books(data).each { |book|
65
- results << book
66
- }
67
- while /Suivant/ =~ data
68
- md = /Enteterouge\">([\d]*)<\/b>/.match(data)
69
- num = md[1].to_i + 1
70
- data = transport.get(URI.parse(req + '&PageActuelle=' + num.to_s))
71
- to_books(data).each { |book|
72
- results << book
73
- }
74
- end
75
- return results
76
- end
77
- rescue StandardError
78
- raise NoResultsError
79
- end
80
- end
81
-
82
- def url(book)
83
- 'http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=' \
84
- '&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=' + book.isbn
85
- end
86
-
87
- private
88
-
89
- NO_BOOKS_FOUND_REGEXP =
90
- /<strong class="Promotion">Aucun article trouv. selon les crit.res demand.s<\/strong>/.freeze
91
- HYPERLINK_SCAN_REGEXP =
92
- /"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/strong><\/a><br>/.
93
- freeze
94
-
95
- def to_books(data)
96
- data = CGI.unescapeHTML(data)
97
- data = data.encode('UTF-8')
98
- raise NoResultsError if data =~ NO_BOOKS_FOUND_REGEXP
99
-
100
- titles = []
101
- data.scan(HYPERLINK_SCAN_REGEXP).each { |md|
102
- titles << md[1].strip
103
- }
104
- raise if titles.empty?
105
-
106
- authors = []
107
- data.scan(/Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/i>/).each { |md|
108
- authors2 = []
109
- for author in md[0].split(' ')
110
- authors2 << author.strip
111
- end
112
- authors << authors2
113
- }
114
- raise if authors.empty?
115
-
116
- isbns = []
117
- data.scan(/ISBN : ?<\/td><td>(\d+)/).each { |md|
118
- isbns << md[0].strip
119
- }
120
- raise if isbns.empty?
121
-
122
- editions = []
123
- publish_years = []
124
- data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each { |md|
125
- editions << md[0].strip
126
- publish_years << md[0].strip.split(/-/)[0].to_i
127
- }
128
- raise if editions.empty? || publish_years.empty?
129
-
130
- publishers = []
131
- data.scan(/diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/span><br>/).each { |md|
132
- publishers << md[0].strip
133
- }
134
- raise if publishers.empty?
135
-
136
- book_covers = []
137
- data.scan(/(\/ImagesEditeurs\/[\d]*\/([\dX]*-f.(jpg|gif))
138
- |\/francais\/suggestion\/images\/livre\/livre.gif)/x).each { |md|
139
- book_covers << BASE_URI + md[0].strip
140
- }
141
- raise if book_covers.empty?
142
-
143
- books = []
144
- titles.each_with_index { |title, i|
145
- books << [Book.new(title, authors[i], isbns[i], publishers[i], publish_years[i], editions[i]),
146
- book_covers[i]]
147
- # print books
148
- }
149
- raise if books.empty?
150
-
151
- books
152
- end
153
- end
154
- end
155
- end
@@ -1,198 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (C) 2009 Cathal Mc Ginley
4
- # Copyright (C) 2014 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
- # http://de.wikipedia.org/wiki/Thalia_%28Buchhandel%29
22
- # Thalia.de bought the Austrian book trade chain Amadeus
23
-
24
- # New Tlalia provider, taken from Palatina MetaDataSource and modified
25
- # for Alexandria. (21 Dec 2009)
26
-
27
- require 'net/http'
28
- require 'cgi'
29
- require 'alexandria/book_providers/web'
30
-
31
- module Alexandria
32
- class BookProviders
33
- class ThaliaProvider < WebsiteBasedProvider
34
- include Alexandria::Logging
35
-
36
- SITE = 'http://www.thalia.de'
37
- BASE_SEARCH_URL = "#{SITE}/shop/bde_bu_hg_startseite/suche/?%s=%s" # type,term
38
-
39
- def initialize
40
- super('Thalia', 'Thalia (Germany)')
41
- # no preferences for the moment
42
- prefs.read
43
- end
44
-
45
- def url(book)
46
- create_search_uri(SEARCH_BY_ISBN, book.isbn)
47
- end
48
-
49
- def search(criterion, type)
50
- req = create_search_uri(type, criterion)
51
- puts req if $DEBUG
52
- html_data = transport.get_response(URI.parse(req))
53
- if type == SEARCH_BY_ISBN
54
- parse_result_data(html_data.body, criterion)
55
- else
56
- results = parse_search_result_data(html_data.body)
57
- raise NoResultsError if results.empty?
58
-
59
- results.map { |result| get_book_from_search_result(result) }
60
- end
61
- end
62
-
63
- def create_search_uri(search_type, search_term)
64
- (search_type_code = {
65
- SEARCH_BY_ISBN => 'sq',
66
- SEARCH_BY_AUTHORS => 'sa', # Autor
67
- SEARCH_BY_TITLE => 'st', # Titel
68
- SEARCH_BY_KEYWORD => 'ssw' # Schlagwort
69
- }[search_type]) || ''
70
- search_type_code = CGI.escape(search_type_code)
71
- search_term_encoded = if search_type == SEARCH_BY_ISBN
72
- # search_term_encoded = search_term.as_isbn_13
73
- Library.canonicalise_isbn(search_term) # check this!
74
- else
75
- CGI.escape(search_term)
76
- end
77
- format(BASE_SEARCH_URL, search_type_code, search_term_encoded)
78
- end
79
-
80
- def parse_search_result_data(html)
81
- doc = html_to_doc(html)
82
- book_search_results = []
83
- results_divs = doc / 'div.articlePresentationSearchCH'
84
- results_divs.each do |div|
85
- result = {}
86
- title_link = div % 'div.articleText/h2/a'
87
- result[:title] = title_link.inner_html
88
- result[:lookup_url] = title_link['href']
89
- book_search_results << result
90
- end
91
- book_search_results
92
- end
93
-
94
- def data_from_label(node, label_text)
95
- label_node = node % "strong[text()*='#{label_text}']"
96
- if (item_node = label_node.parent)
97
- data = ''
98
- item_node.children.each do |n|
99
- data += n.to_html if n.text?
100
- end
101
- data.strip
102
- else
103
- ''
104
- end
105
- end
106
-
107
- def get_book_from_search_result(result)
108
- log.debug { "Fetching book from #{result[:lookup_url]}" }
109
- html_data = transport.get_response(URI.parse(result[:lookup_url]))
110
- parse_result_data(html_data.body, 'noisbn', true)
111
- end
112
-
113
- def parse_result_data(html, isbn, recursing = false)
114
- doc = html_to_doc(html)
115
-
116
- results_divs = doc / 'div.articlePresentationSearchCH'
117
- unless results_divs.empty?
118
- if recursing
119
- # already recursing, avoid doing so endlessly second time
120
- # around *should* lead to a book description, not a result
121
- # list
122
- return
123
- end
124
-
125
- # ISBN-lookup results in multiple results (trying to be
126
- # useful, such as for new editions e.g. 9780974514055
127
- # "Programming Ruby" )
128
- results = parse_search_result_data(html)
129
- isbn10 = Library.canonicalise_isbn(isbn)
130
- # e.g. .../dave_thomas/ISBN0-9745140-5-5/ID6017044.html
131
- chosen = results.first # fallback!
132
- results.each do |rslt|
133
- if rslt[:lookup_url] =~ /\/ISBN(\d+[\d-]*)\//
134
- if Regexp.last_match[1].delete('-') == isbn10
135
- chosen = rslt
136
- break
137
- end
138
- end
139
- end
140
- html_data = transport.get_response(URI.parse(chosen[:lookup_url]))
141
- return parse_result_data(html_data.body, isbn, true)
142
- end
143
-
144
- begin
145
- if (div = doc % 'div#contentFull')
146
- title_img = ((div % :h2) / :img).first
147
- title = title_img['alt']
148
-
149
- # note, the following img also has alt="von Author, Author..."
150
-
151
- if (author_h = doc % 'h3[text()*="Mehr von"]') # "More from..." links
152
- authors = []
153
- author_links = author_h.parent / :a
154
- author_links.each do |a|
155
- if a['href'] =~ /BUCH\/sa/
156
- # 'sa' means search author, there may also be 'ssw' (search keyword) links
157
- authors << a.inner_text[0..-2].strip
158
- # NOTE stripping the little >> character here...
159
- end
160
- end
161
- end
162
-
163
- item_details = doc % 'ul.itemDataList'
164
- isbns = []
165
- isbns << data_from_label(item_details, 'EAN')
166
- isbns << data_from_label(item_details, 'ISBN')
167
-
168
- year = nil
169
- date = data_from_label(item_details, 'Erschienen:')
170
- year = Regexp.last_match[1].to_i if date =~ /([\d]{4})/
171
-
172
- binding = data_from_label(item_details, 'Einband')
173
-
174
- publisher = data_from_label(item_details, 'Erschienen bei:')
175
-
176
- book = Book.new(title, authors, isbns.first,
177
- publisher, year, binding)
178
-
179
- image_url = nil
180
- if (image_link = doc % 'a[@id=itemPicStart]')
181
- image_url = image_link['href']
182
- end
183
-
184
- return [book, image_url]
185
-
186
- end
187
- rescue StandardError => ex
188
- trace = ex.backtrace.join("\n> ")
189
- log.warn {
190
- 'Failed parsing search results for Thalia ' \
191
- "#{ex.message} #{trace}"
192
- }
193
- raise NoResultsError
194
- end
195
- end
196
- end
197
- end
198
- end
@@ -1,63 +0,0 @@
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
- # HIG compliant error dialog boxes
8
- module Alexandria
9
- module UI
10
- class AlertDialog < SimpleDelegator
11
- def initialize(parent, title, stock_icon, buttons, message = nil)
12
- dialog = Gtk::Dialog.new(title: '', parent: parent, flags: :destroy_with_parent, buttons: buttons)
13
- super(dialog)
14
-
15
- self.border_width = 6
16
- self.resizable = false
17
- child.spacing = 12
18
-
19
- hbox = Gtk::Box.new(:horizontal, 12)
20
- hbox.homogeneous = false
21
- hbox.border_width = 6
22
- child.pack_start(hbox)
23
-
24
- image = Gtk::Image.new(stock: stock_icon,
25
- size: Gtk::IconSize::DIALOG)
26
- image.set_alignment(0.5, 0)
27
- hbox.pack_start(image)
28
-
29
- vbox = Gtk::Box.new(:vertical, 6)
30
- vbox.homogeneous = false
31
- hbox.pack_start(vbox)
32
-
33
- label = Gtk::Label.new
34
- label.set_alignment(0, 0)
35
- label.wrap = label.selectable = true
36
- label.markup = "<b><big>#{title}</big></b>"
37
- vbox.pack_start(label)
38
-
39
- if message
40
- label = Gtk::Label.new
41
- label.set_alignment(0, 0)
42
- label.wrap = label.selectable = true
43
- label.markup = message.strip
44
- vbox.pack_start(label)
45
- end
46
- end
47
- end
48
-
49
- class ErrorDialog < AlertDialog
50
- def initialize(parent, title, message = nil)
51
- super(parent, title, Gtk::Stock::DIALOG_ERROR,
52
- [[Gtk::Stock::OK, :ok]], message)
53
- # FIXME: Should accept just :ok
54
- self.default_response = Gtk::ResponseType::OK
55
- end
56
-
57
- def display
58
- show_all && run
59
- destroy
60
- end
61
- end
62
- end
63
- end
@@ -1,176 +0,0 @@
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
- class Alexandria::ImportFilter
8
- def to_filefilter
9
- filefilter = Gtk::FileFilter.new
10
- filefilter.name = name
11
- patterns.each { |x| filefilter.add_pattern(x) }
12
- filefilter
13
- end
14
- end
15
-
16
- module Alexandria
17
- module UI
18
- class SkipEntryDialog < AlertDialog
19
- include GetText
20
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
21
-
22
- def initialize(parent, message)
23
- super(parent, _('Error while importing'),
24
- Gtk::Stock::DIALOG_QUESTION,
25
- [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
26
- [_('_Continue'), Gtk::ResponseType::OK]],
27
- message)
28
- puts "Opened SkipEntryDialog #{inspect}" if $DEBUG
29
- self.default_response = Gtk::ResponseType::CANCEL
30
- end
31
-
32
- def continue?
33
- show_all && (@response = run)
34
- destroy
35
- @response == Gtk::ResponseType::OK
36
- end
37
- end
38
-
39
- class ImportDialog < SimpleDelegator
40
- include GetText
41
- include Logging
42
-
43
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
44
-
45
- FILTERS = Alexandria::ImportFilter.all
46
-
47
- def initialize(parent)
48
- title = _('Import a Library')
49
- dialog = Gtk::FileChooserDialog.new title: title, parent: parent, action: :open
50
- super(dialog)
51
- puts 'ImportDialog opened.' if $DEBUG
52
- @destroyed = false
53
- @running = false
54
- add_button(Gtk::Stock::HELP, Gtk::ResponseType::HELP)
55
- add_button(Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL)
56
- import_button = add_button(_('_Import'),
57
- Gtk::ResponseType::ACCEPT)
58
- import_button.sensitive = false
59
-
60
- signal_connect('destroy') do
61
- if @running
62
- @destroyed = true
63
- else
64
- destroy
65
- end
66
- end
67
-
68
- filters = {}
69
- FILTERS.each do |filter|
70
- filefilter = filter.to_filefilter
71
- add_filter(filefilter)
72
- puts "Added ImportFilter #{filefilter} -- #{filefilter.name}" if $DEBUG
73
- filters[filefilter] = filter
74
- end
75
-
76
- signal_connect('selection_changed') do
77
- import_button.sensitive = filename && File.file?(filename)
78
- end
79
-
80
- # before adding the (hidden) progress bar, we must re-set the
81
- # packing of the button box (currently packed at the end),
82
- # because the progressbar will be *after* the button box.
83
- buttonbox = child.children.last
84
- child.set_child_packing(buttonbox, pack_type: :start)
85
- child.reorder_child(buttonbox, 1)
86
-
87
- pbar = Gtk::ProgressBar.new
88
- pbar.show_text = true
89
- child.pack_start(pbar, expand: false)
90
- end
91
-
92
- def acquire
93
- on_progress = proc do |fraction|
94
- pbar.show unless pbar.visible?
95
- pbar.fraction = fraction
96
- end
97
-
98
- on_error = proc do |message|
99
- SkipEntryDialog.new(self, message).continue?
100
- end
101
-
102
- exec_queue = ExecutionQueue.new
103
-
104
- while !@destroyed &&
105
- ((response = run) != Gtk::ResponseType::CANCEL) &&
106
- response != Gtk::ResponseType::DELETE_EVENT
107
-
108
- if response == Gtk::ResponseType::HELP
109
- Alexandria::UI.display_help(self, 'import-library')
110
- next
111
- end
112
- file = File.basename(filename, '.*')
113
- base = GLib.locale_to_utf8(file)
114
- new_library_name = Library.generate_new_name(
115
- LibraryCollection.instance.all_libraries,
116
- base)
117
-
118
- filter = filters[self.filter]
119
- puts "Going forward with filter: #{filter.name}" if $DEBUG
120
- self.sensitive = false
121
-
122
- filter.on_iterate do |n, total|
123
- unless @destroyed
124
- fraction = n * 1.0 / total
125
- puts "#{inspect} fraction: #{fraction}" if $DEBUG
126
- exec_queue.call(on_progress, fraction)
127
- end
128
- end
129
-
130
- not_cancelled = true
131
- filter.on_error do |message|
132
- not_cancelled = exec_queue.sync_call(on_error, message)
133
- puts "#{inspect} cancel state: #{not_cancelled}" if $DEBUG
134
- end
135
-
136
- library = nil
137
- @bad_isbns = nil
138
- @failed_isbns = nil
139
- thread = Thread.start do
140
- begin
141
- library, @bad_isbns, @failed_isbns = filter.invoke(new_library_name,
142
- filename)
143
- rescue StandardError => ex
144
- trace = ex.backtrace.join("\n> ")
145
- log.error { "Import failed: #{ex.message} #{trace}" }
146
- end
147
- end
148
-
149
- while thread.alive? && !@destroyed
150
- # puts "Thread #{thread} still alive."
151
- @running = true
152
- exec_queue.iterate
153
- Gtk.main_iteration_do(false)
154
- end
155
-
156
- unless @destroyed
157
- if library
158
- yield(library, @bad_isbns, @failed_isbns)
159
- break
160
- elsif not_cancelled
161
- puts "Raising ErrorDialog because not_cancelled is #{not_cancelled}" if $DEBUG
162
- ErrorDialog.new(self,
163
- _("Couldn't import the library"),
164
- _('The format of the file you ' \
165
- 'provided is unknown. Please ' \
166
- 'retry with another file.')).display
167
- end
168
- pbar.hide
169
- self.sensitive = true
170
- end
171
- end
172
- destroy unless @destroyed
173
- end
174
- end
175
- end
176
- end