ui: Created moviemanager
authorSimón Pena <spenap@gmail.com>
Mon, 31 May 2010 17:28:53 +0000 (19:28 +0200)
committerSimón Pena <spenap@gmail.com>
Mon, 31 May 2010 17:28:53 +0000 (19:28 +0200)
Created a moviemanager module to connect the ui with DBus
Updated TODO

TODO
ui/maeviesui/maeviesui/gui.py
ui/maeviesui/util/moviemanager.py [new file with mode: 0644]

diff --git a/TODO b/TODO
index 832cae1..f1ee7f1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -5,5 +5,3 @@ Release 0.1:
     - The result objects lifetime must be controlled and finalized
        when not needed.
 * Update build so that it creates a .service file
-* Create a MovieManager class in Python to ask for and retrieve results
-* Connect the UI with the MovieManager
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 &amp; 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",
diff --git a/ui/maeviesui/util/moviemanager.py b/ui/maeviesui/util/moviemanager.py
new file mode 100644 (file)
index 0000000..3d73948
--- /dev/null
@@ -0,0 +1,91 @@
+# -*- coding: utf-8 -*-
+
+###########################################################################
+#    Maevies
+#    Copyright (C) 2010 Simón Pena <spenap@gmail.com>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+###########################################################################
+
+import dbus
+import gobject
+from dbus import glib
+import random
+import gtk
+
+gobject.threads_init()
+glib.init_threads()
+
+MINFO_PROVIDER_INTERFACE = 'com.simonpena.maevies.minfoprovider'
+MINFO_PROVIDER_BUS_NAME = 'com.simonpena.maevies.minfoprovider'
+TMDB_MOVIE_INTERFACE = 'com.simonpena.maevies.movie'
+TMDB_MOVIE_BUS_NAME = 'com.simonpena.maevies.tmdbmovie'
+TMDB = 0
+WATC = 1
+
+class MovieManager:
+
+    def __init__(self, callback):
+        self.bus = dbus.SessionBus()
+
+        self.minfo_provider = self.bus.get_object(MINFO_PROVIDER_BUS_NAME,
+                                                  '/MInfoProvider')
+        self.minfo_interface = dbus.Interface(self.minfo_provider,
+                                              dbus_interface = MINFO_PROVIDER_INTERFACE)
+        self.minfo_interface.connect_to_signal("ResponseReceived",
+                                              self._on_response_received)
+        self.callback = callback
+
+    def query(self, movie_name = '', query_type = TMDB):
+        self.minfo_interface.Query(query_type, movie_name)
+
+    def _on_response_received(self, object_paths, sender = None):
+        movies = []
+        for path in object_paths:
+            movies.append(self._create_from_path(path))
+
+        self.callback(movies)
+
+    def _create_from_path(self, object_path):
+        dbus_movie = self.bus.get_object(TMDB_MOVIE_BUS_NAME,
+                                         object_path)
+        return MovieDecorator(dbus_movie.GetTitle(dbus_interface = TMDB_MOVIE_INTERFACE))
+
+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