static gboolean panel_callback_handler (const gchar *name, const gchar *value, gpointer user_data, GError **error) { panel_return_val_if_fail (name != NULL, FALSE); if (strcmp (name, "--preferences") == 0 || strcmp (name, "-p") == 0) { opt_preferences = value != NULL ? MAX (0, atoi (value)) : 0; } else if (strcmp (name, "--add-items") == 0 || strcmp (name, "-a") == 0) { opt_add_items = value != NULL ? MAX (0, atoi (value)) : 0; } else { panel_assert_not_reached (); return FALSE; } return TRUE; }
gboolean panel_dbus_client_plugin_event (const gchar *plugin_event, gboolean *return_succeed, GError **error) { DBusGProxy *dbus_proxy; gboolean result = FALSE; gchar **tokens; GType type; GValue value = { 0, }; guint n_tokens; panel_return_val_if_fail (error == NULL || *error == NULL, FALSE); dbus_proxy = panel_dbus_client_get_proxy (error); if (G_UNLIKELY (dbus_proxy == NULL)) return FALSE; tokens = g_strsplit (plugin_event, ":", -1); n_tokens = g_strv_length (tokens); if (!(n_tokens == 2 || n_tokens == N_TOKENS) || exo_str_is_empty (tokens[PLUGIN_NAME]) || exo_str_is_empty (tokens[NAME])) { g_set_error_literal (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, _("Invalid plugin event syntax specified. " "Use PLUGIN-NAME:NAME[:TYPE:VALUE].")); goto out; } else if (n_tokens == 2) { /* set noop value, recognized by the dbus service as %NULL value */ g_value_init (&value, G_TYPE_UCHAR); g_value_set_uchar (&value, '\0'); } else if (n_tokens == N_TOKENS) { type = panel_dbus_client_gtype_from_string (tokens[TYPE]); if (G_LIKELY (type != G_TYPE_NONE)) { g_value_init (&value, type); if (type == G_TYPE_BOOLEAN) g_value_set_boolean (&value, strcmp (tokens[VALUE], "true") == 0); else if (type == G_TYPE_DOUBLE) g_value_set_double (&value, g_ascii_strtod (tokens[VALUE], NULL)); else if (type == G_TYPE_INT) g_value_set_int (&value, strtol (tokens[VALUE], NULL, 0)); else if (type == G_TYPE_STRING) g_value_set_static_string (&value, tokens[VALUE]); else if (type == G_TYPE_UINT) g_value_set_uint (&value, strtol (tokens[VALUE], NULL, 0)); else panel_assert_not_reached (); } else { g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, _("Invalid hint type \"%s\". Valid types " "are bool, double, int, string and uint."), tokens[TYPE]); goto out; } } else { panel_assert_not_reached (); goto out; } /* send value over dbus */ panel_return_val_if_fail (G_IS_VALUE (&value), FALSE); result = _panel_dbus_client_plugin_event (dbus_proxy, tokens[PLUGIN_NAME], tokens[NAME], &value, return_succeed, error); g_value_unset (&value); out: g_strfreev (tokens); g_object_unref (G_OBJECT (dbus_proxy)); return result; }