alexandria-book-collection-manager 0.7.3 → 0.7.8
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 +4 -1
- data/.rubocop.yml +86 -36
- data/.rubocop_todo.yml +58 -161
- data/.simplecov +5 -2
- data/CHANGELOG.md +56 -2
- data/Gemfile +4 -3
- data/INSTALL.md +23 -11
- data/README.md +52 -41
- data/Rakefile +78 -75
- data/alexandria-book-collection-manager.gemspec +50 -44
- data/bin/alexandria +12 -22
- data/doc/FAQ +1 -2
- data/doc/dependency_decisions.yml +27 -8
- data/lib/alexandria.rb +25 -23
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +86 -91
- data/lib/alexandria/book_providers/adlibris.rb +37 -74
- data/lib/alexandria/book_providers/amazon_aws.rb +94 -100
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +289 -324
- data/lib/alexandria/book_providers/barnes_and_noble.rb +42 -42
- data/lib/alexandria/book_providers/douban.rb +25 -41
- data/lib/alexandria/book_providers/proxis.rb +34 -29
- data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
- data/lib/alexandria/book_providers/siciliano.rb +60 -64
- data/lib/alexandria/book_providers/thalia_provider.rb +161 -0
- data/lib/alexandria/book_providers/web.rb +5 -5
- data/lib/alexandria/book_providers/worldcat.rb +66 -95
- data/lib/alexandria/book_providers/z3950.rb +153 -169
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +3 -3
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +13 -12
- data/lib/alexandria/export_format.rb +8 -8
- data/lib/alexandria/export_library.rb +128 -127
- data/lib/alexandria/import_library.rb +102 -126
- data/lib/alexandria/import_library_csv.rb +41 -41
- data/lib/alexandria/library_collection.rb +6 -5
- data/lib/alexandria/library_sort_order.rb +4 -2
- data/lib/alexandria/library_store.rb +39 -28
- data/lib/alexandria/logging.rb +10 -14
- data/lib/alexandria/models/book.rb +5 -4
- data/lib/alexandria/models/library.rb +63 -53
- data/lib/alexandria/net.rb +5 -6
- data/lib/alexandria/preferences.rb +66 -63
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +17 -17
- data/lib/alexandria/scanners/keyboard.rb +8 -8
- data/lib/alexandria/smart_library.rb +110 -112
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +2 -2
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +108 -109
- data/lib/alexandria/ui/alert_dialog.rb +66 -0
- data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +13 -9
- 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} +25 -38
- data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +64 -157
- data/lib/alexandria/ui/builder_base.rb +1 -1
- data/lib/alexandria/ui/calendar_popup.rb +58 -0
- data/lib/alexandria/ui/callbacks.rb +187 -155
- data/lib/alexandria/ui/completion_models.rb +8 -22
- 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/{dialogs/export_dialog.rb → export_dialog.rb} +37 -58
- data/lib/alexandria/ui/icons.rb +38 -43
- 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 +30 -41
- data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +9 -6
- data/lib/alexandria/ui/libraries_combo.rb +15 -14
- data/lib/alexandria/ui/listview.rb +69 -67
- 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 +8 -9
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +113 -114
- data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +22 -19
- 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/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +7 -28
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +53 -48
- 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 +216 -200
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +21 -21
- data/po/Makefile +2 -2
- data/po/cs.po +992 -875
- data/po/cy.po +961 -874
- data/po/de.po +990 -865
- data/po/el.po +989 -865
- data/po/es.po +985 -861
- data/po/fr.po +987 -867
- data/po/ga.po +908 -820
- data/po/gl.po +980 -860
- data/po/it.po +986 -864
- data/po/ja.po +969 -849
- data/po/mk.po +984 -860
- data/po/nb.po +979 -859
- data/po/nl.po +983 -860
- data/po/pl.po +1018 -971
- data/po/pt.po +988 -857
- data/po/pt_BR.po +983 -863
- data/po/ru.po +994 -871
- data/po/sk.po +989 -867
- data/po/sv.po +976 -856
- data/po/uk.po +972 -858
- data/po/zh_TW.po +974 -854
- data/schemas/alexandria.schemas +24 -2
- data/share/alexandria/glade/acquire_dialog__builder.glade +1 -1
- data/share/alexandria/glade/book_properties_dialog__builder.glade +1 -1
- data/share/alexandria/glade/main_app__builder.glade +6 -21
- data/share/alexandria/glade/new_book_dialog__builder.glade +1 -1
- data/share/alexandria/glade/preferences_dialog__builder.glade +1 -1
- data/share/gnome/help/alexandria/C/introduction.xml +0 -4
- 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 -4
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/thalia_provider_spec.rb +119 -0
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +62 -156
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +6 -11
- data/spec/alexandria/export_library_spec.rb +47 -58
- data/spec/alexandria/library_spec.rb +121 -109
- data/spec/alexandria/library_store_spec.rb +8 -8
- 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 +15 -15
- 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 +59 -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 +51 -0
- data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
- 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 +44 -20
- data/spec/end_to_end/basic_run_spec.rb +21 -38
- data/spec/fixtures/cover.jpg +0 -0
- data/spec/spec_helper.rb +54 -10
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +11 -11
- data/util/rake/fileinstall.rb +38 -35
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +158 -45
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/renaud.rb +0 -155
- data/lib/alexandria/book_providers/thalia.rb +0 -198
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -63
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -176
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -62
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -563
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -61
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -423
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -162
- 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,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2004-2006 Laurent Sansonetti
|
4
|
-
#
|
5
|
-
# Alexandria is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU General Public License as
|
7
|
-
# published by the Free Software Foundation; either version 2 of the
|
8
|
-
# License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# Alexandria is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU General Public
|
16
|
-
# License along with Alexandria; see the file COPYING. If not,
|
17
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
18
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
19
|
-
|
20
|
-
module Alexandria
|
21
|
-
module UI
|
22
|
-
class SmartLibraryPropertiesDialog < SmartLibraryPropertiesDialogBase
|
23
|
-
include GetText
|
24
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
|
25
|
-
|
26
|
-
def initialize(parent, smart_library)
|
27
|
-
super(parent)
|
28
|
-
|
29
|
-
add_buttons([Gtk::Stock::CANCEL, :cancel],
|
30
|
-
[Gtk::Stock::SAVE, :ok])
|
31
|
-
|
32
|
-
self.title = _("Properties for '%s'") % smart_library.name
|
33
|
-
# FIXME: Should accept just :cancel
|
34
|
-
self.default_response = Gtk::ResponseType::CANCEL
|
35
|
-
end
|
36
|
-
|
37
|
-
def acquire
|
38
|
-
show_all
|
39
|
-
smart_library.rules.each { |x| insert_new_rule(x) }
|
40
|
-
update_rules_header_box(smart_library.predicate_operator_rule)
|
41
|
-
|
42
|
-
while (response = run) != Gtk::ResponseType::CANCEL
|
43
|
-
if response == Gtk::ResponseType::HELP
|
44
|
-
Alexandria::UI.display_help(self, 'edit-smart-library')
|
45
|
-
elsif response == Gtk::ResponseType::OK
|
46
|
-
if user_confirms_possible_weirdnesses_before_saving?
|
47
|
-
smart_library.rules = smart_library_rules
|
48
|
-
smart_library.predicate_operator_rule =
|
49
|
-
predicate_operator_rule
|
50
|
-
smart_library.save
|
51
|
-
yield(smart_library)
|
52
|
-
break
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
destroy
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,423 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2004-2006 Laurent Sansonetti
|
4
|
-
# Copyright (C) 2011, 2016 Matijs van Zuijlen
|
5
|
-
#
|
6
|
-
# Alexandria is free software; you can redistribute it and/or
|
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
|
-
module Alexandria
|
22
|
-
module UI
|
23
|
-
class SmartLibraryPropertiesDialogBase < SimpleDelegator
|
24
|
-
include Logging
|
25
|
-
include GetText
|
26
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
|
27
|
-
|
28
|
-
attr_reader :predicate_operator_rule
|
29
|
-
|
30
|
-
def initialize(parent)
|
31
|
-
@dialog = Gtk::Dialog.new(title: '',
|
32
|
-
parent: parent,
|
33
|
-
flags: :modal,
|
34
|
-
buttons: [[Gtk::Stock::HELP, :help]])
|
35
|
-
super(@dialog)
|
36
|
-
|
37
|
-
self.window_position = :center
|
38
|
-
self.resizable = true
|
39
|
-
self.border_width = 4
|
40
|
-
child.border_width = 12
|
41
|
-
|
42
|
-
main_box = Gtk::Box.new :vertical
|
43
|
-
main_box.border_width = 4
|
44
|
-
main_box.spacing = 8
|
45
|
-
|
46
|
-
child << main_box
|
47
|
-
|
48
|
-
@smart_library_rules = []
|
49
|
-
|
50
|
-
@rules_header_box = Gtk::Box.new :horizontal
|
51
|
-
@rules_header_box.spacing = 2
|
52
|
-
|
53
|
-
@rules_box = Gtk::Box.new :vertical
|
54
|
-
@rules_box.spacing = 8
|
55
|
-
@rules_box.border_width = 8
|
56
|
-
|
57
|
-
scrollview = Gtk::ScrolledWindow.new
|
58
|
-
scrollview.hscrollbar_policy = :never
|
59
|
-
scrollview.vscrollbar_policy = :automatic
|
60
|
-
scrollview.set_size_request(-1, 125)
|
61
|
-
scrollview.add_with_viewport(@rules_box)
|
62
|
-
|
63
|
-
main_box.pack_start(@rules_header_box, expand: false, fill: false)
|
64
|
-
main_box << scrollview
|
65
|
-
setup_calendar_widgets
|
66
|
-
end
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
def smart_library_rules
|
71
|
-
fill_smart_library_rules_values
|
72
|
-
@smart_library_rules
|
73
|
-
end
|
74
|
-
|
75
|
-
def has_weirdnesses?
|
76
|
-
fill_smart_library_rules_values
|
77
|
-
smart_library_rules.each do |rule|
|
78
|
-
return true if rule.value == ''
|
79
|
-
end
|
80
|
-
false
|
81
|
-
end
|
82
|
-
|
83
|
-
def user_confirms_possible_weirdnesses_before_saving?
|
84
|
-
return true unless has_weirdnesses?
|
85
|
-
|
86
|
-
dialog = AlertDialog.new(
|
87
|
-
@dialog,
|
88
|
-
_('Empty or conflictive condition'),
|
89
|
-
Gtk::Stock::DIALOG_QUESTION,
|
90
|
-
[[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
|
91
|
-
[_('_Save However'), Gtk::ResponseType::YES]],
|
92
|
-
_('This smart library contains one or more conditions ' \
|
93
|
-
'which are empty or conflict with each other. This is ' \
|
94
|
-
'likely to result in never matching a book. Are you ' \
|
95
|
-
'sure you want to save this library?'))
|
96
|
-
dialog.default_response = Gtk::ResponseType::CANCEL
|
97
|
-
dialog.show_all
|
98
|
-
confirmed = dialog.run == Gtk::ResponseType::YES
|
99
|
-
dialog.destroy
|
100
|
-
confirmed
|
101
|
-
end
|
102
|
-
|
103
|
-
def update_rules_header_box(predicate_operator_rule = SmartLibrary::ALL_RULES)
|
104
|
-
@rules_header_box.children.each { |x| @rules_header_box.remove(x) }
|
105
|
-
|
106
|
-
if @rules_box.children.length > 1
|
107
|
-
label1 = Gtk::Label.new
|
108
|
-
label1.set_alignment(0.0, 0.5)
|
109
|
-
label1.text = _('Match')
|
110
|
-
|
111
|
-
cb = Gtk::ComboBoxText.new
|
112
|
-
[_('all'), _('any')].each { |x| cb.append_text(x) }
|
113
|
-
cb.signal_connect('changed') do
|
114
|
-
@predicate_operator_rule = cb.active.zero? ? SmartLibrary::ALL_RULES : SmartLibrary::ANY_RULE
|
115
|
-
end
|
116
|
-
cb.active =
|
117
|
-
predicate_operator_rule == SmartLibrary::ALL_RULES ? 0 : 1
|
118
|
-
|
119
|
-
label2 = Gtk::Label.new
|
120
|
-
label2.set_alignment(0.0, 0.5)
|
121
|
-
label2.text = _('of the following rules:')
|
122
|
-
|
123
|
-
@rules_header_box.pack_start(label1, expand: false, fill: false)
|
124
|
-
@rules_header_box.pack_start(cb, expand: false, fill: false)
|
125
|
-
@rules_header_box.pack_start(label2, expand: false, fill: false)
|
126
|
-
else
|
127
|
-
label = Gtk::Label.new
|
128
|
-
label.set_alignment(0.0, 0.5)
|
129
|
-
label.text = _('Match the following rule:')
|
130
|
-
@rules_header_box << label
|
131
|
-
@predicate_operator_rule = SmartLibrary::ALL_RULES
|
132
|
-
end
|
133
|
-
|
134
|
-
@rules_header_box.show_all
|
135
|
-
end
|
136
|
-
|
137
|
-
def insert_new_rule(rule = nil)
|
138
|
-
rule_box = Gtk::Box.new :horizontal
|
139
|
-
rule_box.spacing = 8
|
140
|
-
|
141
|
-
left_operand_combo = Gtk::ComboBoxText.new
|
142
|
-
operator_combo = Gtk::ComboBoxText.new
|
143
|
-
|
144
|
-
value_entry = Gtk::Entry.new
|
145
|
-
|
146
|
-
date_entry = Gtk::Entry.new
|
147
|
-
date_entry.primary_icon_name = Gtk::Stock::EDIT
|
148
|
-
date_entry.primary_icon_activatable = true
|
149
|
-
date_entry.signal_connect('icon-press') do |entry, primary, _icon|
|
150
|
-
display_calendar_popup(entry) if primary.nick == 'primary'
|
151
|
-
end
|
152
|
-
|
153
|
-
# Really hide the time part of the date entry, as the constructor
|
154
|
-
# does not seem to do it...
|
155
|
-
# ##date_entry.children[2..3].each { |x| date_entry.remove(x) }
|
156
|
-
# ##date_entry.spacing = 8
|
157
|
-
entry_label = Gtk::Label.new('')
|
158
|
-
|
159
|
-
add_button = Gtk::Button.new(label: '')
|
160
|
-
add_button.remove(add_button.children.first)
|
161
|
-
add_button << Gtk::Image.new(stock: Gtk::Stock::ADD,
|
162
|
-
size: Gtk::IconSize::BUTTON)
|
163
|
-
|
164
|
-
add_button.signal_connect('clicked') { insert_new_rule }
|
165
|
-
|
166
|
-
remove_button = Gtk::Button.new(label: '')
|
167
|
-
remove_button.remove(remove_button.children.first)
|
168
|
-
remove_button << Gtk::Image.new(stock: Gtk::Stock::REMOVE,
|
169
|
-
size: Gtk::IconSize::BUTTON)
|
170
|
-
|
171
|
-
remove_button.signal_connect('clicked') do |_button|
|
172
|
-
idx = @rules_box.children.index(rule_box)
|
173
|
-
raise if idx.nil?
|
174
|
-
|
175
|
-
@smart_library_rules.delete_at(idx)
|
176
|
-
@rules_box.remove(rule_box)
|
177
|
-
sensitize_remove_rule_buttons
|
178
|
-
update_rules_header_box
|
179
|
-
end
|
180
|
-
|
181
|
-
operands = SmartLibrary::Rule::Operands::LEFT
|
182
|
-
operands.each do |operand|
|
183
|
-
left_operand_combo.append_text(operand.name)
|
184
|
-
end
|
185
|
-
operator_combo.signal_connect('changed') do
|
186
|
-
operand = operands[left_operand_combo.active]
|
187
|
-
operations = SmartLibrary::Rule.operations_for_operand(operand)
|
188
|
-
operation = operations[operator_combo.active]
|
189
|
-
|
190
|
-
value_entry.visible = date_entry.visible = entry_label.visible = false
|
191
|
-
right_operand = operation.last
|
192
|
-
unless right_operand.nil?
|
193
|
-
entry = case right_operand.klass.name
|
194
|
-
when 'Time'
|
195
|
-
date_entry
|
196
|
-
else
|
197
|
-
value_entry
|
198
|
-
end
|
199
|
-
entry.visible = true
|
200
|
-
unless right_operand.name.nil?
|
201
|
-
entry_label.text = right_operand.name
|
202
|
-
entry_label.visible = true
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
idx = @rules_box.children.index(rule_box)
|
207
|
-
new_rule = @smart_library_rules[idx]
|
208
|
-
if new_rule.nil?
|
209
|
-
new_rule = SmartLibrary::Rule.new(operand,
|
210
|
-
operation.first,
|
211
|
-
nil)
|
212
|
-
@smart_library_rules << new_rule
|
213
|
-
end
|
214
|
-
new_rule.operand = operand
|
215
|
-
new_rule.operation = operation.first
|
216
|
-
new_rule.value = nil
|
217
|
-
end
|
218
|
-
left_operand_combo.signal_connect('changed') do
|
219
|
-
operand = operands[left_operand_combo.active]
|
220
|
-
operator_combo.freeze_notify do
|
221
|
-
operator_combo.remove_all
|
222
|
-
operations = SmartLibrary::Rule.operations_for_operand(operand)
|
223
|
-
operations.each do |operation|
|
224
|
-
operator = operation.first
|
225
|
-
operator_combo.append_text(operator.name)
|
226
|
-
end
|
227
|
-
operator_combo.active = 0
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
rule_box.pack_start(left_operand_combo, expand: false, fill: false)
|
232
|
-
rule_box.pack_start(operator_combo, expand: false, fill: false)
|
233
|
-
rule_box.pack_start(value_entry)
|
234
|
-
rule_box.pack_start(date_entry)
|
235
|
-
rule_box.pack_start(entry_label, expand: false, fill: false)
|
236
|
-
rule_box.pack_end(remove_button, expand: false, fill: false)
|
237
|
-
rule_box.pack_end(add_button, expand: false, fill: false)
|
238
|
-
|
239
|
-
rule_box.show_all
|
240
|
-
value_entry.visible = date_entry.visible = entry_label.visible = false
|
241
|
-
|
242
|
-
@rules_box.pack_start(rule_box, expand: false, fill: true)
|
243
|
-
|
244
|
-
if rule
|
245
|
-
operand_idx = operands.index(rule.operand)
|
246
|
-
operations =
|
247
|
-
SmartLibrary::Rule.operations_for_operand(rule.operand)
|
248
|
-
operation_idx = operations.map(&:first).index(rule.operation)
|
249
|
-
|
250
|
-
if !operand_idx.nil? && !operation_idx.nil?
|
251
|
-
left_operand_combo.active = operand_idx
|
252
|
-
operator_combo.active = operation_idx
|
253
|
-
unless rule.value.nil?
|
254
|
-
case rule.value
|
255
|
-
when String
|
256
|
-
value_entry.text = rule.value
|
257
|
-
when Time
|
258
|
-
date_entry.text = format_date(rule.value)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
else
|
263
|
-
left_operand_combo.active = 0
|
264
|
-
end
|
265
|
-
|
266
|
-
@rules_box.check_resize # force a layout
|
267
|
-
update_rules_header_box
|
268
|
-
sensitize_remove_rule_buttons
|
269
|
-
end
|
270
|
-
|
271
|
-
def sensitize_remove_rule_buttons
|
272
|
-
boxes = @rules_box.children
|
273
|
-
state = boxes.length > 1
|
274
|
-
boxes.each do |box|
|
275
|
-
button = box.children[-1]
|
276
|
-
button.sensitive = state if button.is_a?(Gtk::Button)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
def fill_smart_library_rules_values
|
281
|
-
@rules_box.children.each_with_index do |box, i|
|
282
|
-
entry, date = box.children[2..3]
|
283
|
-
value = nil
|
284
|
-
if entry.visible?
|
285
|
-
value = entry.text.strip
|
286
|
-
elsif date.visible?
|
287
|
-
begin
|
288
|
-
value = parse_date(date.text)
|
289
|
-
rescue StandardError => ex
|
290
|
-
trace = ex.backtrace.join("\n > ")
|
291
|
-
log.warn { "Possibly invalid date entered #{ex.message}" }
|
292
|
-
log.warn { "Date widget returned #{date.text} / #{trace}" }
|
293
|
-
# user entered some non-date...
|
294
|
-
# default to current time, for the moment
|
295
|
-
value = Time.now
|
296
|
-
end
|
297
|
-
end
|
298
|
-
@smart_library_rules[i].value = value
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
# COPIED and PASTED from book_properties_dialog_base
|
303
|
-
|
304
|
-
def setup_calendar_widgets
|
305
|
-
@popup_displayed = false
|
306
|
-
@calendar_popup = Gtk::Window.new # Gtk::Window::POPUP)
|
307
|
-
# @calendar_popup.modal = true
|
308
|
-
@calendar_popup.decorated = false
|
309
|
-
@calendar_popup.skip_taskbar_hint = true
|
310
|
-
@calendar_popup.skip_pager_hint = true
|
311
|
-
@calendar_popup.events = [:focus_change_mask]
|
312
|
-
|
313
|
-
@calendar_popup.set_transient_for(@dialog)
|
314
|
-
@calendar_popup.set_type_hint(:dialog)
|
315
|
-
@calendar_popup.name = 'calendar-popup'
|
316
|
-
@calendar_popup.resizable = false
|
317
|
-
# @calendar_popup.border_width = 4
|
318
|
-
# @calendar_popup.app_paintable = true
|
319
|
-
|
320
|
-
@calendar_popup.signal_connect('focus-out-event') do |_popup, _event|
|
321
|
-
hide_calendar_popup
|
322
|
-
false
|
323
|
-
end
|
324
|
-
|
325
|
-
@calendar = Gtk::Calendar.new
|
326
|
-
@calendar_popup.add(@calendar)
|
327
|
-
|
328
|
-
@calendar.signal_connect('day-selected') do
|
329
|
-
date_arr = @calendar.date
|
330
|
-
year = date_arr[0]
|
331
|
-
month = date_arr[1] # + 1 # gtk : months 0-indexed, Time.gm : 1-index
|
332
|
-
day = date_arr[2]
|
333
|
-
if @calendar_popup_for_entry
|
334
|
-
time = Time.gm(year, month, day)
|
335
|
-
@calendar_popup_for_entry.text = format_date(time)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
@calendar.signal_connect('day-selected-double-click') do
|
340
|
-
date_arr = @calendar.date
|
341
|
-
year = date_arr[0]
|
342
|
-
month = date_arr[1] # + 1 # gtk : months 0-indexed, Time.gm : 1-index
|
343
|
-
day = date_arr[2]
|
344
|
-
if @calendar_popup_for_entry
|
345
|
-
time = Time.gm(year, month, day)
|
346
|
-
@calendar_popup_for_entry.text = format_date(time)
|
347
|
-
end
|
348
|
-
hide_calendar_popup
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
def hide_calendar_popup
|
353
|
-
@calendar_popup_for_entry = nil
|
354
|
-
|
355
|
-
@calendar_popup.hide_all
|
356
|
-
self.modal = true
|
357
|
-
|
358
|
-
GLib::Timeout.add(150) do
|
359
|
-
# If we set @popup_displayed=false immediately, then a click
|
360
|
-
# event on the primary icon of the Entry simultaneous with
|
361
|
-
# the focus-out-event of the Calendar causes the Calendar to
|
362
|
-
# pop up again milliseconds after being closed.
|
363
|
-
#
|
364
|
-
# This is never what the user intends.
|
365
|
-
#
|
366
|
-
# So we add a small delay before the primary icon's event
|
367
|
-
# handler is told to pop up the calendar in response to
|
368
|
-
# clicks.
|
369
|
-
|
370
|
-
@popup_displayed = false
|
371
|
-
false
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
def display_calendar_popup(entry)
|
376
|
-
if @popup_displayed
|
377
|
-
hide_calendar_popup
|
378
|
-
else
|
379
|
-
@calendar_popup_for_entry = entry
|
380
|
-
unless entry.text.strip.empty?
|
381
|
-
time = parse_date(entry.text)
|
382
|
-
unless time.nil?
|
383
|
-
@calendar.year = time.year
|
384
|
-
@calendar.month = time.month - 1
|
385
|
-
@calendar.day = time.day
|
386
|
-
end
|
387
|
-
end
|
388
|
-
self.modal = false
|
389
|
-
@calendar_popup.move(*get_entry_popup_coords(entry))
|
390
|
-
@calendar_popup.show_all
|
391
|
-
@popup_displayed = true
|
392
|
-
end
|
393
|
-
end
|
394
|
-
|
395
|
-
def get_entry_popup_coords(entry)
|
396
|
-
gdk_win = entry.parent_window
|
397
|
-
x, y = gdk_win.origin
|
398
|
-
alloc = entry.allocation
|
399
|
-
x += alloc.x
|
400
|
-
y += alloc.y
|
401
|
-
y += alloc.height
|
402
|
-
# x = [0, x].max
|
403
|
-
# y = [0, y].max
|
404
|
-
[x, y]
|
405
|
-
end
|
406
|
-
|
407
|
-
def parse_date(datestring)
|
408
|
-
date_format = '%d/%m/%Y' # or '%m/%d/%Y' for USA and Canada ; or '%Y-%m-%d' for most of Asia
|
409
|
-
## http://en.wikipedia.org/wiki/Calendar_date#Middle_endian_forms.2C_starting_with_the_month
|
410
|
-
begin
|
411
|
-
d = Date.strptime(datestring, date_format)
|
412
|
-
Time.gm(d.year, d.month, d.day)
|
413
|
-
rescue StandardError
|
414
|
-
nil
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
def format_date(datetime)
|
419
|
-
datetime.strftime('%d/%m/%Y')
|
420
|
-
end
|
421
|
-
end
|
422
|
-
end
|
423
|
-
end
|