alexandria-book-collection-manager 0.6.9.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (293) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rubocop.yml +68 -0
  4. data/.rubocop_todo.yml +200 -0
  5. data/CHANGELOG.md +23 -0
  6. data/COPYING +339 -0
  7. data/ChangeLog.0 +3598 -0
  8. data/Gemfile +9 -0
  9. data/INSTALL.rdoc +156 -0
  10. data/PACKAGING +36 -0
  11. data/README.md +88 -0
  12. data/RELEASE_CHECKLIST +18 -0
  13. data/Rakefile +264 -0
  14. data/TODO +24 -0
  15. data/alexandria-book-collection-manager.gemspec +35 -0
  16. data/alexandria.desktop.in +10 -0
  17. data/bin/alexandria +82 -0
  18. data/doc/AUTHORS +60 -0
  19. data/doc/BUGS +31 -0
  20. data/doc/FAQ +369 -0
  21. data/doc/HACKING +19 -0
  22. data/doc/NEWS +341 -0
  23. data/doc/alexandria.1 +120 -0
  24. data/doc/cuecat_support.rdoc +67 -0
  25. data/lib/alexandria.rb +85 -0
  26. data/lib/alexandria/about.rb +82 -0
  27. data/lib/alexandria/book_providers.rb +411 -0
  28. data/lib/alexandria/book_providers/adlibris.rb +235 -0
  29. data/lib/alexandria/book_providers/amazon_aws.rb +261 -0
  30. data/lib/alexandria/book_providers/amazon_ecs_util.rb +405 -0
  31. data/lib/alexandria/book_providers/barnes_and_noble.rb +229 -0
  32. data/lib/alexandria/book_providers/bol_it.rb +162 -0
  33. data/lib/alexandria/book_providers/deastore.rb +277 -0
  34. data/lib/alexandria/book_providers/douban.rb +135 -0
  35. data/lib/alexandria/book_providers/ibs_it.rb +149 -0
  36. data/lib/alexandria/book_providers/mcu.rb +177 -0
  37. data/lib/alexandria/book_providers/proxis.rb +205 -0
  38. data/lib/alexandria/book_providers/pseudomarc.rb +185 -0
  39. data/lib/alexandria/book_providers/renaud.rb +142 -0
  40. data/lib/alexandria/book_providers/siciliano.rb +271 -0
  41. data/lib/alexandria/book_providers/thalia.rb +197 -0
  42. data/lib/alexandria/book_providers/web.rb +59 -0
  43. data/lib/alexandria/book_providers/webster_it.rb +173 -0
  44. data/lib/alexandria/book_providers/worldcat.rb +251 -0
  45. data/lib/alexandria/book_providers/z3950.rb +422 -0
  46. data/lib/alexandria/config.rb +8 -0
  47. data/lib/alexandria/console.rb +31 -0
  48. data/lib/alexandria/execution_queue.rb +96 -0
  49. data/lib/alexandria/export_library.rb +536 -0
  50. data/lib/alexandria/import_library.rb +316 -0
  51. data/lib/alexandria/import_library_csv.rb +270 -0
  52. data/lib/alexandria/logging.rb +159 -0
  53. data/lib/alexandria/models/book.rb +72 -0
  54. data/lib/alexandria/models/library.rb +714 -0
  55. data/lib/alexandria/net.rb +53 -0
  56. data/lib/alexandria/preferences.rb +324 -0
  57. data/lib/alexandria/scanners.rb +42 -0
  58. data/lib/alexandria/scanners/cuecat.rb +118 -0
  59. data/lib/alexandria/scanners/keyboard.rb +57 -0
  60. data/lib/alexandria/smart_library.rb +525 -0
  61. data/lib/alexandria/ui.rb +53 -0
  62. data/lib/alexandria/ui/builder_base.rb +43 -0
  63. data/lib/alexandria/ui/callbacks.rb +389 -0
  64. data/lib/alexandria/ui/completion_models.rb +228 -0
  65. data/lib/alexandria/ui/dialogs/about_dialog.rb +59 -0
  66. data/lib/alexandria/ui/dialogs/acquire_dialog.rb +640 -0
  67. data/lib/alexandria/ui/dialogs/alert_dialog.rb +68 -0
  68. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +43 -0
  69. data/lib/alexandria/ui/dialogs/barcode_animation.rb +159 -0
  70. data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +210 -0
  71. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +432 -0
  72. data/lib/alexandria/ui/dialogs/export_dialog.rb +172 -0
  73. data/lib/alexandria/ui/dialogs/import_dialog.rb +205 -0
  74. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +85 -0
  75. data/lib/alexandria/ui/dialogs/new_book_dialog.rb +639 -0
  76. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +153 -0
  77. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +67 -0
  78. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +587 -0
  79. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +56 -0
  80. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +432 -0
  81. data/lib/alexandria/ui/dndable.rb +81 -0
  82. data/lib/alexandria/ui/gtk_thread_help.rb +88 -0
  83. data/lib/alexandria/ui/icons.rb +100 -0
  84. data/lib/alexandria/ui/iconview.rb +91 -0
  85. data/lib/alexandria/ui/iconview_tooltips.rb +162 -0
  86. data/lib/alexandria/ui/init.rb +93 -0
  87. data/lib/alexandria/ui/libraries_combo.rb +75 -0
  88. data/lib/alexandria/ui/listview.rb +310 -0
  89. data/lib/alexandria/ui/main_app.rb +67 -0
  90. data/lib/alexandria/ui/multi_drag_treeview.rb +150 -0
  91. data/lib/alexandria/ui/sidepane.rb +194 -0
  92. data/lib/alexandria/ui/sound.rb +107 -0
  93. data/lib/alexandria/ui/ui_manager.rb +1308 -0
  94. data/lib/alexandria/undo_manager.rb +78 -0
  95. data/lib/alexandria/utils.rb +30 -0
  96. data/lib/alexandria/version.rb +24 -0
  97. data/lib/alexandria/web_themes.rb +75 -0
  98. data/misc/sounds/README +15 -0
  99. data/misc/sounds/bad_scan.csd +62 -0
  100. data/misc/sounds/good_scan.csd +61 -0
  101. data/misc/sounds/scanning.csd +46 -0
  102. data/po/ChangeLog +488 -0
  103. data/po/Makefile +44 -0
  104. data/po/README +29 -0
  105. data/po/commit-po +72 -0
  106. data/po/cs.po +1437 -0
  107. data/po/cy.po +1521 -0
  108. data/po/de.po +1400 -0
  109. data/po/el.po +1379 -0
  110. data/po/es.po +1376 -0
  111. data/po/fr.po +1420 -0
  112. data/po/ga.po +1359 -0
  113. data/po/gl.po +1397 -0
  114. data/po/it.po +1406 -0
  115. data/po/ja.po +1355 -0
  116. data/po/mk.po +1373 -0
  117. data/po/nb.po +1386 -0
  118. data/po/nl.po +1405 -0
  119. data/po/pl.po +1373 -0
  120. data/po/pt.po +1398 -0
  121. data/po/pt_BR.po +1409 -0
  122. data/po/ru.po +1372 -0
  123. data/po/sk.po +1380 -0
  124. data/po/sv.po +1402 -0
  125. data/po/uk.po +1423 -0
  126. data/po/zh_TW.po +1394 -0
  127. data/schemas/alexandria.schemas +300 -0
  128. data/share/alexandria/glade/acquire_dialog__builder.glade +201 -0
  129. data/share/alexandria/glade/book_properties_dialog__builder.glade +910 -0
  130. data/share/alexandria/glade/main_app__builder.glade +229 -0
  131. data/share/alexandria/glade/new_book_dialog__builder.glade +379 -0
  132. data/share/alexandria/glade/preferences_dialog__builder.glade +733 -0
  133. data/share/alexandria/icons/alexandria.png +0 -0
  134. data/share/alexandria/icons/alexandria_small.png +0 -0
  135. data/share/alexandria/icons/book.png +0 -0
  136. data/share/alexandria/icons/book_icon.png +0 -0
  137. data/share/alexandria/icons/book_small.png +0 -0
  138. data/share/alexandria/icons/cuecat.png +0 -0
  139. data/share/alexandria/icons/cuecat_inactive.png +0 -0
  140. data/share/alexandria/icons/favorite_tag.png +0 -0
  141. data/share/alexandria/icons/less.png +0 -0
  142. data/share/alexandria/icons/library.png +0 -0
  143. data/share/alexandria/icons/library_small.png +0 -0
  144. data/share/alexandria/icons/lookup.png +0 -0
  145. data/share/alexandria/icons/more.png +0 -0
  146. data/share/alexandria/icons/no_cover.png +0 -0
  147. data/share/alexandria/icons/smart_library.png +0 -0
  148. data/share/alexandria/icons/smart_library_small.png +0 -0
  149. data/share/alexandria/icons/star_set.png +0 -0
  150. data/share/alexandria/icons/star_unset.png +0 -0
  151. data/share/alexandria/icons/view_as_icons.png +0 -0
  152. data/share/alexandria/icons/view_as_list.png +0 -0
  153. data/share/alexandria/ui/menus.xml +91 -0
  154. data/share/alexandria/ui/popups.xml +91 -0
  155. data/share/alexandria/web-themes/clean/clean.css +85 -0
  156. data/share/alexandria/web-themes/clean/preview.jpg +0 -0
  157. data/share/alexandria/web-themes/list/list.css +105 -0
  158. data/share/alexandria/web-themes/list/preview.jpg +0 -0
  159. data/share/app-icon/16x16/alexandria.png +0 -0
  160. data/share/app-icon/16x16/alexandria.svg +263 -0
  161. data/share/app-icon/22x22/alexandria.png +0 -0
  162. data/share/app-icon/22x22/alexandria.svg +465 -0
  163. data/share/app-icon/24x24/alexandria.png +0 -0
  164. data/share/app-icon/32x32/alexandria.png +0 -0
  165. data/share/app-icon/32x32/alexandria.svg +813 -0
  166. data/share/app-icon/32x32/alexandria.xpm +241 -0
  167. data/share/app-icon/48x48/alexandria.png +0 -0
  168. data/share/app-icon/scalable/alexandria.svg +700 -0
  169. data/share/gnome/help/alexandria/C/about.xml +44 -0
  170. data/share/gnome/help/alexandria/C/adding-books.xml +339 -0
  171. data/share/gnome/help/alexandria/C/alexandria.xml +185 -0
  172. data/share/gnome/help/alexandria/C/bugs.xml +18 -0
  173. data/share/gnome/help/alexandria/C/editing-book-properties.xml +124 -0
  174. data/share/gnome/help/alexandria/C/exporting.xml +81 -0
  175. data/share/gnome/help/alexandria/C/figures/adding_books_acquire_from_scanner_process.png +0 -0
  176. data/share/gnome/help/alexandria/C/figures/adding_books_add_by_isbn.png +0 -0
  177. data/share/gnome/help/alexandria/C/figures/adding_books_isbn_import.png +0 -0
  178. data/share/gnome/help/alexandria/C/figures/adding_books_manual_details.png +0 -0
  179. data/share/gnome/help/alexandria/C/figures/adding_books_rename_library_after_import.png +0 -0
  180. data/share/gnome/help/alexandria/C/figures/adding_books_search_results.png +0 -0
  181. data/share/gnome/help/alexandria/C/figures/editing_book_properties_info.png +0 -0
  182. data/share/gnome/help/alexandria/C/figures/editing_book_properties_loaning.png +0 -0
  183. data/share/gnome/help/alexandria/C/figures/exporting_information_html.png +0 -0
  184. data/share/gnome/help/alexandria/C/figures/getting_started_first_launched.png +0 -0
  185. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view.png +0 -0
  186. data/share/gnome/help/alexandria/C/figures/searching_filtering_views_list_view_search.png +0 -0
  187. data/share/gnome/help/alexandria/C/figures/settings_providers_new_z3950.png +0 -0
  188. data/share/gnome/help/alexandria/C/figures/smart_libraries_new_smart_library.png +0 -0
  189. data/share/gnome/help/alexandria/C/figures/working_with_libraries_library_pane.png +0 -0
  190. data/share/gnome/help/alexandria/C/getting-started.xml +154 -0
  191. data/share/gnome/help/alexandria/C/gnu-fdl-1.2.xml +543 -0
  192. data/share/gnome/help/alexandria/C/introduction.xml +142 -0
  193. data/share/gnome/help/alexandria/C/searching.xml +90 -0
  194. data/share/gnome/help/alexandria/C/settings.xml +140 -0
  195. data/share/gnome/help/alexandria/C/smart-libraries.xml +160 -0
  196. data/share/gnome/help/alexandria/C/working-with-libraries.xml +76 -0
  197. data/share/gnome/help/alexandria/ChangeLog +99 -0
  198. data/share/gnome/help/alexandria/fr/alexandria.xml +2292 -0
  199. data/share/gnome/help/alexandria/fr/figures/alexandria_add_button.png +0 -0
  200. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_isbn_1.png +0 -0
  201. data/share/gnome/help/alexandria/fr/figures/alexandria_add_by_search_1.png +0 -0
  202. data/share/gnome/help/alexandria/fr/figures/alexandria_add_manually.png +0 -0
  203. data/share/gnome/help/alexandria/fr/figures/alexandria_add_z3950.png +0 -0
  204. data/share/gnome/help/alexandria/fr/figures/alexandria_close_button.png +0 -0
  205. data/share/gnome/help/alexandria/fr/figures/alexandria_edit_info.png +0 -0
  206. data/share/gnome/help/alexandria/fr/figures/alexandria_export_web_page.png +0 -0
  207. data/share/gnome/help/alexandria/fr/figures/alexandria_importing.png +0 -0
  208. data/share/gnome/help/alexandria/fr/figures/alexandria_library_pane.png +0 -0
  209. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view.png +0 -0
  210. data/share/gnome/help/alexandria/fr/figures/alexandria_list_view_search.png +0 -0
  211. data/share/gnome/help/alexandria/fr/figures/alexandria_loaning.png +0 -0
  212. data/share/gnome/help/alexandria/fr/figures/alexandria_main_window.png +0 -0
  213. data/share/gnome/help/alexandria/fr/figures/alexandria_remove_button.png +0 -0
  214. data/share/gnome/help/alexandria/ja/about.xml +33 -0
  215. data/share/gnome/help/alexandria/ja/adding-books.xml +314 -0
  216. data/share/gnome/help/alexandria/ja/alexandria.xml +172 -0
  217. data/share/gnome/help/alexandria/ja/bugs.xml +11 -0
  218. data/share/gnome/help/alexandria/ja/editing-book-properties.xml +100 -0
  219. data/share/gnome/help/alexandria/ja/exporting.xml +98 -0
  220. data/share/gnome/help/alexandria/ja/figures/adding_books_acquire_from_scanner_process.png +0 -0
  221. data/share/gnome/help/alexandria/ja/figures/adding_books_add_by_isbn.png +0 -0
  222. data/share/gnome/help/alexandria/ja/figures/adding_books_isbn_import.png +0 -0
  223. data/share/gnome/help/alexandria/ja/figures/adding_books_manual_details.png +0 -0
  224. data/share/gnome/help/alexandria/ja/figures/adding_books_rename_library_after_import.png +0 -0
  225. data/share/gnome/help/alexandria/ja/figures/adding_books_search_results.png +0 -0
  226. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_info.png +0 -0
  227. data/share/gnome/help/alexandria/ja/figures/editing_book_properties_loaning.png +0 -0
  228. data/share/gnome/help/alexandria/ja/figures/exporting_information_html.png +0 -0
  229. data/share/gnome/help/alexandria/ja/figures/getting_started_first_launched.png +0 -0
  230. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view.png +0 -0
  231. data/share/gnome/help/alexandria/ja/figures/searching_filtering_views_list_view_search.png +0 -0
  232. data/share/gnome/help/alexandria/ja/figures/settings_providers_new_z3950.png +0 -0
  233. data/share/gnome/help/alexandria/ja/figures/smart_libraries_new_smart_library.png +0 -0
  234. data/share/gnome/help/alexandria/ja/figures/working_with_libraries_library_pane.png +0 -0
  235. data/share/gnome/help/alexandria/ja/getting-started.xml +144 -0
  236. data/share/gnome/help/alexandria/ja/gnu-fdl-1.2.xml +541 -0
  237. data/share/gnome/help/alexandria/ja/introduction.xml +134 -0
  238. data/share/gnome/help/alexandria/ja/searching.xml +104 -0
  239. data/share/gnome/help/alexandria/ja/settings.xml +129 -0
  240. data/share/gnome/help/alexandria/ja/smart-libraries.xml +140 -0
  241. data/share/gnome/help/alexandria/ja/working-with-libraries.xml +88 -0
  242. data/share/menu/alexandria +7 -0
  243. data/share/omf/alexandria/alexandria-C.omf.in +27 -0
  244. data/share/omf/alexandria/alexandria-fr.omf.in +30 -0
  245. data/share/sounds/alexandria/bad_scan.ogg +0 -0
  246. data/share/sounds/alexandria/bad_scan.wav +0 -0
  247. data/share/sounds/alexandria/good_scan.ogg +0 -0
  248. data/share/sounds/alexandria/good_scan.wav +0 -0
  249. data/share/sounds/alexandria/scanning.ogg +0 -0
  250. data/share/sounds/alexandria/scanning.wav +0 -0
  251. data/spec/alexandria/library_spec.rb +205 -0
  252. data/spec/alexandria/preferences_spec.rb +22 -0
  253. data/spec/alexandria/scanners/cuecat_spec.rb +68 -0
  254. data/spec/alexandria/smart_library_spec.rb +22 -0
  255. data/spec/alexandria/ui/dialogs_spec.rb +90 -0
  256. data/spec/alexandria/ui/iconview_spec.rb +27 -0
  257. data/spec/alexandria/ui/listview_spec.rb +28 -0
  258. data/spec/alexandria/ui/main_app_spec.rb +48 -0
  259. data/spec/alexandria/ui/sidepane_spec.rb +27 -0
  260. data/spec/alexandria/ui/ui_manager_spec.rb +26 -0
  261. data/spec/alexandria/ui/ui_utilities_spec.rb +60 -0
  262. data/spec/alexandria/utilities_spec.rb +50 -0
  263. data/spec/data/libraries/0.6.1-noisbn/My Library/0201398257.yaml +10 -0
  264. data/spec/data/libraries/0.6.1-noisbn/My Library/1565920007.yaml +10 -0
  265. data/spec/data/libraries/0.6.1/My Library/0192812173.yaml +9 -0
  266. data/spec/data/libraries/0.6.1/My Library/0201398257.cover +0 -0
  267. data/spec/data/libraries/0.6.1/My Library/0201398257.yaml +10 -0
  268. data/spec/data/libraries/0.6.1/My Library/1565920007.yaml +10 -0
  269. data/spec/data/libraries/0.6.2/My Library/9780140266146.cover +0 -0
  270. data/spec/data/libraries/0.6.2/My Library/9780140266146.yaml +16 -0
  271. data/spec/data/libraries/0.6.2/My Library/9780140278781.cover +0 -0
  272. data/spec/data/libraries/0.6.2/My Library/9780140278781.yaml +21 -0
  273. data/spec/data/libraries/0.6.2/My Library/9780571147168.cover +0 -0
  274. data/spec/data/libraries/0.6.2/My Library/9780571147168.yaml +20 -0
  275. data/spec/data/libraries/0.6.2/My Library/9780575079038.cover +0 -0
  276. data/spec/data/libraries/0.6.2/My Library/9780575079038.yaml +20 -0
  277. data/spec/data/libraries/0.6.2/My Library/9780755322800.cover +0 -0
  278. data/spec/data/libraries/0.6.2/My Library/9780755322800.yaml +20 -0
  279. data/spec/spec_helper.rb +46 -0
  280. data/tasks/rdoc.rake +6 -0
  281. data/tasks/setup.rb +30 -0
  282. data/tasks/spec.rake +29 -0
  283. data/tasks/test.rake +38 -0
  284. data/test/application_test.rb +39 -0
  285. data/test/book_test.rb +34 -0
  286. data/test/data/isbns.txt +3 -0
  287. data/test/isbn_test.rb +68 -0
  288. data/test/providers_test.rb +254 -0
  289. data/test/test_helper.rb +42 -0
  290. data/util/rake/fileinstall.rb +313 -0
  291. data/util/rake/gettextgenerate.rb +158 -0
  292. data/util/rake/omfgenerate.rb +79 -0
  293. metadata +452 -0
@@ -0,0 +1,153 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2011, 2014 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 NewBookDialogManual < BookPropertiesDialogBase
22
+ include GetText
23
+ extend GetText
24
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
25
+
26
+ TMP_COVER_FILE = File.join(Dir.tmpdir, 'tmp_cover')
27
+ def initialize(parent, library, &on_add_cb)
28
+ super(parent, TMP_COVER_FILE)
29
+
30
+ @library, @on_add_cb = library, on_add_cb
31
+ FileUtils.rm_f(TMP_COVER_FILE)
32
+
33
+ cancel_button = Gtk::Button.new(Gtk::Stock::CANCEL)
34
+ cancel_button.signal_connect('clicked') { on_cancel }
35
+ cancel_button.show
36
+ @button_box << cancel_button
37
+
38
+ add_button = Gtk::Button.new(Gtk::Stock::ADD)
39
+ add_button.signal_connect('clicked') { on_add }
40
+ add_button.show
41
+ @button_box << add_button
42
+
43
+ help_button = Gtk::Button.new(Gtk::Stock::HELP)
44
+ help_button.signal_connect('clicked') { on_help }
45
+ help_button.show
46
+ @button_box << help_button
47
+ @button_box.set_child_secondary(help_button, true)
48
+
49
+ self.rating = Book::DEFAULT_RATING
50
+ self.cover = Icons::BOOK_ICON
51
+
52
+ on_title_changed
53
+ end
54
+
55
+ def on_title_changed
56
+ title = @entry_title.text.strip
57
+ begin
58
+ @book_properties_dialog.title = if title.empty?
59
+ _('Adding a Book')
60
+ else
61
+ _("Adding '%s'") % title
62
+ end
63
+ rescue
64
+ raise "There's a problem with a book somewhere"
65
+ end
66
+ end
67
+
68
+ #######
69
+ private
70
+ #######
71
+
72
+ def on_cancel
73
+ @book_properties_dialog.destroy
74
+ end
75
+
76
+ class AddError < StandardError
77
+ end
78
+
79
+ def on_add
80
+ if (title = @entry_title.text.strip).empty?
81
+ raise AddError.new(_('A title must be provided.'))
82
+ end
83
+ isbn = nil
84
+ if @entry_isbn.text != ''
85
+ ary = @library.select { |book|
86
+ book.ident == @entry_isbn.text }
87
+ raise AddError.new(_('The EAN/ISBN you provided is ' \
88
+ 'already used in this library.')) unless ary.empty?
89
+ isbn = begin
90
+ Library.canonicalise_isbn(@entry_isbn.text)
91
+ rescue Alexandria::Library::InvalidISBNError
92
+ raise AddError.new(_("Couldn't validate the " \
93
+ 'EAN/ISBN you provided. Make ' \
94
+ 'sure it is written correcty, ' \
95
+ 'and try again.'))
96
+ end
97
+ end
98
+ if (publisher = @entry_publisher.text.strip).empty?
99
+ raise AddError.new(_('A publisher must be provided.'))
100
+ end
101
+ publishing_year = @entry_publish_date.text.to_i
102
+ # TODO Get rid of this silly requirement
103
+ if (edition = @entry_edition.text.strip).empty?
104
+ raise AddError.new(_('A binding must be provided.'))
105
+ end
106
+ authors = []
107
+ @treeview_authors.model.each { |_m, _p, i| authors << i[0] }
108
+ if authors.empty?
109
+ raise AddError.new(_('At least one author must be ' \
110
+ 'provided.'))
111
+ end
112
+ book = Book.new(title, authors, isbn, publisher,
113
+ publishing_year == 0 ? nil : publishing_year,
114
+ edition)
115
+ book.rating = @current_rating
116
+ book.notes = @textview_notes.buffer.text
117
+ book.loaned = @checkbutton_loaned.active?
118
+ book.loaned_to = @entry_loaned_to.text
119
+ # book.loaned_since = Time.at(@date_loaned_since.time)
120
+ book.loaned_since = parse_date(@date_loaned_since.text)
121
+ book.redd = @checkbutton_redd.active?
122
+ book.own = @checkbutton_own.active?
123
+ book.want = @checkbutton_want.active?
124
+ book.tags = @entry_tags.text.split
125
+ @library << book
126
+ @library.save(book)
127
+ if File.exist?(TMP_COVER_FILE) and (!@delete_cover_file)
128
+ FileUtils.cp(TMP_COVER_FILE, @library.cover(book))
129
+ end
130
+ @on_add_cb.call(book)
131
+ @book_properties_dialog.destroy
132
+ rescue AddError => e
133
+ ErrorDialog.new(@parent, _("Couldn't add the book"),
134
+ e.message)
135
+ end
136
+
137
+ # COPIED from book_properties_dialog_base
138
+ def parse_date(datestring)
139
+ date_format = '%d/%m/%Y'
140
+ begin
141
+ d = Date.strptime(datestring, date_format)
142
+ Time.gm(d.year, d.month, d.day)
143
+ rescue
144
+ nil
145
+ end
146
+ end
147
+
148
+ def on_help
149
+ Alexandria::UI.display_help(@preferences_dialog, 'add-book-manually')
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,67 @@
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 NewSmartLibraryDialog < SmartLibraryPropertiesDialogBase
21
+ include GetText
22
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
23
+
24
+ def initialize(parent, &block)
25
+ super(parent)
26
+
27
+ add_buttons([Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
28
+ [Gtk::Stock::NEW, Gtk::Dialog::RESPONSE_OK])
29
+
30
+ self.title = _('New Smart Library')
31
+ self.default_response = Gtk::Dialog::RESPONSE_CANCEL
32
+
33
+ show_all
34
+ insert_new_rule
35
+
36
+ while (response = run) != Gtk::Dialog::RESPONSE_CANCEL and
37
+ response != Gtk::Dialog::RESPONSE_DELETE_EVENT
38
+
39
+ if response == Gtk::Dialog::RESPONSE_HELP
40
+ Alexandria::UI.display_help(self, 'new-smart-library')
41
+ elsif response == Gtk::Dialog::RESPONSE_OK
42
+ if user_confirms_possible_weirdnesses_before_saving?
43
+ rules = smart_library_rules
44
+ basename = if rules.length == 1 and
45
+ rules.first.value.is_a?(String) and
46
+ !rules.first.value.strip.empty?
47
+ rules.first.value
48
+ else
49
+ _('Smart Library')
50
+ end
51
+ name = Library.generate_new_name(
52
+ Libraries.instance.all_libraries,
53
+ basename)
54
+ library = SmartLibrary.new(name,
55
+ rules,
56
+ predicate_operator_rule)
57
+ block.call(library)
58
+ break
59
+ end
60
+ end
61
+ end
62
+
63
+ destroy
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,587 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Modifications Copyright (C) 2011 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
+ require 'alexandria/scanners/cuecat'
20
+ require 'alexandria/scanners/keyboard'
21
+
22
+ class Gtk::Entry
23
+ attr_writer :mandatory
24
+ def mandatory?
25
+ @mandatory
26
+ end
27
+ end
28
+
29
+ module Alexandria
30
+ module UI
31
+ class ProviderPreferencesBaseDialog < Gtk::Dialog
32
+ def initialize(*args)
33
+ super(*args)
34
+
35
+ self.has_separator = false
36
+ self.resizable = false
37
+ vbox.border_width = 12
38
+
39
+ @controls = []
40
+ end
41
+
42
+ def fill_table(table, provider)
43
+ i = table.n_rows
44
+ table.resize(table.n_rows + provider.prefs.length,
45
+ table.n_columns)
46
+ table.border_width = 12
47
+ table.row_spacings = 6
48
+ table.column_spacings = 12
49
+
50
+ @controls.clear
51
+
52
+ provider.prefs.read.each do |variable|
53
+ if variable.name == 'piggyback'
54
+ next
55
+ # ULTRA-HACK!! for bug #13302
56
+ # not displaying the visual choice, as its usually unnecessary
57
+ # Either way, this is confusing to the user: FIX
58
+ # - Cathal Mc Ginley 2008-02-18
59
+ end
60
+
61
+ if variable.name == 'enabled'
62
+ # also don't display Enabled/Disabled
63
+ next
64
+ end
65
+
66
+ label = Gtk::Label.new('_' + variable.description + ':')
67
+ label.use_underline = true
68
+ label.xalign = 0
69
+ table.attach_defaults(label, 0, 1, i, i + 1)
70
+
71
+ if variable.possible_values.nil?
72
+ entry = Gtk::Entry.new
73
+ entry.text = variable.value.to_s
74
+ entry.mandatory = variable.mandatory?
75
+ else
76
+ entry = Gtk::ComboBox.new
77
+ variable.possible_values.each do |value|
78
+ entry.append_text(value.to_s)
79
+ end
80
+ index = variable.possible_values.index(variable.value)
81
+ entry.active = index
82
+ end
83
+ label.mnemonic_widget = entry
84
+
85
+ @controls << [variable, entry]
86
+
87
+ table.attach_defaults(entry, 1, 2, i, i + 1)
88
+ i += 1
89
+ end
90
+ table
91
+ end
92
+
93
+ def sync_variables
94
+ @controls.each do |variable, entry|
95
+ variable.new_value = case entry
96
+ when Gtk::ComboBox
97
+ variable.possible_values[entry.active]
98
+ when Gtk::Entry
99
+ entry.text
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ class ProviderPreferencesDialog < ProviderPreferencesBaseDialog
106
+ include GetText
107
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
108
+
109
+ def initialize(parent, provider)
110
+ super(_('Preferences for %s') % provider.fullname,
111
+ parent,
112
+ Gtk::Dialog::MODAL,
113
+ [Gtk::Stock::CLOSE, Gtk::Dialog::RESPONSE_CLOSE])
114
+ self.has_separator = false
115
+ self.resizable = false
116
+ vbox.border_width = 12
117
+
118
+ table = Gtk::Table.new(0, 0)
119
+ fill_table(table, provider)
120
+ vbox.pack_start(table)
121
+
122
+ signal_connect('destroy') { sync_variables }
123
+
124
+ show_all
125
+ run
126
+ destroy
127
+ end
128
+ end
129
+
130
+ class NewProviderDialog < ProviderPreferencesBaseDialog
131
+ include GetText
132
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
133
+
134
+ def initialize(parent)
135
+ super(_('New Provider'),
136
+ parent,
137
+ Gtk::Dialog::MODAL,
138
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL])
139
+ @add_button = add_button(Gtk::Stock::ADD,
140
+ Gtk::Dialog::RESPONSE_ACCEPT)
141
+
142
+ instances = BookProviders.abstract_classes.map(&:new)
143
+ @selected_instance = nil
144
+
145
+ @table = Gtk::Table.new(2, 2)
146
+ vbox.pack_start(@table)
147
+
148
+ # Name.
149
+
150
+ label_name = Gtk::Label.new(_('_Name:'))
151
+ label_name.use_underline = true
152
+ label_name.xalign = 0
153
+ @table.attach_defaults(label_name, 0, 1, 0, 1)
154
+
155
+ entry_name = Gtk::Entry.new
156
+ entry_name.mandatory = true
157
+ label_name.mnemonic_widget = entry_name
158
+ @table.attach_defaults(entry_name, 1, 2, 0, 1)
159
+
160
+ # Type.
161
+
162
+ label_type = Gtk::Label.new(_('_Type:'))
163
+ label_type.use_underline = true
164
+ label_type.xalign = 0
165
+ @table.attach_defaults(label_type, 0, 1, 1, 2)
166
+
167
+ combo_type = Gtk::ComboBox.new
168
+ instances.each do |instance|
169
+ combo_type.append_text(instance.name)
170
+ end
171
+ combo_type.signal_connect('changed') do |cb|
172
+ @selected_instance = instances[cb.active]
173
+ fill_table(@table, @selected_instance)
174
+ sensitize
175
+ # FIXME this should be re-written once we have multiple
176
+ # abstract providers.
177
+ end
178
+ combo_type.active = 0
179
+ label_type.mnemonic_widget = combo_type
180
+ @table.attach_defaults(combo_type, 1, 2, 1, 2)
181
+
182
+ show_all
183
+ if run == Gtk::Dialog::RESPONSE_ACCEPT
184
+ @selected_instance.reinitialize(entry_name.text)
185
+ sync_variables
186
+ else
187
+ @selected_instance = nil
188
+ end
189
+ destroy
190
+ end
191
+
192
+ def instance
193
+ @selected_instance
194
+ end
195
+
196
+ #######
197
+ private
198
+ #######
199
+
200
+ def sensitize
201
+ entries = @table.children.select { |x| x.is_a?(Gtk::Entry) }
202
+ entries.each do |entry|
203
+ entry.signal_connect('changed') do
204
+ sensitive = true
205
+ entries.each do |entry2|
206
+ if entry2.mandatory?
207
+ sensitive = !entry2.text.strip.empty?
208
+ break unless sensitive
209
+ end
210
+ end
211
+ @add_button.sensitive = sensitive
212
+ end
213
+ end
214
+ @add_button.sensitive = false
215
+ end
216
+ end
217
+
218
+ class PreferencesDialog < BuilderBase
219
+ include Alexandria::Logging
220
+ include GetText
221
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
222
+
223
+ def initialize(parent, &changed_block)
224
+ super('preferences_dialog__builder.glade', widget_names)
225
+ @preferences_dialog.transient_for = parent
226
+ @changed_block = changed_block
227
+
228
+ @cols = {
229
+ @checkbutton_col_authors => 'col_authors_visible',
230
+ @checkbutton_col_isbn => 'col_isbn_visible',
231
+ @checkbutton_col_publisher => 'col_publisher_visible',
232
+ @checkbutton_col_publish_date => 'col_publish_date_visible',
233
+ @checkbutton_col_edition => 'col_edition_visible',
234
+ @checkbutton_col_redd => 'col_redd_visible',
235
+ @checkbutton_col_own => 'col_own_visible',
236
+ @checkbutton_col_want => 'col_want_visible',
237
+ @checkbutton_col_rating => 'col_rating_visible',
238
+ @checkbutton_col_tags => 'col_tags_visible',
239
+ @checkbutton_col_loaned_to => 'col_loaned_to_visible'
240
+ }
241
+ @cols.each_pair do |checkbutton, pref_name|
242
+ if checkbutton
243
+ checkbutton.active = Preferences.instance.send(pref_name)
244
+ else
245
+ log.warn { "no CheckButton for property #{pref_name} " \
246
+ '(probably conflicting versions of GUI and lib code)' }
247
+ end
248
+ end
249
+
250
+ model = Gtk::ListStore.new(String, String, TrueClass, Integer)
251
+ @treeview_providers.model = model
252
+ reload_providers
253
+ model.signal_connect_after('row-changed') { update_priority }
254
+
255
+ renderer = Gtk::CellRendererToggle.new
256
+ renderer.activatable = true
257
+ renderer.signal_connect('toggled') do |_rndrr, path|
258
+ tree_path = Gtk::TreePath.new(path)
259
+ @treeview_providers.selection.select_path(tree_path)
260
+ prov = selected_provider
261
+ if prov
262
+ prov.toggle_enabled
263
+ adjust_selected_provider(prov)
264
+ # reload_providers
265
+ end
266
+ end
267
+
268
+ # renderer.active = true
269
+ column = Gtk::TreeViewColumn.new('Enabled', renderer)
270
+ column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
271
+ value = iter[2]
272
+ rndr.active = value
273
+ end
274
+
275
+ @treeview_providers.append_column(column)
276
+
277
+ renderer = Gtk::CellRendererText.new
278
+ column = Gtk::TreeViewColumn.new('Providers',
279
+ renderer)
280
+ # :text => 0)
281
+ column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
282
+ rndr.markup = iter[0]
283
+ # enabled = iter[2]
284
+ # unless enabled
285
+ # rndr.foreground = "gray"
286
+ # end
287
+ # rndr.active = value
288
+ end
289
+ @treeview_providers.append_column(column)
290
+ @treeview_providers.selection.signal_connect('changed') \
291
+ { sensitize_providers }
292
+
293
+ @button_prov_setup.sensitive = false
294
+ @button_prov_up.sensitive = @button_prov_down.sensitive =
295
+ BookProviders.length > 1
296
+
297
+ @buttonbox_prov.set_child_secondary(@button_prov_add, true)
298
+ @buttonbox_prov.set_child_secondary(@button_prov_remove, true)
299
+
300
+ if BookProviders.abstract_classes.empty?
301
+ @checkbutton_prov_advanced.sensitive = false
302
+ else
303
+ view_advanced = Preferences.instance.view_advanced_settings
304
+ if view_advanced
305
+ @checkbutton_prov_advanced.active = true
306
+ end
307
+ end
308
+
309
+ setup_enable_disable_popup
310
+ sensitize_providers
311
+ setup_barcode_scanner_tab
312
+ end
313
+
314
+ def widget_names
315
+ [:button_prov_add, :button_prov_down, :button_prov_remove,
316
+ :button_prov_setup, :button_prov_up, :buttonbox_prov,
317
+ :checkbutton_col_authors, :checkbutton_col_edition,
318
+ :checkbutton_col_isbn, :checkbutton_col_loaned_to,
319
+ :checkbutton_col_own, :checkbutton_col_publish_date,
320
+ :checkbutton_col_publisher, :checkbutton_col_rating,
321
+ :checkbutton_col_redd, :checkbutton_col_tags,
322
+ :checkbutton_col_want, :checkbutton_prov_advanced,
323
+ :preferences_dialog, :treeview_providers,
324
+ :scanner_device_type, :use_scanning_sound, :use_scan_sound]
325
+ end
326
+
327
+ def setup_barcode_scanner_tab
328
+ @scanner_device_model = Gtk::ListStore.new(String, String)
329
+ chosen_scanner_name = Preferences.instance.barcode_scanner
330
+ index = 0
331
+ @scanner_device_type.model = @scanner_device_model
332
+ renderer = Gtk::CellRendererText.new
333
+ @scanner_device_type.pack_start(renderer, true)
334
+ @scanner_device_type.add_attribute(renderer, 'text', 0)
335
+
336
+ Alexandria::Scanners.each_scanner do |scanner|
337
+ iter = @scanner_device_model.append
338
+ iter[0] = scanner.display_name
339
+ iter[1] = scanner.name
340
+ if (chosen_scanner_name == scanner.name)
341
+ @scanner_device_type.active = index
342
+ end
343
+ index += 1
344
+ end
345
+
346
+ @use_scanning_sound.active = Preferences.instance.play_scanning_sound
347
+ @use_scan_sound.active = Preferences.instance.play_scan_sound
348
+ end
349
+
350
+ def setup_enable_disable_popup
351
+ # New Enable/Disable pop-up menu...
352
+ @enable_disable_providers_menu = Gtk::Menu.new
353
+ @enable_item = Gtk::MenuItem.new(_('Disable Provider'))
354
+ @enable_item.signal_connect('activate') {
355
+ prov = selected_provider
356
+ prov.toggle_enabled
357
+ adjust_selected_provider(prov)
358
+
359
+ }
360
+ @enable_disable_providers_menu.append(@enable_item)
361
+ @enable_disable_providers_menu.show_all
362
+
363
+ @treeview_providers.signal_connect('button_press_event') do |widget, event|
364
+ if event_is_right_click(event)
365
+ if (path = widget.get_path_at_pos(event.x, event.y))
366
+ widget.grab_focus
367
+ obj, path = widget.selection, path.first
368
+ unless obj.path_is_selected?(path)
369
+ widget.unselect_all
370
+ obj.select_path(path)
371
+ end
372
+ sel = widget.selection.selected
373
+ if sel
374
+ already_enabled = sel[2]
375
+ message = already_enabled ? _('Disable Provider') : _('Enable Provider')
376
+ @enable_item.label = message
377
+ Gtk.idle_add do
378
+ @enable_disable_providers_menu.popup(nil, nil, event.button, event.time)
379
+ false
380
+ end
381
+ end
382
+ else
383
+ puts 'not on a path'
384
+ end
385
+ end
386
+ end
387
+
388
+ # Popup the menu on Shift-F10
389
+ @treeview_providers.signal_connect('popup_menu') {
390
+ selected_prov = @treeview_providers.selection.selected
391
+ puts selected_prov.inspect
392
+ if selected_prov
393
+ Gtk.idle_add do
394
+ already_enabled = selected_prov[2]
395
+ message = already_enabled ? _('Disable Provider') : _('Enable Provider')
396
+ @enable_item.label = message
397
+
398
+ @enable_disable_providers_menu.popup(nil, nil, 0, Gdk::Event::CURRENT_TIME)
399
+ false
400
+ end
401
+ else
402
+ puts 'no action'
403
+ end
404
+ }
405
+ end
406
+
407
+ def event_is_right_click(event)
408
+ event.event_type == Gdk::Event::BUTTON_PRESS and event.button == 3
409
+ end
410
+
411
+ def prefs_empty(prefs)
412
+ prefs.empty? or (prefs.size == 1 and prefs.first.name == 'enabled')
413
+ end
414
+
415
+ def on_provider_setup
416
+ provider = selected_provider
417
+ unless prefs_empty(provider.prefs)
418
+ ProviderPreferencesDialog.new(@preferences_dialog, provider)
419
+ end
420
+ end
421
+
422
+ def on_provider_up
423
+ iter = @treeview_providers.selection.selected
424
+ previous_path = iter.path
425
+ previous_path.prev!
426
+ model = @treeview_providers.model
427
+ model.move_after(model.get_iter(previous_path), iter)
428
+ sensitize_providers
429
+ update_priority
430
+ end
431
+
432
+ def on_provider_down
433
+ iter = @treeview_providers.selection.selected
434
+ next_iter = iter.dup
435
+ next_iter.next!
436
+ @treeview_providers.model.move_after(iter, next_iter)
437
+ sensitize_providers
438
+ update_priority
439
+ end
440
+
441
+ def on_provider_advanced_toggled(checkbutton)
442
+ on = checkbutton.active?
443
+ Preferences.instance.view_advanced_settings = on
444
+ @button_prov_add.visible = @button_prov_remove.visible = on
445
+ end
446
+
447
+ def on_provider_add
448
+ dialog = NewProviderDialog.new(@preferences_dialog)
449
+ if dialog.instance
450
+ BookProviders.update_priority
451
+ reload_providers
452
+ end
453
+ end
454
+
455
+ def on_scanner_device_type(_combo)
456
+ iter = @scanner_device_type.active_iter
457
+ if iter && iter[1]
458
+ Preferences.instance.barcode_scanner = iter[1]
459
+ end
460
+ end
461
+
462
+ def on_use_scanning_sound(checkbox)
463
+ Preferences.instance.play_scanning_sound = checkbox.active?
464
+ end
465
+
466
+ def on_use_scan_sound(checkbox)
467
+ Preferences.instance.play_scan_sound = checkbox.active?
468
+ end
469
+
470
+ def on_provider_remove
471
+ provider = selected_provider
472
+ dialog = AlertDialog.new(@main_app,
473
+ _('Are you sure you want to ' \
474
+ 'permanently delete the provider ' \
475
+ "'%s'?") % provider.fullname,
476
+ Gtk::Stock::DIALOG_QUESTION,
477
+ [[Gtk::Stock::CANCEL,
478
+ Gtk::Dialog::RESPONSE_CANCEL],
479
+ [Gtk::Stock::DELETE,
480
+ Gtk::Dialog::RESPONSE_OK]],
481
+ _('If you continue, the provider and ' \
482
+ 'all of its preferences will be ' \
483
+ 'permanently deleted.'))
484
+ dialog.default_response = Gtk::Dialog::RESPONSE_CANCEL
485
+ dialog.show_all
486
+ if dialog.run == Gtk::Dialog::RESPONSE_OK
487
+ provider.remove
488
+ BookProviders.update_priority
489
+ reload_providers
490
+ end
491
+ dialog.destroy
492
+ end
493
+
494
+ def on_column_toggled(checkbutton)
495
+ raise if @cols[checkbutton].nil?
496
+ Preferences.instance.send("#{@cols[checkbutton]}=",
497
+ checkbutton.active?)
498
+
499
+ @changed_block.call
500
+ end
501
+
502
+ def on_providers_button_press_event(_widget, event)
503
+ # double left click
504
+ if event.event_type == Gdk::Event::BUTTON2_PRESS and
505
+ event.button == 1
506
+
507
+ on_provider_setup
508
+ end
509
+ end
510
+
511
+ def on_close
512
+ @preferences_dialog.destroy
513
+ Alexandria::Preferences.instance.save!
514
+ end
515
+
516
+ def on_help
517
+ Alexandria::UI.display_help(@preferences_dialog,
518
+ 'alexandria-preferences')
519
+ end
520
+
521
+ #######
522
+ private
523
+ #######
524
+
525
+ def reload_providers
526
+ model = @treeview_providers.model
527
+ model.clear
528
+ BookProviders.each_with_index do |x, index|
529
+ iter = model.append
530
+ if x.enabled
531
+ iter[0] = x.fullname
532
+ else
533
+ iter[0] = "<i>#{x.fullname}</i>"
534
+ end
535
+ iter[1] = x.name
536
+ iter[2] = x.enabled
537
+ iter[3] = index
538
+ end
539
+ end
540
+
541
+ def selected_provider
542
+ iter = @treeview_providers.selection.selected
543
+ unless iter.nil?
544
+ BookProviders.find { |x| x.name == iter[1] }
545
+ end
546
+ end
547
+
548
+ def adjust_selected_provider(prov)
549
+ iter = @treeview_providers.selection.selected
550
+ if prov.enabled
551
+ iter[0] = prov.fullname
552
+ else
553
+ iter[0] = "<i>#{prov.fullname}</i>"
554
+ end
555
+ iter[2] = prov.enabled
556
+ end
557
+
558
+ def sensitize_providers
559
+ model = @treeview_providers.model
560
+ sel_iter = @treeview_providers.selection.selected
561
+ if sel_iter.nil?
562
+ # No selection, we are probably called by ListStore#clear
563
+ @button_prov_up.sensitive = false
564
+ @button_prov_down.sensitive = false
565
+ @button_prov_setup.sensitive = false
566
+ @button_prov_remove.sensitive = false
567
+ else
568
+ last_iter = model.get_iter((BookProviders.length - 1).to_s)
569
+ @button_prov_up.sensitive = sel_iter != model.iter_first
570
+ @button_prov_down.sensitive = sel_iter != last_iter
571
+ provider = BookProviders.find { |x| x.name == sel_iter[1] }
572
+ @button_prov_setup.sensitive = !prefs_empty(provider.prefs)
573
+ @button_prov_remove.sensitive = provider.abstract?
574
+ end
575
+ end
576
+
577
+ def update_priority
578
+ priority = []
579
+ @treeview_providers.model.each do |_model, _path, iter|
580
+ priority << iter[1]
581
+ end
582
+ Preferences.instance.providers_priority = priority
583
+ BookProviders.update_priority
584
+ end
585
+ end
586
+ end
587
+ end