Czech translation update (via transifex.net)
[cinaest] / src / main.vala
index f243102..708d00c 100644 (file)
 using Hildon;
 
 public class CinaestProgram : Hildon.Program {
-       MovieListWindow window;
-       List<Plugin> plugins;
+       internal SourceListWindow window;
+       internal WindowStack secondary_stack;
+       public static List<Plugin> plugins;
+       public static MovieSource reference;
+       public static Orientation orientation;
 
        construct {
                Environment.set_application_name ("Cinæst");
 
-               window = new MovieListWindow ();
+               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 ();
        }
 
-       public void register_plugins () {
-               string plugin_path = Environment.get_variable ("PWD");
+       private void on_orientation_changed () {
+               if (orientation.portrait) {
+                       Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.REQUEST);
+               } else {
+                       Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.SUPPORT);
+               }
+       }
+
+       public void register_plugins (Osso.Context context) {
+               string plugin_path = Config.PKGLIBDIR;
                try {
                        var directory = File.new_for_path (plugin_path);
                        var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
@@ -50,7 +68,7 @@ public class CinaestProgram : Hildon.Program {
 
                                        plugin = registrar.new_object ();
                                        plugins.append (plugin);
-                                       plugin.hello (window);
+                                       plugin.hello (window, context);
                                }
                        }
 
@@ -59,27 +77,79 @@ 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 () {
-               register_plugins ();
-               // FIXME - always start with the first plugin's first source for now
-               if (plugins != null) {
-                       var plugin = plugins.first ().data;
-                       if (plugin != null)
-                               window.store.source = plugin.get_sources ().first ().data;
+               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 ();
        }
 
        static int main (string[] args) {
                Gtk.init (ref args);
-               Gdk.threads_init ();
 
-               var osso_context = new Osso.Context ("org.maemo.cinaest", "0.0.1", true, null);
+               Intl.setlocale (LocaleCategory.ALL, "");
+               Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
+               Intl.textdomain (Config.GETTEXT_PACKAGE);
+
+               var osso_context = new Osso.Context ("org.maemo.cinaest", Config.VERSION, true, null);
                if (osso_context == null) {
                        return Osso.Status.ERROR;
                }
 
                CinaestProgram app = new CinaestProgram ();
+               app.register_plugins (osso_context);
+               osso_context.set_rpc_default_callback (osso_callback, app);
                app.run ();
 
                return 0;