summaryrefslogtreecommitdiff
path: root/libnautilus-extensions/nautilus-directory-metafile-monitor.c
blob: 47251d0b354c1ad7961f05fc5ddecfa5ab6a7ad2 (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
/* -*- 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 <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-bonobo-extensions.h>
#include <libnautilus/nautilus-bonobo-workarounds.h>

struct NautilusMetafileMonitorDetails {
	NautilusDirectory *directory;
};

static void nautilus_metafile_monitor_init       (NautilusMetafileMonitor      *monitor);
static void nautilus_metafile_monitor_class_init (NautilusMetafileMonitorClass *klass);

static void destroy (GtkObject *monitor);

static void corba_metafile_changed (PortableServer_Servant       servant,
				    const Nautilus_FileNameList *file_names,
				    CORBA_Environment           *ev);

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

NAUTILUS_BONOBO_X_BOILERPLATE (NautilusMetafileMonitor, Nautilus_MetafileMonitor, BONOBO_X_OBJECT_TYPE, nautilus_metafile_monitor)

static void
nautilus_metafile_monitor_class_init (NautilusMetafileMonitorClass *klass)
{
	GTK_OBJECT_CLASS (klass)->destroy = destroy;

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

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

static void
destroy (GtkObject *object)
{
	NautilusMetafileMonitor *monitor;

	monitor = NAUTILUS_METAFILE_MONITOR (object);
	g_free (monitor->details);

	NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}

NautilusMetafileMonitor *
nautilus_metafile_monitor_new (NautilusDirectory *directory)
{
	NautilusMetafileMonitor *monitor;
	monitor = NAUTILUS_METAFILE_MONITOR (gtk_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);
}