Add a search thread to the movie list store
[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         MovieListWindow window;
23         List<Plugin> plugins;
24
25         construct {
26                 Environment.set_application_name ("Cinæst");
27
28                 window = new MovieListWindow ();
29                 window.destroy.connect (Gtk.main_quit);
30
31                 add_window (window);
32         }
33
34         public void register_plugins () {
35                 string plugin_path = Environment.get_variable ("PWD");
36                 try {
37                         var directory = File.new_for_path (plugin_path);
38                         var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
39
40                         FileInfo file_info;
41                         while ((file_info = enumerator.next_file (null)) != null) {
42                                 string name = file_info.get_name ();
43
44                                 if (name.has_suffix (".so")) {
45                                         Plugin plugin;
46                                         string path = Path.build_filename (plugin_path, name, null);
47
48                                         var registrar = new PluginRegistrar<Plugin> (path);
49                                         registrar.load ();
50
51                                         plugin = registrar.new_object ();
52                                         plugins.append (plugin);
53                                         plugin.hello (window);
54                                 }
55                         }
56
57                 } catch (Error e) {
58                         stderr.printf ("Error: %s\n", e.message);
59                 }
60         }
61
62         public void run () {
63                 register_plugins ();
64                 // FIXME - always start with the first plugin's first source for now
65                 if (plugins != null) {
66                         var plugin = plugins.first ().data;
67                         if (plugin != null)
68                                 window.store.source = plugin.get_sources ().first ().data;
69                 }
70                 Gtk.main ();
71         }
72
73         static int main (string[] args) {
74                 Gtk.init (ref args);
75                 Gdk.threads_init ();
76
77                 var osso_context = new Osso.Context ("org.maemo.cinaest", "0.0.1", true, null);
78                 if (osso_context == null) {
79                         return Osso.Status.ERROR;
80                 }
81
82                 CinaestProgram app = new CinaestProgram ();
83                 app.run ();
84
85                 return 0;
86         }
87 }
88