1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ 2 /* nemo-view.h 3 * 4 * Copyright (C) 1999, 2000 Free Software Foundaton 5 * Copyright (C) 2000, 2001 Eazel, Inc. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public 18 * License along with this program; if not, write to the 19 * Free Software Foundation, Inc., 51 Franklin Street - Suite 500, 20 * Boston, MA 02110-1335, USA. 21 * 22 * Authors: Ettore Perazzoli 23 * Darin Adler <darin@bentspoon.com> 24 * John Sullivan <sullivan@eazel.com> 25 * Pavel Cisler <pavel@eazel.com> 26 */ 27 28 #ifndef NEMO_VIEW_H 29 #define NEMO_VIEW_H 30 31 #include <gtk/gtk.h> 32 #include <gio/gio.h> 33 34 #include <libnemo-private/nemo-directory.h> 35 #include <libnemo-private/nemo-file.h> 36 #include <libnemo-private/nemo-icon-container.h> 37 #include <libnemo-private/nemo-link.h> 38 39 typedef struct NemoView NemoView; 40 typedef struct NemoViewClass NemoViewClass; 41 42 #include "nemo-window.h" 43 #include "nemo-window-slot.h" 44 45 #define NEMO_TYPE_VIEW nemo_view_get_type() 46 #define NEMO_VIEW(obj)\ 47 (G_TYPE_CHECK_INSTANCE_CAST ((obj), NEMO_TYPE_VIEW, NemoView)) 48 #define NEMO_VIEW_CLASS(klass)\ 49 (G_TYPE_CHECK_CLASS_CAST ((klass), NEMO_TYPE_VIEW, NemoViewClass)) 50 #define NEMO_IS_VIEW(obj)\ 51 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NEMO_TYPE_VIEW)) 52 #define NEMO_IS_VIEW_CLASS(klass)\ 53 (G_TYPE_CHECK_CLASS_TYPE ((klass), NEMO_TYPE_VIEW)) 54 #define NEMO_VIEW_GET_CLASS(obj)\ 55 (G_TYPE_INSTANCE_GET_CLASS ((obj), NEMO_TYPE_VIEW, NemoViewClass)) 56 57 typedef struct NemoViewDetails NemoViewDetails; 58 59 struct NemoView { 60 GtkScrolledWindow parent; 61 62 NemoViewDetails *details; 63 }; 64 65 struct NemoViewClass { 66 GtkScrolledWindowClass parent_class; 67 68 /* The 'clear' signal is emitted to empty the view of its contents. 69 * It must be replaced by each subclass. 70 */ 71 void (* clear) (NemoView *view); 72 73 /* The 'begin_file_changes' signal is emitted before a set of files 74 * are added to the view. It can be replaced by a subclass to do any 75 * necessary preparation for a set of new files. The default 76 * implementation does nothing. 77 */ 78 void (* begin_file_changes) (NemoView *view); 79 80 /* The 'add_file' signal is emitted to add one file to the view. 81 * It must be replaced by each subclass. 82 */ 83 void (* add_file) (NemoView *view, 84 NemoFile *file, 85 NemoDirectory *directory); 86 void (* remove_file) (NemoView *view, 87 NemoFile *file, 88 NemoDirectory *directory); 89 90 /* The 'file_changed' signal is emitted to signal a change in a file, 91 * including the file being removed. 92 * It must be replaced by each subclass. 93 */ 94 void (* file_changed) (NemoView *view, 95 NemoFile *file, 96 NemoDirectory *directory); 97 98 /* The 'end_file_changes' signal is emitted after a set of files 99 * are added to the view. It can be replaced by a subclass to do any 100 * necessary cleanup (typically, cleanup for code in begin_file_changes). 101 * The default implementation does nothing. 102 */ 103 void (* end_file_changes) (NemoView *view); 104 105 /* The 'begin_loading' signal is emitted before any of the contents 106 * of a directory are added to the view. It can be replaced by a 107 * subclass to do any necessary preparation to start dealing with a 108 * new directory. The default implementation does nothing. 109 */ 110 void (* begin_loading) (NemoView *view); 111 112 /* The 'end_loading' signal is emitted after all of the contents 113 * of a directory are added to the view. It can be replaced by a 114 * subclass to do any necessary clean-up. The default implementation 115 * does nothing. 116 * 117 * If all_files_seen is true, the handler may assume that 118 * no load error ocurred, and all files of the underlying 119 * directory were loaded. 120 * 121 * Otherwise, end_loading was emitted due to cancellation, 122 * which usually means that not all files are available. 123 */ 124 void (* end_loading) (NemoView *view, 125 gboolean all_files_seen); 126 127 /* The 'load_error' signal is emitted when the directory model 128 * reports an error in the process of monitoring the directory's 129 * contents. The load error indicates that the process of 130 * loading the contents has ended, but the directory is still 131 * being monitored. The default implementation handles common 132 * load failures like ACCESS_DENIED. 133 */ 134 void (* load_error) (NemoView *view, 135 GError *error); 136 137 /* Function pointers that don't have corresponding signals */ 138 139 /* reset_to_defaults is a function pointer that subclasses must 140 * override to set sort order, zoom level, etc to match default 141 * values. 142 */ 143 void (* reset_to_defaults) (NemoView *view); 144 145 /* get_backing uri is a function pointer for subclasses to 146 * override. Subclasses may replace it with a function that 147 * returns the URI for the location where to create new folders, 148 * files, links and paste the clipboard to. 149 */ 150 151 char * (* get_backing_uri) (NemoView *view); 152 153 /* get_selection is not a signal; it is just a function pointer for 154 * subclasses to replace (override). Subclasses must replace it 155 * with a function that returns a newly-allocated GList of 156 * NemoFile pointers. 157 */ 158 GList * (* get_selection) (NemoView *view); 159 160 /* peek_selection is not a signal; it is just a function pointer for 161 * subclasses to replace (override). Subclasses must replace it 162 * with a function that returns a pointer to the existing container 163 * selection list. 164 */ 165 GList * (* peek_selection) (NemoView *view); 166 167 /* get_selection_count is not a signal; it is just a function pointer for 168 * subclasses to replace (override). Subclasses must replace it 169 * with a function that returns the current selection count. 170 */ 171 gint (* get_selection_count) (NemoView *view); 172 173 /* get_selection_for_file_transfer is a function pointer for 174 * subclasses to replace (override). Subclasses must replace it 175 * with a function that returns a newly-allocated GList of 176 * NemoFile pointers. The difference from get_selection is 177 * that any files in the selection that also has a parent folder 178 * in the selection is not included. 179 */ 180 GList * (* get_selection_for_file_transfer)(NemoView *view); 181 182 /* select_all is a function pointer that subclasses must override to 183 * select all of the items in the view */ 184 void (* select_all) (NemoView *view); 185 186 /* set_selection is a function pointer that subclasses must 187 * override to select the specified items (and unselect all 188 * others). The argument is a list of NemoFiles. */ 189 190 void (* set_selection) (NemoView *view, 191 GList *selection); 192 193 /* invert_selection is a function pointer that subclasses must 194 * override to invert selection. */ 195 196 void (* invert_selection) (NemoView *view); 197 198 /* Return an array of locations of selected icons in their view. */ 199 GArray * (* get_selected_icon_locations) (NemoView *view); 200 201 guint (* get_item_count) (NemoView *view); 202 203 /* bump_zoom_level is a function pointer that subclasses must override 204 * to change the zoom level of an object. */ 205 void (* bump_zoom_level) (NemoView *view, 206 int zoom_increment); 207 208 /* zoom_to_level is a function pointer that subclasses must override 209 * to set the zoom level of an object to the specified level. */ 210 void (* zoom_to_level) (NemoView *view, 211 NemoZoomLevel level); 212 213 NemoZoomLevel (* get_zoom_level) (NemoView *view); 214 215 /* restore_default_zoom_level is a function pointer that subclasses must override 216 * to restore the zoom level of an object to a default setting. */ 217 void (* restore_default_zoom_level) (NemoView *view); 218 219 /* return the default zoom level for the current view */ 220 NemoZoomLevel (* get_default_zoom_level) (NemoView *view); 221 /* can_zoom_in is a function pointer that subclasses must override to 222 * return whether the view is at maximum size (furthest-in zoom level) */ 223 gboolean (* can_zoom_in) (NemoView *view); 224 225 /* can_zoom_out is a function pointer that subclasses must override to 226 * return whether the view is at minimum size (furthest-out zoom level) */ 227 gboolean (* can_zoom_out) (NemoView *view); 228 229 /* reveal_selection is a function pointer that subclasses may 230 * override to make sure the selected items are sufficiently 231 * apparent to the user (e.g., scrolled into view). By default, 232 * this does nothing. 233 */ 234 void (* reveal_selection) (NemoView *view); 235 236 /* merge_menus is a function pointer that subclasses can override to 237 * add their own menu items to the window's menu bar. 238 * If overridden, subclasses must call parent class's function. 239 */ 240 void (* merge_menus) (NemoView *view); 241 void (* unmerge_menus) (NemoView *view); 242 243 /* update_menus is a function pointer that subclasses can override to 244 * update the sensitivity or wording of menu items in the menu bar. 245 * It is called (at least) whenever the selection changes. If overridden, 246 * subclasses must call parent class's function. 247 */ 248 void (* update_menus) (NemoView *view); 249 250 /* sort_files is a function pointer that subclasses can override 251 * to provide a sorting order to determine which files should be 252 * presented when only a partial list is provided. 253 */ 254 int (* compare_files) (NemoView *view, 255 NemoFile *a, 256 NemoFile *b); 257 258 /* using_manual_layout is a function pointer that subclasses may 259 * override to control whether or not items can be freely positioned 260 * on the user-visible area. 261 * Note that this value is not guaranteed to be constant within the 262 * view's lifecycle. */ 263 gboolean (* using_manual_layout) (NemoView *view); 264 265 /* is_read_only is a function pointer that subclasses may 266 * override to control whether or not the user is allowed to 267 * change the contents of the currently viewed directory. The 268 * default implementation checks the permissions of the 269 * directory. 270 */ 271 gboolean (* is_read_only) (NemoView *view); 272 273 /* is_empty is a function pointer that subclasses must 274 * override to report whether the view contains any items. 275 */ 276 gboolean (* is_empty) (NemoView *view); 277 278 gboolean (* can_rename_file) (NemoView *view, 279 NemoFile *file); 280 /* select_all specifies whether the whole filename should be selected 281 * or only its basename (i.e. everything except the extension) 282 * */ 283 void (* start_renaming_file) (NemoView *view, 284 NemoFile *file, 285 gboolean select_all); 286 287 /* convert *point from widget's coordinate system to a coordinate 288 * system used for specifying file operation positions, which is view-specific. 289 * 290 * This is used by the the icon view, which converts the screen position to a zoom 291 * level-independent coordinate system. 292 */ 293 void (* widget_to_file_operation_position) (NemoView *view, 294 GdkPoint *position); 295 296 /* Preference change callbacks, overriden by icon and list views. 297 * Icon and list views respond by synchronizing to the new preference 298 * values and forcing an update if appropriate. 299 */ 300 void (* click_policy_changed) (NemoView *view); 301 void (* click_to_rename_mode_changed) (NemoView *view); 302 void (* sort_directories_first_changed) (NemoView *view); 303 304 /* Get the id string for this view. Its a constant string, not memory managed */ 305 const char * (* get_view_id) (NemoView *view); 306 307 /* Return the uri of the first visible file */ 308 char * (* get_first_visible_file) (NemoView *view); 309 /* Scroll the view so that the file specified by the uri is at the top 310 of the view */ 311 void (* scroll_to_file) (NemoView *view, 312 const char *uri); 313 314 /* Signals used only for keybindings */ 315 gboolean (* trash) (NemoView *view); 316 gboolean (* delete) (NemoView *view); 317 }; 318 319 /* GObject support */ 320 GType nemo_view_get_type (void); 321 322 /* Functions callable from the user interface and elsewhere. */ 323 NemoWindow *nemo_view_get_nemo_window (NemoView *view); 324 NemoWindowSlot *nemo_view_get_nemo_window_slot (NemoView *view); 325 char * nemo_view_get_uri (NemoView *view); 326 327 void nemo_view_display_selection_info (NemoView *view); 328 329 GdkAtom nemo_view_get_copied_files_atom (NemoView *view); 330 gboolean nemo_view_get_active (NemoView *view); 331 332 /* Wrappers for signal emitters. These are normally called 333 * only by NemoView itself. They have corresponding signals 334 * that observers might want to connect with. 335 */ 336 gboolean nemo_view_get_loading (NemoView *view); 337 338 /* Hooks for subclasses to call. These are normally called only by 339 * NemoView and its subclasses 340 */ 341 void nemo_view_activate_files (NemoView *view, 342 GList *files, 343 NemoWindowOpenFlags flags, 344 gboolean confirm_multiple); 345 void nemo_view_activate_file (NemoView *view, 346 NemoFile *file, 347 NemoWindowOpenFlags flags); 348 void nemo_view_preview_files (NemoView *view, 349 GList *files, 350 GArray *locations); 351 void nemo_view_start_batching_selection_changes (NemoView *view); 352 void nemo_view_stop_batching_selection_changes (NemoView *view); 353 void nemo_view_notify_selection_changed (NemoView *view); 354 GtkUIManager * nemo_view_get_ui_manager (NemoView *view); 355 NemoDirectory *nemo_view_get_model (NemoView *view); 356 NemoFile *nemo_view_get_directory_as_file (NemoView *view); 357 void nemo_view_pop_up_background_context_menu (NemoView *view, 358 GdkEventButton *event); 359 void nemo_view_pop_up_selection_context_menu (NemoView *view, 360 GdkEventButton *event); 361 gboolean nemo_view_should_show_file (NemoView *view, 362 NemoFile *file); 363 gboolean nemo_view_should_sort_directories_first (NemoView *view); 364 void nemo_view_ignore_hidden_file_preferences (NemoView *view); 365 void nemo_view_set_show_foreign (NemoView *view, 366 gboolean show_foreign); 367 gboolean nemo_view_handle_scroll_event (NemoView *view, 368 GdkEventScroll *event); 369 370 void nemo_view_freeze_updates (NemoView *view); 371 void nemo_view_unfreeze_updates (NemoView *view); 372 gboolean nemo_view_get_is_renaming (NemoView *view); 373 void nemo_view_set_is_renaming (NemoView *view, 374 gboolean renaming); 375 void nemo_view_add_subdirectory (NemoView *view, 376 NemoDirectory*directory); 377 void nemo_view_remove_subdirectory (NemoView *view, 378 NemoDirectory*directory); 379 380 gboolean nemo_view_is_editable (NemoView *view); 381 382 /* NemoView methods */ 383 const char * nemo_view_get_view_id (NemoView *view); 384 385 /* file operations */ 386 char * nemo_view_get_backing_uri (NemoView *view); 387 void nemo_view_move_copy_items (NemoView *view, 388 const GList *item_uris, 389 GArray *relative_item_points, 390 const char *target_uri, 391 int copy_action, 392 int x, 393 int y); 394 void nemo_view_new_file_with_initial_contents (NemoView *view, 395 const char *parent_uri, 396 const char *filename, 397 const char *initial_contents, 398 int length, 399 GdkPoint *pos); 400 401 /* selection handling */ 402 int nemo_view_get_selection_count (NemoView *view); 403 GList * nemo_view_get_selection (NemoView *view); 404 GList * nemo_view_peek_selection (NemoView *view); 405 gint nemo_view_get_selection_count (NemoView *view); 406 void nemo_view_set_selection (NemoView *view, 407 GList *selection); 408 409 410 void nemo_view_load_location (NemoView *view, 411 GFile *location); 412 void nemo_view_stop_loading (NemoView *view); 413 414 char ** nemo_view_get_emblem_names_to_exclude (NemoView *view); 415 char * nemo_view_get_first_visible_file (NemoView *view); 416 void nemo_view_scroll_to_file (NemoView *view, 417 const char *uri); 418 char * nemo_view_get_title (NemoView *view); 419 gboolean nemo_view_supports_zooming (NemoView *view); 420 void nemo_view_bump_zoom_level (NemoView *view, 421 int zoom_increment); 422 void nemo_view_zoom_to_level (NemoView *view, 423 NemoZoomLevel level); 424 void nemo_view_restore_default_zoom_level (NemoView *view); 425 gboolean nemo_view_can_zoom_in (NemoView *view); 426 gboolean nemo_view_can_zoom_out (NemoView *view); 427 NemoZoomLevel nemo_view_get_zoom_level (NemoView *view); 428 void nemo_view_pop_up_location_context_menu (NemoView *view, 429 GdkEventButton *event, 430 const char *location); 431 void nemo_view_grab_focus (NemoView *view); 432 void nemo_view_update_menus (NemoView *view); 433 void nemo_view_new_folder (NemoView *view); 434 435 #endif /* NEMO_VIEW_H */ 436