Back to index

indicator-session  12.10.0
session-service.c
Go to the documentation of this file.
00001 /*
00002 A small wrapper utility to load indicators and put them as menu items
00003 into the gnome-panel using it's applet interface.
00004 
00005 Copyright 2009 Canonical Ltd.
00006 
00007 Authors:
00008     Ted Gould <ted@canonical.com>
00009     Christoph Korn <c_korn@gmx.de>
00010     Cody Russell <crussell@canonical.com>
00011     Conor Curran <conor.curran@canonical.com>
00012     Charles Kerr <charles.kerr@canonical.com>
00013 
00014 This program is free software: you can redistribute it and/or modify it
00015 under the terms of the GNU General Public License version 3, as published
00016 by the Free Software Foundation.
00017 
00018 This program is distributed in the hope that it will be useful, but
00019 WITHOUT ANY WARRANTY; without even the implied warranties of
00020 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
00021 PURPOSE.  See the GNU General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License along
00024 with this program.  If not, see <http://www.gnu.org/licenses/>.
00025 */
00026 
00027 #include "config.h"
00028 
00029 #include <unistd.h>
00030 #include <locale.h>
00031 
00032 #include <glib/gi18n.h>
00033 #include <gio/gio.h>
00034 #include <gio/gdesktopappinfo.h>
00035 
00036 #include <libdbusmenu-glib/server.h>
00037 
00038 #include <gtk/gtk.h>
00039 
00040 #include <libindicator/indicator-service.h>
00041 
00042 #include "session-dbus.h"
00043 #include "session-menu-mgr.h"
00044 #include "shared-names.h"
00045 #include "users-service-dbus.h"
00046 
00047 static SessionDbus * session_dbus = NULL;
00048 static GMainLoop * mainloop = NULL;
00049 
00050 
00051 /* When the service interface starts to shutdown,
00052    we should follow it. */
00053 void
00054 service_shutdown (IndicatorService * service, gpointer user_data)
00055 {
00056   if (mainloop != NULL)
00057     {
00058       g_debug ("Service shutdown");
00059       g_main_loop_quit (mainloop);
00060     }
00061 }
00062 
00063 static inline gboolean
00064 is_greeter_mode (void)
00065 {
00066   return !g_strcmp0 (g_getenv ("INDICATOR_GREETER_MODE"), "1");
00067 }
00068 
00069 /* Main, is well, main.  It brings everything up and throws
00070    us into the mainloop of no return. */
00071 int
00072 main (int argc, char ** argv)
00073 {
00074   g_type_init();
00075 
00076   /* Setting up i18n and gettext.
00077      Apparently we need all of these. */
00078   setlocale (LC_ALL, "");
00079   bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
00080   textdomain (GETTEXT_PACKAGE);
00081 
00082   IndicatorService * service = indicator_service_new_version (INDICATOR_SESSION_DBUS_NAME,
00083                                                             INDICATOR_SESSION_DBUS_VERSION);
00084   g_signal_connect (G_OBJECT(service), INDICATOR_SERVICE_SIGNAL_SHUTDOWN,
00085                     G_CALLBACK(service_shutdown), NULL);
00086 
00087   session_dbus = session_dbus_new();
00088 
00089   SessionMenuMgr * menu_mgr = session_menu_mgr_new (session_dbus, is_greeter_mode());
00090   DbusmenuServer* server = dbusmenu_server_new (INDICATOR_SESSION_DBUS_OBJECT);
00091   dbusmenu_server_set_root (server, session_menu_mgr_get_menu (menu_mgr));
00092 
00093   mainloop = g_main_loop_new(NULL, FALSE);
00094   g_main_loop_run(mainloop);
00095 
00096   return 0;
00097 }
00098