1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
2 
3    nemo-vfs-directory.c: Subclass of NemoDirectory to help implement the
4    virtual trash directory.
5 
6    Copyright (C) 1999, 2000 Eazel, Inc.
7 
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (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 GNU
16    General Public License for more details.
17 
18    You should have received a copy of the GNU General Public
19    License along with this program; if not, write to the
20    Free Software Foundation, Inc., 51 Franklin Street - Suite 500,
21    Boston, MA 02110-1335, USA.
22 
23    Author: Darin Adler <darin@bentspoon.com>
24 */
25 
26 #include <config.h>
27 #include "nemo-vfs-directory.h"
28 
29 #include "nemo-directory-private.h"
30 #include "nemo-file-private.h"
31 
32 G_DEFINE_TYPE (NemoVFSDirectory, nemo_vfs_directory, NEMO_TYPE_DIRECTORY);
33 
34 static void
nemo_vfs_directory_init(NemoVFSDirectory * directory)35 nemo_vfs_directory_init (NemoVFSDirectory *directory)
36 {
37 
38 }
39 
40 static gboolean
vfs_contains_file(NemoDirectory * directory,NemoFile * file)41 vfs_contains_file (NemoDirectory *directory,
42 		   NemoFile *file)
43 {
44 	g_assert (NEMO_IS_VFS_DIRECTORY (directory));
45 	g_assert (NEMO_IS_FILE (file));
46 
47 	return file->details->directory == directory;
48 }
49 
50 static void
vfs_call_when_ready(NemoDirectory * directory,NemoFileAttributes file_attributes,gboolean wait_for_file_list,NemoDirectoryCallback callback,gpointer callback_data)51 vfs_call_when_ready (NemoDirectory *directory,
52 		     NemoFileAttributes file_attributes,
53 		     gboolean wait_for_file_list,
54 		     NemoDirectoryCallback callback,
55 		     gpointer callback_data)
56 {
57 	g_assert (NEMO_IS_VFS_DIRECTORY (directory));
58 
59 	nemo_directory_call_when_ready_internal
60 		(directory,
61 		 NULL,
62 		 file_attributes,
63 		 wait_for_file_list,
64 		 callback,
65 		 NULL,
66 		 callback_data);
67 }
68 
69 static void
vfs_cancel_callback(NemoDirectory * directory,NemoDirectoryCallback callback,gpointer callback_data)70 vfs_cancel_callback (NemoDirectory *directory,
71 		     NemoDirectoryCallback callback,
72 		     gpointer callback_data)
73 {
74 	g_assert (NEMO_IS_VFS_DIRECTORY (directory));
75 
76 	nemo_directory_cancel_callback_internal
77 		(directory,
78 		 NULL,
79 		 callback,
80 		 NULL,
81 		 callback_data);
82 }
83 
84 static void
vfs_file_monitor_add(NemoDirectory * directory,gconstpointer client,gboolean monitor_hidden_files,NemoFileAttributes file_attributes,NemoDirectoryCallback callback,gpointer callback_data)85 vfs_file_monitor_add (NemoDirectory *directory,
86 		      gconstpointer client,
87 		      gboolean monitor_hidden_files,
88 		      NemoFileAttributes file_attributes,
89 		      NemoDirectoryCallback callback,
90 		      gpointer callback_data)
91 {
92 	g_assert (NEMO_IS_VFS_DIRECTORY (directory));
93 	g_assert (client != NULL);
94 
95 	nemo_directory_monitor_add_internal
96 		(directory, NULL,
97 		 client,
98 		 monitor_hidden_files,
99 		 file_attributes,
100 		 callback, callback_data);
101 }
102 
103 static void
vfs_file_monitor_remove(NemoDirectory * directory,gconstpointer client)104 vfs_file_monitor_remove (NemoDirectory *directory,
105 			 gconstpointer client)
106 {
107 	g_assert (NEMO_IS_VFS_DIRECTORY (directory));
108 	g_assert (client != NULL);
109 
110 	nemo_directory_monitor_remove_internal (directory, NULL, client);
111 }
112 
113 static void
vfs_force_reload(NemoDirectory * directory)114 vfs_force_reload (NemoDirectory *directory)
115 {
116 	NemoFileAttributes all_attributes;
117 
118 	g_assert (NEMO_IS_DIRECTORY (directory));
119 
120 	all_attributes = nemo_file_get_all_attributes ();
121 	nemo_directory_force_reload_internal (directory,
122 						  all_attributes);
123 }
124 
125 static gboolean
vfs_are_all_files_seen(NemoDirectory * directory)126 vfs_are_all_files_seen (NemoDirectory *directory)
127 {
128 	g_assert (NEMO_IS_VFS_DIRECTORY (directory));
129 
130 	return directory->details->directory_loaded;
131 }
132 
133 static gboolean
vfs_is_not_empty(NemoDirectory * directory)134 vfs_is_not_empty (NemoDirectory *directory)
135 {
136 	g_assert (NEMO_IS_VFS_DIRECTORY (directory));
137 	g_assert (nemo_directory_is_anyone_monitoring_file_list (directory));
138 
139 	return directory->details->file_list != NULL;
140 }
141 
142 static void
nemo_vfs_directory_class_init(NemoVFSDirectoryClass * klass)143 nemo_vfs_directory_class_init (NemoVFSDirectoryClass *klass)
144 {
145 	NemoDirectoryClass *directory_class = NEMO_DIRECTORY_CLASS (klass);
146 
147 	directory_class->contains_file = vfs_contains_file;
148 	directory_class->call_when_ready = vfs_call_when_ready;
149 	directory_class->cancel_callback = vfs_cancel_callback;
150 	directory_class->file_monitor_add = vfs_file_monitor_add;
151 	directory_class->file_monitor_remove = vfs_file_monitor_remove;
152 	directory_class->force_reload = vfs_force_reload;
153 	directory_class->are_all_files_seen = vfs_are_all_files_seen;
154 	directory_class->is_not_empty = vfs_is_not_empty;
155 }
156