alexandria-book-collection-manager 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.gitignore +4 -1
- data/.rubocop.yml +51 -29
- data/.rubocop_todo.yml +33 -155
- data/.simplecov +5 -2
- data/.travis.yml +10 -4
- data/CHANGELOG.md +19 -0
- data/INSTALL.md +23 -11
- data/README.md +36 -35
- data/Rakefile +7 -5
- data/alexandria-book-collection-manager.gemspec +8 -3
- data/doc/dependency_decisions.yml +22 -3
- data/lib/alexandria.rb +2 -2
- data/lib/alexandria/book_providers.rb +47 -49
- data/lib/alexandria/book_providers/adlibris.rb +8 -13
- data/lib/alexandria/book_providers/amazon_aws.rb +47 -60
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +283 -298
- data/lib/alexandria/book_providers/barnes_and_noble.rb +8 -8
- data/lib/alexandria/book_providers/douban.rb +2 -2
- data/lib/alexandria/book_providers/proxis.rb +12 -11
- data/lib/alexandria/book_providers/pseudomarc.rb +60 -70
- data/lib/alexandria/book_providers/siciliano.rb +5 -6
- data/lib/alexandria/book_providers/thalia.rb +8 -9
- data/lib/alexandria/book_providers/worldcat.rb +25 -31
- data/lib/alexandria/book_providers/z3950.rb +62 -69
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +13 -12
- data/lib/alexandria/export_library.rb +4 -8
- data/lib/alexandria/import_library.rb +38 -62
- data/lib/alexandria/import_library_csv.rb +16 -16
- data/lib/alexandria/library_sort_order.rb +3 -1
- data/lib/alexandria/library_store.rb +16 -16
- data/lib/alexandria/logging.rb +4 -8
- data/lib/alexandria/models/book.rb +2 -2
- data/lib/alexandria/models/library.rb +18 -14
- data/lib/alexandria/net.rb +1 -2
- data/lib/alexandria/preferences.rb +27 -31
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/cue_cat.rb +5 -5
- data/lib/alexandria/scanners/keyboard.rb +1 -1
- data/lib/alexandria/smart_library.rb +22 -26
- data/lib/alexandria/ui.rb +7 -7
- data/lib/alexandria/ui/about_dialog.rb +1 -1
- data/lib/alexandria/ui/acquire_dialog.rb +9 -10
- data/lib/alexandria/ui/alert_dialog.rb +34 -19
- data/lib/alexandria/ui/bad_isbns_dialog.rb +13 -9
- data/lib/alexandria/ui/barcode_animation.rb +5 -5
- data/lib/alexandria/ui/book_properties_dialog.rb +2 -2
- data/lib/alexandria/ui/book_properties_dialog_base.rb +23 -17
- data/lib/alexandria/ui/callbacks.rb +141 -120
- data/lib/alexandria/ui/completion_models.rb +1 -1
- data/lib/alexandria/ui/confirm_erase_dialog.rb +1 -1
- data/lib/alexandria/ui/conflict_while_copying_dialog.rb +1 -1
- data/lib/alexandria/ui/error_dialog.rb +1 -1
- data/lib/alexandria/ui/export_dialog.rb +13 -15
- data/lib/alexandria/ui/icons.rb +34 -40
- data/lib/alexandria/ui/iconview_tooltips.rb +40 -53
- data/lib/alexandria/ui/import_dialog.rb +48 -47
- data/lib/alexandria/ui/init.rb +3 -2
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +2 -2
- data/lib/alexandria/ui/libraries_combo.rb +10 -9
- data/lib/alexandria/ui/listview.rb +5 -6
- data/lib/alexandria/ui/main_app.rb +2 -2
- data/lib/alexandria/ui/multi_drag_treeview.rb +4 -6
- data/lib/alexandria/ui/new_book_dialog.rb +52 -52
- data/lib/alexandria/ui/new_provider_dialog.rb +12 -11
- data/lib/alexandria/ui/new_smart_library_dialog.rb +39 -27
- data/lib/alexandria/ui/preferences_dialog.rb +23 -82
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +9 -5
- data/lib/alexandria/ui/provider_preferences_dialog.rb +5 -5
- data/lib/alexandria/ui/really_delete_dialog.rb +1 -1
- data/lib/alexandria/ui/sidepane_manager.rb +35 -37
- data/lib/alexandria/ui/skip_entry_dialog.rb +3 -2
- data/lib/alexandria/ui/smart_library_properties_dialog.rb +35 -36
- data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +59 -138
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +4 -6
- data/lib/alexandria/ui/ui_manager.rb +62 -64
- data/lib/alexandria/version.rb +2 -2
- data/lib/alexandria/web_themes.rb +15 -15
- data/po/cs.po +991 -874
- data/po/cy.po +957 -870
- data/po/de.po +991 -866
- data/po/el.po +987 -863
- data/po/es.po +986 -862
- data/po/fr.po +988 -868
- data/po/ga.po +910 -822
- data/po/gl.po +983 -863
- data/po/it.po +984 -862
- data/po/ja.po +969 -849
- data/po/mk.po +983 -859
- data/po/nb.po +982 -862
- data/po/nl.po +992 -869
- data/po/pl.po +1018 -963
- data/po/pt.po +983 -852
- data/po/pt_BR.po +983 -863
- data/po/ru.po +992 -869
- data/po/sk.po +986 -864
- data/po/sv.po +980 -860
- data/po/uk.po +975 -861
- data/po/zh_TW.po +974 -854
- data/share/alexandria/glade/main_app__builder.glade +6 -21
- data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
- data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +73 -129
- data/spec/alexandria/console_spec.rb +0 -5
- data/spec/alexandria/export_library_spec.rb +27 -38
- data/spec/alexandria/library_spec.rb +56 -44
- data/spec/alexandria/preferences_spec.rb +29 -3
- data/spec/alexandria/scanners/cue_cat_spec.rb +1 -1
- data/spec/alexandria/ui/about_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/acquire_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/alert_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/book_properties_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/error_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/export_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +1 -1
- data/spec/alexandria/ui/import_dialog_spec.rb +30 -3
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/main_app_spec.rb +1 -1
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +1 -1
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +19 -3
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +28 -3
- data/spec/alexandria/ui/preferences_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +23 -8
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/sidepane_manager_spec.rb +2 -2
- data/spec/alexandria/ui/skip_entry_dialog_spec.rb +1 -1
- data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +21 -7
- data/spec/alexandria/ui/ui_manager_spec.rb +39 -2
- data/spec/spec_helper.rb +46 -3
- data/tasks/spec.rake +3 -5
- data/util/rake/fileinstall.rb +12 -11
- metadata +82 -10
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
- data/spec/alexandria/utilities_spec.rb +0 -52
@@ -72,8 +72,7 @@ module Alexandria
|
|
72
72
|
additional.split(",").each do |add|
|
73
73
|
authors << normalize(add)
|
74
74
|
end
|
75
|
-
isbn = row[@isbn]
|
76
|
-
isbn = Library.canonicalise_ean(isbn) if isbn
|
75
|
+
isbn = Library.canonicalise_ean(row[@isbn])
|
77
76
|
publisher = normalize(row[@publisher])
|
78
77
|
year = row[@publishing_year].to_i
|
79
78
|
edition = normalize(row[@edition])
|
@@ -95,12 +94,13 @@ module Alexandria
|
|
95
94
|
book.redd = true
|
96
95
|
end
|
97
96
|
if row[@mainshelf]
|
98
|
-
|
97
|
+
case row[@mainshelf]
|
98
|
+
when "read"
|
99
99
|
book.redd = true
|
100
|
-
|
100
|
+
when "to-read"
|
101
101
|
book.redd = false
|
102
102
|
book.tags = ["to read"]
|
103
|
-
|
103
|
+
when "currently-reading"
|
104
104
|
book.redd = false
|
105
105
|
book.tags = ["currently reading"]
|
106
106
|
end
|
@@ -112,7 +112,7 @@ module Alexandria
|
|
112
112
|
book.tags << tag unless book.tags.include? tag
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
115
|
+
log.debug { "Goodreads loading #{book.title}" }
|
116
116
|
book
|
117
117
|
end
|
118
118
|
end
|
@@ -146,7 +146,7 @@ module Alexandria
|
|
146
146
|
# sometimes "Publisher (YEAR), Edition: NUM, Binding, NUM pages"
|
147
147
|
publisher_info = normalize(row[@publisher_info])
|
148
148
|
publisher = publisher_info
|
149
|
-
publisher = Regexp.last_match[1] if publisher_info =~ /([
|
149
|
+
publisher = Regexp.last_match[1] if publisher_info =~ /([^(]+)\(/
|
150
150
|
edition = publisher_info # binding
|
151
151
|
edition_info = publisher_info.split(",")
|
152
152
|
edition = publisher_info.split(",")[-2] if edition_info.size >= 3
|
@@ -169,7 +169,7 @@ module Alexandria
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
|
172
|
+
log.debug { "LibraryThing loading #{book.title}" }
|
173
173
|
book
|
174
174
|
end
|
175
175
|
end
|
@@ -183,20 +183,20 @@ module Alexandria
|
|
183
183
|
is_librarything = false
|
184
184
|
is_goodreads = false
|
185
185
|
header.each do |head|
|
186
|
-
|
186
|
+
case head
|
187
|
+
when "'PUBLICATION INFO'"
|
187
188
|
is_librarything = true
|
188
189
|
break
|
189
|
-
|
190
|
+
when "Year Published"
|
190
191
|
is_goodreads = true
|
191
192
|
break
|
192
193
|
end
|
193
194
|
end
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
raise "Not Recognized" unless is_librarything || is_goodreads
|
195
|
+
|
196
|
+
return LibraryThingCSVImport.new(header) if is_librarything
|
197
|
+
return GoodreadsCSVImport.new(header) if is_goodreads
|
198
|
+
|
199
|
+
raise _("Not Recognized") unless is_librarything || is_goodreads
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
@@ -9,7 +9,7 @@ module Alexandria
|
|
9
9
|
include Logging
|
10
10
|
|
11
11
|
FIX_BIGNUM_REGEX =
|
12
|
-
%r{loaned_since:\s*(
|
12
|
+
%r{loaned_since:\s*(!ruby/object:Bignum\s*)?(\d+)\n}.freeze
|
13
13
|
|
14
14
|
include GetText
|
15
15
|
bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
@@ -23,7 +23,7 @@ module Alexandria
|
|
23
23
|
begin
|
24
24
|
Dir.entries(library_dir).each do |file|
|
25
25
|
# Skip hidden files.
|
26
|
-
next if
|
26
|
+
next if file.start_with?(".")
|
27
27
|
# Skip non-directory files.
|
28
28
|
next unless File.stat(File.join(library_dir, file)).directory?
|
29
29
|
|
@@ -64,7 +64,7 @@ module Alexandria
|
|
64
64
|
old_isbn = book.isbn
|
65
65
|
old_pub_year = book.publishing_year
|
66
66
|
begin
|
67
|
-
raise "Not a book:
|
67
|
+
raise format(_("Not a book: %<book>s"), book.inspect) unless book.is_a?(Book)
|
68
68
|
|
69
69
|
ean = Library.canonicalise_ean(book.isbn)
|
70
70
|
book.isbn = ean if ean
|
@@ -74,16 +74,18 @@ module Alexandria
|
|
74
74
|
end
|
75
75
|
|
76
76
|
# Or if isbn has changed
|
77
|
-
|
77
|
+
unless book.isbn == old_isbn
|
78
|
+
raise format(_("%<file>s isbn is not okay"), file: test[1])
|
79
|
+
end
|
78
80
|
|
79
81
|
# Re-save book if Alexandria::DATA_VERSION changes
|
80
82
|
unless book.version == Alexandria::DATA_VERSION
|
81
|
-
raise "
|
83
|
+
raise format(_("%<file>s version is not okay"), file: test[1])
|
82
84
|
end
|
83
85
|
|
84
86
|
# Or if publishing year has changed
|
85
87
|
unless book.publishing_year == old_pub_year
|
86
|
-
raise "
|
88
|
+
raise format(_("%<file>s pub year is not okay"), file: test[1])
|
87
89
|
end
|
88
90
|
|
89
91
|
# ruined_books << [book, book.isbn, library]
|
@@ -92,13 +94,11 @@ module Alexandria
|
|
92
94
|
## TODO copy cover image file, if necessary
|
93
95
|
# due to #26909 cover files for books without ISBN are re-saved as
|
94
96
|
# "g#{ident}.cover"
|
95
|
-
if book.isbn.nil? || book.isbn.empty?
|
96
|
-
|
97
|
-
|
98
|
-
"#{library.name}; book #{book.title} has no ISBN, fixing cover image"
|
99
|
-
end
|
100
|
-
FileUtils::Verbose.mv(library.old_cover(book), library.cover(book))
|
97
|
+
if (book.isbn.nil? || book.isbn.empty?) && File.exist?(library.old_cover(book))
|
98
|
+
log.debug do
|
99
|
+
"#{library.name}; book #{book.title} has no ISBN, fixing cover image"
|
101
100
|
end
|
101
|
+
FileUtils::Verbose.mv(library.old_cover(book), library.cover(book))
|
102
102
|
end
|
103
103
|
|
104
104
|
library << book
|
@@ -198,14 +198,14 @@ module Alexandria
|
|
198
198
|
if (md = FIX_BIGNUM_REGEX.match(text))
|
199
199
|
new_yaml = Time.at(md[2].to_i).to_yaml
|
200
200
|
# Remove the "---" prefix.
|
201
|
-
new_yaml.sub!(/^\s
|
201
|
+
new_yaml.sub!(/^\s*-+\s*/, "")
|
202
202
|
text.sub!(md[0], "loaned_since: #{new_yaml}\n")
|
203
203
|
end
|
204
204
|
|
205
205
|
# TODO: Ensure book loading passes through Book#initialize
|
206
206
|
book = YAML.safe_load(text, permitted_classes: [Book, Time])
|
207
207
|
|
208
|
-
unless book.isbn.
|
208
|
+
unless book.isbn.instance_of? String
|
209
209
|
# HACK
|
210
210
|
md = /isbn: (.+)/.match(text)
|
211
211
|
if md
|
@@ -215,7 +215,7 @@ module Alexandria
|
|
215
215
|
end
|
216
216
|
|
217
217
|
# another HACK of the same type as above
|
218
|
-
unless book.saved_ident.
|
218
|
+
unless book.saved_ident.instance_of? String
|
219
219
|
|
220
220
|
md2 = /saved_ident: (.+)/.match(text)
|
221
221
|
if md2
|
@@ -224,7 +224,7 @@ module Alexandria
|
|
224
224
|
book.saved_ident = string_saved_ident
|
225
225
|
end
|
226
226
|
end
|
227
|
-
if (book.isbn.
|
227
|
+
if (book.isbn.instance_of? String) && book.isbn.empty?
|
228
228
|
book.isbn = nil # save trouble later
|
229
229
|
end
|
230
230
|
book
|
data/lib/alexandria/logging.rb
CHANGED
@@ -25,7 +25,7 @@ module Alexandria
|
|
25
25
|
# A Logger subclass which accepts a source for log messages
|
26
26
|
# in order to improve legibility of the logs.
|
27
27
|
# The source should usually be +self+, whether that be a Class, Module
|
28
|
-
# or Object. A
|
28
|
+
# or Object. A LogWrapper can be used to simplify this procedure.
|
29
29
|
class Logger < ::Logger
|
30
30
|
def add(severity, message = nil, source = nil, progname = nil, &block)
|
31
31
|
return super(severity, message, progname, &block) if source.nil?
|
@@ -118,7 +118,7 @@ module Alexandria
|
|
118
118
|
module Logging
|
119
119
|
module ClassMethods
|
120
120
|
def log
|
121
|
-
@
|
121
|
+
@log ||= LogWrapper.new(Alexandria.log, self)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -127,15 +127,13 @@ module Alexandria
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def log
|
130
|
-
@
|
130
|
+
@log ||= LogWrapper.new(Alexandria.log, self)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
private
|
135
|
-
|
136
134
|
# Creates the Logger for Alexandria
|
137
135
|
def self.create_logger
|
138
|
-
logger = Alexandria::Logger.new(
|
136
|
+
logger = Alexandria::Logger.new($stderr)
|
139
137
|
|
140
138
|
level = ENV["LOGLEVEL"] ? ENV["LOGLEVEL"].intern : nil
|
141
139
|
if [:FATAL, :ERROR, :WARN, :INFO, :DEBUG].include? level
|
@@ -150,8 +148,6 @@ module Alexandria
|
|
150
148
|
|
151
149
|
@@logger = create_logger
|
152
150
|
|
153
|
-
public
|
154
|
-
|
155
151
|
# Returns the Logger for Alexandria
|
156
152
|
def self.log
|
157
153
|
@@logger
|
@@ -17,6 +17,7 @@ module Alexandria
|
|
17
17
|
|
18
18
|
attr_reader :name
|
19
19
|
attr_accessor :ruined_books, :updating, :deleted_books
|
20
|
+
|
20
21
|
DEFAULT_DIR = File.join(ENV["HOME"], ".alexandria")
|
21
22
|
EXT = { book: ".yaml", cover: ".cover" }.freeze
|
22
23
|
|
@@ -95,8 +96,8 @@ module Alexandria
|
|
95
96
|
end
|
96
97
|
|
97
98
|
def self.ean_checksum(numbers)
|
98
|
-
-(numbers.values_at(1, 3, 5, 7, 9, 11).
|
99
|
-
numbers.values_at(0, 2, 4, 6, 8, 10).
|
99
|
+
-(numbers.values_at(1, 3, 5, 7, 9, 11).sum * 3 +
|
100
|
+
numbers.values_at(0, 2, 4, 6, 8, 10).sum) % 10
|
100
101
|
end
|
101
102
|
|
102
103
|
def self.valid_ean?(ean)
|
@@ -108,8 +109,8 @@ module Alexandria
|
|
108
109
|
end
|
109
110
|
|
110
111
|
def self.upc_checksum(numbers)
|
111
|
-
-(numbers.values_at(0, 2, 4, 6, 8, 10).
|
112
|
-
numbers.values_at(1, 3, 5, 7, 9).
|
112
|
+
-(numbers.values_at(0, 2, 4, 6, 8, 10).sum * 3 +
|
113
|
+
numbers.values_at(1, 3, 5, 7, 9).sum) % 10
|
113
114
|
end
|
114
115
|
|
115
116
|
def self.valid_upc?(upc)
|
@@ -221,11 +222,11 @@ module Alexandria
|
|
221
222
|
File.open(yaml(temp_book), "w") { |io| io.puts temp_book.to_yaml }
|
222
223
|
|
223
224
|
# Do not notify twice.
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
225
|
+
return unless changed?
|
226
|
+
|
227
|
+
notify_observers(self,
|
228
|
+
already_there ? BOOK_UPDATED : BOOK_ADDED,
|
229
|
+
book)
|
229
230
|
end
|
230
231
|
|
231
232
|
def transport
|
@@ -283,7 +284,10 @@ module Alexandria
|
|
283
284
|
else
|
284
285
|
if @deleted_books.include?(book)
|
285
286
|
doubles = @deleted_books.select { |b| b.equal?(book) }
|
286
|
-
|
287
|
+
unless doubles.empty?
|
288
|
+
raise ArgumentError, format(_("Book %<isbn>s was already deleted"),
|
289
|
+
isbn: book.isbn)
|
290
|
+
end
|
287
291
|
end
|
288
292
|
@deleted_books << book
|
289
293
|
i = index(book)
|
@@ -346,7 +350,7 @@ module Alexandria
|
|
346
350
|
when Integer
|
347
351
|
something
|
348
352
|
else
|
349
|
-
raise
|
353
|
+
raise NotImplementedError
|
350
354
|
end
|
351
355
|
File.join(path, ident.to_s + EXT[:cover])
|
352
356
|
end
|
@@ -360,7 +364,7 @@ module Alexandria
|
|
360
364
|
when Integer
|
361
365
|
something
|
362
366
|
else
|
363
|
-
raise
|
367
|
+
raise NotImplementedError
|
364
368
|
end
|
365
369
|
File.join(basedir, ident.to_s + EXT[:book])
|
366
370
|
end
|
@@ -378,8 +382,8 @@ module Alexandria
|
|
378
382
|
length - n_rated
|
379
383
|
end
|
380
384
|
|
381
|
-
def ==(
|
382
|
-
|
385
|
+
def ==(other)
|
386
|
+
other.is_a?(self.class) && other.name == name
|
383
387
|
end
|
384
388
|
|
385
389
|
def copy_covers(somewhere)
|
data/lib/alexandria/net.rb
CHANGED
@@ -38,10 +38,9 @@ module Alexandria
|
|
38
38
|
@extra_request_headers.each_pair do |header_name, value|
|
39
39
|
req.add_field(header_name, value)
|
40
40
|
end
|
41
|
-
|
41
|
+
WWWAgent.transport.start(uri.host, uri.port) do |http|
|
42
42
|
http.request(req)
|
43
43
|
end
|
44
|
-
res
|
45
44
|
end
|
46
45
|
|
47
46
|
def language=(lang)
|
@@ -57,30 +57,24 @@ module Alexandria
|
|
57
57
|
@changed_settings.clear
|
58
58
|
end
|
59
59
|
|
60
|
-
def method_missing(id, *args)
|
61
|
-
method = id.id2name
|
62
|
-
if (match = /(.*)=$/.match(method))
|
63
|
-
if args.length != 1
|
64
|
-
raise "Set method #{method} should be called with " \
|
65
|
-
"only one argument (was called with #{args.length})"
|
66
|
-
end
|
67
|
-
variable_name = match[1]
|
68
|
-
new_value = args.first
|
69
|
-
generic_setter(variable_name, new_value)
|
70
|
-
else
|
71
|
-
unless args.empty?
|
72
|
-
raise "Get method #{method} should be called " \
|
73
|
-
"without argument (was called with #{args.length})"
|
74
|
-
end
|
75
|
-
generic_getter(method)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
60
|
def remove_preference(variable_name)
|
80
61
|
@alexandria_settings.delete(variable_name)
|
81
62
|
@changed_settings << variable_name
|
82
63
|
end
|
83
64
|
|
65
|
+
DEFAULT_VALUES.each_key do |var|
|
66
|
+
define_method(var) { generic_getter var }
|
67
|
+
define_method("#{var}=") { |val| generic_setter var, val }
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_variable(variable_name)
|
71
|
+
generic_getter(variable_name.to_s)
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_variable(variable_name, value)
|
75
|
+
generic_setter(variable_name.to_s, value)
|
76
|
+
end
|
77
|
+
|
84
78
|
private
|
85
79
|
|
86
80
|
##
|
@@ -140,11 +134,12 @@ module Alexandria
|
|
140
134
|
##
|
141
135
|
|
142
136
|
def get_gconf_type(value)
|
143
|
-
|
137
|
+
case value
|
138
|
+
when String
|
144
139
|
"string"
|
145
|
-
|
140
|
+
when Integer
|
146
141
|
"int"
|
147
|
-
|
142
|
+
when TrueClass, FalseClass
|
148
143
|
"bool"
|
149
144
|
else
|
150
145
|
"string"
|
@@ -168,24 +163,24 @@ module Alexandria
|
|
168
163
|
end
|
169
164
|
|
170
165
|
def make_list_string(list)
|
171
|
-
list.map! { |x| x.gsub(
|
166
|
+
list.map! { |x| x.gsub(/"/, '\\"') } if get_gconf_type(list.first) == "string"
|
172
167
|
contents = list.join(",")
|
173
168
|
"[" + contents + "]"
|
174
169
|
end
|
175
170
|
|
176
171
|
def exec_gconf_set(var_path, new_value)
|
177
172
|
if /cols_width/.match?(var_path)
|
178
|
-
|
173
|
+
log.debug { new_value }
|
179
174
|
|
180
175
|
# new_value = {}
|
181
176
|
end
|
182
177
|
type = get_gconf_type(new_value)
|
183
178
|
value_str = new_value
|
184
179
|
if new_value.is_a? String
|
185
|
-
new_value = new_value.gsub(
|
180
|
+
new_value = new_value.gsub(/"/, '\\"')
|
186
181
|
value_str = "\"#{new_value}\""
|
187
182
|
end
|
188
|
-
|
183
|
+
log.debug { value_str } if /cols_width/.match?(var_path)
|
189
184
|
`gconftool-2 --type #{type} --set #{var_path} #{value_str}`
|
190
185
|
end
|
191
186
|
|
@@ -242,15 +237,16 @@ module Alexandria
|
|
242
237
|
# gconftool. This is not fool-proof, but it *does* work for the
|
243
238
|
# range of values used by Alexandria.
|
244
239
|
def discriminate(value)
|
245
|
-
|
240
|
+
case value
|
241
|
+
when "true" # bool
|
246
242
|
true
|
247
|
-
|
243
|
+
when "false" # bool
|
248
244
|
false
|
249
|
-
|
245
|
+
when /^[0-9]+$/ # int
|
250
246
|
value.to_i
|
251
|
-
|
247
|
+
when /^\[(.*)\]$/ # list (assume of type String)
|
252
248
|
Regexp.last_match[1].split(",")
|
253
|
-
|
249
|
+
when /^\((.*)\)$/ # pair (assume of type int)
|
254
250
|
begin
|
255
251
|
pair = Regexp.last_match[1].split(",")
|
256
252
|
[discriminate(pair.first), discriminate(pair.last)]
|