Add org.maemo.cinaest.OpenMovie D-Bus method, second window stack
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 19 Aug 2010 17:08:56 +0000 (19:08 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 19 Aug 2010 17:08:56 +0000 (19:08 +0200)
Makefile.am
src/main.vala
vapi/libosso-fix.vapi [new file with mode: 0644]

index 9de75d3..98d948c 100644 (file)
@@ -90,7 +90,7 @@ src/main.c: ${cinaest_VALASOURCES}
 cinaest_VALAFLAGS = --disable-dbus-transformation --vapidir ./vapi --pkg config --pkg cinaest \
        --pkg dbus-glib-1 --pkg gconf-2.0 --pkg hildon-1 --pkg hildon-fm-2 \
        --pkg libosso --pkg gmodule-2.0 --pkg gobject-2.0-fix \
-       --pkg libxml-2.0
+       --pkg libosso-fix --pkg libxml-2.0
 cinaest_CFLAGS = ${CINAEST_CFLAGS} ${DBUS_CFLAGS} ${GCONF_CFLAGS} \
        ${HILDON_CFLAGS} ${HILDONFM_CFLAGS} ${XML_CFLAGS} \
        ${MAEMO_LAUNCHER_CFLAGS} ${OSSO_CFLAGS} ${GMODULE_CFLAGS} \
index 752997c..708d00c 100644 (file)
 using Hildon;
 
 public class CinaestProgram : Hildon.Program {
-       SourceListWindow window;
+       internal SourceListWindow window;
+       internal WindowStack secondary_stack;
        public static List<Plugin> plugins;
+       public static MovieSource reference;
        public static Orientation orientation;
 
        construct {
@@ -29,10 +31,14 @@ public class CinaestProgram : Hildon.Program {
                window = new SourceListWindow ();
                window.destroy.connect (Gtk.main_quit);
 
+               reference = null;
+
                orientation = new Orientation ();
                orientation.changed.connect (on_orientation_changed);
 
                add_window (window);
+
+               secondary_stack = new WindowStack ();
        }
 
        private void on_orientation_changed () {
@@ -71,9 +77,60 @@ public class CinaestProgram : Hildon.Program {
                }
        }
 
+       static int osso_callback (string iface, string method, GLib.Array arguments, void* data, out Osso.Rpc rpc) {
+               var app = (CinaestProgram) data;
+               if (method == "OpenMovie") {
+                       if (arguments.length < 1) {
+                               rpc.type = DBus.RawType.STRING;
+                               ((OssoFix.Rpc) rpc).s = "OpenMovie missing movie parameter";
+                               return Osso.Status.ERROR;
+                       }
+                       // Vala doesn't support GLib.Array<Osso.Rpc>, so we have to cast:
+                       Osso.Rpc* arg = *(Osso.Rpc**) arguments;
+                       if (arg[0].type != DBus.RawType.STRING) {
+                               rpc.type = DBus.RawType.STRING;
+                               ((OssoFix.Rpc) rpc).s = "OpenMovie first parameter must be string";
+                               return Osso.Status.ERROR;
+                       }
+                       string title = arg[0].s;
+                       int year = 0;
+                       if (arguments.length >= 2) {
+                               if (arg[1].type != DBus.RawType.INT32) {
+                                       rpc.type = DBus.RawType.STRING;
+                                       ((OssoFix.Rpc) rpc).s = "OpenMovie second parameter must be int";
+                                       return Osso.Status.ERROR;
+                               }
+                               year = arg[1].i;
+                       }
+                       if (reference == null) {
+                               rpc.type = DBus.RawType.STRING;
+                               ((OssoFix.Rpc) rpc).s = "No reference source installed";
+                               return Osso.Status.ERROR;
+                       }
+                       print ("OpenMovie (\"%s\"", title);
+                       if (year > 0)
+                               print (", %d", year);
+                       print (")\n");
+
+                       var list_window = new MovieListWindow (reference, title, year);
+                       var widget = app.secondary_stack.pop_1 ();
+                       while (widget != null) {
+                               widget.destroy ();
+                               widget = app.secondary_stack.pop_1 ();
+                       }
+                       app.secondary_stack.push_1 (list_window);
+               }
+               rpc.type = DBus.RawType.INVALID;
+               return Osso.Status.OK;
+       }
+
        public void run () {
                foreach (Plugin plugin in plugins) {
                        window.add_sources (plugin.get_sources ());
+                       foreach (MovieSource source in plugin.get_sources ()) {
+                               if (reference == null && SourceFlags.REFERENCE in source.get_flags ())
+                                       reference = source;
+                       }
                }
                Gtk.main ();
        }
@@ -92,6 +149,7 @@ public class CinaestProgram : Hildon.Program {
 
                CinaestProgram app = new CinaestProgram ();
                app.register_plugins (osso_context);
+               osso_context.set_rpc_default_callback (osso_callback, app);
                app.run ();
 
                return 0;
diff --git a/vapi/libosso-fix.vapi b/vapi/libosso-fix.vapi
new file mode 100644 (file)
index 0000000..3496be9
--- /dev/null
@@ -0,0 +1,37 @@
+[CCode (cheader_filename = "libosso.h")]
+namespace OssoFix {
+       [CCode (destroy_function = "osso_rpc_free_val", cname = "osso_rpc_t")]
+       public struct Rpc {
+               public int type;
+               [CCode (cname = "value.u")]
+               private uint32 u;
+               [CCode (cname = "value.i")]
+               private int32 i;
+               [CCode (cname = "value.b")]
+               private bool b;
+               [CCode (cname = "value.d")]
+               private double d;
+               [CCode (cname = "value.s")]
+               private unowned string s;
+               public uint32 to_uint32 () requires (type == DBus.RawType.UINT32) {
+                       return u;
+               }
+               public int32 to_int32 () requires (type == DBus.RawType.INT32) {
+                       return i;
+               }
+               public bool to_bool () requires (type == DBus.RawType.BOOLEAN) {
+                       return b;
+               }
+               public double to_double () requires (type == DBus.RawType.DOUBLE) {
+                       return d;
+               }
+               public unowned string to_string () requires (type == DBus.RawType.STRING) {
+                       return s;
+               }
+               public void set_string (string s_) {
+                       type = DBus.RawType.STRING;
+                       s = s_;
+               }
+       }
+}
+