Movie list menu: use hildon-fm-2 file chooser dialog to import files
[cinaest] / src / main.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2009 Philipp Zabel
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 using Hildon;
20
21 public class CinaestProgram : Hildon.Program {
22         SourceListWindow window;
23         public static List<Plugin> plugins;
24         public static Orientation orientation;
25
26         construct {
27                 Environment.set_application_name ("Cinæst");
28
29                 window = new SourceListWindow ();
30                 window.destroy.connect (Gtk.main_quit);
31
32                 orientation = new Orientation ();
33                 orientation.changed.connect (on_orientation_changed);
34
35                 add_window (window);
36         }
37
38         private void on_orientation_changed () {
39                 if (orientation.portrait) {
40                         Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.REQUEST);
41                 } else {
42                         Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.SUPPORT);
43                 }
44         }
45
46         public void register_plugins (Osso.Context context) {
47                 string plugin_path = Config.PKGLIBDIR;
48                 try {
49                         var directory = File.new_for_path (plugin_path);
50                         var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
51
52                         FileInfo file_info;
53                         while ((file_info = enumerator.next_file (null)) != null) {
54                                 string name = file_info.get_name ();
55
56                                 if (name.has_suffix (".so")) {
57                                         Plugin plugin;
58                                         string path = Path.build_filename (plugin_path, name, null);
59
60                                         var registrar = new PluginRegistrar<Plugin> (path);
61                                         registrar.load ();
62
63                                         plugin = registrar.new_object ();
64                                         plugins.append (plugin);
65                                         plugin.hello (window, context);
66                                 }
67                         }
68
69                 } catch (Error e) {
70                         stderr.printf ("Error: %s\n", e.message);
71                 }
72         }
73
74         public void run () {
75                 foreach (Plugin plugin in plugins) {
76                         window.add_sources (plugin.get_sources ());
77                 }
78                 Gtk.main ();
79         }
80
81         static int main (string[] args) {
82                 Gtk.init (ref args);
83
84                 Intl.setlocale (LocaleCategory.ALL, "");
85                 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
86                 Intl.textdomain (Config.GETTEXT_PACKAGE);
87
88                 var osso_context = new Osso.Context ("org.maemo.cinaest", Config.VERSION, true, null);
89                 if (osso_context == null) {
90                         return Osso.Status.ERROR;
91                 }
92
93                 CinaestProgram app = new CinaestProgram ();
94                 app.register_plugins (osso_context);
95                 app.run ();
96
97                 return 0;
98         }
99 }
100