Пример #1
0
int
purple_blist_node_get_int(PurpleBlistNode* node, const char *key)
{
	GValue *value;
	PurpleBlistNodePrivate *priv = PURPLE_BLIST_NODE_GET_PRIVATE(node);

	g_return_val_if_fail(priv != NULL, 0);
	g_return_val_if_fail(priv->settings != NULL, 0);
	g_return_val_if_fail(key != NULL, 0);

	value = g_hash_table_lookup(priv->settings, key);

	if (value == NULL)
		return 0;

	g_return_val_if_fail(G_VALUE_HOLDS_INT(value), 0);

	return g_value_get_int(value);
}
Пример #2
0
/*
 * settings_enum_get_mapping:
 * @value: value for the object property, initialized to hold the proper type
 * @settings_variant: value of the setting as a #GVariant
 * @enum_values: an array of strings with %NULL as a sentinel at the end.
 *
 * Custom mapping function for setting combo boxes from enum GSettings keys.
 *
 * Returns: %TRUE if the conversion succeeded, %FALSE otherwise.
 */
gboolean
settings_enum_get_mapping(GValue *value, GVariant *settings_variant, char **enum_values)
{
	const char *settings_string = g_variant_get_string(settings_variant, NULL);
	int count;
	char **ptr;

	g_assert(G_VALUE_HOLDS_INT(value));

	for(count = 0, ptr = enum_values; *ptr; count++, ptr++) {
		if(strcmp(*ptr, settings_string) == 0)
			break;
	}
	if(*ptr == NULL)
		return FALSE;

	g_value_set_int(value, count);
	return TRUE;
}
Пример #3
0
/* This function really ought not to be part of Amanda. In my (Ian's) opinion,
   serialization and deserialization should be a part of the GValue
   interface. But it's not, and here we are. */
gboolean g_value_set_from_string(GValue * val, char * string) {
    g_return_val_if_fail(val != NULL, FALSE);
    g_return_val_if_fail(G_IS_VALUE(val), FALSE);

    if (G_VALUE_HOLDS_BOOLEAN(val)) {
        return g_value_set_boolean_from_string(val, string);
    } else if (G_VALUE_HOLDS_INT(val)) {
        return g_value_set_int_from_string(val, string);
    } else if (G_VALUE_HOLDS_UINT(val)) {
        return g_value_set_uint_from_string(val, string);
    } else if (G_VALUE_HOLDS_UINT64(val)) {
        return g_value_set_uint64_from_string(val, string);
    } else if (G_VALUE_HOLDS_STRING(val)) {
        g_value_set_string(val, string);
        return TRUE;
    } else if (G_VALUE_HOLDS_FLAGS(val)) {
        return g_value_set_flags_from_string(val, string);
    }

    return TRUE;
}
Пример #4
0
static void
print_value (GValue *value)
{
	if (G_VALUE_HOLDS_STRING (value))
		printf ("%s", g_value_get_string (value));
	else if (G_VALUE_HOLDS_INT (value))
		printf ("%d", g_value_get_int (value));
	else if (G_VALUE_HOLDS_DOUBLE (value))
		printf ("%f", g_value_get_double (value));
	else if (G_VALUE_TYPE (value) == G_TYPE_VALUE_ARRAY) {
		GValueArray *array = g_value_get_boxed (value);
		int i;
		printf ("[ ");
		for (i = 0; i < array->n_values; i++) {
			if (i != 0)
				printf (", ");
			print_value (&array->values[i]);
		}
		printf (" ]");
	} else
		printf ("(%s)", g_type_name (G_VALUE_TYPE (value)));
}
Пример #5
0
static gboolean
xfce_xsettings_helper_prop_valid (const gchar  *prop_name,
                                  const GValue *value)
{
    /* only accept properties in valid domains */
    if (!g_str_has_prefix (prop_name, "/Net/")
        && !g_str_has_prefix (prop_name, "/Xft/")
        && !g_str_has_prefix (prop_name, "/Gtk/"))
        return FALSE;

    /* notify if the property has an unsupported type */
    if (!G_VALUE_HOLDS_BOOLEAN (value)
        && !G_VALUE_HOLDS_INT (value)
        && !G_VALUE_HOLDS_STRING (value))
    {
        g_warning ("Property \"%s\" has an unsupported type \"%s\".",
                   prop_name, G_VALUE_TYPE_NAME (value));

        return FALSE;
    }

    return TRUE;
}
Пример #6
0
static gboolean
num_to_string (GBinding     *binding,
               const GValue *source_value,
               GValue       *target_value,
               gpointer      userdata)
{
  gchar *string;

  if (G_VALUE_HOLDS_INT (source_value))
    string = g_strdup_printf ("%d", g_value_get_int (source_value));
  else if (G_VALUE_HOLDS_UINT (source_value))
    string = g_strdup_printf ("%d", g_value_get_uint (source_value));
  else if (G_VALUE_HOLDS_DOUBLE (source_value))
    string = g_strdup_printf ("%.2f", g_value_get_double (source_value));
  else if (G_VALUE_HOLDS_FLOAT (source_value))
    string = g_strdup_printf ("%.2f", g_value_get_float (source_value));
  else
    return FALSE;

  g_value_take_string (target_value, string);

  return TRUE;
}
Пример #7
0
static gboolean
string_to_num (GBinding     *binding,
               const GValue *source_value,
               GValue       *target_value,
               gpointer      userdata)
{
  if (G_VALUE_HOLDS_INT (target_value))
    g_value_set_int (target_value,
                     atoi (g_value_get_string (source_value)));
  else if (G_VALUE_HOLDS_UINT (target_value))
    g_value_set_uint (target_value,
                      atoi (g_value_get_string (source_value)));
  else if (G_VALUE_HOLDS_DOUBLE (target_value))
    g_value_set_double (target_value,
                        strtod (g_value_get_string (source_value), NULL));
  else if (G_VALUE_HOLDS_FLOAT (target_value))
    g_value_set_float (target_value,
                       strtof (g_value_get_string (source_value), NULL));
  else
    return FALSE;

  return TRUE;
}
Пример #8
0
static GUPnPDLNAIntValue
get_int_value_from_tag_list (const GstTagList *tags,
                             const gchar *name)
{
        GUPnPDLNAIntValue value = GUPNP_DLNA_INT_VALUE_UNSET;

        if (tags != NULL) {
                const GValue *g_value = gst_tag_list_get_value_index (tags,
                                                                      name,
                                                                      0);

                if (g_value != NULL) {
                        if (G_VALUE_HOLDS_INT (g_value)) {
                                value.state = GUPNP_DLNA_VALUE_STATE_SET;
                                value.value = g_value_get_int (g_value);
                        } else if (G_VALUE_HOLDS_UINT (g_value)) {
                                value.state = GUPNP_DLNA_VALUE_STATE_SET;
                                value.value = g_value_get_uint (g_value);
                        }
                }
        }

        return value;
}
Пример #9
0
JNIEXPORT jint JNICALL
Java_org_gnome_glib_GValue_g_1value_1get_1int
(
	JNIEnv* env,
	jclass cls,
	jlong _value
)
{
	GValue* value;
	gint result;

	// translate value
	value =	(GValue*) _value;
	if (!G_VALUE_HOLDS_INT(value)) {
		bindings_java_throw(env, "You've asked for the int value of a GValue, but it's not a G_TYPE_INT!");
		return 0;
	}

	// call function
	result = g_value_get_int(value);
	
	// and return
	return (jint) result;
}
Пример #10
0
static gboolean
signal_emit_handler (gpointer p)
{
  CallbackPara *para = (CallbackPara*)p;
  jobject global_ac = para->global_ac;
  JNIEnv *jniEnv = jaw_util_get_jni_env();
  if (jniEnv == NULL)
  {
    if (jaw_debug)
      g_warning("signal_emit_handler: jniEnv == NULL");
    free_callback_para(para);
    return G_SOURCE_REMOVE;
  }

  jobjectArray args = para->args;

  if (global_ac == NULL)
  {
    if (jaw_debug)
      g_warning("signal_emit_handler: global_ac == NULL");
    free_callback_para(para);
    return G_SOURCE_REMOVE;
  }

  JawImpl* jaw_impl = jaw_impl_find_instance(jniEnv, global_ac);

  if (jaw_impl == NULL)
  {
    if (jaw_debug)
      g_warning("signal_emit_handler: jaw_impl == NULL");
    free_callback_para(para);
    return G_SOURCE_REMOVE;
  }

  AtkObject* atk_obj = ATK_OBJECT(jaw_impl);

  switch (para->signal_id)
  {
    case Sig_Text_Caret_Moved:
    {
      gint cursor_pos = get_int_value(jniEnv,
                                      (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
      g_signal_emit_by_name(atk_obj, "text_caret_moved", cursor_pos);
      break;
    }
    case Sig_Text_Property_Changed_Insert:
    {
      gint insert_position = get_int_value(jniEnv,
                                           (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
      gint insert_length = get_int_value(jniEnv,
                                         (*jniEnv)->GetObjectArrayElement(jniEnv, args, 1));
      g_signal_emit_by_name(atk_obj,
                            "text_changed::insert",
                            insert_position,
                            insert_length);
      break;
    }
    case Sig_Text_Property_Changed_Delete:
    {
      gint delete_position = get_int_value(jniEnv,
                                           (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
      gint delete_length = get_int_value(jniEnv,
                                         (*jniEnv)->GetObjectArrayElement(jniEnv, args, 1));
      g_signal_emit_by_name(atk_obj,
                            "text_changed::delete",
                            delete_position,
                            delete_length);
      break;
    }
    case Sig_Object_Children_Changed_Add:
    {
      gint child_index = get_int_value(jniEnv,
                                       (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
      jobject child_ac = (*jniEnv)->GetObjectArrayElement(jniEnv, args, 1);
      JawImpl *child_impl = jaw_impl_get_instance(jniEnv, child_ac);
      if (child_impl == NULL)
      {
        if (jaw_debug)
          g_warning("signal_emit_handler: child_impl == NULL");
        free_callback_para(para);
        return G_SOURCE_REMOVE;
      }
      if (!child_impl)
      {
        break;
      }

      g_signal_emit_by_name(atk_obj,
                            "children_changed::add",
                            child_index,
                            child_impl);
        break;
      }
      case Sig_Object_Children_Changed_Remove:
      {
        gint child_index = get_int_value(jniEnv,
                                         (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
        jobject child_ac = (*jniEnv)->GetObjectArrayElement(jniEnv, args, 1);
        JawImpl *child_impl = jaw_impl_find_instance(jniEnv, child_ac);
        if (!child_impl)
        {
          break;
        }

        g_signal_emit_by_name(atk_obj,
                              "children_changed::remove",
                              child_index,
                              child_impl);
        if (G_OBJECT(atk_obj) != NULL)
          g_object_unref(G_OBJECT(atk_obj));
        break;
      }
      case Sig_Object_Active_Descendant_Changed:
      {
      jobject child_ac = (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0);
      JawImpl *child_impl = jaw_impl_get_instance(jniEnv, child_ac);
      if (child_impl == NULL)
      {
        if (jaw_debug)
          g_warning("signal_emit_handler: child_impl == NULL");
        free_callback_para(para);
        return G_SOURCE_REMOVE;
      }
      if (!child_impl)
      {
        break;
      }

      g_signal_emit_by_name(atk_obj,
                            "active_descendant_changed",
                            child_impl);
      break;
    }
    case Sig_Object_Selection_Changed:
    {
      g_signal_emit_by_name(atk_obj,
                            "selection_changed");
      break;
    }
    case Sig_Object_Visible_Data_Changed:
    {
      g_signal_emit_by_name(atk_obj,
                            "visible_data_changed");
      break;
    }
    case Sig_Object_Property_Change_Accessible_Actions:
    {
      gint oldValue = get_int_value(jniEnv,
                                    (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));
      gint newValue = get_int_value(jniEnv,
                                    (*jniEnv)->GetObjectArrayElement(jniEnv, args, 1));
      AtkPropertyValues values = { NULL };

      // GValues must be initialized
      g_assert (!G_VALUE_HOLDS_INT (&values.old_value));
      g_value_init(&values.old_value, G_TYPE_INT);
      g_assert (G_VALUE_HOLDS_INT (&values.old_value));
      g_value_set_int(&values.old_value, oldValue);
      if (jaw_debug)
        printf ("%d\n", g_value_get_int(&values.old_value));

      g_assert (!G_VALUE_HOLDS_INT (&values.new_value));
      g_value_init(&values.new_value, G_TYPE_INT);
      g_assert (G_VALUE_HOLDS_INT (&values.new_value));
      g_value_set_int(&values.new_value, newValue);
      if (jaw_debug)
        printf ("%d\n", g_value_get_int(&values.new_value));

      values.property_name = "accessible-actions";

      g_signal_emit_by_name(atk_obj,
                            "property_change::accessible-actions",
                            &values);
      break;
    }
    case Sig_Object_Property_Change_Accessible_Value:
    {
      g_object_notify(G_OBJECT(atk_obj), "accessible-value");
      break;
    }
    case Sig_Object_Property_Change_Accessible_Description:
    {
      g_object_notify(G_OBJECT(atk_obj), "accessible-description");
      break;
    }
    case Sig_Object_Property_Change_Accessible_Name:
    {
      g_object_notify(G_OBJECT(atk_obj), "accessible-name");
      break;
     }
    case Sig_Object_Property_Change_Accessible_Hypertext_Offset:
    {
      g_signal_emit_by_name(atk_obj,
                            "property_change::accessible-hypertext-offset",
                            NULL);
      break;
    }
    case Sig_Object_Property_Change_Accessible_Table_Caption:
    {
      g_signal_emit_by_name(atk_obj,
                            "property_change::accessible-table-caption",
                            NULL);
      break;
    }
    case Sig_Object_Property_Change_Accessible_Table_Summary:
    {
      g_signal_emit_by_name(atk_obj,
                            "property_change::accessible-table-summary",
                            NULL);
      break;
    }
    case Sig_Object_Property_Change_Accessible_Table_Column_Header:
    {
      g_signal_emit_by_name(atk_obj,
                            "property_change::accessible-table-column-header",
                            NULL);
      break;
    }
    case Sig_Object_Property_Change_Accessible_Table_Column_Description:
    {
      g_signal_emit_by_name(atk_obj,
                            "property_change::accessible-table-column-description",
                            NULL);
      break;
    }
    case Sig_Object_Property_Change_Accessible_Table_Row_Header:
    {
      g_signal_emit_by_name(atk_obj,
      "property_change::accessible-table-row-header",
      NULL);
      break;
    }
    case Sig_Object_Property_Change_Accessible_Table_Row_Description:
    {
      g_signal_emit_by_name(atk_obj,
                            "property_change::accessible-table-row-description",
                            NULL);
      break;
    }
    case Sig_Table_Model_Changed:
    {
      g_signal_emit_by_name(atk_obj,
                            "model_changed");
      break;
    }
    case Sig_Text_Property_Changed:
    {
      JawObject * jaw_obj = JAW_OBJECT(atk_obj);

      gint newValue = get_int_value(jniEnv,
                                    (*jniEnv)->GetObjectArrayElement(jniEnv, args, 0));

      gint prevCount = GPOINTER_TO_INT(g_hash_table_lookup(jaw_obj->storedData,
                                                           "Previous_Count"));
      gint curCount = atk_text_get_character_count(ATK_TEXT(jaw_obj));

      g_hash_table_insert(jaw_obj->storedData,
                          "Previous_Count",
                          GINT_TO_POINTER(curCount));

      if (curCount > prevCount)
      {
        g_signal_emit_by_name(atk_obj,
                              "text_changed::insert",
                              newValue,
                              curCount - prevCount);
      }
      else if (curCount < prevCount)
      {
        g_signal_emit_by_name(atk_obj,
                              "text_changed::delete",
                              newValue,
                              prevCount - curCount);
      }
      break;
    }
    default:
      break;
  }
  free_callback_para(para);
  return G_SOURCE_REMOVE;
}
Пример #11
0
GimpValueArray *
plug_in_params_to_args (GParamSpec **pspecs,
                        gint         n_pspecs,
                        GPParam     *params,
                        gint         n_params,
                        gboolean     return_values,
                        gboolean     full_copy)
{
  GimpValueArray *args;
  gint            i;

  g_return_val_if_fail ((pspecs != NULL && n_pspecs  > 0) ||
                        (pspecs == NULL && n_pspecs == 0), NULL);
  g_return_val_if_fail ((params != NULL && n_params  > 0) ||
                        (params == NULL && n_params == 0), NULL);

  args = gimp_value_array_new (n_params);

  for (i = 0; i < n_params; i++)
    {
      GValue value = G_VALUE_INIT;
      GType  type;
      gint   count;

      /*  first get the fallback compat GType that matches the pdb type  */
      type = gimp_pdb_compat_arg_type_to_gtype (params[i].type);

      /*  then try to try to be more specific by looking at the param
       *  spec (return values have one additional value (the status),
       *  skip that, it's not in the array of param specs)
       */
      if (i > 0 || ! return_values)
        {
          gint pspec_index = i;

          if (return_values)
            pspec_index--;

          /*  are there param specs left?  */
          if (pspec_index < n_pspecs)
            {
              GType          pspec_gtype;
              GimpPDBArgType pspec_arg_type;

              pspec_gtype    = G_PARAM_SPEC_VALUE_TYPE (pspecs[pspec_index]);
              pspec_arg_type = gimp_pdb_compat_arg_type_from_gtype (pspec_gtype);

              /*  if the param spec's GType, mapped to a pdb type, matches
               *  the passed pdb type, use the param spec's GType
               */
              if (pspec_arg_type == params[i].type)
                type = pspec_gtype;
            }
        }

      g_value_init (&value, type);

      switch (gimp_pdb_compat_arg_type_from_gtype (type))
        {
        case GIMP_PDB_INT32:
          if (G_VALUE_HOLDS_INT (&value))
            g_value_set_int (&value, params[i].data.d_int32);
          else if (G_VALUE_HOLDS_UINT (&value))
            g_value_set_uint (&value, params[i].data.d_int32);
          else if (G_VALUE_HOLDS_ENUM (&value))
            g_value_set_enum (&value, params[i].data.d_int32);
          else if (G_VALUE_HOLDS_BOOLEAN (&value))
            g_value_set_boolean (&value, params[i].data.d_int32 ? TRUE : FALSE);
          else
            {
              g_printerr ("%s: unhandled GIMP_PDB_INT32 type: %s\n",
                          G_STRFUNC, g_type_name (G_VALUE_TYPE (&value)));
              g_return_val_if_reached (args);
            }
          break;

        case GIMP_PDB_INT16:
          g_value_set_int (&value, params[i].data.d_int16);
          break;

        case GIMP_PDB_INT8:
          g_value_set_uint (&value, params[i].data.d_int8);
          break;

        case GIMP_PDB_FLOAT:
          g_value_set_double (&value, params[i].data.d_float);
          break;

        case GIMP_PDB_STRING:
          if (full_copy)
            g_value_set_string (&value, params[i].data.d_string);
          else
            g_value_set_static_string (&value, params[i].data.d_string);
          break;

        case GIMP_PDB_INT32ARRAY:
          count = g_value_get_int (gimp_value_array_index (args, i - 1));
          if (full_copy)
            gimp_value_set_int32array (&value,
                                       params[i].data.d_int32array,
                                       count);
          else
            gimp_value_set_static_int32array (&value,
                                              params[i].data.d_int32array,
                                              count);
          break;

        case GIMP_PDB_INT16ARRAY:
          count = g_value_get_int (gimp_value_array_index (args, i - 1));
          if (full_copy)
            gimp_value_set_int16array (&value,
                                       params[i].data.d_int16array,
                                       count);
          else
            gimp_value_set_static_int16array (&value,
                                              params[i].data.d_int16array,
                                              count);
          break;

        case GIMP_PDB_INT8ARRAY:
          count = g_value_get_int (gimp_value_array_index (args, i - 1));
          if (full_copy)
            gimp_value_set_int8array (&value,
                                      params[i].data.d_int8array,
                                      count);
          else
            gimp_value_set_static_int8array (&value,
                                             params[i].data.d_int8array,
                                             count);
          break;

        case GIMP_PDB_FLOATARRAY:
          count = g_value_get_int (gimp_value_array_index (args, i - 1));
          if (full_copy)
            gimp_value_set_floatarray (&value,
                                       params[i].data.d_floatarray,
                                       count);
          else
            gimp_value_set_static_floatarray (&value,
                                              params[i].data.d_floatarray,
                                              count);
          break;

        case GIMP_PDB_STRINGARRAY:
          count = g_value_get_int (gimp_value_array_index (args, i - 1));
          if (full_copy)
            gimp_value_set_stringarray (&value,
                                        (const gchar **) params[i].data.d_stringarray,
                                        count);
          else
            gimp_value_set_static_stringarray (&value,
                                               (const gchar **) params[i].data.d_stringarray,
                                               count);
          break;

        case GIMP_PDB_COLOR:
          gimp_value_set_rgb (&value, &params[i].data.d_color);
          break;

        case GIMP_PDB_ITEM:
          g_value_set_int (&value, params[i].data.d_item);
          break;

        case GIMP_PDB_DISPLAY:
          g_value_set_int (&value, params[i].data.d_display);
          break;

        case GIMP_PDB_IMAGE:
          g_value_set_int (&value, params[i].data.d_image);
          break;

        case GIMP_PDB_LAYER:
          g_value_set_int (&value, params[i].data.d_layer);
          break;

        case GIMP_PDB_CHANNEL:
          g_value_set_int (&value, params[i].data.d_channel);
          break;

        case GIMP_PDB_DRAWABLE:
          g_value_set_int (&value, params[i].data.d_drawable);
          break;

        case GIMP_PDB_SELECTION:
          g_value_set_int (&value, params[i].data.d_selection);
          break;

        case GIMP_PDB_COLORARRAY:
          count = g_value_get_int (gimp_value_array_index (args, i - 1));
          if (full_copy)
            gimp_value_set_colorarray (&value,
                                      params[i].data.d_colorarray,
                                      count);
          else
            gimp_value_set_static_colorarray (&value,
                                             params[i].data.d_colorarray,
                                             count);
          break;

        case GIMP_PDB_VECTORS:
          g_value_set_int (&value, params[i].data.d_vectors);
          break;

        case GIMP_PDB_PARASITE:
          if (full_copy)
            g_value_set_boxed (&value, &params[i].data.d_parasite);
          else
            g_value_set_static_boxed (&value, &params[i].data.d_parasite);
          break;

        case GIMP_PDB_STATUS:
          g_value_set_enum (&value, params[i].data.d_status);
          break;

        case GIMP_PDB_END:
          break;
        }

      gimp_value_array_append (args, &value);
      g_value_unset (&value);
    }

  return args;
}
Пример #12
0
GPParam *
plug_in_args_to_params (GimpValueArray *args,
                        gboolean        full_copy)
{
  GPParam *params;
  gint     length;
  gint     i;

  g_return_val_if_fail (args != NULL, NULL);

  params = g_new0 (GPParam, gimp_value_array_length (args));

  length = gimp_value_array_length (args);

  for (i = 0; i < length; i++)
    {
      GValue *value = gimp_value_array_index (args, i);

      params[i].type =
        gimp_pdb_compat_arg_type_from_gtype (G_VALUE_TYPE (value));

      switch (params[i].type)
        {
        case GIMP_PDB_INT32:
          if (G_VALUE_HOLDS_INT (value))
            params[i].data.d_int32 = g_value_get_int (value);
          else if (G_VALUE_HOLDS_UINT (value))
            params[i].data.d_int32 = g_value_get_uint (value);
          else if (G_VALUE_HOLDS_ENUM (value))
            params[i].data.d_int32 = g_value_get_enum (value);
          else if (G_VALUE_HOLDS_BOOLEAN (value))
            params[i].data.d_int32 = g_value_get_boolean (value);
          else
            {
              g_printerr ("%s: unhandled GIMP_PDB_INT32 type: %s\n",
                          G_STRFUNC, g_type_name (G_VALUE_TYPE (value)));
              g_return_val_if_reached (params);
            }
          break;

        case GIMP_PDB_INT16:
          params[i].data.d_int16 = g_value_get_int (value);
          break;

        case GIMP_PDB_INT8:
          params[i].data.d_int8 = g_value_get_uint (value);
          break;

        case GIMP_PDB_FLOAT:
          params[i].data.d_float = g_value_get_double (value);
          break;

        case GIMP_PDB_STRING:
          if (full_copy)
            params[i].data.d_string = g_value_dup_string (value);
          else
            params[i].data.d_string = (gchar *) g_value_get_string (value);
          break;

        case GIMP_PDB_INT32ARRAY:
          if (full_copy)
            params[i].data.d_int32array = gimp_value_dup_int32array (value);
          else
            params[i].data.d_int32array = (gint32 *) gimp_value_get_int32array (value);
          break;

        case GIMP_PDB_INT16ARRAY:
          if (full_copy)
            params[i].data.d_int16array = gimp_value_dup_int16array (value);
          else
            params[i].data.d_int16array = (gint16 *) gimp_value_get_int16array (value);
          break;

        case GIMP_PDB_INT8ARRAY:
          if (full_copy)
            params[i].data.d_int8array = gimp_value_dup_int8array (value);
          else
            params[i].data.d_int8array = (guint8 *) gimp_value_get_int8array (value);
          break;

        case GIMP_PDB_FLOATARRAY:
          if (full_copy)
            params[i].data.d_floatarray = gimp_value_dup_floatarray (value);
          else
            params[i].data.d_floatarray = (gdouble *) gimp_value_get_floatarray (value);
          break;

        case GIMP_PDB_STRINGARRAY:
          if (full_copy)
            params[i].data.d_stringarray = gimp_value_dup_stringarray (value);
          else
            params[i].data.d_stringarray = (gchar **) gimp_value_get_stringarray (value);
          break;

        case GIMP_PDB_COLOR:
          gimp_value_get_rgb (value, &params[i].data.d_color);
          break;

        case GIMP_PDB_ITEM:
          params[i].data.d_item = g_value_get_int (value);
          break;

        case GIMP_PDB_DISPLAY:
          params[i].data.d_display = g_value_get_int (value);
          break;

        case GIMP_PDB_IMAGE:
          params[i].data.d_image = g_value_get_int (value);
          break;

        case GIMP_PDB_LAYER:
          params[i].data.d_layer = g_value_get_int (value);
          break;

        case GIMP_PDB_CHANNEL:
          params[i].data.d_channel = g_value_get_int (value);
          break;

        case GIMP_PDB_DRAWABLE:
          params[i].data.d_drawable = g_value_get_int (value);
          break;

        case GIMP_PDB_SELECTION:
          params[i].data.d_selection = g_value_get_int (value);
          break;

        case GIMP_PDB_COLORARRAY:
          if (full_copy)
            params[i].data.d_colorarray = gimp_value_dup_colorarray (value);
          else
            params[i].data.d_colorarray = (GimpRGB *) gimp_value_get_colorarray (value);
          break;

        case GIMP_PDB_VECTORS:
          params[i].data.d_vectors = g_value_get_int (value);
          break;

        case GIMP_PDB_PARASITE:
          {
            GimpParasite *parasite = (full_copy ?
                                      g_value_dup_boxed (value) :
                                      g_value_get_boxed (value));

            if (parasite)
              {
                params[i].data.d_parasite.name  = parasite->name;
                params[i].data.d_parasite.flags = parasite->flags;
                params[i].data.d_parasite.size  = parasite->size;
                params[i].data.d_parasite.data  = parasite->data;

                if (full_copy)
                  {
                    parasite->name  = NULL;
                    parasite->flags = 0;
                    parasite->size  = 0;
                    parasite->data  = NULL;

                    gimp_parasite_free (parasite);
                  }
              }
            else
              {
                params[i].data.d_parasite.name  = NULL;
                params[i].data.d_parasite.flags = 0;
                params[i].data.d_parasite.size  = 0;
                params[i].data.d_parasite.data  = NULL;
              }
          }
          break;

        case GIMP_PDB_STATUS:
          params[i].data.d_status = g_value_get_enum (value);
          break;

        case GIMP_PDB_END:
          break;
        }
    }

  return params;
}
Пример #13
0
/**
 * clutter_shader_set_uniform:
 * @shader: a #ClutterShader.
 * @name: name of uniform in GLSL shader program to set.
 * @value: a #ClutterShaderFloat, #ClutterShaderInt or #ClutterShaderMatrix
 *         #GValue.
 *
 * Sets a user configurable variable in the GLSL shader programs attached to
 * a #ClutterShader.
 *
 * Since: 1.0
 *
 * Deprecated: 1.8: Use #ClutterShaderEffect instead.
 */
void
clutter_shader_set_uniform (ClutterShader *shader,
                            const gchar   *name,
                            const GValue  *value)
{
  ClutterShaderPrivate *priv;
  int                   location = 0;
  gsize                 size;

  g_return_if_fail (CLUTTER_IS_SHADER (shader));
  g_return_if_fail (name != NULL);
  g_return_if_fail (value != NULL);
  g_return_if_fail (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value) ||
                    CLUTTER_VALUE_HOLDS_SHADER_INT (value) ||
                    CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value) ||
                    G_VALUE_HOLDS_FLOAT (value) ||
                    G_VALUE_HOLDS_INT (value));

  priv = shader->priv;
  g_return_if_fail (priv->program != COGL_INVALID_HANDLE);

  location = cogl_program_get_uniform_location (priv->program, name);

  if (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value))
    {
      const float *floats;

      floats = clutter_value_get_shader_float (value, &size);
      cogl_program_set_uniform_float (priv->program,
                                      location, size, 1, floats);
    }
  else if (CLUTTER_VALUE_HOLDS_SHADER_INT (value))
    {
      const int *ints;

      ints = clutter_value_get_shader_int (value, &size);
      cogl_program_set_uniform_int (priv->program,
                                    location, size, 1, ints);
    }
  else if (CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value))
    {
      const float *matrix;

      matrix = clutter_value_get_shader_matrix (value, &size);
      cogl_program_set_uniform_matrix (priv->program,
                                       location, size, 1, FALSE, matrix);
    }
  else if (G_VALUE_HOLDS_FLOAT (value))
    {
      float float_val = g_value_get_float (value);

      cogl_program_set_uniform_float (priv->program,
                                      location, 1, 1, &float_val);
    }
  else if (G_VALUE_HOLDS_INT (value))
    {
      int int_val = g_value_get_int (value);

      cogl_program_set_uniform_int (priv->program,
                                    location, 1, 1, &int_val);
    }
  else
    g_assert_not_reached ();
}
Пример #14
0
void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value)
{
    GOwnPtr<gchar> originalName(JSStringCopyUTF8CString(key));
    GOwnPtr<gchar> valueAsString(JSStringCopyUTF8CString(value));

    WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
    ASSERT(view);

    // This transformation could be handled by a hash table (and it once was), but
    // having it prominent, makes it easier for people from other ports to keep the
    // list up to date.
    const gchar* propertyName = 0;
    if (g_str_equal(originalName.get(), "WebKitJavaScriptEnabled"))
        propertyName = "enable-scripts";
    else if (g_str_equal(originalName.get(), "WebKitDefaultFontSize"))
        propertyName = "default-font-size";
    else if (g_str_equal(originalName.get(), "WebKitEnableCaretBrowsing"))
        propertyName = "enable-caret-browsing";
    else if (g_str_equal(originalName.get(), "WebKitUsesPageCachePreferenceKey"))
        propertyName = "enable-page-cache";
    else if (g_str_equal(originalName.get(), "WebKitPluginsEnabled"))
        propertyName = "enable-plugins";
    else if (g_str_equal(originalName.get(), "WebKitHyperlinkAuditingEnabled"))
        propertyName = "enable-hyperlink-auditing";
    else if (g_str_equal(originalName.get(), "WebKitWebGLEnabled"))
        propertyName = "enable-webgl";
    else if (g_str_equal(originalName.get(), "WebKitWebAudioEnabled"))
        propertyName = "enable-webaudio";
    else if (g_str_equal(originalName.get(), "WebKitTabToLinksPreferenceKey")) {
        DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(booleanFromValue(valueAsString.get()));
        return;
    } else if (g_str_equal(originalName.get(), "WebKitHixie76WebSocketProtocolEnabled")) {
        DumpRenderTreeSupportGtk::setHixie76WebSocketProtocolEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
        return;
    } else if (g_str_equal(originalName.get(), "WebKitPageCacheSupportsPluginsPreferenceKey")) {
        DumpRenderTreeSupportGtk::setPageCacheSupportsPlugins(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get()));
        return;
    } else {
        fprintf(stderr, "LayoutTestController::overridePreference tried to override "
                "unknown preference '%s'.\n", originalName.get());
        return;
    }

    WebKitWebSettings* settings = webkit_web_view_get_settings(view);
    GParamSpec* pspec = g_object_class_find_property(G_OBJECT_CLASS(
        WEBKIT_WEB_SETTINGS_GET_CLASS(settings)), propertyName);
    GValue currentPropertyValue = { 0, { { 0 } } };
    g_value_init(&currentPropertyValue, pspec->value_type);

    if (G_VALUE_HOLDS_STRING(&currentPropertyValue))
        g_object_set(settings, propertyName, valueAsString.get(), NULL);
    else if (G_VALUE_HOLDS_BOOLEAN(&currentPropertyValue))
        g_object_set(G_OBJECT(settings), propertyName, booleanFromValue(valueAsString.get()), NULL);
    else if (G_VALUE_HOLDS_INT(&currentPropertyValue))
        g_object_set(G_OBJECT(settings), propertyName, atoi(valueAsString.get()), NULL);
    else if (G_VALUE_HOLDS_FLOAT(&currentPropertyValue)) {
        gfloat newValue = g_ascii_strtod(valueAsString.get(), 0);
        g_object_set(G_OBJECT(settings), propertyName, newValue, NULL);
    } else
        fprintf(stderr, "LayoutTestController::overridePreference failed to override "
                "preference '%s'.\n", originalName.get());
}
Пример #15
0
static GtkCellEditable *
parasite_property_cell_renderer_start_editing(GtkCellRenderer *renderer,
        GdkEvent *event,
        GtkWidget *widget,
        const gchar *path,
        GdkRectangle *background_area,
        GdkRectangle *cell_area,
        GtkCellRendererState flags)
{
    PangoFontDescription *font_desc;
    GtkCellEditable *editable = NULL;
    GObject *object;
    const char *name;
    GValue gvalue = {0};
    GParamSpec *prop;

    g_object_get(renderer,
                 "object", &object,
                 "name", &name,
                 NULL);

    prop = g_object_class_find_property(G_OBJECT_GET_CLASS(object), name);

    if (!(prop->flags & G_PARAM_WRITABLE))
        return NULL;

    g_value_init(&gvalue, prop->value_type);
    g_object_get_property(object, name, &gvalue);

    if (G_VALUE_HOLDS_ENUM(&gvalue) || G_VALUE_HOLDS_BOOLEAN(&gvalue))
    {
        GtkWidget *combobox = gtk_combo_box_new_text();
        gtk_widget_show(combobox);
        g_object_set(G_OBJECT(combobox), "has-frame", FALSE, NULL);
        GList *renderers;

        if (G_VALUE_HOLDS_BOOLEAN(&gvalue))
        {
            gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "FALSE");
            gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "TRUE");

            gtk_combo_box_set_active(GTK_COMBO_BOX(combobox),
                                     g_value_get_boolean(&gvalue) ? 1 : 0);
        }
        else if (G_VALUE_HOLDS_ENUM(&gvalue))
        {
            gint value = g_value_get_enum(&gvalue);
            GEnumClass *enum_class = G_PARAM_SPEC_ENUM(prop)->enum_class;
            guint i;

            for (i = 0; i < enum_class->n_values; i++)
            {
                GEnumValue *enum_value = &enum_class->values[i];

                gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),
                                          enum_value->value_name);

                if (enum_value->value == value)
                    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), i);
            }

        }

        renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(combobox));
        g_object_set(G_OBJECT(renderers->data), "scale", TREE_TEXT_SCALE, NULL);
        g_list_free(renderers);

        editable = GTK_CELL_EDITABLE(combobox);
    }
    else if (G_VALUE_HOLDS_STRING(&gvalue))
    {
        GtkWidget *entry = gtk_entry_new();
        gtk_widget_show(entry);
        gtk_entry_set_text(GTK_ENTRY(entry), g_value_get_string(&gvalue));

        editable = GTK_CELL_EDITABLE(entry);
    }
    else if (G_VALUE_HOLDS_INT(&gvalue)    ||
             G_VALUE_HOLDS_UINT(&gvalue)   ||
             G_VALUE_HOLDS_INT64(&gvalue)  ||
             G_VALUE_HOLDS_UINT64(&gvalue) ||
             G_VALUE_HOLDS_LONG(&gvalue)   ||
             G_VALUE_HOLDS_ULONG(&gvalue)  ||
             G_VALUE_HOLDS_DOUBLE(&gvalue))
    {
        double min, max, value;
        GtkWidget *spinbutton;
        guint digits = 0;

        if (G_VALUE_HOLDS_INT(&gvalue))
        {
            GParamSpecInt *paramspec = G_PARAM_SPEC_INT(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_int(&gvalue);
        }
        else if (G_VALUE_HOLDS_UINT(&gvalue))
        {
            GParamSpecUInt *paramspec = G_PARAM_SPEC_UINT(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_uint(&gvalue);
        }
        else if (G_VALUE_HOLDS_INT64(&gvalue))
        {
            GParamSpecInt64 *paramspec = G_PARAM_SPEC_INT64(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_int64(&gvalue);
        }
        else if (G_VALUE_HOLDS_UINT64(&gvalue))
        {
            GParamSpecUInt64 *paramspec = G_PARAM_SPEC_UINT64(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_uint64(&gvalue);
        }
        else if (G_VALUE_HOLDS_LONG(&gvalue))
        {
            GParamSpecLong *paramspec = G_PARAM_SPEC_LONG(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_long(&gvalue);
        }
        else if (G_VALUE_HOLDS_ULONG(&gvalue))
        {
            GParamSpecULong *paramspec = G_PARAM_SPEC_ULONG(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_ulong(&gvalue);
        }
        else if (G_VALUE_HOLDS_DOUBLE(&gvalue))
        {
            GParamSpecDouble *paramspec = G_PARAM_SPEC_DOUBLE(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_double(&gvalue);
            digits = 2;
        }
        else
        {
            // Shouldn't really be able to happen.
            return NULL;
        }

        spinbutton = gtk_spin_button_new_with_range(min, max, 1);
        gtk_widget_show(spinbutton);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton), value);
        gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinbutton), digits);

        editable = GTK_CELL_EDITABLE(spinbutton);
    }

    font_desc = pango_font_description_new();
    pango_font_description_set_size(font_desc, 8 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(editable), font_desc);
    pango_font_description_free(font_desc);

    g_value_unset(&gvalue);

    g_signal_connect(G_OBJECT(editable), "editing_done",
                     G_CALLBACK(parasite_property_cell_renderer_stop_editing),
                     renderer);

    g_object_set_data_full(G_OBJECT(editable), "_prop_name", g_strdup(name),
                           g_free);
    g_object_set_data(G_OBJECT(editable), "_prop_object", object);

    return editable;
}
static gboolean
gst_video_crop_transform_dimension_value (const GValue * src_val,
    gint delta, GValue * dest_val, GstPadDirection direction, gboolean dynamic)
{
  gboolean ret = TRUE;

  if (G_VALUE_HOLDS_INT (src_val)) {
    gint ival = g_value_get_int (src_val);
    ival = gst_video_crop_transform_dimension (ival, delta);

    if (dynamic) {
      if (direction == GST_PAD_SRC) {
        if (ival == G_MAXINT) {
          g_value_init (dest_val, G_TYPE_INT);
          g_value_set_int (dest_val, ival);
        } else {
          g_value_init (dest_val, GST_TYPE_INT_RANGE);
          gst_value_set_int_range (dest_val, ival, G_MAXINT);
        }
      } else {
        if (ival == 1) {
          g_value_init (dest_val, G_TYPE_INT);
          g_value_set_int (dest_val, ival);
        } else {
          g_value_init (dest_val, GST_TYPE_INT_RANGE);
          gst_value_set_int_range (dest_val, 1, ival);
        }
      }
    } else {
      g_value_init (dest_val, G_TYPE_INT);
      g_value_set_int (dest_val, ival);
    }
  } else if (GST_VALUE_HOLDS_INT_RANGE (src_val)) {
    gint min = gst_value_get_int_range_min (src_val);
    gint max = gst_value_get_int_range_max (src_val);

    min = gst_video_crop_transform_dimension (min, delta);
    max = gst_video_crop_transform_dimension (max, delta);

    if (dynamic) {
      if (direction == GST_PAD_SRC)
        max = G_MAXINT;
      else
        min = 1;
    }

    if (min == max) {
      g_value_init (dest_val, G_TYPE_INT);
      g_value_set_int (dest_val, min);
    } else {
      g_value_init (dest_val, GST_TYPE_INT_RANGE);
      gst_value_set_int_range (dest_val, min, max);
    }
  } else if (GST_VALUE_HOLDS_LIST (src_val)) {
    gint i;

    g_value_init (dest_val, GST_TYPE_LIST);

    for (i = 0; i < gst_value_list_get_size (src_val); ++i) {
      const GValue *list_val;
      GValue newval = { 0, };

      list_val = gst_value_list_get_value (src_val, i);
      if (gst_video_crop_transform_dimension_value (list_val, delta, &newval,
              direction, dynamic))
        gst_value_list_append_value (dest_val, &newval);
      g_value_unset (&newval);
    }

    if (gst_value_list_get_size (dest_val) == 0) {
      g_value_unset (dest_val);
      ret = FALSE;
    }
  } else {
    ret = FALSE;
  }

  return ret;
}
Пример #17
0
int
main (int argc,
      char *argv[])
{
    
  /* Initialisation */
  gst_init (&argc, &argv);

  GList *element_list = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER, 
							       GST_RANK_NONE);
  GList *iter = element_list;
  while (iter != NULL)
    {
      g_print ("+++++\n");
      g_print ("%s -- ", gst_element_factory_get_longname ((GstElementFactory *)iter->data));
      g_print ("%s\n", gst_plugin_feature_get_name ((GstPluginFeature *)iter->data));
	 
      const GList *static_pads = 
	gst_element_factory_get_static_pad_templates ((GstElementFactory *)iter->data);
	 
      while (NULL != static_pads)
	{
	  GstStaticPadTemplate *pad = (GstStaticPadTemplate *)static_pads->data; 
	  //the following is EMPTY gchar *caps_str = gst_caps_to_string (&pad->static_caps.caps); 
	  //g_free (caps_str); 
	  /* g_print ("string: %s\n",  */
	  /* 	      pad->static_caps.string);  */
	  GstCaps *caps = gst_caps_from_string (pad->static_caps.string);
	  guint caps_size = gst_caps_get_size (caps);
	  if (! gst_caps_is_any (caps))
	    for (guint i = caps_size; i > 0; i--) 
	      {
		GstStructure *caps_struct = gst_caps_get_structure (caps, i-1);
		if (gst_structure_has_name (caps_struct,"application/x-rtp")) 
		  {
		    g_print ("string: %s\n",   
			     gst_structure_to_string (caps_struct));   
		    
		    {//payload 
		      const GValue *val = gst_structure_get_value (caps_struct, "payload");  
		      if (NULL != val) 
			{ 
			  //g_print ("payload struct type %s\n", G_VALUE_TYPE_NAME (val));  
			  if(GST_VALUE_HOLDS_INT_RANGE(val)) 
			    { 
			      g_print ("payload min %d\n", gst_value_get_int_range_min (val));  
			    } 
			  if (GST_VALUE_HOLDS_LIST(val)) 
			    { 
			      for (guint i = 0; i < gst_value_list_get_size (val); i++) 
				{ 
				  const GValue *item_val = gst_value_list_get_value (val, i); 
				  g_print ("payload list %d\n", g_value_get_int (item_val)); 
				} 
			    } 
			  if (G_VALUE_HOLDS_INT (val)) 
			    { 
			      g_print ("payload int %d\n", g_value_get_int (val)); 
			    } 
			} 
		    } 
		    { //encodeing-name
		      const GValue *val = gst_structure_get_value (caps_struct, "encoding-name");  
		      if (NULL != val) 
			{
			  //g_print ("encoding-name struct type %s\n", G_VALUE_TYPE_NAME (val));  
			  if (GST_VALUE_HOLDS_LIST(val)) 
			    { 
			      for (guint i = 0; i < gst_value_list_get_size (val); i++) 
				{ 
				  const GValue *item_val = gst_value_list_get_value (val, i); 
				  g_print ("encoding-name list %s\n", g_value_get_string (item_val)); 
				} 
			    } 
			  if (G_VALUE_HOLDS_STRING (val)) 
			    { 
			      g_print ("encoding-name string %s\n", g_value_get_string (val)); 
			    } 
				      
			}
		    } 
		    {//media
		      const GValue *val = gst_structure_get_value (caps_struct, "media");  
		      if (NULL != val) 
			{
			  if (GST_VALUE_HOLDS_LIST(val)) 
			    { 
			      for (guint i = 0; i < gst_value_list_get_size (val); i++) 
				{ 
				  const GValue *item_val = gst_value_list_get_value (val, i); 
				  g_print ("media list %s\n", g_value_get_string (item_val)); 
				} 
			    } 
			  if (G_VALUE_HOLDS_STRING (val)) 
			    { 
			      g_print ("media string %s\n", g_value_get_string (val)); 
			    } 
				      
			}
		    } 

		    {//clock rate 
		      const GValue *val = gst_structure_get_value (caps_struct, "clock-rate");  
		      if (NULL != val) 
			{ 
			  //g_print ("payload struct type %s\n", G_VALUE_TYPE_NAME (val));  
			  if(GST_VALUE_HOLDS_INT_RANGE(val)) 
			    { 
			      g_print ("clock-rate min %d\n", gst_value_get_int_range_min (val));  
			    } 
			  if (GST_VALUE_HOLDS_LIST(val)) 
			    { 
			      for (guint i = 0; i < gst_value_list_get_size (val); i++) 
				{ 
				  const GValue *item_val = gst_value_list_get_value (val, i); 
				  g_print ("clock-rate list %d\n", g_value_get_int (item_val)); 
				} 
			    } 
			  if (G_VALUE_HOLDS_INT (val)) 
			    { 
			      g_print ("clock-rate int %d\n", g_value_get_int (val)); 
			    } 
			} 
		    } 

		    /* g_print ("\nencoding-name %s\n",   */
		    /* 	 gst_structure_get_string (caps_struct,  */
		    /* 				   "encoding-name"));  */
			
		  }
	      }
	  static_pads = g_list_next (static_pads); 
	  gst_caps_unref (caps);
	}
	 
      iter = g_list_next (iter);
    }
  gst_plugin_feature_list_free (element_list);
    
  return 0;
}
Пример #18
0
/**
 * file_open_thumbnail:
 * @gimp:
 * @context:
 * @progress:
 * @file:         an image file
 * @size:         requested size of the thumbnail
 * @mime_type:    return location for image MIME type
 * @image_width:  return location for image width
 * @image_height: return location for image height
 * @format:       return location for image format (set to NULL if unknown)
 * @num_layers:   return location for number of layers
 *                (set to -1 if the number of layers is not known)
 * @error:
 *
 * Attempts to load a thumbnail by using a registered thumbnail loader.
 *
 * Return value: the thumbnail image
 */
GimpImage *
file_open_thumbnail (Gimp           *gimp,
                     GimpContext    *context,
                     GimpProgress   *progress,
                     GFile          *file,
                     gint            size,
                     const gchar   **mime_type,
                     gint           *image_width,
                     gint           *image_height,
                     const Babl    **format,
                     gint           *num_layers,
                     GError        **error)
{
  GimpPlugInProcedure *file_proc;
  GimpProcedure       *procedure;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (mime_type != NULL, NULL);
  g_return_val_if_fail (image_width != NULL, NULL);
  g_return_val_if_fail (image_height != NULL, NULL);
  g_return_val_if_fail (format != NULL, NULL);
  g_return_val_if_fail (num_layers != NULL, NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  *image_width  = 0;
  *image_height = 0;
  *format       = NULL;
  *num_layers   = -1;

  file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, file,
                                   NULL);

  if (! file_proc || ! file_proc->thumb_loader)
    return NULL;

  procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader);

  if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1)
    {
      GimpPDBStatusType  status;
      GimpValueArray    *return_vals;
      GimpImage         *image = NULL;
      gchar             *path  = NULL;

      if (! file_proc->handles_uri)
        path = g_file_get_path (file);

      if (! path)
        path = g_file_get_uri (file);

      return_vals =
        gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                            context, progress, error,
                                            gimp_object_get_name (procedure),
                                            G_TYPE_STRING,   path,
                                            GIMP_TYPE_INT32, size,
                                            G_TYPE_NONE);

      g_free (path);

      status = g_value_get_enum (gimp_value_array_index (return_vals, 0));

      if (status == GIMP_PDB_SUCCESS &&
          GIMP_VALUE_HOLDS_IMAGE_ID (gimp_value_array_index (return_vals, 1)))
        {
          image = gimp_value_get_image (gimp_value_array_index (return_vals, 1),
                                        gimp);

          if (gimp_value_array_length (return_vals) >= 3 &&
              G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 2)) &&
              G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 3)))
            {
              *image_width =
                MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 2)));

              *image_height =
                MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 3)));

              if (gimp_value_array_length (return_vals) >= 5 &&
                  G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 4)))
                {
                  gint value = g_value_get_int (gimp_value_array_index (return_vals, 4));

                  switch (value)
                    {
                    case GIMP_RGB_IMAGE:
                      *format = gimp_babl_format (GIMP_RGB,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  FALSE);
                      break;

                    case GIMP_RGBA_IMAGE:
                      *format = gimp_babl_format (GIMP_RGB,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  TRUE);
                      break;

                    case GIMP_GRAY_IMAGE:
                      *format = gimp_babl_format (GIMP_GRAY,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  FALSE);
                      break;

                    case GIMP_GRAYA_IMAGE:
                      *format = gimp_babl_format (GIMP_GRAY,
                                                  GIMP_PRECISION_U8_GAMMA,
                                                  TRUE);
                      break;

                    case GIMP_INDEXED_IMAGE:
                    case GIMP_INDEXEDA_IMAGE:
                      {
                        const Babl *rgb;
                        const Babl *rgba;

                        babl_new_palette ("-gimp-indexed-format-dummy",
                                          &rgb, &rgba);

                        if (value == GIMP_INDEXED_IMAGE)
                          *format = rgb;
                        else
                          *format = rgba;
                      }
                      break;

                    default:
                      break;
                    }
                }

              if (gimp_value_array_length (return_vals) >= 6 &&
                  G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 5)))
                {
                  *num_layers =
                    MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 5)));
                }
            }

          if (image)
            {
              file_open_sanitize_image (image, FALSE);

              *mime_type = file_proc->mime_type;

#ifdef GIMP_UNSTABLE
              g_printerr ("opened thumbnail at %d x %d\n",
                          gimp_image_get_width  (image),
                          gimp_image_get_height (image));
#endif
            }
        }

      gimp_value_array_unref (return_vals);

      return image;
    }

  return NULL;
}
Пример #19
0
static GstCaps *
gst_avdtp_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
{
  GstAvdtpSrc *avdtpsrc = GST_AVDTP_SRC (bsrc);
  GstCaps *caps = NULL, *ret = NULL;

  if (avdtpsrc->dev_caps) {
    const GValue *value;
    const char *format;
    int rate;
    GstStructure *structure = gst_caps_get_structure (avdtpsrc->dev_caps, 0);

    format = gst_structure_get_name (structure);

    if (g_str_equal (format, "audio/x-sbc")) {
      /* FIXME: we can return a fixed payload type once we
       * are in PLAYING */
      caps = gst_caps_new_simple ("application/x-rtp",
          "media", G_TYPE_STRING, "audio",
          "payload", GST_TYPE_INT_RANGE, 96, 127,
          "encoding-name", G_TYPE_STRING, "SBC", NULL);
    } else if (g_str_equal (format, "audio/mpeg")) {
      caps = gst_caps_new_simple ("application/x-rtp",
          "media", G_TYPE_STRING, "audio",
          "payload", GST_TYPE_INT_RANGE, 96, 127,
          "encoding-name", G_TYPE_STRING, "MP4A-LATM", NULL);

      value = gst_structure_get_value (structure, "mpegversion");
      if (!value || !G_VALUE_HOLDS_INT (value)) {
        GST_ERROR_OBJECT (avdtpsrc, "Failed to get mpegversion");
        gst_caps_unref (caps);
        return NULL;
      }
      gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT,
          g_value_get_int (value), NULL);

      value = gst_structure_get_value (structure, "channels");
      if (!value || !G_VALUE_HOLDS_INT (value)) {
        GST_ERROR_OBJECT (avdtpsrc, "Failed to get channels");
        gst_caps_unref (caps);
        return NULL;
      }
      gst_caps_set_simple (caps, "channels", G_TYPE_INT,
          g_value_get_int (value), NULL);

      value = gst_structure_get_value (structure, "base-profile");
      if (!value || !G_VALUE_HOLDS_STRING (value)) {
        GST_ERROR_OBJECT (avdtpsrc, "Failed to get base-profile");
        gst_caps_unref (caps);
        return NULL;
      }
      gst_caps_set_simple (caps, "base-profile", G_TYPE_STRING,
          g_value_get_string (value), NULL);

    } else {
      GST_ERROR_OBJECT (avdtpsrc,
          "Only SBC and MPEG-2/4 are supported at the moment");
    }

    value = gst_structure_get_value (structure, "rate");
    if (!value || !G_VALUE_HOLDS_INT (value)) {
      GST_ERROR_OBJECT (avdtpsrc, "Failed to get sample rate");
      gst_caps_unref (caps);
      return NULL;
    }
    rate = g_value_get_int (value);

    gst_caps_set_simple (caps, "clock-rate", G_TYPE_INT, rate, NULL);

    if (filter) {
      ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
      gst_caps_unref (caps);
    } else
      ret = caps;
  } else {
    GST_DEBUG_OBJECT (avdtpsrc, "device not open, using template caps");
    ret = GST_BASE_SRC_CLASS (parent_class)->get_caps (bsrc, filter);
  }

  return ret;
}
Пример #20
0
/**
 * file_open_thumbnail:
 * @gimp:
 * @context:
 * @progress:
 * @uri:          the URI of the image file
 * @size:         requested size of the thumbnail
 * @mime_type:    return location for image MIME type
 * @image_width:  return location for image width
 * @image_height: return location for image height
 * @type:         return location for image type (set to -1 if unknown)
 * @num_layers:   return location for number of layers
 *                (set to -1 if the number of layers is not known)
 * @error:
 *
 * Attempts to load a thumbnail by using a registered thumbnail loader.
 *
 * Return value: the thumbnail image
 */
GimpImage *
file_open_thumbnail (Gimp           *gimp,
                     GimpContext    *context,
                     GimpProgress   *progress,
                     const gchar    *uri,
                     gint            size,
                     const gchar   **mime_type,
                     gint           *image_width,
                     gint           *image_height,
                     GimpImageType  *type,
                     gint           *num_layers,
                     GError        **error)
{
    GimpPlugInProcedure *file_proc;
    GimpProcedure       *procedure;

    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
    g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
    g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
    g_return_val_if_fail (mime_type != NULL, NULL);
    g_return_val_if_fail (image_width != NULL, NULL);
    g_return_val_if_fail (image_height != NULL, NULL);
    g_return_val_if_fail (type != NULL, NULL);
    g_return_val_if_fail (num_layers != NULL, NULL);
    g_return_val_if_fail (error == NULL || *error == NULL, NULL);

    *image_width  = 0;
    *image_height = 0;
    *type         = -1;
    *num_layers   = -1;

    file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri,
                                     NULL);

    if (! file_proc || ! file_proc->thumb_loader)
        return NULL;

    procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader);

    if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1)
    {
        GimpPDBStatusType  status;
        GValueArray       *return_vals;
        gchar             *filename;
        GimpImage         *image = NULL;

        filename = file_utils_filename_from_uri (uri);

        if (! filename)
            filename = g_strdup (uri);

        return_vals =
            gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                                context, progress, error,
                                                gimp_object_get_name (procedure),
                                                G_TYPE_STRING,   filename,
                                                GIMP_TYPE_INT32, size,
                                                G_TYPE_NONE);

        g_free (filename);

        status = g_value_get_enum (&return_vals->values[0]);

        if (status == GIMP_PDB_SUCCESS &&
                GIMP_VALUE_HOLDS_IMAGE_ID (&return_vals->values[1]))
        {
            image = gimp_value_get_image (&return_vals->values[1], gimp);

            if (return_vals->n_values >= 3 &&
                    G_VALUE_HOLDS_INT (&return_vals->values[2]) &&
                    G_VALUE_HOLDS_INT (&return_vals->values[3]))
            {
                *image_width  = MAX (0,
                                     g_value_get_int (&return_vals->values[2]));
                *image_height = MAX (0,
                                     g_value_get_int (&return_vals->values[3]));

                if (return_vals->n_values >= 5 &&
                        G_VALUE_HOLDS_INT (&return_vals->values[4]))
                {
                    gint value = g_value_get_int (&return_vals->values[4]);

                    if (gimp_enum_get_value (GIMP_TYPE_IMAGE_TYPE, value,
                                             NULL, NULL, NULL, NULL))
                    {
                        *type = value;
                    }
                }

                if (return_vals->n_values >= 6 &&
                        G_VALUE_HOLDS_INT (&return_vals->values[5]))
                {
                    *num_layers = MAX (0,
                                       g_value_get_int (&return_vals->values[5]));
                }
            }

            if (image)
            {
                file_open_sanitize_image (image, FALSE);

                *mime_type = file_proc->mime_type;

#ifdef GIMP_UNSTABLE
                g_printerr ("opened thumbnail at %d x %d\n",
                            gimp_image_get_width  (image),
                            gimp_image_get_height (image));
#endif
            }
        }

        g_value_array_free (return_vals);

        return image;
    }

    return NULL;
}
Пример #21
0
static gboolean _extract_metadata (GHashTable *pMetadata)
{
	gboolean bTrackHasChanged = FALSE;
	GValue *v;
	const gchar *str = NULL;
	
	v = g_hash_table_lookup (pMetadata, "mpris:trackid");  // a string or a dbus object path that uniquely identifies the track within the scope of the playlist
	if (v != NULL)
	{
		if (G_VALUE_HOLDS (v, DBUS_TYPE_G_OBJECT_PATH)) // now this attribute should be of D-Bus type "o"
			str = (gchar*) g_value_get_boxed (v);
		else if (G_VALUE_HOLDS_STRING (v)) // but can be a string... e.g. with Rhythmbox
			str = g_value_get_string (v);
		bTrackHasChanged = _is_a_new_track (str);
	}

	v = g_hash_table_lookup (pMetadata, "mpris:length");  // length of the track, in microseconds (signed 64-bit integer)
	if (v != NULL)
	{
		if (G_VALUE_HOLDS_INT64 (v)) // should be a int64
			myData.iSongLength = g_value_get_int64 (v) / 1000000;
		else if (G_VALUE_HOLDS_INT (v)) // but some players doesn't respect that... maybe a limitation?
			myData.iSongLength = g_value_get_int (v) / 1000000;
		else
			cd_warning ("Length has a wrong type");
		cd_debug ("Length: %d", myData.iSongLength);
	}

	gchar *cOldArtist = myData.cArtist;
	myData.cArtist = NULL;
	v = (GValue *) g_hash_table_lookup(pMetadata, "xesam:artist");
	if (v != NULL && G_VALUE_HOLDS(v, G_TYPE_STRV))
	{
		gchar **artists = g_value_get_boxed(v);
		if (artists != NULL)
			myData.cArtist = g_strjoinv (NULL, artists);
	}
	cd_message ("  cArtist <- %s", myData.cArtist);
	
	// maybe the user has renamed the tags of the current song...
	if (! bTrackHasChanged && cairo_dock_strings_differ (myData.cArtist, cOldArtist))
		bTrackHasChanged = TRUE;
	g_free (cOldArtist);
	
	g_free (myData.cAlbum);
	myData.cAlbum = NULL;
	v = (GValue *) g_hash_table_lookup(pMetadata, "xesam:album");
	if (v != NULL && G_VALUE_HOLDS_STRING(v))
	{
		str = g_value_get_string(v);
		if (str && *str != '\0')
			myData.cAlbum = g_strdup (str);
	}
	cd_message ("  cAlbum <- %s", myData.cAlbum);

	gchar *cOldTitle = myData.cTitle;
	myData.cTitle = NULL;
	v = (GValue *) g_hash_table_lookup(pMetadata, "xesam:title");
	if (v != NULL && G_VALUE_HOLDS_STRING(v))
	{
		str = g_value_get_string(v);
		if (str && *str != '\0')
			myData.cTitle = g_strdup (str);
	}
	cd_message ("  cTitle <- %s", myData.cTitle);

	/* some players doesn't support (well) the trackid. Even if this is not our
	 * problem, it can be interesting to also check if the title has changed.
	 */
	if (! bTrackHasChanged && cairo_dock_strings_differ (myData.cTitle, cOldTitle))
		bTrackHasChanged = TRUE;
	g_free (cOldTitle);
	
	g_free (myData.cPlayingUri);
	myData.cPlayingUri = NULL;
	v = (GValue *) g_hash_table_lookup(pMetadata, "xesam:url");
	if (!v)
		v = (GValue *) g_hash_table_lookup(pMetadata, "xesam:uri");
	if (v != NULL && G_VALUE_HOLDS_STRING(v))
	{
		str = g_value_get_string(v);
		if (str && *str != '\0')
			myData.cPlayingUri = g_strdup (str);
	}
	cd_message ("  cUri <- %s", myData.cPlayingUri);

	myData.iTrackNumber = 0;  // not really useful, it's the track-number in the album.
	v = (GValue *) g_hash_table_lookup(pMetadata, "xesam:trackNumber");
	if (v != NULL && G_VALUE_HOLDS_INT(v))
	{
		myData.iTrackNumber = g_value_get_int (v);
	}
	cd_message ("  iTrackNumber <- %d", myData.iTrackNumber);

	const gchar *cCoverPath = NULL;
	v = g_hash_table_lookup(pMetadata, "mpris:artUrl");
	if (v != NULL && G_VALUE_HOLDS_STRING(v))
	{
		cCoverPath = g_value_get_string(v);
	}
	cd_musicplayer_set_cover_path (cCoverPath);  // do it at the end (we have to know the artist and the album if (cCoverPath == NULL))

	/// we miss iTrackListIndex and tracklist-length ...
	
	
	return bTrackHasChanged;
}
Пример #22
0
static void __mqb_set_metadata(MidgardMetadata *mdata, GdaDataModel *model, gint i)
{
	guint col = 0;
	const GValue *gvalue;	
	GValue mt = {0, };

	/* creator */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);	
	midgard_core_metadata_set_creator (mdata, gvalue);

	/* created */	
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP(created);

	/* revisor */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	if(G_VALUE_HOLDS_STRING (gvalue)) 
		midgard_core_metadata_set_revisor (mdata, gvalue);
		
	/* revised */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP(revised);

	/* revision */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	mdata->priv->revision = 0;
	_SET_METADATA_UINT(mdata->priv->revision, gvalue);
		
	/* locker */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	if(G_VALUE_HOLDS_STRING (gvalue)) 
		midgard_core_metadata_set_locker (mdata, gvalue);
		
	/* locked */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP(locked);

	/* approver */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	if(G_VALUE_HOLDS_STRING (gvalue)) 
		midgard_core_metadata_set_approver (mdata, gvalue);


	/* approved */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP(approved);

	/* authors */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	if(G_VALUE_HOLDS_STRING (gvalue)) 
		midgard_core_metadata_set_authors (mdata, gvalue);
		
	/* owner */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	if(G_VALUE_HOLDS_STRING (gvalue)) 
		midgard_core_metadata_set_owner (mdata, gvalue);

	/* schedule_start */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP (schedule_start);

	/* schedule_end */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP (schedule_end);

	/* hidden */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	mdata->priv->hidden = FALSE;
	if(G_VALUE_HOLDS_BOOLEAN(gvalue)) {
		mdata->priv->hidden = 
			g_value_get_boolean(gvalue);
	}

	/* nav_noentry */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	mdata->priv->nav_noentry = FALSE;
	if(G_VALUE_HOLDS_BOOLEAN(gvalue)) {
		mdata->priv->nav_noentry = 
			g_value_get_boolean(gvalue);
	}

	/* size */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	mdata->priv->size = 0;
	if(G_VALUE_HOLDS_INT(gvalue)) {
		mdata->priv->size = (guint) g_value_get_int(gvalue);
	}	

	/* published */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP (published);

	/* exported */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP(exported);

	/* imported */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	_SET_METADATA_TIMESTAMP(imported);

	/* deleted */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	mdata->priv->deleted = FALSE;
	if(G_VALUE_HOLDS_BOOLEAN(gvalue)) {
		mdata->priv->deleted = 
			g_value_get_boolean(gvalue);
	}
		
	/* score */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	mdata->priv->score = 0;
	if(G_VALUE_HOLDS_INT(gvalue)) {
		mdata->priv->score = 
			g_value_get_int(gvalue);
	}

	/* islocked */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	if(G_VALUE_HOLDS_BOOLEAN(gvalue)) {
		mdata->priv->is_locked = 
			g_value_get_boolean(gvalue);
	}

	/* isapproved */
	gvalue = midgard_data_model_get_value_at(model, ++col, i);
	if(G_VALUE_HOLDS_BOOLEAN(gvalue)) {
		mdata->priv->is_approved = 
			g_value_get_boolean(gvalue);
	}

	return;
}
Пример #23
0
static void
foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
{
	GValue *variant = (GValue *) value;
	NMAccessPoint *ap = (NMAccessPoint *) user_data;

	if (G_VALUE_HOLDS_BOXED (variant)) {
		GArray *array = g_value_get_boxed (variant);

		if (!strcmp (key, "SSID")) {
			guint32 len = MIN (32, array->len);
			GByteArray *ssid;

			/* Stupid ieee80211 layer uses <hidden> */
			if (((len == 8) || (len == 9))
				&& (memcmp (array->data, "<hidden>", 8) == 0))
				return;

			if (nm_utils_is_empty_ssid ((const guint8 *) array->data, len))
				return;

			ssid = g_byte_array_sized_new (len);
			g_byte_array_append (ssid, (const guint8 *) array->data, len);
			nm_ap_set_ssid (ap, ssid);
			g_byte_array_free (ssid, TRUE);
		} else if (!strcmp (key, "BSSID")) {
			struct ether_addr addr;

			if (array->len != ETH_ALEN)
				return;
			memset (&addr, 0, sizeof (struct ether_addr));
			memcpy (&addr, array->data, ETH_ALEN);
			nm_ap_set_address (ap, &addr);
		} else if (!strcmp (key, "Rates")) {
			guint32 maxrate = 0;
			int i;

			/* Find the max AP rate */
			for (i = 0; i < array->len; i++) {
				guint32 r = g_array_index (array, guint32, i);

				if (r > maxrate) {
					maxrate = r;
					nm_ap_set_max_bitrate (ap, r / 1000);
				}
			}
		} else if (!strcmp (key, "WPA")) {
			NM80211ApSecurityFlags flags = nm_ap_get_wpa_flags (ap);

			flags |= security_from_dict (g_value_get_boxed (variant));
			nm_ap_set_wpa_flags (ap, flags);
		} else if (!strcmp (key, "RSN")) {
			NM80211ApSecurityFlags flags = nm_ap_get_rsn_flags (ap);

			flags |= security_from_dict (g_value_get_boxed (variant));
			nm_ap_set_rsn_flags (ap, flags);
		}
	} else if (G_VALUE_HOLDS_UINT (variant)) {
		guint32 val = g_value_get_uint (variant);

		if (!strcmp (key, "Frequency"))
			nm_ap_set_freq (ap, val);
	} else if (G_VALUE_HOLDS_INT (variant)) {
		gint val = g_value_get_int (variant);

		if (!strcmp (key, "Signal"))
			nm_ap_set_strength (ap, nm_ap_utils_level_to_quality (val));
	} else if (G_VALUE_HOLDS_STRING (variant)) {
		const char *val = g_value_get_string (variant);

		if (val && !strcmp (key, "Mode")) {
			if (strcmp (val, "infrastructure") == 0)
				nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
			else if (strcmp (val, "ad-hoc") == 0)
				nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
		}
	} else if (G_VALUE_HOLDS_BOOLEAN (variant)) {
		gboolean val = g_value_get_boolean (variant);

		if (strcmp (key, "Privacy") == 0) {
			if (val) {
				NM80211ApFlags flags = nm_ap_get_flags (ap);
				nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY);
			}
		}
	}
}
static gboolean
validate_opt (const char *detail,
              GHashTable *hash,
              const char *key,
              OptType val_type,
              gconstpointer expected,
              size_t expected_len)
{
	GValue *value;
	gint int_val;
	GByteArray *array;
	const char *s;
	const unsigned char *expected_array = expected;
	int result;

	ASSERT (hash != NULL, detail, "hash was NULL");

	value = g_hash_table_lookup (hash, key);
	ASSERT (value != NULL,
	        detail, "option '%s' expected but not found in config hash.");

	switch (val_type) {
	case TYPE_INT:
		ASSERT (G_VALUE_HOLDS_INT (value),
		        detail, "config hash item '%s' was not TYPE_INT.", key);
		int_val = g_value_get_int (value);
		ASSERT (int_val == GPOINTER_TO_INT (expected),
		        detail, "unexpected config hash item '%s' value %d (expected %d)",
		        key, int_val, GPOINTER_TO_INT (expected));
		break;
	case TYPE_BYTES:
		ASSERT (G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY),
		        detail, "config hash item '%s' was not TYPE_BYTES.", key);
		array = g_value_get_boxed (value);
		ASSERT (array->len == expected_len,
		        detail, "unexpected config hash item '%s' length %d (expected %d)",
		        key, array->len, expected_len);
		result = memcmp (array->data, expected_array, expected_len);
		ASSERT (result == 0, detail, "unexpected config hash item '%s' value", key);
		break;
	case TYPE_KEYWORD:
	case TYPE_STRING:
		ASSERT (G_VALUE_HOLDS_STRING (value),
		        detail, "config hash item '%s' was not TYPE_STRING or TYPE_KEYWORD.", key);
		if (expected_len == -1)
			expected_len = strlen ((const char *) expected);
		s = g_value_get_string (value);
		ASSERT (s != NULL, detail, "unexpected NULL config hash string item '%s'.", key);
		ASSERT (strlen (s) == expected_len,
		        detail, "unexpected config hash string item '%s' length %d (expected %d)",
		        key, strlen (s), expected_len);
		result = strcmp (s, (const char *) expected);
		ASSERT (result == 0,
		        detail, "unexpected config hash string item '%s' value '%s' (expected '%s')",
		        key, s, (const char *) expected);
		break;
	default:
		g_warning ("unknown supplicant config hash item '%s' option type %d",
		           key, val_type);
		return FALSE;
	}

	return TRUE;
}
Пример #25
0
/*
 * cheese_camera_device_update_format_table:
 * @device: a #CheeseCameraDevice
 *
 * Clear the current list of video formats supported by the @device and create
 * it anew.
 */
static void
cheese_camera_device_update_format_table (CheeseCameraDevice *device)
{
  CheeseCameraDevicePrivate *priv = device->priv;

  guint i;
  guint num_structures;

  free_format_list (device);

  num_structures = gst_caps_get_size (priv->caps);
  for (i = 0; i < num_structures; i++)
  {
    GstStructure *structure;
    const GValue *width, *height, *framerate;
    structure = gst_caps_get_structure (priv->caps, i);

    width  = gst_structure_get_value (structure, "width");
    height = gst_structure_get_value (structure, "height");
    framerate = gst_structure_get_value (structure, "framerate");

    if (G_VALUE_HOLDS_INT (width))
    {
      CheeseVideoFormatFull *format = g_slice_new0 (CheeseVideoFormatFull);

      gst_structure_get_int (structure, "width", &(format->width));
      gst_structure_get_int (structure, "height", &(format->height));
      cheese_camera_device_add_format (device, format, framerate);
    }
    else if (GST_VALUE_HOLDS_INT_RANGE (width))
    {
      gint min_width, max_width, min_height, max_height;
      gint cur_width, cur_height;

      min_width  = gst_value_get_int_range_min (width);
      max_width  = gst_value_get_int_range_max (width);
      min_height = gst_value_get_int_range_min (height);
      max_height = gst_value_get_int_range_max (height);

      /* Some devices report a very small min_width / height down to reporting
       * 0x0 as minimum resolution, which causes an infinte loop below, limit
       * these to something reasonable. */
      if (min_width < 160)
        min_width = 160;
      if (min_height < 120)
        min_height = 120;

      cur_width  = min_width;
      cur_height = min_height;

      /* Gstreamer will sometimes give us a range with min_xxx == max_xxx,
       * we use <= here (and not below) to make this work */
      while (cur_width <= max_width && cur_height <= max_height)
      {
        CheeseVideoFormatFull *format = g_slice_new0 (CheeseVideoFormatFull);

        /* Gstreamer wants resolutions for YUV formats where the width is
         * a multiple of 8, and the height is a multiple of 2 */
        format->width  = cur_width & ~7;
        format->height = cur_height & ~1;

        cheese_camera_device_add_format (device, format, framerate);

        cur_width  *= 2;
        cur_height *= 2;
      }

      cur_width  = max_width;
      cur_height = max_height;
      while (cur_width > min_width && cur_height > min_height)
      {
        CheeseVideoFormatFull *format = g_slice_new0 (CheeseVideoFormatFull);

        /* Gstreamer wants resolutions for YUV formats where the width is
         * a multiple of 8, and the height is a multiple of 2 */
        format->width  = cur_width & ~7;
        format->height = cur_height & ~1;

        cheese_camera_device_add_format (device, format, framerate);

        cur_width  /= 2;
        cur_height /= 2;
      }
    }
    else
    {
      g_critical ("GValue type %s, cannot be handled for resolution width", G_VALUE_TYPE_NAME (width));
    }
  }
}
Пример #26
0
static void
clutter_shader_effect_update_uniforms (ClutterShaderEffect *effect)
{
  ClutterShaderEffectPrivate *priv = effect->priv;
  GHashTableIter iter;
  gpointer key, value;
  gsize size;

  if (priv->program == COGL_INVALID_HANDLE)
    return;

  if (priv->uniforms == NULL)
    return;

  key = value = NULL;
  g_hash_table_iter_init (&iter, priv->uniforms);
  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      ShaderUniform *uniform = value;

      if (uniform->location == -1)
        uniform->location = cogl_program_get_uniform_location (priv->program,
                                                               uniform->name);

      if (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (&uniform->value))
        {
          const GLfloat *floats;

          floats = clutter_value_get_shader_float (&uniform->value, &size);
          cogl_program_set_uniform_float (priv->program, uniform->location,
                                          size, 1,
                                          floats);
        }
      else if (CLUTTER_VALUE_HOLDS_SHADER_INT (&uniform->value))
        {
          const GLint *ints;

          ints = clutter_value_get_shader_int (&uniform->value, &size);
          cogl_program_set_uniform_int (priv->program, uniform->location,
                                        size, 1,
                                        ints);
        }
      else if (CLUTTER_VALUE_HOLDS_SHADER_MATRIX (&uniform->value))
        {
          const GLfloat *matrix;

          matrix = clutter_value_get_shader_matrix (&uniform->value, &size);
          cogl_program_set_uniform_matrix (priv->program, uniform->location,
                                           size, 1,
                                           FALSE,
                                           matrix);
        }
      else if (G_VALUE_HOLDS_FLOAT (&uniform->value))
        {
          const GLfloat float_val = g_value_get_float (&uniform->value);

          cogl_program_set_uniform_float (priv->program, uniform->location,
                                          1, 1,
                                          &float_val);
        }
      else if (G_VALUE_HOLDS_DOUBLE (&uniform->value))
        {
          const GLfloat float_val =
            (GLfloat) g_value_get_double (&uniform->value);

          cogl_program_set_uniform_float (priv->program, uniform->location,
                                          1, 1,
                                          &float_val);
        }
      else if (G_VALUE_HOLDS_INT (&uniform->value))
        {
          const GLint int_val = g_value_get_int (&uniform->value);

          cogl_program_set_uniform_int (priv->program, uniform->location,
                                        1, 1,
                                        &int_val);
        }
      else
        g_warning ("Invalid uniform of type '%s' for name '%s'",
                   g_type_name (G_VALUE_TYPE (&uniform->value)),
                   uniform->name);
    }
}
Пример #27
0
GVariant *
g_settings_set_mapping (const GValue       *value,
                        const GVariantType *expected_type,
                        gpointer            user_data)
{
  gchar *type_string;

  if (G_VALUE_HOLDS_BOOLEAN (value))
    {
      if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BOOLEAN))
        return g_variant_new_boolean (g_value_get_boolean (value));
    }

  else if (G_VALUE_HOLDS_CHAR (value)  ||
           G_VALUE_HOLDS_UCHAR (value))
    {
      if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTE))
        {
          if (G_VALUE_HOLDS_CHAR (value))
            return g_variant_new_byte (g_value_get_char (value));
          else
            return g_variant_new_byte (g_value_get_uchar (value));
        }
    }

  else if (G_VALUE_HOLDS_INT (value)   ||
           G_VALUE_HOLDS_INT64 (value))
    return g_settings_set_mapping_int (value, expected_type);

  else if (G_VALUE_HOLDS_DOUBLE (value))
    return g_settings_set_mapping_float (value, expected_type);

  else if (G_VALUE_HOLDS_UINT (value)  ||
           G_VALUE_HOLDS_UINT64 (value))
    return g_settings_set_mapping_unsigned_int (value, expected_type);

  else if (G_VALUE_HOLDS_STRING (value))
    {
      if (g_value_get_string (value) == NULL)
        return NULL;
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_STRING))
        return g_variant_new_string (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTESTRING))
        return g_variant_new_bytestring (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_OBJECT_PATH))
        return g_variant_new_object_path (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_SIGNATURE))
        return g_variant_new_signature (g_value_get_string (value));
    }

  else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
    {
      if (g_value_get_boxed (value) == NULL)
        return NULL;
      return g_variant_new_strv ((const gchar **) g_value_get_boxed (value),
                                 -1);
    }

  else if (G_VALUE_HOLDS_ENUM (value))
    {
      GEnumValue *enumval;
      GEnumClass *eclass;

      /* GParamSpecEnum holds a ref on the class so we just peek... */
      eclass = g_type_class_peek (G_VALUE_TYPE (value));
      enumval = g_enum_get_value (eclass, g_value_get_enum (value));

      if (enumval)
        return g_variant_new_string (enumval->value_nick);
      else
        return NULL;
    }

  else if (G_VALUE_HOLDS_FLAGS (value))
    {
      GVariantBuilder builder;
      GFlagsValue *flagsval;
      GFlagsClass *fclass;
      guint flags;

      fclass = g_type_class_peek (G_VALUE_TYPE (value));
      flags = g_value_get_flags (value);

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
      while (flags)
        {
          flagsval = g_flags_get_first_value (fclass, flags);

          if (flagsval == NULL)
            {
              g_variant_builder_clear (&builder);
              return NULL;
            }

          g_variant_builder_add (&builder, "s", flagsval->value_nick);
          flags &= ~flagsval->value;
        }

      return g_variant_builder_end (&builder);
    }

  type_string = g_variant_type_dup_string (expected_type);
  g_critical ("No GSettings bind handler for type \"%s\".", type_string);
  g_free (type_string);

  return NULL;
}
static void
foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
{
	GValue *variant = (GValue *) value;
	NMAccessPoint *ap = (NMAccessPoint *) user_data;

	if (G_VALUE_HOLDS_BOXED (variant)) {
		GArray *array = g_value_get_boxed (variant);

		if (!strcmp (key, "ssid")) {
			guint32 len = MIN (IW_ESSID_MAX_SIZE, array->len);
			GByteArray * ssid;

			/* Stupid ieee80211 layer uses <hidden> */
			if (((len == 8) || (len == 9))
				&& (memcmp (array->data, "<hidden>", 8) == 0))
				return;

			if (nm_utils_is_empty_ssid ((const guint8 *) array->data, len))
				return;

			ssid = g_byte_array_sized_new (len);
			g_byte_array_append (ssid, (const guint8 *) array->data, len);
			nm_ap_set_ssid (ap, ssid);
			g_byte_array_free (ssid, TRUE);
		} else if (!strcmp (key, "bssid")) {
			struct ether_addr addr;

			if (array->len != ETH_ALEN)
				return;
			memset (&addr, 0, sizeof (struct ether_addr));
			memcpy (&addr, array->data, ETH_ALEN);
			nm_ap_set_address (ap, &addr);
		} else if (!strcmp (key, "wpaie")) {
			guint8 * ie = (guint8 *) array->data;
			guint32 flags = nm_ap_get_wpa_flags (ap);

			if (array->len <= 0 || array->len > WPA_MAX_IE_LEN)
				return;
			flags = nm_ap_add_security_from_ie (flags, ie, array->len);
			nm_ap_set_wpa_flags (ap, flags);
		} else if (!strcmp (key, "rsnie")) {
			guint8 * ie = (guint8 *) array->data;
			guint32 flags = nm_ap_get_rsn_flags (ap);

			if (array->len <= 0 || array->len > WPA_MAX_IE_LEN)
				return;
			flags = nm_ap_add_security_from_ie (flags, ie, array->len);
			nm_ap_set_rsn_flags (ap, flags);
		}
	} else if (G_VALUE_HOLDS_INT (variant)) {
		gint32 int_val = g_value_get_int (variant);

		if (!strcmp (key, "frequency")) {
			nm_ap_set_freq (ap, (guint32) int_val);
		} else if (!strcmp (key, "maxrate")) {
			/* Supplicant reports as b/s, we use Kb/s internally */
			nm_ap_set_max_bitrate (ap, int_val / 1000);
		}
	} else if (G_VALUE_HOLDS_UINT (variant)) {
		guint32 val = g_value_get_uint (variant);

		if (!strcmp (key, "capabilities")) {
			if (val & IEEE80211_CAP_ESS) {
				nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
			} else if (val & IEEE80211_CAP_IBSS) {
				nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
			}

			if (val & IEEE80211_CAP_PRIVACY) {
				guint32 flags = nm_ap_get_flags (ap);
				nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY);
			}
		}
	}
}
Пример #29
0
// TODO: gets formats for cameras, when a format return a range it gets
// in steps /2 and *2 from min to max, for format7 it should be free to get any size
static void
get_supported_video_formats (ofGstDevice &webcam_device, GstCaps &caps)
{
    int i;
    int num_structures;

    num_structures = gst_caps_get_size (&caps);
    for (i = 0; i < num_structures; i++)
    {
        GstStructure *structure;
        const GValue *width, *height;
        structure = gst_caps_get_structure (&caps, i);

        width  = gst_structure_get_value (structure, "width");
        height = gst_structure_get_value (structure, "height");

        if (G_VALUE_HOLDS_INT (width))
        {
            ofGstVideoFormat * video_format = new ofGstVideoFormat;

            video_format->mimetype = g_strdup (gst_structure_get_name (structure));
            gst_structure_get_int (structure, "width", &(video_format->width));
            gst_structure_get_int (structure, "height", &(video_format->height));
            add_video_format(webcam_device, video_format, *structure);
        }
        else if (GST_VALUE_HOLDS_INT_RANGE (width))
        {
            int min_width, max_width, min_height, max_height;
            int cur_width, cur_height;

            min_width  = gst_value_get_int_range_min (width);
            max_width  = gst_value_get_int_range_max (width);
            min_height = gst_value_get_int_range_min (height);
            max_height = gst_value_get_int_range_max (height);

            cur_width  = min_width;
            cur_height = min_height;
            /* Gstreamer will sometimes give us a range with min_xxx == max_xxx,
             we use <= here (and not below) to make this work */
            while (cur_width <= max_width && cur_height <= max_height)
            {
                ofGstVideoFormat * video_format = new ofGstVideoFormat;

                video_format->mimetype = g_strdup (gst_structure_get_name (structure));
                video_format->width    = cur_width;
                video_format->height   = cur_height;
                add_video_format(webcam_device, video_format, *structure);
                cur_width  *= 2;
                cur_height *= 2;
            }

            cur_width  = max_width;
            cur_height = max_height;
            while (cur_width > min_width && cur_height > min_height)
            {
                ofGstVideoFormat * video_format = new ofGstVideoFormat;

                video_format->mimetype = g_strdup (gst_structure_get_name (structure));
                video_format->width    = cur_width;
                video_format->height   = cur_height;
                add_video_format(webcam_device, video_format, *structure);
                cur_width  /= 2;
                cur_height /= 2;
            }
        }
        else
        {
            g_critical ("GValue type %s, cannot be handled for resolution width", G_VALUE_TYPE_NAME (width));
        }
    }

    /* Sort the format array (so that it will show sorted in the resolution
    selection GUI), and rebuild the hashtable (as that will be invalid after
    the sorting) */
    sort (webcam_device.video_formats.begin(), webcam_device.video_formats.end(), resolution_compare);
    g_hash_table_remove_all (webcam_device.supported_resolutions);
    for (i = 0; i < webcam_device.num_video_formats; i++) {
        ofGstVideoFormat * format = webcam_device.video_formats[i];

        g_hash_table_insert (webcam_device.supported_resolutions,
                             g_strdup_printf ("%ix%i", format->width,
                                              format->height),
                             GINT_TO_POINTER(i + 1));
    }
}