IMDb plaintext downloader: fix progress indicator
authorPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 10 Jul 2010 17:34:06 +0000 (19:34 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 14 Jul 2010 21:34:09 +0000 (23:34 +0200)
src/imdb/ftp-downloader.vala
src/imdb/imdb-gzip-parser.vala
src/imdb/imdb-plaintext-downloader.vala

index 2e873c9..fc35ea3 100644 (file)
@@ -44,6 +44,7 @@ class FtpDownloader {
                        Posix.Stat st;
                        Posix.stat (filename, out st);
                        if (size == st.st_size) {
+                               progress (size, size);
                                return;
                        }
                }
index a729206..b13069c 100644 (file)
@@ -10,6 +10,8 @@ class IMDbGzipParser {
                parser = _parser;
 
                var file = File.new_for_path (path);
+               var info = file.query_info (FILE_ATTRIBUTE_STANDARD_SIZE, FileQueryInfoFlags.NONE, cancellable);
+               int total = (int) info.get_size ();
                var gz_stream = new GzipInputStream (file.read (cancellable));
                var stream = new DataInputStream (gz_stream);
 
@@ -23,7 +25,7 @@ class IMDbGzipParser {
                        line = stream.read_line (out length, cancellable);
                        if (gz_stream.total_in () > total_in) {
                                total_in = (int) gz_stream.total_in ();
-                               progress (0, total_in);
+                               progress (total, total_in);
                        }
                }
        }
index a8462c0..8b95f36 100644 (file)
@@ -79,52 +79,54 @@ class IMDbDownloadServer : Object, IMDbDownloader {
                        downloader.progress.connect (on_progress);
 
                        var parser = new IMDbGzipParser (cancellable);
+                       parser.progress.connect (on_progress);
 
                        if (MOVIES in flags) {
                                description_changed ("Downloading movie list ...");
                                downloader.download (url + "movies.list.gz", Path.build_filename (cache_dir, "movies.list.gz"));
                        }
-                       percent_finished = 20;
+                       percent_finished = 10;
                        if (GENRES in flags) {
                                description_changed ("Downloading genre data ...");
                                downloader.download (url + "genres.list.gz", Path.build_filename (cache_dir, "genres.list.gz"));
                        }
-                       percent_finished = 40;
+                       percent_finished = 20;
                        if (RATINGS in flags) {
                                description_changed ("Downloading rating data ...");
                                downloader.download (url + "ratings.list.gz", Path.build_filename (cache_dir, "ratings.list.gz"));
                        }
-                       percent_finished = 60;
+                       percent_finished = 30;
                        if (AKAS in flags) {
                                description_changed ("Downloading alternative titles ...");
                                downloader.download (url + "aka-titles.list.gz", Path.build_filename (cache_dir, "aka-titles.list.gz"));
                        }
-                       percent_finished = 80;
+                       percent_finished = 40;
                        if (PLOTS in flags) {
                                description_changed ("Downloading plots ...");
                                downloader.download (url + "plot.list.gz", Path.build_filename (cache_dir, "plot.list.gz"));
                        }
 
+                       percent_finished = 50;
                        if (MOVIES in flags) {
                                description_changed ("Parsing movie list ...");
                                parser.parse (Path.build_filename (cache_dir, "movies.list.gz"), movie_parser);
                        }
-                       percent_finished = 20;
+                       percent_finished = 60;
                        if (GENRES in flags) {
                                description_changed ("Parsing genre data ...");
                                parser.parse (Path.build_filename (cache_dir, "genres.list.gz"), genre_parser);
                        }
-                       percent_finished = 40;
+                       percent_finished = 70;
                        if (RATINGS in flags) {
                                description_changed ("Parsing rating data ...");
                                parser.parse (Path.build_filename (cache_dir, "ratings.list.gz"), rating_parser);
                        }
-                       percent_finished = 60;
+                       percent_finished = 80;
                        if (AKAS in flags) {
                                description_changed ("Parsing alternative titles ...");
                                parser.parse (Path.build_filename (cache_dir, "aka-titles.list.gz"), aka_parser);
                        }
-                       percent_finished = 80;
+                       percent_finished = 90;
                        if (PLOTS in flags) {
                                description_changed ("Parsing plots ...");
                                parser.parse (Path.build_filename (cache_dir, "plot.list.gz"), plot_parser);
@@ -157,8 +159,11 @@ class IMDbDownloadServer : Object, IMDbDownloader {
 
        private void on_progress (int dltotal, int dlnow) {
                stdout.printf ("%d / %d\r", dlnow, dltotal);
-               if (dltotal > 0)
-                       progress (99*dlnow/dltotal/100);
+               if (dltotal > 0) {
+                       int p = percent_finished + 10*dlnow/dltotal;
+                       if (p < 100)
+                               progress (p);
+               }
        }
 
        private void timeout_quit () {