alexandria-book-collection-manager 0.7.1 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +5 -2
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +113 -45
  6. data/.rubocop_todo.yml +82 -170
  7. data/.simplecov +5 -1
  8. data/.travis.yml +45 -0
  9. data/.yardopts +1 -1
  10. data/CHANGELOG.md +60 -0
  11. data/ChangeLog.0 +33 -35
  12. data/Gemfile +6 -5
  13. data/INSTALL.md +164 -0
  14. data/README.md +52 -42
  15. data/Rakefile +95 -109
  16. data/TODO.md +9 -1
  17. data/alexandria-book-collection-manager.gemspec +52 -45
  18. data/bin/alexandria +31 -53
  19. data/doc/AUTHORS +61 -0
  20. data/doc/BUGS +31 -0
  21. data/doc/FAQ +365 -0
  22. data/doc/HACKING +19 -0
  23. data/doc/NEWS +341 -0
  24. data/doc/alexandria.1 +120 -0
  25. data/doc/cuecat_support.rdoc +67 -0
  26. data/doc/dependency_decisions.yml +80 -0
  27. data/lib/alexandria.rb +29 -37
  28. data/lib/alexandria/about.rb +52 -51
  29. data/lib/alexandria/book_providers.rb +94 -101
  30. data/lib/alexandria/book_providers/adlibris.rb +45 -85
  31. data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
  32. data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
  33. data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
  34. data/lib/alexandria/book_providers/douban.rb +29 -51
  35. data/lib/alexandria/book_providers/proxis.rb +42 -59
  36. data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
  37. data/lib/alexandria/book_providers/siciliano.rb +68 -70
  38. data/lib/alexandria/book_providers/thalia.rb +46 -45
  39. data/lib/alexandria/book_providers/web.rb +17 -33
  40. data/lib/alexandria/book_providers/worldcat.rb +74 -102
  41. data/lib/alexandria/book_providers/z3950.rb +170 -174
  42. data/lib/alexandria/config.rb +5 -3
  43. data/lib/alexandria/console.rb +10 -21
  44. data/lib/alexandria/default_preferences.rb +37 -0
  45. data/lib/alexandria/execution_queue.rb +17 -15
  46. data/lib/alexandria/export_format.rb +47 -0
  47. data/lib/alexandria/export_library.rb +188 -302
  48. data/lib/alexandria/import_library.rb +114 -155
  49. data/lib/alexandria/import_library_csv.rb +46 -96
  50. data/lib/alexandria/library_collection.rb +79 -0
  51. data/lib/alexandria/library_sort_order.rb +45 -0
  52. data/lib/alexandria/library_store.rb +233 -0
  53. data/lib/alexandria/logging.rb +15 -19
  54. data/lib/alexandria/models/book.rb +15 -20
  55. data/lib/alexandria/models/library.rb +81 -363
  56. data/lib/alexandria/net.rb +7 -6
  57. data/lib/alexandria/preferences.rb +73 -91
  58. data/lib/alexandria/scanners.rb +4 -2
  59. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
  60. data/lib/alexandria/scanners/keyboard.rb +10 -8
  61. data/lib/alexandria/smart_library.rb +135 -171
  62. data/lib/alexandria/ui.rb +17 -15
  63. data/lib/alexandria/ui/about_dialog.rb +49 -0
  64. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
  65. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  66. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  67. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
  68. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
  69. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
  70. data/lib/alexandria/ui/builder_base.rb +9 -27
  71. data/lib/alexandria/ui/callbacks.rb +188 -186
  72. data/lib/alexandria/ui/columns.rb +2 -0
  73. data/lib/alexandria/ui/completion_models.rb +12 -23
  74. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  75. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  76. data/lib/alexandria/ui/dndable.rb +10 -8
  77. data/lib/alexandria/ui/error_dialog.rb +25 -0
  78. data/lib/alexandria/ui/export_dialog.rb +139 -0
  79. data/lib/alexandria/ui/icons.rb +49 -65
  80. data/lib/alexandria/ui/iconview.rb +15 -13
  81. data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
  82. data/lib/alexandria/ui/import_dialog.rb +157 -0
  83. data/lib/alexandria/ui/init.rb +23 -33
  84. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  85. data/lib/alexandria/ui/libraries_combo.rb +18 -14
  86. data/lib/alexandria/ui/listview.rb +77 -88
  87. data/lib/alexandria/ui/main_app.rb +26 -26
  88. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  89. data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
  90. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
  91. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  92. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  93. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  94. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  95. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  96. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  97. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  98. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
  99. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  100. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  101. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
  102. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  103. data/lib/alexandria/ui/sound.rb +13 -13
  104. data/lib/alexandria/ui/ui_manager.rb +262 -283
  105. data/lib/alexandria/undo_manager.rb +3 -0
  106. data/lib/alexandria/version.rb +6 -19
  107. data/lib/alexandria/web_themes.rb +24 -21
  108. data/po/Makefile +2 -2
  109. data/po/cs.po +993 -880
  110. data/po/cy.po +957 -874
  111. data/po/de.po +990 -869
  112. data/po/el.po +989 -869
  113. data/po/es.po +985 -865
  114. data/po/fr.po +986 -870
  115. data/po/ga.po +907 -823
  116. data/po/gl.po +981 -865
  117. data/po/it.po +986 -868
  118. data/po/ja.po +969 -853
  119. data/po/mk.po +983 -863
  120. data/po/nb.po +979 -863
  121. data/po/nl.po +983 -864
  122. data/po/pl.po +1020 -969
  123. data/po/pt.po +988 -861
  124. data/po/pt_BR.po +984 -868
  125. data/po/ru.po +992 -873
  126. data/po/sk.po +987 -869
  127. data/po/sv.po +977 -861
  128. data/po/uk.po +975 -865
  129. data/po/zh_TW.po +976 -860
  130. data/schemas/alexandria.schemas +25 -3
  131. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  132. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  133. data/share/alexandria/glade/main_app__builder.glade +24 -33
  134. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  135. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  136. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  137. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  138. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  139. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  140. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  141. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  142. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  143. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  144. data/spec/alexandria/book_providers_spec.rb +77 -210
  145. data/spec/alexandria/book_spec.rb +16 -12
  146. data/spec/alexandria/console_spec.rb +27 -0
  147. data/spec/alexandria/export_library_spec.rb +130 -0
  148. data/spec/alexandria/library_spec.rb +130 -172
  149. data/spec/alexandria/library_store_spec.rb +37 -0
  150. data/spec/alexandria/preferences_spec.rb +46 -17
  151. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  152. data/spec/alexandria/smart_library_spec.rb +32 -25
  153. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  154. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  155. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  156. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  157. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  159. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  160. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  161. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  162. data/spec/alexandria/ui/icons_spec.rb +26 -0
  163. data/spec/alexandria/ui/iconview_spec.rb +9 -21
  164. data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
  165. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  166. data/spec/alexandria/ui/main_app_spec.rb +8 -33
  167. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  168. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  169. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  170. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  171. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  172. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  173. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  174. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  175. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  176. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
  177. data/spec/alexandria/ui/sound_spec.rb +4 -2
  178. data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
  179. data/spec/end_to_end/basic_run_spec.rb +57 -0
  180. data/spec/spec_helper.rb +66 -33
  181. data/tasks/setup.rb +5 -3
  182. data/tasks/spec.rake +18 -3
  183. data/util/rake/fileinstall.rb +38 -40
  184. data/util/rake/gettextgenerate.rb +15 -70
  185. data/util/rake/omfgenerate.rb +10 -10
  186. metadata +176 -60
  187. data/INSTALL.rdoc +0 -148
  188. data/dogtail/basic_run_test.py +0 -9
  189. data/lib/alexandria/book_providers/bol_it.rb +0 -160
  190. data/lib/alexandria/book_providers/deastore.rb +0 -273
  191. data/lib/alexandria/book_providers/ibs_it.rb +0 -147
  192. data/lib/alexandria/book_providers/mcu.rb +0 -169
  193. data/lib/alexandria/book_providers/renaud.rb +0 -140
  194. data/lib/alexandria/book_providers/webster_it.rb +0 -167
  195. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
  196. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
  197. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
  198. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  199. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  200. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
  201. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  202. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  203. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
  204. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
  205. data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
  206. data/spec/alexandria/ui/dialogs_spec.rb +0 -94
  207. data/spec/alexandria/ui/sidepane_spec.rb +0 -27
  208. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
  209. data/spec/alexandria/utilities_spec.rb +0 -50
  210. data/tasks/dogtail.rake +0 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alexandria
2
4
  module UI
3
5
  module Columns
@@ -1,20 +1,8 @@
1
- # Copyright (C) 2005-2006 Laurent Sansonetti
2
- # Copyright (C) 2011, 2016 Matijs van Zuijlen
3
- #
4
- # Alexandria is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU General Public License as
6
- # published by the Free Software Foundation; either version 2 of the
7
- # License, or (at your option) any later version.
8
- #
9
- # Alexandria is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # General Public License for more details.
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
13
4
  #
14
- # You should have received a copy of the GNU General Public
15
- # License along with Alexandria; see the file COPYING. If not,
16
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
18
6
 
19
7
  module Alexandria
20
8
  module EntryOverrides
@@ -42,26 +30,26 @@ module Alexandria
42
30
  complete(Alexandria::UI::CompletionModels::TAG)
43
31
  # min = self.completion.minimum_key_length
44
32
  min = 2
45
- completion.signal_connect('match-selected') do |c, model, iter|
33
+ completion.signal_connect("match-selected") do |c, model, iter|
46
34
  cur_text = c.entry.text
47
35
  # TODO: Replace with iter[0] if possible
48
36
  new_tag = model.get_value(iter, 0)
49
- cur_text_split = cur_text.split(',')
37
+ cur_text_split = cur_text.split(",")
50
38
  cur_text_split.delete_at(-1)
51
39
  cur_text_split << new_tag
52
- c.entry.text = cur_text_split.join(',')
40
+ c.entry.text = cur_text_split.join(",")
53
41
  true
54
42
  end
55
43
  completion.set_match_func do |_comp, key, iter|
56
- cur_tag = key.split(',').last.strip
44
+ cur_tag = key.split(",").last.strip
57
45
  if cur_tag.size >= min
58
46
  begin
59
- if iter[0] =~ /^#{cur_tag}/
47
+ if /^#{cur_tag}/.match?(iter[0])
60
48
  true
61
49
  else
62
50
  false
63
51
  end
64
- rescue
52
+ rescue StandardError
65
53
  false
66
54
  end
67
55
  else
@@ -176,7 +164,7 @@ module Alexandria
176
164
  editions << book.edition
177
165
  borrowers << book.loaned_to
178
166
  # TODO: Ensure #tags is always an array
179
- (book.tags || []).each { |tag| tags << tag }
167
+ tags.concat(book.tags) if book.tags
180
168
  end
181
169
  end
182
170
 
@@ -198,6 +186,7 @@ module Alexandria
198
186
  iter = nil
199
187
  values.uniq.each do |value|
200
188
  next if value.nil?
189
+
201
190
  iter = iter ? model.insert_after(iter) : model.append
202
191
  iter[0] = value
203
192
  end
@@ -0,0 +1,33 @@
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/alert_dialog"
8
+
9
+ module Alexandria
10
+ module UI
11
+ class ConfirmEraseDialog < AlertDialog
12
+ include GetText
13
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
14
+
15
+ def initialize(parent, filename)
16
+ super(parent, _("File already exists"),
17
+ Gtk::Stock::DIALOG_QUESTION,
18
+ [[Gtk::Stock::CANCEL, :cancel],
19
+ [_("_Replace"), :ok]],
20
+ _("A file named '%s' already exists. Do you want " \
21
+ "to replace it with the one you are generating?") % filename)
22
+ # FIXME: Should accept just :cancel
23
+ dialog.default_response = Gtk::ResponseType::CANCEL
24
+ end
25
+
26
+ def erase?
27
+ show_all && (@response = run)
28
+ destroy
29
+ @response == Gtk::ResponseType::OK
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
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/alert_dialog"
8
+
9
+ module Alexandria
10
+ module UI
11
+ class ConflictWhileCopyingDialog < AlertDialog
12
+ include GetText
13
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
14
+
15
+ def initialize(parent, library, book)
16
+ super(parent,
17
+ format(_("The book '%s' already exists in '%s'. Would you like " \
18
+ "to replace it?"), book.title, library.name),
19
+ Gtk::Stock::DIALOG_QUESTION,
20
+ [[_("_Skip"), Gtk::ResponseType::CANCEL],
21
+ [_("_Replace"), Gtk::ResponseType::OK]],
22
+ _("If you replace the existing book, its contents will " \
23
+ "be overwritten."))
24
+ dialog.default_response = Gtk::ResponseType::CANCEL
25
+ end
26
+
27
+ def replace?
28
+ show_all && (@response = run)
29
+ destroy
30
+ @response == Gtk::ResponseType::OK
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (C) 2004-2006 Laurent Sansonetti
2
4
  # Copyright (C) 2008 Joseph Method
3
5
  # Copyright (C) 2016 Matijs van Zuijlen
@@ -19,15 +21,15 @@
19
21
 
20
22
  module Alexandria
21
23
  module UI
22
- BOOKS_TARGET_TABLE = [Gtk::TargetEntry.new('ALEXANDRIA_BOOKS', :same_app, 0)].freeze
24
+ BOOKS_TARGET_TABLE = [Gtk::TargetEntry.new("ALEXANDRIA_BOOKS", :same_app, 0)].freeze
23
25
 
24
26
  module DragAndDropable
25
- BADGE_MARKUP = '<span weight="heavy" foreground="white">%d</span>'.freeze
27
+ BADGE_MARKUP = '<span weight="heavy" foreground="white">%d</span>'
26
28
 
27
29
  def setup_view_source_dnd(view)
28
30
  # better be Loggable!
29
- log.info { 'setup_view_source_dnd for %s' % view }
30
- view.signal_connect_after('drag-begin') do |_widget, drag_context|
31
+ log.info { format("setup_view_source_dnd for %s", view) }
32
+ view.signal_connect_after("drag-begin") do |_widget, drag_context|
31
33
  n_books = @parent.selected_books.length
32
34
  if n_books > 1
33
35
  # Render generic book icon.
@@ -43,8 +45,8 @@ module Alexandria
43
45
 
44
46
  # Draw a red ellipse where the badge number should be.
45
47
  red_gc = Gdk::GC.new(pixmap)
46
- red_gc.rgb_fg_color = Gdk::Color.parse('red')
47
- red_gc.rgb_bg_color = Gdk::Color.parse('red')
48
+ red_gc.rgb_fg_color = Gdk::Color.parse("red")
49
+ red_gc.rgb_bg_color = Gdk::Color.parse("red")
48
50
  pixmap.draw_arc(red_gc,
49
51
  true,
50
52
  x - 5, y - 2,
@@ -64,11 +66,11 @@ module Alexandria
64
66
  end
65
67
  end
66
68
 
67
- view.signal_connect('drag-data-get') do |_widget, _drag_context, selection_data, _info, _time|
69
+ view.signal_connect("drag-data-get") do |_, _, selection_data, _, _|
68
70
  idents = @parent.selected_books.map(&:ident)
69
71
  unless idents.empty?
70
72
  selection_data.set(Gdk::Selection::TYPE_STRING,
71
- idents.join(','))
73
+ idents.join(","))
72
74
  end
73
75
  end
74
76
 
@@ -0,0 +1,25 @@
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/alert_dialog"
8
+
9
+ module Alexandria
10
+ module UI
11
+ class ErrorDialog < AlertDialog
12
+ def initialize(parent, title, message = nil)
13
+ super(parent, title, Gtk::Stock::DIALOG_ERROR,
14
+ [[Gtk::Stock::OK, :ok]], message)
15
+ # FIXME: Should accept just :ok
16
+ dialog.default_response = Gtk::ResponseType::OK
17
+ end
18
+
19
+ def display
20
+ show_all && run
21
+ destroy
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,139 @@
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/export_format"
8
+ require "alexandria/ui/confirm_erase_dialog"
9
+ require "alexandria/ui/error_dialog"
10
+
11
+ module Alexandria
12
+ module UI
13
+ class ExportDialog
14
+ include GetText
15
+ extend GetText
16
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
17
+
18
+ FORMATS = Alexandria::ExportFormat.all
19
+ THEMES = Alexandria::WebTheme.all
20
+
21
+ def initialize(parent, library, sort_order)
22
+ @dialog = Gtk::FileChooserDialog.new(title: _("Export '%s'") % library.name,
23
+ parent: parent,
24
+ action: :save,
25
+ buttons: [[Gtk::Stock::HELP, :help],
26
+ [Gtk::Stock::CANCEL, :cancel],
27
+ [_("_Export"), :accept]])
28
+ @dialog.current_name = library.name
29
+ @dialog.signal_connect("destroy") { @dialog.hide }
30
+
31
+ @parent = parent
32
+ @library = library
33
+ @sort_order = sort_order
34
+
35
+ preview_image = Gtk::Image.new
36
+
37
+ @theme_combo = Gtk::ComboBoxText.new
38
+ @theme_combo.valign = :center
39
+ @theme_combo.vexpand = false
40
+ THEMES.each do |theme|
41
+ @theme_combo.append_text(theme.name)
42
+ end
43
+ @theme_combo.signal_connect("changed") do
44
+ file = THEMES[@theme_combo.active].preview_file
45
+ preview_image.pixbuf = GdkPixbuf::Pixbuf.new(file: file)
46
+ end
47
+ @theme_combo.active = 0
48
+ theme_label = Gtk::Label.new(_("_Theme:"), use_underline: true)
49
+ theme_label.xalign = 0
50
+ theme_label.mnemonic_widget = @theme_combo
51
+
52
+ @types_combo = Gtk::ComboBoxText.new
53
+ @types_combo.vexpand = false
54
+ @types_combo.valign = :center
55
+ FORMATS.each do |format|
56
+ text = format.name + " ("
57
+ text += if format.ext
58
+ "*." + format.ext
59
+ else
60
+ _("directory")
61
+ end
62
+ text += ")"
63
+ @types_combo.append_text(text)
64
+ end
65
+ @types_combo.active = 0
66
+ @types_combo.signal_connect("changed") do
67
+ visible = FORMATS[@types_combo.active].needs_preview?
68
+ theme_label.visible = @theme_combo.visible = preview_image.visible = visible
69
+ end
70
+ @types_combo.show
71
+
72
+ types_label = Gtk::Label.new(_("Export for_mat:"), use_underline: true)
73
+ types_label.xalign = 0
74
+ types_label.mnemonic_widget = @types_combo
75
+ types_label.show
76
+
77
+ # TODO: Re-design extra widget layout
78
+ grid = Gtk::Grid.new
79
+ grid.column_spacing = 6
80
+ grid.attach types_label, 0, 0, 1, 1
81
+ grid.attach @types_combo, 1, 0, 1, 1
82
+ grid.attach theme_label, 0, 1, 1, 1
83
+ grid.attach @theme_combo, 1, 1, 1, 1
84
+ grid.attach preview_image, 2, 0, 1, 3
85
+ @dialog.set_extra_widget grid
86
+ end
87
+
88
+ def perform
89
+ while ((response = run) != Gtk::ResponseType::CANCEL) &&
90
+ (response != Gtk::ResponseType::DELETE_EVENT)
91
+
92
+ if response == Gtk::ResponseType::HELP
93
+ Alexandria::UI.display_help(self, "exporting")
94
+ else
95
+ begin
96
+ break if on_export(FORMATS[@types_combo.active],
97
+ THEMES[@theme_combo.active])
98
+ rescue StandardError => ex
99
+ ErrorDialog.new(@dialog, _("Export failed"), ex.message).display
100
+ end
101
+ end
102
+ end
103
+ destroy
104
+ end
105
+
106
+ private
107
+
108
+ def on_export(format, theme)
109
+ filename = self.filename
110
+ if format.ext
111
+ filename += "." + format.ext if File.extname(filename).empty?
112
+ if File.exist?(filename)
113
+ dialog = ConfirmEraseDialog.new(@dialog, filename)
114
+ return unless dialog.erase?
115
+
116
+ FileUtils.rm(filename)
117
+ end
118
+ args = []
119
+ else
120
+ if File.exist?(filename)
121
+ unless File.directory?(filename)
122
+ msg = _("The target, named '%s', is a regular " \
123
+ "file. A directory is needed for this " \
124
+ "operation. Please select a directory and " \
125
+ "try again.") % filename
126
+ ErrorDialog.new(@dialog, _("Not a directory"), msg).display
127
+ return
128
+ end
129
+ else
130
+ Dir.mkdir(filename)
131
+ end
132
+ args = [theme]
133
+ end
134
+ format.invoke(@library, @sort_order, filename, *args)
135
+ true
136
+ end
137
+ end
138
+ end
139
+ end
@@ -1,60 +1,15 @@
1
- # Copyright (C) 2004-2006 Laurent Sansonetti
2
- # Copyright (C) 2014-2016 Matijs van Zuijlen
3
- #
4
- # Alexandria is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU General Public License as
6
- # published by the Free Software Foundation; either version 2 of the
7
- # License, or (at your option) any later version.
8
- #
9
- # Alexandria is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public
15
- # License along with Alexandria; see the file COPYING. If not,
16
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
- # Fifth Floor, Boston, MA 02110-1301 USA.
18
-
19
- class GdkPixbuf::Pixbuf
20
- def tag(tag_pixbuf)
21
- # Computes some tweaks.
22
- tweak_x = tag_pixbuf.width / 3
23
- tweak_y = tag_pixbuf.height / 3
24
-
25
- # Creates the destination pixbuf.
26
- new_pixbuf = GdkPixbuf::Pixbuf.new(colorspace: :rgb,
27
- has_alpha: true,
28
- bits_per_sample: 8,
29
- width: width + tweak_x,
30
- height: height + tweak_y)
1
+ # frozen_string_literal: true
31
2
 
32
- # Fills with blank.
33
- new_pixbuf.fill!(0)
34
-
35
- # Copies the current pixbuf there (south-west).
36
- copy_area(0, 0,
37
- width, height,
38
- new_pixbuf,
39
- 0, tweak_y)
40
-
41
- # Copies the tag pixbuf there (north-est).
42
- tag_pixbuf_x = width - (tweak_x * 2)
43
- new_pixbuf.composite!(tag_pixbuf,
44
- dest_x: 0, dest_y: 0,
45
- dest_width: tag_pixbuf.width + tag_pixbuf_x,
46
- dest_height: tag_pixbuf.height,
47
- offset_x: tag_pixbuf_x, offset_y: 0,
48
- scale_x: 1, scale_y: 1,
49
- interpolation_type: :hyper, overall_alpha: 255)
50
- new_pixbuf
51
- end
52
- end
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
53
6
 
54
7
  module Alexandria
55
8
  module UI
56
9
  module Icons
57
- ICONS_DIR = File.join(Alexandria::Config::DATA_DIR, 'icons')
10
+ include Logging
11
+
12
+ ICONS_DIR = File.join(Alexandria::Config::DATA_DIR, "icons")
58
13
  def self.init
59
14
  load_icon_images
60
15
  end
@@ -63,10 +18,11 @@ module Alexandria
63
18
  # Alexandria::UI::Icons namespace, e.g., Icons::STAR_SET
64
19
  def self.load_icon_images
65
20
  Dir.entries(ICONS_DIR).each do |file|
66
- next unless file =~ /\.png$/ # skip non '.png' files
21
+ next unless file.end_with?(".png") # skip non '.png' files
22
+
67
23
  # Don't use upcase and use tr instead
68
24
  # For example in Turkish the upper case of 'i' is still 'i'.
69
- name = File.basename(file, '.png').tr('a-z', 'A-Z')
25
+ name = File.basename(file, ".png").tr("a-z", "A-Z")
70
26
  const_set(name, GdkPixbuf::Pixbuf.new(file: File.join(ICONS_DIR, file)))
71
27
  end
72
28
  end
@@ -74,26 +30,54 @@ module Alexandria
74
30
  def self.cover(library, book)
75
31
  begin
76
32
  return BOOK_ICON if library.nil?
33
+
77
34
  filename = library.cover(book)
78
- if File.exist?(filename)
79
- return GdkPixbuf::Pixbuf.new(file: filename)
35
+ return GdkPixbuf::Pixbuf.new(file: filename) if File.exist?(filename)
36
+ rescue GdkPixbuf::PixbufError
37
+ log.error do
38
+ "Failed to load GdkPixbuf::Pixbuf," \
39
+ " please ensure that #{filename} is a valid image file"
80
40
  end
81
- rescue => err
82
- # report load error; FIX should go to a Logger...
83
- puts err.message
84
- puts err.backtrace.join("\n> ")
85
- puts "Failed to load GdkPixbuf::Pixbuf, please ensure that from #{filename} is a valid image file"
86
41
  end
87
42
  BOOK_ICON
88
43
  end
89
44
 
45
+ def self.tag_icon(icon_pixbuf, tag_pixbuf)
46
+ # Computes some tweaks.
47
+ tweak_x = tag_pixbuf.width / 3
48
+ tweak_y = tag_pixbuf.height / 3
49
+
50
+ # Creates the destination pixbuf.
51
+ new_pixbuf = GdkPixbuf::Pixbuf.new(colorspace: :rgb,
52
+ has_alpha: true,
53
+ bits_per_sample: 8,
54
+ width: icon_pixbuf.width + tweak_x,
55
+ height: icon_pixbuf.height + tweak_y)
56
+
57
+ # Fills with blank.
58
+ new_pixbuf.fill!(0)
59
+
60
+ # Copies the current pixbuf there (south-west).
61
+ icon_pixbuf.copy_area(0, 0,
62
+ icon_pixbuf.width, icon_pixbuf.height,
63
+ new_pixbuf,
64
+ 0, tweak_y)
65
+
66
+ # Copies the tag pixbuf there (north-est).
67
+ tag_pixbuf_x = icon_pixbuf.width - (tweak_x * 2)
68
+ new_pixbuf.composite!(tag_pixbuf,
69
+ dest_x: 0, dest_y: 0,
70
+ dest_width: tag_pixbuf.width + tag_pixbuf_x,
71
+ dest_height: tag_pixbuf.height,
72
+ offset_x: tag_pixbuf_x, offset_y: 0,
73
+ scale_x: 1, scale_y: 1,
74
+ interpolation_type: :hyper, overall_alpha: 255)
75
+ new_pixbuf
76
+ end
77
+
90
78
  def self.blank?(filename)
91
79
  pixbuf = GdkPixbuf::Pixbuf.new(file: filename)
92
80
  (pixbuf.width == 1) && (pixbuf.height == 1)
93
- rescue => err
94
- puts err.message
95
- puts err.backtrace.join("\n> ")
96
- true
97
81
  end
98
82
  end
99
83
  end