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