1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 
3 /*
4  *  GThumb
5  *
6  *  Copyright (C) 2008 Free Software Foundation, Inc.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "gth-file-selection.h"
23 
24 
25 enum {
26 	FILE_SELECTION_CHANGED,
27 	LAST_SIGNAL
28 };
29 
30 
31 static guint gth_file_selection_signals[LAST_SIGNAL] = { 0 };
32 
33 
34 G_DEFINE_INTERFACE (GthFileSelection, gth_file_selection, 0)
35 
36 
37 static void
gth_file_selection_default_init(GthFileSelectionInterface * iface)38 gth_file_selection_default_init (GthFileSelectionInterface *iface)
39 {
40 	static gboolean initialized = FALSE;
41 
42 	if (! initialized) {
43 		gth_file_selection_signals[FILE_SELECTION_CHANGED] =
44 			g_signal_new ("file-selection-changed",
45 				      GTH_TYPE_FILE_SELECTION,
46 				      G_SIGNAL_RUN_LAST,
47 				      G_STRUCT_OFFSET (GthFileSelectionInterface, file_selection_changed),
48 				      NULL, NULL,
49 				      g_cclosure_marshal_VOID__VOID,
50 				      G_TYPE_NONE, 0);
51 		initialized = TRUE;
52 	}
53 }
54 
55 
56 void
gth_file_selection_set_selection_mode(GthFileSelection * self,GtkSelectionMode mode)57 gth_file_selection_set_selection_mode (GthFileSelection *self,
58 				       GtkSelectionMode  mode)
59 {
60 	GTH_FILE_SELECTION_GET_INTERFACE (self)->set_selection_mode (self, mode);
61 }
62 
63 
64 GList *
gth_file_selection_get_selected(GthFileSelection * self)65 gth_file_selection_get_selected (GthFileSelection *self)
66 {
67 	GList *items;
68 
69 	items = GTH_FILE_SELECTION_GET_INTERFACE (self)->get_selected (self);
70 	items = g_list_sort (items, (GCompareFunc) gtk_tree_path_compare);
71 
72 	return items;
73 }
74 
75 
76 void
gth_file_selection_select(GthFileSelection * self,int pos)77 gth_file_selection_select (GthFileSelection *self,
78 			   int               pos)
79 {
80 	GTH_FILE_SELECTION_GET_INTERFACE (self)->select (self, pos);
81 }
82 
83 
84 void
gth_file_selection_unselect(GthFileSelection * self,int pos)85 gth_file_selection_unselect (GthFileSelection *self,
86 			     int               pos)
87 {
88 	GTH_FILE_SELECTION_GET_INTERFACE (self)->unselect (self, pos);
89 }
90 
91 
92 void
gth_file_selection_select_all(GthFileSelection * self)93 gth_file_selection_select_all (GthFileSelection *self)
94 {
95 	GTH_FILE_SELECTION_GET_INTERFACE (self)->select_all (self);
96 }
97 
98 
99 void
gth_file_selection_unselect_all(GthFileSelection * self)100 gth_file_selection_unselect_all (GthFileSelection *self)
101 {
102 	GTH_FILE_SELECTION_GET_INTERFACE (self)->unselect_all (self);
103 }
104 
105 
106 gboolean
gth_file_selection_is_selected(GthFileSelection * self,int pos)107 gth_file_selection_is_selected (GthFileSelection *self,
108 				int               pos)
109 {
110 	return GTH_FILE_SELECTION_GET_INTERFACE (self)->is_selected (self, pos);
111 }
112 
113 
114 GtkTreePath *
gth_file_selection_get_first_selected(GthFileSelection * self)115 gth_file_selection_get_first_selected (GthFileSelection *self)
116 {
117 	return GTH_FILE_SELECTION_GET_INTERFACE (self)->get_first_selected (self);
118 }
119 
120 
121 GtkTreePath *
gth_file_selection_get_last_selected(GthFileSelection * self)122 gth_file_selection_get_last_selected (GthFileSelection *self)
123 {
124 	return GTH_FILE_SELECTION_GET_INTERFACE (self)->get_last_selected (self);
125 }
126 
127 
128 guint
gth_file_selection_get_n_selected(GthFileSelection * self)129 gth_file_selection_get_n_selected (GthFileSelection *self)
130 {
131 	return GTH_FILE_SELECTION_GET_INTERFACE (self)->get_n_selected (self);
132 }
133 
134 
135 void
gth_file_selection_changed(GthFileSelection * self)136 gth_file_selection_changed (GthFileSelection *self)
137 {
138 	g_signal_emit (self, gth_file_selection_signals[FILE_SELECTION_CHANGED], 0);
139 }
140