summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-link.c
blob: bedf5954cb1c0a5625529d91e257521a14a7148b (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-

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

#include <config.h>
#include "nautilus-link.h"
#include "nautilus-link-historical.h"
#include "nautilus-link-desktop-file.h"

#include "nautilus-directory-notify.h"
#include "nautilus-directory.h"
#include "nautilus-file-attributes.h"
#include "nautilus-file.h"
#include "nautilus-metadata.h"
#include "nautilus-file-utilities.h"
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gnome-extensions.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-xml-extensions.h>
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libgnomevfs/gnome-vfs-mime.h>
#include <libgnomevfs/gnome-vfs.h>
#include <stdlib.h>

const char *get_uri_mime_type_full (const gchar *uri_path);

const char *
get_uri_mime_type_full (const gchar *uri_path)
{
	const gchar *retval;
	GnomeVFSURI *uri;

	uri = gnome_vfs_uri_new (uri_path);
	retval = gnome_vfs_get_mime_type (uri);
	gnome_vfs_uri_unref (uri);

	return retval;
}

gboolean
nautilus_link_local_create (const char *directory_path,
			    const char *name,
			    const char *image,
			    const char *target_uri,
			    const GdkPoint *point,
			    NautilusLinkType type)
{
	gboolean retval;

	retval = nautilus_link_desktop_file_local_create (directory_path,
							  name, image,
							  target_uri, point,
							  type);

	return retval;
}

gboolean
nautilus_link_local_set_icon (const char *path, const char *icon_name)
{
	const gchar *mime_type;
	gboolean retval;
	NautilusFile *file;
	GList *attributes;

	mime_type = get_uri_mime_type_full (path);
	retval = FALSE;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_set_icon (path, icon_name);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_local_set_icon (path, icon_name);
	}

	file = nautilus_file_get (path);
	attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI);
	nautilus_file_invalidate_attributes (file, attributes);
	nautilus_file_unref (file);
	g_list_free (attributes);
	
	return retval;
}

gboolean
nautilus_link_local_set_link_uri (const char *path, const char *link_uri)
{
	const gchar *mime_type;
	gboolean retval;
	NautilusFile *file;
	GList *attributes;

	mime_type = get_uri_mime_type_full (path);
	retval = FALSE;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_set_link_uri (path, link_uri);
	}
	/* FIXME: May want to implement this for desktop files too */
	
	file = nautilus_file_get (path);
	attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI);
	nautilus_file_invalidate_attributes (file, attributes);
	nautilus_file_unref (file);
	g_list_free (attributes);

	return retval;
}

gboolean
nautilus_link_local_set_type (const char *path,
			      NautilusLinkType type)
{
	const gchar *mime_type;
	gboolean retval;

	mime_type = get_uri_mime_type_full (path);
	retval = FALSE;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_set_type (path, type);
	} 
	/* FIXME: May want to implement this for desktop files too */

	return retval;
}

/* returns additional text to display under the name, NULL if none */
char *
nautilus_link_local_get_additional_text (const char *path)
{
	const gchar *mime_type;
	gchar *retval;

	mime_type = get_uri_mime_type_full (path);
	retval = NULL;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_get_additional_text (path);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_local_get_additional_text (path);
	}

	return retval;
}

/* Returns the link uri associated with a link file. */
char *
nautilus_link_local_get_link_uri (const char *path)
{
	const gchar *mime_type;
	gchar *retval;

	mime_type = get_uri_mime_type_full (path);
	retval = NULL;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_get_link_uri (path);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_local_get_link_uri (path);
	}

	return retval;
}

/* Returns the link type of the link file. */
NautilusLinkType
nautilus_link_local_get_link_type (const char *path)
{
	const gchar *mime_type;
 	NautilusLinkType retval;

	mime_type = get_uri_mime_type_full (path);
	retval = NAUTILUS_LINK_GENERIC;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_get_link_type (path);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_local_get_link_type (path);
	}

	return retval;
}

char *
nautilus_link_get_link_uri_given_file_contents (const char *file_contents,
						int file_size)
{
	const gchar *mime_type;
	gchar *retval;

	mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
	retval = NULL;

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_get_link_uri_given_file_contents (file_contents, file_size);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_get_link_uri_given_file_contents (file_contents, file_size);
	}

	return retval;
}

char *
nautilus_link_get_link_name_given_file_contents (const char *file_contents,
						int file_size)
{
	const gchar *mime_type;
	gchar *retval;

	mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
	retval = NULL;

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = NULL;
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_get_link_name_given_file_contents (file_contents, file_size);
	}

	return retval;
}

char *
nautilus_link_get_link_icon_given_file_contents (const char *file_contents,
						int file_size)
{
	const gchar *mime_type;
	gchar *retval;

	mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
	retval = NULL;

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_get_link_icon_given_file_contents (file_contents, file_size);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_get_link_icon_given_file_contents (file_contents, file_size);
	}

	return retval;
}

gboolean
nautilus_link_local_is_volume_link (const char *path)
{
	const gchar *mime_type;
	gboolean retval;

	mime_type = get_uri_mime_type_full (path);
	retval = FALSE;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_is_volume_link (path);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_local_is_volume_link (path);
	}

	return retval;
}

gboolean
nautilus_link_local_is_home_link (const char *path)
{
	const gchar *mime_type;
	gboolean retval;

	mime_type = get_uri_mime_type_full (path);
	retval = FALSE;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_is_home_link (path);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_local_is_home_link (path);
	}

	return retval;
}

gboolean
nautilus_link_local_is_trash_link (const char *path)
{
	const gchar *mime_type;
	gboolean retval;

	mime_type = get_uri_mime_type_full (path);
	retval = FALSE;

	if (mime_type == NULL) {
		return retval;
	}

	if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
		retval = nautilus_link_historical_local_is_trash_link (path);
	} else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
		retval = nautilus_link_desktop_file_local_is_trash_link (path);
	}

	return retval;
}


void
nautilus_link_local_create_from_gnome_entry (GnomeDesktopEntry *entry, const char *dest_path, const GdkPoint *position)
{
	nautilus_link_desktop_file_local_create_from_gnome_entry (entry, dest_path, position);
}