inline static void
add_model (ETableSelectionModel *etsm,
           ETableModel *model)
{
	etsm->model = model;
	if (model) {
		g_object_ref (model);
		etsm->model_pre_change_id = g_signal_connect (
			model, "model_pre_change",
			G_CALLBACK (model_pre_change), etsm);
		etsm->model_changed_id = g_signal_connect (
			model, "model_changed",
			G_CALLBACK (model_changed), etsm);
		etsm->model_row_changed_id = g_signal_connect (
			model, "model_row_changed",
			G_CALLBACK (model_row_changed), etsm);
		etsm->model_cell_changed_id = g_signal_connect (
			model, "model_cell_changed",
			G_CALLBACK (model_cell_changed), etsm);
		etsm->model_rows_inserted_id = g_signal_connect (
			model, "model_rows_inserted",
			G_CALLBACK (model_rows_inserted), etsm);
		etsm->model_rows_deleted_id = g_signal_connect (
			model, "model_rows_deleted",
			G_CALLBACK (model_rows_deleted), etsm);
	}
	e_selection_model_array_confirm_row_count (E_SELECTION_MODEL_ARRAY (etsm));
}
void      e_selection_model_simple_insert_rows         (ESelectionModelSimple *esms,
							int                    row,
							int                    count)
{
	esms->row_count += count;
	e_selection_model_array_insert_rows (E_SELECTION_MODEL_ARRAY(esms), row, count);
}
void
e_selection_model_simple_move_row            (ESelectionModelSimple *esms,
					      int                    old_row,
					      int                    new_row)
{
	e_selection_model_array_move_row (E_SELECTION_MODEL_ARRAY(esms), old_row, new_row);
}
static void
model_rows_deleted (ETableModel *etm,
                    gint row,
                    gint count,
                    ETableSelectionModel *etsm)
{
	e_selection_model_array_delete_rows (E_SELECTION_MODEL_ARRAY (etsm), row, count);
	free_hash (etsm);
}
void
e_selection_model_simple_set_row_count (ESelectionModelSimple *esms,
					int row_count)
{
	if (esms->row_count != row_count) {
		ESelectionModelArray *esma = E_SELECTION_MODEL_ARRAY(esms);
		if (esma->eba)
			g_object_unref(esma->eba);
		esma->eba = NULL;
		esma->selected_row = -1;
		esma->selected_range_end = -1;
	}
	esms->row_count = row_count;
}
static gint
model_changed_idle (ETableSelectionModel *etsm)
{
	ETableModel *etm = etsm->model;

	e_selection_model_clear (E_SELECTION_MODEL (etsm));

	if (etsm->cursor_id && etm && e_table_model_has_save_id (etm)) {
		gint row_count = e_table_model_row_count (etm);
		gint cursor_row = -1;
		gint cursor_col = -1;
		gint i;
		e_selection_model_array_confirm_row_count (E_SELECTION_MODEL_ARRAY (etsm));
		for (i = 0; i < row_count; i++) {
			gchar *save_id = e_table_model_get_save_id (etm, i);
			if (g_hash_table_lookup (etsm->hash, save_id))
				e_selection_model_change_one_row (E_SELECTION_MODEL (etsm), i, TRUE);

			if (etsm->cursor_id && !strcmp (etsm->cursor_id, save_id)) {
				cursor_row = i;
				cursor_col = e_selection_model_cursor_col (E_SELECTION_MODEL (etsm));
				if (cursor_col == -1) {
					if (etsm->eth) {
						cursor_col = e_table_header_prioritized_column (etsm->eth);
					} else
						cursor_col = 0;
				}
				e_selection_model_change_cursor (E_SELECTION_MODEL (etsm), cursor_row, cursor_col);
				g_free (etsm->cursor_id);
				etsm->cursor_id = NULL;
			}
			g_free (save_id);
		}
		free_hash (etsm);
		e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), cursor_row, cursor_col);
		e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));
	}
	etsm->model_changed_idle_id = 0;
	return FALSE;
}