Ejemplo n.º 1
0
void
ghb_settings_set_int(GValue *settings, const gchar *key, gint ival)
{
    GValue *value;
    value = ghb_int64_value_new((gint64)ival);
    ghb_dict_insert(settings, g_strdup(key), value);
}
Ejemplo n.º 2
0
static void
end_element(
	GMarkupParseContext *ctx, 
	const gchar *name, 
	gpointer ud,
	GError **error)
{
	parse_data_t *pd = (parse_data_t*)ud;
	gint id;
	union 
	{
		gint id;
		gpointer pid;
	} start_id;
	gint ii;

	// Check to see if the first element found has been closed
	// If so, ignore any junk following it.
	if (pd->closed_top)
		return;

	for (ii = 0; ii < TAG_MAP_SZ; ii++)
	{
		if (strcmp(name, tag_map[ii].tag) == 0)
		{
			id = tag_map[ii].id;
			break;
		}
	}
	if (ii == TAG_MAP_SZ)
	{
		g_warning("Unrecognized start tag (%s)", name);
		return;
	}
	start_id.pid = g_queue_pop_head(pd->tag_stack);
	if (start_id.id != id)
		g_warning("start tag != end tag: (%s %d) %d", name, id, id);

	GValue *gval = NULL;
	GValue *current = g_queue_peek_head(pd->stack);
	GType gtype = 0;
	switch (id)
	{
		case P_PLIST:
		{ // Ignore
		} break;
		case P_KEY:
		{
			if (pd->key) g_free(pd->key);
			pd->key = g_strdup(pd->value);
			return;
		} break;
		case P_DICT:
		{
			g_queue_pop_head(pd->stack);
		} break;
		case P_ARRAY:
		{
			g_queue_pop_head(pd->stack);
		} break;
		case P_INTEGER:
		{
			gint64 val = g_strtod(pd->value, NULL);
			gval = ghb_int64_value_new(val);
		} break;
		case P_REAL:
		{
			gdouble val = g_strtod(pd->value, NULL);
			gval = ghb_double_value_new(val);
		} break;
		case P_STRING:
		{
			gval = ghb_string_value_new(pd->value);
		} break;
		case P_DATE:
		{
			GDate date;
			GTimeVal time;
			g_time_val_from_iso8601(pd->value, &time);
			g_date_set_time_val(&date, &time);
			gval = ghb_date_value_new(&date);
		} break;
		case P_TRUE:
		{
			gval = ghb_boolean_value_new(TRUE);
		} break;
		case P_FALSE:
		{
			gval = ghb_boolean_value_new(FALSE);
		} break;
		case P_DATA:
		{
			ghb_rawdata_t *data;
			data = g_malloc(sizeof(ghb_rawdata_t));
			data->data = g_base64_decode(pd->value, &(data->size));
			gval = ghb_rawdata_value_new(data);
		} break;
	}
	if (gval)
	{
		// Get the top of the data structure stack and if it's an array
		// or dict, add the current element
		if (current == NULL)
		{
			pd->plist = gval;
			pd->closed_top = TRUE;
			return;
		}
		gtype = G_VALUE_TYPE(current);
		if (gtype == ghb_array_get_type())
		{
			ghb_array_append(current, gval);
		}
		else if (gtype == ghb_dict_get_type())
		{
			if (pd->key == NULL)
			{
				g_warning("No key for dictionary item");
				ghb_value_free(gval);
			}
			else
			{
				ghb_dict_insert(current, g_strdup(pd->key), gval);
			}
		}
		else
		{
			g_error("Invalid container type. This shouldn't happen");
		}
	}
	if (g_queue_is_empty(pd->stack))
		pd->closed_top = TRUE;
}
Ejemplo n.º 3
0
GValue*
ghb_widget_value(GtkWidget *widget)
{
    GValue *value = NULL;
    const gchar *name;
    GType type;

    if (widget == NULL)
    {
        g_debug("NULL widget\n");
        return NULL;
    }

    type = G_OBJECT_TYPE(widget);
    name = ghb_get_setting_key(widget);
    g_debug("ghb_widget_value widget (%s)\n", name);
    if (type == GTK_TYPE_ENTRY)
    {
        const gchar *str = gtk_entry_get_text(GTK_ENTRY(widget));
        value = ghb_string_value_new(str);
    }
    else if (type == GTK_TYPE_RADIO_BUTTON)
    {
        g_debug("\tradio_button");
        gboolean bval;
        bval = gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON(widget));
        if (bval)
        {
            value = ghb_boolean_value_new(FALSE);
        }
        else
        {
            bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
            value = ghb_boolean_value_new(bval);
        }
    }
    else if (type == GTK_TYPE_CHECK_BUTTON)
    {
        g_debug("\tcheck_button");
        gboolean bval;
        bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_TOGGLE_TOOL_BUTTON)
    {
        g_debug("\ttoggle_tool_button");
        gboolean bval;
        bval = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_TOGGLE_BUTTON)
    {
        g_debug("\ttoggle_button");
        gboolean bval;
        bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_CHECK_MENU_ITEM)
    {
        g_debug("\tcheck_menu_item");
        gboolean bval;
        bval = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
        value = ghb_boolean_value_new(bval);
    }
    else if (type == GTK_TYPE_COMBO_BOX)
    {
        g_debug("\tcombo_box");
        GtkTreeModel *store;
        GtkTreeIter iter;
        gchar *shortOpt;

        store = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
        if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter))
        {
            gtk_tree_model_get(store, &iter, 2, &shortOpt, -1);
            value = ghb_string_value_new(shortOpt);
            g_free(shortOpt);
        }
        else if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(widget)))
        {
            const gchar *str;
            str = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(widget))));
            if (str == NULL) str = "";
            value = ghb_string_value_new(str);
        }
        else
        {
            value = ghb_string_value_new("");
        }
    }
    else if (type == GTK_TYPE_SPIN_BUTTON)
    {
        gint ival;
        ival = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
        value = ghb_int64_value_new(ival);
    }
    else if (type == GTK_TYPE_SCALE)
    {
        gdouble dval;
        gint digits;

        digits = gtk_scale_get_digits(GTK_SCALE(widget));
        dval = gtk_range_get_value(GTK_RANGE(widget));
        if (digits)
        {
            value = ghb_double_value_new(dval);
        }
        else
        {
            value = ghb_int_value_new(dval);
        }
    }
    else if (type == GTK_TYPE_SCALE_BUTTON)
    {
        gdouble dval;

        dval = gtk_scale_button_get_value(GTK_SCALE_BUTTON(widget));
        value = ghb_double_value_new(dval);
    }
    else if (type == GTK_TYPE_TEXT_VIEW)
    {
        GtkTextBuffer *buffer;
        GtkTextIter start, end;
        gchar *str;

        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
        gtk_text_buffer_get_bounds(buffer, &start, &end);
        str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
        value = ghb_string_value_new(str);
        g_free(str);
    }
    else if (type == GTK_TYPE_LABEL)
    {
        const gchar *str;
        str = gtk_label_get_text (GTK_LABEL(widget));
        value = ghb_string_value_new(str);
    }
    else if (type == GTK_TYPE_FILE_CHOOSER_BUTTON)
    {
        gchar *str = NULL;
        str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(widget));
        if (str == NULL)
        {
            str = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(widget));
        }
        value = ghb_string_value_new(str);
        if (str != NULL)
            g_free(str);
    }
    else
    {
        g_debug("Attempt to set unknown widget type: %s\n", name);
        g_free(value);
        value = NULL;
    }
    return value;
}