/*
* zavai - simple interface to the OpenMoko (or to the FSO stack)
*
- * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
+ * Copyright (C) 2009--2010 Enrico Zini <enrico@enricozini.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
using GLib;
//string VERSION = "0.1";
+static string pidfilename;
+
+static Posix.pid_t is_running()
+{
+ string pidfile = zavai.config.homedir + "/" + pidfilename + ".pid";
+ string contents;
+ try {
+ if (!FileUtils.get_contents(pidfile, out contents))
+ return 0;
+ } catch (FileError e) {
+ return 0;
+ }
+ int val = contents.to_int();
+ string procdir = "/proc/%d".printf(val);
+ if (FileUtils.test(procdir, FileTest.IS_DIR))
+ return (Posix.pid_t)val;
+ else
+ return 0;
+}
+
+static void make_pidfile()
+{
+ string pidfile = zavai.config.homedir + "/" + pidfilename + ".pid";
+ try {
+ FileUtils.set_contents(pidfile, "%d".printf(Posix.getpid()));
+ } catch (FileError e) {
+ zavai.log.error("Cannot create pidfile " + pidfile + ": " + e.message);
+ }
+}
+
+static void on_kill(int sig)
+{
+ Gtk.main_quit();
+}
+
static int main (string[] args) {
- Gtk.init (ref args);
-
- // parser = Parser(usage="usage: %prog [options]",
- // version="%prog "+ VERSION,
- // description="Simple interactive interface for the OpenMoko")
- // parser.add_option("-v", "--verbose", action="store_true", help="verbose mode")
- //
- // (opts, args) = parser.parse_args()
- //
+ bool opt_popup = false;
+ bool opt_calendar = false;
+ GLib.OptionEntry[] entries = new GLib.OptionEntry[] {
+ OptionEntry() {
+ long_name = "popup",
+ short_name = 'p',
+ flags = 0,
+ arg = OptionArg.NONE,
+ arg_data = &opt_popup,
+ description = "run as a popup at the specified location on screen",
+ arg_description = null },
+ OptionEntry() {
+ long_name = "calendar",
+ short_name = 0,
+ flags = 0,
+ arg = OptionArg.NONE,
+ arg_data = &opt_calendar,
+ description = "run as calendar only",
+ arg_description = null },
+ OptionEntry()
+ };
+ try {
+ Gtk.init_with_args(ref args, "", entries, null);
+ } catch (Error e) {
+ zavai.log.error("Cannot init gtk: " + e.message);
+ return 1;
+ }
+ Gst.init (ref args);
+
+ pidfilename = "zavai";
+
// if not opts.verbose:
// zavai.set_quiet()
- //
- // # Read configuration
- // zavai.info("Loading configuration")
- // conf = zavai.Config()
// Set up zavai
// Core infrastructure
zavai.config = new zavai.Config();
zavai.config.argv0 = args[0];
+
+ if (opt_calendar)
+ {
+ pidfilename = "calendar";
+
+ // User interface
+ var calendar = new zavai.widgets.Calendar();
+
+ Gtk.Window win = new Gtk.Window(Gtk.WindowType.TOPLEVEL);
+ if (opt_popup)
+ {
+ Posix.pid_t pid = is_running();
+ if (pid != 0)
+ {
+ // Kill a running calendar
+ Posix.kill(pid, Posix.SIGINT);
+ FileUtils.unlink(zavai.config.homedir + "/" + pidfilename + ".pid");
+ return 0;
+ }
+
+ make_pidfile();
+
+ win.set_decorated(false);
+ //win.set_resizable(false);
+ win.set_border_width(5);
+ win.set_skip_taskbar_hint(true);
+ win.set_skip_pager_hint(true);
+ // gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DOCK);
+ win.set_position(Gtk.WindowPosition.MOUSE);
+ win.stick();
+ }
+
+ win.title = "Zavai calendar";
+ win.destroy += Gtk.main_quit;
+ win.add(calendar);
+ win.set_size_request(300, 500);
+ win.show_all();
+ win.show();
+
+ // Shutdown the main loop on SIGINT
+ Posix.signal(Posix.SIGINT, on_kill);
+ Posix.signal(Posix.SIGTERM, on_kill);
+
+ Gtk.main();
+
+ calendar.flush();
+
+ return 0;
+ }
+
+
zavai.registry = new zavai.Registry();
zavai.main.init();
// Additional infrastructure
zavai.input.init();
zavai.uevent.init();
+ zavai.power.init();
zavai.gps.init();
zavai.gsm.init();
- zavai.audio.init();
zavai.clock.init();
+ zavai.audio.init();
+ zavai.log.init();
+ zavai.wifi.init();
+ zavai.bluetooth.init();
/*
zavai.clock.clock.schedule(new zavai.clock.Alarm(123456, "Second"));
*/
// User interface
+ zavai.ui.music.init();
zavai.ui.main.init();
+ zavai.ui.notify.init();
zavai.ui.gps.init();
zavai.ui.gsm.init();
- zavai.app.run_script(zavai.config.homedir + "/display init");
+ zavai.config.find_and_run_script("display", "init");
zavai.ui.power.init();
+ zavai.ui.aux.init();
zavai.ui.kbd.init();
zavai.ui.wm.init();
zavai.ui.calendar.init();
+ zavai.ui.alarm.init();
+ zavai.ui.wifi.init();
+ zavai.ui.bluetooth.init();
+ zavai.ui.logview.init();
zavai.ui.debug.init();
//zavai.app.show_applet("menu.main");
*/
zavai.app.run();
+
+ if (args.length > 1 && args[1] == "alarm")
+ {
+ zavai.clock.AlarmTriggerInfo alarm = new zavai.clock.AlarmTriggerInfo("Prova");
+ zavai.clock.alarm_trigger_queue.enqueue_trigger(alarm);
+ }
+
+ if (args.length > 2 && args[1] == "showlog")
+ {
+ zavai.log.log.list_entries((d, f) => {
+ stderr.printf("FALSE %s %s\n", d, f);
+ return true;
+ }, false);
+ zavai.log.log.list_entries((d, f) => {
+ stderr.printf("TRUE %s %s\n", d, f);
+ return true;
+ }, true);
+ zavai.log.Log l = zavai.log.log.load(args[2]);
+ l.dump();
+ return 0;
+ }
+
+ if (args.length > 2 && args[1] == "play")
+ {
+ zavai.audio.musicplayer.play("file://" + args[2]);
+
+ // Timeout.add(3 * 1000, () => {
+ // zavai.audio.soundplayer.play("file:///backup/ciapino/src/openmoocow/data/moo.wav", true);
+ // Timeout.add(4 * 1000, () => {
+ // zavai.audio.soundplayer.stop();
+ // return false;
+ // });
+ // return false;
+ // });
+ }
+
Gtk.main();
// zavai.info("Shutting down")