Commit 7e292ac0 authored by Darin Adler's avatar Darin Adler

Added first cut at code to put metafiles in the user's home directory if

	* libnautilus/nautilus-directory.c:
	(nautilus_directory_read_metafile):
	(nautilus_directory_try_to_read_metafile):
	(nautilus_directory_write_metafile):
	(nautilus_directory_try_to_write_metafile):
	(nautilus_directory_switch_to_alternate_metafile_uri):
	(nautilus_directory_escape_slashes):
	(nautilus_make_directory_and_parents): Added first cut at code to
	put metafiles in the user's home directory if the directory is not
	accessible and you can't read and write a metafile in the
	directory itself. We'll have to refine this later to handle cases
	where you end up with two metafiles.

	* libnautilus/Makefile.am: libnautilus/nautilus-debug.h:
	libnautilus/nautilus-debug.c: Took trick for getting into the
	debugger and put it into a public header file so it can be used
	outside of the nautilus executable.

	* src/ntl-main.c: (stop_in_debugger):
	(nautilus_stop_after_default_log_handler): (main): Use the new
	calls from libnautilus to set up the drop into debugger for
	criticals and warnings.

	* src/file-manager/fm-main.c: (main): Minimized includes and used
	the new calls from libnautilus to set up the drop into debugger
	for criticals and warnings.

	* src/ntl-uri-map.c: (nautilus_navinfo_add_mapping):
	src/ntl-window.c: (nautilus_window_constructed):
	src/file-manager/fm-directory-view.c:
	(fm_directory_view_initialize): (fm_directory_view_destroy):
	(notify_location_change_cb): (stop_location_change_cb):
	(fm_directory_view_sort): Removed some messages that aren't so
	useful.

	* libnautilus/ntl-view-frame.h: Minimized includes.
	* libnautilus/ntl-view-frame.c: Include "ntl-view-frame.h" first
	so it tests to see that it has sufficient includes in it.

	* src/ntl-view.c: (nautilus_view_load_client): Changed function so
	that NULL for an iid is allowed and simply results in a failed
	load instead of being illegal.

	* src/ntl-window-msgs.c:
	(nautilus_window_change_location_internal): src/ntl-window.c:
	(nautilus_window_up): Got rid of calls to gnome_vfs_uri_destroy;
	use gnome_vfs_uri_unref instead since it's safer and Federico is
	getting rid of gnome_vfs_uri_destroy.

	* src/file-manager/fm-directory-view-icons.h:
	src/file-manager/fm-directory-view-icons.c:
	(fm_directory_view_icons_new):
	src/file-manager/fm-directory-view-list.h:
	src/file-manager/fm-directory-view-list.c:
	(fm_directory_view_list_new):
	src/file-manager/fm-directory-view.h:
	src/file-manager/fm-directory-view.c: (fm_directory_view_new):
	Minimized includes and got rid of the unused _new functions.

	* libnautilus/nautilus-directory.h: Added a missing 2000 copyright
	date.
parent 98d22d4f
2000-01-18 Darin Adler <darin@eazel.com>
* libnautilus/nautilus-directory.c:
(nautilus_directory_read_metafile):
(nautilus_directory_try_to_read_metafile):
(nautilus_directory_write_metafile):
(nautilus_directory_try_to_write_metafile):
(nautilus_directory_switch_to_alternate_metafile_uri):
(nautilus_directory_escape_slashes):
(nautilus_make_directory_and_parents): Added first cut at code to
put metafiles in the user's home directory if the directory is not
accessible and you can't read and write a metafile in the
directory itself. We'll have to refine this later to handle cases
where you end up with two metafiles.
* libnautilus/Makefile.am: libnautilus/nautilus-debug.h:
libnautilus/nautilus-debug.c: Took trick for getting into the
debugger and put it into a public header file so it can be used
outside of the nautilus executable.
* src/ntl-main.c: (stop_in_debugger):
(nautilus_stop_after_default_log_handler): (main): Use the new
calls from libnautilus to set up the drop into debugger for
criticals and warnings.
* src/file-manager/fm-main.c: (main): Minimized includes and used
the new calls from libnautilus to set up the drop into debugger
for criticals and warnings.
* src/ntl-uri-map.c: (nautilus_navinfo_add_mapping):
src/ntl-window.c: (nautilus_window_constructed):
src/file-manager/fm-directory-view.c:
(fm_directory_view_initialize): (fm_directory_view_destroy):
(notify_location_change_cb): (stop_location_change_cb):
(fm_directory_view_sort): Removed some messages that aren't so
useful.
* libnautilus/ntl-view-frame.h: Minimized includes.
* libnautilus/ntl-view-frame.c: Include "ntl-view-frame.h" first
so it tests to see that it has sufficient includes in it.
* src/ntl-view.c: (nautilus_view_load_client): Changed function so
that NULL for an iid is allowed and simply results in a failed
load instead of being illegal.
* src/ntl-window-msgs.c:
(nautilus_window_change_location_internal): src/ntl-window.c:
(nautilus_window_up): Got rid of calls to gnome_vfs_uri_destroy;
use gnome_vfs_uri_unref instead since it's safer and Federico is
getting rid of gnome_vfs_uri_destroy.
* src/file-manager/fm-directory-view-icons.h:
src/file-manager/fm-directory-view-icons.c:
(fm_directory_view_icons_new):
src/file-manager/fm-directory-view-list.h:
src/file-manager/fm-directory-view-list.c:
(fm_directory_view_list_new):
src/file-manager/fm-directory-view.h:
src/file-manager/fm-directory-view.c: (fm_directory_view_new):
Minimized includes and got rid of the unused _new functions.
* libnautilus/nautilus-directory.h: Added a missing 2000 copyright
date.
2000-01-17 John Sullivan <sullivan@eazel.com>
First steps towards making the list view non-degenerate.
......
......@@ -32,6 +32,7 @@ libnautilusinclude_HEADERS= \
gtkscrollframe.h \
nautilus.h \
nautilus-background.h \
nautilus-debug.h \
nautilus-directory.h \
nautilus-file-utilities.h \
nautilus-gtk-extensions.h \
......@@ -51,6 +52,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
gtkscrollframe.c \
nautilus-background.c \
nautilus-background-canvas-group.c \
nautilus-debug.c \
nautilus-directory.c \
nautilus-file-utilities.c \
nautilus-gtk-extensions.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-debug.c: Nautilus debugging aids.
Copyright (C) 2000 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: Darin Adler <darin@eazel.com>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "nautilus-debug.h"
#include <glib.h>
#include <signal.h>
/* Raise a SIGINT signal to get the attention of the debugger.
When not running under the debugger, we don't want to stop,
so we ignore the signal for just the moment that we raise it.
*/
void
nautilus_stop_in_debugger (void)
{
void (* saved_handler) (int);
saved_handler = signal (SIGINT, SIG_IGN);
raise (SIGINT);
signal (SIGINT, saved_handler);
}
/* Stop in the debugger after running the default log handler.
This makes certain kinds of messages stop in the debugger
without making them fatal.
*/
static void
nautilus_stop_after_default_log_handler (const char *domain,
GLogLevelFlags level,
const char *message,
gpointer data)
{
g_log_default_handler (domain, level, message, data);
nautilus_stop_in_debugger ();
}
static void
nautilus_set_stop_after_default_log_handler (const char *domain)
{
g_log_set_handler (domain, G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
nautilus_stop_after_default_log_handler, NULL);
}
void
nautilus_make_warnings_and_criticals_stop_in_debugger (const char *first_domain, ...)
{
va_list domains;
const char *domain;
nautilus_set_stop_after_default_log_handler (first_domain);
va_start (domains, first_domain);
for (;;) {
domain = va_arg (domains, const char *);
if (domain == NULL)
break;
nautilus_set_stop_after_default_log_handler (domain);
}
va_end (domains);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-debug.h: Nautilus debugging aids.
Copyright (C) 2000 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: Darin Adler <darin@eazel.com>
*/
#ifndef NAUTILUS_DEBUG_H
#define NAUTILUS_DEBUG_H
void nautilus_stop_in_debugger (void);
void nautilus_make_warnings_and_criticals_stop_in_debugger (const char *first_domain, ...);
#endif /* NAUTILUS_DEBUG_H */
......@@ -45,7 +45,18 @@
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-string.h"
#define METAFILE_NAME ".nautilus.xml"
#define METAFILE_NAME ".nautilus-metafile.xml"
#define METAFILE_PERMISSIONS (GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_USER_WRITE \
| GNOME_VFS_PERM_GROUP_READ | GNOME_VFS_PERM_GROUP_WRITE \
| GNOME_VFS_PERM_OTHER_READ | GNOME_VFS_PERM_OTHER_WRITE)
#define NAUTILUS_DIRECTORY_NAME ".nautilus"
#define METAFILES_DIRECTORY_NAME "metafiles"
#define METAFILES_DIRECTORY_PERMISSIONS (GNOME_VFS_PERM_USER_ALL \
| GNOME_VFS_PERM_GROUP_ALL \
| GNOME_VFS_PERM_OTHER_ALL)
#define METAFILE_SUFFIX ".xml"
#define METAFILE_XML_VERSION "1.0"
static void nautilus_directory_initialize_class (gpointer klass);
......@@ -58,6 +69,7 @@ static void nautilus_directory_read_metafile (NautilusDirectory *directory);
static void nautilus_directory_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_request_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory);
static gboolean nautilus_directory_switch_to_alternate_metafile_uri (NautilusDirectory *directory);
NAUTILUS_DEFINE_GET_TYPE_FUNCTION (NautilusDirectory, nautilus_directory, GTK_TYPE_OBJECT)
......@@ -69,6 +81,7 @@ struct _NautilusDirectoryDetails
GnomeVFSURI *uri;
GnomeVFSURI *metafile_uri;
gboolean is_alternate_metafile_uri;
xmlDoc *metafile_tree;
int write_metafile_idle_id;
......@@ -172,52 +185,39 @@ nautilus_directory_get (const char *uri)
with async. calls; currently you can only get the file length with
a synchronous call.
*/
static void
nautilus_directory_read_metafile (NautilusDirectory *directory)
static GnomeVFSResult
nautilus_directory_try_to_read_metafile (NautilusDirectory *directory)
{
GnomeVFSResult result;
GnomeVFSFileInfo metafile_info;
GnomeVFSHandle *metafile_handle;
char *buffer;
GnomeVFSFileSize size, actual_size;
char *buffer;
g_assert (directory->details->metafile_tree == NULL);
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), GNOME_VFS_ERROR_GENERIC);
g_return_val_if_fail (directory->details->metafile_tree == NULL, GNOME_VFS_ERROR_GENERIC);
result = gnome_vfs_get_file_info_uri (directory->details->metafile_uri,
&metafile_info,
GNOME_VFS_FILE_INFO_DEFAULT,
NULL);
if (result == GNOME_VFS_ERROR_NOTFOUND)
return;
if (result != GNOME_VFS_OK)
g_warning ("nautilus_directory_read_metafile: gnome_vfs_get_file_info_uri failed");
metafile_handle = NULL;
if (result == GNOME_VFS_OK) {
if (result == GNOME_VFS_OK)
result = gnome_vfs_open_uri (&metafile_handle,
directory->details->metafile_uri,
GNOME_VFS_OPEN_READ);
if (result != GNOME_VFS_OK)
g_warning ("nautilus_directory_read_metafile: gnome_vfs_open_uri failed");
}
if (result == GNOME_VFS_OK) {
size = metafile_info.size;
if (size != metafile_info.size) {
g_warning ("nautilus_directory_read_metafile: metafile too large");
if (size != metafile_info.size)
result = GNOME_VFS_ERROR_TOOBIG;
}
}
buffer = NULL;
if (result == GNOME_VFS_OK) {
buffer = g_malloc (size);
result = gnome_vfs_read (metafile_handle, buffer, size, &actual_size);
if (result != GNOME_VFS_OK)
g_warning ("nautilus_directory_read_metafile: gnome_vfs_read failed");
else if (actual_size != size)
g_warning ("nautilus_directory_read_metafile: size changed between get_info and read");
}
if (metafile_handle != NULL)
......@@ -227,6 +227,24 @@ nautilus_directory_read_metafile (NautilusDirectory *directory)
directory->details->metafile_tree = xmlParseMemory (buffer, actual_size);
g_free (buffer);
return result;
}
static void
nautilus_directory_read_metafile (NautilusDirectory *directory)
{
GnomeVFSResult result;
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
result = nautilus_directory_try_to_read_metafile (directory);
if (result == GNOME_VFS_ERROR_ACCESSDENIED && !directory->details->is_alternate_metafile_uri)
if (nautilus_directory_switch_to_alternate_metafile_uri (directory))
result = nautilus_directory_try_to_read_metafile (directory);
if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_NOTFOUND)
g_warning ("nautilus_directory_read_metafile failed to read metafile - we should report this to the user");
}
static void
......@@ -239,8 +257,8 @@ nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory)
}
/* This writes the metafile synchronously. This must go eventually. */
static void
nautilus_directory_write_metafile (NautilusDirectory *directory)
static GnomeVFSResult
nautilus_directory_try_to_write_metafile (NautilusDirectory *directory)
{
xmlChar *buffer;
int buffer_size;
......@@ -248,43 +266,58 @@ nautilus_directory_write_metafile (NautilusDirectory *directory)
GnomeVFSHandle *metafile_handle;
GnomeVFSFileSize actual_size;
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
/* We are about the write the metafile, so we can cancel the pending
request to do it. */
nautilus_directory_remove_write_metafile_idle (directory);
/* Don't write anything if there's nothing to write.
At some point, we might want to change this to actually delete
the metafile in this case.
*/
if (directory->details->metafile_tree == NULL)
return;
xmlDocDumpMemory (directory->details->metafile_tree, &buffer, &buffer_size);
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), GNOME_VFS_ERROR_GENERIC);
g_return_val_if_fail (directory->details != NULL, GNOME_VFS_ERROR_GENERIC);
g_return_val_if_fail (directory->details->metafile_tree != NULL, GNOME_VFS_ERROR_GENERIC);
metafile_handle = NULL;
result = gnome_vfs_create_uri (&metafile_handle,
directory->details->metafile_uri,
GNOME_VFS_OPEN_WRITE,
FALSE,
GNOME_VFS_PERM_USER_ALL | GNOME_VFS_PERM_GROUP_ALL | GNOME_VFS_PERM_OTHER_ALL);
if (result != GNOME_VFS_OK)
g_warning ("nautilus_directory_write_metafile: gnome_vfs_create_uri failed");
METAFILE_PERMISSIONS);
buffer = NULL;
if (result == GNOME_VFS_OK) {
xmlDocDumpMemory (directory->details->metafile_tree, &buffer, &buffer_size);
result = gnome_vfs_write (metafile_handle, buffer, buffer_size, &actual_size);
if (result != GNOME_VFS_OK)
g_warning ("nautilus_directory_write_metafile: gnome_vfs_write failed");
else if (actual_size != buffer_size)
g_warning ("nautilus_directory_read_metafile: unable to write all");
if (buffer_size != actual_size)
result = GNOME_VFS_ERROR_GENERIC;
}
if (metafile_handle != NULL)
gnome_vfs_close (metafile_handle);
xmlFree (buffer);
return result;
}
static void
nautilus_directory_write_metafile (NautilusDirectory *directory)
{
GnomeVFSResult result;
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
/* We are about the write the metafile, so we can cancel the pending
request to do it. */
nautilus_directory_remove_write_metafile_idle (directory);
/* Don't write anything if there's nothing to write.
At some point, we might want to change this to actually delete
the metafile in this case.
*/
if (directory->details->metafile_tree == NULL)
return;
result = nautilus_directory_try_to_write_metafile (directory);
if (result == GNOME_VFS_ERROR_ACCESSDENIED && !directory->details->is_alternate_metafile_uri)
if (nautilus_directory_switch_to_alternate_metafile_uri (directory))
result = nautilus_directory_try_to_write_metafile (directory);
if (result != GNOME_VFS_OK)
g_warning ("nautilus_directory_write_metafile failed to write metafile - we should report this to the user");
}
static gboolean
......@@ -304,6 +337,134 @@ nautilus_directory_request_write_metafile (NautilusDirectory *directory)
gtk_idle_add (nautilus_directory_write_metafile_on_idle,
directory);
}
/* To use a directory name as a file name, we need to escape any slashes.
This means that "/" is replaced by "%2F" and "%" is replaced by "%25".
Later we might share the escaping code with some more generic escaping
function, but this should do for now.
*/
static char *
nautilus_directory_escape_slashes (const char *path)
{
char c;
const char *in;
guint length;
char *result;
char *out;
/* Figure out how long the result needs to be. */
in = path;
length = 0;
while ((c = *in++) != '\0')
switch (c) {
case '/':
case '%':
length += 3;
break;
default:
length += 1;
}
/* Create the result string. */
result = g_malloc (length + 1);
in = path;
out = result;
while ((c = *in++) != '\0')
switch (c) {
case '/':
*out++ = '%';
*out++ = '2';
*out++ = 'F';
break;
case '%':
*out++ = '%';
*out++ = '2';
*out++ = '5';
break;
default:
*out++ = c;
}
g_assert (out == result + length);
*out = '\0';
return result;
}
static GnomeVFSResult
nautilus_make_directory_and_parents (GnomeVFSURI *uri, guint permissions)
{
GnomeVFSResult result;
GnomeVFSURI *parent_uri;
/* Make the directory, and return right away unless there's
a possible problem with the parent.
*/
result = gnome_vfs_make_directory_for_uri (uri, permissions);
if (result != GNOME_VFS_ERROR_NOTFOUND)
return result;
/* If we can't get a parent, we are done. */
parent_uri = gnome_vfs_uri_get_parent (uri);
if (parent_uri == NULL)
return result;
/* If we can get a parent, use a recursive call to create
the parent and its parents.
*/
result = nautilus_make_directory_and_parents (parent_uri, permissions);
gnome_vfs_uri_unref (parent_uri);
if (result != GNOME_VFS_OK)
return result;
/* A second try at making the directory after the parents
have all been created.
*/
result = gnome_vfs_make_directory_for_uri (uri, permissions);
return result;
}
static gboolean
nautilus_directory_switch_to_alternate_metafile_uri (NautilusDirectory *directory)
{
GnomeVFSResult result;
GnomeVFSURI *home_uri, *nautilus_directory_uri, *metafiles_directory_uri, *alternate_uri;
char *uri_as_string, *escaped_uri, *file_name;
g_return_val_if_fail (!directory->details->is_alternate_metafile_uri, FALSE);
/* Ensure that the metafiles directory exists. */
home_uri = gnome_vfs_uri_new (g_get_home_dir ());
nautilus_directory_uri = gnome_vfs_uri_append_path (home_uri, NAUTILUS_DIRECTORY_NAME);
gnome_vfs_uri_unref (home_uri);
metafiles_directory_uri = gnome_vfs_uri_append_path (nautilus_directory_uri, METAFILES_DIRECTORY_NAME);
gnome_vfs_uri_unref (nautilus_directory_uri);
result = nautilus_make_directory_and_parents (metafiles_directory_uri, METAFILES_DIRECTORY_PERMISSIONS);
if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_FILEEXISTS) {
gnome_vfs_uri_unref (metafiles_directory_uri);
return FALSE;
}
/* Construct a file name from the URI. */
uri_as_string = gnome_vfs_uri_to_string (directory->details->uri,
GNOME_VFS_URI_HIDE_NONE);
escaped_uri = nautilus_directory_escape_slashes (uri_as_string);
g_free (uri_as_string);
file_name = g_strconcat (escaped_uri, ".xml", NULL);
g_free (escaped_uri);
/* Construct a URI for something in the "metafiles" directory. */
alternate_uri = gnome_vfs_uri_append_path (metafiles_directory_uri, file_name);
gnome_vfs_uri_unref (metafiles_directory_uri);
g_free (file_name);
/* Switch over to the new URI. */
if (directory->details->metafile_uri != NULL)
gnome_vfs_uri_unref (directory->details->metafile_uri);
directory->details->metafile_uri = alternate_uri;
directory->details->is_alternate_metafile_uri = TRUE;
return TRUE;
}
#if NAUTILUS_DIRECTORY_ASYNC
......@@ -335,7 +496,7 @@ nautilus_directory_new (const char* uri)
directory = gtk_type_new (NAUTILUS_TYPE_DIRECTORY);
directory->details->uri_text = g_strdup (uri);
directory->details->uri_text = g_strdup(uri);
directory->details->uri = vfs_uri;
directory->details->metafile_uri = metafile_uri;
......@@ -377,7 +538,7 @@ nautilus_directory_get_metadata (NautilusDirectory *directory,
result = g_strdup (default_metadata);
else
result = g_strdup (property);
g_free (property);
xmlFree (property);
return result;
}
......@@ -461,6 +622,16 @@ nautilus_self_check_directory (void)
gtk_object_unref (GTK_OBJECT (directory));
g_assert (g_hash_table_size (directory_objects) == 0);
/* nautilus_directory_escape_slashes */
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes (""), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("a"), "a");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("/"), "%2F");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("%"), "%25");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("a/a"), "a%2Fa");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("a%a"), "a%25a");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("%25"), "%2525");
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_escape_slashes ("%2F"), "%252F");
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
......@@ -2,7 +2,7 @@
nautilus-directory.h: Nautilus directory model.
Copyright (C) 1999 Eazel, Inc.
Copyright (C) 1999, 2000 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
......
......@@ -32,6 +32,7 @@ libnautilusinclude_HEADERS= \
gtkscrollframe.h \
nautilus.h \
nautilus-background.h \
nautilus-debug.h \
nautilus-directory.h \
nautilus-file-utilities.h \
nautilus-gtk-extensions.h \
......@@ -51,6 +52,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
gtkscrollframe.c \
nautilus-background.c \
nautilus-background-canvas-group.c \
nautilus-debug.c \
nautilus-directory.c \
nautilus-file-utilities.c \
nautilus-gtk-extensions.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-debug.c: Nautilus debugging aids.
Copyright (C) 2000 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: Darin Adler <darin@eazel.com>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "nautilus-debug.h"
#include <glib.h>
#include <signal.h>
/* Raise a SIGINT signal to get the attention of the debugger.
When not running under the debugger, we don't want to stop,
so we ignore the signal for just the moment that we raise it.
*/
void
nautilus_stop_in_debugger (void)
{
void (* saved_handler) (int);
saved_handler = signal (SIGINT, SIG_IGN);
raise (SIGINT);
signal (SIGINT, saved_handler);
}
/* Stop in the debugger after running the default log handler.
This makes certain kinds of messages stop in the debugger
without making them fatal.
*/
static void
nautilus_stop_after_default_log_handler (const char *domain,
GLogLevelFlags level,
const char *message,
gpointer data)
{
g_log_default_handler (domain, level, message, data);
nautilus_stop_in_debugger ();
}
static void
nautilus_set_stop_after_default_log_handler (const char *domain)
{
g_log_set_handler (domain, G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
nautilus_stop_after_default_log_handler, NULL);
}
void
nautilus_make_warnings_and_criticals_stop_in_debugger (const char *first_domain, ...)
{
va_list domains;
const char *domain;
nautilus_set_stop_after_default_log_handler (first_domain);
va_start (domains, first_domain);
for (;;) {
domain = va_arg (domains, const char *);
if (domain == NULL)
break;
nautilus_set_stop_after_default_log_handler (domain);
}
va_end (domains);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-debug.h: Nautilus debugging aids.
Copyright (C) 2000 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: Darin Adler <darin@eazel.com>
*/