mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-09-17 23:01:59 +00:00
bc8ad1bf56
* configure.in: * cut-n-paste-code/widgets/Makefile.am: * cut-n-paste-code/widgets/e-paned: * libnautilus-private/Makefile.am: * libnautilus-private/nautilus-horizontal-splitter.c: * libnautilus-private/nautilus-horizontal-splitter.h: * src/nautilus-window.c: (nautilus_window_constructed), (nautilus_window_set_content_view_widget), (nautilus_window_hide_sidebar), (nautilus_window_show_sidebar), (nautilus_window_sidebar_showing): Remove e-paned. * configure.in: * data/Makefile.am: * data/linksets/ * libnautilus-private/Makefile.am: * libnautilus-private/nautilus-file-utilities.c: * libnautilus-private/nautilus-link-set.c: * libnautilus-private/nautilus-link-set.h: * src/Makefile.am: * src/nautilus-link-set-window.c: * src/nautilus-link-set-window.h: * src/nautilus-sidebar.c: (metadata_button_callback): Remove link sets. * libnautilus-private/nautilus-program-chooser.c: (launch_mime_capplet_on_ok), (launch_mime_capplet_and_close_dialog): * src/nautilus-window-menus.c: (forget_history_if_yes), (remove_bookmarks_for_uri_if_yes): Destroy dialogs when done, since GtkDialog doesn't do this for us. * src/nautilus-preferences-dialog.c: (preferences_dialog_create): Get rid of close signal handler, since default close handler does the same thing as a delete_event, which is what we want. We still might have to do something fancier on a delete_event.
272 lines
6.8 KiB
C
272 lines
6.8 KiB
C
/* -*- 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, 2001 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 "nautilus-global-preferences.h"
|
|
#include "nautilus-lib-self-check-functions.h"
|
|
#include "nautilus-metadata.h"
|
|
#include "nautilus-metafile.h"
|
|
#include <eel/eel-glib-extensions.h>
|
|
#include <eel/eel-string.h>
|
|
#include <libgnome/gnome-util.h>
|
|
#include <libgnomevfs/gnome-vfs-ops.h>
|
|
#include <libgnomevfs/gnome-vfs-uri.h>
|
|
#include <libgnomevfs/gnome-vfs-utils.h>
|
|
#include <unistd.h>
|
|
|
|
#define NAUTILUS_USER_DIRECTORY_NAME ".nautilus"
|
|
#define DEFAULT_NAUTILUS_DIRECTORY_MODE (0755)
|
|
|
|
#define DESKTOP_DIRECTORY_NAME ".gnome-desktop"
|
|
#define DEFAULT_DESKTOP_DIRECTORY_MODE (0755)
|
|
|
|
gboolean
|
|
nautilus_file_name_matches_hidden_pattern (const char *name_or_relative_uri)
|
|
{
|
|
g_return_val_if_fail (name_or_relative_uri != NULL, FALSE);
|
|
|
|
return name_or_relative_uri[0] == '.';
|
|
}
|
|
|
|
gboolean
|
|
nautilus_file_name_matches_backup_pattern (const char *name_or_relative_uri)
|
|
{
|
|
g_return_val_if_fail (name_or_relative_uri != NULL, FALSE);
|
|
|
|
return eel_str_has_suffix (name_or_relative_uri, "~");
|
|
}
|
|
|
|
gboolean
|
|
nautilus_file_name_matches_metafile_pattern (const char *name_or_relative_uri)
|
|
{
|
|
g_return_val_if_fail (name_or_relative_uri != NULL, FALSE);
|
|
|
|
return eel_str_has_suffix (name_or_relative_uri, NAUTILUS_METAFILE_NAME_SUFFIX);
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
int path_length;
|
|
char *result;
|
|
|
|
path_length = strlen (path);
|
|
insert_separator = path_length > 0 &&
|
|
name[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_get_user_directory:
|
|
*
|
|
* Get the path for the directory containing nautilus settings.
|
|
*
|
|
* Return value: the directory path.
|
|
**/
|
|
char *
|
|
nautilus_get_user_directory (void)
|
|
{
|
|
char *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);
|
|
/* FIXME bugzilla.gnome.org 41286:
|
|
* How should we handle the case where this mkdir fails?
|
|
* Note that nautilus_application_startup will refuse to launch if this
|
|
* directory doesn't get created, so that case is OK. But the directory
|
|
* could be deleted after Nautilus was launched, and perhaps
|
|
* there is some bad side-effect of not handling that case.
|
|
*/
|
|
}
|
|
|
|
return user_directory;
|
|
}
|
|
|
|
/**
|
|
* nautilus_get_desktop_directory:
|
|
*
|
|
* Get the path for the directory containing files on the desktop.
|
|
*
|
|
* Return value: the directory path.
|
|
**/
|
|
char *
|
|
nautilus_get_desktop_directory (void)
|
|
{
|
|
char *desktop_directory;
|
|
|
|
if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR)) {
|
|
desktop_directory = g_strdup (g_get_home_dir());
|
|
} else {
|
|
desktop_directory = nautilus_get_gmc_desktop_directory ();
|
|
if (!g_file_exists (desktop_directory)) {
|
|
mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
|
|
/* FIXME bugzilla.gnome.org 41286:
|
|
* How should we handle the case where this mkdir fails?
|
|
* Note that nautilus_application_startup will refuse to launch if this
|
|
* directory doesn't get created, so that case is OK. But the directory
|
|
* could be deleted after Nautilus was launched, and perhaps
|
|
* there is some bad side-effect of not handling that case.
|
|
*/
|
|
}
|
|
}
|
|
|
|
return desktop_directory;
|
|
}
|
|
|
|
/**
|
|
* nautilus_get_gmc_desktop_directory:
|
|
*
|
|
* Get the path for the directory containing the legacy gmc desktop.
|
|
*
|
|
* Return value: the directory path.
|
|
**/
|
|
char *
|
|
nautilus_get_gmc_desktop_directory (void)
|
|
{
|
|
return nautilus_make_path (g_get_home_dir (), DESKTOP_DIRECTORY_NAME);
|
|
}
|
|
|
|
/**
|
|
* nautilus_get_pixmap_directory
|
|
*
|
|
* Get the path for the directory containing Nautilus pixmaps.
|
|
*
|
|
* Return value: the directory path.
|
|
**/
|
|
char *
|
|
nautilus_get_pixmap_directory (void)
|
|
{
|
|
return g_strdup (DATADIR "/pixmaps/nautilus");
|
|
}
|
|
|
|
/* FIXME bugzilla.gnome.org 42423:
|
|
* Callers just use this and dereference so we core dump if
|
|
* pixmaps are missing. That is lame.
|
|
*/
|
|
char *
|
|
nautilus_pixmap_file (const char *partial_path)
|
|
{
|
|
char *path;
|
|
|
|
path = nautilus_make_path (DATADIR "/pixmaps/nautilus", partial_path);
|
|
if (g_file_exists (path)) {
|
|
return path;
|
|
}
|
|
g_free (path);
|
|
return NULL;
|
|
}
|
|
|
|
char *
|
|
nautilus_get_data_file_path (const char *partial_path)
|
|
{
|
|
char *path;
|
|
char *user_directory;
|
|
|
|
/* first try the user's home directory */
|
|
user_directory = nautilus_get_user_directory ();
|
|
path = nautilus_make_path (user_directory, partial_path);
|
|
g_free (user_directory);
|
|
if (g_file_exists (path)) {
|
|
return path;
|
|
}
|
|
g_free (path);
|
|
|
|
/* next try the shared directory */
|
|
path = nautilus_make_path (NAUTILUS_DATADIR, partial_path);
|
|
if (g_file_exists (path)) {
|
|
return path;
|
|
}
|
|
g_free (path);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
char *
|
|
nautilus_unique_temporary_file_name (void)
|
|
{
|
|
const char *prefix = "/tmp/nautilus-temp-file";
|
|
char *file_name;
|
|
static guint count = 1;
|
|
|
|
file_name = g_strdup_printf ("%sXXXXXX", prefix);
|
|
|
|
if (mktemp (file_name) != file_name) {
|
|
g_free (file_name);
|
|
file_name = g_strdup_printf ("%s-%d-%d", prefix, count++, getpid ());
|
|
}
|
|
|
|
return file_name;
|
|
}
|
|
|
|
char *
|
|
nautilus_get_build_time_stamp (void)
|
|
{
|
|
#ifdef EAZEL_BUILD_TIMESTAMP
|
|
return g_strdup (EAZEL_BUILD_TIMESTAMP);
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|
|
|
|
char *
|
|
nautilus_get_build_message (void)
|
|
{
|
|
#ifdef NAUTILUS_BUILD_MESSAGE
|
|
return g_strdup (NAUTILUS_BUILD_MESSAGE);
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|
|
|
|
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
|
|
|
|
void
|
|
nautilus_self_check_file_utilities (void)
|
|
{
|
|
}
|
|
|
|
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
|