Google plugin: store complete cinema information when parsing
authorPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 24 Nov 2009 20:17:04 +0000 (21:17 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 26 Nov 2009 18:27:53 +0000 (19:27 +0100)
Stores phone number and address in a Cinema instance.

src/plugins/google-parser.vala
src/plugins/google-plugin.vala

index 7c93f51..204e913 100644 (file)
@@ -21,8 +21,18 @@ errordomain ParserError {
        EOF
 }
 
+public class Cinema {
+       public string name;
+       public string address;
+       public string phone;
+
+       public Cinema (string _name) {
+               name = _name;
+       }
+}
+
 public class GoogleMovie : Movie {
-       public string cinema;
+       public Cinema cinema;
        public string runtime;
        public string fsk;
        public string showtimes;
@@ -31,7 +41,7 @@ public class GoogleMovie : Movie {
 public class GoogleParser : Object {
        private MovieSource.ReceiveMovieFunction _get_callback;
        char *current;
-       string cinema_name;
+       Cinema last_cinema;
        public string location;
        MovieFilter _filter;
        PatternSpec pattern;
@@ -218,7 +228,7 @@ public class GoogleParser : Object {
                movie.year = 0;
                movie.rating = (int) (rating * 10);
 
-               movie.cinema = cinema_name;
+               movie.cinema = last_cinema;
                if (runtime_and_fsk.length >= 2) {
                        movie.runtime = runtime_and_fsk[0];
                        movie.fsk = runtime_and_fsk[1];
@@ -227,9 +237,9 @@ public class GoogleParser : Object {
 
                // TODO - could be configurable by settings
                if (movie.runtime != null)
-                       movie.secondary = "%s - %s - %s".printf (movie.runtime, cinema_name, showtimes);
+                       movie.secondary = "%s - %s - %s".printf (movie.runtime, last_cinema.name, showtimes);
                else
-                       movie.secondary = "%s - %s".printf (cinema_name, showtimes);
+                       movie.secondary = "%s - %s".printf (last_cinema.name, showtimes);
 
                _get_callback (movie);
        }
@@ -257,17 +267,20 @@ public class GoogleParser : Object {
                expect_tag ("/h2");
                expect_tag ("div"); // class=info
                var address_and_phone = parse_text ().replace ("&nbsp;", " ").split (" - ");
+               string address = null;
+               string phone = null;
                if (address_and_phone.length >= 2) {
-               //      string address = address_and_phone[0];
-               //      string phone = address_and_phone[1];
+                       address = address_and_phone[0];
+                       phone = address_and_phone[1].replace (" ", "").replace ("-", "");
                }
                expect_tag ("a"); // target=_top
                expect_tag ("/a");
                expect_tag ("/div");
                expect_tag ("/div");
 
-               cinema_name = name;
-               // FIXME - store cinema address for movie detail window
+               last_cinema = new Cinema (name);
+               last_cinema.address = address;
+               last_cinema.phone = phone;
        }
 
        public void parse (ref char[] buf) throws Error {
index bc00fee..69a9f29 100644 (file)
@@ -103,7 +103,7 @@ class GooglePlugin : Plugin {
                                runtime = 7200;
                        }
 
-                       res = Calendar.add_event (movie.title, _("Movie"), movie.cinema, showtime, showtime + runtime);
+                       res = Calendar.add_event (movie.title, _("Movie"), movie.cinema.name, showtime, showtime + runtime);
                        var banner = (Banner) Banner.show_information_with_markup (window, null, (res == 0) ?
                                                                                   _("Added calendar event at %d:%02d").printf (hour, min) :
                                                                                   _("Failed to add calendar event"));