2 * zavai - simple interface to the OpenMoko (or to the FSO stack)
4 * Copyright (C) 2009--2010 Enrico Zini <enrico@enricozini.org>
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.
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.
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
23 //string VERSION = "0.1";
24 static string pidfilename;
26 static Posix.pid_t is_running()
28 string pidfile = zavai.config.homedir + "/" + pidfilename + ".pid";
31 if (!FileUtils.get_contents(pidfile, out contents))
33 } catch (FileError e) {
36 int val = contents.to_int();
37 string procdir = "/proc/%d".printf(val);
38 if (FileUtils.test(procdir, FileTest.IS_DIR))
39 return (Posix.pid_t)val;
44 static void make_pidfile()
46 string pidfile = zavai.config.homedir + "/" + pidfilename + ".pid";
47 FileUtils.set_contents(pidfile, "%d".printf(Posix.getpid()));
50 static void on_kill(int sig)
56 static int main (string[] args) {
57 bool opt_popup = false;
58 bool opt_calendar = false;
59 GLib.OptionEntry[] entries = new GLib.OptionEntry[] {
65 arg_data = &opt_popup,
66 description = "run as a popup at the specified location on screen",
67 arg_description = null },
69 long_name = "calendar",
73 arg_data = &opt_calendar,
74 description = "run as calendar only",
75 arg_description = null },
78 Gtk.init_with_args(ref args, "", entries, null);
81 pidfilename = "zavai";
83 // if not opts.verbose:
89 int id = at.earliestID();
90 stderr.printf("%d\n", id);
93 string? label = zavai.clock.Alarm.getLabel(id);
95 stdout.printf("generic at job\n");
97 stdout.printf("zavai at job: %s\n", label);
100 zavai.clock.Alarm.schedule("now + 1 hour", "An\"\'\'\n\n\ttani blinda la supercazzola");
105 if (args.length > 1 && args[1] == "notify")
107 stdout.printf("NOTIFY\n");
108 DBus.Connection sbus;
109 dynamic DBus.Object zav;
111 sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
112 } catch (DBus.Error e) {
113 stderr.printf("Cannot access system DBus bus: %s\n", e.message);
116 // see mdbus -s org.freesmartphone.ousaged /org/freesmartphone/Usage
117 zav = sbus.get_object(
118 "org.enricozini.zavai",
119 "/org/enricozini/Zavai/Clock",
120 "org.enricozini.zavai.Alarm");
123 stdout.printf("NOTIFY %s\n", args[2]);
132 // Core infrastructure
133 zavai.config = new zavai.Config();
134 zavai.config.argv0 = args[0];
138 pidfilename = "calendar";
141 var calendar = new zavai.widgets.Calendar();
143 Gtk.Window win = new Gtk.Window(Gtk.WindowType.TOPLEVEL);
146 Posix.pid_t pid = is_running();
149 // Kill a running calendar
150 Posix.kill(pid, Posix.SIGINT);
151 FileUtils.unlink(zavai.config.homedir + "/" + pidfilename + ".pid");
157 win.set_decorated(false);
158 //win.set_resizable(false);
159 win.set_border_width(5);
160 win.set_skip_taskbar_hint(true);
161 win.set_skip_pager_hint(true);
162 // gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DOCK);
163 win.set_position(Gtk.WindowPosition.MOUSE);
167 win.title = "Zavai calendar";
168 win.destroy += Gtk.main_quit;
170 win.set_size_request(300, 500);
174 // Shutdown the main loop on SIGINT
175 Posix.signal(Posix.SIGINT, on_kill);
176 Posix.signal(Posix.SIGTERM, on_kill);
186 zavai.registry = new zavai.Registry();
190 // Additional infrastructure
200 zavai.bluetooth.init();
203 zavai.clock.clock.schedule(new zavai.clock.Alarm(123456, "Second"));
204 zavai.clock.clock.schedule(new zavai.clock.Alarm(1234567, "Third"));
205 zavai.clock.clock.schedule(new zavai.clock.Alarm(12345, "First"));
206 zavai.clock.clock.check_alarms();
210 zavai.ui.music.init();
211 zavai.ui.main.init();
214 zavai.config.find_and_run_script("display", "init");
215 zavai.ui.power.init();
219 zavai.ui.calendar.init();
220 zavai.ui.alarm.init();
221 zavai.ui.wifi.init();
222 zavai.ui.bluetooth.init();
223 zavai.ui.debug.init();
225 //zavai.app.show_applet("menu.main");
226 zavai.app.show_applet(zavai.ui.main.status);
229 zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 10, "Test second"));
230 zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 5, "Test first"));
231 zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 300, "Test third"));
234 //zavai.ui.power.power_menu.toggle();
236 // # Shutdown the main loop on SIGINT
237 // def on_kill(signum, frame):
239 // signal.signal(signal.SIGINT, on_kill)
240 // signal.signal(signal.SIGTERM, on_kill)
242 // zavai.info("Starting")
243 // app = registry.resource("app")
244 // app.connect("destroy", gtk.main_quit)
248 dynamic DBus.Object otime = zavai.registry.sbus.get_object(
249 "org.freesmartphone.otimed",
250 "/org/freesmartphone/Time/Alarm",
251 "org.freesmartphone.Time.Alarm");
254 otime.SetAlarm(time_t() + 10);
256 dynamic DBus.Object notification = zavai.registry.sbus.get_object(
257 "org.freesmartphone",
258 "org/freesmartphone/Notification",
259 "org.freesmartphone.Notification");
260 notification.Alarm += on_alarm;
265 if (args.length > 1 && args[1] == "alarm")
267 zavai.clock.AlarmTriggerInfo alarm = new zavai.clock.AlarmTriggerInfo("Prova");
268 zavai.clock.alarm_trigger_queue.enqueue_trigger(alarm);
271 if (args.length > 2 && args[1] == "play")
273 zavai.audio.musicplayer.play("file://" + args[2]);
275 // Timeout.add(3 * 1000, () => {
276 // zavai.audio.soundplayer.play("file:///backup/ciapino/src/openmoocow/data/moo.wav", true);
277 // Timeout.add(4 * 1000, () => {
278 // zavai.audio.soundplayer.stop();
287 // zavai.info("Shutting down")
288 zavai.registry.shutdown();