All pastes #168785 Raw Edit

Casanova

public text v1 · immutable
·published 2006-09-13 09:41 UTC
rendered paste body
static LDTPError*
select_row (Accessible *object, GSList *l, FILE *log_fp)
{
	long i, j;
	gboolean flag = FALSE;
	LDTPError *error;
	long n_rows, n_cols;
	Accessible *cell;
	AccessibleTable *table;
	char *name = NULL;
	char *row_text = l->data;
	long n_matches = 0;

	l = l->next;
	if (l && l->data)
		n_matches = atol (l->data);
    
	table = Accessible_getTable (object);
	n_rows = AccessibleTable_getNRows (table);
	n_cols = AccessibleTable_getNColumns (table);
	g_print ("Number of rows: %ld\tColumn: %ld\tMatch index: %ld\n", n_rows, n_cols, n_matches);

	for (i = 0; i < n_rows; i++) {
		for (j = 0; j < n_cols; j++) {
			long child_count;
			cell = AccessibleTable_getAccessibleAt (table, i, j);
			child_count = Accessible_getChildCount (cell);
			if (child_count > 0) {
				long k;
				Accessible *child;
				for (k = 0; k < child_count; k++) {
					child = Accessible_getChildAtIndex (cell, k);
					name = Accessible_getName (child);
					if (name)
						g_print ("Table cell Name: %s\n", name);
					if (g_utf8_collate (name, row_text) == 0) {
						if (n_matches != 0) { 
							n_matches--;
							Accessible_unref (child);
							SPI_freeString(name);
							continue;
						}
						if (Accessible_isComponent (cell)) {
							AccessibleComponent *accessible_component;
							accessible_component = Accessible_getComponent (cell);
							if (!AccessibleComponent_grabFocus (accessible_component)) {
								Accessible_unref (accessible_component);
								Accessible_unref (child);
								Accessible_unref (cell);
								error = ldtp_error_get_error (LDTP_ERROR_UNABLE_TO_GRAB_FOCUS);
								log_msg (LDTP_LOG_CAUSE, error->message, log_fp);
								SPI_freeString(name);
								return error;
							}
							Accessible_unref (accessible_component);
						}
						SPI_freeString (name);
						Accessible_unref (child);
						Accessible_unref (cell);
						flag = TRUE;
						break;
					} // if
					SPI_freeString (name);
					Accessible_unref (child);
				} // for
			} // if
			else {
				name = Accessible_getName (cell);
				if (g_utf8_collate (name, row_text) == 0) {
					if (n_matches != 0) { 
						n_matches--;
						Accessible_unref (cell);
						SPI_freeString(name);
						continue;
					}

					if (Accessible_isComponent (cell)) {
						AccessibleComponent *accessible_component;
						accessible_component = Accessible_getComponent (cell);
						if (!AccessibleComponent_grabFocus (accessible_component)) {
							Accessible_unref (accessible_component);
							Accessible_unref (cell);
							error = ldtp_error_get_error (LDTP_ERROR_UNABLE_TO_GRAB_FOCUS);
							log_msg (LDTP_LOG_CAUSE, error->message, log_fp);
							return error;
						}
						Accessible_unref (accessible_component);
					}
					SPI_freeString (name);
					Accessible_unref (cell);
					flag = TRUE;
					break;
				}
			}
			Accessible_unref (cell);
		} // for j
		if (flag == TRUE)
			break;
	} // for i
  
	Accessible_unref (table);
	if (flag == FALSE) {
		error = ldtp_error_get_error (LDTP_ERROR_UNABLE_TO_SELECT_ROW);
		log_msg (LDTP_LOG_CAUSE, error->message, log_fp);
		return error;
	}
	return ldtp_error_get_error (LDTP_ERROR_SUCCESS);
}