ui: Created moviemanager
[maevies] / ui / maeviesui / maeviesui / gui.py
index c3efc05..925a110 100644 (file)
@@ -24,7 +24,7 @@ import hildon
 import pygtk
 import pango
 import gobject
-import random
+from maeviesui.util.moviemanager import MovieManager
 pygtk.require("2.0")
 import gtk
 
@@ -54,8 +54,7 @@ class Maevies(hildon.StackableWindow):
                                hildon.BUTTON_ARRANGEMENT_VERTICAL, title, subtitle)
         button.connect("clicked", self._button_clicked, action)
 
-        box.pack_start(button,
-                             expand = True, fill = False)
+        box.pack_start(button, expand = True, fill = False)
 
         return box
 
@@ -164,7 +163,8 @@ class ResultsWindow(hildon.StackableWindow):
         self.search_term = search_term
         self.search_category = search_category
 
-        self._simulate_search()
+        self.moviemanager = MovieManager(self._populate_view)
+
         content_area = hildon.PannableArea()
         self._movies_view = MoviesView()
         self._movies_view.connect('row-activated', self._row_activated_cb)
@@ -172,28 +172,20 @@ class ResultsWindow(hildon.StackableWindow):
         content_area.add(self._movies_view)
         self.add(content_area)
 
+        self._start_search()
         self.show_all()
 
     def _row_activated_cb(self, view, path, column):
         #movie = view.get_movie_from_path(path)
         MovieWindow(None)
 
-
-    def _simulate_search(self):
+    def _start_search(self):
         self._show_banner()
         hildon.hildon_gtk_window_set_progress_indicator(self, True)
-        gobject.timeout_add(constants.TIMEOUT_TIME_MILLIS, self._populate_view)
-
-    def _populate_view(self):
-        self._movies_view.add_movies([MovieDecorator("The Lord of the Rings"),
-                                      MovieDecorator("The Lord of the flies"),
-                                      MovieDecorator("Gone by the wind"),
-                                      MovieDecorator("Madagascar"),
-                                      MovieDecorator("Madagascar 2"),
-                                      MovieDecorator("2 Fast 2 Furious"),
-                                      MovieDecorator("Fast & Furious"),
-                                      MovieDecorator("Pitch Black"),
-                                      ])
+        self.moviemanager.query(self.search_term)
+
+    def _populate_view(self, movies):
+        self._movies_view.add_movies(movies)
         hildon.hildon_gtk_window_set_progress_indicator(self, False)
         return False
 
@@ -256,34 +248,6 @@ class AboutDialog(gtk.Dialog):
         self.set_title("About Maevies")
         self.show_all()
 
-class MovieDecorator:
-
-    def __init__(self, name):
-        self._name = name
-        pass
-
-    def get_name(self):
-        return self._name
-
-    def get_length(self):
-        return "%sh:%sm" % (random.randrange(1, 2), random.randrange(0, 59))
-
-    def get_score(self):
-        return "%s" % (random.randrange(6, 9))
-
-    def get_info(self):
-        return "<b>%s</b>\n<small><i>Length: </i>%s || <i>Score: </i>%s</small>" % (
-                                                                                     self.get_name(),
-                                                                                     self.get_length(),
-                                                                                     self.get_score())
-
-    def get_image(self):
-        return self._get_placeholder_pixbuf()
-
-    def _get_placeholder_pixbuf(self):
-        pixbuf = gtk.IconTheme().load_icon('general_video_file', 48, 0)
-        return pixbuf
-
 class MovieWindow(hildon.StackableWindow):
 
     _zombieland = {'Title' : "Zombieland", 'Release date' : "27 November 2009",