示例#1
0
static gboolean
data_model_errors_remove_row (GdaDataModel *model, gint row, GError **error)
{
	DataModelErrors *imodel;

	g_return_val_if_fail (IS_DATA_MODEL_ERRORS (model), FALSE);
	imodel = (DataModelErrors *) model;
	g_return_val_if_fail (imodel->priv, FALSE);

	if (row >= (gint)imodel->priv->rows->len) {
		gchar *str;
		if (imodel->priv->rows->len > 0)
			str = g_strdup_printf ("Row %d out of range (0-%d)", row,
					       imodel->priv->rows->len - 1);
		else
			str = g_strdup_printf ("Row %d not found (empty data model)", row);
		g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s", str);
		g_free (str);
                return FALSE;
        }

	GdaRow *drow;
	drow =  g_ptr_array_index (imodel->priv->rows, row);
	/* remove row from data model */
	g_object_unref (drow);
	g_ptr_array_remove_index (imodel->priv->rows, row);
	gda_data_model_row_removed (model, row);
	
	return TRUE;
}
static void
update_data_model (GdaDataModelDir *model)
{	gsize i;
	model->priv->upd_row = -1;
	update_data_model_real (model, "");

	/* clean extra rows */

	for (i = model->priv->upd_row + 1; i < model->priv->rows->len; i++) {
		FileRow *row = g_ptr_array_index (model->priv->rows, model->priv->rows->len - 1);
		file_row_free (row);
		g_ptr_array_remove_index (model->priv->rows, model->priv->rows->len - 1);
		gda_data_model_row_removed ((GdaDataModel *) model, model->priv->rows->len - 1);
	}
}
示例#3
0
static void
model_row_removed_cb (G_GNUC_UNUSED GdaDataModel *mod, gint row, GdaDataAccessWrapper *model)
{
	gda_data_model_row_removed ((GdaDataModel*) model, row);
}
static gboolean
gda_data_model_dir_remove_row (GdaDataModel *model, gint row, GError **error)
{
	GdaDataModelDir *imodel;
	gchar *filename;
	FileRow *frow;

	g_return_val_if_fail (GDA_IS_DATA_MODEL_DIR (model), FALSE);
	g_return_val_if_fail (row >=0, FALSE);
	imodel = (GdaDataModelDir *) model;
	g_return_val_if_fail (imodel->priv, FALSE);

	if ((guint)row >= imodel->priv->rows->len) {
		gchar *str;
		if (imodel->priv->rows->len > 0)
			str = g_strdup_printf (_("Row %d out of range (0-%d)"), row,
					       imodel->priv->rows->len - 1);
		else
			str = g_strdup_printf (_("Row %d not found (empty data model)"), row);
		add_error (imodel, str);
		g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
			     "%s", str);
		g_free (str);
                return FALSE;
        }

	frow =  g_ptr_array_index (imodel->priv->rows, row);

	/* remove filename */
	filename = g_build_filename (imodel->priv->basedir,
				     frow->reldir,
				     frow->raw_filename_value ? frow->raw_filename_value :
				     g_value_get_string (frow->filename_value), NULL);
	if (g_unlink (filename)) {
		gchar *str;
		str = g_strdup_printf (_("Cannot remove file '%s'"), filename);
		add_error (imodel, str);
		g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
			     "%s", str);
		g_free (str);
		g_free (filename);
		return FALSE;
	}
	g_free (filename);

	/* remove dir */
#ifndef G_OS_WIN32
	gchar *path;

	path = g_build_path (G_DIR_SEPARATOR_S, imodel->priv->basedir,
			     frow->reldir, NULL);
	g_rmdir (path);
	g_free (path);
#endif

	/* remove row from data model */
	file_row_free (frow);
	g_ptr_array_remove_index (imodel->priv->rows, row);
	gda_data_model_row_removed (model, row);

	return TRUE;
}