int main(int argc, char **argv) { guint owner_id = 0, timeout_id = 0; int ret = 1; if (argc > 1) { g_printerr("No options supported\n"); return 1; } systemd_proxy = get_bus_proxy(SYSTEMD_NAME, SYSTEMD_PATH, SYSTEMD_MANAGER_INTERFACE); if (!systemd_proxy) goto error; polkit_proxy = get_bus_proxy(POLKIT_NAME, POLKIT_PATH, POLKIT_INTERFACE); if (!polkit_proxy) goto error; owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, TIMEDATED_NAME, G_BUS_NAME_OWNER_FLAGS_REPLACE, register_object, NULL, NULL, NULL, NULL); read_ntp_units(); main_quit = FALSE; /* This is the main loop. Quit when idle for QUIT_TIMEOUT seconds. */ while (!main_quit) { /* Add timeout when not waiting for an authorization check */ if (!running_auth_checks) timeout_id = g_timeout_add(QUIT_TIMEOUT * 1000, stop_main_loop, NULL); g_main_context_iteration(g_main_context_default(), TRUE); if (timeout_id) g_source_remove(timeout_id); timeout_id = 0; } ret = 0; error: if (owner_id) g_bus_unown_name(owner_id); if (polkit_proxy) g_object_unref(polkit_proxy); if (systemd_proxy) g_object_unref(systemd_proxy); free_ntp_units(); return ret; }
static gboolean bus_register (DBusGConnection *bus) { DBusGProxy *bus_proxy; gboolean ret; mate_settings_profile_start (NULL); ret = FALSE; bus_proxy = get_bus_proxy (bus); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object"); goto out; } ret = acquire_name_on_proxy (bus_proxy); g_object_unref (bus_proxy); if (!ret) { g_warning ("Could not acquire name"); goto out; } g_debug ("Successfully connected to D-Bus"); out: mate_settings_profile_end (NULL); return ret; }
int main (int argc, char **argv) { GMainLoop *loop; GsdDatetimeMechanism *mechanism; DBusGProxy *bus_proxy; DBusGConnection *connection; int ret; ret = 1; if (! g_thread_supported ()) { g_thread_init (NULL); } dbus_g_thread_init (); g_type_init (); connection = get_system_bus (); if (connection == NULL) { goto out; } bus_proxy = get_bus_proxy (connection); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object; bailing out"); goto out; } if (!acquire_name_on_proxy (bus_proxy) ) { g_warning ("Could not acquire name; bailing out"); goto out; } mechanism = gsd_datetime_mechanism_new (); if (mechanism == NULL) { goto out; } loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (mechanism); g_main_loop_unref (loop); ret = 0; out: return ret; }
static GVariant *get_object_property(const gchar *name, const gchar *path, const gchar *interface, const gchar *property) { GDBusProxy *proxy; GVariant *ret; proxy = get_bus_proxy(name, path, interface); if (!proxy) return NULL; ret = g_dbus_proxy_get_cached_property(proxy, property); g_object_unref(proxy); return ret; }
int main (int argc, char **argv) { GMainLoop *main_loop; DBusGConnection *connection; DBusGProxy *bus_proxy; g_type_init (); connection = get_system_bus (); if (connection == NULL) { goto out; } bus_proxy = get_bus_proxy (connection); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object; bailing out"); goto out; } if (! acquire_name_on_proxy (bus_proxy) ) { g_warning ("Could not acquire name; bailing out"); goto out; } settings = gdm_settings_new (); if (settings == NULL) { g_warning ("Unable to initialize settings"); exit (1); } main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); g_main_loop_unref (main_loop); g_object_unref (settings); out: return 0; }
int main (int argc, char **argv) { GMainLoop *loop; GConfDefaults *mechanism; DBusGProxy *bus_proxy; DBusGConnection *connection; int ret; GOptionContext *options; GError *error = NULL; ret = 1; if (! g_thread_supported ()) { g_thread_init (NULL); } dbus_g_thread_init (); options = g_option_context_new (NULL); g_option_context_add_main_entries (options, entries, NULL); if (!g_option_context_parse (options, &argc, &argv, &error)) { g_warning ("Failed to parse options: %s\n", error->message); g_error_free (error); } g_option_context_free (options); g_log_set_default_handler (log_default_handler, NULL); if (debug) { log_levels = log_levels | G_LOG_LEVEL_DEBUG; } connection = get_system_bus (); if (connection == NULL) { g_warning ("Could not get system bus connection; bailing out"); goto out; } bus_proxy = get_bus_proxy (connection); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object; bailing out"); goto out; } mechanism = gconf_defaults_new (); if (mechanism == NULL) { goto out; } if (!acquire_name_on_proxy (bus_proxy)) { g_warning ("Could not acquire name; bailing out"); goto out; } loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (mechanism); g_main_loop_unref (loop); ret = 0; out: return ret; }
int main (int argc, char **argv) { gboolean arg_version = FALSE; gboolean arg_display_properties = FALSE; gboolean arg_display_about = FALSE; gboolean arg_consider_new_mail_as_read = FALSE; gboolean arg_update = FALSE; gboolean arg_print_summary = FALSE; gboolean arg_unset_obsolete_configuration = FALSE; gboolean arg_quit = FALSE; const GOptionEntry options[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &arg_version, N_("Show version information"), NULL }, { "enable-info", 'i', 0, G_OPTION_ARG_NONE, &arg_enable_info, N_("Enable informational output"), NULL }, { "display-properties", 'p', 0, G_OPTION_ARG_NONE, &arg_display_properties, N_("Display the properties dialog"), NULL }, { "display-about", 'a', 0, G_OPTION_ARG_NONE, &arg_display_about, N_("Display the about dialog"), NULL }, { "consider-new-mail-as-read", 'r', 0, G_OPTION_ARG_NONE, &arg_consider_new_mail_as_read, N_("Consider new mail as read"), NULL }, { "update", 'u', 0, G_OPTION_ARG_NONE, &arg_update, N_("Update the mail status"), NULL }, { "print-summary", 's', 0, G_OPTION_ARG_NONE, &arg_print_summary, N_("Print a XML mail summary"), NULL }, { "unset-obsolete-configuration", '\0', 0, G_OPTION_ARG_NONE, &arg_unset_obsolete_configuration, N_("Unset obsolete GConf configuration"), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &arg_quit, N_("Quit Mail Notification"), NULL }, { NULL } }; GOptionContext *option_context; DBusGConnection *bus; DBusGProxy *bus_proxy; g_log_set_fatal_mask(NULL, G_LOG_LEVEL_CRITICAL); g_log_set_handler(NULL, G_LOG_LEVEL_INFO, info_log_cb, NULL); #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif g_set_application_name(_("Mail Notification")); g_thread_init(NULL); if (! g_thread_supported()) /* * We cannot use mn_fatal_error_dialog() because gtk_init() has * not been called yet. */ g_critical(_("multi-threading is not available")); gdk_threads_init(); GDK_THREADS_ENTER(); option_context = g_option_context_new(NULL); g_option_context_add_main_entries(option_context, options, GETTEXT_PACKAGE); gnome_program_init(PACKAGE, VERSION, LIBGNOME_MODULE, argc, argv, GNOME_PARAM_HUMAN_READABLE_NAME, _("Mail Notification"), GNOME_PROGRAM_STANDARD_PROPERTIES, GNOME_PARAM_GOPTION_CONTEXT, option_context, NULL); gtk_init(&argc, &argv); if (arg_version) { print_version(); goto end; } if (arg_unset_obsolete_configuration) { mn_conf_unset_obsolete(); goto end; } ensure_icon_path(); gtk_window_set_default_icon_name("mail-notification"); mn_stock_init(); bus = connect_to_session_bus(); bus_proxy = get_bus_proxy(bus); if (mn_server_start(bus, bus_proxy)) /* not already running */ { if (arg_quit) g_message(_("Mail Notification is not running")); else { mn_mailbox_init_types(); #if WITH_MBOX || WITH_MOZILLA || WITH_MH || WITH_MAILDIR || WITH_SYLPHEED mn_vfs_mailbox_init_types(); #endif /* mn-client-session uses sockets, we don't want to die on SIGPIPE */ signal(SIGPIPE, SIG_IGN); if (! gnome_vfs_init()) mn_show_fatal_error_dialog(NULL, _("Unable to initialize the GnomeVFS library.")); #if !GTK_CHECK_VERSION(3,0,0) gnome_authentication_manager_init(); #endif /* must be called before init_gmime() */ mn_conf_init(); #if WITH_GMIME init_gmime(); #endif if (! notify_init(_("Mail Notification"))) mn_show_error_dialog(NULL, _("An initialization error has occurred in Mail Notification"), _("Unable to initialize the notification library. Message popups will not be displayed.")); /* * Work around * http://bugzilla.gnome.org/show_bug.cgi?id=64764: * initialize the classes we will be using concurrently * before any thread is created. */ init_classes(); mn_shell_new(bus, bus_proxy); /* also display the properties dialog if there are no mailboxes */ if (! mn_shell->mailboxes->list) arg_display_properties = TRUE; if (arg_display_properties) mn_shell_show_properties_dialog(mn_shell, 0); if (arg_display_about) mn_shell_show_about_dialog(mn_shell, 0); if (arg_consider_new_mail_as_read) report_option_ignored("--consider-new-mail-as-read"); if (arg_update) report_option_ignored("--update"); if (arg_print_summary) report_option_ignored("--print-summary"); /* in case no window has been displayed */ gdk_notify_startup_complete(); gtk_main(); } } else /* already running */ { DBusGProxy *proxy; GError *err = NULL; proxy = dbus_g_proxy_new_for_name(bus, MN_SERVER_SERVICE, MN_SERVER_PATH, MN_SERVER_INTERFACE); if (arg_quit) { g_message(_("quitting Mail Notification")); CALL_SERVER(org_gnome_MailNotification_quit(proxy, &err)); } else { /* also display the properties dialog if there are no mailboxes */ if (! arg_display_properties) { gboolean has; CALL_SERVER(org_gnome_MailNotification_has_mailboxes(proxy, &has, &err)); arg_display_properties = ! has; } if (arg_display_properties) CALL_SERVER(org_gnome_MailNotification_display_properties(proxy, &err)); if (arg_display_about) CALL_SERVER(org_gnome_MailNotification_display_about(proxy, &err)); if (arg_consider_new_mail_as_read) { g_message(_("considering new mail as read")); CALL_SERVER(org_gnome_MailNotification_consider_new_mail_as_read(proxy, &err)); } if (arg_update) { g_message(_("updating the mail status")); CALL_SERVER(org_gnome_MailNotification_update(proxy, &err)); } if (arg_print_summary) { char *summary; CALL_SERVER(org_gnome_MailNotification_get_summary(proxy, &summary, &err)); g_print("%s", summary); g_free(summary); } if (! (arg_display_properties || arg_display_about || arg_consider_new_mail_as_read || arg_update || arg_print_summary)) g_message(_("Mail Notification is already running")); } /* * Do not unref the proxy, since it might break when the * DBusGProxy memory management issue is fixed * (https://bugs.freedesktop.org/show_bug.cgi?id=14030). */ /* no window has been displayed by this process */ gdk_notify_startup_complete(); } end: GDK_THREADS_LEAVE(); return 0; }