X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=gtk%2Fsrc%2Fvalues.c;h=17319a582ef3afc7f3b0b9863430671981fdf9e0;hb=0884cb45aeeb60a46effe1d1056a61fe68300ea7;hp=6013db8d8011090995df14d84d448a9ae342ec2b;hpb=e205b3e8ebcb560af77303c9c23957793e60ff20;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/gtk/src/values.c b/gtk/src/values.c index 6013db8d..17319a58 100644 --- a/gtk/src/values.c +++ b/gtk/src/values.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "values.h" static void dict_delete_key(gpointer data); @@ -45,7 +46,7 @@ ghb_value_dup(const GValue *val) return copy; } -static void +void debug_show_type(GType tp) { const gchar *str = "unknown"; @@ -61,6 +62,10 @@ debug_show_type(GType tp) { str ="int64"; } + else if (tp == G_TYPE_DOUBLE) + { + str ="double"; + } else if (tp == G_TYPE_BOOLEAN) { str ="bool"; @@ -73,7 +78,43 @@ debug_show_type(GType tp) { str ="dict"; } - g_debug("%s", str); + g_debug("Type %s", str); +} + +void +debug_show_value(GValue *gval) +{ + GType tp; + + tp = G_VALUE_TYPE(gval); + if (tp == G_TYPE_STRING) + { + g_message("Type %s value %s", "string", g_value_get_string(gval)); + } + else if (tp == G_TYPE_INT) + { + g_message("Type %s value %d", "int", g_value_get_int(gval)); + } + else if (tp == G_TYPE_INT64) + { + g_message("Type %s value %" PRId64, "int64", g_value_get_int64(gval)); + } + else if (tp == G_TYPE_DOUBLE) + { + g_message("Type %s value %f", "double", g_value_get_double(gval)); + } + else if (tp == G_TYPE_BOOLEAN) + { + g_message("Type %s value %d", "boolean", g_value_get_boolean(gval)); + } + else if (tp == ghb_array_get_type()) + { + g_message("Type %s", "boolean"); + } + else if (tp == ghb_dict_get_type()) + { + g_message("Type %s", "dict"); + } } gint @@ -83,21 +124,21 @@ ghb_value_int(const GValue *val) if (val == NULL) return 0; GValue xform = {0,}; - if (G_VALUE_TYPE(val) != G_TYPE_INT64) + if (G_VALUE_TYPE(val) != G_TYPE_INT) { - g_value_init(&xform, G_TYPE_INT64); + g_value_init(&xform, G_TYPE_INT); if (!g_value_transform(val, &xform)) { debug_show_type(G_VALUE_TYPE(val)); g_warning("int can't transform"); return 0; } - result = (gint)g_value_get_int64(&xform); + result = g_value_get_int(&xform); g_value_unset(&xform); } else { - result = (gint)g_value_get_int64(val); + result = g_value_get_int(val); } return result; } @@ -212,6 +253,10 @@ ghb_value_cmp(const GValue *vala, const GValue *valb) GType typa; GType typb; + if ((vala == NULL && valb != NULL) || (vala != NULL && valb == NULL)) + { + return 1; + } typa = G_VALUE_TYPE(vala); typb = G_VALUE_TYPE(valb); if (typa != typb) @@ -529,7 +574,7 @@ ghb_dict_iter_init(GHashTableIter *iter, GValue *gval) } GValue* -ghb_dict_lookup(GValue *gval, const gchar *key) +ghb_dict_lookup(const GValue *gval, const gchar *key) { GHashTable *dict = g_value_get_boxed(gval); return g_hash_table_lookup(dict, key); @@ -640,6 +685,34 @@ ghb_array_remove(GValue *gval, guint ii) g_value_take_boxed(gval, arr); } +void +ghb_array_replace(GValue *gval, guint ii, GValue *val) +{ + GArray *arr = g_value_get_boxed(gval); + // A little nastyness here. The array pointer + // can change when the array changes size. So + // I must re-box it in the GValue each time. + if (ii >= arr->len) return; + ghb_value_free(((GValue**)arr->data)[ii]); + ((GValue**)arr->data)[ii] = val; +} + +void +ghb_array_copy(GValue *arr1, GValue *arr2, gint count) +{ + gint len, ii; + + // empty the first array if it is not already empty + len = ghb_array_len(arr1); + for (ii = 0; ii < len; ii++) + ghb_array_remove(arr1, 0); + + len = ghb_array_len(arr2); + count = MIN(count, len); + for (ii = 0; ii < count; ii++) + ghb_array_append(arr1, ghb_value_dup(ghb_array_get_nth(arr2, ii))); +} + gint ghb_array_len(const GValue *gval) { @@ -651,16 +724,23 @@ ghb_array_len(const GValue *gval) static void xform_string_int(const GValue *sval, GValue *ival) { + gchar *end; + const gchar *str = g_value_get_string(sval); - gint val = g_strtod(str, NULL); + gint val = g_strtod(str, &end); + if (*end) + val = (guint)(~0)>>1; g_value_set_int(ival, val); } static void xform_string_int64(const GValue *sval, GValue *ival) { + gchar *end; const gchar *str = g_value_get_string(sval); - gint64 val = g_strtod(str, NULL); + gint64 val = g_strtod(str, &end); + if (*end) + val = (guint64)(~0L)>>1; g_value_set_int64(ival, val); }