alexandria-book-collection-manager 0.7.1 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +5 -2
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +113 -45
  6. data/.rubocop_todo.yml +82 -170
  7. data/.simplecov +5 -1
  8. data/.travis.yml +45 -0
  9. data/.yardopts +1 -1
  10. data/CHANGELOG.md +60 -0
  11. data/ChangeLog.0 +33 -35
  12. data/Gemfile +6 -5
  13. data/INSTALL.md +164 -0
  14. data/README.md +52 -42
  15. data/Rakefile +95 -109
  16. data/TODO.md +9 -1
  17. data/alexandria-book-collection-manager.gemspec +52 -45
  18. data/bin/alexandria +31 -53
  19. data/doc/AUTHORS +61 -0
  20. data/doc/BUGS +31 -0
  21. data/doc/FAQ +365 -0
  22. data/doc/HACKING +19 -0
  23. data/doc/NEWS +341 -0
  24. data/doc/alexandria.1 +120 -0
  25. data/doc/cuecat_support.rdoc +67 -0
  26. data/doc/dependency_decisions.yml +80 -0
  27. data/lib/alexandria.rb +29 -37
  28. data/lib/alexandria/about.rb +52 -51
  29. data/lib/alexandria/book_providers.rb +94 -101
  30. data/lib/alexandria/book_providers/adlibris.rb +45 -85
  31. data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
  32. data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
  33. data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
  34. data/lib/alexandria/book_providers/douban.rb +29 -51
  35. data/lib/alexandria/book_providers/proxis.rb +42 -59
  36. data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
  37. data/lib/alexandria/book_providers/siciliano.rb +68 -70
  38. data/lib/alexandria/book_providers/thalia.rb +46 -45
  39. data/lib/alexandria/book_providers/web.rb +17 -33
  40. data/lib/alexandria/book_providers/worldcat.rb +74 -102
  41. data/lib/alexandria/book_providers/z3950.rb +170 -174
  42. data/lib/alexandria/config.rb +5 -3
  43. data/lib/alexandria/console.rb +10 -21
  44. data/lib/alexandria/default_preferences.rb +37 -0
  45. data/lib/alexandria/execution_queue.rb +17 -15
  46. data/lib/alexandria/export_format.rb +47 -0
  47. data/lib/alexandria/export_library.rb +188 -302
  48. data/lib/alexandria/import_library.rb +114 -155
  49. data/lib/alexandria/import_library_csv.rb +46 -96
  50. data/lib/alexandria/library_collection.rb +79 -0
  51. data/lib/alexandria/library_sort_order.rb +45 -0
  52. data/lib/alexandria/library_store.rb +233 -0
  53. data/lib/alexandria/logging.rb +15 -19
  54. data/lib/alexandria/models/book.rb +15 -20
  55. data/lib/alexandria/models/library.rb +81 -363
  56. data/lib/alexandria/net.rb +7 -6
  57. data/lib/alexandria/preferences.rb +73 -91
  58. data/lib/alexandria/scanners.rb +4 -2
  59. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
  60. data/lib/alexandria/scanners/keyboard.rb +10 -8
  61. data/lib/alexandria/smart_library.rb +135 -171
  62. data/lib/alexandria/ui.rb +17 -15
  63. data/lib/alexandria/ui/about_dialog.rb +49 -0
  64. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
  65. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  66. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  67. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
  68. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
  69. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
  70. data/lib/alexandria/ui/builder_base.rb +9 -27
  71. data/lib/alexandria/ui/callbacks.rb +188 -186
  72. data/lib/alexandria/ui/columns.rb +2 -0
  73. data/lib/alexandria/ui/completion_models.rb +12 -23
  74. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  75. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  76. data/lib/alexandria/ui/dndable.rb +10 -8
  77. data/lib/alexandria/ui/error_dialog.rb +25 -0
  78. data/lib/alexandria/ui/export_dialog.rb +139 -0
  79. data/lib/alexandria/ui/icons.rb +49 -65
  80. data/lib/alexandria/ui/iconview.rb +15 -13
  81. data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
  82. data/lib/alexandria/ui/import_dialog.rb +157 -0
  83. data/lib/alexandria/ui/init.rb +23 -33
  84. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  85. data/lib/alexandria/ui/libraries_combo.rb +18 -14
  86. data/lib/alexandria/ui/listview.rb +77 -88
  87. data/lib/alexandria/ui/main_app.rb +26 -26
  88. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  89. data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
  90. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
  91. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  92. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  93. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  94. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  95. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  96. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  97. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  98. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
  99. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  100. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  101. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
  102. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  103. data/lib/alexandria/ui/sound.rb +13 -13
  104. data/lib/alexandria/ui/ui_manager.rb +262 -283
  105. data/lib/alexandria/undo_manager.rb +3 -0
  106. data/lib/alexandria/version.rb +6 -19
  107. data/lib/alexandria/web_themes.rb +24 -21
  108. data/po/Makefile +2 -2
  109. data/po/cs.po +993 -880
  110. data/po/cy.po +957 -874
  111. data/po/de.po +990 -869
  112. data/po/el.po +989 -869
  113. data/po/es.po +985 -865
  114. data/po/fr.po +986 -870
  115. data/po/ga.po +907 -823
  116. data/po/gl.po +981 -865
  117. data/po/it.po +986 -868
  118. data/po/ja.po +969 -853
  119. data/po/mk.po +983 -863
  120. data/po/nb.po +979 -863
  121. data/po/nl.po +983 -864
  122. data/po/pl.po +1020 -969
  123. data/po/pt.po +988 -861
  124. data/po/pt_BR.po +984 -868
  125. data/po/ru.po +992 -873
  126. data/po/sk.po +987 -869
  127. data/po/sv.po +977 -861
  128. data/po/uk.po +975 -865
  129. data/po/zh_TW.po +976 -860
  130. data/schemas/alexandria.schemas +25 -3
  131. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  132. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  133. data/share/alexandria/glade/main_app__builder.glade +24 -33
  134. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  135. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  136. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  137. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  138. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  139. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  140. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  141. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  142. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  143. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  144. data/spec/alexandria/book_providers_spec.rb +77 -210
  145. data/spec/alexandria/book_spec.rb +16 -12
  146. data/spec/alexandria/console_spec.rb +27 -0
  147. data/spec/alexandria/export_library_spec.rb +130 -0
  148. data/spec/alexandria/library_spec.rb +130 -172
  149. data/spec/alexandria/library_store_spec.rb +37 -0
  150. data/spec/alexandria/preferences_spec.rb +46 -17
  151. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  152. data/spec/alexandria/smart_library_spec.rb +32 -25
  153. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  154. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  155. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  156. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  157. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  159. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  160. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  161. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  162. data/spec/alexandria/ui/icons_spec.rb +26 -0
  163. data/spec/alexandria/ui/iconview_spec.rb +9 -21
  164. data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
  165. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  166. data/spec/alexandria/ui/main_app_spec.rb +8 -33
  167. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  168. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  169. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  170. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  171. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  172. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  173. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  174. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  175. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  176. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
  177. data/spec/alexandria/ui/sound_spec.rb +4 -2
  178. data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
  179. data/spec/end_to_end/basic_run_spec.rb +57 -0
  180. data/spec/spec_helper.rb +66 -33
  181. data/tasks/setup.rb +5 -3
  182. data/tasks/spec.rake +18 -3
  183. data/util/rake/fileinstall.rb +38 -40
  184. data/util/rake/gettextgenerate.rb +15 -70
  185. data/util/rake/omfgenerate.rb +10 -10
  186. metadata +176 -60
  187. data/INSTALL.rdoc +0 -148
  188. data/dogtail/basic_run_test.py +0 -9
  189. data/lib/alexandria/book_providers/bol_it.rb +0 -160
  190. data/lib/alexandria/book_providers/deastore.rb +0 -273
  191. data/lib/alexandria/book_providers/ibs_it.rb +0 -147
  192. data/lib/alexandria/book_providers/mcu.rb +0 -169
  193. data/lib/alexandria/book_providers/renaud.rb +0 -140
  194. data/lib/alexandria/book_providers/webster_it.rb +0 -167
  195. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
  196. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
  197. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
  198. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  199. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  200. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
  201. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  202. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  203. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
  204. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
  205. data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
  206. data/spec/alexandria/ui/dialogs_spec.rb +0 -94
  207. data/spec/alexandria/ui/sidepane_spec.rb +0 -27
  208. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
  209. data/spec/alexandria/utilities_spec.rb +0 -50
  210. data/tasks/dogtail.rake +0 -4
@@ -1,167 +0,0 @@
1
- # Copyright (C) 2007 Marco Costantini
2
- # Copyright (C) 2014, 2016 Matijs van Zuijlen
3
- # based on ibs_it.rb by Claudio Belotti
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
- require 'fileutils'
21
- require 'net/http'
22
- require 'open-uri'
23
- # require 'cgi'
24
-
25
- module Alexandria
26
- class BookProviders
27
- class Webster_itProvider < GenericProvider
28
- BASE_URI = 'http://www.libreriauniversitaria.it'.freeze # also "http://www.webster.it"
29
- CACHE_DIR = File.join(Alexandria::Library::DIR, '.webster_it_cache')
30
- REFERER = BASE_URI
31
- LOCALE = 'BIT'.freeze # used only for search by title/author/keyword. possible are: "BIT", "BUS", "BUK", "BDE", "MIT"
32
- def initialize
33
- super('Webster_it', 'Webster (Italy)')
34
- FileUtils.mkdir_p(CACHE_DIR) unless File.exist?(CACHE_DIR)
35
- # no preferences for the moment
36
- at_exit { clean_cache }
37
- end
38
-
39
- def search(criterion, type)
40
- criterion = criterion.encode('ISO-8859-15')
41
- req = BASE_URI + '/'
42
- req += case type
43
- when SEARCH_BY_ISBN
44
- 'isbn/' # "#{LOCALE}/"
45
-
46
- when SEARCH_BY_TITLE
47
- "c_search.php?noinput=1&shelf=#{LOCALE}&title_query="
48
-
49
- when SEARCH_BY_AUTHORS
50
- "c_search.php?noinput=1&shelf=#{LOCALE}&author_query="
51
-
52
- when SEARCH_BY_KEYWORD
53
- "c_search.php?noinput=1&shelf=#{LOCALE}&subject_query="
54
-
55
- else
56
- raise InvalidSearchTypeError
57
-
58
- end
59
-
60
- req += CGI.escape(criterion)
61
- p req if $DEBUG
62
- data = transport.get(URI.parse(req))
63
- if type == SEARCH_BY_ISBN
64
- to_book(data) # rescue raise NoResultsError
65
- else
66
- begin
67
- results = []
68
- each_book_page(data) do |code, _title|
69
- results << to_book(transport.get(URI.parse(BASE_URI + "/#{LOCALE}/" + code)))
70
- end
71
- return results
72
- rescue
73
- raise NoResultsError
74
- end
75
- end
76
- end
77
-
78
- def url(book)
79
- BASE_URI + '/isbn/' + book.isbn
80
- end
81
-
82
- private
83
-
84
- def to_book(data)
85
- raise NoResultsError if data =~ /<font color="\#ffffff"><b>Prodotto non esistente<\/b><\/font>/
86
- data = data.encode('UTF-8')
87
-
88
- md = /<li><span class="product_label">Titolo:<\/span><span class="product_text"> ([^<]+)/.match(data)
89
- raise unless md
90
- title = CGI.unescape(md[1].strip)
91
- if (md = /<span class="product_heading_volume">([^<]+)/.match(data))
92
- title += ' ' + CGI.unescape(md[1].strip)
93
- end
94
-
95
- authors = []
96
- if (md = /<li><span class="product_label">Autor[ei]:<\/span> <span class="product_text">(<a href="[^>]+">([^<]+)<\/a>,? ?)+<\/span><li>/.match(data))
97
- this = CGI.unescape(md[0].strip)
98
- authors = this.scan(/<a href="[^>]+">([^<]+)<\/a>,?/)
99
- authors = authors.map { |author| author[0] }
100
- # puts this
101
- # md[1].strip.split(', ').each { |a| authors << CGI.unescape(a.strip) }
102
- end
103
-
104
- md = /<li><span class="product_label">ISBN:<\/span> <span class="product_text">([^<]+)/.match(data)
105
- raise unless md
106
- isbn = Library.canonicalise_ean(md[1].strip)
107
-
108
- # raise unless
109
- md = /<li><span class="product_label">Editore:<\/span> <span class="product_text"><a href="[^>]+>([^<]+)/.match(data)
110
- (publisher = CGI.unescape(md[1].strip)) || md
111
-
112
- edition = if (md = /<li><span class="product_label">Pagine:<\/span> <span class="product_text">([^<]+)/.match(data))
113
- CGI.unescape(md[1].strip) + ' p.'
114
- end
115
-
116
- publish_year = nil
117
- if (md = /<li><span class="product_label">Data di Pubblicazione:<\/span> <span class="product_text">([^<]+)/.match(data))
118
- publish_year = CGI.unescape(md[1].strip)[-4..-1].to_i
119
- publish_year = nil if publish_year.zero?
120
- end
121
-
122
- if data =~ /javascript:popImage/ && (md = /<img border="0" alt="[^"]+" src="([^"]+)/.match(data))
123
- cover_url = BASE_URI + md[1].strip
124
- # use "p" instead of "g" for smaller image
125
- cover_url[-5] = 112 if cover_url[-5] == 103
126
-
127
- cover_filename = isbn + '.tmp'
128
- Dir.chdir(CACHE_DIR) do
129
- begin
130
- cover_data = open(cover_url, 'Referer' => REFERER).read
131
- rescue OpenURI::HTTPError
132
- cover_data = nil
133
- end
134
- if cover_data
135
- File.open(cover_filename, 'w') do |file|
136
- file.write cover_data
137
- end
138
- end
139
- end
140
-
141
- medium_cover = CACHE_DIR + '/' + cover_filename
142
- if File.size(medium_cover) > 0
143
- puts medium_cover + ' has non-0 size' if $DEBUG
144
- return [Book.new(title, authors, isbn, publisher, publish_year, edition), medium_cover]
145
- end
146
- puts medium_cover + ' has 0 size, removing ...' if $DEBUG
147
- File.delete(medium_cover)
148
- end
149
- [Book.new(title, authors, isbn, publisher, publish_year, edition)]
150
- end
151
-
152
- def each_book_page(data)
153
- raise if data.scan(/<tr ><td width="10%" align="center"">&nbsp;<a href="#{LOCALE}\/([^\/]+)/) { |a| yield a }.empty?
154
- end
155
-
156
- def clean_cache
157
- # FIXME: begin ... rescue ... end?
158
- Dir.chdir(CACHE_DIR) do
159
- Dir.glob('*.tmp') do |file|
160
- puts 'removing ' + file if $DEBUG
161
- File.delete(file)
162
- end
163
- end
164
- end
165
- end
166
- end
167
- end
@@ -1,59 +0,0 @@
1
- # Copyright (C) 2004-2006 Laurent Sansonetti
2
- #
3
- # Alexandria is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU General Public License as
5
- # published by the Free Software Foundation; either version 2 of the
6
- # License, or (at your option) any later version.
7
- #
8
- # Alexandria is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU General Public
14
- # License along with Alexandria; see the file COPYING. If not,
15
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
16
- # Fifth Floor, Boston, MA 02110-1301 USA.
17
-
18
- module Alexandria
19
- module UI
20
- class AboutDialog < Gtk::AboutDialog
21
- include GetText
22
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
23
-
24
- GPL = <<EOL.freeze
25
- Alexandria is free software; you can redistribute it and/or
26
- modify it under the terms of the GNU General Public License as
27
- published by the Free Software Foundation; either version 2 of the
28
- License, or (at your option) any later version.
29
-
30
- Alexandria is distributed in the hope that it will be useful,
31
- but WITHOUT ANY WARRANTY; without even the implied warranty of
32
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
- General Public License for more details.
34
-
35
- You should have received a copy of the GNU General Public
36
- License along with Alexandria; see the file COPYING. If not,
37
- write to the Free Software Foundation, Inc., 51 Franklin Street,
38
- Fifth Floor, Boston, MA 02110-1301 USA.
39
- EOL
40
-
41
- def initialize(parent)
42
- super()
43
- self.name = Alexandria::TITLE
44
- self.version = Alexandria::DISPLAY_VERSION
45
- self.copyright = Alexandria::COPYRIGHT
46
- self.comments = Alexandria::DESCRIPTION
47
- self.authors = Alexandria::AUTHORS
48
- self.documenters = Alexandria::DOCUMENTERS
49
- self.artists = Alexandria::ARTISTS
50
- self.translator_credits = Alexandria::TRANSLATORS.join("\n")
51
- self.logo = Icons::ALEXANDRIA
52
- self.website = Alexandria::WEBSITE_URL
53
- self.license = GPL
54
- self.transient_for = parent
55
- signal_connect('response') { destroy }
56
- end
57
- end
58
- end
59
- end
@@ -1,70 +0,0 @@
1
- # Copyright (C) 2004-2006 Laurent Sansonetti
2
- #
3
- # Alexandria is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU General Public License as
5
- # published by the Free Software Foundation; either version 2 of the
6
- # License, or (at your option) any later version.
7
- #
8
- # Alexandria is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU General Public
14
- # License along with Alexandria; see the file COPYING. If not,
15
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
16
- # Fifth Floor, Boston, MA 02110-1301 USA.
17
-
18
- # HIG compliant error dialog boxes
19
- module Alexandria
20
- module UI
21
- class AlertDialog < Gtk::Dialog
22
- def initialize(parent, title, stock_icon, buttons, message = nil)
23
- super(title: '', parent: parent, flags: :destroy_with_parent, buttons: buttons)
24
-
25
- self.border_width = 6
26
- self.resizable = false
27
- child.spacing = 12
28
-
29
- hbox = Gtk::Box.new(:horizontal, 12)
30
- hbox.homogeneous = false
31
- hbox.border_width = 6
32
- child.pack_start(hbox)
33
-
34
- image = Gtk::Image.new(stock: stock_icon,
35
- size: Gtk::IconSize::DIALOG)
36
- image.set_alignment(0.5, 0)
37
- hbox.pack_start(image)
38
-
39
- vbox = Gtk::Box.new(:vertical, 6)
40
- vbox.homogeneous = false
41
- hbox.pack_start(vbox)
42
-
43
- label = Gtk::Label.new
44
- label.set_alignment(0, 0)
45
- label.wrap = label.selectable = true
46
- label.markup = "<b><big>#{title}</big></b>"
47
- vbox.pack_start(label)
48
-
49
- if message
50
- label = Gtk::Label.new
51
- label.set_alignment(0, 0)
52
- label.wrap = label.selectable = true
53
- label.markup = message.strip
54
- vbox.pack_start(label)
55
- end
56
- end
57
- end
58
-
59
- class ErrorDialog < AlertDialog
60
- def initialize(parent, title, message = nil)
61
- super(parent, title, Gtk::Stock::DIALOG_ERROR,
62
- [[Gtk::Stock::OK, :ok]], message)
63
- # FIXME: Should accept just :ok
64
- self.default_response = Gtk::ResponseType::OK
65
- show_all && run
66
- destroy
67
- end
68
- end
69
- end
70
- end
@@ -1,43 +0,0 @@
1
- # Copyright (C) 2007 Joseph Method
2
- #
3
- # Alexandria is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU General Public License as
5
- # published by the Free Software Foundation; either version 2 of the
6
- # License, or (at your option) any later version.
7
- #
8
- # Alexandria is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU General Public
14
- # License along with Alexandria; see the file COPYING. If not,
15
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
16
- # Fifth Floor, Boston, MA 02110-1301 USA.
17
-
18
- module Alexandria
19
- module UI
20
- # Generalized Dialog for lists of bad isbns. Used for on_import. Can also
21
- # be used for on_load library conversions.
22
- class BadIsbnsDialog < Gtk::MessageDialog
23
- def initialize(parent, message = nil, list = nil)
24
- message = _("There's a problem") unless message
25
- super(parent, Gtk::Dialog::MODAL, Gtk::MessageDialog::WARNING, Gtk::MessageDialog::BUTTONS_CLOSE, message)
26
- isbn_container = Gtk::Box.new :horizontal
27
- the_vbox = children.first
28
- the_vbox.pack_start(isbn_container)
29
- the_vbox.reorder_child(isbn_container, 3)
30
- scrolley = Gtk::ScrolledWindow.new
31
- isbn_container.pack_start(scrolley)
32
- textview = Gtk::TextView.new(Gtk::TextBuffer.new)
33
- textview.editable = false
34
- textview.cursor_visible = false
35
- scrolley.add(textview)
36
- list.each do |li|
37
- textview.buffer.insert_at_cursor("#{li}\n")
38
- end
39
- show_all
40
- end
41
- end
42
- end
43
- end
@@ -1,171 +0,0 @@
1
- # Copyright (C) 2004-2006 Laurent Sansonetti
2
- # Copyright (C) 2014, 2016 Matijs van Zuijlen
3
- #
4
- # Alexandria is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU General Public License as
6
- # published by the Free Software Foundation; either version 2 of the
7
- # License, or (at your option) any later version.
8
- #
9
- # Alexandria is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public
15
- # License along with Alexandria; see the file COPYING. If not,
16
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
- # Fifth Floor, Boston, MA 02110-1301 USA.
18
-
19
- module Alexandria
20
- module UI
21
- class ConfirmEraseDialog < AlertDialog
22
- include GetText
23
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
24
-
25
- def initialize(parent, filename)
26
- super(parent, _('File already exists'),
27
- Gtk::Stock::DIALOG_QUESTION,
28
- [[Gtk::Stock::CANCEL, :cancel],
29
- [_('_Replace'), :ok]],
30
- _("A file named '%s' already exists. Do you want " \
31
- 'to replace it with the one you are generating?') % filename)
32
- # FIXME: Should accept just :cancel
33
- self.default_response = Gtk::ResponseType::CANCEL
34
- show_all && (@response = run)
35
- destroy
36
- end
37
-
38
- def erase?
39
- @response == :ok
40
- end
41
- end
42
-
43
- class ExportDialog < Gtk::FileChooserDialog
44
- include GetText
45
- extend GetText
46
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
47
-
48
- FORMATS = Alexandria::ExportFormat.all
49
- THEMES = Alexandria::WebTheme.all
50
-
51
- def initialize(parent, library, sort_order)
52
- super(title: _("Export '%s'") % library.name,
53
- action: :save,
54
- buttons: [[Gtk::Stock::HELP, :help],
55
- [Gtk::Stock::CANCEL, :cancel],
56
- [_('_Export'), :accept]])
57
-
58
- self.transient_for = parent
59
- self.current_name = library.name
60
- signal_connect('destroy') { hide }
61
-
62
- @parent = parent
63
- @library = library
64
- @sort_order = sort_order
65
-
66
- preview_image = Gtk::Image.new
67
-
68
- theme_combo = Gtk::ComboBoxText.new
69
- theme_combo.valign = :center
70
- theme_combo.vexpand = false
71
- THEMES.each do |theme|
72
- theme_combo.append_text(theme.name)
73
- end
74
- theme_combo.signal_connect('changed') do
75
- file = THEMES[theme_combo.active].preview_file
76
- preview_image.pixbuf = GdkPixbuf::Pixbuf.new(file: file)
77
- end
78
- theme_combo.active = 0
79
- theme_label = Gtk::Label.new(_('_Theme:'), use_underline: true)
80
- theme_label.xalign = 0
81
- theme_label.mnemonic_widget = theme_combo
82
-
83
- types_combo = Gtk::ComboBoxText.new
84
- types_combo.vexpand = false
85
- types_combo.valign = :center
86
- FORMATS.each do |format|
87
- text = format.name + ' ('
88
- text += if format.ext
89
- '*.' + format.ext
90
- else
91
- _('directory')
92
- end
93
- text += ')'
94
- types_combo.append_text(text)
95
- end
96
- types_combo.active = 0
97
- types_combo.signal_connect('changed') do
98
- visible = FORMATS[types_combo.active].needs_preview?
99
- theme_label.visible = theme_combo.visible = preview_image.visible = visible
100
- end
101
- types_combo.show
102
-
103
- types_label = Gtk::Label.new(_('Export for_mat:'), use_underline: true)
104
- types_label.xalign = 0
105
- types_label.mnemonic_widget = types_combo
106
- types_label.show
107
-
108
- # TODO: Re-design extra widget layout
109
- grid = Gtk::Grid.new
110
- grid.column_spacing = 6
111
- grid.attach types_label, 0, 0, 1, 1
112
- grid.attach types_combo, 1, 0, 1, 1
113
- grid.attach theme_label, 0, 1, 1, 1
114
- grid.attach theme_combo, 1, 1, 1, 1
115
- grid.attach preview_image, 2, 0, 1, 3
116
- set_extra_widget grid
117
-
118
- while ((response = run) != :cancel) &&
119
- (response != :delete_event)
120
-
121
- if response == :help
122
- Alexandria::UI.display_help(self, 'exporting')
123
- else
124
- begin
125
- break if on_export(FORMATS[types_combo.active],
126
- THEMES[theme_combo.active])
127
- rescue => e
128
- raise
129
- ErrorDialog.new(self, _('Export failed'), e.message)
130
- end
131
- end
132
- end
133
- destroy
134
- end
135
-
136
- private
137
-
138
- def on_export(format, theme)
139
- unless @library.respond_to?(format.message)
140
- raise NotImplementedError
141
- end
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