]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/zavai-calendar.vala
Debugging
[gregoa/zavai.git] / src / zavai-calendar.vala
index 17bcfde178c4a9635f087cec84d5e3d6618cf118..5d34139fd11f470b3c43c4389402a284787de40f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * zavai - simple interface to the OpenMoko (or to the FSO stack)
+ * zavai-calendar - simple calendar tool
  *
  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
  *
@@ -22,8 +22,49 @@ using GLib;
 
 //string VERSION = "0.1";
 
+static Posix.pid_t is_running()
+{
+       string pidfile = zavai.config.homedir + "/calendar.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 + "/calendar.pid";
+       FileUtils.set_contents(pidfile, "%d".printf(Posix.getpid()));
+}
+
+static void on_kill(int sig)
+{
+       Gtk.main_quit();
+}
+
 static int main (string[] args) {
-       Gtk.init (ref args);
+       bool opt_popup = 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()
+       };
+        Gtk.init_with_args(ref args, "", entries, null);
 
        // parser = Parser(usage="usage: %prog [options]",
        //                 version="%prog "+ VERSION,
@@ -41,44 +82,50 @@ static int main (string[] args) {
 
        // Set up zavai
 
-    // Core infrastructure
+       // Core infrastructure
        zavai.config = new zavai.Config();
 
        // User interface
        var calendar = new zavai.widgets.Calendar();
 
-       // # Shutdown the main loop on SIGINT
-       // def on_kill(signum, frame):
-       //     gtk.main_quit()
-       // signal.signal(signal.SIGINT, on_kill)
-       // signal.signal(signal.SIGTERM, on_kill)
+       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 + "/calendar.pid");
+                       return 0;
+               }
 
-       // zavai.info("Starting")
-       // app = registry.resource("app")
-       // app.connect("destroy", gtk.main_quit)
-       // app.run()
+               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);
 
-/*
-       dynamic DBus.Object otime = zavai.registry.sbus.get_object(
-                       "org.freesmartphone.otimed",
-                       "/org/freesmartphone/Time/Alarm",
-                       "org.freesmartphone.Time.Alarm");
-
-       otime.ClearAlarm();
-       otime.SetAlarm(time_t() + 10);
-
-       dynamic DBus.Object notification = zavai.registry.sbus.get_object(
-                       "org.freesmartphone",
-                       "org/freesmartphone/Notification",
-                       "org.freesmartphone.Notification");
-       notification.Alarm += on_alarm;
-*/
-
-       //zavai.app.run();
        Gtk.main();
 
-       // zavai.info("Shutting down")
-       //zavai.registry.shutdown();
+       calendar.flush();
 
        return 0;
 }