1 /* nautilus-view.c
2  *
3  * Copyright (C) 2015 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "config.h"
20 
21 #include "nautilus-view.h"
22 #include <glib/gi18n.h>
23 
G_DEFINE_INTERFACE(NautilusView,nautilus_view,GTK_TYPE_WIDGET)24 G_DEFINE_INTERFACE (NautilusView, nautilus_view, GTK_TYPE_WIDGET)
25 
26 static void
27 nautilus_view_default_init (NautilusViewInterface *iface)
28 {
29     /**
30      * NautilusView::loading:
31      *
32      * %TRUE if the view is loading the location, %FALSE otherwise.
33      */
34     g_object_interface_install_property (iface,
35                                          g_param_spec_boolean ("loading",
36                                                                "Current view is loading",
37                                                                "Whether the current view is loading the location or not",
38                                                                FALSE,
39                                                                G_PARAM_READABLE));
40 
41     /**
42      * NautilusView::searching:
43      *
44      * %TRUE if the view is searching, %FALSE otherwise.
45      */
46     g_object_interface_install_property (iface,
47                                          g_param_spec_boolean ("searching",
48                                                                "Current view is searching",
49                                                                "Whether the current view is searching or not",
50                                                                FALSE,
51                                                                G_PARAM_READABLE));
52 
53     /**
54      * NautilusView::location:
55      *
56      * The current location of the view.
57      */
58     g_object_interface_install_property (iface,
59                                          g_param_spec_object ("location",
60                                                               "Location displayed by the view",
61                                                               "The current location displayed by the view",
62                                                               G_TYPE_FILE,
63                                                               G_PARAM_READWRITE));
64 
65     /**
66      * NautilusView::selection:
67      *
68      * The current selection of the view.
69      */
70     g_object_interface_install_property (iface,
71                                          g_param_spec_pointer ("selection",
72                                                                "Selection of the view",
73                                                                "The current selection of the view",
74                                                                G_PARAM_READWRITE));
75 
76     /**
77      * NautilusView::search-query:
78      *
79      * The search query being performed, or NULL.
80      */
81     g_object_interface_install_property (iface,
82                                          g_param_spec_object ("search-query",
83                                                               "Search query being performed",
84                                                               "The search query being performed on the view",
85                                                               NAUTILUS_TYPE_QUERY,
86                                                               G_PARAM_READWRITE));
87 
88     /**
89      * NautilusView::extensions-background-menu:
90      *
91      * Menu for the background click of extensions
92      */
93     g_object_interface_install_property (iface,
94                                          g_param_spec_object ("extensions-background-menu",
95                                                               "Menu for the background click of extensions",
96                                                               "Menu for the background click of extensions",
97                                                               G_TYPE_MENU_MODEL,
98                                                               G_PARAM_READWRITE));
99     /**
100      * NautilusView::templates-menu:
101      *
102      * Menu of templates
103      */
104     g_object_interface_install_property (iface,
105                                          g_param_spec_object ("templates-menu",
106                                                               "Menu of templates",
107                                                               "Menu of templates",
108                                                               G_TYPE_MENU_MODEL,
109                                                               G_PARAM_READWRITE));
110 }
111 
112 /**
113  * nautilus_view_get_icon:
114  * @view: a #NautilusView
115  *
116  * Retrieves the #GIcon that represents @view.
117  *
118  * Returns: (transfer full): a #GIcon
119  */
120 GIcon *
nautilus_view_get_icon(guint view_id)121 nautilus_view_get_icon (guint view_id)
122 {
123     if (view_id == NAUTILUS_VIEW_GRID_ID)
124     {
125         return g_themed_icon_new ("view-grid-symbolic");
126     }
127     else if (view_id == NAUTILUS_VIEW_LIST_ID)
128     {
129         return g_themed_icon_new ("view-list-symbolic");
130     }
131     else if (view_id == NAUTILUS_VIEW_OTHER_LOCATIONS_ID)
132     {
133         return g_themed_icon_new_with_default_fallbacks ("view-list-symbolic");
134     }
135     else
136     {
137         return NULL;
138     }
139 }
140 
141 /**
142  * nautilus_view_get_tooltip:
143  * @view: a #NautilusView
144  *
145  * Retrieves the static string that represents @view.
146  *
147  * Returns: (transfer none): a static string
148  */
149 const gchar *
nautilus_view_get_tooltip(guint view_id)150 nautilus_view_get_tooltip (guint view_id)
151 {
152     if (view_id == NAUTILUS_VIEW_GRID_ID)
153     {
154         return _("Show grid");
155     }
156     else if (view_id == NAUTILUS_VIEW_LIST_ID)
157     {
158         return _("Show list");
159     }
160     else if (view_id == NAUTILUS_VIEW_OTHER_LOCATIONS_ID)
161     {
162         return _("Show List");
163     }
164     else
165     {
166         return NULL;
167     }
168 }
169 
170 /**
171  * nautilus_view_get_view_id:
172  * @view: a #NautilusView
173  *
174  * Retrieves the view id that represents the @view type.
175  *
176  * Returns: a guint representing the view type
177  */
178 guint
nautilus_view_get_view_id(NautilusView * view)179 nautilus_view_get_view_id (NautilusView *view)
180 {
181     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_view_id, NAUTILUS_VIEW_INVALID_ID);
182 
183     return NAUTILUS_VIEW_GET_IFACE (view)->get_view_id (view);
184 }
185 
186 /**
187  * nautilus_view_get_toolbar_menu_sections:
188  * @view: a #NautilusView
189  *
190  * Retrieves the menu sections to show in the main toolbar menu when this view
191  * is active
192  *
193  * Returns: (transfer none): a #NautilusToolbarMenuSections with the sections to
194  * be displayed
195  */
196 NautilusToolbarMenuSections *
nautilus_view_get_toolbar_menu_sections(NautilusView * view)197 nautilus_view_get_toolbar_menu_sections (NautilusView *view)
198 {
199     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_toolbar_menu_sections, NULL);
200 
201     return NAUTILUS_VIEW_GET_IFACE (view)->get_toolbar_menu_sections (view);
202 }
203 
204 GMenuModel *
nautilus_view_get_extensions_background_menu(NautilusView * view)205 nautilus_view_get_extensions_background_menu (NautilusView *view)
206 {
207     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_extensions_background_menu, NULL);
208 
209     return NAUTILUS_VIEW_GET_IFACE (view)->get_extensions_background_menu (view);
210 }
211 
212 /* Protected */
213 void
nautilus_view_set_extensions_background_menu(NautilusView * view,GMenuModel * menu)214 nautilus_view_set_extensions_background_menu (NautilusView *view,
215                                               GMenuModel   *menu)
216 {
217     g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_extensions_background_menu);
218 
219     NAUTILUS_VIEW_GET_IFACE (view)->set_extensions_background_menu (view, menu);
220 }
221 
222 GMenuModel *
nautilus_view_get_templates_menu(NautilusView * view)223 nautilus_view_get_templates_menu (NautilusView *view)
224 {
225     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_templates_menu, NULL);
226 
227     return NAUTILUS_VIEW_GET_IFACE (view)->get_templates_menu (view);
228 }
229 
230 /* Protected */
231 void
nautilus_view_set_templates_menu(NautilusView * view,GMenuModel * menu)232 nautilus_view_set_templates_menu (NautilusView *view,
233                                   GMenuModel   *menu)
234 {
235     g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_templates_menu);
236 
237     NAUTILUS_VIEW_GET_IFACE (view)->set_templates_menu (view, menu);
238 }
239 
240 /**
241  * nautilus_view_get_search_query:
242  * @view: a #NautilusView
243  *
244  * Retrieves the current current location of @view.
245  *
246  * Returns: (transfer none): a #GFile
247  */
248 GFile *
nautilus_view_get_location(NautilusView * view)249 nautilus_view_get_location (NautilusView *view)
250 {
251     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_location, NULL);
252 
253     return NAUTILUS_VIEW_GET_IFACE (view)->get_location (view);
254 }
255 
256 /**
257  * nautilus_view_set_location:
258  * @view: a #NautilusView
259  * @location: the location displayed by @view
260  *
261  * Sets the location of @view.
262  *
263  * Returns:
264  */
265 void
nautilus_view_set_location(NautilusView * view,GFile * location)266 nautilus_view_set_location (NautilusView *view,
267                             GFile        *location)
268 {
269     g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_location);
270 
271     NAUTILUS_VIEW_GET_IFACE (view)->set_location (view, location);
272 }
273 
274 /**
275  * nautilus_view_get_selection:
276  * @view: a #NautilusView
277  *
278  * Get the current selection of the view.
279  *
280  * Returns: (transfer full) (type GFile): a newly allocated list
281  * of the currently selected files.
282  */
283 GList *
nautilus_view_get_selection(NautilusView * view)284 nautilus_view_get_selection (NautilusView *view)
285 {
286     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_selection, NULL);
287 
288     return NAUTILUS_VIEW_GET_IFACE (view)->get_selection (view);
289 }
290 
291 /**
292  * nautilus_view_set_selection:
293  * @view: a #NautilusView
294  * @selection: (nullable): a list of files
295  *
296  * Sets the current selection of the view.
297  *
298  * Returns:
299  */
300 void
nautilus_view_set_selection(NautilusView * view,GList * selection)301 nautilus_view_set_selection (NautilusView *view,
302                              GList        *selection)
303 {
304     g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_selection);
305 
306     NAUTILUS_VIEW_GET_IFACE (view)->set_selection (view, selection);
307 }
308 
309 /**
310  * nautilus_view_get_search_query:
311  * @view: a #NautilusView
312  *
313  * Retrieves the current search query displayed by @view.
314  *
315  * Returns: (transfer none): a #
316  */
317 NautilusQuery *
nautilus_view_get_search_query(NautilusView * view)318 nautilus_view_get_search_query (NautilusView *view)
319 {
320     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_search_query, NULL);
321 
322     return NAUTILUS_VIEW_GET_IFACE (view)->get_search_query (view);
323 }
324 
325 /**
326  * nautilus_view_set_search_query:
327  * @view: a #NautilusView
328  * @query: the search query to be performed, or %NULL
329  *
330  * Sets the current search query performed by @view.
331  *
332  * Returns:
333  */
334 void
nautilus_view_set_search_query(NautilusView * view,NautilusQuery * query)335 nautilus_view_set_search_query (NautilusView  *view,
336                                 NautilusQuery *query)
337 {
338     g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_search_query);
339 
340     NAUTILUS_VIEW_GET_IFACE (view)->set_search_query (view, query);
341 }
342 
343 /**
344  * nautilus_view_is_loading:
345  * @view: a #NautilusView
346  *
347  * Whether @view is loading the current location.
348  *
349  * Returns: %TRUE if @view is loading, %FALSE otherwise.
350  */
351 gboolean
nautilus_view_is_loading(NautilusView * view)352 nautilus_view_is_loading (NautilusView *view)
353 {
354     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_loading, FALSE);
355 
356     return NAUTILUS_VIEW_GET_IFACE (view)->is_loading (view);
357 }
358 
359 /**
360  * nautilus_view_is_searching:
361  * @view: a #NautilusView
362  *
363  * Whether @view is searching.
364  *
365  * Returns: %TRUE if @view is searching, %FALSE otherwise.
366  */
367 gboolean
nautilus_view_is_searching(NautilusView * view)368 nautilus_view_is_searching (NautilusView *view)
369 {
370     g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_searching, FALSE);
371 
372     return NAUTILUS_VIEW_GET_IFACE (view)->is_searching (view);
373 }
374