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,81 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2008 Joseph Method
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
+ BOOKS_TARGET_TABLE = [['ALEXANDRIA_BOOKS', Gtk::Drag::TARGET_SAME_APP, 0]]
22
+
23
+ module DragAndDropable
24
+ BADGE_MARKUP = "<span weight=\"heavy\" foreground=\"white\">%d</span>"
25
+
26
+ def setup_view_source_dnd(view)
27
+ # better be Loggable!
28
+ log.info { 'setup_view_source_dnd for %s' % view }
29
+ view.signal_connect_after('drag-begin') do |_widget, drag_context|
30
+ n_books = @parent.selected_books.length
31
+ if n_books > 1
32
+ # Render generic book icon.
33
+ pixmap, mask = Icons::BOOK_ICON.render_pixmap_and_mask(255)
34
+
35
+ # Create number badge.
36
+ context = Gdk::Pango.context
37
+ layout = Pango::Layout.new(context)
38
+ layout.markup = BADGE_MARKUP % n_books
39
+ width, height = layout.pixel_size
40
+ x = Icons::BOOK_ICON.width - width - 11
41
+ y = Icons::BOOK_ICON.height - height - 11
42
+
43
+ # Draw a red ellipse where the badge number should be.
44
+ red_gc = Gdk::GC.new(pixmap)
45
+ red_gc.rgb_fg_color = Gdk::Color.parse('red')
46
+ red_gc.rgb_bg_color = Gdk::Color.parse('red')
47
+ pixmap.draw_arc(red_gc,
48
+ true,
49
+ x - 5, y - 2,
50
+ width + 9, height + 4,
51
+ 0, 360 * 64)
52
+
53
+ # Draw the number badge.
54
+ pixmap.draw_layout(Gdk::GC.new(pixmap), x, y, layout)
55
+
56
+ # And set the drag icon.
57
+ Gtk::Drag.set_icon(drag_context,
58
+ pixmap.colormap,
59
+ pixmap,
60
+ mask,
61
+ 10,
62
+ 10)
63
+ end
64
+ end
65
+
66
+ view.signal_connect('drag-data-get') do |_widget, _drag_context, selection_data, _info, _time|
67
+
68
+ idents = @parent.selected_books.map(&:ident)
69
+ unless idents.empty?
70
+ selection_data.set(Gdk::Selection::TYPE_STRING,
71
+ idents.join(','))
72
+ end
73
+ end
74
+
75
+ view.enable_model_drag_source(Gdk::Window::BUTTON1_MASK,
76
+ Alexandria::UI::BOOKS_TARGET_TABLE,
77
+ Gdk::DragContext::ACTION_MOVE)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,88 @@
1
+ # -*- ruby -*-
2
+ #--
3
+ # Copyright (C) 2010 Cathal Mc Ginley
4
+ # Modifications Copyright (C) 2011 Matijs van Zuijlen
5
+ #
6
+ # This file is part of Alexandria, a GNOME book collection manager.
7
+ #
8
+ # Alexandria is free software; you can redistribute it and/or modify it
9
+ # under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # Alexandria is distributed in the hope that it will be useful, but
14
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with Alexandria; see the file COPYING. If not, write to the Free
20
+ # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
+ # MA 02110-1301 USA.
22
+ #++
23
+
24
+ # Taken from a tip on the ruby-gnome2 website
25
+ # http://ruby-gnome2.sourceforge.jp/hiki.cgi?tips_threads
26
+
27
+ # First, force all your your Ruby threads to start from within the
28
+ # main loop using the standard Gtk.init method. You can call Gtk.init
29
+ # as many times as necessary. For example:
30
+ #
31
+ # Gtk.init_add do
32
+ # DBus.start_listener
33
+ # false
34
+ # end
35
+
36
+ require 'gtk2'
37
+ require 'monitor'
38
+
39
+ module Gtk
40
+ GTK_PENDING_BLOCKS = []
41
+ GTK_PENDING_BLOCKS_LOCK = Monitor.new
42
+
43
+ def self.queue(&block)
44
+ if Thread.current == Thread.main
45
+ block.call
46
+ else
47
+ GTK_PENDING_BLOCKS_LOCK.synchronize do
48
+ GTK_PENDING_BLOCKS << block
49
+ end
50
+ end
51
+ end
52
+
53
+ # an optional addition from http://www.ruby-forum.com/topic/125038
54
+ # "I call Gtk.thread_flush right after killing a thread when I ever
55
+ # happen to need kill a thread" -- Mathieu Blondel
56
+
57
+ # def self.thread_flush
58
+ # if PENDING_CALLS_MUTEX.try_lock
59
+ # for closure in PENDING_CALLS
60
+ # closure.call
61
+ # end
62
+ # PENDING_CALLS.clear
63
+ # PENDING_CALLS_MUTEX.unlock
64
+ # end
65
+ # end
66
+
67
+ def self.main_with_queue(timeout = 100) # millis
68
+ Gtk.timeout_add(timeout) do
69
+ GTK_PENDING_BLOCKS_LOCK.synchronize do
70
+ for block in GTK_PENDING_BLOCKS
71
+ block.call
72
+ end
73
+ GTK_PENDING_BLOCKS.clear
74
+ end
75
+ true
76
+ end
77
+ Gtk.main
78
+ end
79
+ end
80
+
81
+ # Usage is very simple:
82
+
83
+ # Start your Gtk application by calling Gtk.main_with_queue rather
84
+ # than Gtk.main. The "timeout" argument is in milliseconds, and it is
85
+ # the maximum time that can pass until queued blocks get called: 100
86
+ # should be fine.
87
+
88
+ # Whenever you need to queue a call, use Gtk.queue. For example:
@@ -0,0 +1,100 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 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
+ class Gdk::Pixbuf
20
+ def tag(tag_pixbuf)
21
+ # Computes some tweaks.
22
+ tweak_x = tag_pixbuf.width / 3
23
+ tweak_y = tag_pixbuf.height / 3
24
+
25
+ # Creates the destination pixbuf.
26
+ new_pixbuf = Gdk::Pixbuf.new(Gdk::Pixbuf::COLORSPACE_RGB,
27
+ true,
28
+ 8,
29
+ width + tweak_x,
30
+ height + tweak_y)
31
+
32
+ # Fills with blank.
33
+ new_pixbuf.fill!(0)
34
+
35
+ # Copies the current pixbuf there (south-west).
36
+ copy_area(0, 0,
37
+ width, height,
38
+ new_pixbuf,
39
+ 0, tweak_y)
40
+
41
+ # Copies the tag pixbuf there (north-est).
42
+ tag_pixbuf_x = width - (tweak_x * 2)
43
+ new_pixbuf.composite!(tag_pixbuf,
44
+ 0, 0,
45
+ tag_pixbuf.width + tag_pixbuf_x,
46
+ tag_pixbuf.height,
47
+ tag_pixbuf_x, 0,
48
+ 1, 1,
49
+ Gdk::Pixbuf::INTERP_HYPER, 255)
50
+ new_pixbuf
51
+ end
52
+ end
53
+
54
+ module Alexandria
55
+ module UI
56
+ module Icons
57
+ ICONS_DIR = File.join(Alexandria::Config::DATA_DIR, 'icons')
58
+ def self.init
59
+ load_icon_images
60
+ end
61
+
62
+ # loads icons from icons_dir location and gives them as uppercase constants to
63
+ # Alexandria::UI::Icons namespace, e.g., Icons::STAR_SET
64
+ def self.load_icon_images
65
+ Dir.entries(ICONS_DIR).each do |file|
66
+ next unless file =~ /\.png$/ # skip non '.png' files
67
+ # Don't use upcase and use tr instead
68
+ # For example in Turkish the upper case of 'i' is still 'i'.
69
+ name = File.basename(file, '.png').tr('a-z', 'A-Z')
70
+ const_set(name, Gdk::Pixbuf.new(File.join(ICONS_DIR, file)))
71
+ end
72
+ end
73
+
74
+ def self.cover(library, book)
75
+ begin
76
+ return BOOK_ICON if library.nil?
77
+ filename = library.cover(book)
78
+ if File.exist?(filename)
79
+ return Gdk::Pixbuf.new(filename)
80
+ end
81
+ rescue => err
82
+ # report load error; FIX should go to a Logger...
83
+ puts err.message
84
+ puts err.backtrace.join("\n> ")
85
+ puts "Failed to load Gdk::Pixbuf, please ensure that from #{filename} is a valid image file"
86
+ end
87
+ BOOK_ICON
88
+ end
89
+
90
+ def self.blank?(filename)
91
+ pixbuf = Gdk::Pixbuf.new(filename)
92
+ pixbuf.width == 1 and pixbuf.height == 1
93
+ rescue => err
94
+ puts err.message
95
+ puts err.backtrace.join("\n> ")
96
+ true
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,91 @@
1
+ # Copyright (C) 2004-2006 Laurent Sansonetti
2
+ # Copyright (C) 2008 Joseph Method
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/ui/iconview_tooltips'
20
+
21
+ module Alexandria
22
+ module UI
23
+ module Columns
24
+ COVER_LIST, COVER_ICON, TITLE, TITLE_REDUCED, AUTHORS,
25
+ ISBN, PUBLISHER, PUBLISH_DATE, EDITION, RATING, IDENT,
26
+ NOTES, REDD, OWN, WANT, TAGS = (0..16).to_a
27
+ end
28
+
29
+ class IconViewManager
30
+ ICON_WIDTH = 60
31
+ include Logging
32
+ include GetText
33
+ include DragAndDropable
34
+ def initialize(_iconview, parent)
35
+ @parent = parent
36
+ @iconview = @parent.iconview
37
+ @tooltips = IconViewTooltips.new(@iconview)
38
+ @iconview_model = @parent.iconview_model
39
+ @filtered_model = @parent.filtered_model
40
+ @actiongroup = @parent.actiongroup
41
+ setup_books_iconview
42
+ end
43
+
44
+ def setup_books_iconview
45
+ log.info { "setup_books_iconview #{@iconview_model.inspect}" }
46
+ @iconview.model = @iconview_model
47
+ log.info { "now @iconview.model = #{@iconview.model.inspect}" }
48
+ @iconview.selection_mode = Gtk::SELECTION_MULTIPLE
49
+ @iconview.text_column = Columns::TITLE_REDUCED
50
+ @iconview.pixbuf_column = Columns::COVER_ICON
51
+ @iconview.orientation = Gtk::ORIENTATION_VERTICAL
52
+ @iconview.row_spacing = 4
53
+ @iconview.column_spacing = 16
54
+ @iconview.item_width = ICON_WIDTH + 16
55
+
56
+ @iconview.signal_connect('selection-changed') do
57
+ log.debug { 'selection-changed' }
58
+ @tooltips.hide_tooltip
59
+ @parent.on_books_selection_changed
60
+ end
61
+
62
+ @iconview.signal_connect('item-activated') do
63
+ log.debug { 'item-activated' }
64
+ # Dirty hack to avoid the beginning of a drag within this
65
+ # handler.
66
+ @tooltips.hide_tooltip
67
+ Gtk.timeout_add(100) do
68
+ @actiongroup['Properties'].activate
69
+ false
70
+ end
71
+ end
72
+
73
+ # DND support for Gtk::IconView is shipped since GTK+ 2.8.0.
74
+ if @iconview.respond_to?(:enable_model_drag_source)
75
+ setup_view_source_dnd(@iconview)
76
+ end
77
+ end
78
+
79
+ ICONS_SORTS = [
80
+ Columns::TITLE, Columns::AUTHORS, Columns::ISBN,
81
+ Columns::PUBLISHER, Columns::EDITION, Columns::RATING, Columns::REDD, Columns::OWN, Columns::WANT
82
+ ]
83
+ def setup_books_iconview_sorting
84
+ mode = ICONS_SORTS[@prefs.arrange_icons_mode]
85
+ @iconview_model.set_sort_column_id(mode,
86
+ @prefs.reverse_icons ? Gtk::SORT_DESCENDING : Gtk::SORT_ASCENDING)
87
+ @filtered_model.refilter # force redraw
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,162 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # Copyright (C) 2007 kksou
4
+ # Copyright (C) 2008,2009 Cathal Mc Ginley
5
+ # Modifications Copyright (C) 2011 Matijs van Zuijlen
6
+ #
7
+ # Alexandria is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License as
9
+ # published by the Free Software Foundation; either version 2 of the
10
+ # License, or (at your option) any later version.
11
+ #
12
+ # Alexandria is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public
18
+ # License along with Alexandria; see the file COPYING. If not,
19
+ # write to the Free Software Foundation, Inc., 51 Franklin Street,
20
+ # Fifth Floor, Boston, MA 02110-1301 USA.
21
+
22
+ # Please retain the following note:
23
+ #
24
+ # Based upon Recipe 168 - "How to display tooltips in GtkTreeView - Part 3"
25
+ # from the "php-gtk2 Cookbook" website, by kksou.
26
+ # http://www.kksou.com/php-gtk2/articles/display-tooltips-in-GtkTreeView---Part-3---no-hardcoding-of-header-height.php
27
+ #
28
+ # Ported to ruby-gtk2 (and modified for IconView) by Cathal Mc Ginley
29
+
30
+ require 'cgi'
31
+
32
+ class IconViewTooltips
33
+ include Alexandria::Logging
34
+
35
+ def initialize(view)
36
+ @tooltip_window = Gtk::Window.new(Gtk::Window::POPUP)
37
+ @tooltip_window.name = 'gtk-tooltips'
38
+ @tooltip_window.resizable = false
39
+ @tooltip_window.border_width = 4
40
+ @tooltip_window.app_paintable = true
41
+
42
+ @tooltip_window.signal_connect('expose_event') { |window, event|
43
+ on_expose(window, event) }
44
+
45
+ @tooltip_window.signal_connect('leave_notify_event') { |vw, event|
46
+ on_leave(vw, event) }
47
+
48
+ @label = Gtk::Label.new('')
49
+ @label.wrap = true
50
+ @label.set_alignment(0.5, 0.5)
51
+ @label.use_markup = true
52
+ @label.show
53
+
54
+ @tooltip_window.add(@label)
55
+ set_view(view)
56
+ end
57
+
58
+ def set_view(view)
59
+ view.signal_connect('motion_notify_event') { |vw, event|
60
+ on_motion(vw, event) }
61
+ view.signal_connect('leave_notify_event') { |vw, event|
62
+ on_leave(vw, event) }
63
+ end
64
+
65
+ def on_expose(window, _event)
66
+ # this paints a nice outline around the label
67
+ size = window.size_request
68
+ window.style.paint_flat_box(window.window,
69
+ Gtk::STATE_NORMAL,
70
+ Gtk::SHADOW_OUT,
71
+ nil,
72
+ @tooltip_window,
73
+ 'tooltip',
74
+ 0, 0, size[0], size[1])
75
+ # must return nil so the label contents get drawn correctly
76
+ nil
77
+ end
78
+
79
+ def label_for_book(title, authors, publisher, year)
80
+ # This is much too complex... but it works for now!
81
+ html = ''
82
+ if title.size > 0
83
+ html += "<b>#{CGI.escapeHTML(title)}</b>"
84
+ if authors.size > 0
85
+ html += "\n"
86
+ end
87
+ end
88
+ if authors.size > 0
89
+ html += "<i>#{CGI.escapeHTML(authors)}</i>"
90
+ end
91
+ if (title.size > 0) or (authors.size > 0)
92
+ html += "\n"
93
+ end
94
+
95
+ html += '<small>'
96
+ if publisher and publisher.size > 0
97
+ html += "#{CGI.escapeHTML(publisher)}"
98
+ end
99
+
100
+ if year and year.size > 0
101
+ if publisher and publisher.size > 0
102
+ html += ' '
103
+ end
104
+ html += "(#{year})"
105
+ end
106
+
107
+ html + '</small>'
108
+ end
109
+
110
+ def on_motion(view, event)
111
+ tree_path = view.get_path(event.x, event.y)
112
+ # TODO translate path a few times, for sorting & filtering...
113
+ # hmmm, actually seems to work. Report a bug if you can spot a failure
114
+ if tree_path
115
+ iter = view.model.get_iter(tree_path)
116
+ if @latest_iter.nil?
117
+ @latest_iter = iter
118
+
119
+ @tooltip_timeout_id = Gtk.timeout_add(250) do
120
+ if @latest_iter == iter
121
+
122
+ title = iter[2] # HACK hardcoded, should use column names...
123
+ authors = iter[4]
124
+ publisher = iter[6]
125
+ year = iter[7]
126
+ @label.markup = label_for_book(title, authors, publisher, year)
127
+ ## "<b>#{title}</b>\n<i>#{authors}</i>\n<small>#{publisher} <i>(#{year})</i></small>"
128
+ size = @tooltip_window.size_request
129
+ @tooltip_window.move(event.x_root - size[0],
130
+ event.y_root + 12)
131
+ @tooltip_window.show
132
+ # don't run again
133
+ false
134
+ else
135
+ @tooltip_timeout_id = nil
136
+ end
137
+ end
138
+
139
+ elsif @latest_iter != iter
140
+ hide_tooltip
141
+ end
142
+
143
+ else
144
+ hide_tooltip
145
+ end
146
+ end
147
+
148
+ def hide_tooltip
149
+ unless @tooltip_window.nil?
150
+ @tooltip_window.hide
151
+ if @tooltip_timeout_id
152
+ Gtk.timeout_remove(@tooltip_timeout_id)
153
+ @tooltip_timeout_id = nil
154
+ end
155
+ @latest_iter = nil
156
+ end
157
+ end
158
+
159
+ def on_leave(_view, _event)
160
+ @tooltip_window.hide
161
+ end
162
+ end