lib/alexandria/ui/dialogs/import_dialog.rb in alexandria-book-collection-manager-0.7.2 vs lib/alexandria/ui/dialogs/import_dialog.rb in alexandria-book-collection-manager-0.7.3
- old
+ new
@@ -1,24 +1,10 @@
# frozen_string_literal: true
-# Copyright (C) 2004-2006 Laurent Sansonetti
-# 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.
class Alexandria::ImportFilter
def to_filefilter
filefilter = Gtk::FileFilter.new
filefilter.name = name
@@ -34,56 +20,52 @@
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
def initialize(parent, message)
super(parent, _('Error while importing'),
Gtk::Stock::DIALOG_QUESTION,
- [[Gtk::Stock::CANCEL, :cancel],
- [_('_Continue'), :ok]],
+ [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
+ [_('_Continue'), Gtk::ResponseType::OK]],
message)
puts "Opened SkipEntryDialog #{inspect}" if $DEBUG
self.default_response = Gtk::ResponseType::CANCEL
- show_all && (@response = run)
- destroy
end
def continue?
- @response == :ok
+ show_all && (@response = run)
+ destroy
+ @response == Gtk::ResponseType::OK
end
end
- class ImportDialog < Gtk::FileChooserDialog
+ class ImportDialog < SimpleDelegator
include GetText
include Logging
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
FILTERS = Alexandria::ImportFilter.all
def initialize(parent)
- super()
+ title = _('Import a Library')
+ dialog = Gtk::FileChooserDialog.new title: title, parent: parent, action: :open
+ super(dialog)
puts 'ImportDialog opened.' if $DEBUG
@destroyed = false
- self.title = _('Import a Library')
- self.action = :open
- self.transient_for = parent
- # self.deletable = false
- running = false
- add_button(Gtk::Stock::HELP, :help)
- add_button(Gtk::Stock::CANCEL, :cancel)
+ @running = false
+ add_button(Gtk::Stock::HELP, Gtk::ResponseType::HELP)
+ add_button(Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL)
import_button = add_button(_('_Import'),
- :accept)
+ Gtk::ResponseType::ACCEPT)
import_button.sensitive = false
- signal_connect('destroy') {
- if running
+ signal_connect('destroy') do
+ if @running
@destroyed = true
-
else
destroy
end
- # self.destroy unless running
- }
+ end
filters = {}
FILTERS.each do |filter|
filefilter = filter.to_filefilter
add_filter(filefilter)
@@ -103,38 +85,36 @@
child.reorder_child(buttonbox, 1)
pbar = Gtk::ProgressBar.new
pbar.show_text = true
child.pack_start(pbar, expand: false)
+ end
+ def acquire
on_progress = proc do |fraction|
- begin
- pbar.show unless pbar.visible?
- pbar.fraction = fraction
- rescue
- # TODO: check if destroyed instead...
- end
+ pbar.show unless pbar.visible?
+ pbar.fraction = fraction
end
on_error = proc do |message|
- SkipEntryDialog.new(parent, message).continue?
+ SkipEntryDialog.new(self, message).continue?
end
exec_queue = ExecutionQueue.new
while !@destroyed &&
- ((response = run) != :cancel) &&
- (response != :delete_event)
+ ((response = run) != Gtk::ResponseType::CANCEL) &&
+ response != Gtk::ResponseType::DELETE_EVENT
- if response == :help
+ if response == Gtk::ResponseType::HELP
Alexandria::UI.display_help(self, 'import-library')
next
end
file = File.basename(filename, '.*')
base = GLib.locale_to_utf8(file)
new_library_name = Library.generate_new_name(
- Libraries.instance.all_libraries,
+ LibraryCollection.instance.all_libraries,
base)
filter = filters[self.filter]
puts "Going forward with filter: #{filter.name}" if $DEBUG
self.sensitive = false
@@ -158,33 +138,33 @@
@failed_isbns = nil
thread = Thread.start do
begin
library, @bad_isbns, @failed_isbns = filter.invoke(new_library_name,
filename)
- rescue => ex
+ rescue StandardError => ex
trace = ex.backtrace.join("\n> ")
log.error { "Import failed: #{ex.message} #{trace}" }
end
end
while thread.alive? && !@destroyed
# puts "Thread #{thread} still alive."
- running = true
+ @running = true
exec_queue.iterate
Gtk.main_iteration_do(false)
end
unless @destroyed
if library
yield(library, @bad_isbns, @failed_isbns)
break
elsif not_cancelled
puts "Raising ErrorDialog because not_cancelled is #{not_cancelled}" if $DEBUG
- ErrorDialog.new(parent,
+ ErrorDialog.new(self,
_("Couldn't import the library"),
_('The format of the file you ' \
'provided is unknown. Please ' \
- 'retry with another file.'))
+ 'retry with another file.')).display
end
pbar.hide
self.sensitive = true
end
end