alexandria-book-collection-manager 0.7.5 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +72 -0
  4. data/.gitignore +4 -1
  5. data/.rubocop.yml +65 -30
  6. data/.rubocop_todo.yml +49 -165
  7. data/.simplecov +5 -2
  8. data/CHANGELOG.md +64 -0
  9. data/ChangeLog.0 +19 -19
  10. data/INSTALL.md +26 -16
  11. data/README.md +31 -35
  12. data/Rakefile +18 -16
  13. data/alexandria-book-collection-manager.gemspec +35 -29
  14. data/doc/FAQ +2 -2
  15. data/doc/dependency_decisions.yml +22 -3
  16. data/lib/alexandria/about.rb +1 -1
  17. data/lib/alexandria/book_providers/bl_provider.rb +88 -0
  18. data/lib/alexandria/book_providers/douban.rb +2 -2
  19. data/lib/alexandria/book_providers/loc_provider.rb +38 -0
  20. data/lib/alexandria/book_providers/pseudomarc.rb +61 -71
  21. data/lib/alexandria/book_providers/sbn_provider.rb +108 -0
  22. data/lib/alexandria/book_providers/{thalia.rb → thalia_provider.rb} +37 -74
  23. data/lib/alexandria/book_providers/web.rb +2 -2
  24. data/lib/alexandria/book_providers/worldcat.rb +34 -38
  25. data/lib/alexandria/book_providers/z3950_provider.rb +199 -0
  26. data/lib/alexandria/book_providers.rb +48 -65
  27. data/lib/alexandria/default_preferences.rb +2 -1
  28. data/lib/alexandria/execution_queue.rb +13 -12
  29. data/lib/alexandria/export_library.rb +21 -22
  30. data/lib/alexandria/image_fetcher.rb +25 -0
  31. data/lib/alexandria/import_library.rb +46 -70
  32. data/lib/alexandria/import_library_csv.rb +16 -16
  33. data/lib/alexandria/library_sort_order.rb +3 -1
  34. data/lib/alexandria/library_store.rb +19 -20
  35. data/lib/alexandria/logging.rb +5 -9
  36. data/lib/alexandria/models/book.rb +15 -2
  37. data/lib/alexandria/models/library.rb +31 -35
  38. data/lib/alexandria/net.rb +1 -2
  39. data/lib/alexandria/preferences.rb +27 -33
  40. data/lib/alexandria/scanners/cue_cat.rb +6 -6
  41. data/lib/alexandria/scanners/keyboard.rb +1 -1
  42. data/lib/alexandria/scanners.rb +2 -2
  43. data/lib/alexandria/smart_library.rb +22 -26
  44. data/lib/alexandria/ui/about_dialog.rb +1 -1
  45. data/lib/alexandria/ui/acquire_dialog.rb +15 -19
  46. data/lib/alexandria/ui/alert_dialog.rb +36 -19
  47. data/lib/alexandria/ui/bad_isbns_dialog.rb +13 -9
  48. data/lib/alexandria/ui/barcode_animation.rb +6 -6
  49. data/lib/alexandria/ui/book_properties_dialog.rb +2 -3
  50. data/lib/alexandria/ui/book_properties_dialog_base.rb +35 -137
  51. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  52. data/lib/alexandria/ui/callbacks.rb +144 -123
  53. data/lib/alexandria/ui/completion_models.rb +2 -6
  54. data/lib/alexandria/ui/confirm_erase_dialog.rb +1 -1
  55. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +2 -2
  56. data/lib/alexandria/ui/error_dialog.rb +1 -1
  57. data/lib/alexandria/ui/export_dialog.rb +19 -18
  58. data/lib/alexandria/ui/icons.rb +34 -40
  59. data/lib/alexandria/ui/iconview_tooltips.rb +40 -53
  60. data/lib/alexandria/ui/import_dialog.rb +49 -48
  61. data/lib/alexandria/ui/init.rb +14 -12
  62. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +2 -2
  63. data/lib/alexandria/ui/libraries_combo.rb +10 -9
  64. data/lib/alexandria/ui/listview.rb +6 -7
  65. data/lib/alexandria/ui/main_app.rb +2 -2
  66. data/lib/alexandria/ui/multi_drag_treeview.rb +5 -7
  67. data/lib/alexandria/ui/new_book_dialog.rb +63 -65
  68. data/lib/alexandria/ui/new_book_dialog_manual.rb +1 -1
  69. data/lib/alexandria/ui/new_provider_dialog.rb +12 -11
  70. data/lib/alexandria/ui/new_smart_library_dialog.rb +39 -27
  71. data/lib/alexandria/ui/preferences_dialog.rb +25 -84
  72. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +10 -6
  73. data/lib/alexandria/ui/provider_preferences_dialog.rb +5 -5
  74. data/lib/alexandria/ui/really_delete_dialog.rb +2 -2
  75. data/lib/alexandria/ui/sidepane_manager.rb +38 -38
  76. data/lib/alexandria/ui/skip_entry_dialog.rb +3 -2
  77. data/lib/alexandria/ui/smart_library_properties_dialog.rb +35 -36
  78. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +61 -244
  79. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  80. data/lib/alexandria/ui/sound.rb +4 -6
  81. data/lib/alexandria/ui/ui_manager.rb +80 -83
  82. data/lib/alexandria/ui.rb +7 -7
  83. data/lib/alexandria/version.rb +2 -2
  84. data/lib/alexandria/web_themes.rb +15 -15
  85. data/lib/alexandria.rb +2 -2
  86. data/po/cs.po +947 -865
  87. data/po/cy.po +913 -864
  88. data/po/de.po +961 -865
  89. data/po/el.po +956 -861
  90. data/po/es.po +952 -857
  91. data/po/fr.po +950 -865
  92. data/po/ga.po +866 -819
  93. data/po/gl.po +946 -861
  94. data/po/it.po +945 -858
  95. data/po/ja.po +921 -836
  96. data/po/mk.po +953 -858
  97. data/po/nb.po +932 -847
  98. data/po/nl.po +955 -849
  99. data/po/pl.po +999 -963
  100. data/po/pt.po +946 -850
  101. data/po/pt_BR.po +944 -859
  102. data/po/ru.po +959 -868
  103. data/po/sk.po +950 -863
  104. data/po/sv.po +944 -859
  105. data/po/uk.po +925 -846
  106. data/po/zh_TW.po +926 -841
  107. data/schemas/alexandria.schemas +1 -1
  108. data/share/alexandria/glade/main_app__builder.glade +6 -21
  109. data/share/gnome/help/alexandria/C/adding-books.xml +3 -4
  110. data/share/gnome/help/alexandria/C/introduction.xml +0 -16
  111. data/share/gnome/help/alexandria/C/searching.xml +1 -4
  112. data/share/gnome/help/alexandria/C/settings.xml +0 -30
  113. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  114. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  115. data/share/gnome/help/alexandria/fr/alexandria.xml +5 -160
  116. data/share/gnome/help/alexandria/ja/adding-books.xml +1 -1
  117. data/share/gnome/help/alexandria/ja/introduction.xml +0 -15
  118. data/share/gnome/help/alexandria/ja/searching.xml +3 -7
  119. data/share/gnome/help/alexandria/ja/settings.xml +0 -27
  120. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  121. data/spec/alexandria/book_providers/bl_provider_spec.rb +13 -0
  122. data/spec/alexandria/book_providers/loc_provider_spec.rb +17 -0
  123. data/spec/alexandria/book_providers/sbn_provider_spec.rb +13 -0
  124. data/spec/alexandria/book_providers/thalia_provider_spec.rb +119 -0
  125. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  126. data/spec/alexandria/book_providers_spec.rb +0 -154
  127. data/spec/alexandria/console_spec.rb +0 -5
  128. data/spec/alexandria/export_library_spec.rb +27 -38
  129. data/spec/alexandria/library_spec.rb +76 -46
  130. data/spec/alexandria/preferences_spec.rb +29 -3
  131. data/spec/alexandria/scanners/cue_cat_spec.rb +1 -1
  132. data/spec/alexandria/ui/about_dialog_spec.rb +1 -1
  133. data/spec/alexandria/ui/acquire_dialog_spec.rb +1 -1
  134. data/spec/alexandria/ui/alert_dialog_spec.rb +1 -1
  135. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +1 -1
  136. data/spec/alexandria/ui/book_properties_dialog_spec.rb +47 -5
  137. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +1 -1
  138. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +1 -1
  139. data/spec/alexandria/ui/error_dialog_spec.rb +1 -1
  140. data/spec/alexandria/ui/export_dialog_spec.rb +25 -4
  141. data/spec/alexandria/ui/icons_spec.rb +26 -0
  142. data/spec/alexandria/ui/iconview_spec.rb +1 -1
  143. data/spec/alexandria/ui/import_dialog_spec.rb +35 -3
  144. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +1 -1
  145. data/spec/alexandria/ui/main_app_spec.rb +1 -1
  146. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +39 -3
  147. data/spec/alexandria/ui/new_provider_dialog_spec.rb +19 -3
  148. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +28 -3
  149. data/spec/alexandria/ui/preferences_dialog_spec.rb +2 -2
  150. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +23 -8
  151. data/spec/alexandria/ui/really_delete_dialog_spec.rb +1 -1
  152. data/spec/alexandria/ui/sidepane_manager_spec.rb +2 -2
  153. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +1 -1
  154. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +37 -6
  155. data/spec/alexandria/ui/ui_manager_spec.rb +116 -2
  156. data/spec/data/libraries/0.6.2/My Library/9780571147168.yaml +2 -0
  157. data/spec/end_to_end/basic_run_spec.rb +3 -8
  158. data/spec/fixtures/cover.jpg +0 -0
  159. data/spec/spec_helper.rb +47 -3
  160. data/tasks/spec.rake +3 -5
  161. data/util/rake/fileinstall.rb +16 -15
  162. data/util/rake/omfgenerate.rb +1 -1
  163. metadata +141 -52
  164. data/.travis.yml +0 -39
  165. data/lib/alexandria/book_providers/adlibris.rb +0 -196
  166. data/lib/alexandria/book_providers/amazon_aws.rb +0 -252
  167. data/lib/alexandria/book_providers/amazon_ecs_util.rb +0 -388
  168. data/lib/alexandria/book_providers/barnes_and_noble.rb +0 -209
  169. data/lib/alexandria/book_providers/proxis.rb +0 -175
  170. data/lib/alexandria/book_providers/siciliano.rb +0 -257
  171. data/lib/alexandria/book_providers/z3950.rb +0 -415
  172. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  173. data/spec/alexandria/utilities_spec.rb +0 -52
@@ -1,25 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby -*-
3
+ # This file is part of Alexandria.
4
4
  #
5
- # Copyright (C) 2007 kksou
6
- # Copyright (C) 2008,2009 Cathal Mc Ginley
7
- # Copyright (C) 2011, 2014, 2016 Matijs van Zuijlen
8
- #
9
- # Alexandria is free software; you can redistribute it and/or
10
- # modify it under the terms of the GNU General Public License as
11
- # published by the Free Software Foundation; either version 2 of the
12
- # License, or (at your option) any later version.
13
- #
14
- # Alexandria is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- # General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU General Public
20
- # License along with Alexandria; see the file COPYING. If not,
21
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
22
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
23
6
 
24
7
  # Please retain the following note:
25
8
  #
@@ -31,47 +14,51 @@
31
14
 
32
15
  require "cgi"
33
16
 
34
- class IconViewTooltips
35
- include Alexandria::Logging
17
+ module Alexandria
18
+ module UI
19
+ class IconViewTooltips
20
+ include Logging
36
21
 
37
- def initialize(view)
38
- set_view(view)
39
- end
22
+ def initialize(view)
23
+ set_view(view)
24
+ end
40
25
 
41
- def set_view(view)
42
- view.has_tooltip = true
43
- view.signal_connect("query-tooltip") do |_widget, x, y, _keyboard_mode, tooltip|
44
- tree_path = view.get_path_at_pos(x, y)
45
- if tree_path
46
- iter = view.model.get_iter(tree_path)
26
+ def set_view(view)
27
+ view.has_tooltip = true
28
+ view.signal_connect("query-tooltip") do |_widget, x, y, _keyboard_mode, tooltip|
29
+ tree_path = view.get_path_at_pos(x, y)
30
+ if tree_path
31
+ iter = view.model.get_iter(tree_path)
47
32
 
48
- title = iter[2] # HACK: hardcoded, should use column names...
49
- authors = iter[4]
50
- publisher = iter[6]
51
- year = iter[7]
52
- tooltip.set_markup label_for_book(title, authors, publisher, year)
33
+ title = iter[2] # HACK: hardcoded, should use column names...
34
+ authors = iter[4]
35
+ publisher = iter[6]
36
+ year = iter[7]
37
+ tooltip.set_markup label_for_book(title, authors, publisher, year)
38
+ end
39
+ end
53
40
  end
54
- end
55
- end
56
41
 
57
- def label_for_book(title, authors, publisher, year)
58
- # This is much too complex... but it works for now!
59
- html = ""
60
- unless title.empty?
61
- html += "<b>#{CGI.escapeHTML(title)}</b>"
62
- html += "\n" unless authors.empty?
63
- end
64
- html += "<i>#{CGI.escapeHTML(authors)}</i>" unless authors.empty?
65
- html += "\n" if !title.empty? || !authors.empty?
42
+ def label_for_book(title, authors, publisher, year)
43
+ # This is much too complex... but it works for now!
44
+ html = ""
45
+ unless title.empty?
46
+ html += "<b>#{CGI.escapeHTML(title)}</b>"
47
+ html += "\n" unless authors.empty?
48
+ end
49
+ html += "<i>#{CGI.escapeHTML(authors)}</i>" unless authors.empty?
50
+ html += "\n" if !title.empty? || !authors.empty?
66
51
 
67
- html += "<small>"
68
- html += CGI.escapeHTML(publisher).to_s if publisher && !publisher.empty?
52
+ html += "<small>"
53
+ html += CGI.escapeHTML(publisher).to_s if publisher && !publisher.empty?
69
54
 
70
- if year && !year.empty?
71
- html += " " if publisher && !publisher.empty?
72
- html += "(#{year})"
73
- end
55
+ if year && !year.empty?
56
+ html += " " if publisher && !publisher.empty?
57
+ html += "(#{year})"
58
+ end
74
59
 
75
- html + "</small>"
60
+ html + "</small>"
61
+ end
62
+ end
76
63
  end
77
64
  end
@@ -7,18 +7,9 @@
7
7
  require "alexandria/ui/error_dialog"
8
8
  require "alexandria/ui/skip_entry_dialog"
9
9
 
10
- class Alexandria::ImportFilter
11
- def to_filefilter
12
- filefilter = Gtk::FileFilter.new
13
- filefilter.name = name
14
- patterns.each { |x| filefilter.add_pattern(x) }
15
- filefilter
16
- end
17
- end
18
-
19
10
  module Alexandria
20
11
  module UI
21
- class ImportDialog < SimpleDelegator
12
+ class ImportDialog
22
13
  include GetText
23
14
  include Logging
24
15
 
@@ -26,55 +17,56 @@ module Alexandria
26
17
 
27
18
  FILTERS = Alexandria::ImportFilter.all
28
19
 
20
+ attr_reader :dialog
21
+
29
22
  def initialize(parent)
30
23
  title = _("Import a Library")
31
- dialog = Gtk::FileChooserDialog.new title: title, parent: parent, action: :open
32
- super(dialog)
33
- puts "ImportDialog opened." if $DEBUG
24
+ @dialog = Gtk::FileChooserDialog.new title: title, parent: parent, action: :open
25
+ log.debug { "ImportDialog opened" }
34
26
  @destroyed = false
35
27
  @running = false
36
- add_button(Gtk::Stock::HELP, Gtk::ResponseType::HELP)
37
- add_button(Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL)
38
- import_button = add_button(_("_Import"),
39
- Gtk::ResponseType::ACCEPT)
28
+ dialog.add_button(Gtk::Stock::HELP, Gtk::ResponseType::HELP)
29
+ dialog.add_button(Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL)
30
+ import_button = dialog.add_button(_("_Import"),
31
+ Gtk::ResponseType::ACCEPT)
40
32
  import_button.sensitive = false
41
33
 
42
- signal_connect("destroy") do
34
+ dialog.signal_connect("destroy") do
43
35
  if @running
44
36
  @destroyed = true
45
37
  else
46
- destroy
38
+ dialog.destroy
47
39
  end
48
40
  end
49
41
 
50
- filters = {}
42
+ @filters = {}
51
43
  FILTERS.each do |filter|
52
- filefilter = filter.to_filefilter
53
- add_filter(filefilter)
54
- puts "Added ImportFilter #{filefilter} -- #{filefilter.name}" if $DEBUG
55
- filters[filefilter] = filter
44
+ filefilter = make_filefilter filter
45
+ dialog.add_filter(filefilter)
46
+ log.debug { "Added ImportFilter #{filefilter} -- #{filefilter.name}" }
47
+ @filters[filefilter] = filter
56
48
  end
57
49
 
58
- signal_connect("selection_changed") do
59
- import_button.sensitive = !!(filename && File.file?(filename))
50
+ dialog.signal_connect("selection_changed") do
51
+ import_button.sensitive = dialog.filename && File.file?(dialog.filename)
60
52
  end
61
53
 
62
54
  # before adding the (hidden) progress bar, we must re-set the
63
55
  # packing of the button box (currently packed at the end),
64
56
  # because the progressbar will be *after* the button box.
65
- buttonbox = child.children.last
66
- child.set_child_packing(buttonbox, pack_type: :start)
67
- child.reorder_child(buttonbox, 1)
57
+ buttonbox = dialog.child.children.last
58
+ dialog.child.set_child_packing(buttonbox, pack_type: :start)
59
+ dialog.child.reorder_child(buttonbox, 1)
68
60
 
69
- pbar = Gtk::ProgressBar.new
70
- pbar.show_text = true
71
- child.pack_start(pbar, expand: false)
61
+ @pbar = Gtk::ProgressBar.new
62
+ @pbar.show_text = true
63
+ dialog.child.pack_start(@pbar, expand: false)
72
64
  end
73
65
 
74
66
  def acquire
75
67
  on_progress = proc do |fraction|
76
- pbar.show unless pbar.visible?
77
- pbar.fraction = fraction
68
+ @pbar.show unless @pbar.visible?
69
+ @pbar.fraction = fraction
78
70
  end
79
71
 
80
72
  on_error = proc do |message|
@@ -84,27 +76,27 @@ module Alexandria
84
76
  exec_queue = ExecutionQueue.new
85
77
 
86
78
  while !@destroyed &&
87
- ((response = run) != Gtk::ResponseType::CANCEL) &&
79
+ ((response = dialog.run) != Gtk::ResponseType::CANCEL) &&
88
80
  response != Gtk::ResponseType::DELETE_EVENT
89
81
 
90
82
  if response == Gtk::ResponseType::HELP
91
83
  Alexandria::UI.display_help(self, "import-library")
92
84
  next
93
85
  end
94
- file = File.basename(filename, ".*")
86
+ file = File.basename(dialog.filename, ".*")
95
87
  base = GLib.locale_to_utf8(file)
96
88
  new_library_name = Library.generate_new_name(
97
89
  LibraryCollection.instance.all_libraries,
98
90
  base)
99
91
 
100
- filter = filters[self.filter]
101
- puts "Going forward with filter: #{filter.name}" if $DEBUG
102
- self.sensitive = false
92
+ filter = @filters[dialog.filter]
93
+ log.debug { "Going forward with filter: #{filter.name}" }
94
+ dialog.sensitive = false
103
95
 
104
96
  filter.on_iterate do |n, total|
105
97
  unless @destroyed
106
98
  fraction = n * 1.0 / total
107
- puts "#{inspect} fraction: #{fraction}" if $DEBUG
99
+ log.debug { "#{inspect} fraction: #{fraction}" }
108
100
  exec_queue.call(on_progress, fraction)
109
101
  end
110
102
  end
@@ -112,22 +104,21 @@ module Alexandria
112
104
  not_cancelled = true
113
105
  filter.on_error do |message|
114
106
  not_cancelled = exec_queue.sync_call(on_error, message)
115
- puts "#{inspect} cancel state: #{not_cancelled}" if $DEBUG
107
+ log.debug { "#{inspect} cancel state: #{not_cancelled}" }
116
108
  end
117
109
 
118
110
  library = nil
119
111
  @bad_isbns = nil
120
112
  @failed_isbns = nil
121
113
  thread = Thread.start do
122
- library, @bad_isbns, @failed_isbns = filter.invoke(new_library_name,
123
- filename)
114
+ library, @bad_isbns, @failed_isbns =
115
+ filter.invoke(new_library_name, dialog.filename)
124
116
  rescue StandardError => ex
125
117
  trace = ex.backtrace.join("\n> ")
126
118
  log.error { "Import failed: #{ex.message} #{trace}" }
127
119
  end
128
120
 
129
121
  while thread.alive? && !@destroyed
130
- # puts "Thread #{thread} still alive."
131
122
  @running = true
132
123
  exec_queue.iterate
133
124
  Gtk.main_iteration_do(false)
@@ -138,18 +129,28 @@ module Alexandria
138
129
  yield(library, @bad_isbns, @failed_isbns)
139
130
  break
140
131
  elsif not_cancelled
141
- puts "Raising ErrorDialog because not_cancelled is #{not_cancelled}" if $DEBUG
142
- ErrorDialog.new(self,
132
+ log.debug { "Raising ErrorDialog because not_cancelled is #{not_cancelled}" }
133
+ ErrorDialog.new(dialog,
143
134
  _("Couldn't import the library"),
144
135
  _("The format of the file you " \
145
136
  "provided is unknown. Please " \
146
137
  "retry with another file.")).display
147
138
  end
148
- pbar.hide
139
+ @pbar.hide
149
140
  self.sensitive = true
150
141
  end
151
142
  end
152
- destroy unless @destroyed
143
+
144
+ dialog.destroy unless @destroyed
145
+ end
146
+
147
+ private
148
+
149
+ def make_filefilter(import_filter)
150
+ filefilter = Gtk::FileFilter.new
151
+ filefilter.name = import_filter.name
152
+ import_filter.patterns.each { |x| filefilter.add_pattern(x) }
153
+ filefilter
153
154
  end
154
155
  end
155
156
  end
@@ -8,6 +8,7 @@ require "alexandria/ui/error_dialog"
8
8
 
9
9
  class CellRendererToggle < Gtk::CellRendererToggle
10
10
  attr_accessor :text
11
+
11
12
  type_register
12
13
  install_property(GLib::Param::String.new(
13
14
  "text",
@@ -18,33 +19,34 @@ class CellRendererToggle < Gtk::CellRendererToggle
18
19
  end
19
20
 
20
21
  class Gtk::ActionGroup
21
- def [](x)
22
- get_action(x)
22
+ def [](index)
23
+ get_action(index)
23
24
  end
24
25
  end
25
26
 
26
- class Gtk::IconView
27
- def freeze
28
- @old_model = model
29
- self.model = nil
30
- end
31
-
32
- def unfreeze
33
- self.model = @old_model
27
+ module Alexandria::UI::FreezeThaw
28
+ def frozen?
29
+ @old_model && !model
34
30
  end
35
- end
36
31
 
37
- class Gtk::TreeView
38
32
  def freeze
33
+ return if frozen?
34
+
39
35
  @old_model = model
40
36
  self.model = nil
41
37
  end
42
38
 
43
39
  def unfreeze
40
+ return unless frozen?
41
+
44
42
  self.model = @old_model
43
+ @old_model = nil
45
44
  end
46
45
  end
47
46
 
47
+ Gtk::IconView.include Alexandria::UI::FreezeThaw
48
+ Gtk::TreeView.include Alexandria::UI::FreezeThaw
49
+
48
50
  class Alexandria::Library
49
51
  def action_name
50
52
  "MoveIn" + name.gsub(/\s/, "")
@@ -16,13 +16,13 @@ module Alexandria
16
16
  title = _("Invalid ISBN '%s'") % book.isbn
17
17
  message =
18
18
  _("The book titled '%s' has an invalid ISBN, but still " \
19
- "exists in the providers libraries. Do you want to " \
19
+ "exists in the providers libraries. Do you want to " \
20
20
  "keep the book but change the ISBN or cancel the addition?") % book.title
21
21
  super(parent, title,
22
22
  Gtk::Stock::DIALOG_QUESTION,
23
23
  [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
24
24
  [_("_Keep"), Gtk::ResponseType::OK]], message)
25
- self.default_response = Gtk::ResponseType::OK
25
+ dialog.default_response = Gtk::ResponseType::OK
26
26
  end
27
27
 
28
28
  def keep?
@@ -35,16 +35,10 @@ module Alexandria
35
35
  clear
36
36
  self.model = Gtk::ListStore.new(GdkPixbuf::Pixbuf, String, TrueClass)
37
37
  libraries_names.each do |library_name|
38
- iter = model.append
39
- iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL
40
- iter[1] = library_name
41
- iter[2] = false
38
+ append_entry(Alexandria::UI::Icons::LIBRARY_SMALL, library_name, false)
42
39
  end
43
- model.append[1] = "-"
44
- iter = model.append
45
- iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL
46
- iter[1] = _("New Library")
47
- iter[2] = true
40
+ append_entry(nil, "-", nil)
41
+ append_entry(Alexandria::UI::Icons::LIBRARY_SMALL, _("New Library"), true)
48
42
  renderer = Gtk::CellRendererPixbuf.new
49
43
  pack_start(renderer, false)
50
44
  set_attributes(renderer, pixbuf: 0)
@@ -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
 
@@ -83,9 +83,8 @@ module Alexandria
83
83
  end
84
84
 
85
85
  def setup_tags_column
86
- # adding tags column...
87
86
  title = _("Tags")
88
- log.debug { "Create listview column for 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,
@@ -105,7 +104,7 @@ module Alexandria
105
104
 
106
105
  def setup_rating_column
107
106
  title = _("Rating")
108
- log.debug { format("Create listview column for %s...", title) }
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
@@ -164,7 +163,7 @@ module Alexandria
164
163
  column = Gtk::TreeViewColumn.new(title, renderer, text: iterid)
165
164
  column.sort_column_id = iterid
166
165
  column.resizable = true
167
- log.debug { format("Create listview column for %s...", title) }
166
+ log.debug { format("Create listview column for %s", title) }
168
167
 
169
168
  column.add_attribute(renderer, "active", iterid)
170
169
  if iterid == Columns::WANT
@@ -176,7 +175,7 @@ module Alexandria
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,
@@ -202,9 +201,9 @@ module Alexandria
202
201
  @prefs.col_rating_visible,
203
202
  @prefs.col_tags_visible
204
203
  ]
205
- cols = @listview.columns[1..-1] # skip "Title"
204
+ cols = @listview.columns[1..] # skip "Title"
206
205
  cols.each_index do |i|
207
- cols[i].visible = !!cols_visibility[i]
206
+ cols[i].visible = cols_visibility[i]
208
207
  end
209
208
  log.debug do
210
209
  "Columns visibility: " +
@@ -50,8 +50,8 @@ module Alexandria
50
50
  include Logging
51
51
  include GetText
52
52
  include Singleton
53
- attr_accessor :main_app, :libraries, :actiongroup, :appbar, :prefs
54
- attr_accessor :ui_manager
53
+ attr_accessor :main_app, :libraries, :actiongroup, :appbar, :prefs, :ui_manager
54
+
55
55
  def initialize
56
56
  log.info { "Starting MainApp" }
57
57
  @ui_manager = UIManager.new self
@@ -6,16 +6,14 @@
6
6
 
7
7
  module Alexandria
8
8
  module EventOverrides
9
- def ==(obj)
10
- obj.is_a?(self.class) &&
11
- (time == obj.time) && (x == obj.x) && (y == obj.y) &&
12
- (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)
13
13
  end
14
14
  end
15
15
 
16
16
  module TreeViewOverrides
17
- # include Alexandria::Logging
18
-
19
17
  Context = Struct.new(:pressed_button,
20
18
  :x,
21
19
  :y,
@@ -101,7 +99,7 @@ module Alexandria
101
99
  return true
102
100
  end
103
101
 
104
- return false if event.event_type == :'2button_press'
102
+ return false if event.event_type == :"2button_press"
105
103
 
106
104
  path, _, cell_x, cell_y = get_path_at_pos(event.x, event.y)
107
105
  return false if path.nil?