summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-directory-metafile-monitor.c
blob: 3cc32d56a44f831a4d7f2b567b4d658a454a5be9 (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
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-directory-metafile-monitor.c
 *
 * Copyright (C) 2001 Eazel, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include "nautilus-directory-metafile-monitor.h"

#include "nautilus-directory-private.h"
#include "nautilus-file-private.h"

#include <eel/eel-gtk-macros.h>
#include <eel/eel-glib-extensions.h>
#include "nautilus-bonobo-extensions.h"

struct NautilusMetafileMonitorDetails {
	NautilusDirectory *directory;
};

BONOBO_CLASS_BOILERPLATE_FULL (NautilusMetafileMonitor, nautilus_metafile_monitor,
			       Nautilus_MetafileMonitor,
			       BonoboObject, BONOBO_OBJECT_TYPE)

static void
nautilus_metafile_monitor_instance_init (NautilusMetafileMonitor *monitor)
{
	monitor->details = g_new0 (NautilusMetafileMonitorDetails, 1);
}

static void
finalize (GObject *object)
{
	NautilusMetafileMonitor *monitor;

	monitor = NAUTILUS_METAFILE_MONITOR (object);

	g_free (monitor->details);

	G_OBJECT_CLASS (parent_class)->finalize (object);
}

NautilusMetafileMonitor *
nautilus_metafile_monitor_new (NautilusDirectory *directory)
{
	NautilusMetafileMonitor *monitor;
	
	monitor = NAUTILUS_METAFILE_MONITOR (g_object_new (NAUTILUS_TYPE_METAFILE_MONITOR, NULL));
	monitor->details->directory = directory;
	/* The monitor is owned by the directory, so we don't ref the directory. */
	return monitor;
}

static void
corba_metafile_changed (PortableServer_Servant       servant,
			const Nautilus_FileNameList *file_names,
			CORBA_Environment           *ev)
{
	GList                   *file_list;
	NautilusFile		*file;
	CORBA_unsigned_long      buf_pos;
	NautilusMetafileMonitor *monitor;
	
	monitor = NAUTILUS_METAFILE_MONITOR (bonobo_object_from_servant (servant));

	file_list = NULL;
	
	for (buf_pos = 0; buf_pos < file_names->_length; ++buf_pos) {
		file = nautilus_directory_find_file_by_internal_uri
			(monitor->details->directory, file_names->_buffer [buf_pos]);

		if (file != NULL) {
			if (nautilus_file_is_self_owned (file)) {
				nautilus_file_emit_changed (file);
			} else {
				file_list = g_list_prepend (file_list, file);
			}
		}
	}

	if (file_list != NULL) {
		file_list = g_list_reverse (file_list);
		nautilus_directory_emit_change_signals (monitor->details->directory, file_list);
		g_list_free (file_list);
	}
}

static void
corba_metafile_ready (PortableServer_Servant       servant,
		      CORBA_Environment           *ev)
{
	NautilusMetafileMonitor *monitor;

	monitor = NAUTILUS_METAFILE_MONITOR (bonobo_object_from_servant (servant));
	emit_change_signals_for_all_files (monitor->details->directory);
	nautilus_idle_queue_add (monitor->details->directory->details->idle_queue,
				 (GFunc) nautilus_directory_async_state_changed,
				 monitor->details->directory,
				 NULL,
				 NULL);
}

static void
nautilus_metafile_monitor_class_init (NautilusMetafileMonitorClass *klass)
{
	G_OBJECT_CLASS (klass)->finalize = finalize;

	klass->epv.metafile_changed = corba_metafile_changed;
	klass->epv.metafile_ready   = corba_metafile_ready;
}