[simple-scan] Remove duplicate of make_indexed_file () method



commit f9eb49a9f7e1f4e9d688ae6fa3043f2ff62f7539
Author: Stéphane Fillion <stphanef3724 gmail com>
Date:   Sun Jun 4 00:43:54 2017 -0400

    Remove duplicate of make_indexed_file () method

 src/app-window.vala |    4 +-
 src/book.vala       |   62 +++++++++++++++++---------------------------------
 2 files changed, 23 insertions(+), 43 deletions(-)
---
diff --git a/src/app-window.vala b/src/app-window.vala
index 792e0dc..49f8065 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -441,7 +441,7 @@ public class AppWindow : Gtk.ApplicationWindow
 #endif
             {
                 for (var j = 0; j < book.n_pages; j++)
-                    files.append (book.make_indexed_file (uri, j));
+                    files.append (make_indexed_file (uri, j, book.n_pages));
             }
             else
                 files.append (File.new_for_uri (uri));
@@ -1197,7 +1197,7 @@ public class AppWindow : Gtk.ApplicationWindow
             else
             {
                 for (var i = 0; i < book.n_pages; i++) {
-                    var indexed_file = book.make_indexed_file (file.get_uri (), i);
+                    var indexed_file = make_indexed_file (file.get_uri (), i, book.n_pages);
                     command_line += " --attach %s".printf (indexed_file.get_path ());
                 }
             }
diff --git a/src/book.vala b/src/book.vala
index be49dc0..d53b31a 100644
--- a/src/book.vala
+++ b/src/book.vala
@@ -136,26 +136,6 @@ public class Book
         return pages.index (page);
     }
 
-    public File make_indexed_file (string uri, int i)
-    {
-        if (n_pages == 1)
-            return File.new_for_uri (uri);
-
-        /* Insert index before extension */
-        var basename = Path.get_basename (uri);
-        string prefix = uri, suffix = "";
-        var extension_index = basename.last_index_of_char ('.');
-        if (extension_index >= 0)
-        {
-            suffix = basename.slice (extension_index, basename.length);
-            prefix = uri.slice (0, uri.length - suffix.length);
-        }
-        var width = n_pages.to_string().length;
-        var number_format = "%%0%dd".printf (width);
-        var filename = prefix + "-" + number_format.printf (i + 1) + suffix;
-        return File.new_for_uri (filename);
-    }
-
     public async void save_async (string t, int q, File f, ProgressionCallback? p, Cancellable? c) throws 
Error
     {
         var book_saver = new BookSaver ();
@@ -551,7 +531,7 @@ private class BookSaver
                 return write_task.error;
             }
 
-            var indexed_file = make_indexed_file (file.get_uri (), write_task.number);
+            var indexed_file = make_indexed_file (file.get_uri (), write_task.number, n_pages);
             try
             {
                 var stream = indexed_file.replace (null, false, FileCreateFlags.NONE);
@@ -834,26 +814,6 @@ private class BookSaver
 
     /* Utility methods */
 
-    private File make_indexed_file (string uri, int i)
-    {
-        if (n_pages == 1)
-            return File.new_for_uri (uri);
-
-        /* Insert index before extension */
-        var basename = Path.get_basename (uri);
-        string prefix = uri, suffix = "";
-        var extension_index = basename.last_index_of_char ('.');
-        if (extension_index >= 0)
-        {
-            suffix = basename.slice (extension_index, basename.length);
-            prefix = uri.slice (0, uri.length - suffix.length);
-        }
-        var width = n_pages.to_string().length;
-        var number_format = "%%0%dd".printf (width);
-        var filename = prefix + "-" + number_format.printf (i + 1) + suffix;
-        return File.new_for_uri (filename);
-    }
-
     private static uint8[]? compress_zlib (uint8[] data, uint max_size)
     {
         var stream = ZLib.DeflateStream (ZLib.Level.BEST_COMPRESSION);
@@ -966,3 +926,23 @@ private class PDFWriter
         return 0;
     }
 }
+
+public File make_indexed_file (string uri, uint i, uint n_pages)
+{
+    if (n_pages == 1)
+        return File.new_for_uri (uri);
+
+    /* Insert index before extension */
+    var basename = Path.get_basename (uri);
+    string prefix = uri, suffix = "";
+    var extension_index = basename.last_index_of_char ('.');
+    if (extension_index >= 0)
+    {
+        suffix = basename.slice (extension_index, basename.length);
+        prefix = uri.slice (0, uri.length - suffix.length);
+    }
+    var width = n_pages.to_string().length;
+    var number_format = "%%0%dd".printf (width);
+    var filename = prefix + "-" + number_format.printf (i + 1) + suffix;
+    return File.new_for_uri (filename);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]