From: Philipp Zabel Date: Wed, 10 Feb 2010 17:52:21 +0000 (+0100) Subject: Google plugin/backend: turn runtime string into an integer (in seconds) X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=204b335f74d7ee48c46b15fde50df252331787c6;p=cinaest Google plugin/backend: turn runtime string into an integer (in seconds) --- diff --git a/src/backends/google/google-backend.vala b/src/backends/google/google-backend.vala index 6a375b8..1b78685 100644 --- a/src/backends/google/google-backend.vala +++ b/src/backends/google/google-backend.vala @@ -68,7 +68,7 @@ public class MovieSearch : Object { var m = new string[results.length ()]; int i = 0; for (unowned GLib.List node = results.first (); node != null; node = node.next) { - m[i++] = "{\"title\":\"%s\",\"rating\":%f,\"showtimes\":\"%s\",\"cinema_name\":\"%s\",\"cinema_phone\":\"%s\"}".printf (node.data.title, node.data.rating, node.data.showtimes, node.data.cinema.name, node.data.cinema.phone); + m[i++] = "{\"title\":\"%s\",\"rating\":%f,\"runtime\":%d,\"showtimes\":\"%s\",\"cinema_name\":\"%s\",\"cinema_phone\":\"%s\"}".printf (node.data.title, node.data.rating, node.data.runtime, node.data.showtimes, node.data.cinema.name, node.data.cinema.phone); } movies_found (m, true); service.timeout_quit (); diff --git a/src/backends/google/google-parser.vala b/src/backends/google/google-parser.vala index 886772d..6254416 100644 --- a/src/backends/google/google-parser.vala +++ b/src/backends/google/google-parser.vala @@ -34,9 +34,8 @@ public class Cinema { public class GoogleMovie { public string title; public int rating; - public string secondary; public Cinema cinema; - public string runtime; + public int runtime; public string fsk; public string showtimes; } @@ -259,18 +258,16 @@ public class GoogleParser : Object { movie.rating = (int) (rating * 10); movie.cinema = last_cinema; + movie.runtime = 0; if (runtime_and_fsk.length >= 2) { - movie.runtime = runtime_and_fsk[0]; + unowned string runtime = runtime_and_fsk[0]; + movie.runtime = 3600 * runtime.to_int (); + runtime = runtime.str ("hr "); + if (runtime != null) + movie.runtime += 60 * runtime.offset (3).to_int (); movie.fsk = runtime_and_fsk[1]; } movie.showtimes = showtimes; - - // TODO - could be configurable by settings - if (movie.runtime != null) - movie.secondary = "%s - %s - %s".printf (movie.runtime, last_cinema.name, showtimes); - else - movie.secondary = "%s - %s".printf (last_cinema.name, showtimes); - _get_callback (movie); } diff --git a/src/plugins/google-plugin.vala b/src/plugins/google-plugin.vala index 5491a6d..d02b7a8 100644 --- a/src/plugins/google-plugin.vala +++ b/src/plugins/google-plugin.vala @@ -22,7 +22,7 @@ using Hildon; public class GoogleMovie : Movie { public string cinema_name; public string cinema_phone; - public string runtime; + public int runtime; public string showtimes; } @@ -96,7 +96,7 @@ class GooglePlugin : Plugin { timeinfo.hour = hour; showtime = timeinfo.mktime (); - int runtime = 3600 * movie.runtime.to_int () + 60 * movie.runtime.str ("hr ").offset (3).to_int (); + int runtime = movie.runtime; if (runtime == 0) { // Default to 120min if we failed to parse the runtime runtime = 7200; @@ -258,8 +258,12 @@ class GoogleSource : MovieSource { movie.rating = (int) object.get_double_member ("rating"); movie.cinema_name = object.get_string_member ("cinema_name"); movie.cinema_phone = object.get_string_member ("cinema_phone"); + movie.runtime = (int) object.get_int_member ("runtime"); movie.showtimes = object.get_string_member ("showtimes"); - movie.secondary = movie.cinema_name + " - " + movie.showtimes; + if (movie.runtime > 0) + movie.secondary = "%d min - %s - %s".printf (movie.runtime / 60, movie.cinema_name, movie.showtimes); + else + movie.secondary = movie.cinema_name + " - " + movie.showtimes; callback (movie); }