static gboolean table_sorter_needs_sorting (ESorter *sorter) { ETableSorter *table_sorter = E_TABLE_SORTER (sorter); if (table_sorter->needs_sorting < 0) { if (e_table_sort_info_sorting_get_count (table_sorter->sort_info) + e_table_sort_info_grouping_get_count (table_sorter->sort_info)) table_sorter->needs_sorting = 1; else table_sorter->needs_sorting = 0; } return table_sorter->needs_sorting; }
ETableCol * e_table_util_calculate_current_search_col (ETableHeader *header, ETableHeader *full_header, ETableSortInfo *sort_info, gboolean always_search) { gint i; gint count; ETableCol *col = NULL; count = e_table_sort_info_grouping_get_count (sort_info); for (i = 0; i < count; i++) { ETableSortColumn column = e_table_sort_info_grouping_get_nth (sort_info, i); col = e_table_header_get_column (full_header, column.column); if (col && col->search) break; col = NULL; } if (col == NULL) { count = e_table_sort_info_sorting_get_count (sort_info); for (i = 0; i < count; i++) { ETableSortColumn column = e_table_sort_info_sorting_get_nth (sort_info, i); col = e_table_header_get_column (full_header, column.column); if (col && col->search) break; col = NULL; } } if (col == NULL && always_search) { col = e_table_header_prioritized_column_selected (header, check_col, NULL); } return col; }
static void e_table_group_leaf_construct (GnomeCanvasGroup *parent, ETableGroupLeaf *etgl, ETableHeader *full_header, ETableHeader *header, ETableModel *model, ETableSortInfo *sort_info) { etgl->is_grouped = (e_table_sort_info_grouping_get_count (sort_info) > 0); if (etgl->is_grouped) etgl->ets = e_table_sorted_variable_new ( model, full_header, sort_info); else etgl->ets = e_table_sorted_new ( model, full_header, sort_info); e_table_group_construct ( parent, E_TABLE_GROUP (etgl), full_header, header, model); }
static void config_group_info_update (ETableConfig *config) { ETableSortInfo *info = config->state->sort_info; GString *res; int count, i; if (!e_table_sort_info_get_can_group (info)) return; count = e_table_sort_info_grouping_get_count (info); res = g_string_new (""); for (i = 0; i < count; i++) { ETableSortColumn col = e_table_sort_info_grouping_get_nth (info, i); ETableColumnSpecification *column; column = find_column_in_spec (config->source_spec, col.column); if (!column){ g_warning ("Could not find model column in specification"); continue; } g_string_append (res, dgettext (config->domain, (column)->title)); g_string_append_c (res, ' '); g_string_append ( res, col.ascending ? _("(Ascending)") : _("(Descending)")); if ((i+1) != count) g_string_append (res, ", "); } if (res->str [0] == 0) g_string_append (res, _("No grouping")); gtk_label_set_text (GTK_LABEL (config->group_label), res->str); g_string_free (res, TRUE); }
static gint qsort_callback (gconstpointer data1, gconstpointer data2, gpointer user_data) { struct qsort_data *qd = (struct qsort_data *) user_data; gint row1 = *(gint *) data1; gint row2 = *(gint *) data2; gint j; gint sort_count; gint comp_val = 0; gint ascending = 1; sort_count = e_table_sort_info_sorting_get_count ( qd->table_sorter->sort_info) + e_table_sort_info_grouping_get_count ( qd->table_sorter->sort_info); for (j = 0; j < sort_count; j++) { comp_val = (*(qd->compare[j]))(qd->vals[qd->cols * row1 + j], qd->vals[qd->cols * row2 + j], qd->cmp_cache); ascending = qd->ascending[j]; if (comp_val != 0) break; } if (comp_val == 0) { if (row1 < row2) comp_val = -1; if (row1 > row2) comp_val = 1; } if (!ascending) comp_val = -comp_val; return comp_val; }
static void update_sort_and_group_config_dialog (ETableConfig *config, gboolean is_sort) { ETableConfigSortWidgets *widgets; int count, i; if (is_sort){ count = e_table_sort_info_sorting_get_count ( config->temp_state->sort_info); widgets = &config->sort [0]; } else { count = e_table_sort_info_grouping_get_count ( config->temp_state->sort_info); widgets = &config->group [0]; } for (i = 0; i < 4; i++){ gboolean sensitive = (i <= count); char *text = ""; gtk_widget_set_sensitive (widgets [i].frames, sensitive); /* * Sorting is set, auto select the text */ g_signal_handler_block ( widgets [i].radio_ascending, widgets [i].toggled_id); g_signal_handler_block ( widgets [i].combo, widgets [i].changed_id); if (i < count){ GtkToggleButton *a, *d; ETableSortColumn col = is_sort ? e_table_sort_info_sorting_get_nth ( config->temp_state->sort_info, i) : e_table_sort_info_grouping_get_nth ( config->temp_state->sort_info, i); ETableColumnSpecification *column = find_column_in_spec (config->source_spec, col.column); if (!column){ /* * This is a bug in the programmer * stuff, but by the time we arrive * here, the user has been given a * warning */ continue; } text = column->title; /* * Update radio buttons */ a = GTK_TOGGLE_BUTTON ( widgets [i].radio_ascending); d = GTK_TOGGLE_BUTTON ( widgets [i].radio_descending); gtk_toggle_button_set_active (col.ascending ? a:d, 1); } else { GtkToggleButton *t; t = GTK_TOGGLE_BUTTON ( widgets [i].radio_ascending); if (is_sort) g_return_if_fail (widgets [i].radio_ascending != config->group [i].radio_ascending); else g_return_if_fail (widgets [i].radio_ascending != config->sort [i].radio_ascending); gtk_toggle_button_set_active (t, 1); } /* Set the text */ configure_combo_box_set_active ( GTK_COMBO_BOX (widgets[i].combo), text); g_signal_handler_unblock ( widgets [i].radio_ascending, widgets [i].toggled_id); g_signal_handler_unblock ( widgets [i].combo, widgets [i].changed_id); } }
static void table_sorter_sort (ETableSorter *table_sorter) { gint rows; gint i; gint j; gint cols; gint group_cols; struct qsort_data qd; if (table_sorter->sorted) return; rows = e_table_model_row_count (table_sorter->source); group_cols = e_table_sort_info_grouping_get_count (table_sorter->sort_info); cols = e_table_sort_info_sorting_get_count (table_sorter->sort_info) + group_cols; table_sorter->sorted = g_new (int, rows); for (i = 0; i < rows; i++) table_sorter->sorted[i] = i; qd.cols = cols; qd.table_sorter = table_sorter; qd.vals = g_new (gpointer , rows * cols); qd.ascending = g_new (int, cols); qd.compare = g_new (GCompareDataFunc, cols); qd.cmp_cache = e_table_sorting_utils_create_cmp_cache (); for (j = 0; j < cols; j++) { ETableColumnSpecification *spec; ETableCol *col; GtkSortType sort_type; if (j < group_cols) spec = e_table_sort_info_grouping_get_nth ( table_sorter->sort_info, j, &sort_type); else spec = e_table_sort_info_sorting_get_nth ( table_sorter->sort_info, j - group_cols, &sort_type); col = e_table_header_get_column_by_spec ( table_sorter->full_header, spec); if (col == NULL) { gint last = e_table_header_count ( table_sorter->full_header) - 1; col = e_table_header_get_column ( table_sorter->full_header, last); } for (i = 0; i < rows; i++) { qd.vals[i * cols + j] = e_table_model_value_at ( table_sorter->source, col->spec->model_col, i); } qd.compare[j] = col->compare; qd.ascending[j] = (sort_type == GTK_SORT_ASCENDING); } g_qsort_with_data (table_sorter->sorted, rows, sizeof (gint), qsort_callback, &qd); for (j = 0; j < cols; j++) { ETableColumnSpecification *spec; ETableCol *col; GtkSortType sort_type; if (j < group_cols) spec = e_table_sort_info_grouping_get_nth ( table_sorter->sort_info, j, &sort_type); else spec = e_table_sort_info_sorting_get_nth ( table_sorter->sort_info, j - group_cols, &sort_type); col = e_table_header_get_column_by_spec ( table_sorter->full_header, spec); if (col == NULL) { gint last = e_table_header_count ( table_sorter->full_header) - 1; col = e_table_header_get_column ( table_sorter->full_header, last); } for (i = 0; i < rows; i++) { e_table_model_free_value (table_sorter->source, col->spec->model_col, qd.vals[i * cols + j]); } } g_free (qd.vals); g_free (qd.ascending); g_free (qd.compare); e_table_sorting_utils_free_cmp_cache (qd.cmp_cache); }