1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
5 * Cinaest is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Cinaest is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
21 public class CinaestProgram : Hildon.Program {
22 internal SourceListWindow window;
23 internal WindowStack secondary_stack;
24 public static List<Plugin> plugins;
25 public static MovieSource reference;
26 public static Orientation orientation;
29 Environment.set_application_name ("Cinæst");
31 window = new SourceListWindow ();
32 window.destroy.connect (Gtk.main_quit);
36 orientation = new Orientation ();
37 orientation.changed.connect (on_orientation_changed);
41 secondary_stack = new WindowStack ();
44 private void on_orientation_changed () {
45 if (orientation.portrait) {
46 Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.REQUEST);
48 Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.SUPPORT);
52 public void register_plugins (Osso.Context context) {
53 string plugin_path = Config.PKGLIBDIR;
55 var directory = File.new_for_path (plugin_path);
56 var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
59 while ((file_info = enumerator.next_file (null)) != null) {
60 string name = file_info.get_name ();
62 if (name.has_suffix (".so")) {
64 string path = Path.build_filename (plugin_path, name, null);
66 var registrar = new PluginRegistrar<Plugin> (path);
69 plugin = registrar.new_object ();
70 plugins.append (plugin);
71 plugin.hello (window, context);
76 stderr.printf ("Error: %s\n", e.message);
80 static int osso_callback (string iface, string method, GLib.Array arguments, void* data, out Osso.Rpc rpc) {
81 var app = (CinaestProgram) data;
82 if (method == "OpenMovie") {
83 if (arguments.length < 1) {
84 rpc.type = DBus.RawType.STRING;
85 ((OssoFix.Rpc) rpc).s = "OpenMovie missing movie parameter";
86 return Osso.Status.ERROR;
88 // Vala doesn't support GLib.Array<Osso.Rpc>, so we have to cast:
89 Osso.Rpc* arg = *(Osso.Rpc**) arguments;
90 if (arg[0].type != DBus.RawType.STRING) {
91 rpc.type = DBus.RawType.STRING;
92 ((OssoFix.Rpc) rpc).s = "OpenMovie first parameter must be string";
93 return Osso.Status.ERROR;
95 string title = arg[0].s;
97 if (arguments.length >= 2) {
98 if (arg[1].type != DBus.RawType.INT32) {
99 rpc.type = DBus.RawType.STRING;
100 ((OssoFix.Rpc) rpc).s = "OpenMovie second parameter must be int";
101 return Osso.Status.ERROR;
105 if (reference == null) {
106 rpc.type = DBus.RawType.STRING;
107 ((OssoFix.Rpc) rpc).s = "No reference source installed";
108 return Osso.Status.ERROR;
110 print ("OpenMovie (\"%s\"", title);
112 print (", %d", year);
115 var list_window = new MovieListWindow (reference, title, year);
116 var widget = app.secondary_stack.pop_1 ();
117 while (widget != null) {
119 widget = app.secondary_stack.pop_1 ();
121 app.secondary_stack.push_1 (list_window);
123 rpc.type = DBus.RawType.INVALID;
124 return Osso.Status.OK;
128 foreach (Plugin plugin in plugins) {
129 window.add_sources (plugin.get_sources ());
130 foreach (MovieSource source in plugin.get_sources ()) {
131 if (reference == null && SourceFlags.REFERENCE in source.get_flags ())
138 static int main (string[] args) {
141 Intl.setlocale (LocaleCategory.ALL, "");
142 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
143 Intl.textdomain (Config.GETTEXT_PACKAGE);
145 var osso_context = new Osso.Context ("org.maemo.cinaest", Config.VERSION, true, null);
146 if (osso_context == null) {
147 return Osso.Status.ERROR;
150 CinaestProgram app = new CinaestProgram ();
151 app.register_plugins (osso_context);
152 osso_context.set_rpc_default_callback (osso_callback, app);