summaryrefslogtreecommitdiff
path: root/thunar/thunar-view.c
blob: 2f3f8bd01aa7a334fe573676fb730a7ce27336c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
 * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <libxfce4util/libxfce4util.h>

#include <thunar/thunar-private.h>
#include <thunar/thunar-view.h>



static void thunar_view_class_init (gpointer klass);



GType
thunar_view_get_type (void)
{
  static gsize type__static = 0;
  GType        type;

  if (g_once_init_enter (&type__static))
    {
      type = g_type_register_static_simple (G_TYPE_INTERFACE,
                                            I_("ThunarView"),
                                            sizeof (ThunarViewIface),
                                            (GClassInitFunc) (void (*)(void)) thunar_view_class_init,
                                            0,
                                            NULL,
                                            0);

      g_type_interface_add_prerequisite (type, GTK_TYPE_WIDGET);
      g_type_interface_add_prerequisite (type, THUNAR_TYPE_COMPONENT);

      g_once_init_leave (&type__static, type);
    }

  return type__static;
}



static void
thunar_view_class_init (gpointer klass)
{
  /**
   * ThunarView:loading:
   *
   * Indicates whether the given #ThunarView is currently loading or
   * layouting its contents. Implementations should invoke
   * #g_object_notify() on this property whenever they start to load
   * the contents and then once they have finished loading.
   *
   * Other modules can use this property to display some kind of
   * user visible notification about the loading state, e.g. a
   * progress bar or an animated image.
   **/
  g_object_interface_install_property (klass,
                                       g_param_spec_boolean ("loading",
                                                             "loading",
                                                             "loading",
                                                             FALSE,
                                                             EXO_PARAM_READABLE));

  /**
   * ThunarView:statusbar-text:
   *
   * The text to be displayed in the status bar, which is associated
   * with this #ThunarView instance. Implementations should invoke
   * #g_object_notify() on this property, whenever they have a new
   * text to be display in the status bar (e.g. the selection changed
   * or similar).
   **/
  g_object_interface_install_property (klass,
                                       g_param_spec_string ("statusbar-text",
                                                            "statusbar-text",
                                                            "statusbar-text",
                                                            NULL,
                                                            EXO_PARAM_READABLE));

  /**
   * ThunarView:show-hidden:
   *
   * Tells whether to display hidden and backup files in the
   * #ThunarView or whether to hide them.
   **/
  g_object_interface_install_property (klass,
                                       g_param_spec_boolean ("show-hidden",
                                                             "show-hidden",
                                                             "show-hidden",
                                                             FALSE,
                                                             EXO_PARAM_READWRITE));

  /**
   * ThunarView:zoom-level:
   *
   * The #ThunarZoomLevel at which the items within this
   * #ThunarView should be displayed.
   **/
  g_object_interface_install_property (klass,
                                       g_param_spec_enum ("zoom-level",
                                                          "zoom-level",
                                                          "zoom-level",
                                                          THUNAR_TYPE_ZOOM_LEVEL,
                                                          THUNAR_ZOOM_LEVEL_100_PERCENT,
                                                          EXO_PARAM_READWRITE));
}



/**
 * thunar_view_get_loading:
 * @view : a #ThunarView instance.
 *
 * Tells whether the given #ThunarView is currently loading or
 * layouting its contents.
 *
 * Return value: %TRUE if @view is currently being loaded, else %FALSE.
 **/
gboolean
thunar_view_get_loading (ThunarView *view)
{
  _thunar_return_val_if_fail (THUNAR_IS_VIEW (view), FALSE);
  return (*THUNAR_VIEW_GET_IFACE (view)->get_loading) (view);
}



/**
 * thunar_view_get_statusbar_text:
 * @view : a #ThunarView instance.
 *
 * Queries the text that should be displayed in the status bar
 * associated with @view.
 *
 * Return value: the text to be displayed in the status bar
 *               asssociated with @view.
 **/
const gchar*
thunar_view_get_statusbar_text (ThunarView *view)
{
  _thunar_return_val_if_fail (THUNAR_IS_VIEW (view), NULL);
  return (*THUNAR_VIEW_GET_IFACE (view)->get_statusbar_text) (view);
}



/**
 * thunar_view_get_show_hidden:
 * @view : a #ThunarView instance.
 *
 * Returns %TRUE if hidden and backup files are shown
 * in @view. Else %FALSE is returned.
 *
 * Return value: whether @view displays hidden files.
 **/
gboolean
thunar_view_get_show_hidden (ThunarView *view)
{
  _thunar_return_val_if_fail (THUNAR_IS_VIEW (view), FALSE);
  return (*THUNAR_VIEW_GET_IFACE (view)->get_show_hidden) (view);
}



/**
 * thunar_view_set_show_hidden:
 * @view        : a #ThunarView instance.
 * @show_hidden : &TRUE to display hidden files, else %FALSE.
 *
 * If @show_hidden is %TRUE then @view will display hidden and
 * backup files, else those files will be hidden from the user
 * interface.
 **/
void
thunar_view_set_show_hidden (ThunarView *view,
                             gboolean    show_hidden)
{
  _thunar_return_if_fail (THUNAR_IS_VIEW (view));
  (*THUNAR_VIEW_GET_IFACE (view)->set_show_hidden) (view, show_hidden);
}



/**
 * thunar_view_get_zoom_level:
 * @view : a #ThunarView instance.
 *
 * Returns the #ThunarZoomLevel currently used for the @view.
 *
 * Return value: the #ThunarZoomLevel currently used for the @view.
 **/
ThunarZoomLevel
thunar_view_get_zoom_level (ThunarView *view)
{
  _thunar_return_val_if_fail (THUNAR_IS_VIEW (view), THUNAR_ZOOM_LEVEL_100_PERCENT);
  return (*THUNAR_VIEW_GET_IFACE (view)->get_zoom_level) (view);
}



/**
 * thunar_view_set_zoom_level:
 * @view       : a #ThunarView instance.
 * @zoom_level : the new #ThunarZoomLevel for @view.
 *
 * Sets the zoom level used for @view to @zoom_level.
 **/
void
thunar_view_set_zoom_level (ThunarView     *view,
                            ThunarZoomLevel zoom_level)
{
  _thunar_return_if_fail (THUNAR_IS_VIEW (view));
  _thunar_return_if_fail (zoom_level < THUNAR_ZOOM_N_LEVELS);
  (*THUNAR_VIEW_GET_IFACE (view)->set_zoom_level) (view, zoom_level);
}



/**
 * thunar_view_reset_zoom_level:
 * @view : a #ThunarView instance.
 *
 * Resets the zoom level of @view to the default
 * #ThunarZoomLevel for @view.
 **/
void
thunar_view_reset_zoom_level (ThunarView *view)
{
  _thunar_return_if_fail (THUNAR_IS_VIEW (view));
  (*THUNAR_VIEW_GET_IFACE (view)->reset_zoom_level) (view);
}



/**
 * thunar_view_reload:
 * @view : a #ThunarView instance.
 * @reload_info : whether to reload file info for all files too
 *
 * Tells @view to reread the currently displayed folder
 * contents from the underlying media. If reload_info is
 * TRUE, it will reload information for all files too.
 **/
void
thunar_view_reload (ThunarView *view,
                    gboolean    reload_info)
{
  _thunar_return_if_fail (THUNAR_IS_VIEW (view));
  (*THUNAR_VIEW_GET_IFACE (view)->reload) (view, reload_info);
}



/**
 * thunar_view_get_visible_range:
 * @view       : a #ThunarView instance.
 * @start_file : return location for start of region, or %NULL.
 * @end_file   : return location for end of region, or %NULL.
 *
 * Sets @start_file and @end_file to be the first and last visible
 * #ThunarFile.
 *
 * The files should be freed with g_object_unref() when no
 * longer needed.
 *
 * Return value: %TRUE if valid files were placed in @start_file
 *               and @end_file.
 **/
gboolean
thunar_view_get_visible_range (ThunarView  *view,
                               ThunarFile **start_file,
                               ThunarFile **end_file)
{
  _thunar_return_val_if_fail (THUNAR_IS_VIEW (view), FALSE);
  return (*THUNAR_VIEW_GET_IFACE (view)->get_visible_range) (view, start_file, end_file);
}



/**
 * thunar_view_scroll_to_file:
 * @view        : a #ThunarView instance.
 * @file        : the #ThunarFile to scroll to.
 * @select_file : %TRUE to also select the @file in the @view.
 * @use_align   : whether to use alignment arguments.
 * @row_align   : the vertical alignment.
 * @col_align   : the horizontal alignment.
 *
 * Tells @view to scroll to the @file. If @view is currently
 * loading, it'll remember to scroll to @file later when
 * the contents are loaded.
 **/
void
thunar_view_scroll_to_file (ThunarView *view,
                            ThunarFile *file,
                            gboolean    select_file,
                            gboolean    use_align,
                            gfloat      row_align,
                            gfloat      col_align)
{
  _thunar_return_if_fail (THUNAR_IS_VIEW (view));
  _thunar_return_if_fail (THUNAR_IS_FILE (file));
  _thunar_return_if_fail (row_align >= 0.0f && row_align <= 1.0f);
  _thunar_return_if_fail (col_align >= 0.0f && col_align <= 1.0f);
  (*THUNAR_VIEW_GET_IFACE (view)->scroll_to_file) (view, file, select_file, use_align, row_align, col_align);
}



GList*
thunar_view_get_selected_files (ThunarView *view)
{
  _thunar_return_val_if_fail (THUNAR_IS_VIEW (view), NULL);
  return (*THUNAR_VIEW_GET_IFACE (view)->get_selected_files) (view);
}



void
thunar_view_set_selected_files (ThunarView *view,
                                GList      *path_list)
{
  _thunar_return_if_fail (THUNAR_IS_VIEW (view));
  (*THUNAR_VIEW_GET_IFACE (view)->set_selected_files) (view, path_list);
}