lib/alexandria/ui/ui_manager.rb in alexandria-book-collection-manager-0.7.2 vs lib/alexandria/ui/ui_manager.rb in alexandria-book-collection-manager-0.7.3
- old
+ new
@@ -1,27 +1,14 @@
# frozen_string_literal: true
-# Copyright (C) 2004-2006 Laurent Sansonetti
-# Copyright (C) 2008 Joseph Method
-# Copyright (C) 2011, 2016 Matijs van Zuijlen
+# This file is part of Alexandria.
#
-# Alexandria is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of the
-# License, or (at your option) any later version.
-#
-# Alexandria is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with Alexandria; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 51 Franklin Street,
-# Fifth Floor, Boston, MA 02110-1301 USA.
+# See the file README.md for authorship and licensing information.
+require 'alexandria/ui/callbacks'
require 'alexandria/ui/columns'
+require 'alexandria/library_sort_order'
module Alexandria
module UI
class UIManager < BuilderBase
attr_accessor :main_app, :actiongroup, :appbar, :prefs, :listview, :iconview, :listview_model,
@@ -91,11 +78,10 @@
@listview_manager.setup_listview_columns_visibility
@listview_manager.setup_listview_columns_width
end
def setup_callbacks
- require 'alexandria/ui/callbacks'
self.class.send(:include, Callbacks)
connect_signals
end
def get_preferences
@@ -348,38 +334,23 @@
# we should select the library first (we call on_focus
# manually, since the above call to obj.select_path(path) doesn't
# seem to suffice).
#
# Then we wait a while and only *then* pop up the menu.
+ sensitize_library selected_library if library_already_selected
- if library_already_selected
- sensitize_library selected_library
-
- GLib::Idle.add do
- menu.popup(nil, nil, event.button, event.time)
- # @clicking_on_sidepane = false
- false
- end
- else
- GLib::Idle.add do
- menu.popup(nil, nil, event.button, event.time)
- # @clicking_on_sidepane = false
-
- false
- end
+ GLib::Idle.add do
+ menu.popup(nil, nil, event.button, event.time)
+ false
end
- else
# not a right click
- if (path = widget.get_path_at_pos(event.x, event.y))
- @clicking_on_sidepane = true
- obj, path = widget.is_a?(Gtk::TreeView) ? [widget.selection, path.first] : [widget, path]
- obj.select_path(path)
- sensitize_library selected_library
-
- end
-
+ elsif (path = widget.get_path_at_pos(event.x, event.y))
+ @clicking_on_sidepane = true
+ obj, path = widget.is_a?(Gtk::TreeView) ? [widget.selection, path.first] : [widget, path]
+ obj.select_path(path)
+ sensitize_library selected_library
end
end
def determine_library_popup(widget, event)
if widget.get_path_at_pos(event.x, event.y).nil?
@@ -500,11 +471,11 @@
no_urls = true
BookProviders.each do |provider|
has_no_url = true
begin
has_no_url = (b.isbn.nil? || b.isbn.strip.empty? || provider.url(b).nil?)
- rescue => ex
+ rescue StandardError => ex
log.warn { "Error determining URL from #{provider.name}; #{ex.message}" }
end
@actiongroup[provider.action_name].sensitive = !has_no_url
no_urls = false unless has_no_url
end
@@ -549,12 +520,14 @@
def select_a_book(book)
select_this_book = proc do |bk, view|
@filtered_model.refilter
iter = iter_from_book bk
next unless iter
+
path = iter.path
next unless view.model
+
path = view_path_to_model_path(view, path)
log.debug { "Path for #{bk.ident} is #{path}" }
selection = view.respond_to?(:selection) ? @listview.selection : @iconview
selection.unselect_all
selection.select_path(path)
@@ -562,11 +535,11 @@
begin
log.debug { 'select_a_book: listview' }
select_this_book.call(book, @listview)
log.debug { 'select_a_book: listview' }
select_this_book.call(book, @iconview)
- rescue => ex
+ rescue StandardError => ex
trace = ex.backtrace.join("\n> ")
log.warn { "Failed to automatically select book: #{ex.message} #{trace}" }
end
# TODO: Figure out why this frequently selects the wrong book!
end
@@ -625,17 +598,17 @@
end
end
end
def load_libraries
- log.info { 'Loading Libraries...' }
+ log.info { 'Loading libraries...' }
@completion_models = CompletionModels.instance
if @libraries
detach_old_libraries
@libraries.reload
else
- @libraries = Libraries.instance
+ @libraries = LibraryCollection.instance
@libraries.reload
handle_ruined_books unless @libraries.ruined_books.empty?
end
@libraries.all_regular_libraries.each do |library|
library.add_observer(self)
@@ -655,11 +628,11 @@
Gtk::MessageDialog::WARNING,
Gtk::MessageDialog::BUTTONS_OK_CANCEL,
new_message).show
recovery_dialog.signal_connect('response') do |_dialog, response_type|
recovery_dialog.destroy
- if response_type == :ok
+ if response_type == Gtk::ResponseType::OK
# progress indicator...
@progressbar.fraction = 0
@appbar.children.first.visible = true # show the progress bar
total_book_count = @libraries.ruined_books.size
@@ -682,21 +655,21 @@
if isbn.size == 10
filename = library.yaml(isbn)
log.debug { "removing old file #{filename}" }
begin
File.delete(filename)
- rescue => ex
+ rescue StandardError => ex
log.error { "Could not delete empty file #{filename}" }
end
end
log.debug { "Trying to add #{book.title}, #{cover_uri} in library ''#{library.name}'" }
library.save_cover(book, cover_uri) unless cover_uri.nil?
library << book
library.save(book)
set_status_label(format(_("Added '%s' to library '%s'"), book.title, library.name))
- rescue => ex
+ rescue StandardError => ex
log.error { "Couldn't add book #{isbn}: #{ex}" }
log.error { ex.backtrace.join("\n") }
end
prog_percentage += fraction_per_book
@@ -833,13 +806,13 @@
def refresh_books
log.debug { 'refresh_books' }
@library_listview.set_sensitive(false)
library = selected_library
- @model.clear
@iconview.freeze
- @listview.freeze # NEW / bdewey
+ @listview.freeze
+ @model.clear
@progressbar.fraction = 0
@appbar.children.first.visible = true # show the progress bar
set_status_label(_("Loading '%s'...") % library.name)
total = library.length
log.debug { "library #{library.name} length #{library.length}" }
@@ -849,11 +822,11 @@
block_return = true
book = library[n]
if book
begin
append_book(book)
- rescue => ex
+ rescue StandardError => ex
trace = ex.backtrace.join("\n > ")
log.error { "append_books failed #{ex.message} #{trace}" }
end
fraction = n * 1.0 / total
log.debug { "#index #{n} fraction #{fraction}" }
@@ -878,11 +851,12 @@
end
def selected_library
log.debug { 'selected_library' }
if (iter = @library_listview.selection.selected)
- @libraries.all_libraries.find { |x| x.name == iter[1] }
+ target_name = iter[1]
+ @libraries.all_libraries.find { |it| it.name == target_name }
else
@libraries.all_libraries.first
end
end
@@ -908,10 +882,11 @@
log.debug { ident.to_s }
iter = @model.iter_first
ok = true
while ok
return iter if iter[Columns::IDENT] == ident
+
ok = iter.next!
end
nil
end
@@ -1059,10 +1034,11 @@
end
def setup_move_actions
@actiongroup.actions.each do |action|
next unless /^MoveIn/ =~ action.name
+
@actiongroup.remove_action(action)
end
actions = []
@libraries.all_regular_libraries.each do |library|
actions << [
@@ -1100,19 +1076,19 @@
"library_sort_order #{@notebook.page}: " \
"#{@iconview.model.inspect} #{@listview.model.inspect}"
}
result, sort_column, sort_order = current_view.model.sort_column_id
if result
- column_ids_to_attributes = { 2 => :title,
- 4 => :authors,
- 5 => :isbn,
- 6 => :publisher,
- 7 => :publishing_year,
- 8 => :edition, # binding
+ column_ids_to_attributes = { 2 => :title,
+ 4 => :authors,
+ 5 => :isbn,
+ 6 => :publisher,
+ 7 => :publishing_year,
+ 8 => :edition, # binding
12 => :redd,
13 => :own,
14 => :want,
- 9 => :rating }
+ 9 => :rating }
sort_attribute = column_ids_to_attributes.fetch sort_column
ascending = (sort_order == :ascending)
LibrarySortOrder.new(sort_attribute, ascending)
else