]> ToastFreeware Gitweb - gregoa/zavai.git/blob - src/zavai.vala
Implement looping
[gregoa/zavai.git] / src / zavai.vala
1 /*
2  * zavai - simple interface to the OpenMoko (or to the FSO stack)
3  *
4  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 using GLib;
22
23 //string VERSION = "0.1";
24
25 static int main (string[] args) {
26         Gtk.init (ref args);
27     Gst.init (ref args);
28
29         // parser = Parser(usage="usage: %prog [options]",
30         //                 version="%prog "+ VERSION,
31         //                 description="Simple interactive interface for the OpenMoko")
32         // parser.add_option("-v", "--verbose", action="store_true", help="verbose mode")
33         // 
34         // (opts, args) = parser.parse_args()
35         // 
36         // if not opts.verbose:
37         //     zavai.set_quiet()
38         // 
39         // # Read configuration
40         // zavai.info("Loading configuration")
41         // conf = zavai.Config()
42
43         // Set up zavai
44
45 /*
46         int id = at.earliestID();
47         stderr.printf("%d\n", id);
48         if (id != -1)
49         {
50                 string? label = zavai.clock.Alarm.getLabel(id);
51                 if (label == null)
52                         stdout.printf("generic at job\n");
53                 else
54                         stdout.printf("zavai at job: %s\n", label);
55         }
56
57         zavai.clock.Alarm.schedule("now + 1 hour", "An\"\'\'\n\n\ttani blinda la supercazzola");
58
59         return 0;
60 */
61
62         if (args.length > 1 && args[1] == "notify")
63         {
64                 stdout.printf("NOTIFY\n");
65                 DBus.Connection sbus;
66                 dynamic DBus.Object zav;
67                 try {
68                         sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
69                 } catch (DBus.Error e) {
70                         stderr.printf("Cannot access system DBus bus: %s\n", e.message);
71                         return 1;
72                 }
73                 // see mdbus -s org.freesmartphone.ousaged /org/freesmartphone/Usage
74                 zav = sbus.get_object(
75                         "org.enricozini.zavai",
76                         "/org/enricozini/Zavai/Clock",
77                         "org.enricozini.zavai.Alarm");
78                 if (args.length > 2)
79                 {
80                         stdout.printf("NOTIFY %s\n", args[2]);
81                         zav.Notify(args[2]);
82                 }
83                 else
84                         zav.Notify("Alarm");
85                 
86                 return 0;
87         }
88
89     // Core infrastructure
90         zavai.config = new zavai.Config();
91         zavai.config.argv0 = args[0];
92         zavai.registry = new zavai.Registry();
93
94     zavai.main.init();
95
96     // Additional infrastructure
97         zavai.input.init();
98         zavai.uevent.init();
99         zavai.power.init();
100         zavai.gps.init();
101         zavai.gsm.init();
102         zavai.clock.init();
103         zavai.audio.init();
104         zavai.log.init();
105         zavai.wifi.init();
106         zavai.bluetooth.init();
107
108         /*
109         zavai.clock.clock.schedule(new zavai.clock.Alarm(123456, "Second"));
110         zavai.clock.clock.schedule(new zavai.clock.Alarm(1234567, "Third"));
111         zavai.clock.clock.schedule(new zavai.clock.Alarm(12345, "First"));
112         zavai.clock.clock.check_alarms();
113         */
114
115         // User interface
116         zavai.ui.main.init();
117         zavai.ui.gps.init();
118         zavai.ui.gsm.init();
119         zavai.app.run_script(zavai.config.homedir + "/display init");
120         zavai.ui.power.init();
121         zavai.ui.aux.init();
122         zavai.ui.kbd.init();
123         zavai.ui.wm.init();
124         zavai.ui.calendar.init();
125         zavai.ui.alarm.init();
126         zavai.ui.wifi.init();
127         zavai.ui.bluetooth.init();
128         zavai.ui.debug.init();
129
130         //zavai.app.show_applet("menu.main");
131         zavai.app.show_applet(zavai.ui.main.status);
132
133 /*
134         zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 10, "Test second"));
135         zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 5, "Test first"));
136         zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 300, "Test third"));
137 */
138
139         //zavai.ui.power.power_menu.toggle();
140
141         // # Shutdown the main loop on SIGINT
142         // def on_kill(signum, frame):
143         //     gtk.main_quit()
144         // signal.signal(signal.SIGINT, on_kill)
145         // signal.signal(signal.SIGTERM, on_kill)
146
147         // zavai.info("Starting")
148         // app = registry.resource("app")
149         // app.connect("destroy", gtk.main_quit)
150         // app.run()
151
152 /*
153         dynamic DBus.Object otime = zavai.registry.sbus.get_object(
154                         "org.freesmartphone.otimed",
155                         "/org/freesmartphone/Time/Alarm",
156                         "org.freesmartphone.Time.Alarm");
157
158         otime.ClearAlarm();
159         otime.SetAlarm(time_t() + 10);
160
161         dynamic DBus.Object notification = zavai.registry.sbus.get_object(
162                         "org.freesmartphone",
163                         "org/freesmartphone/Notification",
164                         "org.freesmartphone.Notification");
165         notification.Alarm += on_alarm;
166 */
167
168         zavai.app.run();
169
170         if (args.length > 1 && args[1] == "alarm")
171     {
172         zavai.clock.AlarmTriggerInfo alarm = new zavai.clock.AlarmTriggerInfo("Prova");
173         zavai.clock.alarm_trigger_queue.enqueue_trigger(alarm);
174     }
175
176         if (args.length > 2 && args[1] == "play")
177     {
178         zavai.audio.musicplayer.play("file://" + args[2]);
179
180         Timeout.add(3 * 1000, () => {
181             zavai.audio.soundplayer.play("file:///backup/ciapino/src/openmoocow/data/moo.wav", true);
182             Timeout.add(4 * 1000, () => {
183                 zavai.audio.soundplayer.stop();
184                 return false;
185             });
186             return false;
187         });
188     }
189
190         Gtk.main();
191
192         // zavai.info("Shutting down")
193         zavai.registry.shutdown();
194
195         return 0;
196 }