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";
48 FileUtils.set_contents(pidfile, "%d".printf(Posix.getpid()));
49 } catch (FileError e) {
50 zavai.log.error("Cannot create pidfile " + pidfile + ": " + e.message);
54 static void on_kill(int sig)
60 static int main (string[] args) {
61 bool opt_popup = false;
62 bool opt_calendar = false;
63 GLib.OptionEntry[] entries = new GLib.OptionEntry[] {
69 arg_data = &opt_popup,
70 description = "run as a popup at the specified location on screen",
71 arg_description = null },
73 long_name = "calendar",
77 arg_data = &opt_calendar,
78 description = "run as calendar only",
79 arg_description = null },
83 Gtk.init_with_args(ref args, "", entries, null);
85 zavai.log.error("Cannot init gtk: " + e.message);
90 pidfilename = "zavai";
92 // if not opts.verbose:
98 int id = at.earliestID();
99 stderr.printf("%d\n", id);
102 string? label = zavai.clock.Alarm.getLabel(id);
104 stdout.printf("generic at job\n");
106 stdout.printf("zavai at job: %s\n", label);
109 zavai.clock.Alarm.schedule("now + 1 hour", "An\"\'\'\n\n\ttani blinda la supercazzola");
114 if (args.length > 1 && args[1] == "notify")
116 stdout.printf("NOTIFY\n");
117 DBus.Connection sbus;
118 dynamic DBus.Object zav;
120 sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
121 } catch (DBus.Error e) {
122 stderr.printf("Cannot access system DBus bus: %s\n", e.message);
125 // see mdbus -s org.freesmartphone.ousaged /org/freesmartphone/Usage
126 zav = sbus.get_object(
127 "org.enricozini.zavai",
128 "/org/enricozini/Zavai/Clock",
129 "org.enricozini.zavai.Alarm");
132 stdout.printf("NOTIFY %s\n", args[2]);
141 // Core infrastructure
142 zavai.config = new zavai.Config();
143 zavai.config.argv0 = args[0];
147 pidfilename = "calendar";
150 var calendar = new zavai.widgets.Calendar();
152 Gtk.Window win = new Gtk.Window(Gtk.WindowType.TOPLEVEL);
155 Posix.pid_t pid = is_running();
158 // Kill a running calendar
159 Posix.kill(pid, Posix.SIGINT);
160 FileUtils.unlink(zavai.config.homedir + "/" + pidfilename + ".pid");
166 win.set_decorated(false);
167 //win.set_resizable(false);
168 win.set_border_width(5);
169 win.set_skip_taskbar_hint(true);
170 win.set_skip_pager_hint(true);
171 // gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DOCK);
172 win.set_position(Gtk.WindowPosition.MOUSE);
176 win.title = "Zavai calendar";
177 win.destroy += Gtk.main_quit;
179 win.set_size_request(300, 500);
183 // Shutdown the main loop on SIGINT
184 Posix.signal(Posix.SIGINT, on_kill);
185 Posix.signal(Posix.SIGTERM, on_kill);
195 zavai.registry = new zavai.Registry();
199 // Additional infrastructure
209 zavai.bluetooth.init();
212 zavai.clock.clock.schedule(new zavai.clock.Alarm(123456, "Second"));
213 zavai.clock.clock.schedule(new zavai.clock.Alarm(1234567, "Third"));
214 zavai.clock.clock.schedule(new zavai.clock.Alarm(12345, "First"));
215 zavai.clock.clock.check_alarms();
219 zavai.ui.music.init();
220 zavai.ui.main.init();
223 zavai.config.find_and_run_script("display", "init");
224 zavai.ui.power.init();
228 zavai.ui.calendar.init();
229 zavai.ui.alarm.init();
230 zavai.ui.wifi.init();
231 zavai.ui.bluetooth.init();
232 zavai.ui.debug.init();
234 //zavai.app.show_applet("menu.main");
235 zavai.app.show_applet(zavai.ui.main.status);
238 zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 10, "Test second"));
239 zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 5, "Test first"));
240 zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 300, "Test third"));
243 //zavai.ui.power.power_menu.toggle();
245 // # Shutdown the main loop on SIGINT
246 // def on_kill(signum, frame):
248 // signal.signal(signal.SIGINT, on_kill)
249 // signal.signal(signal.SIGTERM, on_kill)
251 // zavai.info("Starting")
252 // app = registry.resource("app")
253 // app.connect("destroy", gtk.main_quit)
257 dynamic DBus.Object otime = zavai.registry.sbus.get_object(
258 "org.freesmartphone.otimed",
259 "/org/freesmartphone/Time/Alarm",
260 "org.freesmartphone.Time.Alarm");
263 otime.SetAlarm(time_t() + 10);
265 dynamic DBus.Object notification = zavai.registry.sbus.get_object(
266 "org.freesmartphone",
267 "org/freesmartphone/Notification",
268 "org.freesmartphone.Notification");
269 notification.Alarm += on_alarm;
274 if (args.length > 1 && args[1] == "alarm")
276 zavai.clock.AlarmTriggerInfo alarm = new zavai.clock.AlarmTriggerInfo("Prova");
277 zavai.clock.alarm_trigger_queue.enqueue_trigger(alarm);
280 if (args.length > 2 && args[1] == "showlog")
282 zavai.log.log.list_entries((d, f) => {
283 stderr.printf("FALSE %s %s\n", d, f);
286 zavai.log.log.list_entries((d, f) => {
287 stderr.printf("TRUE %s %s\n", d, f);
290 zavai.log.Log l = zavai.log.log.load(args[2]);
295 if (args.length > 2 && args[1] == "play")
297 zavai.audio.musicplayer.play("file://" + args[2]);
299 // Timeout.add(3 * 1000, () => {
300 // zavai.audio.soundplayer.play("file:///backup/ciapino/src/openmoocow/data/moo.wav", true);
301 // Timeout.add(4 * 1000, () => {
302 // zavai.audio.soundplayer.stop();
311 // zavai.info("Shutting down")
312 zavai.registry.shutdown();