static void
relativeTimeCriteriaSetWidgetData (GtkWidget *widget, GValue *val)
{
	GtkBox *box = GTK_BOX (widget);

	GtkSpinButton *timeSpin = GTK_SPIN_BUTTON (get_box_widget_at_pos (box, 0));
	GtkComboBox *unitMenu = GTK_COMBO_BOX (get_box_widget_at_pos (box, 1));

	gulong time = g_value_get_ulong (val);
	gulong unit = 0;
	int i;

	/* determine the best units to use for the given value */
	for (i = 0; i < G_N_ELEMENTS(time_unit_options); i++) {
		/* find out if the time is an even multiple of the unit */
		if (time % time_unit_options[i].timeMultiplier == 0)
			unit = i;
	}

	time = time / time_unit_options[unit].timeMultiplier;
	g_assert (time < G_MAXINT);
	/* set the time value and unit*/
	gtk_combo_box_set_active (unitMenu, unit);
	gtk_spin_button_set_value (timeSpin, time);
}
Exemplo n.º 2
0
/**
 * rb_query_creator_get_query:
 * @creator: #RBQueryCreator instance
 *
 * Constructs a database query that represents the criteria in the query creator.
 *
 * Return value: (transfer full): database query array
 */
GPtrArray *
rb_query_creator_get_query (RBQueryCreator *creator)
{
	RBQueryCreatorPrivate *priv;
	GPtrArray *query;
	GPtrArray *sub_query;
	GList *rows, *row;
	gboolean disjunction;

	g_return_val_if_fail (RB_IS_QUERY_CREATOR (creator), NULL);

	priv = QUERY_CREATOR_GET_PRIVATE (creator);

	disjunction = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->disjunction_check));
	sub_query = g_ptr_array_new ();
	rows = priv->rows;

	for (row = rows; row; row = row->next) {
		GtkComboBox *propmenu = GTK_COMBO_BOX (get_box_widget_at_pos (GTK_BOX (row->data),
										  0));
		GtkComboBox *criteria_menu = GTK_COMBO_BOX (get_box_widget_at_pos (GTK_BOX (row->data),
										       1));
		guint prop_position = gtk_combo_box_get_active (propmenu);
		const RBQueryCreatorPropertyOption *prop_option = &property_options[prop_position];
		const RBQueryCreatorCriteriaOption *criteria_options = prop_option->property_type->criteria_options;
		const RBQueryCreatorCriteriaOption *criteria_option = &criteria_options[gtk_combo_box_get_active (criteria_menu)];

		g_assert (prop_option->property_type->criteria_get_widget_data != NULL);
		{
			RhythmDBQueryData *data = g_new0 (RhythmDBQueryData, 1);
			GValue *val = g_new0 (GValue, 1);

			data->type = criteria_option->val;
			data->propid = criteria_option->strict ? prop_option->strict_val : prop_option->fuzzy_val;

			prop_option->property_type->criteria_get_widget_data (get_box_widget_at_pos (GTK_BOX (row->data), 2), val);
			data->val = val;

			g_ptr_array_add (sub_query, data);
			}

			if (disjunction && row->next)
				rhythmdb_query_append (priv->db,
						       sub_query,
						       RHYTHMDB_QUERY_DISJUNCTION,
						       RHYTHMDB_QUERY_END);
		}
	query = rhythmdb_query_parse (priv->db,
				      /* type=songs */
				      RHYTHMDB_QUERY_PROP_EQUALS,
				      RHYTHMDB_PROP_TYPE,
				      RHYTHMDB_ENTRY_TYPE_SONG,
				      /* the constructed query */
                                      RHYTHMDB_QUERY_SUBQUERY,
                                      sub_query,
                                      RHYTHMDB_QUERY_END);
	return query;
}
static void
durationCriteriaSetWidgetData (GtkWidget *widget, GValue *val)
{
	GtkSpinButton *minutesSpinner = GTK_SPIN_BUTTON (get_box_widget_at_pos (GTK_BOX (widget), 0));
	GtkSpinButton *secondsSpinner = GTK_SPIN_BUTTON (get_box_widget_at_pos (GTK_BOX (widget), 2));

	gtk_spin_button_set_value (minutesSpinner, (gdouble) (g_value_get_ulong (val) / 60));
	gtk_spin_button_set_value (secondsSpinner, (gdouble) (g_value_get_ulong (val) % 60));
}
static void
relativeTimeCriteriaGetWidgetData (GtkWidget *widget, GValue *val)
{
	GtkSpinButton *timeSpin = GTK_SPIN_BUTTON (get_box_widget_at_pos (GTK_BOX (widget), 0));
	GtkComboBox *unitMenu = GTK_COMBO_BOX (get_box_widget_at_pos (GTK_BOX (widget), 1));

	gulong timeMultiplier = time_unit_options [gtk_combo_box_get_active (unitMenu)].timeMultiplier;
	gint value = gtk_spin_button_get_value_as_int (timeSpin) * timeMultiplier;
	g_assert (value >= 0);

	g_value_init (val, G_TYPE_ULONG);
	g_value_set_ulong (val, (gulong) value);
}
static void
durationCriteriaGetWidgetData (GtkWidget *widget, GValue *val)
{

	GtkSpinButton *minutesSpinner = GTK_SPIN_BUTTON (get_box_widget_at_pos (GTK_BOX (widget), 0));
	GtkSpinButton *secondsSpinner = GTK_SPIN_BUTTON (get_box_widget_at_pos (GTK_BOX (widget), 2));

	gint value = gtk_spin_button_get_value_as_int (minutesSpinner) * 60
		   + gtk_spin_button_get_value_as_int (secondsSpinner);
	g_assert (value >= 0);

	g_value_init (val, G_TYPE_ULONG);
	g_value_set_ulong (val, (gulong) value);
}
Exemplo n.º 6
0
static void
property_option_menu_changed (GtkComboBox *propmenu,
			      RBQueryCreator *creator)
{
	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
	GtkWidget *row;
	GtkWidget *criteria;
	GtkWidget *entry;
	const RBQueryCreatorPropertyOption *prop_option;
	const RBQueryCreatorCriteriaOption *criteria_options;
	guint length;
	guint old_value;
	gboolean constrain;

	prop_option = &property_options[gtk_combo_box_get_active (propmenu)];
	old_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (propmenu), "prop-menu old-value"));

	/* don't recreate the criteria menu and entry if they will be the same*/
	if (prop_option->property_type == property_options[old_value].property_type)
		return;

	g_object_set_data (G_OBJECT (propmenu), "prop-menu old-value",
			   GINT_TO_POINTER (gtk_combo_box_get_active (propmenu)));

	row = lookup_row_by_widget (creator, GTK_WIDGET (propmenu));

	criteria = get_box_widget_at_pos (GTK_BOX (row), 1);
	gtk_container_remove (GTK_CONTAINER (row), criteria);

	criteria_options = prop_option->property_type->criteria_options;
	length = prop_option->property_type->num_criteria_options;

	criteria = create_criteria_option_menu (criteria_options, length);
	gtk_widget_show (criteria);
	gtk_size_group_add_widget (priv->criteria_size_group, criteria);
	gtk_box_pack_start (GTK_BOX (row), GTK_WIDGET (criteria), TRUE, TRUE, 0);
	gtk_box_reorder_child (GTK_BOX (row), criteria, 1);

	entry = get_box_widget_at_pos (GTK_BOX (row), 2);
	gtk_container_remove (GTK_CONTAINER (row), entry);
	entry = get_entry_for_property (creator, prop_option->strict_val,
					&constrain);
	gtk_widget_show (entry);

	if (constrain)
		gtk_size_group_add_widget (priv->entry_size_group, entry);
	gtk_box_pack_start (GTK_BOX (row), GTK_WIDGET (entry), TRUE, TRUE, 0);
	gtk_box_reorder_child (GTK_BOX (row), entry, 2);
}
Exemplo n.º 7
0
static gboolean
rb_query_creator_load_query (RBQueryCreator *creator,
                             GPtrArray *query,
			     RhythmDBQueryModelLimitType limit_type,
                             GVariant *limit_value)
{
	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
	int i;
	GList *rows;
	gboolean disjunction = FALSE;
	RhythmDBQueryData *qdata;
	GPtrArray *subquery;
	guint64 limit;

	g_return_val_if_fail (query->len == 2, FALSE);

	qdata = g_ptr_array_index (query, 1);
	g_return_val_if_fail (qdata->type == RHYTHMDB_QUERY_SUBQUERY, FALSE);

	subquery = qdata->subquery;

	if (subquery->len > 0) {
		for (i = 0; i < subquery->len; i++) {
			RhythmDBQueryData *data = g_ptr_array_index (subquery, i);
			if (data->type != RHYTHMDB_QUERY_DISJUNCTION)
				append_row (creator);
		}
	}

	rows = priv->rows;

	for (i = 0; i < subquery->len; i++) {
		RhythmDBQueryData *data = g_ptr_array_index (subquery, i);
		GtkComboBox *propmenu;
		GtkWidget *criteria_menu;
		int index;
		const RBQueryCreatorPropertyType *property_type;

		if (data->type == RHYTHMDB_QUERY_DISJUNCTION) {
			disjunction = TRUE;
			continue;
		}

		propmenu = GTK_COMBO_BOX (get_box_widget_at_pos (GTK_BOX (rows->data), 0));
		index = get_property_index_from_proptype (property_options, num_property_options, data->propid);
		gtk_combo_box_set_active (propmenu, index);

		criteria_menu = get_box_widget_at_pos (GTK_BOX (rows->data), 1);
		select_criteria_from_value (creator, criteria_menu, data->propid, data->type);

		property_type = property_options[index].property_type;
		g_assert (property_type->criteria_set_widget_data != NULL);
		property_type->criteria_set_widget_data (get_box_widget_at_pos (GTK_BOX (rows->data), 2),
					      data->val);

		rows = rows->next;
	}

	/* setup the limits */
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->disjunction_check),
				      disjunction);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->limit_check),
				      limit_type != RHYTHMDB_QUERY_MODEL_LIMIT_NONE);

	switch (limit_type) {
	case RHYTHMDB_QUERY_MODEL_LIMIT_NONE:
		limit = 0;
		break;

	case RHYTHMDB_QUERY_MODEL_LIMIT_COUNT:
		gtk_combo_box_set_active (GTK_COMBO_BOX (priv->limit_option), 0);
		limit = g_variant_get_uint64 (limit_value);
		break;

	case RHYTHMDB_QUERY_MODEL_LIMIT_TIME:
		gtk_combo_box_set_active (GTK_COMBO_BOX (priv->limit_option), 3);
		/* convert to minutes */
		limit = g_variant_get_uint64 (limit_value) / 60;
		break;

	case RHYTHMDB_QUERY_MODEL_LIMIT_SIZE:
		limit = g_variant_get_uint64 (limit_value);

		if (limit % 1000 == 0) {
			gtk_combo_box_set_active (GTK_COMBO_BOX (priv->limit_option), 2);
			limit /= 1000;
		} else {
			gtk_combo_box_set_active (GTK_COMBO_BOX (priv->limit_option), 1);
		}

		break;
	default:
		g_assert_not_reached ();
	}

	gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->limit_entry), limit);

	return TRUE;
}