alexandria-book-collection-manager 0.7.3 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +77 -0
  4. data/.gitignore +4 -1
  5. data/.rubocop.yml +86 -36
  6. data/.rubocop_todo.yml +58 -161
  7. data/.simplecov +5 -2
  8. data/CHANGELOG.md +56 -2
  9. data/Gemfile +4 -3
  10. data/INSTALL.md +23 -11
  11. data/README.md +52 -41
  12. data/Rakefile +78 -75
  13. data/alexandria-book-collection-manager.gemspec +50 -44
  14. data/bin/alexandria +12 -22
  15. data/doc/FAQ +1 -2
  16. data/doc/dependency_decisions.yml +27 -8
  17. data/lib/alexandria.rb +25 -23
  18. data/lib/alexandria/about.rb +50 -50
  19. data/lib/alexandria/book_providers.rb +86 -91
  20. data/lib/alexandria/book_providers/adlibris.rb +37 -74
  21. data/lib/alexandria/book_providers/amazon_aws.rb +94 -100
  22. data/lib/alexandria/book_providers/amazon_ecs_util.rb +289 -324
  23. data/lib/alexandria/book_providers/barnes_and_noble.rb +42 -42
  24. data/lib/alexandria/book_providers/douban.rb +25 -41
  25. data/lib/alexandria/book_providers/proxis.rb +34 -29
  26. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  27. data/lib/alexandria/book_providers/siciliano.rb +60 -64
  28. data/lib/alexandria/book_providers/thalia_provider.rb +161 -0
  29. data/lib/alexandria/book_providers/web.rb +5 -5
  30. data/lib/alexandria/book_providers/worldcat.rb +66 -95
  31. data/lib/alexandria/book_providers/z3950.rb +153 -169
  32. data/lib/alexandria/config.rb +1 -1
  33. data/lib/alexandria/console.rb +3 -3
  34. data/lib/alexandria/default_preferences.rb +37 -0
  35. data/lib/alexandria/execution_queue.rb +13 -12
  36. data/lib/alexandria/export_format.rb +8 -8
  37. data/lib/alexandria/export_library.rb +128 -127
  38. data/lib/alexandria/import_library.rb +102 -126
  39. data/lib/alexandria/import_library_csv.rb +41 -41
  40. data/lib/alexandria/library_collection.rb +6 -5
  41. data/lib/alexandria/library_sort_order.rb +4 -2
  42. data/lib/alexandria/library_store.rb +39 -28
  43. data/lib/alexandria/logging.rb +10 -14
  44. data/lib/alexandria/models/book.rb +5 -4
  45. data/lib/alexandria/models/library.rb +63 -53
  46. data/lib/alexandria/net.rb +5 -6
  47. data/lib/alexandria/preferences.rb +66 -63
  48. data/lib/alexandria/scanners.rb +2 -2
  49. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +17 -17
  50. data/lib/alexandria/scanners/keyboard.rb +8 -8
  51. data/lib/alexandria/smart_library.rb +110 -112
  52. data/lib/alexandria/ui.rb +15 -15
  53. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +2 -2
  54. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +108 -109
  55. data/lib/alexandria/ui/alert_dialog.rb +66 -0
  56. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +13 -9
  57. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  58. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -38
  59. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +64 -157
  60. data/lib/alexandria/ui/builder_base.rb +1 -1
  61. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  62. data/lib/alexandria/ui/callbacks.rb +187 -155
  63. data/lib/alexandria/ui/completion_models.rb +8 -22
  64. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  65. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  66. data/lib/alexandria/ui/dndable.rb +7 -7
  67. data/lib/alexandria/ui/error_dialog.rb +25 -0
  68. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +37 -58
  69. data/lib/alexandria/ui/icons.rb +38 -43
  70. data/lib/alexandria/ui/iconview.rb +12 -10
  71. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  72. data/lib/alexandria/ui/import_dialog.rb +157 -0
  73. data/lib/alexandria/ui/init.rb +30 -41
  74. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +9 -6
  75. data/lib/alexandria/ui/libraries_combo.rb +15 -14
  76. data/lib/alexandria/ui/listview.rb +69 -67
  77. data/lib/alexandria/ui/main_app.rb +24 -26
  78. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  79. data/lib/alexandria/ui/multi_drag_treeview.rb +8 -9
  80. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +113 -114
  81. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +22 -19
  82. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  83. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  84. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  85. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  86. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  87. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +7 -28
  88. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +53 -48
  89. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  90. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  91. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  92. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  93. data/lib/alexandria/ui/sound.rb +11 -13
  94. data/lib/alexandria/ui/ui_manager.rb +216 -200
  95. data/lib/alexandria/version.rb +4 -19
  96. data/lib/alexandria/web_themes.rb +21 -21
  97. data/po/Makefile +2 -2
  98. data/po/cs.po +992 -875
  99. data/po/cy.po +961 -874
  100. data/po/de.po +990 -865
  101. data/po/el.po +989 -865
  102. data/po/es.po +985 -861
  103. data/po/fr.po +987 -867
  104. data/po/ga.po +908 -820
  105. data/po/gl.po +980 -860
  106. data/po/it.po +986 -864
  107. data/po/ja.po +969 -849
  108. data/po/mk.po +984 -860
  109. data/po/nb.po +979 -859
  110. data/po/nl.po +983 -860
  111. data/po/pl.po +1018 -971
  112. data/po/pt.po +988 -857
  113. data/po/pt_BR.po +983 -863
  114. data/po/ru.po +994 -871
  115. data/po/sk.po +989 -867
  116. data/po/sv.po +976 -856
  117. data/po/uk.po +972 -858
  118. data/po/zh_TW.po +974 -854
  119. data/schemas/alexandria.schemas +24 -2
  120. data/share/alexandria/glade/acquire_dialog__builder.glade +1 -1
  121. data/share/alexandria/glade/book_properties_dialog__builder.glade +1 -1
  122. data/share/alexandria/glade/main_app__builder.glade +6 -21
  123. data/share/alexandria/glade/new_book_dialog__builder.glade +1 -1
  124. data/share/alexandria/glade/preferences_dialog__builder.glade +1 -1
  125. data/share/gnome/help/alexandria/C/introduction.xml +0 -4
  126. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  127. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  128. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  129. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  130. data/share/gnome/help/alexandria/ja/introduction.xml +0 -4
  131. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  132. data/spec/alexandria/book_providers/thalia_provider_spec.rb +119 -0
  133. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  134. data/spec/alexandria/book_providers_spec.rb +62 -156
  135. data/spec/alexandria/book_spec.rb +12 -10
  136. data/spec/alexandria/console_spec.rb +6 -11
  137. data/spec/alexandria/export_library_spec.rb +47 -58
  138. data/spec/alexandria/library_spec.rb +121 -109
  139. data/spec/alexandria/library_store_spec.rb +8 -8
  140. data/spec/alexandria/preferences_spec.rb +44 -17
  141. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  142. data/spec/alexandria/smart_library_spec.rb +15 -15
  143. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  144. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  145. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  146. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/book_properties_dialog_spec.rb +59 -0
  148. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  150. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  152. data/spec/alexandria/ui/icons_spec.rb +26 -0
  153. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  154. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  155. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  156. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  157. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +51 -0
  158. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  159. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  160. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  161. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  162. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  163. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  164. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  165. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  166. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  167. data/spec/alexandria/ui/sound_spec.rb +2 -2
  168. data/spec/alexandria/ui/ui_manager_spec.rb +44 -20
  169. data/spec/end_to_end/basic_run_spec.rb +21 -38
  170. data/spec/fixtures/cover.jpg +0 -0
  171. data/spec/spec_helper.rb +54 -10
  172. data/tasks/setup.rb +2 -2
  173. data/tasks/spec.rake +11 -11
  174. data/util/rake/fileinstall.rb +38 -35
  175. data/util/rake/gettextgenerate.rb +7 -7
  176. data/util/rake/omfgenerate.rb +7 -7
  177. metadata +158 -45
  178. data/dogtail/basic_run_test.py +0 -9
  179. data/lib/alexandria/book_providers/renaud.rb +0 -155
  180. data/lib/alexandria/book_providers/thalia.rb +0 -198
  181. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -63
  182. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -176
  183. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -62
  184. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -563
  185. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -61
  186. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -423
  187. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  188. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  189. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  190. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  191. data/spec/alexandria/utilities_spec.rb +0 -52
  192. data/tasks/dogtail.rake +0 -6
@@ -24,7 +24,7 @@ module Alexandria
24
24
  module ComboBoxOverrides
25
25
  include GetText
26
26
  extend GetText
27
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
27
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
28
28
 
29
29
  def populate_with_libraries(libraries, selected_library)
30
30
  libraries_names = libraries.map(&:name)
@@ -33,28 +33,22 @@ module Alexandria
33
33
  libraries_names.unshift selected_library.name
34
34
  end
35
35
  clear
36
- set_row_separator_func do |model, iter|
37
- # TODO: Replace with iter[1] if possible
38
- model.get_value(iter, 1) == '-'
39
- end
40
36
  self.model = Gtk::ListStore.new(GdkPixbuf::Pixbuf, String, TrueClass)
41
37
  libraries_names.each do |library_name|
42
- iter = model.append
43
- iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL
44
- iter[1] = library_name
45
- iter[2] = false
38
+ append_entry(Alexandria::UI::Icons::LIBRARY_SMALL, library_name, false)
46
39
  end
47
- model.append[1] = '-'
48
- iter = model.append
49
- iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL
50
- iter[1] = _('New Library')
51
- iter[2] = true
40
+ append_entry(nil, "-", nil)
41
+ append_entry(Alexandria::UI::Icons::LIBRARY_SMALL, _("New Library"), true)
52
42
  renderer = Gtk::CellRendererPixbuf.new
53
43
  pack_start(renderer, false)
54
44
  set_attributes(renderer, pixbuf: 0)
55
45
  renderer = Gtk::CellRendererText.new
56
46
  pack_start(renderer, true)
57
47
  set_attributes(renderer, text: 1)
48
+ set_row_separator_func do |model, iter|
49
+ # TODO: Replace with iter[1] if possible
50
+ model.get_value(iter, 1) == "-"
51
+ end
58
52
  self.active = 0
59
53
  # self.sensitive = libraries.length > 1
60
54
  # This prohibits us from adding a "New Library" from this combo
@@ -79,6 +73,13 @@ module Alexandria
79
73
 
80
74
  [library, is_new]
81
75
  end
76
+
77
+ def append_entry(icon, label, is_new)
78
+ iter = model.append
79
+ iter[0] = icon
80
+ iter[1] = label
81
+ iter[2] = is_new
82
+ end
82
83
  end
83
84
  end
84
85
 
@@ -4,18 +4,18 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
- require 'alexandria/ui/columns'
7
+ require "alexandria/ui/columns"
8
8
 
9
9
  module Alexandria
10
10
  module UI
11
11
  include Logging
12
12
  include GetText
13
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
13
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
14
14
  class ListViewManager
15
15
  include Logging
16
16
  include GetText
17
17
  include DragAndDropable
18
- BOOKS_TARGET_TABLE = [['ALEXANDRIA_BOOKS', :same_app, 0]].freeze
18
+ BOOKS_TARGET_TABLE = [["ALEXANDRIA_BOOKS", :same_app, 0]].freeze
19
19
 
20
20
  def initialize(_listview, parent)
21
21
  @parent = parent
@@ -29,18 +29,18 @@ module Alexandria
29
29
  end
30
30
 
31
31
  def setup_title_column
32
- title = _('Title')
33
- log.debug { format('Create listview column for %s', title) }
32
+ title = _("Title")
33
+ log.debug { format("Create listview column for %s", title) }
34
34
  column = Gtk::TreeViewColumn.new(title)
35
35
 
36
36
  renderer = Gtk::CellRendererPixbuf.new
37
37
  column.pack_start(renderer, false)
38
- column.add_attribute(renderer, 'pixbuf', Columns::COVER_LIST)
38
+ column.add_attribute(renderer, "pixbuf", Columns::COVER_LIST)
39
39
 
40
40
  renderer = Gtk::CellRendererText.new
41
41
  renderer.ellipsize = :end
42
42
  column.pack_start(renderer, true)
43
- column.add_attribute(renderer, 'text', Columns::TITLE)
43
+ column.add_attribute(renderer, "text", Columns::TITLE)
44
44
 
45
45
  column.sort_column_id = Columns::TITLE
46
46
  column.resizable = true
@@ -48,21 +48,21 @@ module Alexandria
48
48
  end
49
49
 
50
50
  TEXT_COLUMNS = [
51
- [_('Authors'), Columns::AUTHORS],
52
- [_('ISBN'), Columns::ISBN],
53
- [_('Publisher'), Columns::PUBLISHER],
54
- [_('Publish Year'), Columns::PUBLISH_DATE],
55
- [_('Binding'), Columns::EDITION],
56
- [_('Loaned To'), Columns::LOANED_TO]
51
+ [_("Authors"), Columns::AUTHORS],
52
+ [_("ISBN"), Columns::ISBN],
53
+ [_("Publisher"), Columns::PUBLISHER],
54
+ [_("Publish Year"), Columns::PUBLISH_DATE],
55
+ [_("Binding"), Columns::EDITION],
56
+ [_("Loaned To"), Columns::LOANED_TO]
57
57
  ].freeze
58
58
  CHECK_COLUMNS = [
59
- [_('Read'), Columns::REDD],
60
- [_('Own'), Columns::OWN],
61
- [_('Want'), Columns::WANT]
59
+ [_("Read"), Columns::REDD],
60
+ [_("Own"), Columns::OWN],
61
+ [_("Want"), Columns::WANT]
62
62
  ].freeze
63
63
 
64
64
  def setup_books_listview
65
- log.debug { 'setup_books_listview' }
65
+ log.debug { "setup_books_listview" }
66
66
  @listview.model = @listview_model
67
67
  setup_title_column
68
68
  TEXT_COLUMNS.each do |title, iterid|
@@ -73,8 +73,8 @@ module Alexandria
73
73
  end
74
74
  setup_rating_column
75
75
  @listview.selection.mode = :multiple
76
- @listview.selection.signal_connect('changed') do
77
- log.debug { 'changed' }
76
+ @listview.selection.signal_connect("changed") do
77
+ log.debug { "changed" }
78
78
  @parent.on_books_selection_changed
79
79
  end
80
80
  setup_tags_column
@@ -83,9 +83,8 @@ module Alexandria
83
83
  end
84
84
 
85
85
  def setup_tags_column
86
- # adding tags column...
87
- title = _('Tags')
88
- log.debug { 'Create listview column for tags...' }
86
+ title = _("Tags")
87
+ log.debug { "Create listview column for tags" }
89
88
  renderer = Gtk::CellRendererText.new
90
89
  renderer.ellipsize = :end
91
90
  column = Gtk::TreeViewColumn.new(title, renderer,
@@ -96,16 +95,16 @@ module Alexandria
96
95
  end
97
96
 
98
97
  def setup_row_activation
99
- @listview.signal_connect('row-activated') do
100
- log.debug { 'row-activated' }
101
- @actiongroup['Properties'].activate
98
+ @listview.signal_connect("row-activated") do
99
+ log.debug { "row-activated" }
100
+ @actiongroup["Properties"].activate
102
101
  false
103
102
  end
104
103
  end
105
104
 
106
105
  def setup_rating_column
107
- title = _('Rating')
108
- log.debug { format('Create listview column for %s...', title) }
106
+ title = _("Rating")
107
+ log.debug { format("Create listview column for %s", title) }
109
108
  column = Gtk::TreeViewColumn.new(title)
110
109
  column.sizing = :fixed
111
110
  width = (Icons::STAR_SET.width + 1) * Book::MAX_RATING_STARS
@@ -127,56 +126,56 @@ module Alexandria
127
126
  def setup_check_column(title, iterid)
128
127
  renderer = CellRendererToggle.new
129
128
  renderer.activatable = true
130
- renderer.signal_connect('toggled') do |_rndrr, path|
131
- begin
132
- tree_path = Gtk::TreePath.new(path)
133
- child_path = @listview_model.convert_path_to_child_path(tree_path)
134
- if child_path
135
- unfiltered_path = @filtered_model.convert_path_to_child_path(child_path)
136
- # FIX this sometimes returns a nil path for iconview...
137
- if unfiltered_path
138
- iter = @model.get_iter(unfiltered_path)
139
- if iter
140
- book = @parent.book_from_iter(@parent.selected_library, iter)
141
- toggle_state = case iterid
142
- when Columns::REDD then book.redd
143
- when Columns::OWN then book.own
144
- when Columns::WANT then book.want
145
- end
146
- # invert toggle_state
147
- unless iterid == Columns::WANT && book.own
148
- toggle_state = !toggle_state
149
- case iterid
150
- when Columns::REDD then book.redd = toggle_state
151
- when Columns::OWN then book.own = toggle_state
152
- when Columns::WANT then book.want = toggle_state
153
- end
154
- iter[iterid] = toggle_state
155
- lib = @parent.selected_library
156
- lib.save(book)
129
+ renderer.signal_connect("toggled") do |_rndrr, path|
130
+ tree_path = Gtk::TreePath.new(path)
131
+ child_path = @listview_model.convert_path_to_child_path(tree_path)
132
+ if child_path
133
+ unfiltered_path = @filtered_model.convert_path_to_child_path(child_path)
134
+ # FIX this sometimes returns a nil path for iconview...
135
+ if unfiltered_path
136
+ iter = @model.get_iter(unfiltered_path)
137
+ if iter
138
+ book = @parent.book_from_iter(@parent.selected_library, iter)
139
+ toggle_state = case iterid
140
+ when Columns::REDD then book.redd
141
+ when Columns::OWN then book.own
142
+ when Columns::WANT then book.want
143
+ end
144
+ # invert toggle_state
145
+ unless iterid == Columns::WANT && book.own
146
+ toggle_state = !toggle_state
147
+ case iterid
148
+ when Columns::REDD then book.redd = toggle_state
149
+ when Columns::OWN then book.own = toggle_state
150
+ when Columns::WANT then book.want = toggle_state
157
151
  end
152
+ iter[iterid] = toggle_state
153
+ lib = @parent.selected_library
154
+ lib.save(book)
158
155
  end
159
156
  end
160
-
161
157
  end
162
- rescue StandardError => e
163
- log.error { "toggle failed for path #{path} #{e}\n" + e.backtrace.join("\n") }
158
+
164
159
  end
160
+ rescue StandardError => ex
161
+ log.error { "toggle failed for path #{path} #{ex}\n" + e.backtrace.join("\n") }
165
162
  end
166
163
  column = Gtk::TreeViewColumn.new(title, renderer, text: iterid)
167
164
  column.sort_column_id = iterid
168
165
  column.resizable = true
169
- log.debug { format('Create listview column for %s...', title) }
166
+ log.debug { format("Create listview column for %s", title) }
170
167
 
171
- column.add_attribute(renderer, 'active', iterid)
172
- column.add_attribute(renderer, 'inconsistent', Columns::OWN) if iterid == Columns::WANT
168
+ column.add_attribute(renderer, "active", iterid)
169
+ if iterid == Columns::WANT
170
+ column.add_attribute(renderer, "inconsistent", Columns::OWN)
171
+ end
173
172
 
174
173
  log.debug { "append_column #{column}" }
175
174
  @listview.append_column(column)
176
175
  end
177
176
 
178
177
  def setup_text_column(title, iterid)
179
- log.debug { format('Create listview column for %s...', title) }
178
+ log.debug { format("Create listview column for %s", title) }
180
179
  renderer = Gtk::CellRendererText.new
181
180
  renderer.ellipsize = :end
182
181
  column = Gtk::TreeViewColumn.new(title, renderer,
@@ -187,7 +186,7 @@ module Alexandria
187
186
  end
188
187
 
189
188
  def setup_listview_columns_visibility
190
- log.debug { 'setup_listview_columns_visibility' }
189
+ log.debug { "setup_listview_columns_visibility" }
191
190
  # Show or hide list view columns according to the preferences.
192
191
  cols_visibility = [
193
192
  @prefs.col_authors_visible,
@@ -206,7 +205,10 @@ module Alexandria
206
205
  cols.each_index do |i|
207
206
  cols[i].visible = cols_visibility[i]
208
207
  end
209
- log.debug { 'Columns visibility: ' + cols.map { |col| "#{col.title} #{col.visible?}" }.join(', ') }
208
+ log.debug do
209
+ "Columns visibility: " +
210
+ cols.map { |col| "#{col.title} #{col.visible?}" }.join(", ")
211
+ end
210
212
  end
211
213
 
212
214
  # Sets the width of each column based on any respective
@@ -227,10 +229,10 @@ module Alexandria
227
229
  end
228
230
  end
229
231
  end
230
- log.debug {
231
- 'Columns width: ' +
232
- @listview.columns.map { |col| "#{col.title} #{col.width}" }.join(', ')
233
- }
232
+ log.debug do
233
+ "Columns width: " +
234
+ @listview.columns.map { |col| "#{col.title} #{col.width}" }.join(", ")
235
+ end
234
236
  end
235
237
  end
236
238
  end
@@ -19,43 +19,41 @@
19
19
  # write to the Free Software Foundation, Inc., 51 Franklin Street,
20
20
  # Fifth Floor, Boston, MA 02110-1301 USA.
21
21
 
22
- require 'alexandria/ui/dialogs/alert_dialog'
23
- # misc_dialogs depends on alert_dialog
24
- require 'alexandria/ui/dialogs/misc_dialogs'
25
- require 'alexandria/ui/dialogs/about_dialog'
26
- require 'alexandria/ui/dialogs/book_properties_dialog_base'
27
- require 'alexandria/ui/dialogs/book_properties_dialog'
28
- require 'alexandria/ui/dialogs/new_book_dialog_manual'
29
- require 'alexandria/ui/dialogs/new_book_dialog'
30
- require 'alexandria/ui/dialogs/preferences_dialog'
31
- require 'alexandria/ui/dialogs/export_dialog'
32
- require 'alexandria/ui/dialogs/import_dialog'
33
- require 'alexandria/ui/dialogs/acquire_dialog'
34
- require 'alexandria/ui/dialogs/smart_library_properties_dialog_base'
35
- require 'alexandria/ui/dialogs/smart_library_properties_dialog'
36
- require 'alexandria/ui/dialogs/new_smart_library_dialog'
37
- require 'alexandria/ui/dialogs/bad_isbns_dialog'
38
- require 'alexandria/ui/dndable'
39
- require 'alexandria/ui/init'
40
- require 'alexandria/ui/ui_manager'
41
- require 'alexandria/ui/listview'
42
- require 'alexandria/ui/iconview'
43
- require 'alexandria/ui/sidepane'
22
+ require "alexandria/ui/alert_dialog"
23
+ require "alexandria/ui/about_dialog"
24
+ require "alexandria/ui/book_properties_dialog_base"
25
+ require "alexandria/ui/book_properties_dialog"
26
+ require "alexandria/ui/new_book_dialog_manual"
27
+ require "alexandria/ui/new_book_dialog"
28
+ require "alexandria/ui/preferences_dialog"
29
+ require "alexandria/ui/export_dialog"
30
+ require "alexandria/ui/import_dialog"
31
+ require "alexandria/ui/acquire_dialog"
32
+ require "alexandria/ui/smart_library_properties_dialog_base"
33
+ require "alexandria/ui/smart_library_properties_dialog"
34
+ require "alexandria/ui/new_smart_library_dialog"
35
+ require "alexandria/ui/bad_isbns_dialog"
36
+ require "alexandria/ui/dndable"
37
+ require "alexandria/ui/init"
38
+ require "alexandria/ui/ui_manager"
39
+ require "alexandria/ui/listview"
40
+ require "alexandria/ui/iconview"
41
+ require "alexandria/ui/sidepane_manager"
44
42
 
45
43
  module Alexandria
46
44
  module UI
47
45
  include Logging
48
46
  include GetText
49
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
47
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
50
48
 
51
49
  class MainApp
52
50
  include Logging
53
51
  include GetText
54
52
  include Singleton
55
- attr_accessor :main_app, :libraries, :actiongroup, :appbar, :prefs
56
- attr_accessor :ui_manager
53
+ attr_accessor :main_app, :libraries, :actiongroup, :appbar, :prefs, :ui_manager
54
+
57
55
  def initialize
58
- log.info { 'Starting MainApp' }
56
+ log.info { "Starting MainApp" }
59
57
  @ui_manager = UIManager.new self
60
58
  @actiongroup = @ui_manager.actiongroup
61
59
  @appbar = @ui_manager.appbar
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ module Alexandria
8
+ module UI
9
+ end
10
+ end
@@ -6,14 +6,14 @@
6
6
 
7
7
  module Alexandria
8
8
  module EventOverrides
9
- def ==(obj)
10
- obj.is_a?(self.class) && (time == obj.time) && (x == obj.x) && (y == obj.y) && (button == obj.button)
9
+ def ==(other)
10
+ other.is_a?(self.class) &&
11
+ (time == other.time) && (x == other.x) && (y == other.y) &&
12
+ (button == other.button)
11
13
  end
12
14
  end
13
15
 
14
16
  module TreeViewOverrides
15
- # include Alexandria::Logging
16
-
17
17
  Context = Struct.new(:pressed_button,
18
18
  :x,
19
19
  :y,
@@ -50,7 +50,7 @@ module Alexandria
50
50
  @context.source_actions = actions
51
51
 
52
52
  @context.button_press_handler =
53
- signal_connect('button_press_event') do |_widget, event, _data|
53
+ signal_connect("button_press_event") do |_widget, event, _data|
54
54
  button_press_event(event)
55
55
  end
56
56
  end
@@ -104,13 +104,12 @@ module Alexandria
104
104
  path, _, cell_x, cell_y = get_path_at_pos(event.x, event.y)
105
105
  return false if path.nil?
106
106
 
107
- # call_parent = (event.state.control_mask? or event.state.shift_mask?) or !selected or event.button != 1
108
107
  (call_parent = !selection.path_is_selected?(path)) ||
109
108
  (event.button != 1)
110
109
 
111
110
  if call_parent
112
111
  signal_handler_block(@context.button_press_handler) do
113
- signal_emit('button_press_event', event)
112
+ signal_emit("button_press_event", event)
114
113
  end
115
114
  end
116
115
 
@@ -122,11 +121,11 @@ module Alexandria
122
121
  @context.cell_x = cell_x
123
122
  @context.cell_y = cell_y
124
123
  @context.motion_notify_handler =
125
- signal_connect('motion_notify_event') do |_widget, evnt, _data|
124
+ signal_connect("motion_notify_event") do |_widget, evnt, _data|
126
125
  motion_notify_event(evnt)
127
126
  end
128
127
  @context.button_release_handler =
129
- signal_connect('button_release_event') do |_widget, evnt, _data|
128
+ signal_connect("button_release_event") do |_widget, evnt, _data|
130
129
  button_release_event(evnt)
131
130
  end
132
131
  @context.events << event unless call_parent
@@ -4,9 +4,10 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
- require 'gdk_pixbuf2'
8
- require 'alexandria/ui/builder_base'
9
- require 'alexandria/ui/dialogs/keep_bad_isbn_dialog'
7
+ require "gdk_pixbuf2"
8
+ require "alexandria/ui/builder_base"
9
+ require "alexandria/ui/error_dialog"
10
+ require "alexandria/ui/keep_bad_isbn_dialog"
10
11
 
11
12
  module Alexandria
12
13
  class DuplicateBookException < NameError
@@ -17,12 +18,12 @@ module Alexandria
17
18
  include Logging
18
19
  include GetText
19
20
  extend GetText
20
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
21
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
21
22
  @@last_criterion_was_not_isbn = false
22
23
 
23
24
  def initialize(parent, selected_library = nil, &block)
24
- super('new_book_dialog__builder.glade', widget_names)
25
- log.info { 'New Book Dialog' }
25
+ super("new_book_dialog__builder.glade", widget_names)
26
+ log.info { "New Book Dialog" }
26
27
  @new_book_dialog.transient_for = @parent = parent
27
28
  @block = block
28
29
  @destroyed = false
@@ -31,6 +32,10 @@ module Alexandria
31
32
  @progressbar.hide
32
33
  end
33
34
 
35
+ def show
36
+ @new_book_dialog.show
37
+ end
38
+
34
39
  def widget_names
35
40
  [:new_book_dialog, :button_add, :button_cancel, :button_find,
36
41
  :button_help, :combo_libraries, :combo_search, :entry_isbn,
@@ -48,12 +53,12 @@ module Alexandria
48
53
  @treeview_results.model = Gtk::ListStore.new(String, String,
49
54
  GdkPixbuf::Pixbuf)
50
55
  @treeview_results.selection.mode = :multiple
51
- @treeview_results.selection.signal_connect('changed') do
56
+ @treeview_results.selection.signal_connect("changed") do
52
57
  @button_add.sensitive = true
53
58
  end
54
59
 
55
60
  renderer = Gtk::CellRendererPixbuf.new
56
- col = Gtk::TreeViewColumn.new('', renderer)
61
+ col = Gtk::TreeViewColumn.new("", renderer)
57
62
  col.set_cell_data_func(renderer) do |_column, cell, _model, iter|
58
63
  pixbuf = iter[2]
59
64
  max_height = 25
@@ -67,7 +72,7 @@ module Alexandria
67
72
  end
68
73
  @treeview_results.append_column(col)
69
74
 
70
- col = Gtk::TreeViewColumn.new('', Gtk::CellRendererText.new,
75
+ col = Gtk::TreeViewColumn.new("", Gtk::CellRendererText.new,
71
76
  text: 0)
72
77
  @treeview_results.append_column(col)
73
78
 
@@ -86,14 +91,14 @@ module Alexandria
86
91
  @find_thread = nil
87
92
  @image_thread = nil
88
93
 
89
- @new_book_dialog.signal_connect('destroy') {
94
+ @new_book_dialog.signal_connect("destroy") do
90
95
  @new_book_dialog.destroy
91
96
  @destroyed = true
92
- }
97
+ end
93
98
  end
94
99
 
95
100
  def on_criterion_toggled(item)
96
- log.debug { 'on_criterion_toggled' }
101
+ log.debug { "on_criterion_toggled" }
97
102
  return unless item.active?
98
103
 
99
104
  # There used to be a strange effect here (pre SVN r1022).
@@ -138,19 +143,19 @@ module Alexandria
138
143
 
139
144
  def on_changed(entry)
140
145
  ok = !entry.text.strip.empty?
141
- decode_cuecat?(@entry_isbn) if entry == @entry_isbn
146
+ decode_cuecat(@entry_isbn) if entry == @entry_isbn
142
147
  (entry == @entry_isbn ? @button_add : @button_find).sensitive = ok
143
148
  end
144
149
 
145
150
  def image_error_dialog(error)
146
151
  ErrorDialog.new(
147
152
  @parent,
148
- _('A problem occurred while downloading images'),
153
+ _("A problem occurred while downloading images"),
149
154
  error)
150
155
  end
151
156
 
152
157
  def get_images_async
153
- log.info { 'get_images_async' }
158
+ log.info { "get_images_async" }
154
159
  @images = {}
155
160
  @image_error = nil
156
161
  @image_thread = Thread.new do
@@ -160,7 +165,7 @@ module Alexandria
160
165
  uri = result[1]
161
166
  if uri
162
167
  if URI.parse(uri).scheme.nil?
163
- File.open(uri, 'r') do |io|
168
+ File.open(uri, "r") do |io|
164
169
  @images[i] = io.read
165
170
  end
166
171
  else
@@ -168,8 +173,8 @@ module Alexandria
168
173
  end
169
174
  end
170
175
  end
171
- rescue StandardError => e
172
- @image_error = e.message
176
+ rescue StandardError => ex
177
+ @image_error = ex.message
173
178
  end
174
179
  end
175
180
 
@@ -178,24 +183,22 @@ module Alexandria
178
183
  image_error_dialog(@image_error).display
179
184
  else
180
185
  @images.each_pair do |key, value|
181
- begin
182
- loader = GdkPixbuf::PixbufLoader.new
183
- loader.last_write(value)
184
- pixbuf = loader.pixbuf
185
-
186
- if pixbuf.width > 1
187
- iter = @treeview_results.model.get_iter(key.to_s)
188
- unless @treeview_results.model.iter_is_valid?(iter)
189
- raise format('Iter is invalid! %s', iter)
190
- end
191
-
192
- iter[2] = pixbuf # I bet you this is it!
186
+ loader = GdkPixbuf::PixbufLoader.new
187
+ loader.last_write(value)
188
+ pixbuf = loader.pixbuf
189
+
190
+ if pixbuf.width > 1
191
+ iter = @treeview_results.model.get_iter(key.to_s)
192
+ unless @treeview_results.model.iter_is_valid?(iter)
193
+ raise format(_("Iter is invalid! %s"), iter)
193
194
  end
194
195
 
195
- @images.delete(key)
196
- rescue StandardError => e
197
- image_error_dialog(e.message).display
196
+ iter[2] = pixbuf # I bet you this is it!
198
197
  end
198
+
199
+ @images.delete(key)
200
+ rescue StandardError => ex
201
+ image_error_dialog(ex.message).display
199
202
  end
200
203
  end
201
204
 
@@ -211,7 +214,7 @@ module Alexandria
211
214
  end
212
215
 
213
216
  def on_find
214
- log.info { 'on_find' }
217
+ log.info { "on_find" }
215
218
  mode = case @combo_search.active
216
219
  when 0
217
220
  BookProviders::SEARCH_BY_TITLE
@@ -223,11 +226,11 @@ module Alexandria
223
226
 
224
227
  criterion = @entry_search.text.strip
225
228
  @treeview_results.model.clear
226
- log.info {
227
- format('TreeStore Model: %s columns; ref_counts: %s',
229
+ log.info do
230
+ format("TreeStore Model: %s columns; ref_counts: %s",
228
231
  @treeview_results.model.n_columns,
229
232
  @treeview_results.model.ref_count)
230
- }
233
+ end
231
234
 
232
235
  @find_error = nil
233
236
  @results = nil
@@ -244,8 +247,8 @@ module Alexandria
244
247
  @results = Alexandria::BookProviders.search(criterion, mode)
245
248
 
246
249
  log.info { "got #{@results.length} results" }
247
- rescue StandardError => e
248
- @find_error = e.message
250
+ rescue StandardError => ex
251
+ @find_error = ex.message
249
252
  ensure
250
253
  Alexandria::BookProviders.instance.delete_observer(self)
251
254
  # notify_end_add_by_isbn
@@ -261,7 +264,7 @@ module Alexandria
261
264
  # Err... continue == false if @find_error
262
265
  continue = if @find_error
263
266
  ErrorDialog.new(@new_book_dialog,
264
- _('Unable to find matches for your search'),
267
+ _("Unable to find matches for your search"),
265
268
  @find_error).display
266
269
  false
267
270
  elsif @results
@@ -285,15 +288,10 @@ module Alexandria
285
288
  # continue == false if @find_error OR if results are returned
286
289
  # timeout ends if continue is false!
287
290
 
288
- unless continue
289
- unless @find_thread.alive? # This happens after find_thread is done
290
- unless @destroyed
291
- # GLib::Source.remove(progress_pulsing)
292
- # @progressbar.hide
293
- notify_end_add_by_isbn
294
- @button_add.sensitive = false
295
- end
296
- end
291
+ # @find_thread.alive? happens after find_thread is done
292
+ unless continue || @find_thread.alive? || @destroyed
293
+ notify_end_add_by_isbn
294
+ @button_add.sensitive = false
297
295
  end
298
296
 
299
297
  continue # timeout loop condition
@@ -302,13 +300,13 @@ module Alexandria
302
300
 
303
301
  def copy_results_to_treeview_model(results, model)
304
302
  results.each do |book, _cover_url|
305
- s = format(_('%s, by %s'), book.title, book.authors.join(', '))
306
- similar_books = results.find { |book2, _cover2|
303
+ s = format(_("%s, by %s"), book.title, book.authors.join(", "))
304
+ similar_books = results.find do |book2, _cover2|
307
305
  (book.title == book2.title) &&
308
306
  (book.authors == book2.authors)
309
- }
307
+ end
310
308
  s += " (#{book.edition}, #{book.publisher})" if similar_books.length > 1
311
- log.info { format('Copying %s into tree view.', book.title) }
309
+ log.info { format(_("Copying %s into tree view."), book.title) }
312
310
  iter = model.append
313
311
  iter[0] = s
314
312
  iter[1] = book.ident
@@ -316,14 +314,14 @@ module Alexandria
316
314
  end
317
315
  end
318
316
 
319
- def decode_cuecat?(entry) # srsly?
320
- if entry.text =~ /^\..*?\..*?\.(.*?)\.$/
321
- tmp = Regexp.last_match[1].tr('a-zA-Z0-9+-', ' -_')
322
- tmp = ((32 + tmp.length * 3 / 4).to_i.chr << tmp).unpack('u')[0]
323
- tmp.chomp!("\000")
324
- entry.text = tmp.gsub!(/./) { |c| (c[0] ^ 67).chr }
325
- entry.text = 'Bad scan result' if entry.text.count('^ -~') > 0
326
- end
317
+ def decode_cuecat(entry)
318
+ return unless entry.text =~ /^\..*?\..*?\.(.*?)\.$/
319
+
320
+ tmp = Regexp.last_match[1].tr("a-zA-Z0-9+-", " -_")
321
+ tmp = ((32 + tmp.length * 3 / 4).to_i.chr << tmp).unpack1("u")
322
+ tmp.chomp!("\000")
323
+ entry.text = tmp.gsub!(/./) { |c| (c[0] ^ 67).chr }
324
+ entry.text = "Bad scan result" if entry.text.count("^ -~") > 0
327
325
  end
328
326
 
329
327
  def on_results_button_press_event(_widget, event)
@@ -337,8 +335,8 @@ module Alexandria
337
335
  Library.canonicalise_isbn(@entry_isbn.text)
338
336
  rescue StandardError
339
337
  raise _("Couldn't validate the EAN/ISBN you " \
340
- 'provided. Make sure it is written ' \
341
- 'correctly, and try again.')
338
+ "provided. Make sure it is written " \
339
+ "correctly, and try again.")
342
340
  end
343
341
  assert_not_exist(library, @entry_isbn.text)
344
342
  @button_add.sensitive = false
@@ -354,17 +352,16 @@ module Alexandria
354
352
  notify_end_add_by_isbn
355
353
 
356
354
  if book
357
-
358
- puts "adding book #{book} to library"
355
+ log.debug { "adding book #{book} to library" }
359
356
  add_book_to_library(library, book, cover_url)
360
- @entry_isbn.text = ''
357
+ @entry_isbn.text = ""
361
358
 
362
359
  post_addition([book], library, is_new)
363
360
  else
364
361
  post_addition([], library, is_new)
365
362
  end
366
- rescue Alexandria::BookProviders::NoResultsError => e
367
- @find_error = e.message
363
+ rescue Alexandria::BookProviders::NoResultsError => ex
364
+ @find_error = ex.message
368
365
  @button_add.sensitive = true
369
366
  notify_end_add_by_isbn
370
367
  ensure
@@ -385,7 +382,7 @@ module Alexandria
385
382
 
386
383
  isbn = book.isbn
387
384
  if isbn.nil? || isbn.empty?
388
- puts 'noisbn'
385
+ log.debug { "noisbn" }
389
386
  book.isbn = book.saved_ident = nil
390
387
  books_to_add << [book, cover]
391
388
  next
@@ -393,7 +390,7 @@ module Alexandria
393
390
 
394
391
  isbn = Library.canonicalise_ean(isbn)
395
392
  unless isbn
396
- puts "invalidisbn #{book.isbn}"
393
+ log.debug { "invalidisbn #{book.isbn}" }
397
394
  next unless KeepBadISBNDialog.new(@new_book_dialog, book).keep?
398
395
 
399
396
  book.isbn = book.saved_ident = nil
@@ -417,7 +414,7 @@ module Alexandria
417
414
  end
418
415
 
419
416
  def post_addition(books, library, is_new_library)
420
- puts "post_addition #{books.size}"
417
+ log.debug { "post_addition #{books.size}" }
421
418
  return if books.empty?
422
419
 
423
420
  # books, a 1d array of Alexandria::Book
@@ -431,7 +428,7 @@ module Alexandria
431
428
  @entry_search.grab_focus
432
429
  else
433
430
  @button_add.sensitive = true #
434
- @entry_isbn.text = '' # blank ISBN field
431
+ @entry_isbn.text = "" # blank ISBN field
435
432
  @entry_isbn.grab_focus
436
433
  end
437
434
 
@@ -464,9 +461,9 @@ module Alexandria
464
461
 
465
462
  # Do not destroy if there is no addition.
466
463
  # return unless book_was_added
467
- rescue StandardError => e
464
+ rescue StandardError => ex
468
465
  # FIXME: Message containing <> should be displayed correctly.
469
- ErrorDialog.new(@new_book_dialog, _("Couldn't add the book"), e.message).display
466
+ ErrorDialog.new(@new_book_dialog, _("Couldn't add the book"), ex.message).display
470
467
  end
471
468
  # books_to_add
472
469
  end
@@ -492,10 +489,10 @@ module Alexandria
492
489
 
493
490
  def notify_end_add_by_isbn
494
491
  MainApp.instance.appbar.children.first.visible = false
495
- if @progress_pulsing
496
- GLib::Source.remove(@progress_pulsing)
497
- @progress_pulsing = nil
498
- end
492
+ return unless @progress_pulsing
493
+
494
+ GLib::Source.remove(@progress_pulsing)
495
+ @progress_pulsing = nil
499
496
  end
500
497
 
501
498
  def update(status, provider)
@@ -511,25 +508,26 @@ module Alexandria
511
508
  end
512
509
 
513
510
  def on_focus
514
- if @isbn_radiobutton.active? && @entry_isbn.text.strip.empty?
515
- clipboard = Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD)
516
- if (text = clipboard.wait_for_text)
517
- if Library.valid_isbn?(text) || Library.valid_ean?(text) ||
518
- Library.valid_upc?(text)
519
- GLib::Idle.add do
520
- @entry_isbn.text = text
521
- @entry_isbn.grab_focus
522
- @entry_isbn.select_region(0, -1) # select all...
523
- # @button_add.grab_focus
524
- false
525
- end
526
- log.debug { "Setting ISBN field to #{text}" }
527
- puts text # required, strangely, to prevent GUI strangeness
528
- # above last checked with ruby-gnome2 0.17.1 2009-12-09
529
- # if this puts is commented out, the cursor disappears
530
- # from the @entry_isbn box... weird, ne? - CathalMagus
531
- end
511
+ return unless @isbn_radiobutton.active? && @entry_isbn.text.strip.empty?
512
+
513
+ clipboard = Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD)
514
+ text = clipboard.wait_for_text or return
515
+
516
+ if Library.valid_isbn?(text) || Library.valid_ean?(text) ||
517
+ Library.valid_upc?(text)
518
+ GLib::Idle.add do
519
+ @entry_isbn.text = text
520
+ @entry_isbn.grab_focus
521
+ @entry_isbn.select_region(0, -1) # select all...
522
+ # @button_add.grab_focus
523
+ false
532
524
  end
525
+ log.debug { "Setting ISBN field to #{text}" }
526
+ # FIXME: Get rid of this puts!
527
+ puts text # required, strangely, to prevent GUI strangeness
528
+ # above last checked with ruby-gnome2 0.17.1 2009-12-09
529
+ # if this puts is commented out, the cursor disappears
530
+ # from the @entry_isbn box... weird, ne? - CathalMagus
533
531
  end
534
532
  end
535
533
 
@@ -537,19 +535,18 @@ module Alexandria
537
535
  if (event.event_type == :button_press) &&
538
536
  (event.button == 1)
539
537
 
540
- radio, target_widget, box2, box3 = case widget
541
- when @eventbox_entry_search
542
- [@title_radiobutton, @entry_search,
543
- @eventbox_combo_search, @eventbox_entry_isbn]
544
-
545
- when @eventbox_combo_search
546
- [@title_radiobutton, @combo_search,
547
- @eventbox_entry_search, @eventbox_entry_isbn]
548
-
549
- when @eventbox_entry_isbn
550
- [@isbn_radiobutton, @entry_isbn,
551
- @eventbox_entry_search, @eventbox_combo_search]
552
- end
538
+ radio, target_widget, box2, box3 =
539
+ case widget
540
+ when @eventbox_entry_search
541
+ [@title_radiobutton, @entry_search,
542
+ @eventbox_combo_search, @eventbox_entry_isbn]
543
+ when @eventbox_combo_search
544
+ [@title_radiobutton, @combo_search,
545
+ @eventbox_entry_search, @eventbox_entry_isbn]
546
+ when @eventbox_entry_isbn
547
+ [@isbn_radiobutton, @entry_isbn,
548
+ @eventbox_entry_search, @eventbox_combo_search]
549
+ end
553
550
  radio.active = true
554
551
  target_widget.grab_focus
555
552
  widget.above_child = false
@@ -558,7 +555,7 @@ module Alexandria
558
555
  end
559
556
 
560
557
  def on_help
561
- Alexandria::UI.display_help(@preferences_dialog, 'add-book-by-isbn')
558
+ Alexandria::UI.display_help(@preferences_dialog, "add-book-by-isbn")
562
559
  end
563
560
 
564
561
  private
@@ -568,10 +565,12 @@ module Alexandria
568
565
  isbn13 = Library.canonicalise_ean(isbn)
569
566
  return unless isbn13
570
567
 
571
- if (book = library.find { |bk| bk.isbn == isbn13 })
572
- raise DuplicateBookException, format(_("'%s' already exists in '%s' (titled '%s')."),
573
- isbn, library.name, book.title.sub('&', '&amp;'))
574
- end
568
+ book = library.find { |bk| bk.isbn == isbn13 }
569
+ return unless book
570
+
571
+ raise DuplicateBookException,
572
+ format(_("'%s' already exists in '%s' (titled '%s')."),
573
+ isbn, library.name, book.title.sub("&", "&amp;"))
575
574
  end
576
575
  end
577
576
  end