~unity-team/unity-lens-sample/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * BEGIN LICENSE
 * This file is in the public domain
 * END LICENSE
 */

using Config;

namespace Unity.SampleLens {

  static Daemon? daemon = null;
  static MainLoop? mainloop = null;

  public static int main (string[] args)
    {
      /* Set up necesities for i18n */
      GLib.Intl.textdomain (Config.PACKAGE);
      GLib.Intl.bindtextdomain (Config.PACKAGE, Config.LOCALEDIR);
      GLib.Intl.bind_textdomain_codeset (Config.PACKAGE, "UTF-8");
      GLib.Intl.setlocale(GLib.LocaleCategory.ALL, "");
    
      DesktopAppInfo.set_desktop_env ("Unity");

      /* Export the lens daemon on the session bus - as everywhere else
       * these values should match those definedd in the .lens file */
      Bus.own_name (BusType.SESSION, "com.canonical.Unity.SampleLens",
                    BusNameOwnerFlags.NONE,
                    on_bus_acquired, on_name_acquired, on_name_lost);
      
      mainloop = new MainLoop ();
      mainloop.run ();

      return 0;
    }
  
  private static void on_bus_acquired (DBusConnection conn, string name)
  {
    debug ("Connected to session bus - checking for existing instances...");
    
    /* We need to set up our DBus objects *before* we know if we've acquired
     * the name. This is a bit unfortunate because it means we might do work
     * for no reason if another daemon is already running. See
     * https://bugzilla.gnome.org/show_bug.cgi?id=640714 */
    daemon = new Daemon ();
  }
  
  private static void on_name_acquired (DBusConnection conn, string name)
  {
    debug ("Acquired name %s. We're the main instance.\nAll system are go.",
           name);
  }
  
  private static void on_name_lost (DBusConnection conn, string name)
  {
    debug ("Another daemon is running.\nBailing out.");
    mainloop.quit ();
  }
  
} /* End namespace Unity.SampleLens */