Movie list, plugins: detect if there are more results than the limit
[cinaest] / src / plugins / google-parser.vala
index fa71710..3eb638f 100644 (file)
@@ -288,7 +288,9 @@ public class GoogleParser : Object {
                last_cinema.phone = phone;
        }
 
-       public void parse (ref char[] buf) throws Error {
+       public int parse (ref char[] buf) throws Error {
+               int movies = 0;
+
                current = buf;
                next_tag ();
                while (location == null && current[0] != 0) {
@@ -311,6 +313,7 @@ public class GoogleParser : Object {
                        while (current[i++] != '>');
                        if (((string) current).has_prefix ("<div class=movie>")) {
                                parse_movie ();
+                               movies++;
                        } else if (((string) current).has_prefix("<div class=theater>")) {
                                parse_cinema ();
                        } else {
@@ -318,9 +321,11 @@ public class GoogleParser : Object {
                        }
                        next_tag ();
                }
+
+               return movies;
        }
 
-       public async void query (MovieFilter filter, string? location, MovieSource.ReceiveMovieFunction callback, Cancellable? cancellable) {
+       public async int query (MovieFilter filter, string? location, MovieSource.ReceiveMovieFunction callback, Cancellable? cancellable) {
                _get_callback = callback;
                _filter = filter;
                if (filter.title.chr(filter.title.length, '*') != null) {
@@ -346,14 +351,16 @@ public class GoogleParser : Object {
                                nread = yield stream.read_async ((char *)buf + total, 256*1024 - total, Priority.DEFAULT_IDLE, cancellable);
                                total += nread;
                                if (cancellable.is_cancelled ())
-                                       return;
+                                       return 0;
                                if (nread == 0)
                                        break;
                        }
                        buf[total] = 0;
-                       parse (ref buf);
+                       return parse (ref buf);
                } catch (Error e) {
                        stderr.printf ("Error: %s\n", e.message);
                }
+
+               return 0;
        }
 }