alexandria-book-collection-manager 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -25
  3. data/.rubocop_todo.yml +87 -67
  4. data/CHANGELOG.md +12 -1
  5. data/Gemfile +4 -3
  6. data/README.md +16 -6
  7. data/Rakefile +71 -72
  8. data/alexandria-book-collection-manager.gemspec +44 -44
  9. data/bin/alexandria +12 -12
  10. data/lib/alexandria.rb +22 -22
  11. data/lib/alexandria/about.rb +50 -50
  12. data/lib/alexandria/book_providers.rb +50 -50
  13. data/lib/alexandria/book_providers/adlibris.rb +28 -44
  14. data/lib/alexandria/book_providers/amazon_aws.rb +64 -64
  15. data/lib/alexandria/book_providers/amazon_ecs_util.rb +52 -78
  16. data/lib/alexandria/book_providers/barnes_and_noble.rb +34 -34
  17. data/lib/alexandria/book_providers/douban.rb +21 -37
  18. data/lib/alexandria/book_providers/proxis.rb +24 -24
  19. data/lib/alexandria/book_providers/pseudomarc.rb +19 -19
  20. data/lib/alexandria/book_providers/renaud.rb +44 -57
  21. data/lib/alexandria/book_providers/siciliano.rb +39 -39
  22. data/lib/alexandria/book_providers/thalia.rb +33 -33
  23. data/lib/alexandria/book_providers/web.rb +5 -5
  24. data/lib/alexandria/book_providers/worldcat.rb +44 -69
  25. data/lib/alexandria/book_providers/z3950.rb +94 -109
  26. data/lib/alexandria/config.rb +1 -1
  27. data/lib/alexandria/console.rb +3 -3
  28. data/lib/alexandria/export_format.rb +8 -8
  29. data/lib/alexandria/export_library.rb +112 -113
  30. data/lib/alexandria/import_library.rb +45 -45
  31. data/lib/alexandria/import_library_csv.rb +30 -30
  32. data/lib/alexandria/library_collection.rb +4 -4
  33. data/lib/alexandria/library_sort_order.rb +1 -1
  34. data/lib/alexandria/library_store.rb +14 -14
  35. data/lib/alexandria/logging.rb +5 -5
  36. data/lib/alexandria/models/book.rb +1 -1
  37. data/lib/alexandria/models/library.rb +36 -36
  38. data/lib/alexandria/net.rb +5 -5
  39. data/lib/alexandria/preferences.rb +32 -32
  40. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +13 -13
  41. data/lib/alexandria/scanners/keyboard.rb +5 -5
  42. data/lib/alexandria/smart_library.rb +53 -53
  43. data/lib/alexandria/ui.rb +15 -15
  44. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +1 -1
  45. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +66 -65
  46. data/lib/alexandria/ui/{dialogs/alert_dialog.rb → alert_dialog.rb} +1 -16
  47. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +0 -0
  48. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +7 -7
  49. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -37
  50. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +38 -37
  51. data/lib/alexandria/ui/builder_base.rb +1 -1
  52. data/lib/alexandria/ui/callbacks.rb +95 -91
  53. data/lib/alexandria/ui/completion_models.rb +7 -21
  54. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  55. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  56. data/lib/alexandria/ui/dndable.rb +7 -7
  57. data/lib/alexandria/ui/error_dialog.rb +25 -0
  58. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +22 -42
  59. data/lib/alexandria/ui/icons.rb +6 -6
  60. data/lib/alexandria/ui/iconview.rb +7 -7
  61. data/lib/alexandria/ui/iconview_tooltips.rb +6 -6
  62. data/lib/alexandria/ui/{dialogs/import_dialog.rb → import_dialog.rb} +14 -32
  63. data/lib/alexandria/ui/init.rb +16 -29
  64. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +6 -4
  65. data/lib/alexandria/ui/libraries_combo.rb +7 -7
  66. data/lib/alexandria/ui/listview.rb +40 -40
  67. data/lib/alexandria/ui/main_app.rb +22 -24
  68. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  69. data/lib/alexandria/ui/multi_drag_treeview.rb +4 -4
  70. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +46 -45
  71. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +20 -19
  72. data/lib/alexandria/ui/new_provider_dialog.rb +99 -0
  73. data/lib/alexandria/ui/{dialogs/new_smart_library_dialog.rb → new_smart_library_dialog.rb} +4 -4
  74. data/lib/alexandria/ui/{dialogs/preferences_dialog.rb → preferences_dialog.rb} +44 -235
  75. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +90 -0
  76. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  77. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +6 -27
  78. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +27 -25
  79. data/lib/alexandria/ui/skip_entry_dialog.rb +32 -0
  80. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog.rb → smart_library_properties_dialog.rb} +2 -2
  81. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +30 -30
  82. data/lib/alexandria/ui/sound.rb +8 -8
  83. data/lib/alexandria/ui/ui_manager.rb +136 -135
  84. data/lib/alexandria/version.rb +4 -19
  85. data/lib/alexandria/web_themes.rb +8 -8
  86. data/po/cs.po +97 -97
  87. data/po/cy.po +97 -97
  88. data/po/de.po +97 -97
  89. data/po/el.po +97 -97
  90. data/po/es.po +97 -97
  91. data/po/fr.po +97 -97
  92. data/po/ga.po +97 -97
  93. data/po/gl.po +97 -97
  94. data/po/it.po +97 -97
  95. data/po/ja.po +97 -97
  96. data/po/mk.po +97 -97
  97. data/po/nb.po +97 -97
  98. data/po/nl.po +97 -97
  99. data/po/pl.po +97 -97
  100. data/po/pt.po +97 -97
  101. data/po/pt_BR.po +97 -97
  102. data/po/ru.po +97 -97
  103. data/po/sk.po +97 -97
  104. data/po/sv.po +97 -97
  105. data/po/uk.po +97 -97
  106. data/po/zh_TW.po +97 -97
  107. data/schemas/alexandria.schemas +24 -2
  108. data/spec/alexandria/book_providers_spec.rb +65 -82
  109. data/spec/alexandria/book_spec.rb +12 -10
  110. data/spec/alexandria/console_spec.rb +9 -9
  111. data/spec/alexandria/export_library_spec.rb +31 -31
  112. data/spec/alexandria/library_spec.rb +86 -86
  113. data/spec/alexandria/library_store_spec.rb +8 -8
  114. data/spec/alexandria/preferences_spec.rb +18 -17
  115. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  116. data/spec/alexandria/smart_library_spec.rb +15 -15
  117. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  118. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  119. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  120. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  121. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  122. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  123. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  124. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  125. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  126. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  127. data/spec/alexandria/ui/import_dialog_spec.rb +14 -0
  128. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  129. data/spec/alexandria/ui/main_app_spec.rb +6 -6
  130. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  131. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  132. data/spec/alexandria/ui/new_provider_dialog_spec.rb +14 -0
  133. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +14 -0
  134. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  135. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +19 -0
  136. data/spec/alexandria/ui/really_delete_dialog_spec.rb +15 -0
  137. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  138. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  139. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +18 -0
  140. data/spec/alexandria/ui/sound_spec.rb +2 -2
  141. data/spec/alexandria/ui/ui_manager_spec.rb +6 -20
  142. data/spec/alexandria/ui/ui_utilities_spec.rb +9 -9
  143. data/spec/alexandria/utilities_spec.rb +6 -6
  144. data/spec/end_to_end/basic_run_spec.rb +24 -36
  145. data/spec/spec_helper.rb +9 -9
  146. data/tasks/dogtail.rake +1 -1
  147. data/tasks/setup.rb +2 -2
  148. data/tasks/spec.rake +11 -11
  149. data/util/rake/fileinstall.rb +25 -25
  150. data/util/rake/gettextgenerate.rb +7 -7
  151. data/util/rake/omfgenerate.rb +7 -7
  152. metadata +59 -33
  153. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  154. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  155. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
@@ -4,16 +4,17 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
- require 'tmpdir'
7
+ require "tmpdir"
8
+ require "alexandria/ui/error_dialog"
8
9
 
9
10
  module Alexandria
10
11
  module UI
11
12
  class NewBookDialogManual < BookPropertiesDialogBase
12
13
  include GetText
13
14
  extend GetText
14
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
15
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
15
16
 
16
- TMP_COVER_FILE = File.join(Dir.tmpdir, 'tmp_cover')
17
+ TMP_COVER_FILE = File.join(Dir.tmpdir, "tmp_cover")
17
18
  def initialize(parent, library, &on_add_cb)
18
19
  super(parent, TMP_COVER_FILE)
19
20
 
@@ -22,17 +23,17 @@ module Alexandria
22
23
  FileUtils.rm_f(TMP_COVER_FILE)
23
24
 
24
25
  cancel_button = Gtk::Button.new(stock_id: Gtk::Stock::CANCEL)
25
- cancel_button.signal_connect('clicked') { on_cancel }
26
+ cancel_button.signal_connect("clicked") { on_cancel }
26
27
  cancel_button.show
27
28
  @button_box << cancel_button
28
29
 
29
30
  add_button = Gtk::Button.new(stock_id: Gtk::Stock::ADD)
30
- add_button.signal_connect('clicked') { on_add }
31
+ add_button.signal_connect("clicked") { on_add }
31
32
  add_button.show
32
33
  @button_box << add_button
33
34
 
34
35
  help_button = Gtk::Button.new(stock_id: Gtk::Stock::HELP)
35
- help_button.signal_connect('clicked') { on_help }
36
+ help_button.signal_connect("clicked") { on_help }
36
37
  help_button.show
37
38
  @button_box << help_button
38
39
  @button_box.set_child_secondary(help_button, true)
@@ -46,7 +47,7 @@ module Alexandria
46
47
  def on_title_changed
47
48
  title = @entry_title.text.strip
48
49
  @book_properties_dialog.title = if title.empty?
49
- _('Adding a Book')
50
+ _("Adding a Book")
50
51
  else
51
52
  _("Adding '%s'") % title
52
53
  end
@@ -63,34 +64,34 @@ module Alexandria
63
64
 
64
65
  def on_add
65
66
  if (title = @entry_title.text.strip).empty?
66
- raise AddError, _('A title must be provided.')
67
+ raise AddError, _("A title must be provided.")
67
68
  end
68
69
 
69
70
  isbn = nil
70
- if @entry_isbn.text != ''
71
+ if @entry_isbn.text != ""
71
72
  isbn = Library.canonicalise_ean(@entry_isbn.text)
72
73
  unless isbn
73
74
  raise AddError, _("Couldn't validate the EAN/ISBN you provided. Make " \
74
- 'sure it is written correcty, and try again.')
75
+ "sure it is written correcty, and try again.")
75
76
  end
76
77
  ary = @library.select { |book| book.ident == isbn }
77
- raise AddError, _('The EAN/ISBN you provided is already used in this library.') unless ary.empty?
78
+ raise AddError, _("The EAN/ISBN you provided is already used in this library.") unless ary.empty?
78
79
  end
79
80
  if (publisher = @entry_publisher.text.strip).empty?
80
- raise AddError, _('A publisher must be provided.')
81
+ raise AddError, _("A publisher must be provided.")
81
82
  end
82
83
 
83
84
  publishing_year = @entry_publish_date.text.to_i
84
85
  # TODO: Get rid of this silly requirement
85
86
  if (edition = @entry_edition.text.strip).empty?
86
- raise AddError, _('A binding must be provided.')
87
+ raise AddError, _("A binding must be provided.")
87
88
  end
88
89
 
89
90
  authors = []
90
91
  @treeview_authors.model.each { |_m, _p, i| authors << i[0] }
91
92
  if authors.empty?
92
- raise AddError, _('At least one author must be ' \
93
- 'provided.')
93
+ raise AddError, _("At least one author must be " \
94
+ "provided.")
94
95
  end
95
96
  book = Book.new(title, authors, isbn, publisher,
96
97
  publishing_year.zero? ? nil : publishing_year,
@@ -112,14 +113,14 @@ module Alexandria
112
113
  end
113
114
  @on_add_cb.call(book)
114
115
  @book_properties_dialog.destroy
115
- rescue AddError => e
116
+ rescue AddError => ex
116
117
  ErrorDialog.new(@book_properties_dialog, _("Couldn't add the book"),
117
- e.message).display
118
+ ex.message).display
118
119
  end
119
120
 
120
121
  # COPIED from book_properties_dialog_base
121
122
  def parse_date(datestring)
122
- date_format = '%d/%m/%Y'
123
+ date_format = "%d/%m/%Y"
123
124
  begin
124
125
  d = Date.strptime(datestring, date_format)
125
126
  Time.gm(d.year, d.month, d.day)
@@ -129,7 +130,7 @@ module Alexandria
129
130
  end
130
131
 
131
132
  def on_help
132
- Alexandria::UI.display_help(@preferences_dialog, 'add-book-manually')
133
+ Alexandria::UI.display_help(@preferences_dialog, "add-book-manually")
133
134
  end
134
135
  end
135
136
  end
@@ -0,0 +1,99 @@
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
+ require "alexandria/ui/provider_preferences_base_dialog"
8
+
9
+ module Alexandria
10
+ module UI
11
+ class NewProviderDialog < ProviderPreferencesBaseDialog
12
+ include GetText
13
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
14
+
15
+ def initialize(parent)
16
+ super(title: _("New Provider"),
17
+ parent: parent,
18
+ flags: :modal,
19
+ buttons: [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL]])
20
+ @add_button = add_button(Gtk::Stock::ADD,
21
+ Gtk::ResponseType::ACCEPT)
22
+
23
+ instances = BookProviders.abstract_classes.map(&:new)
24
+ @selected_instance = nil
25
+
26
+ @table = Gtk::Table.new(2, 2)
27
+ child.pack_start(@table)
28
+
29
+ # Name.
30
+
31
+ label_name = Gtk::Label.new(_("_Name:"))
32
+ label_name.use_underline = true
33
+ label_name.xalign = 0
34
+ @table.attach_defaults(label_name, 0, 1, 0, 1)
35
+
36
+ entry_name = Gtk::Entry.new
37
+ entry_name.mandatory = true
38
+ label_name.mnemonic_widget = entry_name
39
+ @table.attach_defaults(entry_name, 1, 2, 0, 1)
40
+
41
+ # Type.
42
+
43
+ label_type = Gtk::Label.new(_("_Type:"))
44
+ label_type.use_underline = true
45
+ label_type.xalign = 0
46
+ @table.attach_defaults(label_type, 0, 1, 1, 2)
47
+
48
+ combo_type = Gtk::ComboBoxText.new
49
+ instances.each do |instance|
50
+ combo_type.append_text(instance.name)
51
+ end
52
+ combo_type.signal_connect("changed") do |cb|
53
+ @selected_instance = instances[cb.active]
54
+ fill_table(@table, @selected_instance)
55
+ sensitize
56
+ # FIXME: this should be re-written once we have multiple
57
+ # abstract providers.
58
+ end
59
+ combo_type.active = 0
60
+ label_type.mnemonic_widget = combo_type
61
+ @table.attach_defaults(combo_type, 1, 2, 1, 2)
62
+ end
63
+
64
+ def acquire
65
+ show_all
66
+ if run == Gtk::ResponseType::ACCEPT
67
+ @selected_instance.reinitialize(entry_name.text)
68
+ sync_variables
69
+ else
70
+ @selected_instance = nil
71
+ end
72
+ destroy
73
+ end
74
+
75
+ def instance
76
+ @selected_instance
77
+ end
78
+
79
+ private
80
+
81
+ def sensitize
82
+ entries = @table.children.select { |x| x.is_a?(Gtk::Entry) }
83
+ entries.each do |entry|
84
+ entry.signal_connect("changed") do
85
+ sensitive = true
86
+ entries.each do |entry2|
87
+ if entry2.mandatory?
88
+ sensitive = !entry2.text.strip.empty?
89
+ break unless sensitive
90
+ end
91
+ end
92
+ @add_button.sensitive = sensitive
93
+ end
94
+ end
95
+ @add_button.sensitive = false
96
+ end
97
+ end
98
+ end
99
+ end
@@ -8,7 +8,7 @@ module Alexandria
8
8
  module UI
9
9
  class NewSmartLibraryDialog < SmartLibraryPropertiesDialogBase
10
10
  include GetText
11
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
11
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
12
12
 
13
13
  def initialize(parent)
14
14
  super(parent)
@@ -16,7 +16,7 @@ module Alexandria
16
16
  add_buttons([Gtk::Stock::CANCEL, :cancel],
17
17
  [Gtk::Stock::NEW, :ok])
18
18
 
19
- self.title = _('New Smart Library')
19
+ self.title = _("New Smart Library")
20
20
  # FIXME: Should accept just :cancel
21
21
  self.default_response = Gtk::ResponseType::CANCEL
22
22
  end
@@ -29,11 +29,11 @@ module Alexandria
29
29
  (response != Gtk::ResponseType::DELETE_EVENT)
30
30
 
31
31
  if response == Gtk::ResponseType::HELP
32
- Alexandria::UI.display_help(self, 'new-smart-library')
32
+ Alexandria::UI.display_help(self, "new-smart-library")
33
33
  elsif response == Gtk::ResponseType::OK
34
34
  if user_confirms_possible_weirdnesses_before_saving?
35
35
  rules = smart_library_rules
36
- basename = smart_library_base_name(rules) || _('Smart Library')
36
+ basename = smart_library_base_name(rules) || _("Smart Library")
37
37
  name = Library.generate_new_name(
38
38
  LibraryCollection.instance.all_libraries,
39
39
  basename)
@@ -4,247 +4,56 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
- require 'alexandria/ui/builder_base'
8
- require 'alexandria/scanners/cuecat'
9
- require 'alexandria/scanners/keyboard'
10
-
11
- class Gtk::Entry
12
- attr_writer :mandatory
13
- def mandatory?
14
- @mandatory
15
- end
16
- end
7
+ require "alexandria/scanners/cue_cat"
8
+ require "alexandria/scanners/keyboard"
9
+ require "alexandria/ui/builder_base"
10
+ require "alexandria/ui/provider_preferences_dialog"
11
+ require "alexandria/ui/new_provider_dialog"
17
12
 
18
13
  module Alexandria
19
14
  module UI
20
- class ProviderPreferencesBaseDialog < SimpleDelegator
21
- def initialize(title:, parent:, flags:, buttons:)
22
- dialog = Gtk::Dialog.new(title: title, parent: parent, flags: flags, buttons: buttons)
23
- super(dialog)
24
-
25
- self.resizable = false
26
- child.border_width = 12
27
-
28
- @controls = []
29
- end
30
-
31
- def fill_table(table, provider)
32
- i = table.n_rows
33
- table.resize(table.n_rows + provider.prefs.length,
34
- table.n_columns)
35
- table.border_width = 12
36
- table.row_spacings = 6
37
- table.column_spacings = 12
38
-
39
- @controls.clear
40
-
41
- provider.prefs.read.each do |variable|
42
- if variable.name == 'piggyback'
43
- next
44
- # ULTRA-HACK!! for bug #13302
45
- # not displaying the visual choice, as its usually unnecessary
46
- # Either way, this is confusing to the user: FIX
47
- # - Cathal Mc Ginley 2008-02-18
48
- end
49
-
50
- if variable.name == 'enabled'
51
- # also don't display Enabled/Disabled
52
- next
53
- end
54
-
55
- label = Gtk::Label.new('_' + variable.description + ':')
56
- label.use_underline = true
57
- label.xalign = 0
58
- table.attach_defaults(label, 0, 1, i, i + 1)
59
-
60
- if variable.possible_values.nil?
61
- entry = Gtk::Entry.new
62
- entry.text = variable.value.to_s
63
- entry.mandatory = variable.mandatory?
64
- else
65
- entry = Gtk::ComboBoxText.new
66
- variable.possible_values.each do |value|
67
- entry.append_text(value.to_s)
68
- end
69
- index = variable.possible_values.index(variable.value)
70
- entry.active = index
71
- end
72
- label.mnemonic_widget = entry
73
-
74
- @controls << [variable, entry]
75
-
76
- table.attach_defaults(entry, 1, 2, i, i + 1)
77
- i += 1
78
- end
79
- table
80
- end
81
-
82
- def sync_variables
83
- @controls.each do |variable, entry|
84
- variable.new_value = case entry
85
- when Gtk::ComboBox
86
- variable.possible_values[entry.active]
87
- when Gtk::Entry
88
- entry.text
89
- end
90
- end
91
- end
92
- end
93
-
94
- class ProviderPreferencesDialog < ProviderPreferencesBaseDialog
95
- include GetText
96
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
97
-
98
- def initialize(parent, provider)
99
- super(title: _('Preferences for %s') % provider.fullname,
100
- parent: parent,
101
- flags: :modal,
102
- buttons: [[Gtk::Stock::CLOSE, :close]])
103
-
104
- table = Gtk::Table.new(0, 0)
105
- fill_table(table, provider)
106
- child.pack_start(table)
107
-
108
- signal_connect('destroy') { sync_variables }
109
- end
110
-
111
- def acquire
112
- show_all
113
- run
114
- destroy
115
- end
116
- end
117
-
118
- class NewProviderDialog < ProviderPreferencesBaseDialog
119
- include GetText
120
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
121
-
122
- def initialize(parent)
123
- super(title: _('New Provider'),
124
- parent: parent,
125
- flags: :modal,
126
- buttons: [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL]])
127
- @add_button = add_button(Gtk::Stock::ADD,
128
- Gtk::ResponseType::ACCEPT)
129
-
130
- instances = BookProviders.abstract_classes.map(&:new)
131
- @selected_instance = nil
132
-
133
- @table = Gtk::Table.new(2, 2)
134
- child.pack_start(@table)
135
-
136
- # Name.
137
-
138
- label_name = Gtk::Label.new(_('_Name:'))
139
- label_name.use_underline = true
140
- label_name.xalign = 0
141
- @table.attach_defaults(label_name, 0, 1, 0, 1)
142
-
143
- entry_name = Gtk::Entry.new
144
- entry_name.mandatory = true
145
- label_name.mnemonic_widget = entry_name
146
- @table.attach_defaults(entry_name, 1, 2, 0, 1)
147
-
148
- # Type.
149
-
150
- label_type = Gtk::Label.new(_('_Type:'))
151
- label_type.use_underline = true
152
- label_type.xalign = 0
153
- @table.attach_defaults(label_type, 0, 1, 1, 2)
154
-
155
- combo_type = Gtk::ComboBoxText.new
156
- instances.each do |instance|
157
- combo_type.append_text(instance.name)
158
- end
159
- combo_type.signal_connect('changed') do |cb|
160
- @selected_instance = instances[cb.active]
161
- fill_table(@table, @selected_instance)
162
- sensitize
163
- # FIXME: this should be re-written once we have multiple
164
- # abstract providers.
165
- end
166
- combo_type.active = 0
167
- label_type.mnemonic_widget = combo_type
168
- @table.attach_defaults(combo_type, 1, 2, 1, 2)
169
- end
170
-
171
- def acquire
172
- show_all
173
- if run == Gtk::ResponseType::ACCEPT
174
- @selected_instance.reinitialize(entry_name.text)
175
- sync_variables
176
- else
177
- @selected_instance = nil
178
- end
179
- destroy
180
- end
181
-
182
- def instance
183
- @selected_instance
184
- end
185
-
186
- private
187
-
188
- def sensitize
189
- entries = @table.children.select { |x| x.is_a?(Gtk::Entry) }
190
- entries.each do |entry|
191
- entry.signal_connect('changed') do
192
- sensitive = true
193
- entries.each do |entry2|
194
- if entry2.mandatory?
195
- sensitive = !entry2.text.strip.empty?
196
- break unless sensitive
197
- end
198
- end
199
- @add_button.sensitive = sensitive
200
- end
201
- end
202
- @add_button.sensitive = false
203
- end
204
- end
205
-
206
15
  class PreferencesDialog < BuilderBase
207
16
  include Alexandria::Logging
208
17
  include GetText
209
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
18
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
210
19
 
211
20
  def initialize(parent, &changed_block)
212
- super('preferences_dialog__builder.glade', widget_names)
21
+ super("preferences_dialog__builder.glade", widget_names)
213
22
  @preferences_dialog.transient_for = parent
214
23
  @changed_block = changed_block
215
24
 
216
25
  @cols = {
217
- @checkbutton_col_authors => 'col_authors_visible',
218
- @checkbutton_col_isbn => 'col_isbn_visible',
219
- @checkbutton_col_publisher => 'col_publisher_visible',
220
- @checkbutton_col_publish_date => 'col_publish_date_visible',
221
- @checkbutton_col_edition => 'col_edition_visible',
222
- @checkbutton_col_redd => 'col_redd_visible',
223
- @checkbutton_col_own => 'col_own_visible',
224
- @checkbutton_col_want => 'col_want_visible',
225
- @checkbutton_col_rating => 'col_rating_visible',
226
- @checkbutton_col_tags => 'col_tags_visible',
227
- @checkbutton_col_loaned_to => 'col_loaned_to_visible'
26
+ @checkbutton_col_authors => "col_authors_visible",
27
+ @checkbutton_col_isbn => "col_isbn_visible",
28
+ @checkbutton_col_publisher => "col_publisher_visible",
29
+ @checkbutton_col_publish_date => "col_publish_date_visible",
30
+ @checkbutton_col_edition => "col_edition_visible",
31
+ @checkbutton_col_redd => "col_redd_visible",
32
+ @checkbutton_col_own => "col_own_visible",
33
+ @checkbutton_col_want => "col_want_visible",
34
+ @checkbutton_col_rating => "col_rating_visible",
35
+ @checkbutton_col_tags => "col_tags_visible",
36
+ @checkbutton_col_loaned_to => "col_loaned_to_visible"
228
37
  }
229
38
  @cols.each_pair do |checkbutton, pref_name|
230
39
  if checkbutton
231
40
  checkbutton.active = Preferences.instance.send(pref_name)
232
41
  else
233
- log.warn {
42
+ log.warn do
234
43
  "no CheckButton for property #{pref_name} " \
235
- '(probably conflicting versions of GUI and lib code)'
236
- }
44
+ "(probably conflicting versions of GUI and lib code)"
45
+ end
237
46
  end
238
47
  end
239
48
 
240
49
  model = Gtk::ListStore.new(String, String, TrueClass, Integer)
241
50
  @treeview_providers.model = model
242
51
  reload_providers
243
- model.signal_connect_after('row-changed') { update_priority }
52
+ model.signal_connect_after("row-changed") { update_priority }
244
53
 
245
54
  renderer = Gtk::CellRendererToggle.new
246
55
  renderer.activatable = true
247
- renderer.signal_connect('toggled') do |_rndrr, path|
56
+ renderer.signal_connect("toggled") do |_rndrr, path|
248
57
  tree_path = Gtk::TreePath.new(path)
249
58
  @treeview_providers.selection.select_path(tree_path)
250
59
  prov = selected_provider
@@ -256,7 +65,7 @@ module Alexandria
256
65
  end
257
66
 
258
67
  # renderer.active = true
259
- column = Gtk::TreeViewColumn.new('Enabled', renderer)
68
+ column = Gtk::TreeViewColumn.new("Enabled", renderer)
260
69
  column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
261
70
  value = iter[2]
262
71
  rndr.active = value
@@ -265,7 +74,7 @@ module Alexandria
265
74
  @treeview_providers.append_column(column)
266
75
 
267
76
  renderer = Gtk::CellRendererText.new
268
- column = Gtk::TreeViewColumn.new('Providers',
77
+ column = Gtk::TreeViewColumn.new("Providers",
269
78
  renderer)
270
79
  # :text => 0)
271
80
  column.set_cell_data_func(renderer) do |_col, rndr, _mod, iter|
@@ -277,7 +86,7 @@ module Alexandria
277
86
  # rndr.active = value
278
87
  end
279
88
  @treeview_providers.append_column(column)
280
- @treeview_providers.selection.signal_connect('changed') \
89
+ @treeview_providers.selection.signal_connect("changed") \
281
90
  { sensitize_providers }
282
91
 
283
92
  @button_prov_setup.sensitive = false
@@ -318,7 +127,7 @@ module Alexandria
318
127
  @scanner_device_type.model = @scanner_device_model
319
128
  renderer = Gtk::CellRendererText.new
320
129
  @scanner_device_type.pack_start(renderer, true)
321
- @scanner_device_type.add_attribute(renderer, 'text', 0)
130
+ @scanner_device_type.add_attribute(renderer, "text", 0)
322
131
 
323
132
  Alexandria::Scanners.each_scanner do |scanner|
324
133
  iter = @scanner_device_model.append
@@ -335,16 +144,16 @@ module Alexandria
335
144
  def setup_enable_disable_popup
336
145
  # New Enable/Disable pop-up menu...
337
146
  @enable_disable_providers_menu = Gtk::Menu.new
338
- @enable_item = Gtk::MenuItem.new(label: _('Disable Provider'))
339
- @enable_item.signal_connect('activate') {
147
+ @enable_item = Gtk::MenuItem.new(label: _("Disable Provider"))
148
+ @enable_item.signal_connect("activate") do
340
149
  prov = selected_provider
341
150
  prov.toggle_enabled
342
151
  adjust_selected_provider(prov)
343
- }
152
+ end
344
153
  @enable_disable_providers_menu.append(@enable_item)
345
154
  @enable_disable_providers_menu.show_all
346
155
 
347
- @treeview_providers.signal_connect('button_press_event') do |widget, event|
156
+ @treeview_providers.signal_connect("button_press_event") do |widget, event|
348
157
  if event_is_right_click(event)
349
158
  if (path = widget.get_path_at_pos(event.x, event.y))
350
159
  widget.grab_focus
@@ -357,7 +166,7 @@ module Alexandria
357
166
  sel = widget.selection.selected
358
167
  if sel
359
168
  already_enabled = sel[2]
360
- message = already_enabled ? _('Disable Provider') : _('Enable Provider')
169
+ message = already_enabled ? _("Disable Provider") : _("Enable Provider")
361
170
  @enable_item.label = message
362
171
  GLib::Idle.add do
363
172
  @enable_disable_providers_menu.popup(nil, nil, event.button, event.time)
@@ -365,28 +174,28 @@ module Alexandria
365
174
  end
366
175
  end
367
176
  else
368
- puts 'not on a path'
177
+ puts "not on a path"
369
178
  end
370
179
  end
371
180
  end
372
181
 
373
182
  # Popup the menu on Shift-F10
374
- @treeview_providers.signal_connect('popup_menu') {
183
+ @treeview_providers.signal_connect("popup_menu") do
375
184
  selected_prov = @treeview_providers.selection.selected
376
185
  puts selected_prov.inspect
377
186
  if selected_prov
378
187
  GLib::Idle.add do
379
188
  already_enabled = selected_prov[2]
380
- message = already_enabled ? _('Disable Provider') : _('Enable Provider')
189
+ message = already_enabled ? _("Disable Provider") : _("Enable Provider")
381
190
  @enable_item.label = message
382
191
 
383
192
  @enable_disable_providers_menu.popup(nil, nil, 0, :current_time)
384
193
  false
385
194
  end
386
195
  else
387
- puts 'no action'
196
+ puts "no action"
388
197
  end
389
- }
198
+ end
390
199
  end
391
200
 
392
201
  def event_is_right_click(event)
@@ -394,7 +203,7 @@ module Alexandria
394
203
  end
395
204
 
396
205
  def prefs_empty(prefs)
397
- prefs.empty? || ((prefs.size == 1) && (prefs.first.name == 'enabled'))
206
+ prefs.empty? || ((prefs.size == 1) && (prefs.first.name == "enabled"))
398
207
  end
399
208
 
400
209
  def on_provider_setup
@@ -453,17 +262,17 @@ module Alexandria
453
262
  def on_provider_remove
454
263
  provider = selected_provider
455
264
  dialog = AlertDialog.new(@main_app,
456
- _('Are you sure you want to ' \
457
- 'permanently delete the provider ' \
265
+ _("Are you sure you want to " \
266
+ "permanently delete the provider " \
458
267
  "'%s'?") % provider.fullname,
459
268
  Gtk::Stock::DIALOG_QUESTION,
460
269
  [[Gtk::Stock::CANCEL,
461
270
  Gtk::ResponseType::CANCEL],
462
271
  [Gtk::Stock::DELETE,
463
272
  Gtk::ResponseType::OK]],
464
- _('If you continue, the provider and ' \
465
- 'all of its preferences will be ' \
466
- 'permanently deleted.'))
273
+ _("If you continue, the provider and " \
274
+ "all of its preferences will be " \
275
+ "permanently deleted."))
467
276
  dialog.default_response = Gtk::ResponseType::CANCEL
468
277
  dialog.show_all
469
278
  if dialog.run == Gtk::ResponseType::OK
@@ -495,7 +304,7 @@ module Alexandria
495
304
 
496
305
  def on_help
497
306
  Alexandria::UI.display_help(@preferences_dialog,
498
- 'alexandria-preferences')
307
+ "alexandria-preferences")
499
308
  end
500
309
 
501
310
  private