static gboolean
do_command (DBusConnection *connection)
{
	DBusMessage *reply;

	if (do_quit)
	{
		reply = screensaver_send_message_void (connection, "Quit", FALSE);
		goto done;
	}

	if (do_query)
	{
		DBusMessageIter iter;
		DBusMessageIter array;
		dbus_bool_t     v;

		reply = screensaver_send_message_void (connection, "GetActive", TRUE);
		if (! reply)
		{
			g_message ("Did not receive a reply from the screensaver.");
			goto done;
		}

		dbus_message_iter_init (reply, &iter);
		dbus_message_iter_get_basic (&iter, &v);
		g_print (_("The screensaver is %s\n"), v ? _("active") : _("inactive"));

		dbus_message_unref (reply);

		reply = screensaver_send_message_void (connection, "GetInhibitors", TRUE);
		if (! reply)
		{
			g_message ("Did not receive a reply from screensaver.");
			goto done;
		}

		dbus_message_iter_init (reply, &iter);
		dbus_message_iter_recurse (&iter, &array);

		if (dbus_message_iter_get_arg_type (&array) == DBUS_TYPE_INVALID)
		{
			g_print (_("The screensaver is not inhibited\n"));
		}
		else
		{
			char **inhibitors;
			int    i;
			int    num;

			g_print (_("The screensaver is being inhibited by:\n"));
			inhibitors = get_string_from_iter (&array, &num);
			for (i = 0; i < num; i++)
			{
				g_print ("\t%s\n", inhibitors[i]);
			}
			g_strfreev (inhibitors);
		}

		dbus_message_unref (reply);
	}

	if (do_time)
	{
		DBusMessageIter iter;
		dbus_bool_t     v;
		dbus_int32_t    t;

		reply = screensaver_send_message_void (connection, "GetActive", TRUE);
		if (! reply)
		{
			g_message ("Did not receive a reply from the screensaver.");
			goto done;
		}

		dbus_message_iter_init (reply, &iter);
		dbus_message_iter_get_basic (&iter, &v);
		dbus_message_unref (reply);

		if (v)
		{

			reply = screensaver_send_message_void (connection, "GetActiveTime", TRUE);
			dbus_message_iter_init (reply, &iter);
			dbus_message_iter_get_basic (&iter, &t);
			g_print (_("The screensaver has been active for %d seconds.\n"), t);

			dbus_message_unref (reply);
		}
		else
		{
			g_print (_("The screensaver is not currently active.\n"));
		}
	}

	if (do_lock)
	{
		reply = screensaver_send_message_void (connection, "Lock", FALSE);
	}

	if (do_cycle)
	{
		reply = screensaver_send_message_void (connection, "Cycle", FALSE);
	}

	if (do_poke)
	{
		reply = screensaver_send_message_void (connection, "SimulateUserActivity", FALSE);
	}

	if (do_activate)
	{
		reply = screensaver_send_message_bool (connection, "SetActive", TRUE);
		if (! reply)
		{
			g_message ("Did not receive a reply from the screensaver.");
			goto done;
		}
		dbus_message_unref (reply);
	}

	if (do_deactivate)
	{
		reply = screensaver_send_message_bool (connection, "SetActive", FALSE);
		if (! reply)
		{
			g_message ("Did not receive a reply from the screensaver.");
			goto done;
		}
		dbus_message_unref (reply);
	}

	if (do_inhibit)
	{
		reply = screensaver_send_message_inhibit (connection,
		        inhibit_application ? inhibit_application : "Unknown",
		        inhibit_reason ? inhibit_reason : "Unknown");
		if (! reply)
		{
			g_message ("Did not receive a reply from the screensaver.");
			goto done;
		}
		dbus_message_unref (reply);

		return FALSE;
	}

done:
	g_main_loop_quit (loop);

	return FALSE;
}
static gboolean
do_command (GDBusConnection *connection)
{
        GDBusMessage *reply;

        if (do_quit) {
                reply = screensaver_send_message_void (connection, "Quit", FALSE);
                goto done;
        }

        if (do_query) {
                GVariant     *body;
                gboolean      v;

                if (! screensaver_is_running (connection)) {
                        g_message ("Screensaver is not running!");
                        goto done;
                }

                reply = screensaver_send_message_void (connection, "GetActive", TRUE);
                if (reply == NULL) {
                        g_message ("Did not receive a reply from the screensaver.");
                        goto done;
                }

                body = g_dbus_message_get_body (reply);
                g_variant_get (body, "(b)", &v);
                g_object_unref (reply);

                if (v)  {
                        g_print (_("The screensaver is active\n"));
                } else {
                        g_print (_("The screensaver is inactive\n"));
                }
        }

        if (do_time) {
                GVariant *body;
                gboolean  v;
                gint32    t;

                reply = screensaver_send_message_void (connection, "GetActive", TRUE);
                if (reply == NULL) {
                        g_message ("Did not receive a reply from the screensaver.");
                        goto done;
                }

                body = g_dbus_message_get_body (reply);
                g_variant_get (body, "(b)", &v);
                g_object_unref (reply);

                if (v) {
                        reply = screensaver_send_message_void (connection, "GetActiveTime", TRUE);
                        if (reply == NULL) {
                                g_message ("Did not receive a reply from the screensaver.");
                                goto done;
                        }

                        body = g_dbus_message_get_body (reply);
                        g_variant_get (body, "(u)", &t);
                        g_object_unref (reply);

                        g_print (ngettext ("The screensaver has been active for %d second.\n", "The screensaver has been active for %d seconds.\n", t), t);
                } else {
                        g_print (_("The screensaver is not currently active.\n"));
                }
        }

        if (do_lock) {
				if (g_strcmp0 (away_message, "DEFAULT") == 0) {
					reply = screensaver_send_message_string (connection, "Lock", away_message);
				}
				else {
					gchar * custom_message = g_strdup_printf("CUSTOM###%s", away_message);
					reply = screensaver_send_message_string (connection, "Lock", custom_message);
					g_free (custom_message);
				}
                if (reply == NULL) {
                        g_message ("Did not receive a reply from the screensaver.");
                        goto done;
                }
                g_object_unref (reply);
        }

        if (do_activate) {
                reply = screensaver_send_message_bool (connection, "SetActive", TRUE);
                if (reply == NULL) {
                        g_message ("Did not receive a reply from the screensaver.");
                        goto done;
                }
                g_object_unref (reply);
        }

        if (do_deactivate) {
                reply = screensaver_send_message_bool (connection, "SetActive", FALSE);
                if (reply == NULL) {
                        g_message ("Did not receive a reply from the screensaver.");
                        goto done;
                }
                g_object_unref (reply);
        }

 done:
        g_main_loop_quit (loop);
        return FALSE;
}