evolution-3.6.4/e-util/e-sorter.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Chris Lahey <clahey@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <stdlib.h>
 28 #include <string.h>
 29 
 30 #include "e-sorter.h"
 31 #include "e-util.h"
 32 
 33 #define d(x)
 34 
 35 #define PARENT_TYPE G_TYPE_OBJECT
 36 
 37 G_DEFINE_TYPE (
 38 	ESorter,
 39 	e_sorter,
 40 	G_TYPE_OBJECT)
 41 
 42 static gint es_model_to_sorted (ESorter *es, gint row);
 43 static gint es_sorted_to_model (ESorter *es, gint row);
 44 static void es_get_model_to_sorted_array (ESorter *es, gint **array, gint *count);
 45 static void es_get_sorted_to_model_array (ESorter *es, gint **array, gint *count);
 46 static gboolean es_needs_sorting (ESorter *es);
 47 
 48 static void
 49 e_sorter_class_init (ESorterClass *class)
 50 {
 51 	class->model_to_sorted           = es_model_to_sorted;
 52 	class->sorted_to_model           = es_sorted_to_model;
 53 	class->get_model_to_sorted_array = es_get_model_to_sorted_array;
 54 	class->get_sorted_to_model_array = es_get_sorted_to_model_array;
 55 	class->needs_sorting             = es_needs_sorting;
 56 }
 57 
 58 static void
 59 e_sorter_init (ESorter *es)
 60 {
 61 }
 62 
 63 ESorter *
 64 e_sorter_new (void)
 65 {
 66 	ESorter *es = g_object_new (E_SORTER_TYPE, NULL);
 67 
 68 	return es;
 69 }
 70 
 71 static gint
 72 es_model_to_sorted (ESorter *es,
 73                     gint row)
 74 {
 75 	return row;
 76 }
 77 
 78 static gint
 79 es_sorted_to_model (ESorter *es,
 80                     gint row)
 81 {
 82 	return row;
 83 }
 84 
 85 static void
 86 es_get_model_to_sorted_array (ESorter *es,
 87                               gint **array,
 88                               gint *count)
 89 {
 90 }
 91 
 92 static void
 93 es_get_sorted_to_model_array (ESorter *es,
 94                               gint **array,
 95                               gint *count)
 96 {
 97 }
 98 
 99 static gboolean
100 es_needs_sorting (ESorter *es)
101 {
102 	return FALSE;
103 }
104 
105 gint
106 e_sorter_model_to_sorted (ESorter *es,
107                           gint row)
108 {
109 	g_return_val_if_fail (es != NULL, -1);
110 	g_return_val_if_fail (row >= 0, -1);
111 
112 	if (E_SORTER_GET_CLASS (es)->model_to_sorted)
113 		return E_SORTER_GET_CLASS (es)->model_to_sorted (es, row);
114 	else
115 		return -1;
116 }
117 
118 gint
119 e_sorter_sorted_to_model (ESorter *es,
120                           gint row)
121 {
122 	g_return_val_if_fail (es != NULL, -1);
123 	g_return_val_if_fail (row >= 0, -1);
124 
125 	if (E_SORTER_GET_CLASS (es)->sorted_to_model)
126 		return E_SORTER_GET_CLASS (es)->sorted_to_model (es, row);
127 	else
128 		return -1;
129 }
130 
131 void
132 e_sorter_get_model_to_sorted_array (ESorter *es,
133                                     gint **array,
134                                     gint *count)
135 {
136 	g_return_if_fail (es != NULL);
137 
138 	if (E_SORTER_GET_CLASS (es)->get_model_to_sorted_array)
139 		E_SORTER_GET_CLASS (es)->get_model_to_sorted_array (es, array, count);
140 }
141 
142 void
143 e_sorter_get_sorted_to_model_array (ESorter *es,
144                                     gint **array,
145                                     gint *count)
146 {
147 	g_return_if_fail (es != NULL);
148 
149 	if (E_SORTER_GET_CLASS (es)->get_sorted_to_model_array)
150 		E_SORTER_GET_CLASS (es)->get_sorted_to_model_array (es, array, count);
151 }
152 
153 gboolean
154 e_sorter_needs_sorting (ESorter *es)
155 {
156 	g_return_val_if_fail (es != NULL, FALSE);
157 
158 	if (E_SORTER_GET_CLASS (es)->needs_sorting)
159 		return E_SORTER_GET_CLASS (es)->needs_sorting (es);
160 	else
161 		return FALSE;
162 }