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
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-file-utilities..c - implementation of file manipulation routines.
Copyright (C) 1999, 2000 Eazel, Inc.
The Gnome 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.
The Gnome 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 the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: John Sullivan <sullivan@eazel.com>
*/
#include <config.h>
#include "nautilus-file-utilities.h"
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-util.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include "nautilus-file.h"
#include "nautilus-metadata.h"
const char* const nautilus_user_directory_name = ".nautilus";
const char* const nautilus_user_main_directory_name = "Nautilus";
const unsigned default_nautilus_directory_mode = 0755;
/**
* nautilus_make_path:
*
* Make a path name from a base path and name. The base path
* can end with or without a separator character.
*
* Return value: the combined path name.
**/
char *
nautilus_make_path(const char *path, const char* name)
{
gboolean insert_separator;
gint path_length;
char *result;
path_length = strlen (path);
insert_separator = path_length > 0 &&
name[0] != '\0' > 0 &&
path[path_length - 1] != G_DIR_SEPARATOR;
if (insert_separator) {
result = g_strconcat(path, G_DIR_SEPARATOR_S, name, NULL);
} else {
result = g_strconcat(path, name, NULL);
}
return result;
}
/**
* nautilus_user_directory:
*
* Get the path for the directory containing nautilus settings.
*
* Return value: the directory path.
**/
const char *
nautilus_user_directory()
{
static char *user_directory;
if (user_directory == NULL)
{
user_directory = nautilus_make_path (g_get_home_dir(),
nautilus_user_directory_name);
if (!g_file_exists (user_directory))
{
mkdir (user_directory, default_nautilus_directory_mode);
}
}
if (!g_file_test (user_directory, G_FILE_TEST_ISDIR))
{
/* Bad news, directory still isn't there.
* FIXME bugzilla.eazel.com 647: Report this to user somehow.
*/
g_assert_not_reached();
}
return user_directory;
}
/**
* nautilus_user_main_directory:
*
* Get the path for the user's main Nautilus directory.
* Usually ~/Nautilus
*
* Return value: the directory path.
**/
const char *
nautilus_user_main_directory (void)
{
static char *user_main_directory;
NautilusFile *file;
if (user_main_directory == NULL)
{
const char * user_directory;
user_directory = nautilus_user_directory ();
g_assert (user_directory != NULL);
user_main_directory = g_strdup_printf ("%s/%s",
g_get_home_dir(),
nautilus_user_main_directory_name);
if (!g_file_exists (user_main_directory))
{
char *src;
char *command;
char *file_uri, *image_uri, *temp_str;
src = gnome_datadir_file ("nautilus/top");
command = g_strdup_printf ("cp -R %s %s", src, user_main_directory);
if (system (command) != 0)
{
g_warning ("could not execute '%s'. Make sure you typed 'make install'",
command);
}
g_free (src);
g_free (command);
/* assign a custom image for the directory icon */
file_uri = g_strdup_printf("file://%s", user_main_directory);
temp_str = gnome_pixmap_file ("nautilus/nautilus-logo.png");
image_uri = g_strdup_printf("file://%s", temp_str);
g_free(temp_str);
file = nautilus_file_get (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
g_free(file_uri);
/* now do the same for the about file */
file_uri = g_strdup_printf("file://%s/About.html", user_main_directory);
file = nautilus_file_get (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
g_free(file_uri);
g_free(image_uri);
}
}
if (!g_file_test (user_main_directory, G_FILE_TEST_ISDIR))
{
/* Bad news, directory still isn't there.
* FIXME bugzilla.eazel.com 647: Report this to user somehow.
*/
g_assert_not_reached();
}
return user_main_directory;
}
|