~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
60
61
62
/*
 * Copyright (C) 2010 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 *
 */

using DBus;
using Config;

namespace Unity.SamplePlace {

  public static int main (string[] args)
    {
      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 ("GNOME");
    
      var daemon = new Daemon ();

      /* Export the place daemon on the session bus - as everywhere else
       * these values should match those definedd in the .place file */
      try {
        var conn = DBus.Bus.get (DBus.BusType.SESSION);
        dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
                                                   "/org/freedesktop/DBus",
                                                   "org.freedesktop.DBus");

        uint request_name_result = bus.request_name ("com.canonical.Unity.SamplePlace", (uint) 0);
        if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER)
          {
            debug ("Running sample place daemon.");
            new MainLoop (null, false).run();
          }
        else
          {
            print (_("Another Sample Place daemon appears to be running.\nBailing out."));
            return 1;
          }
      } catch (DBus.Error error) {
        print (_("Error connecting to session bus: %s.\nBailing out."), error.message);
        return 2;
      }

      return 0;
    }
} /* End namespace Unity.SamplePlace */