summaryrefslogtreecommitdiff
path: root/src/ui.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.vala')
-rw-r--r--src/ui.vala105
1 files changed, 22 insertions, 83 deletions
diff --git a/src/ui.vala b/src/ui.vala
index 41b33b1..5b192d9 100644
--- a/src/ui.vala
+++ b/src/ui.vala
@@ -61,7 +61,6 @@ public class UserInterface
private Gtk.FileChooserDialog? save_dialog;
private ProgressBarDialog progress_dialog;
- private DragAndDropHandler dnd_handler = null;
private bool have_error;
private string error_title;
@@ -102,6 +101,12 @@ public class UserInterface
load ();
}
+ ~UserInterface ()
+ {
+ book.page_removed.disconnect (page_removed_cb);
+ book.page_added.disconnect (page_added_cb);
+ }
+
private bool find_scan_device (string device, out Gtk.TreeIter iter)
{
bool have_iter = false;
@@ -334,7 +339,7 @@ public class UserInterface
/* Get directory to save to */
string? directory = null;
directory = settings.get_string ("save-directory");
-
+
if (directory == null || directory == "")
directory = Environment.get_user_special_dir (UserDirectory.DOCUMENTS);
@@ -425,6 +430,7 @@ public class UserInterface
settings.set_string ("save-directory", save_dialog.get_current_folder ());
+ file_type_view.get_selection ().changed.disconnect (on_file_type_changed);
save_dialog.destroy ();
save_dialog = null;
@@ -530,6 +536,8 @@ public class UserInterface
_("Discard Changes")))
return;
+ if (scanning)
+ stop_scan ();
clear_document ();
}
@@ -792,7 +800,7 @@ public class UserInterface
e.message);
return;
}
-
+
try
{
Gtk.show_uri (window.get_screen (), file.get_uri (), Gtk.get_current_event_time ());
@@ -1025,6 +1033,8 @@ public class UserInterface
{
warning ("Error printing: %s", e.message);
}
+
+ print.draw_page.disconnect (draw_page);
}
[CCode (cname = "G_MODULE_EXPORT help_contents_menuitem_activate_cb", instance_pos = -1)]
@@ -1178,6 +1188,9 @@ public class UserInterface
private void page_removed_cb (Book book, Page page)
{
+ page.size_changed.disconnect (page_size_changed_cb);
+ page.scan_direction_changed.disconnect (page_scan_direction_changed_cb);
+
/* If this is the last page add a new blank one */
if (book.get_n_pages () == 1)
add_default_page ();
@@ -1401,13 +1414,11 @@ public class UserInterface
add_default_page ();
book.set_needs_saving (false);
book.needs_saving_changed.connect (needs_saving_cb);
-
+
progress_dialog = new ProgressBarDialog (window, _("Saving document..."));
book.saving.connect (book_saving_cb);
-
- dnd_handler = new DragAndDropHandler (book_view);
}
-
+
private void book_saving_cb (int page_number)
{
/* Prevent GUI from freezing */
@@ -1417,7 +1428,7 @@ public class UserInterface
var total = (int) book.get_n_pages ();
var fraction = (page_number + 1.0) / total;
var complete = fraction == 1.0;
- if (complete)
+ if (complete)
Timeout.add(500, () => {
progress_dialog.hide();
return false;
@@ -1427,12 +1438,12 @@ public class UserInterface
progress_dialog.set_fraction (fraction);
progress_dialog.set_message (message);
}
-
+
public void show_progress_dialog ()
{
progress_dialog.show ();
}
-
+
public void hide_progress_dialog ()
{
progress_dialog.hide ();
@@ -1511,84 +1522,13 @@ class ProgressBarDialog : Gtk.Window
{
bar.set_fraction (percent);
}
-
+
public void set_message (string message)
{
bar.set_text (message);
}
}
-class DragAndDropHandler
-{
- private enum TargetType
- {
- IMAGE,
- URI
- }
-
- private BookView book_view;
-
- public DragAndDropHandler (BookView book_view)
- {
- this.book_view = book_view;
- var event_source = book_view.get_event_source ();
-
- set_targets (event_source);
- event_source.drag_data_get.connect (on_drag_data_get);
- }
-
- private void set_targets (Gtk.Widget event_source)
- {
- var table = new Gtk.TargetEntry [0];
- var targets = new Gtk.TargetList (table);
- targets.add_uri_targets (TargetType.URI);
- targets.add_image_targets (TargetType.IMAGE, true);
-
- Gtk.drag_source_set (event_source, Gdk.ModifierType.BUTTON1_MASK, table, Gdk.DragAction.COPY);
- Gtk.drag_source_set_target_list (event_source, targets);
- }
-
- private void on_drag_data_get (Gdk.DragContext context, Gtk.SelectionData selection, uint target_type, uint time)
- {
- var page = book_view.get_selected ();
- return_if_fail (page != null);
-
- switch (target_type)
- {
- case TargetType.IMAGE:
- var image = page.get_image (true);
- selection.set_pixbuf (image);
-
- debug ("Saving page to pixbuf");
- break;
-
- case TargetType.URI:
- var filetype = "png";
- var path = get_temporary_filename ("scanned-page", filetype);
- return_if_fail (path != null);
-
- var file = File.new_for_path (path);
- var uri = file.get_uri ();
-
- try
- {
- page.save (filetype, file);
- selection.set_uris ({ uri });
- debug ("Saving page to %s", uri);
- }
- catch (Error e)
- {
- warning ("Unable to save file using drag-drop %s", e.message);
- }
- break;
-
- default:
- warning ("Invalid DND target type %u", target_type);
- break;
- }
- }
-}
-
// FIXME: Duplicated from simple-scan.vala
private string? get_temporary_filename (string prefix, string extension)
{
@@ -1610,4 +1550,3 @@ private string? get_temporary_filename (string prefix, string extension)
return path;
}
-