/** * gpm_inhibit_applet_init: * @applet: Inhibit applet instance **/ static void gpm_inhibit_applet_init (GpmInhibitApplet *applet) { DBusGConnection *connection; /* initialize fields */ applet->size = 0; applet->icon = NULL; applet->cookie = 0; applet->connection = NULL; applet->proxy = NULL; /* Add application specific icons to search path */ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), GPM_DATA G_DIR_SEPARATOR_S "icons"); applet->monitor = egg_dbus_monitor_new (); g_signal_connect (applet->monitor, "connection-changed", G_CALLBACK (monitor_connection_cb), applet); connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); egg_dbus_monitor_assign (applet->monitor, connection, GS_DBUS_SERVICE); gpm_inhibit_applet_dbus_connect (applet); /* prepare */ mate_panel_applet_set_flags (MATE_PANEL_APPLET (applet), MATE_PANEL_APPLET_EXPAND_MINOR); /* show */ gtk_widget_show_all (GTK_WIDGET(applet)); /* set appropriate size and load icon accordingly */ gpm_applet_draw_cb (applet); /* connect */ g_signal_connect (G_OBJECT(applet), "button-press-event", G_CALLBACK(gpm_applet_click_cb), NULL); #if GTK_CHECK_VERSION (3, 0, 0) g_signal_connect (G_OBJECT(applet), "draw", G_CALLBACK(gpm_applet_draw_cb), NULL); #else g_signal_connect (G_OBJECT(applet), "expose-event", G_CALLBACK(gpm_applet_draw_cb), NULL); #endif /* We use g_signal_connect_after because letting the panel draw * the background is the only way to have the correct * background when a theme defines a background picture. */ g_signal_connect_after (G_OBJECT(applet), "expose-event", G_CALLBACK(gpm_applet_draw_cb), NULL); g_signal_connect (G_OBJECT(applet), "change-background", G_CALLBACK(gpm_applet_change_background_cb), NULL); g_signal_connect (G_OBJECT(applet), "change-orient", G_CALLBACK(gpm_applet_draw_cb), NULL); g_signal_connect (G_OBJECT(applet), "destroy", G_CALLBACK(gpm_applet_destroy_cb), NULL); }
/** * main: **/ int main (int argc, char *argv[]) { DBusGConnection *system_connection; EggDbusMonitor *monitor; gboolean ret; gboolean disable_timer = FALSE; gboolean version = FALSE; gboolean use_daemon = FALSE; gboolean timed_exit = FALSE; gboolean immediate_exit = FALSE; gboolean do_logging = FALSE; gchar *backend_name = NULL; PkEngine *engine = NULL; PkBackend *backend = NULL; PkConf *conf = NULL; PkSyslog *syslog = NULL; GError *error = NULL; GOptionContext *context; const GOptionEntry options[] = { { "backend", '\0', 0, G_OPTION_ARG_STRING, &backend_name, /* TRANSLATORS: a backend is the system package tool, e.g. yum, apt */ _("Packaging backend to use, e.g. dummy"), NULL }, { "daemonize", '\0', 0, G_OPTION_ARG_NONE, &use_daemon, /* TRANSLATORS: if we should run in the background */ _("Daemonize and detach from the terminal"), NULL }, { "disable-timer", '\0', 0, G_OPTION_ARG_NONE, &disable_timer, /* TRANSLATORS: if we should not monitor how long we are inactive for */ _("Disable the idle timer"), NULL }, { "version", '\0', 0, G_OPTION_ARG_NONE, &version, /* TRANSLATORS: show version */ _("Show version and exit"), NULL }, { "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit, /* TRANSLATORS: exit after we've started up, used for user profiling */ _("Exit after a small delay"), NULL }, { "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit, /* TRANSLATORS: exit straight away, used for automatic profiling */ _("Exit after the engine has loaded"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); dbus_g_thread_init (); g_type_init (); /* TRANSLATORS: describing the service that is running */ context = g_option_context_new (_("PackageKit service")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); if (version) { g_print ("Version %s\n", VERSION); goto exit_program; } /* check if an instance is already running */ monitor = egg_dbus_monitor_new (); egg_dbus_monitor_assign (monitor, EGG_DBUS_MONITOR_SYSTEM, PK_DBUS_SERVICE); ret = egg_dbus_monitor_is_connected (monitor); g_object_unref (monitor); if (ret) { g_print ("Already running service which provides %s\n", PK_DBUS_SERVICE); goto exit_program; } /* do stuff on ctrl-c */ signal (SIGINT, pk_main_sigint_handler); /* we need to daemonize before we get a system connection */ if (use_daemon && daemon (0, 0)) { g_print ("Could not daemonize: %s\n", g_strerror (errno)); goto exit_program; } /* don't let GIO start it's own session bus: http://bugzilla.gnome.org/show_bug.cgi?id=526454 */ setenv ("GIO_USE_VFS", "local", 1); /* check dbus connections, exit if not valid */ system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error) { /* TRANSLATORS: fatal error, dbus is not running */ g_print ("%s: %s\n", _("Cannot connect to the system bus"), error->message); g_error_free (error); goto exit_program; } /* we don't actually need to do this, except it rules out the * 'it works from the command line but not service activation' bugs */ #ifdef HAVE_CLEARENV clearenv (); #endif /* get values from the config file */ conf = pk_conf_new (); /* log the startup */ syslog = pk_syslog_new (); pk_syslog_add (syslog, PK_SYSLOG_TYPE_INFO, "daemon start"); /* do we log? */ do_logging = pk_conf_get_bool (conf, "TransactionLogging"); egg_debug ("Log all transactions: %i", do_logging); if (do_logging) egg_debug_set_log_filename ("/var/log/PackageKit"); /* after how long do we timeout? */ exit_idle_time = pk_conf_get_int (conf, "ShutdownTimeout"); egg_debug ("daemon shutdown set to %i seconds", exit_idle_time); if (backend_name == NULL) { backend_name = pk_conf_get_string (conf, "DefaultBackend"); egg_debug ("using default backend %s", backend_name); } /* load our chosen backend */ backend = pk_backend_new (); ret = pk_backend_set_name (backend, backend_name); g_free (backend_name); /* all okay? */ if (!ret) egg_error ("cannot continue, backend invalid"); loop = g_main_loop_new (NULL, FALSE); /* create a new engine object */ engine = pk_engine_new (); g_signal_connect (engine, "quit", G_CALLBACK (pk_main_quit_cb), loop); if (!pk_object_register (system_connection, G_OBJECT (engine), &error)) { /* TRANSLATORS: cannot register on system bus, unknown reason -- geeky error follows */ g_print ("%s %s\n", _("Error trying to start:"), error->message); g_error_free (error); goto out; } /* Only timeout and close the mainloop if we have specified it * on the command line */ if (timed_exit) g_timeout_add_seconds (20, (GSourceFunc) timed_exit_cb, loop); /* only poll every 10 seconds when we are alive */ if (exit_idle_time != 0 && !disable_timer) g_timeout_add_seconds (5, (GSourceFunc) pk_main_timeout_check_cb, engine); /* immediatly exit */ if (immediate_exit) g_timeout_add (50, (GSourceFunc) timed_exit_cb, loop); /* run until quit */ g_main_loop_run (loop); out: /* log the shutdown */ pk_syslog_add (syslog, PK_SYSLOG_TYPE_INFO, "daemon quit"); g_main_loop_unref (loop); g_object_unref (syslog); g_object_unref (conf); g_object_unref (engine); g_object_unref (backend); exit_program: return 0; }