Fixed bugs relating to multiple directory and file objects for the same

* libnautilus/nautilus-directory-private.h,
	libnautilus/nautilus-directory.c, libnautilus/nautilus-file.c
	(nautilus_directory_find_file, compare_file_with_name,
	nautilus_directory_get, nautilus_file_get): Fixed bugs relating to
	multiple directory and file objects for the same entity. Stripped
	trailing '/' characters in nautilus_directory_get and changed
	nautilus_file_get to return already-existing files instead of
	always creating new ones. Added self-checks to make sure this
	works.

	* libnautilus/nautilus-directory.c
	(nautilus_directory_try_to_read_metafile): Fixed bug where
	metafile reading would fail. The gnome-xml parser requires a null
	character at the end of the file, even though the size is passed
	in!

	* libnautilus/nautilus-directory.c
	(nautilus_directory_remove_write_metafile_idle,
	nautilus_directory_finalize,
	nautilus_directory_try_to_write_metafile,
	nautilus_directory_request_write_metafile, ): Changed metafile
	writing so it always happens at idle time.

	* libnautilus/nautilus-directory.c
	(nautilus_directory_try_to_read_metafile): Fixed bug where
	metafile reading would fail. The gnome-xml parser requires a null
	character at the end of the file, even though the size is passed
	in!

	* libnautilus/nautilus-lib-self-check-functions.h: Changed order
	so lower-level tests come before higher-level ones.

	* libnautilus/nautilus-string.h, libnautilus/nautilus-string.c:
	Renamed functions:
		nautilus_has_prefix -> nautilus_str_has_prefix
		nautilus_strdup_prefix -> nautilus_str_get_prefix
		nautilus_has_suffix -> nautilus_str_has_suffix
		nautilus_strstrip -> nautilus_str_strip_chr
		nautilus_string_to_int -> nautilus_str_to_int
		nautilus_eat_string_to_int -> nautilus_eat_str_to_int
	Changed nautilus_str_strip_chr not to modify in place.
	Added nautilus_str_strip_trailing_chr.

	* components/music/nautilus-music-view.c (is_mp3_file,
	nautilus_music_view_update_from_uri),
	libnautilus/nautilus-icon-factory.c
	(nautilus_icon_factory_get_icon_for_file, make_thumbnail_path,
	load_specific_image), libnautilus/nautilus-icons-view-icon-item.c
	(draw_mini_text), src/ntl-index-panel.c (command_button_cb,
	add_command_buttons), src/ntl-window-msgs.c
	(nautilus_window_change_location_2),
	src/file-manager-fm-directory-view-icons.c
	(fm_directory_view_icons_compute_menu_item_info),
	src/file-manager/fm-directory-view.c (compute_menu_item_info),
	src/file-manager/fm-icons-controller.c
	(fm_icons_controller_get_icon_property): Switched callers to use
	new names for string calls.

	* libnautilus/gnome-icon-container.c (destroy): Reformatting.

	* components/help/converters/gnome-info2html2/main.c (main):
	Fixed a warning.
This commit is contained in:
Darin Adler 2000-03-09 20:34:50 +00:00
parent cb99884c95
commit 8656eb9d85
39 changed files with 1353 additions and 893 deletions

View file

@ -1,3 +1,65 @@
2000-03-09 Darin Adler <darin@eazel.com>
* libnautilus/nautilus-directory-private.h,
libnautilus/nautilus-directory.c, libnautilus/nautilus-file.c
(nautilus_directory_find_file, compare_file_with_name,
nautilus_directory_get, nautilus_file_get): Fixed bugs relating to
multiple directory and file objects for the same entity. Stripped
trailing '/' characters in nautilus_directory_get and changed
nautilus_file_get to return already-existing files instead of
always creating new ones. Added self-checks to make sure this
works.
* libnautilus/nautilus-directory.c
(nautilus_directory_try_to_read_metafile): Fixed bug where
metafile reading would fail. The gnome-xml parser requires a null
character at the end of the file, even though the size is passed
in!
* libnautilus/nautilus-directory.c
(nautilus_directory_remove_write_metafile_idle,
nautilus_directory_finalize,
nautilus_directory_try_to_write_metafile,
nautilus_directory_request_write_metafile, ): Changed metafile
writing so it always happens at idle time.
* libnautilus/nautilus-directory.c
(nautilus_directory_try_to_read_metafile): Fixed bug where
metafile reading would fail. The gnome-xml parser requires a null
character at the end of the file, even though the size is passed
in!
* libnautilus/nautilus-lib-self-check-functions.h: Changed order
so lower-level tests come before higher-level ones.
* libnautilus/nautilus-string.h, libnautilus/nautilus-string.c:
Renamed functions:
nautilus_has_prefix -> nautilus_str_has_prefix
nautilus_strdup_prefix -> nautilus_str_get_prefix
nautilus_has_suffix -> nautilus_str_has_suffix
nautilus_strstrip -> nautilus_str_strip_chr
nautilus_string_to_int -> nautilus_str_to_int
nautilus_eat_string_to_int -> nautilus_eat_str_to_int
Changed nautilus_str_strip_chr not to modify in place.
Added nautilus_str_strip_trailing_chr.
* components/music/nautilus-music-view.c (is_mp3_file,
nautilus_music_view_update_from_uri),
libnautilus/nautilus-icon-factory.c
(nautilus_icon_factory_get_icon_for_file, make_thumbnail_path,
load_specific_image), libnautilus/nautilus-icons-view-icon-item.c
(draw_mini_text), src/ntl-index-panel.c (command_button_cb,
add_command_buttons), src/ntl-window-msgs.c
(nautilus_window_change_location_2),
src/file-manager-fm-directory-view-icons.c
(fm_directory_view_icons_compute_menu_item_info),
src/file-manager/fm-directory-view.c (compute_menu_item_info),
src/file-manager/fm-icons-controller.c
(fm_icons_controller_get_icon_property): Switched callers to use
new names for string calls.
* libnautilus/gnome-icon-container.c (destroy): Reformatting.
2000-03-09 John Sullivan <sullivan@eazel.com>
* libnautilus/gnome-icon-container.c: (update_icon):
@ -25,6 +87,7 @@
causing havoc later, by setting list to result of g_list_remove.
2000-03-09 Elliot Lee <sopwith@redhat.com>
* libnautilus/Makefile.am: Install libnautilus.h
* src/ntl-uri-map.c: Handle mapping of special schemes
(i.e. unknown to gnome-vfs). Currently just 'irc'.

View file

@ -1,3 +1,7 @@
2000-03-09 Darin Adler <darin@eazel.com>
* gnome-info2html2/main.c (main): Fixed a warning.
2000-02-11 Jonathan Blandford <jrb@redhat.com>
* gnome-db2html2/toc-elements.c: removed TIP, NOTE, WARNING, and

View file

@ -55,7 +55,7 @@ main(int argc, char **argv)
if (!be_quiet)
printf("info2html Version %s\n",INFO2HTML_VERSION);
ctx = poptGetContext("gnome-info2html2", argc, (const char **)argv, options, 0);
ctx = poptGetContext("gnome-info2html2", argc, argv, options, 0);
while(poptGetNextOpt(ctx) >= 0)
/**/ ;

View file

@ -24,12 +24,12 @@
/* music view - presents the contents of the directory as an album of music */
#include <config.h>
#include "nautilus-music-view.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include "nautilus-music-view.h"
#include <libnautilus/libnautilus.h>
#include <libnautilus/nautilus-background.h>
@ -47,7 +47,7 @@
#include <limits.h>
struct _NautilusMusicViewDetails {
gchar *current_uri;
char *current_uri;
NautilusContentViewFrame *view_frame;
GtkVBox *album_container;
@ -59,14 +59,14 @@ struct _NautilusMusicViewDetails {
/* structure for holding song info */
typedef struct {
gint track_number;
gchar *title;
gchar *artist;
gchar *album;
gchar *year;
gchar *comment;
gchar *path_name;
typedef struct {
int track_number;
char *title;
char *artist;
char *album;
char *year;
char *comment;
char *path_name;
} SongInfo;
#define MUSIC_VIEW_DEFAULT_BACKGROUND_COLOR "rgb:BBBB/BBBB/FFFF"
@ -74,7 +74,7 @@ typedef struct {
enum {
TARGET_URI_LIST,
TARGET_COLOR,
TARGET_GNOME_URI_LIST
TARGET_GNOME_URI_LIST
};
static GtkTargetEntry music_dnd_target_table[] = {
@ -85,7 +85,7 @@ static GtkTargetEntry music_dnd_target_table[] = {
static void nautilus_music_view_background_changed (NautilusMusicView *music_view);
static void nautilus_music_view_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data,
guint info, guint time);
@ -101,7 +101,7 @@ static void
music_view_notify_location_change_cb(NautilusContentViewFrame *view,
Nautilus_NavigationInfo *navinfo,
NautilusMusicView *music_view);
static void selection_callback(GtkCList * clist, gint row, gint column, GdkEventButton * event);
static void selection_callback(GtkCList * clist, int row, int column, GdkEventButton * event);
static void
nautilus_music_view_initialize_class (NautilusMusicViewClass *klass)
@ -123,9 +123,9 @@ static void
nautilus_music_view_initialize (NautilusMusicView *music_view)
{
NautilusBackground *background;
gchar *file_name;
char *file_name;
GtkWidget *song_box, *scrollwindow;
gchar *titles[] = {"Track", "Title", "Artist", "Time"};
char *titles[] = {"Track", "Title", "Artist", "Time"};
music_view->details = g_new0 (NautilusMusicViewDetails, 1);
@ -211,10 +211,10 @@ nautilus_music_view_destroy (GtkObject *object)
/* handle a row being selected in the list view by playing the corresponding song */
/* FIXME: xmms shouldn't be hardwired */
static void
selection_callback(GtkCList * clist, gint row, gint column, GdkEventButton * event)
selection_callback(GtkCList * clist, int row, int column, GdkEventButton * event)
{
pid_t play_pid;
gchar* song_name = gtk_clist_get_row_data(clist, row);
char* song_name = gtk_clist_get_row_data(clist, row);
if (!song_name)
return;
@ -298,18 +298,19 @@ release_song_info(SongInfo *info)
/* determine if the passed in filename is an mp3 file by looking at the extension */
static gboolean
is_mp3_file(gchar *song_path)
is_mp3_file(char *song_path)
{
return nautilus_has_suffix(song_path, ".mp3") || nautilus_has_suffix(song_path, ".MP3");
return nautilus_str_has_suffix(song_path, ".mp3")
|| nautilus_str_has_suffix(song_path, ".MP3");
}
/* read the id3 tag of the file if present */
/* FIXME: need to use gnome vfs for this */
static gboolean
read_id_tag(gchar* song_path, SongInfo* song_info)
read_id_tag(char* song_path, SongInfo* song_info)
{
gint mp3_file;
int mp3_file;
char tag_buffer[129];
char temp_str[255];
@ -355,7 +356,7 @@ read_id_tag(gchar* song_path, SongInfo* song_info)
/* allocate a return a song info record, from an mp3 tag if present, or from intrinsic info */
static SongInfo*
fetch_song_info(gchar *song_path, gint file_order)
fetch_song_info(char *song_path, int file_order)
{
gboolean has_info = FALSE;
SongInfo *info;
@ -381,15 +382,15 @@ fetch_song_info(gchar *song_path, gint file_order)
/* format_play_time takes the pathname to a file and returns the play time formated as mm:ss */
/* FIXME: assumes 128k bits/second. Must read header and factor in bitrate */
static gchar*
format_play_time(gchar* song_path_name)
static char*
format_play_time(char* song_path_name)
{
NautilusFile *file = nautilus_file_get(song_path_name);
GnomeVFSFileSize file_size = nautilus_file_get_size(file);
gint seconds = (file_size - 512) / 16384;
gint minutes = seconds / 60;
gint remain_seconds = seconds - (60 * minutes);
gchar *result = g_strdup_printf("%d:%02d", minutes, remain_seconds);
int seconds = (file_size - 512) / 16384;
int minutes = seconds / 60;
int remain_seconds = seconds - (60 * minutes);
char *result = g_strdup_printf("%d:%02d", minutes, remain_seconds);
nautilus_file_unref(file);
return result;
@ -412,11 +413,11 @@ sort_by_track_number (gconstpointer ap, gconstpointer bp)
album or artist. Return NULL if no names or too heterogenous. This first cut just captures
the first one it can - soon, we'll use a hash table and count them up */
static gchar*
static char*
determine_attribute(GList *song_list, gboolean is_artist)
{
SongInfo *info;
gchar *attribute_value = NULL;
char *attribute_value = NULL;
GList *next_item = song_list;
while ((next_item != NULL) && (attribute_value == NULL)) {
info = (SongInfo*) next_item->data;
@ -433,7 +434,7 @@ determine_attribute(GList *song_list, gboolean is_artist)
/* FIXME: need to use gnome-vfs for iterating the directory */
static void
nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const gchar *uri)
nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const char *uri)
{
DIR *dir;
struct dirent *entry;
@ -444,10 +445,10 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const gchar
GList *this_song;
GList *song_list = NULL ;
SongInfo *info;
gchar *path_name;
gchar *image_path_name = NULL;
gint file_index = 1;
gint track_index = 0;
char *path_name;
char *image_path_name = NULL;
int file_index = 1;
int track_index = 0;
/* iterate through the directory, collecting mp3 files and extracting id3 data if present */
/* soon we'll use gnomevfs, but at first just the standard unix stuff */
@ -477,9 +478,9 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const gchar
else {
/* it's not an mp3 file, so see if it's an image */
NautilusFile *file = nautilus_file_get(path_name);
const gchar *mime_type = nautilus_file_get_mime_type (file);
const char *mime_type = nautilus_file_get_mime_type (file);
if (nautilus_has_prefix(mime_type, "image/")) {
if (nautilus_str_has_prefix(mime_type, "image/")) {
/* for now, just keep the first image */
if (image_path_name == NULL)
image_path_name = strdup(path_name);
@ -560,8 +561,8 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const gchar
/* determine the album title/artist line */
if (music_view->details->album_title) {
gchar *artist_name, *temp_str;
gchar* album_name = determine_attribute(song_list, FALSE);
char *artist_name, *temp_str;
char* album_name = determine_attribute(song_list, FALSE);
if (album_name == NULL)
album_name = g_basename(uri);
@ -589,7 +590,7 @@ nautilus_music_view_update_from_uri (NautilusMusicView *music_view, const gchar
void
nautilus_music_view_load_uri (NautilusMusicView *music_view, const gchar *uri)
nautilus_music_view_load_uri (NautilusMusicView *music_view, const char *uri)
{
if (music_view->details->current_uri != NULL)
g_free(music_view->details->current_uri);
@ -644,7 +645,7 @@ nautilus_music_view_background_changed (NautilusMusicView *music_view)
static void
nautilus_music_view_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data, guint info, guint time)
{
g_return_if_fail (NAUTILUS_IS_MUSIC_VIEW (widget));

View file

@ -1698,7 +1698,7 @@ static void
destroy (GtkObject *object)
{
GnomeIconContainer *container;
int index;
int i;
container = GNOME_ICON_CONTAINER (object);
@ -1709,18 +1709,24 @@ destroy (GtkObject *object)
g_hash_table_destroy (container->details->canvas_item_to_icon);
unschedule_kbd_icon_visibility (container);
if (container->details->rubberband_info.timer_id != 0)
if (container->details->rubberband_info.timer_id != 0) {
gtk_timeout_remove (container->details->rubberband_info.timer_id);
if (container->details->rubberband_info.selection_rectangle != NULL)
}
if (container->details->rubberband_info.selection_rectangle != NULL) {
gtk_object_destroy (GTK_OBJECT (container->details->rubberband_info.selection_rectangle));
}
if (container->details->idle_id != 0)
if (container->details->idle_id != 0) {
gtk_idle_remove (container->details->idle_id);
if (container->details->linger_selection_mode_timer_id != 0)
}
if (container->details->linger_selection_mode_timer_id != 0) {
gtk_timeout_remove (container->details->linger_selection_mode_timer_id);
for (index = 0; index < NAUTILUS_N_ELEMENTS (container->details->label_font); index++)
if (container->details->label_font[index] != NULL)
gdk_font_unref(container->details->label_font[index]);
}
for (i = 0; i < NAUTILUS_N_ELEMENTS (container->details->label_font); i++) {
if (container->details->label_font[i] != NULL) {
gdk_font_unref(container->details->label_font[i]);
}
}
g_free (container->details);
@ -2441,8 +2447,9 @@ gnome_icon_container_clear (GnomeIconContainer *container)
set_kbd_current (container, NULL, FALSE);
details->stretch_icon = NULL;
for (p = details->icons; p != NULL; p = p->next)
for (p = details->icons; p != NULL; p = p->next) {
icon_free (p->data);
}
g_list_free (details->icons);
details->icons = NULL;
details->num_icons = 0;

View file

@ -55,6 +55,8 @@ struct NautilusDirectoryDetails
GList *files;
};
NautilusFile *nautilus_directory_find_file (NautilusDirectory *directory,
const char *file_name);
NautilusFile *nautilus_directory_new_file (NautilusDirectory *directory,
GnomeVFSFileInfo *info);
char * nautilus_directory_get_file_metadata (NautilusDirectory *directory,

View file

@ -71,7 +71,6 @@ static void nautilus_directory_finalize (GtkObje
static NautilusDirectory *nautilus_directory_new (const char *uri);
static void nautilus_directory_read_metafile (NautilusDirectory *directory);
static void nautilus_directory_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory);
static void nautilus_directory_load_cb (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
GnomeVFSDirectoryList *list,
@ -133,9 +132,7 @@ nautilus_directory_finalize (GtkObject *object)
directory = NAUTILUS_DIRECTORY (object);
if (directory->details->write_metafile_idle_id != 0) {
nautilus_directory_write_metafile (directory);
}
g_assert (directory->details->write_metafile_idle_id == 0);
g_hash_table_remove (directory_objects, directory->details->uri_text);
@ -172,13 +169,15 @@ nautilus_directory_finalize (GtkObject *object)
NautilusDirectory *
nautilus_directory_get (const char *uri)
{
char *canonical_uri;
NautilusDirectory *directory;
g_return_val_if_fail (uri != NULL, NULL);
/* FIXME: This currently ignores the issue of two uris that are not identical but point
to the same data.
to the same data except for the specific case of trailing '/' characters.
*/
canonical_uri = nautilus_str_strip_trailing_chr (uri, '/');
/* Create the hash table first time through. */
if (directory_objects == NULL) {
@ -186,25 +185,30 @@ nautilus_directory_get (const char *uri)
}
/* If the object is already in the hash table, look it up. */
directory = g_hash_table_lookup (directory_objects, uri);
directory = g_hash_table_lookup (directory_objects,
canonical_uri);
if (directory != NULL) {
g_assert (NAUTILUS_IS_DIRECTORY (directory));
gtk_object_ref (GTK_OBJECT (directory));
} else {
/* Create a new directory object instead. */
directory = nautilus_directory_new (uri);
directory = nautilus_directory_new (canonical_uri);
if (directory == NULL) {
return NULL;
}
g_assert (strcmp (directory->details->uri_text, uri) == 0);
g_assert (strcmp (directory->details->uri_text, canonical_uri) == 0);
/* Put it in the hash table. */
gtk_object_ref (GTK_OBJECT (directory));
gtk_object_sink (GTK_OBJECT (directory));
g_hash_table_insert (directory_objects, directory->details->uri_text, directory);
g_hash_table_insert (directory_objects,
directory->details->uri_text,
directory);
}
g_free (canonical_uri);
return directory;
}
@ -252,13 +256,6 @@ nautilus_directory_try_to_read_metafile (NautilusDirectory *directory, GnomeVFSU
if (size != metafile_info.size) {
result = GNOME_VFS_ERROR_TOOBIG;
}
/* Avoid allocating a NULL buffer later and passing it
around; we still want to try to parse an empty file
so we get a metafile tree and a valid result. */
if (size == 0) {
size = 1;
}
}
metafile_handle = NULL;
@ -269,8 +266,14 @@ nautilus_directory_try_to_read_metafile (NautilusDirectory *directory, GnomeVFSU
}
if (result == GNOME_VFS_OK) {
buffer = g_malloc (size);
/* The gnome-xml parser requires a zero-terminated array.
* Also, we don't want to allocate an empty buffer
* because it would be NULL and gnome-xml won't parse
* NULL properly.
*/
buffer = g_malloc (size + 1);
result = gnome_vfs_read (metafile_handle, buffer, size, &actual_size);
buffer[actual_size] = '\0';
directory->details->metafile_tree = xmlParseMemory (buffer, actual_size);
g_free (buffer);
}
@ -290,22 +293,16 @@ nautilus_directory_read_metafile (NautilusDirectory *directory)
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
/* Check for the alternate metafile first.
If we read from it, then write to it later. */
* If we read from it, then write to it later.
*/
directory->details->use_alternate_metafile = FALSE;
result = nautilus_directory_try_to_read_metafile (directory, directory->details->alternate_metafile_uri);
result = nautilus_directory_try_to_read_metafile (directory,
directory->details->alternate_metafile_uri);
if (result == GNOME_VFS_OK) {
directory->details->use_alternate_metafile = TRUE;
} else {
result = nautilus_directory_try_to_read_metafile (directory, directory->details->metafile_uri);
}
}
static void
nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory)
{
if (directory->details->write_metafile_idle_id != 0) {
gtk_idle_remove (directory->details->write_metafile_idle_id);
directory->details->write_metafile_idle_id = 0;
result = nautilus_directory_try_to_read_metafile (directory,
directory->details->metafile_uri);
}
}
@ -355,35 +352,45 @@ nautilus_directory_write_metafile (NautilusDirectory *directory)
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
gtk_object_ref (GTK_OBJECT (directory));
/* We are about the write the metafile, so we can cancel the pending
request to do so.
*/
nautilus_directory_remove_write_metafile_idle (directory);
if (directory->details->write_metafile_idle_id != 0) {
gtk_idle_remove (directory->details->write_metafile_idle_id);
directory->details->write_metafile_idle_id = 0;
gtk_object_unref (GTK_OBJECT (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;
if (directory->details->metafile_tree != NULL) {
/* Try the main URI, unless we have already been instructed to use the alternate URI. */
if (directory->details->use_alternate_metafile) {
result = GNOME_VFS_ERROR_ACCESSDENIED;
} else {
result = nautilus_directory_try_to_write_metafile (directory,
directory->details->metafile_uri);
}
/* Try the alternate URI if the main one failed. */
if (result != GNOME_VFS_OK) {
result = nautilus_directory_try_to_write_metafile (directory,
directory->details->alternate_metafile_uri);
}
/* Check for errors. FIXME: Later this must be reported to the user, not spit out as a warning. */
if (result != GNOME_VFS_OK) {
g_warning ("nautilus_directory_write_metafile failed to write metafile - we should report this to the user");
}
}
/* Try the main URI, unless we have already been instructed to use the alternate URI. */
if (directory->details->use_alternate_metafile) {
result = GNOME_VFS_ERROR_ACCESSDENIED;
} else {
result = nautilus_directory_try_to_write_metafile (directory, directory->details->metafile_uri);
}
/* Try the alternate URI if the main one failed. */
if (result != GNOME_VFS_OK) {
result = nautilus_directory_try_to_write_metafile (directory, directory->details->alternate_metafile_uri);
}
/* Check for errors. FIXME: Later this must be reported to the user, not spit out as a warning. */
if (result != GNOME_VFS_OK) {
g_warning ("nautilus_directory_write_metafile failed to write metafile - we should report this to the user");
}
gtk_object_unref (GTK_OBJECT (directory));
}
static gboolean
@ -396,6 +403,8 @@ nautilus_directory_write_metafile_idle_cb (gpointer callback_data)
directory->details->write_metafile_idle_id = 0;
nautilus_directory_write_metafile (directory);
gtk_object_unref (GTK_OBJECT (directory));
return FALSE;
}
@ -404,6 +413,7 @@ nautilus_directory_request_write_metafile (NautilusDirectory *directory)
{
/* Set up an idle task that will write the metafile. */
if (directory->details->write_metafile_idle_id == 0) {
gtk_object_ref (GTK_OBJECT (directory));
directory->details->write_metafile_idle_id =
gtk_idle_add (nautilus_directory_write_metafile_idle_cb,
directory);
@ -1056,6 +1066,27 @@ nautilus_directory_set_file_metadata (NautilusDirectory *directory,
nautilus_directory_request_write_metafile (directory);
}
static int
compare_file_with_name (gconstpointer a, gconstpointer b)
{
return strcmp (((const NautilusFile *) a)->info->name, b);
}
NautilusFile *
nautilus_directory_find_file (NautilusDirectory *directory, const char *name)
{
GList *list_entry;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
g_return_val_if_fail (name != NULL, NULL);
list_entry = g_list_find_custom (directory->details->files,
(gpointer) name,
compare_file_with_name);
return list_entry == NULL ? NULL : list_entry->data;
}
NautilusFile *
nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *info)
{
@ -1138,28 +1169,40 @@ nautilus_self_check_directory (void)
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (NULL, "TEST_INTEGER", 42), 42);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "NONEXISTENT_KEY", 42), 42);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc/") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc////") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
gtk_object_unref (GTK_OBJECT (directory));
/* let the idle function run */
while (gtk_events_pending ()) {
gtk_main_iteration ();
}
NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directory_objects), 0);
directory = nautilus_directory_get ("file:///etc");
NAUTILUS_CHECK_BOOLEAN_RESULT (directory->details->metafile_tree != NULL, TRUE);
NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directory_objects), 1);
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
/* 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");
file_1 = nautilus_file_get ("file:///home/");
NAUTILUS_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "home");
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get ("file:///home/") == file_1, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get ("file:///home") == file_1, TRUE);
nautilus_file_unref (file_1);
nautilus_file_unref (file_1);
file_1 = nautilus_file_get ("file:///home");
@ -1179,6 +1222,16 @@ nautilus_self_check_directory (void)
nautilus_file_unref (file_1);
nautilus_file_unref (file_2);
/* 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 */

View file

@ -83,19 +83,22 @@ nautilus_file_get (const char *uri)
GNOME_VFS_FILE_INFO_GETMIMETYPE
| GNOME_VFS_FILE_INFO_FASTMIMETYPE
| GNOME_VFS_FILE_INFO_FOLLOWLINKS, NULL);
if (result != GNOME_VFS_OK)
if (result != GNOME_VFS_OK) {
return NULL;
}
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL)
if (vfs_uri == NULL) {
return NULL;
}
/* Make VFS version of directory URI. */
directory_vfs_uri = gnome_vfs_uri_get_parent (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
if (directory_vfs_uri == NULL)
if (directory_vfs_uri == NULL) {
return NULL;
}
/* Make text version of directory URI. */
directory_uri = gnome_vfs_uri_to_string (directory_vfs_uri,
@ -105,10 +108,16 @@ nautilus_file_get (const char *uri)
/* Get object that represents the directory. */
directory = nautilus_directory_get (directory_uri);
g_free (directory_uri);
if (directory == NULL)
if (directory == NULL) {
return NULL;
}
file = nautilus_directory_new_file (directory, file_info);
file = nautilus_directory_find_file (directory, file_info->name);
if (file == NULL) {
file = nautilus_directory_new_file (directory, file_info);
directory->details->files =
g_list_append (directory->details->files, file);
}
gnome_vfs_file_info_unref (file_info);
nautilus_file_ref (file);
@ -176,14 +185,17 @@ nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFi
is_directory_1 = nautilus_file_is_directory (file_1);
is_directory_2 = nautilus_file_is_directory (file_2);
if (is_directory_1 && !is_directory_2)
if (is_directory_1 && !is_directory_2) {
return -1;
}
if (is_directory_2 && !is_directory_1)
if (is_directory_2 && !is_directory_1) {
return +1;
}
if (!is_directory_1 && !is_directory_2)
if (!is_directory_1 && !is_directory_2) {
return 0;
}
/* Both are directories, compare by item count. */
/* FIXME: get_directory_item_count_hack is slow, and calling
@ -195,11 +207,13 @@ nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFi
item_count_1 = get_directory_item_count_hack (file_1, FALSE);
item_count_2 = get_directory_item_count_hack (file_2, FALSE);
if (item_count_1 < item_count_2)
if (item_count_1 < item_count_2) {
return -1;
}
if (item_count_2 < item_count_1)
if (item_count_2 < item_count_1) {
return +1;
}
return 0;
}
@ -221,17 +235,21 @@ nautilus_file_compare_by_type (NautilusFile *file_1, NautilusFile *file_2)
is_directory_1 = nautilus_file_is_directory (file_1);
is_directory_2 = nautilus_file_is_directory (file_2);
if (is_directory_1 && is_directory_2)
if (is_directory_1 && is_directory_2) {
return 0;
}
if (is_directory_1)
if (is_directory_1) {
return -1;
}
if (is_directory_2)
if (is_directory_2) {
return +1;
}
if (nautilus_strcmp (file_1->info->mime_type, file_2->info->mime_type) == 0)
if (nautilus_strcmp (file_1->info->mime_type, file_2->info->mime_type) == 0) {
return 0;
}
type_string_1 = nautilus_file_get_type_as_string (file_1);
type_string_2 = nautilus_file_get_type_as_string (file_2);
@ -300,14 +318,15 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
return 0;
}
if (reversed)
if (reversed) {
return gnome_vfs_file_info_compare_for_sort_reversed (file_1->info,
file_2->info,
rules);
else
} else {
return gnome_vfs_file_info_compare_for_sort (file_1->info,
file_2->info,
rules);
}
}
/**
@ -460,23 +479,16 @@ nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type
* internationalization's sake.
*/
if (file_date_age == 0)
{
if (file_date_age == 0) {
/* today, use special word */
format = _("today %-I:%M %p");
}
else if (file_date_age == 1)
{
} else if (file_date_age == 1) {
/* yesterday, use special word */
format = _("yesterday %-I:%M %p");
}
else if (file_date_age < 7)
{
} else if (file_date_age < 7) {
/* current week, include day of week */
format = _("%A %-m/%-d/%y %-I:%M %p");
}
else
{
} else {
format = _("%-m/%-d/%y %-I:%M %p");
}
@ -578,8 +590,7 @@ nautilus_file_get_owner_as_string (NautilusFile *file)
g_print ("pointer to password info is %p\n", password_info);
if (password_info == NULL)
{
if (password_info == NULL) {
return g_strdup (_("unknown owner"));
}
@ -607,8 +618,7 @@ nautilus_file_get_group_as_string (NautilusFile *file)
/* No need to free result of getgrgid */
group_info = getgrgid (file->info->gid);
if (group_info == NULL)
{
if (group_info == NULL) {
return g_strdup (_("unknown group"));
}
@ -633,24 +643,28 @@ get_directory_item_count_hack (NautilusFile *file, gboolean ignore_invisible_ite
g_assert (nautilus_file_is_directory (file));
uri = nautilus_file_get_uri (file);
if (nautilus_has_prefix (uri, "file://"))
if (nautilus_str_has_prefix (uri, "file://")) {
path = uri + 7;
else
} else {
path = uri;
}
directory = opendir (path);
g_free (uri);
if (!directory)
if (!directory) {
return 0;
}
count = 0;
while ((entry = readdir(directory)) != NULL)
while ((entry = readdir(directory)) != NULL) {
// Only count invisible items if requested.
if (!ignore_invisible_items || entry->d_name[0] != '.')
if (!ignore_invisible_items || entry->d_name[0] != '.') {
count += 1;
}
}
closedir(directory);
@ -678,8 +692,7 @@ nautilus_file_get_size_as_string (NautilusFile *file)
{
g_return_val_if_fail (file != NULL, NULL);
if (nautilus_file_is_directory (file))
{
if (nautilus_file_is_directory (file)) {
/* FIXME: Since computing the item count is slow, we
* want to do it in a deferred way. However, that
* architecture doesn't exist yet, so we're hacking

View file

@ -610,7 +610,7 @@ nautilus_icon_factory_get_icon_for_file (NautilusFile *file)
or use a thumbnail if one exists. If a thumbnail is required, but does not yet exist,
put an entry on the thumbnail queue so we eventually make one */
if (uri == NULL && nautilus_has_prefix (nautilus_file_get_mime_type (file), "image/")) {
if (uri == NULL && nautilus_str_has_prefix (nautilus_file_get_mime_type (file), "image/")) {
if (nautilus_file_get_size (file) < SELF_THUMBNAIL_SIZE_THRESHOLD)
uri = nautilus_file_get_uri (file);
else
@ -686,7 +686,8 @@ make_thumbnail_path (const char *image_uri, gboolean directory_only)
if (directory_only)
thumbnail_uri = g_strdup_printf ("%s/.thumbnails", temp_str);
else {
if (nautilus_has_suffix (image_uri, ".png") || nautilus_has_suffix (image_uri, ".PNG")) {
if (nautilus_str_has_suffix (image_uri, ".png")
|| nautilus_str_has_suffix (image_uri, ".PNG")) {
thumbnail_uri = g_strdup_printf ("%s/.thumbnails/%s", temp_str, last_slash + 1);
} else {
thumbnail_uri = g_strdup_printf ("%s/.thumbnails/%s.png", temp_str, last_slash + 1);
@ -869,7 +870,7 @@ load_specific_image (NautilusScalableIcon *scalable_icon,
* and gdk-pixbuf.
*/
if (size_in_pixels == NAUTILUS_ICON_SIZE_STANDARD
&& nautilus_has_prefix (scalable_icon->uri, "file://")) {
&& nautilus_str_has_prefix (scalable_icon->uri, "file://")) {
return gdk_pixbuf_new_from_file (scalable_icon->uri + 7);
}

View file

@ -601,7 +601,7 @@ draw_mini_text (GnomeCanvasItem* item, GdkDrawable *drawable,
/* FIXME: need to use gnome_vfs to read the file */
file_name = details->text_source;
if (nautilus_has_prefix (details->text_source, "file://")) {
if (nautilus_str_has_prefix (details->text_source, "file://")) {
file_name += 7;
}
text_file = fopen(file_name, "r");

View file

@ -39,13 +39,13 @@ void nautilus_run_lib_self_checks (void);
*/
#define NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
macro (nautilus_self_check_string) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gdk_extensions) \
macro (nautilus_self_check_background) \
macro (nautilus_self_check_directory) \
macro (nautilus_self_check_gdk_extensions) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gnome_icon_container) \
macro (nautilus_self_check_icon_factory) \
macro (nautilus_self_check_string) \
/* Add new self-check functions to the list above this line. */
/* Generate prototypes for all the functions. */

View file

@ -32,22 +32,22 @@
#include "nautilus-lib-self-check-functions.h"
size_t
nautilus_strlen (const char *string_null_allowed)
nautilus_strlen (const char *string)
{
return string_null_allowed == NULL ? 0 : strlen (string_null_allowed);
return string == NULL ? 0 : strlen (string);
}
char *
nautilus_strchr (const char *haystack_null_allowed, char needle)
nautilus_strchr (const char *haystack, char needle)
{
return haystack_null_allowed == NULL ? NULL : strchr (haystack_null_allowed, needle);
return haystack == NULL ? NULL : strchr (haystack, needle);
}
int
nautilus_strcmp (const char *string_a_null_allowed, const char *string_b_null_allowed)
nautilus_strcmp (const char *string_a, const char *string_b)
{
return strcmp (string_a_null_allowed == NULL ? "" : string_a_null_allowed,
string_b_null_allowed == NULL ? "" : string_b_null_allowed);
return strcmp (string_a == NULL ? "" : string_a,
string_b == NULL ? "" : string_b);
}
int
@ -61,13 +61,13 @@ nautilus_eat_strcmp (char *string_a, const char *string_b)
}
gboolean
nautilus_has_prefix (const char *haystack_null_allowed, const char *needle_null_allowed)
nautilus_str_has_prefix (const char *haystack, const char *needle)
{
const char *h, *n;
/* Eat one character at a time. */
h = haystack_null_allowed == NULL ? "" : haystack_null_allowed;
n = needle_null_allowed == NULL ? "" : needle_null_allowed;
h = haystack == NULL ? "" : haystack;
n = needle == NULL ? "" : needle;
do {
if (*n == '\0') {
return TRUE;
@ -80,25 +80,25 @@ nautilus_has_prefix (const char *haystack_null_allowed, const char *needle_null_
}
gboolean
nautilus_has_suffix (const char *haystack_null_allowed, const char *needle_null_allowed)
nautilus_str_has_suffix (const char *haystack, const char *needle)
{
const char *h, *n;
if (needle_null_allowed == NULL) {
if (needle == NULL) {
return TRUE;
}
if (haystack_null_allowed == NULL) {
return needle_null_allowed[0] == '\0';
if (haystack == NULL) {
return needle[0] == '\0';
}
/* Eat one character at a time. */
h = haystack_null_allowed + strlen(haystack_null_allowed);
n = needle_null_allowed + strlen(needle_null_allowed);
h = haystack + strlen(haystack);
n = needle + strlen(needle);
do {
if (n == needle_null_allowed) {
if (n == needle) {
return TRUE;
}
if (h == haystack_null_allowed) {
if (h == haystack) {
return FALSE;
}
} while (*--h == *--n);
@ -107,44 +107,44 @@ nautilus_has_suffix (const char *haystack_null_allowed, const char *needle_null_
/**
* nautilus_strdup_prefix:
* nautilus_str_get_prefix:
* Get a new string containing the first part of an existing string.
*
* @source_null_allowed: The string whose prefix should be extracted.
* @delimiter_null_allowed: The string that marks the end of the prefix.
* @source: The string whose prefix should be extracted.
* @delimiter: The string that marks the end of the prefix.
*
* Return value: A newly-allocated string that that matches the first part
* of @source_null_allowed, up to but not including the first occurrence of
* @delimiter_null_allowed. If @source_null_allowed is NULL, returns NULL. If
* @delimiter_null_allowed is NULL, returns a copy of @source_null_allowed.
* If @delimiter_null_allowed does not occur in @source_null_allowed, returns
* a copy of @source_null_allowed.
* of @source, up to but not including the first occurrence of
* @delimiter. If @source is NULL, returns NULL. If
* @delimiter is NULL, returns a copy of @source.
* If @delimiter does not occur in @source, returns
* a copy of @source.
**/
char *
nautilus_strdup_prefix (const char *source_null_allowed,
const char *delimiter_null_allowed)
nautilus_str_get_prefix (const char *source,
const char *delimiter)
{
char *prefix_start;
if (source_null_allowed == NULL) {
if (source == NULL) {
return NULL;
}
if (delimiter_null_allowed == NULL) {
return g_strdup (source_null_allowed);
if (delimiter == NULL) {
return g_strdup (source);
}
prefix_start = strstr (source_null_allowed, delimiter_null_allowed);
prefix_start = strstr (source, delimiter);
if (prefix_start == NULL) {
return NULL;
}
return g_strndup (source_null_allowed, prefix_start - source_null_allowed);
return g_strndup (source, prefix_start - source);
}
gboolean
nautilus_string_to_int (const char *string, int *integer)
nautilus_str_to_int (const char *string, int *integer)
{
long result;
char *parse_end;
@ -179,63 +179,94 @@ nautilus_string_to_int (const char *string, int *integer)
}
/**
* nautilus_strstrip:
* Remove all occurrences of a character from a string. The
* original string is modified in place, and also returned for convenience.
* nautilus_str_strip_chr:
* Remove all occurrences of a character from a string.
*
* @string_null_allowed: The string to be stripped.
* @remove_this: The char to remove from @string_null_allowed
* @source: The string to be stripped.
* @remove_this: The char to remove from @source
*
* Return value: @string_null_allowed, after removing all occurrences
* Return value: A copy of @source, after removing all occurrences
* of @remove_this.
*/
char *
nautilus_strstrip (char *string_null_allowed, char remove_this)
nautilus_str_strip_chr (const char *source, char remove_this)
{
if (string_null_allowed != NULL) {
char *in, *out;
char *result, *out;
const char *in;
if (source == NULL) {
return NULL;
}
result = g_malloc (strlen (source) + 1);
in = source;
out = result;
do {
if (*in != remove_this) {
*out++ = *in;
}
} while (*in++ != '\0');
in = string_null_allowed;
out = string_null_allowed;
do {
if (*in != remove_this) {
*out++ = *in;
}
} while (*in++ != '\0');
}
return result;
}
return string_null_allowed;
/**
* nautilus_str_strip_trailing_chr:
* Remove trailing occurrences of a character from a string.
*
* @source: The string to be stripped.
* @remove_this: The char to remove from @source
*
* Return value: @source, after removing trailing occurrences
* of @remove_this.
*/
char *
nautilus_str_strip_trailing_chr (const char *source, char remove_this)
{
const char *end;
if (source == NULL) {
return NULL;
}
for (end = source + strlen (source); end != source; end--) {
if (end[-1] != remove_this) {
break;
}
}
return g_strndup (source, end - source);
}
gboolean
nautilus_eat_string_to_int (char *string, int *integer)
nautilus_eat_str_to_int (char *source, int *integer)
{
gboolean result;
result = nautilus_string_to_int (string, integer);
g_free (string);
result = nautilus_str_to_int (source, integer);
g_free (source);
return result;
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
static int
call_string_to_int (const char *string)
call_str_to_int (const char *string)
{
int integer;
integer = 9999;
nautilus_string_to_int (string, &integer);
nautilus_str_to_int (string, &integer);
return integer;
}
static int
call_eat_string_to_int (char *string)
call_eat_str_to_int (char *string)
{
int integer;
integer = 9999;
nautilus_eat_string_to_int (string, &integer);
nautilus_eat_str_to_int (string, &integer);
return integer;
}
@ -278,57 +309,64 @@ nautilus_self_check_string (void)
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaa"), "aaab") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaab"), "aaa") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("ab", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaa", "aaab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("ab", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaa", "aaab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaab", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("ab", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("ab", "b"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("aaa", "baaa"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("baaa", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("ab", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("ab", "b"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("aaa", "baaa"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("baaa", "aaa"), TRUE);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix (NULL, NULL), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix (NULL, "foo"), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo", NULL), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo", "foo"), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo:", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo:bar", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("footle:bar", "tle:"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix (NULL, NULL), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix (NULL, "foo"), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo", NULL), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo", "foo"), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo:", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo:bar", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("footle:bar", "tle:"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("foo"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_foo"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("foo_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_foo_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_f_o__o_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("foo_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_foo__", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_f_o__o_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_foo", '_'), "_foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("foo_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_foo__", '_'), "_foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_f_o__o_", '_'), "_f_o__o");
#define TEST_INTEGER_CONVERSION_FUNCTIONS(string, boolean_result, integer_result) \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_to_int (string, &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_string_to_int (string), integer_result); \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_string_to_int (g_strdup (string), &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_eat_string_to_int (g_strdup (string)), integer_result);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_to_int (string, &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_str_to_int (string), integer_result); \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_str_to_int (g_strdup (string), &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_eat_str_to_int (g_strdup (string)), integer_result);
TEST_INTEGER_CONVERSION_FUNCTIONS (NULL, FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("", FALSE, 9999)

View file

@ -28,33 +28,39 @@
#include <glib.h>
#include <string.h>
/* We use the "str" abbrevation to mean char * string, since
* "string" usually means g_string instead.
*/
/* NULL is allowed for all the str parameters to these functions. */
/* Versions of basic string functions that allow NULL. */
size_t nautilus_strlen (const char *string_null_allowed);
char * nautilus_strchr (const char *haystack_null_allowed,
char needle);
int nautilus_strcmp (const char *string_a_null_allowed,
const char *string_b_null_allowed);
size_t nautilus_strlen (const char *string);
char * nautilus_strchr (const char *haystack,
char needle);
int nautilus_strcmp (const char *string_a,
const char *string_b);
/* Versions of basic string functions that free their parameters. */
int nautilus_eat_strcmp (char *string_a_null_allowed_gets_freed,
const char *string_b_null_allowed);
int nautilus_eat_strcmp (char *string_a_gets_freed,
const char *string_b);
/* Other basic string operations. */
gboolean nautilus_has_prefix (const char *target_null_allowed,
const char *prefix_null_allowed);
char * nautilus_strdup_prefix (const char *source_null_allowed,
const char *delimiter_null_allowed);
gboolean nautilus_has_suffix (const char *target_null_allowed,
const char *suffix_null_allowed);
char * nautilus_strstrip (char *string_null_allowed,
char remove_this);
gboolean nautilus_str_has_prefix (const char *target,
const char *prefix);
char * nautilus_str_get_prefix (const char *source,
const char *delimiter);
gboolean nautilus_str_has_suffix (const char *target,
const char *suffix);
char * nautilus_str_strip_chr (const char *string,
char remove_this);
char * nautilus_str_strip_trailing_chr (const char *string,
char remove_this);
/* Conversions to and from strings. */
gboolean nautilus_string_to_int (const char *string,
int *integer);
gboolean nautilus_eat_string_to_int (char *string_gets_freed,
int *integer);
gboolean nautilus_str_to_int (const char *string,
int *integer);
gboolean nautilus_eat_str_to_int (char *string_gets_freed,
int *integer);
#endif /* NAUTILUS_STRING_H */

View file

@ -1698,7 +1698,7 @@ static void
destroy (GtkObject *object)
{
GnomeIconContainer *container;
int index;
int i;
container = GNOME_ICON_CONTAINER (object);
@ -1709,18 +1709,24 @@ destroy (GtkObject *object)
g_hash_table_destroy (container->details->canvas_item_to_icon);
unschedule_kbd_icon_visibility (container);
if (container->details->rubberband_info.timer_id != 0)
if (container->details->rubberband_info.timer_id != 0) {
gtk_timeout_remove (container->details->rubberband_info.timer_id);
if (container->details->rubberband_info.selection_rectangle != NULL)
}
if (container->details->rubberband_info.selection_rectangle != NULL) {
gtk_object_destroy (GTK_OBJECT (container->details->rubberband_info.selection_rectangle));
}
if (container->details->idle_id != 0)
if (container->details->idle_id != 0) {
gtk_idle_remove (container->details->idle_id);
if (container->details->linger_selection_mode_timer_id != 0)
}
if (container->details->linger_selection_mode_timer_id != 0) {
gtk_timeout_remove (container->details->linger_selection_mode_timer_id);
for (index = 0; index < NAUTILUS_N_ELEMENTS (container->details->label_font); index++)
if (container->details->label_font[index] != NULL)
gdk_font_unref(container->details->label_font[index]);
}
for (i = 0; i < NAUTILUS_N_ELEMENTS (container->details->label_font); i++) {
if (container->details->label_font[i] != NULL) {
gdk_font_unref(container->details->label_font[i]);
}
}
g_free (container->details);
@ -2441,8 +2447,9 @@ gnome_icon_container_clear (GnomeIconContainer *container)
set_kbd_current (container, NULL, FALSE);
details->stretch_icon = NULL;
for (p = details->icons; p != NULL; p = p->next)
for (p = details->icons; p != NULL; p = p->next) {
icon_free (p->data);
}
g_list_free (details->icons);
details->icons = NULL;
details->num_icons = 0;

View file

@ -55,6 +55,8 @@ struct NautilusDirectoryDetails
GList *files;
};
NautilusFile *nautilus_directory_find_file (NautilusDirectory *directory,
const char *file_name);
NautilusFile *nautilus_directory_new_file (NautilusDirectory *directory,
GnomeVFSFileInfo *info);
char * nautilus_directory_get_file_metadata (NautilusDirectory *directory,

View file

@ -71,7 +71,6 @@ static void nautilus_directory_finalize (GtkObje
static NautilusDirectory *nautilus_directory_new (const char *uri);
static void nautilus_directory_read_metafile (NautilusDirectory *directory);
static void nautilus_directory_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory);
static void nautilus_directory_load_cb (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
GnomeVFSDirectoryList *list,
@ -133,9 +132,7 @@ nautilus_directory_finalize (GtkObject *object)
directory = NAUTILUS_DIRECTORY (object);
if (directory->details->write_metafile_idle_id != 0) {
nautilus_directory_write_metafile (directory);
}
g_assert (directory->details->write_metafile_idle_id == 0);
g_hash_table_remove (directory_objects, directory->details->uri_text);
@ -172,13 +169,15 @@ nautilus_directory_finalize (GtkObject *object)
NautilusDirectory *
nautilus_directory_get (const char *uri)
{
char *canonical_uri;
NautilusDirectory *directory;
g_return_val_if_fail (uri != NULL, NULL);
/* FIXME: This currently ignores the issue of two uris that are not identical but point
to the same data.
to the same data except for the specific case of trailing '/' characters.
*/
canonical_uri = nautilus_str_strip_trailing_chr (uri, '/');
/* Create the hash table first time through. */
if (directory_objects == NULL) {
@ -186,25 +185,30 @@ nautilus_directory_get (const char *uri)
}
/* If the object is already in the hash table, look it up. */
directory = g_hash_table_lookup (directory_objects, uri);
directory = g_hash_table_lookup (directory_objects,
canonical_uri);
if (directory != NULL) {
g_assert (NAUTILUS_IS_DIRECTORY (directory));
gtk_object_ref (GTK_OBJECT (directory));
} else {
/* Create a new directory object instead. */
directory = nautilus_directory_new (uri);
directory = nautilus_directory_new (canonical_uri);
if (directory == NULL) {
return NULL;
}
g_assert (strcmp (directory->details->uri_text, uri) == 0);
g_assert (strcmp (directory->details->uri_text, canonical_uri) == 0);
/* Put it in the hash table. */
gtk_object_ref (GTK_OBJECT (directory));
gtk_object_sink (GTK_OBJECT (directory));
g_hash_table_insert (directory_objects, directory->details->uri_text, directory);
g_hash_table_insert (directory_objects,
directory->details->uri_text,
directory);
}
g_free (canonical_uri);
return directory;
}
@ -252,13 +256,6 @@ nautilus_directory_try_to_read_metafile (NautilusDirectory *directory, GnomeVFSU
if (size != metafile_info.size) {
result = GNOME_VFS_ERROR_TOOBIG;
}
/* Avoid allocating a NULL buffer later and passing it
around; we still want to try to parse an empty file
so we get a metafile tree and a valid result. */
if (size == 0) {
size = 1;
}
}
metafile_handle = NULL;
@ -269,8 +266,14 @@ nautilus_directory_try_to_read_metafile (NautilusDirectory *directory, GnomeVFSU
}
if (result == GNOME_VFS_OK) {
buffer = g_malloc (size);
/* The gnome-xml parser requires a zero-terminated array.
* Also, we don't want to allocate an empty buffer
* because it would be NULL and gnome-xml won't parse
* NULL properly.
*/
buffer = g_malloc (size + 1);
result = gnome_vfs_read (metafile_handle, buffer, size, &actual_size);
buffer[actual_size] = '\0';
directory->details->metafile_tree = xmlParseMemory (buffer, actual_size);
g_free (buffer);
}
@ -290,22 +293,16 @@ nautilus_directory_read_metafile (NautilusDirectory *directory)
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
/* Check for the alternate metafile first.
If we read from it, then write to it later. */
* If we read from it, then write to it later.
*/
directory->details->use_alternate_metafile = FALSE;
result = nautilus_directory_try_to_read_metafile (directory, directory->details->alternate_metafile_uri);
result = nautilus_directory_try_to_read_metafile (directory,
directory->details->alternate_metafile_uri);
if (result == GNOME_VFS_OK) {
directory->details->use_alternate_metafile = TRUE;
} else {
result = nautilus_directory_try_to_read_metafile (directory, directory->details->metafile_uri);
}
}
static void
nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory)
{
if (directory->details->write_metafile_idle_id != 0) {
gtk_idle_remove (directory->details->write_metafile_idle_id);
directory->details->write_metafile_idle_id = 0;
result = nautilus_directory_try_to_read_metafile (directory,
directory->details->metafile_uri);
}
}
@ -355,35 +352,45 @@ nautilus_directory_write_metafile (NautilusDirectory *directory)
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
gtk_object_ref (GTK_OBJECT (directory));
/* We are about the write the metafile, so we can cancel the pending
request to do so.
*/
nautilus_directory_remove_write_metafile_idle (directory);
if (directory->details->write_metafile_idle_id != 0) {
gtk_idle_remove (directory->details->write_metafile_idle_id);
directory->details->write_metafile_idle_id = 0;
gtk_object_unref (GTK_OBJECT (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;
if (directory->details->metafile_tree != NULL) {
/* Try the main URI, unless we have already been instructed to use the alternate URI. */
if (directory->details->use_alternate_metafile) {
result = GNOME_VFS_ERROR_ACCESSDENIED;
} else {
result = nautilus_directory_try_to_write_metafile (directory,
directory->details->metafile_uri);
}
/* Try the alternate URI if the main one failed. */
if (result != GNOME_VFS_OK) {
result = nautilus_directory_try_to_write_metafile (directory,
directory->details->alternate_metafile_uri);
}
/* Check for errors. FIXME: Later this must be reported to the user, not spit out as a warning. */
if (result != GNOME_VFS_OK) {
g_warning ("nautilus_directory_write_metafile failed to write metafile - we should report this to the user");
}
}
/* Try the main URI, unless we have already been instructed to use the alternate URI. */
if (directory->details->use_alternate_metafile) {
result = GNOME_VFS_ERROR_ACCESSDENIED;
} else {
result = nautilus_directory_try_to_write_metafile (directory, directory->details->metafile_uri);
}
/* Try the alternate URI if the main one failed. */
if (result != GNOME_VFS_OK) {
result = nautilus_directory_try_to_write_metafile (directory, directory->details->alternate_metafile_uri);
}
/* Check for errors. FIXME: Later this must be reported to the user, not spit out as a warning. */
if (result != GNOME_VFS_OK) {
g_warning ("nautilus_directory_write_metafile failed to write metafile - we should report this to the user");
}
gtk_object_unref (GTK_OBJECT (directory));
}
static gboolean
@ -396,6 +403,8 @@ nautilus_directory_write_metafile_idle_cb (gpointer callback_data)
directory->details->write_metafile_idle_id = 0;
nautilus_directory_write_metafile (directory);
gtk_object_unref (GTK_OBJECT (directory));
return FALSE;
}
@ -404,6 +413,7 @@ nautilus_directory_request_write_metafile (NautilusDirectory *directory)
{
/* Set up an idle task that will write the metafile. */
if (directory->details->write_metafile_idle_id == 0) {
gtk_object_ref (GTK_OBJECT (directory));
directory->details->write_metafile_idle_id =
gtk_idle_add (nautilus_directory_write_metafile_idle_cb,
directory);
@ -1056,6 +1066,27 @@ nautilus_directory_set_file_metadata (NautilusDirectory *directory,
nautilus_directory_request_write_metafile (directory);
}
static int
compare_file_with_name (gconstpointer a, gconstpointer b)
{
return strcmp (((const NautilusFile *) a)->info->name, b);
}
NautilusFile *
nautilus_directory_find_file (NautilusDirectory *directory, const char *name)
{
GList *list_entry;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
g_return_val_if_fail (name != NULL, NULL);
list_entry = g_list_find_custom (directory->details->files,
(gpointer) name,
compare_file_with_name);
return list_entry == NULL ? NULL : list_entry->data;
}
NautilusFile *
nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *info)
{
@ -1138,28 +1169,40 @@ nautilus_self_check_directory (void)
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (NULL, "TEST_INTEGER", 42), 42);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "NONEXISTENT_KEY", 42), 42);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc/") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc////") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
gtk_object_unref (GTK_OBJECT (directory));
/* let the idle function run */
while (gtk_events_pending ()) {
gtk_main_iteration ();
}
NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directory_objects), 0);
directory = nautilus_directory_get ("file:///etc");
NAUTILUS_CHECK_BOOLEAN_RESULT (directory->details->metafile_tree != NULL, TRUE);
NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directory_objects), 1);
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
/* 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");
file_1 = nautilus_file_get ("file:///home/");
NAUTILUS_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "home");
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get ("file:///home/") == file_1, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get ("file:///home") == file_1, TRUE);
nautilus_file_unref (file_1);
nautilus_file_unref (file_1);
file_1 = nautilus_file_get ("file:///home");
@ -1179,6 +1222,16 @@ nautilus_self_check_directory (void)
nautilus_file_unref (file_1);
nautilus_file_unref (file_2);
/* 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 */

View file

@ -83,19 +83,22 @@ nautilus_file_get (const char *uri)
GNOME_VFS_FILE_INFO_GETMIMETYPE
| GNOME_VFS_FILE_INFO_FASTMIMETYPE
| GNOME_VFS_FILE_INFO_FOLLOWLINKS, NULL);
if (result != GNOME_VFS_OK)
if (result != GNOME_VFS_OK) {
return NULL;
}
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL)
if (vfs_uri == NULL) {
return NULL;
}
/* Make VFS version of directory URI. */
directory_vfs_uri = gnome_vfs_uri_get_parent (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
if (directory_vfs_uri == NULL)
if (directory_vfs_uri == NULL) {
return NULL;
}
/* Make text version of directory URI. */
directory_uri = gnome_vfs_uri_to_string (directory_vfs_uri,
@ -105,10 +108,16 @@ nautilus_file_get (const char *uri)
/* Get object that represents the directory. */
directory = nautilus_directory_get (directory_uri);
g_free (directory_uri);
if (directory == NULL)
if (directory == NULL) {
return NULL;
}
file = nautilus_directory_new_file (directory, file_info);
file = nautilus_directory_find_file (directory, file_info->name);
if (file == NULL) {
file = nautilus_directory_new_file (directory, file_info);
directory->details->files =
g_list_append (directory->details->files, file);
}
gnome_vfs_file_info_unref (file_info);
nautilus_file_ref (file);
@ -176,14 +185,17 @@ nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFi
is_directory_1 = nautilus_file_is_directory (file_1);
is_directory_2 = nautilus_file_is_directory (file_2);
if (is_directory_1 && !is_directory_2)
if (is_directory_1 && !is_directory_2) {
return -1;
}
if (is_directory_2 && !is_directory_1)
if (is_directory_2 && !is_directory_1) {
return +1;
}
if (!is_directory_1 && !is_directory_2)
if (!is_directory_1 && !is_directory_2) {
return 0;
}
/* Both are directories, compare by item count. */
/* FIXME: get_directory_item_count_hack is slow, and calling
@ -195,11 +207,13 @@ nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFi
item_count_1 = get_directory_item_count_hack (file_1, FALSE);
item_count_2 = get_directory_item_count_hack (file_2, FALSE);
if (item_count_1 < item_count_2)
if (item_count_1 < item_count_2) {
return -1;
}
if (item_count_2 < item_count_1)
if (item_count_2 < item_count_1) {
return +1;
}
return 0;
}
@ -221,17 +235,21 @@ nautilus_file_compare_by_type (NautilusFile *file_1, NautilusFile *file_2)
is_directory_1 = nautilus_file_is_directory (file_1);
is_directory_2 = nautilus_file_is_directory (file_2);
if (is_directory_1 && is_directory_2)
if (is_directory_1 && is_directory_2) {
return 0;
}
if (is_directory_1)
if (is_directory_1) {
return -1;
}
if (is_directory_2)
if (is_directory_2) {
return +1;
}
if (nautilus_strcmp (file_1->info->mime_type, file_2->info->mime_type) == 0)
if (nautilus_strcmp (file_1->info->mime_type, file_2->info->mime_type) == 0) {
return 0;
}
type_string_1 = nautilus_file_get_type_as_string (file_1);
type_string_2 = nautilus_file_get_type_as_string (file_2);
@ -300,14 +318,15 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
return 0;
}
if (reversed)
if (reversed) {
return gnome_vfs_file_info_compare_for_sort_reversed (file_1->info,
file_2->info,
rules);
else
} else {
return gnome_vfs_file_info_compare_for_sort (file_1->info,
file_2->info,
rules);
}
}
/**
@ -460,23 +479,16 @@ nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type
* internationalization's sake.
*/
if (file_date_age == 0)
{
if (file_date_age == 0) {
/* today, use special word */
format = _("today %-I:%M %p");
}
else if (file_date_age == 1)
{
} else if (file_date_age == 1) {
/* yesterday, use special word */
format = _("yesterday %-I:%M %p");
}
else if (file_date_age < 7)
{
} else if (file_date_age < 7) {
/* current week, include day of week */
format = _("%A %-m/%-d/%y %-I:%M %p");
}
else
{
} else {
format = _("%-m/%-d/%y %-I:%M %p");
}
@ -578,8 +590,7 @@ nautilus_file_get_owner_as_string (NautilusFile *file)
g_print ("pointer to password info is %p\n", password_info);
if (password_info == NULL)
{
if (password_info == NULL) {
return g_strdup (_("unknown owner"));
}
@ -607,8 +618,7 @@ nautilus_file_get_group_as_string (NautilusFile *file)
/* No need to free result of getgrgid */
group_info = getgrgid (file->info->gid);
if (group_info == NULL)
{
if (group_info == NULL) {
return g_strdup (_("unknown group"));
}
@ -633,24 +643,28 @@ get_directory_item_count_hack (NautilusFile *file, gboolean ignore_invisible_ite
g_assert (nautilus_file_is_directory (file));
uri = nautilus_file_get_uri (file);
if (nautilus_has_prefix (uri, "file://"))
if (nautilus_str_has_prefix (uri, "file://")) {
path = uri + 7;
else
} else {
path = uri;
}
directory = opendir (path);
g_free (uri);
if (!directory)
if (!directory) {
return 0;
}
count = 0;
while ((entry = readdir(directory)) != NULL)
while ((entry = readdir(directory)) != NULL) {
// Only count invisible items if requested.
if (!ignore_invisible_items || entry->d_name[0] != '.')
if (!ignore_invisible_items || entry->d_name[0] != '.') {
count += 1;
}
}
closedir(directory);
@ -678,8 +692,7 @@ nautilus_file_get_size_as_string (NautilusFile *file)
{
g_return_val_if_fail (file != NULL, NULL);
if (nautilus_file_is_directory (file))
{
if (nautilus_file_is_directory (file)) {
/* FIXME: Since computing the item count is slow, we
* want to do it in a deferred way. However, that
* architecture doesn't exist yet, so we're hacking

View file

@ -610,7 +610,7 @@ nautilus_icon_factory_get_icon_for_file (NautilusFile *file)
or use a thumbnail if one exists. If a thumbnail is required, but does not yet exist,
put an entry on the thumbnail queue so we eventually make one */
if (uri == NULL && nautilus_has_prefix (nautilus_file_get_mime_type (file), "image/")) {
if (uri == NULL && nautilus_str_has_prefix (nautilus_file_get_mime_type (file), "image/")) {
if (nautilus_file_get_size (file) < SELF_THUMBNAIL_SIZE_THRESHOLD)
uri = nautilus_file_get_uri (file);
else
@ -686,7 +686,8 @@ make_thumbnail_path (const char *image_uri, gboolean directory_only)
if (directory_only)
thumbnail_uri = g_strdup_printf ("%s/.thumbnails", temp_str);
else {
if (nautilus_has_suffix (image_uri, ".png") || nautilus_has_suffix (image_uri, ".PNG")) {
if (nautilus_str_has_suffix (image_uri, ".png")
|| nautilus_str_has_suffix (image_uri, ".PNG")) {
thumbnail_uri = g_strdup_printf ("%s/.thumbnails/%s", temp_str, last_slash + 1);
} else {
thumbnail_uri = g_strdup_printf ("%s/.thumbnails/%s.png", temp_str, last_slash + 1);
@ -869,7 +870,7 @@ load_specific_image (NautilusScalableIcon *scalable_icon,
* and gdk-pixbuf.
*/
if (size_in_pixels == NAUTILUS_ICON_SIZE_STANDARD
&& nautilus_has_prefix (scalable_icon->uri, "file://")) {
&& nautilus_str_has_prefix (scalable_icon->uri, "file://")) {
return gdk_pixbuf_new_from_file (scalable_icon->uri + 7);
}

View file

@ -601,7 +601,7 @@ draw_mini_text (GnomeCanvasItem* item, GdkDrawable *drawable,
/* FIXME: need to use gnome_vfs to read the file */
file_name = details->text_source;
if (nautilus_has_prefix (details->text_source, "file://")) {
if (nautilus_str_has_prefix (details->text_source, "file://")) {
file_name += 7;
}
text_file = fopen(file_name, "r");

View file

@ -39,13 +39,13 @@ void nautilus_run_lib_self_checks (void);
*/
#define NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
macro (nautilus_self_check_string) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gdk_extensions) \
macro (nautilus_self_check_background) \
macro (nautilus_self_check_directory) \
macro (nautilus_self_check_gdk_extensions) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gnome_icon_container) \
macro (nautilus_self_check_icon_factory) \
macro (nautilus_self_check_string) \
/* Add new self-check functions to the list above this line. */
/* Generate prototypes for all the functions. */

View file

@ -32,22 +32,22 @@
#include "nautilus-lib-self-check-functions.h"
size_t
nautilus_strlen (const char *string_null_allowed)
nautilus_strlen (const char *string)
{
return string_null_allowed == NULL ? 0 : strlen (string_null_allowed);
return string == NULL ? 0 : strlen (string);
}
char *
nautilus_strchr (const char *haystack_null_allowed, char needle)
nautilus_strchr (const char *haystack, char needle)
{
return haystack_null_allowed == NULL ? NULL : strchr (haystack_null_allowed, needle);
return haystack == NULL ? NULL : strchr (haystack, needle);
}
int
nautilus_strcmp (const char *string_a_null_allowed, const char *string_b_null_allowed)
nautilus_strcmp (const char *string_a, const char *string_b)
{
return strcmp (string_a_null_allowed == NULL ? "" : string_a_null_allowed,
string_b_null_allowed == NULL ? "" : string_b_null_allowed);
return strcmp (string_a == NULL ? "" : string_a,
string_b == NULL ? "" : string_b);
}
int
@ -61,13 +61,13 @@ nautilus_eat_strcmp (char *string_a, const char *string_b)
}
gboolean
nautilus_has_prefix (const char *haystack_null_allowed, const char *needle_null_allowed)
nautilus_str_has_prefix (const char *haystack, const char *needle)
{
const char *h, *n;
/* Eat one character at a time. */
h = haystack_null_allowed == NULL ? "" : haystack_null_allowed;
n = needle_null_allowed == NULL ? "" : needle_null_allowed;
h = haystack == NULL ? "" : haystack;
n = needle == NULL ? "" : needle;
do {
if (*n == '\0') {
return TRUE;
@ -80,25 +80,25 @@ nautilus_has_prefix (const char *haystack_null_allowed, const char *needle_null_
}
gboolean
nautilus_has_suffix (const char *haystack_null_allowed, const char *needle_null_allowed)
nautilus_str_has_suffix (const char *haystack, const char *needle)
{
const char *h, *n;
if (needle_null_allowed == NULL) {
if (needle == NULL) {
return TRUE;
}
if (haystack_null_allowed == NULL) {
return needle_null_allowed[0] == '\0';
if (haystack == NULL) {
return needle[0] == '\0';
}
/* Eat one character at a time. */
h = haystack_null_allowed + strlen(haystack_null_allowed);
n = needle_null_allowed + strlen(needle_null_allowed);
h = haystack + strlen(haystack);
n = needle + strlen(needle);
do {
if (n == needle_null_allowed) {
if (n == needle) {
return TRUE;
}
if (h == haystack_null_allowed) {
if (h == haystack) {
return FALSE;
}
} while (*--h == *--n);
@ -107,44 +107,44 @@ nautilus_has_suffix (const char *haystack_null_allowed, const char *needle_null_
/**
* nautilus_strdup_prefix:
* nautilus_str_get_prefix:
* Get a new string containing the first part of an existing string.
*
* @source_null_allowed: The string whose prefix should be extracted.
* @delimiter_null_allowed: The string that marks the end of the prefix.
* @source: The string whose prefix should be extracted.
* @delimiter: The string that marks the end of the prefix.
*
* Return value: A newly-allocated string that that matches the first part
* of @source_null_allowed, up to but not including the first occurrence of
* @delimiter_null_allowed. If @source_null_allowed is NULL, returns NULL. If
* @delimiter_null_allowed is NULL, returns a copy of @source_null_allowed.
* If @delimiter_null_allowed does not occur in @source_null_allowed, returns
* a copy of @source_null_allowed.
* of @source, up to but not including the first occurrence of
* @delimiter. If @source is NULL, returns NULL. If
* @delimiter is NULL, returns a copy of @source.
* If @delimiter does not occur in @source, returns
* a copy of @source.
**/
char *
nautilus_strdup_prefix (const char *source_null_allowed,
const char *delimiter_null_allowed)
nautilus_str_get_prefix (const char *source,
const char *delimiter)
{
char *prefix_start;
if (source_null_allowed == NULL) {
if (source == NULL) {
return NULL;
}
if (delimiter_null_allowed == NULL) {
return g_strdup (source_null_allowed);
if (delimiter == NULL) {
return g_strdup (source);
}
prefix_start = strstr (source_null_allowed, delimiter_null_allowed);
prefix_start = strstr (source, delimiter);
if (prefix_start == NULL) {
return NULL;
}
return g_strndup (source_null_allowed, prefix_start - source_null_allowed);
return g_strndup (source, prefix_start - source);
}
gboolean
nautilus_string_to_int (const char *string, int *integer)
nautilus_str_to_int (const char *string, int *integer)
{
long result;
char *parse_end;
@ -179,63 +179,94 @@ nautilus_string_to_int (const char *string, int *integer)
}
/**
* nautilus_strstrip:
* Remove all occurrences of a character from a string. The
* original string is modified in place, and also returned for convenience.
* nautilus_str_strip_chr:
* Remove all occurrences of a character from a string.
*
* @string_null_allowed: The string to be stripped.
* @remove_this: The char to remove from @string_null_allowed
* @source: The string to be stripped.
* @remove_this: The char to remove from @source
*
* Return value: @string_null_allowed, after removing all occurrences
* Return value: A copy of @source, after removing all occurrences
* of @remove_this.
*/
char *
nautilus_strstrip (char *string_null_allowed, char remove_this)
nautilus_str_strip_chr (const char *source, char remove_this)
{
if (string_null_allowed != NULL) {
char *in, *out;
char *result, *out;
const char *in;
if (source == NULL) {
return NULL;
}
result = g_malloc (strlen (source) + 1);
in = source;
out = result;
do {
if (*in != remove_this) {
*out++ = *in;
}
} while (*in++ != '\0');
in = string_null_allowed;
out = string_null_allowed;
do {
if (*in != remove_this) {
*out++ = *in;
}
} while (*in++ != '\0');
}
return result;
}
return string_null_allowed;
/**
* nautilus_str_strip_trailing_chr:
* Remove trailing occurrences of a character from a string.
*
* @source: The string to be stripped.
* @remove_this: The char to remove from @source
*
* Return value: @source, after removing trailing occurrences
* of @remove_this.
*/
char *
nautilus_str_strip_trailing_chr (const char *source, char remove_this)
{
const char *end;
if (source == NULL) {
return NULL;
}
for (end = source + strlen (source); end != source; end--) {
if (end[-1] != remove_this) {
break;
}
}
return g_strndup (source, end - source);
}
gboolean
nautilus_eat_string_to_int (char *string, int *integer)
nautilus_eat_str_to_int (char *source, int *integer)
{
gboolean result;
result = nautilus_string_to_int (string, integer);
g_free (string);
result = nautilus_str_to_int (source, integer);
g_free (source);
return result;
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
static int
call_string_to_int (const char *string)
call_str_to_int (const char *string)
{
int integer;
integer = 9999;
nautilus_string_to_int (string, &integer);
nautilus_str_to_int (string, &integer);
return integer;
}
static int
call_eat_string_to_int (char *string)
call_eat_str_to_int (char *string)
{
int integer;
integer = 9999;
nautilus_eat_string_to_int (string, &integer);
nautilus_eat_str_to_int (string, &integer);
return integer;
}
@ -278,57 +309,64 @@ nautilus_self_check_string (void)
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaa"), "aaab") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaab"), "aaa") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("ab", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaa", "aaab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("ab", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaa", "aaab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaab", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("ab", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("ab", "b"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("aaa", "baaa"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("baaa", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("ab", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("ab", "b"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("aaa", "baaa"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("baaa", "aaa"), TRUE);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix (NULL, NULL), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix (NULL, "foo"), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo", NULL), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo", "foo"), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo:", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo:bar", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("footle:bar", "tle:"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix (NULL, NULL), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix (NULL, "foo"), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo", NULL), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo", "foo"), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo:", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo:bar", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("footle:bar", "tle:"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("foo"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_foo"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("foo_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_foo_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_f_o__o_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("foo_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_foo__", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_f_o__o_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_foo", '_'), "_foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("foo_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_foo__", '_'), "_foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_f_o__o_", '_'), "_f_o__o");
#define TEST_INTEGER_CONVERSION_FUNCTIONS(string, boolean_result, integer_result) \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_to_int (string, &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_string_to_int (string), integer_result); \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_string_to_int (g_strdup (string), &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_eat_string_to_int (g_strdup (string)), integer_result);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_to_int (string, &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_str_to_int (string), integer_result); \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_str_to_int (g_strdup (string), &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_eat_str_to_int (g_strdup (string)), integer_result);
TEST_INTEGER_CONVERSION_FUNCTIONS (NULL, FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("", FALSE, 9999)

View file

@ -28,33 +28,39 @@
#include <glib.h>
#include <string.h>
/* We use the "str" abbrevation to mean char * string, since
* "string" usually means g_string instead.
*/
/* NULL is allowed for all the str parameters to these functions. */
/* Versions of basic string functions that allow NULL. */
size_t nautilus_strlen (const char *string_null_allowed);
char * nautilus_strchr (const char *haystack_null_allowed,
char needle);
int nautilus_strcmp (const char *string_a_null_allowed,
const char *string_b_null_allowed);
size_t nautilus_strlen (const char *string);
char * nautilus_strchr (const char *haystack,
char needle);
int nautilus_strcmp (const char *string_a,
const char *string_b);
/* Versions of basic string functions that free their parameters. */
int nautilus_eat_strcmp (char *string_a_null_allowed_gets_freed,
const char *string_b_null_allowed);
int nautilus_eat_strcmp (char *string_a_gets_freed,
const char *string_b);
/* Other basic string operations. */
gboolean nautilus_has_prefix (const char *target_null_allowed,
const char *prefix_null_allowed);
char * nautilus_strdup_prefix (const char *source_null_allowed,
const char *delimiter_null_allowed);
gboolean nautilus_has_suffix (const char *target_null_allowed,
const char *suffix_null_allowed);
char * nautilus_strstrip (char *string_null_allowed,
char remove_this);
gboolean nautilus_str_has_prefix (const char *target,
const char *prefix);
char * nautilus_str_get_prefix (const char *source,
const char *delimiter);
gboolean nautilus_str_has_suffix (const char *target,
const char *suffix);
char * nautilus_str_strip_chr (const char *string,
char remove_this);
char * nautilus_str_strip_trailing_chr (const char *string,
char remove_this);
/* Conversions to and from strings. */
gboolean nautilus_string_to_int (const char *string,
int *integer);
gboolean nautilus_eat_string_to_int (char *string_gets_freed,
int *integer);
gboolean nautilus_str_to_int (const char *string,
int *integer);
gboolean nautilus_eat_str_to_int (char *string_gets_freed,
int *integer);
#endif /* NAUTILUS_STRING_H */

View file

@ -1698,7 +1698,7 @@ static void
destroy (GtkObject *object)
{
GnomeIconContainer *container;
int index;
int i;
container = GNOME_ICON_CONTAINER (object);
@ -1709,18 +1709,24 @@ destroy (GtkObject *object)
g_hash_table_destroy (container->details->canvas_item_to_icon);
unschedule_kbd_icon_visibility (container);
if (container->details->rubberband_info.timer_id != 0)
if (container->details->rubberband_info.timer_id != 0) {
gtk_timeout_remove (container->details->rubberband_info.timer_id);
if (container->details->rubberband_info.selection_rectangle != NULL)
}
if (container->details->rubberband_info.selection_rectangle != NULL) {
gtk_object_destroy (GTK_OBJECT (container->details->rubberband_info.selection_rectangle));
}
if (container->details->idle_id != 0)
if (container->details->idle_id != 0) {
gtk_idle_remove (container->details->idle_id);
if (container->details->linger_selection_mode_timer_id != 0)
}
if (container->details->linger_selection_mode_timer_id != 0) {
gtk_timeout_remove (container->details->linger_selection_mode_timer_id);
for (index = 0; index < NAUTILUS_N_ELEMENTS (container->details->label_font); index++)
if (container->details->label_font[index] != NULL)
gdk_font_unref(container->details->label_font[index]);
}
for (i = 0; i < NAUTILUS_N_ELEMENTS (container->details->label_font); i++) {
if (container->details->label_font[i] != NULL) {
gdk_font_unref(container->details->label_font[i]);
}
}
g_free (container->details);
@ -2441,8 +2447,9 @@ gnome_icon_container_clear (GnomeIconContainer *container)
set_kbd_current (container, NULL, FALSE);
details->stretch_icon = NULL;
for (p = details->icons; p != NULL; p = p->next)
for (p = details->icons; p != NULL; p = p->next) {
icon_free (p->data);
}
g_list_free (details->icons);
details->icons = NULL;
details->num_icons = 0;

View file

@ -55,6 +55,8 @@ struct NautilusDirectoryDetails
GList *files;
};
NautilusFile *nautilus_directory_find_file (NautilusDirectory *directory,
const char *file_name);
NautilusFile *nautilus_directory_new_file (NautilusDirectory *directory,
GnomeVFSFileInfo *info);
char * nautilus_directory_get_file_metadata (NautilusDirectory *directory,

View file

@ -71,7 +71,6 @@ static void nautilus_directory_finalize (GtkObje
static NautilusDirectory *nautilus_directory_new (const char *uri);
static void nautilus_directory_read_metafile (NautilusDirectory *directory);
static void nautilus_directory_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory);
static void nautilus_directory_load_cb (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
GnomeVFSDirectoryList *list,
@ -133,9 +132,7 @@ nautilus_directory_finalize (GtkObject *object)
directory = NAUTILUS_DIRECTORY (object);
if (directory->details->write_metafile_idle_id != 0) {
nautilus_directory_write_metafile (directory);
}
g_assert (directory->details->write_metafile_idle_id == 0);
g_hash_table_remove (directory_objects, directory->details->uri_text);
@ -172,13 +169,15 @@ nautilus_directory_finalize (GtkObject *object)
NautilusDirectory *
nautilus_directory_get (const char *uri)
{
char *canonical_uri;
NautilusDirectory *directory;
g_return_val_if_fail (uri != NULL, NULL);
/* FIXME: This currently ignores the issue of two uris that are not identical but point
to the same data.
to the same data except for the specific case of trailing '/' characters.
*/
canonical_uri = nautilus_str_strip_trailing_chr (uri, '/');
/* Create the hash table first time through. */
if (directory_objects == NULL) {
@ -186,25 +185,30 @@ nautilus_directory_get (const char *uri)
}
/* If the object is already in the hash table, look it up. */
directory = g_hash_table_lookup (directory_objects, uri);
directory = g_hash_table_lookup (directory_objects,
canonical_uri);
if (directory != NULL) {
g_assert (NAUTILUS_IS_DIRECTORY (directory));
gtk_object_ref (GTK_OBJECT (directory));
} else {
/* Create a new directory object instead. */
directory = nautilus_directory_new (uri);
directory = nautilus_directory_new (canonical_uri);
if (directory == NULL) {
return NULL;
}
g_assert (strcmp (directory->details->uri_text, uri) == 0);
g_assert (strcmp (directory->details->uri_text, canonical_uri) == 0);
/* Put it in the hash table. */
gtk_object_ref (GTK_OBJECT (directory));
gtk_object_sink (GTK_OBJECT (directory));
g_hash_table_insert (directory_objects, directory->details->uri_text, directory);
g_hash_table_insert (directory_objects,
directory->details->uri_text,
directory);
}
g_free (canonical_uri);
return directory;
}
@ -252,13 +256,6 @@ nautilus_directory_try_to_read_metafile (NautilusDirectory *directory, GnomeVFSU
if (size != metafile_info.size) {
result = GNOME_VFS_ERROR_TOOBIG;
}
/* Avoid allocating a NULL buffer later and passing it
around; we still want to try to parse an empty file
so we get a metafile tree and a valid result. */
if (size == 0) {
size = 1;
}
}
metafile_handle = NULL;
@ -269,8 +266,14 @@ nautilus_directory_try_to_read_metafile (NautilusDirectory *directory, GnomeVFSU
}
if (result == GNOME_VFS_OK) {
buffer = g_malloc (size);
/* The gnome-xml parser requires a zero-terminated array.
* Also, we don't want to allocate an empty buffer
* because it would be NULL and gnome-xml won't parse
* NULL properly.
*/
buffer = g_malloc (size + 1);
result = gnome_vfs_read (metafile_handle, buffer, size, &actual_size);
buffer[actual_size] = '\0';
directory->details->metafile_tree = xmlParseMemory (buffer, actual_size);
g_free (buffer);
}
@ -290,22 +293,16 @@ nautilus_directory_read_metafile (NautilusDirectory *directory)
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
/* Check for the alternate metafile first.
If we read from it, then write to it later. */
* If we read from it, then write to it later.
*/
directory->details->use_alternate_metafile = FALSE;
result = nautilus_directory_try_to_read_metafile (directory, directory->details->alternate_metafile_uri);
result = nautilus_directory_try_to_read_metafile (directory,
directory->details->alternate_metafile_uri);
if (result == GNOME_VFS_OK) {
directory->details->use_alternate_metafile = TRUE;
} else {
result = nautilus_directory_try_to_read_metafile (directory, directory->details->metafile_uri);
}
}
static void
nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory)
{
if (directory->details->write_metafile_idle_id != 0) {
gtk_idle_remove (directory->details->write_metafile_idle_id);
directory->details->write_metafile_idle_id = 0;
result = nautilus_directory_try_to_read_metafile (directory,
directory->details->metafile_uri);
}
}
@ -355,35 +352,45 @@ nautilus_directory_write_metafile (NautilusDirectory *directory)
g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
gtk_object_ref (GTK_OBJECT (directory));
/* We are about the write the metafile, so we can cancel the pending
request to do so.
*/
nautilus_directory_remove_write_metafile_idle (directory);
if (directory->details->write_metafile_idle_id != 0) {
gtk_idle_remove (directory->details->write_metafile_idle_id);
directory->details->write_metafile_idle_id = 0;
gtk_object_unref (GTK_OBJECT (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;
if (directory->details->metafile_tree != NULL) {
/* Try the main URI, unless we have already been instructed to use the alternate URI. */
if (directory->details->use_alternate_metafile) {
result = GNOME_VFS_ERROR_ACCESSDENIED;
} else {
result = nautilus_directory_try_to_write_metafile (directory,
directory->details->metafile_uri);
}
/* Try the alternate URI if the main one failed. */
if (result != GNOME_VFS_OK) {
result = nautilus_directory_try_to_write_metafile (directory,
directory->details->alternate_metafile_uri);
}
/* Check for errors. FIXME: Later this must be reported to the user, not spit out as a warning. */
if (result != GNOME_VFS_OK) {
g_warning ("nautilus_directory_write_metafile failed to write metafile - we should report this to the user");
}
}
/* Try the main URI, unless we have already been instructed to use the alternate URI. */
if (directory->details->use_alternate_metafile) {
result = GNOME_VFS_ERROR_ACCESSDENIED;
} else {
result = nautilus_directory_try_to_write_metafile (directory, directory->details->metafile_uri);
}
/* Try the alternate URI if the main one failed. */
if (result != GNOME_VFS_OK) {
result = nautilus_directory_try_to_write_metafile (directory, directory->details->alternate_metafile_uri);
}
/* Check for errors. FIXME: Later this must be reported to the user, not spit out as a warning. */
if (result != GNOME_VFS_OK) {
g_warning ("nautilus_directory_write_metafile failed to write metafile - we should report this to the user");
}
gtk_object_unref (GTK_OBJECT (directory));
}
static gboolean
@ -396,6 +403,8 @@ nautilus_directory_write_metafile_idle_cb (gpointer callback_data)
directory->details->write_metafile_idle_id = 0;
nautilus_directory_write_metafile (directory);
gtk_object_unref (GTK_OBJECT (directory));
return FALSE;
}
@ -404,6 +413,7 @@ nautilus_directory_request_write_metafile (NautilusDirectory *directory)
{
/* Set up an idle task that will write the metafile. */
if (directory->details->write_metafile_idle_id == 0) {
gtk_object_ref (GTK_OBJECT (directory));
directory->details->write_metafile_idle_id =
gtk_idle_add (nautilus_directory_write_metafile_idle_cb,
directory);
@ -1056,6 +1066,27 @@ nautilus_directory_set_file_metadata (NautilusDirectory *directory,
nautilus_directory_request_write_metafile (directory);
}
static int
compare_file_with_name (gconstpointer a, gconstpointer b)
{
return strcmp (((const NautilusFile *) a)->info->name, b);
}
NautilusFile *
nautilus_directory_find_file (NautilusDirectory *directory, const char *name)
{
GList *list_entry;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
g_return_val_if_fail (name != NULL, NULL);
list_entry = g_list_find_custom (directory->details->files,
(gpointer) name,
compare_file_with_name);
return list_entry == NULL ? NULL : list_entry->data;
}
NautilusFile *
nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *info)
{
@ -1138,28 +1169,40 @@ nautilus_self_check_directory (void)
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (NULL, "TEST_INTEGER", 42), 42);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_directory_get_integer_metadata (directory, "NONEXISTENT_KEY", 42), 42);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc/") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_directory_get ("file:///etc////") == directory, TRUE);
gtk_object_unref (GTK_OBJECT (directory));
gtk_object_unref (GTK_OBJECT (directory));
/* let the idle function run */
while (gtk_events_pending ()) {
gtk_main_iteration ();
}
NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directory_objects), 0);
directory = nautilus_directory_get ("file:///etc");
NAUTILUS_CHECK_BOOLEAN_RESULT (directory->details->metafile_tree != NULL, TRUE);
NAUTILUS_CHECK_INTEGER_RESULT (g_hash_table_size (directory_objects), 1);
NAUTILUS_CHECK_STRING_RESULT (nautilus_directory_get_metadata (directory, "TEST", "default"), "value");
/* 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");
file_1 = nautilus_file_get ("file:///home/");
NAUTILUS_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "home");
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get ("file:///home/") == file_1, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_file_get ("file:///home") == file_1, TRUE);
nautilus_file_unref (file_1);
nautilus_file_unref (file_1);
file_1 = nautilus_file_get ("file:///home");
@ -1179,6 +1222,16 @@ nautilus_self_check_directory (void)
nautilus_file_unref (file_1);
nautilus_file_unref (file_2);
/* 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 */

View file

@ -83,19 +83,22 @@ nautilus_file_get (const char *uri)
GNOME_VFS_FILE_INFO_GETMIMETYPE
| GNOME_VFS_FILE_INFO_FASTMIMETYPE
| GNOME_VFS_FILE_INFO_FOLLOWLINKS, NULL);
if (result != GNOME_VFS_OK)
if (result != GNOME_VFS_OK) {
return NULL;
}
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL)
if (vfs_uri == NULL) {
return NULL;
}
/* Make VFS version of directory URI. */
directory_vfs_uri = gnome_vfs_uri_get_parent (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
if (directory_vfs_uri == NULL)
if (directory_vfs_uri == NULL) {
return NULL;
}
/* Make text version of directory URI. */
directory_uri = gnome_vfs_uri_to_string (directory_vfs_uri,
@ -105,10 +108,16 @@ nautilus_file_get (const char *uri)
/* Get object that represents the directory. */
directory = nautilus_directory_get (directory_uri);
g_free (directory_uri);
if (directory == NULL)
if (directory == NULL) {
return NULL;
}
file = nautilus_directory_new_file (directory, file_info);
file = nautilus_directory_find_file (directory, file_info->name);
if (file == NULL) {
file = nautilus_directory_new_file (directory, file_info);
directory->details->files =
g_list_append (directory->details->files, file);
}
gnome_vfs_file_info_unref (file_info);
nautilus_file_ref (file);
@ -176,14 +185,17 @@ nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFi
is_directory_1 = nautilus_file_is_directory (file_1);
is_directory_2 = nautilus_file_is_directory (file_2);
if (is_directory_1 && !is_directory_2)
if (is_directory_1 && !is_directory_2) {
return -1;
}
if (is_directory_2 && !is_directory_1)
if (is_directory_2 && !is_directory_1) {
return +1;
}
if (!is_directory_1 && !is_directory_2)
if (!is_directory_1 && !is_directory_2) {
return 0;
}
/* Both are directories, compare by item count. */
/* FIXME: get_directory_item_count_hack is slow, and calling
@ -195,11 +207,13 @@ nautilus_file_compare_by_size_with_directories (NautilusFile *file_1, NautilusFi
item_count_1 = get_directory_item_count_hack (file_1, FALSE);
item_count_2 = get_directory_item_count_hack (file_2, FALSE);
if (item_count_1 < item_count_2)
if (item_count_1 < item_count_2) {
return -1;
}
if (item_count_2 < item_count_1)
if (item_count_2 < item_count_1) {
return +1;
}
return 0;
}
@ -221,17 +235,21 @@ nautilus_file_compare_by_type (NautilusFile *file_1, NautilusFile *file_2)
is_directory_1 = nautilus_file_is_directory (file_1);
is_directory_2 = nautilus_file_is_directory (file_2);
if (is_directory_1 && is_directory_2)
if (is_directory_1 && is_directory_2) {
return 0;
}
if (is_directory_1)
if (is_directory_1) {
return -1;
}
if (is_directory_2)
if (is_directory_2) {
return +1;
}
if (nautilus_strcmp (file_1->info->mime_type, file_2->info->mime_type) == 0)
if (nautilus_strcmp (file_1->info->mime_type, file_2->info->mime_type) == 0) {
return 0;
}
type_string_1 = nautilus_file_get_type_as_string (file_1);
type_string_2 = nautilus_file_get_type_as_string (file_2);
@ -300,14 +318,15 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
return 0;
}
if (reversed)
if (reversed) {
return gnome_vfs_file_info_compare_for_sort_reversed (file_1->info,
file_2->info,
rules);
else
} else {
return gnome_vfs_file_info_compare_for_sort (file_1->info,
file_2->info,
rules);
}
}
/**
@ -460,23 +479,16 @@ nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type
* internationalization's sake.
*/
if (file_date_age == 0)
{
if (file_date_age == 0) {
/* today, use special word */
format = _("today %-I:%M %p");
}
else if (file_date_age == 1)
{
} else if (file_date_age == 1) {
/* yesterday, use special word */
format = _("yesterday %-I:%M %p");
}
else if (file_date_age < 7)
{
} else if (file_date_age < 7) {
/* current week, include day of week */
format = _("%A %-m/%-d/%y %-I:%M %p");
}
else
{
} else {
format = _("%-m/%-d/%y %-I:%M %p");
}
@ -578,8 +590,7 @@ nautilus_file_get_owner_as_string (NautilusFile *file)
g_print ("pointer to password info is %p\n", password_info);
if (password_info == NULL)
{
if (password_info == NULL) {
return g_strdup (_("unknown owner"));
}
@ -607,8 +618,7 @@ nautilus_file_get_group_as_string (NautilusFile *file)
/* No need to free result of getgrgid */
group_info = getgrgid (file->info->gid);
if (group_info == NULL)
{
if (group_info == NULL) {
return g_strdup (_("unknown group"));
}
@ -633,24 +643,28 @@ get_directory_item_count_hack (NautilusFile *file, gboolean ignore_invisible_ite
g_assert (nautilus_file_is_directory (file));
uri = nautilus_file_get_uri (file);
if (nautilus_has_prefix (uri, "file://"))
if (nautilus_str_has_prefix (uri, "file://")) {
path = uri + 7;
else
} else {
path = uri;
}
directory = opendir (path);
g_free (uri);
if (!directory)
if (!directory) {
return 0;
}
count = 0;
while ((entry = readdir(directory)) != NULL)
while ((entry = readdir(directory)) != NULL) {
// Only count invisible items if requested.
if (!ignore_invisible_items || entry->d_name[0] != '.')
if (!ignore_invisible_items || entry->d_name[0] != '.') {
count += 1;
}
}
closedir(directory);
@ -678,8 +692,7 @@ nautilus_file_get_size_as_string (NautilusFile *file)
{
g_return_val_if_fail (file != NULL, NULL);
if (nautilus_file_is_directory (file))
{
if (nautilus_file_is_directory (file)) {
/* FIXME: Since computing the item count is slow, we
* want to do it in a deferred way. However, that
* architecture doesn't exist yet, so we're hacking

View file

@ -610,7 +610,7 @@ nautilus_icon_factory_get_icon_for_file (NautilusFile *file)
or use a thumbnail if one exists. If a thumbnail is required, but does not yet exist,
put an entry on the thumbnail queue so we eventually make one */
if (uri == NULL && nautilus_has_prefix (nautilus_file_get_mime_type (file), "image/")) {
if (uri == NULL && nautilus_str_has_prefix (nautilus_file_get_mime_type (file), "image/")) {
if (nautilus_file_get_size (file) < SELF_THUMBNAIL_SIZE_THRESHOLD)
uri = nautilus_file_get_uri (file);
else
@ -686,7 +686,8 @@ make_thumbnail_path (const char *image_uri, gboolean directory_only)
if (directory_only)
thumbnail_uri = g_strdup_printf ("%s/.thumbnails", temp_str);
else {
if (nautilus_has_suffix (image_uri, ".png") || nautilus_has_suffix (image_uri, ".PNG")) {
if (nautilus_str_has_suffix (image_uri, ".png")
|| nautilus_str_has_suffix (image_uri, ".PNG")) {
thumbnail_uri = g_strdup_printf ("%s/.thumbnails/%s", temp_str, last_slash + 1);
} else {
thumbnail_uri = g_strdup_printf ("%s/.thumbnails/%s.png", temp_str, last_slash + 1);
@ -869,7 +870,7 @@ load_specific_image (NautilusScalableIcon *scalable_icon,
* and gdk-pixbuf.
*/
if (size_in_pixels == NAUTILUS_ICON_SIZE_STANDARD
&& nautilus_has_prefix (scalable_icon->uri, "file://")) {
&& nautilus_str_has_prefix (scalable_icon->uri, "file://")) {
return gdk_pixbuf_new_from_file (scalable_icon->uri + 7);
}

View file

@ -601,7 +601,7 @@ draw_mini_text (GnomeCanvasItem* item, GdkDrawable *drawable,
/* FIXME: need to use gnome_vfs to read the file */
file_name = details->text_source;
if (nautilus_has_prefix (details->text_source, "file://")) {
if (nautilus_str_has_prefix (details->text_source, "file://")) {
file_name += 7;
}
text_file = fopen(file_name, "r");

View file

@ -39,13 +39,13 @@ void nautilus_run_lib_self_checks (void);
*/
#define NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
macro (nautilus_self_check_string) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gdk_extensions) \
macro (nautilus_self_check_background) \
macro (nautilus_self_check_directory) \
macro (nautilus_self_check_gdk_extensions) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gnome_icon_container) \
macro (nautilus_self_check_icon_factory) \
macro (nautilus_self_check_string) \
/* Add new self-check functions to the list above this line. */
/* Generate prototypes for all the functions. */

View file

@ -32,22 +32,22 @@
#include "nautilus-lib-self-check-functions.h"
size_t
nautilus_strlen (const char *string_null_allowed)
nautilus_strlen (const char *string)
{
return string_null_allowed == NULL ? 0 : strlen (string_null_allowed);
return string == NULL ? 0 : strlen (string);
}
char *
nautilus_strchr (const char *haystack_null_allowed, char needle)
nautilus_strchr (const char *haystack, char needle)
{
return haystack_null_allowed == NULL ? NULL : strchr (haystack_null_allowed, needle);
return haystack == NULL ? NULL : strchr (haystack, needle);
}
int
nautilus_strcmp (const char *string_a_null_allowed, const char *string_b_null_allowed)
nautilus_strcmp (const char *string_a, const char *string_b)
{
return strcmp (string_a_null_allowed == NULL ? "" : string_a_null_allowed,
string_b_null_allowed == NULL ? "" : string_b_null_allowed);
return strcmp (string_a == NULL ? "" : string_a,
string_b == NULL ? "" : string_b);
}
int
@ -61,13 +61,13 @@ nautilus_eat_strcmp (char *string_a, const char *string_b)
}
gboolean
nautilus_has_prefix (const char *haystack_null_allowed, const char *needle_null_allowed)
nautilus_str_has_prefix (const char *haystack, const char *needle)
{
const char *h, *n;
/* Eat one character at a time. */
h = haystack_null_allowed == NULL ? "" : haystack_null_allowed;
n = needle_null_allowed == NULL ? "" : needle_null_allowed;
h = haystack == NULL ? "" : haystack;
n = needle == NULL ? "" : needle;
do {
if (*n == '\0') {
return TRUE;
@ -80,25 +80,25 @@ nautilus_has_prefix (const char *haystack_null_allowed, const char *needle_null_
}
gboolean
nautilus_has_suffix (const char *haystack_null_allowed, const char *needle_null_allowed)
nautilus_str_has_suffix (const char *haystack, const char *needle)
{
const char *h, *n;
if (needle_null_allowed == NULL) {
if (needle == NULL) {
return TRUE;
}
if (haystack_null_allowed == NULL) {
return needle_null_allowed[0] == '\0';
if (haystack == NULL) {
return needle[0] == '\0';
}
/* Eat one character at a time. */
h = haystack_null_allowed + strlen(haystack_null_allowed);
n = needle_null_allowed + strlen(needle_null_allowed);
h = haystack + strlen(haystack);
n = needle + strlen(needle);
do {
if (n == needle_null_allowed) {
if (n == needle) {
return TRUE;
}
if (h == haystack_null_allowed) {
if (h == haystack) {
return FALSE;
}
} while (*--h == *--n);
@ -107,44 +107,44 @@ nautilus_has_suffix (const char *haystack_null_allowed, const char *needle_null_
/**
* nautilus_strdup_prefix:
* nautilus_str_get_prefix:
* Get a new string containing the first part of an existing string.
*
* @source_null_allowed: The string whose prefix should be extracted.
* @delimiter_null_allowed: The string that marks the end of the prefix.
* @source: The string whose prefix should be extracted.
* @delimiter: The string that marks the end of the prefix.
*
* Return value: A newly-allocated string that that matches the first part
* of @source_null_allowed, up to but not including the first occurrence of
* @delimiter_null_allowed. If @source_null_allowed is NULL, returns NULL. If
* @delimiter_null_allowed is NULL, returns a copy of @source_null_allowed.
* If @delimiter_null_allowed does not occur in @source_null_allowed, returns
* a copy of @source_null_allowed.
* of @source, up to but not including the first occurrence of
* @delimiter. If @source is NULL, returns NULL. If
* @delimiter is NULL, returns a copy of @source.
* If @delimiter does not occur in @source, returns
* a copy of @source.
**/
char *
nautilus_strdup_prefix (const char *source_null_allowed,
const char *delimiter_null_allowed)
nautilus_str_get_prefix (const char *source,
const char *delimiter)
{
char *prefix_start;
if (source_null_allowed == NULL) {
if (source == NULL) {
return NULL;
}
if (delimiter_null_allowed == NULL) {
return g_strdup (source_null_allowed);
if (delimiter == NULL) {
return g_strdup (source);
}
prefix_start = strstr (source_null_allowed, delimiter_null_allowed);
prefix_start = strstr (source, delimiter);
if (prefix_start == NULL) {
return NULL;
}
return g_strndup (source_null_allowed, prefix_start - source_null_allowed);
return g_strndup (source, prefix_start - source);
}
gboolean
nautilus_string_to_int (const char *string, int *integer)
nautilus_str_to_int (const char *string, int *integer)
{
long result;
char *parse_end;
@ -179,63 +179,94 @@ nautilus_string_to_int (const char *string, int *integer)
}
/**
* nautilus_strstrip:
* Remove all occurrences of a character from a string. The
* original string is modified in place, and also returned for convenience.
* nautilus_str_strip_chr:
* Remove all occurrences of a character from a string.
*
* @string_null_allowed: The string to be stripped.
* @remove_this: The char to remove from @string_null_allowed
* @source: The string to be stripped.
* @remove_this: The char to remove from @source
*
* Return value: @string_null_allowed, after removing all occurrences
* Return value: A copy of @source, after removing all occurrences
* of @remove_this.
*/
char *
nautilus_strstrip (char *string_null_allowed, char remove_this)
nautilus_str_strip_chr (const char *source, char remove_this)
{
if (string_null_allowed != NULL) {
char *in, *out;
char *result, *out;
const char *in;
if (source == NULL) {
return NULL;
}
result = g_malloc (strlen (source) + 1);
in = source;
out = result;
do {
if (*in != remove_this) {
*out++ = *in;
}
} while (*in++ != '\0');
in = string_null_allowed;
out = string_null_allowed;
do {
if (*in != remove_this) {
*out++ = *in;
}
} while (*in++ != '\0');
}
return result;
}
return string_null_allowed;
/**
* nautilus_str_strip_trailing_chr:
* Remove trailing occurrences of a character from a string.
*
* @source: The string to be stripped.
* @remove_this: The char to remove from @source
*
* Return value: @source, after removing trailing occurrences
* of @remove_this.
*/
char *
nautilus_str_strip_trailing_chr (const char *source, char remove_this)
{
const char *end;
if (source == NULL) {
return NULL;
}
for (end = source + strlen (source); end != source; end--) {
if (end[-1] != remove_this) {
break;
}
}
return g_strndup (source, end - source);
}
gboolean
nautilus_eat_string_to_int (char *string, int *integer)
nautilus_eat_str_to_int (char *source, int *integer)
{
gboolean result;
result = nautilus_string_to_int (string, integer);
g_free (string);
result = nautilus_str_to_int (source, integer);
g_free (source);
return result;
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
static int
call_string_to_int (const char *string)
call_str_to_int (const char *string)
{
int integer;
integer = 9999;
nautilus_string_to_int (string, &integer);
nautilus_str_to_int (string, &integer);
return integer;
}
static int
call_eat_string_to_int (char *string)
call_eat_str_to_int (char *string)
{
int integer;
integer = 9999;
nautilus_eat_string_to_int (string, &integer);
nautilus_eat_str_to_int (string, &integer);
return integer;
}
@ -278,57 +309,64 @@ nautilus_self_check_string (void)
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaa"), "aaab") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaab"), "aaa") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("ab", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaa", "aaab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("ab", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaa", "aaab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_prefix ("aaab", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("ab", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("ab", "b"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("aaa", "baaa"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_suffix ("baaa", "aaa"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("ab", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("ab", "b"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("aaa", "baaa"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_has_suffix ("baaa", "aaa"), TRUE);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix (NULL, NULL), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix (NULL, "foo"), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo", NULL), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo", "foo"), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo:", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("foo:bar", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strdup_prefix ("footle:bar", "tle:"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix (NULL, NULL), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix (NULL, "foo"), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo", NULL), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo", "foo"), "");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo:", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("foo:bar", ":"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_get_prefix ("footle:bar", "tle:"), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("foo"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_foo"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("foo_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_foo_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_strstrip (g_strdup ("_f_o__o_"), '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("foo_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_foo__", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_chr ("_f_o__o_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr (NULL, '_'), NULL);
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("foo", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_foo", '_'), "_foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("foo_", '_'), "foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_foo__", '_'), "_foo");
NAUTILUS_CHECK_STRING_RESULT (nautilus_str_strip_trailing_chr ("_f_o__o_", '_'), "_f_o__o");
#define TEST_INTEGER_CONVERSION_FUNCTIONS(string, boolean_result, integer_result) \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_to_int (string, &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_string_to_int (string), integer_result); \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_string_to_int (g_strdup (string), &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_eat_string_to_int (g_strdup (string)), integer_result);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_str_to_int (string, &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_str_to_int (string), integer_result); \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_str_to_int (g_strdup (string), &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_eat_str_to_int (g_strdup (string)), integer_result);
TEST_INTEGER_CONVERSION_FUNCTIONS (NULL, FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("", FALSE, 9999)

View file

@ -28,33 +28,39 @@
#include <glib.h>
#include <string.h>
/* We use the "str" abbrevation to mean char * string, since
* "string" usually means g_string instead.
*/
/* NULL is allowed for all the str parameters to these functions. */
/* Versions of basic string functions that allow NULL. */
size_t nautilus_strlen (const char *string_null_allowed);
char * nautilus_strchr (const char *haystack_null_allowed,
char needle);
int nautilus_strcmp (const char *string_a_null_allowed,
const char *string_b_null_allowed);
size_t nautilus_strlen (const char *string);
char * nautilus_strchr (const char *haystack,
char needle);
int nautilus_strcmp (const char *string_a,
const char *string_b);
/* Versions of basic string functions that free their parameters. */
int nautilus_eat_strcmp (char *string_a_null_allowed_gets_freed,
const char *string_b_null_allowed);
int nautilus_eat_strcmp (char *string_a_gets_freed,
const char *string_b);
/* Other basic string operations. */
gboolean nautilus_has_prefix (const char *target_null_allowed,
const char *prefix_null_allowed);
char * nautilus_strdup_prefix (const char *source_null_allowed,
const char *delimiter_null_allowed);
gboolean nautilus_has_suffix (const char *target_null_allowed,
const char *suffix_null_allowed);
char * nautilus_strstrip (char *string_null_allowed,
char remove_this);
gboolean nautilus_str_has_prefix (const char *target,
const char *prefix);
char * nautilus_str_get_prefix (const char *source,
const char *delimiter);
gboolean nautilus_str_has_suffix (const char *target,
const char *suffix);
char * nautilus_str_strip_chr (const char *string,
char remove_this);
char * nautilus_str_strip_trailing_chr (const char *string,
char remove_this);
/* Conversions to and from strings. */
gboolean nautilus_string_to_int (const char *string,
int *integer);
gboolean nautilus_eat_string_to_int (char *string_gets_freed,
int *integer);
gboolean nautilus_str_to_int (const char *string,
int *integer);
gboolean nautilus_eat_str_to_int (char *string_gets_freed,
int *integer);
#endif /* NAUTILUS_STRING_H */

View file

@ -351,13 +351,14 @@ fm_directory_view_icons_compute_menu_item_info (FMDirectoryViewIcons *view,
gboolean *sensitive_return)
{
GnomeIconContainer *icon_container;
char *name, *stripped;
g_assert (FM_IS_DIRECTORY_VIEW_ICONS (view));
icon_container = get_icon_container (view);
if (strcmp (MENU_PATH_STRETCH_ICON, menu_path) == 0) {
*return_name = g_strdup (_("_Stretch Icon"));
name = g_strdup (_("_Stretch Icon"));
/* Current stretching UI only works on one item at a time, so we'll
* desensitize the menu item if that's not the case.
*/
@ -365,23 +366,27 @@ fm_directory_view_icons_compute_menu_item_info (FMDirectoryViewIcons *view,
&& !gnome_icon_container_has_stretch_handles (icon_container);
} else if (strcmp (MENU_PATH_RESTORE_STRETCHED_ICONS, menu_path) == 0) {
if (g_list_length (files) > 1) {
*return_name = g_strdup (_("_Restore Icons to Unstretched Size"));
name = g_strdup (_("_Restore Icons to Unstretched Size"));
} else {
*return_name = g_strdup (_("_Restore Icon to Unstretched Size"));
name = g_strdup (_("_Restore Icon to Unstretched Size"));
}
*sensitive_return = gnome_icon_container_is_stretched (icon_container);
} else if (strcmp (MENU_PATH_CUSTOMIZE_ICON_TEXT, menu_path) == 0) {
*return_name = g_strdup (_("Customize _Icon Text..."));
name = g_strdup (_("Customize _Icon Text..."));
*sensitive_return = TRUE;
} else {
g_assert_not_reached ();
}
if (!include_accelerator_underbars) {
nautilus_strstrip (*return_name, '_');
stripped = nautilus_str_strip_chr (name, '_');
g_free (name);
name = stripped;
}
*return_name = name;
}
static void

View file

@ -1210,29 +1210,35 @@ compute_menu_item_info (const char *path,
char **return_name,
gboolean *return_sensitivity)
{
char *name, *stripped;
if (strcmp (path, MENU_PATH_OPEN) == 0) {
*return_name = g_strdup_printf (_("_Open"));
name = g_strdup_printf (_("_Open"));
*return_sensitivity = selection_length == 1;
} else if (strcmp (path, MENU_PATH_OPEN_IN_NEW_WINDOW) == 0) {
if (selection_length <= 1) {
*return_name = g_strdup (_("Open in _New Window"));
name = g_strdup (_("Open in _New Window"));
} else {
*return_name = g_strdup_printf (_("Open in %d _New Windows"), selection_length);
name = g_strdup_printf (_("Open in %d _New Windows"), selection_length);
}
*return_sensitivity = selection_length > 0;
} else if (strcmp (path, MENU_PATH_DELETE) == 0) {
*return_name = g_strdup (_("_Delete..."));
name = g_strdup (_("_Delete..."));
*return_sensitivity = selection_length > 0;
} else if (strcmp (path, MENU_PATH_SET_PROPERTIES) == 0) {
*return_name = g_strdup (_("Set _Properties..."));
name = g_strdup (_("Set _Properties..."));
*return_sensitivity = selection_length > 0;
} else {
g_assert_not_reached ();
}
if (!include_accelerator_underbars) {
nautilus_strstrip (*return_name, '_');
if (!include_accelerator_underbars) {
stripped = nautilus_str_strip_chr (name, '_');
g_free (name);
name = stripped;
}
*return_name = name;
}
static void

View file

@ -108,11 +108,11 @@ fm_icons_controller_get_icon_property (NautilusIconsController *controller,
* the theme name starting with eazel.
*/
theme_name = nautilus_icon_factory_get_theme ();
use_text = nautilus_has_prefix (theme_name, "eazel");
use_text = nautilus_str_has_prefix (theme_name, "eazel");
g_free (theme_name);
mime_type = nautilus_file_get_mime_type (NAUTILUS_FILE (icon));
if (use_text && (mime_type == NULL || nautilus_has_prefix (mime_type, "text/"))) {
if (use_text && (mime_type == NULL || nautilus_str_has_prefix (mime_type, "text/"))) {
return nautilus_file_get_uri (NAUTILUS_FILE (icon));
}
}

View file

@ -25,14 +25,11 @@
*/
#include <config.h>
#include <math.h>
#include "ntl-index-panel.h"
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include "libnautilus/nautilus-mime-type.h"
#include <math.h>
#include <gnome.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
@ -42,7 +39,11 @@
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-metadata.h>
#include <libnautilus/nautilus-string.h>
#include <gnome.h>
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include <libnautilus/nautilus-mime-type.h>
struct _NautilusIndexPanelDetails {
GtkWidget *index_container;
@ -53,7 +54,7 @@ struct _NautilusIndexPanelDetails {
GtkWidget *button_box;
gboolean has_buttons;
char *uri;
gint selected_index;
int selected_index;
NautilusDirectory *directory;
int background_connection;
};
@ -67,7 +68,7 @@ static void nautilus_index_panel_destroy (GtkObject *object);
static void nautilus_index_panel_finalize (GtkObject *object);
static void nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data,
guint info, guint time);
@ -217,7 +218,7 @@ nautilus_index_panel_new (void)
static void
nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data, guint info, guint time)
{
NautilusIndexPanel *index_panel;
@ -277,7 +278,7 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie
GtkWidget *label;
const char *description;
char cbuf[32];
gint page_num;
int page_num;
g_return_if_fail (NAUTILUS_IS_INDEX_PANEL (index_panel));
g_return_if_fail (NAUTILUS_IS_META_VIEW (meta_view));
@ -305,7 +306,7 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie
void
nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, NautilusView *meta_view)
{
gint page_num;
int page_num;
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view));
g_return_if_fail (page_num >= 0);
@ -314,7 +315,7 @@ nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nautilus
/* utility to activate the metaview corresponding to the passed in index */
static void
nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, gint which_view)
nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, int which_view)
{
char *title;
GtkNotebook *notebook = GTK_NOTEBOOK(index_panel->details->notebook);
@ -359,7 +360,7 @@ nautilus_index_panel_deactivate_meta_view(NautilusIndexPanel *index_panel)
static gboolean
nautilus_index_panel_motion_event (GtkWidget *widget, GdkEventMotion *event)
{
gint x, y;
int x, y;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL (widget);
NautilusIndexTabs *index_tabs = NAUTILUS_INDEX_TABS(index_panel->details->index_tabs);
@ -367,16 +368,16 @@ nautilus_index_panel_motion_event (GtkWidget *widget, GdkEventMotion *event)
/* if the click is in the main tabs, tell them about it */
if (y >= index_panel->details->index_tabs->allocation.y) {
gint which_tab = nautilus_index_tabs_hit_test(index_tabs, (double) x, (double) y);
int which_tab = nautilus_index_tabs_hit_test(index_tabs, (double) x, (double) y);
nautilus_index_tabs_prelite_tab(index_tabs, which_tab);
}
/* also handle prelighting in the title tab if necessary */
if (index_panel->details->selected_index >= 0) {
gint title_top = index_panel->details->title_tab->allocation.y;
gint title_bottom = title_top + index_panel->details->title_tab->allocation.height;
int title_top = index_panel->details->title_tab->allocation.y;
int title_bottom = title_top + index_panel->details->title_tab->allocation.height;
if ((y >= title_top) && (y <= title_bottom)) {
gint which_tab = nautilus_index_tabs_hit_test(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), (double) x, (double) y);
int which_tab = nautilus_index_tabs_hit_test(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), (double) x, (double) y);
nautilus_index_tabs_prelite_tab(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), which_tab);
}
else
@ -408,15 +409,15 @@ nautilus_index_panel_leave_event (GtkWidget *widget, GdkEventCrossing *event)
static gboolean
nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
{
gint title_top, title_bottom;
int title_top, title_bottom;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL (widget);
NautilusIndexTabs *index_tabs = NAUTILUS_INDEX_TABS(index_panel->details->index_tabs);
NautilusIndexTabs *title_tab = NAUTILUS_INDEX_TABS(index_panel->details->title_tab);
gint rounded_y = floor(event->y + .5);
int rounded_y = floor(event->y + .5);
/* if the click is in the main tabs, tell them about it */
if (rounded_y >= index_panel->details->index_tabs->allocation.y) {
gint which_tab = nautilus_index_tabs_hit_test(index_tabs, event->x, event->y);
int which_tab = nautilus_index_tabs_hit_test(index_tabs, event->x, event->y);
if (which_tab >= 0) {
nautilus_index_tabs_select_tab(index_tabs, which_tab);
nautilus_index_panel_activate_meta_view(index_panel, which_tab);
@ -429,7 +430,7 @@ nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
title_top = index_panel->details->title_tab->allocation.y;
title_bottom = title_top + index_panel->details->title_tab->allocation.height;
if ((rounded_y >= title_top) && (rounded_y <= title_bottom)) {
gint which_tab = nautilus_index_tabs_hit_test(title_tab, event->x, event->y);
int which_tab = nautilus_index_tabs_hit_test(title_tab, event->x, event->y);
if (which_tab >= 0) {
/* the user clicked in the title tab, so deactivate the metaview */
nautilus_index_panel_deactivate_meta_view(index_panel);
@ -461,19 +462,24 @@ nautilus_index_panel_background_changed (NautilusIndexPanel *index_panel)
/* utility to fork a process to actually execute the button command */
static void
command_button_cb(GtkWidget *button, gchar* command_str)
command_button_cb (GtkWidget *button, char* command_str)
{
pid_t button_pid;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL(gtk_object_get_user_data(GTK_OBJECT(button)));
gchar *parameter_ptr = index_panel->details->uri;
if (nautilus_has_prefix(index_panel->details->uri, "file://"))
parameter_ptr += 7;
if (!(button_pid = fork())) {
execlp(command_str, command_str, parameter_ptr, NULL);
exit(0);
}
pid_t button_pid;
NautilusIndexPanel *index_panel;
char *parameter_ptr;
index_panel = NAUTILUS_INDEX_PANEL (gtk_object_get_user_data (GTK_OBJECT (button)));
parameter_ptr = index_panel->details->uri;
if (nautilus_str_has_prefix (parameter_ptr, "file://")) {
parameter_ptr += 7;
}
button_pid = fork();
if (button_pid == 0) {
execlp(command_str, command_str, parameter_ptr, NULL);
exit(0);
}
}
/* utility routine that allocates the command buttons from the command list */
@ -481,7 +487,7 @@ command_button_cb(GtkWidget *button, gchar* command_str)
static void
add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list)
{
gchar *command_string, *temp_str;
char *command_string, *temp_str;
GList *this_item = command_list;
GtkWidget *temp_button, *temp_label;
@ -501,10 +507,11 @@ add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list)
/* FIXME: we must quote the uri in case it has blanks */
if (nautilus_has_prefix(index_panel->details->uri, "file://"))
temp_str = index_panel->details->uri + 7;
else
temp_str = index_panel->details->uri;
if (nautilus_str_has_prefix (index_panel->details->uri, "file://")) {
temp_str = index_panel->details->uri + 7;
} else {
temp_str = index_panel->details->uri;
}
command_string = g_strdup_printf(info->command_string, temp_str);
gtk_signal_connect(GTK_OBJECT (temp_button), "clicked", GTK_SIGNAL_FUNC (command_button_cb), command_string);
@ -535,7 +542,7 @@ nautilus_index_panel_set_up_buttons (NautilusIndexPanel *index_panel, const char
file_object = nautilus_file_get(new_uri);
if (file_object) {
const gchar* mime_type = nautilus_file_get_mime_type(file_object);
const char* mime_type = nautilus_file_get_mime_type(file_object);
/* generate a command list from the mime-type */
if (mime_type) {

View file

@ -25,14 +25,11 @@
*/
#include <config.h>
#include <math.h>
#include "ntl-index-panel.h"
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include "libnautilus/nautilus-mime-type.h"
#include <math.h>
#include <gnome.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
@ -42,7 +39,11 @@
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-metadata.h>
#include <libnautilus/nautilus-string.h>
#include <gnome.h>
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include <libnautilus/nautilus-mime-type.h>
struct _NautilusIndexPanelDetails {
GtkWidget *index_container;
@ -53,7 +54,7 @@ struct _NautilusIndexPanelDetails {
GtkWidget *button_box;
gboolean has_buttons;
char *uri;
gint selected_index;
int selected_index;
NautilusDirectory *directory;
int background_connection;
};
@ -67,7 +68,7 @@ static void nautilus_index_panel_destroy (GtkObject *object);
static void nautilus_index_panel_finalize (GtkObject *object);
static void nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data,
guint info, guint time);
@ -217,7 +218,7 @@ nautilus_index_panel_new (void)
static void
nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data, guint info, guint time)
{
NautilusIndexPanel *index_panel;
@ -277,7 +278,7 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie
GtkWidget *label;
const char *description;
char cbuf[32];
gint page_num;
int page_num;
g_return_if_fail (NAUTILUS_IS_INDEX_PANEL (index_panel));
g_return_if_fail (NAUTILUS_IS_META_VIEW (meta_view));
@ -305,7 +306,7 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie
void
nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, NautilusView *meta_view)
{
gint page_num;
int page_num;
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view));
g_return_if_fail (page_num >= 0);
@ -314,7 +315,7 @@ nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nautilus
/* utility to activate the metaview corresponding to the passed in index */
static void
nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, gint which_view)
nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, int which_view)
{
char *title;
GtkNotebook *notebook = GTK_NOTEBOOK(index_panel->details->notebook);
@ -359,7 +360,7 @@ nautilus_index_panel_deactivate_meta_view(NautilusIndexPanel *index_panel)
static gboolean
nautilus_index_panel_motion_event (GtkWidget *widget, GdkEventMotion *event)
{
gint x, y;
int x, y;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL (widget);
NautilusIndexTabs *index_tabs = NAUTILUS_INDEX_TABS(index_panel->details->index_tabs);
@ -367,16 +368,16 @@ nautilus_index_panel_motion_event (GtkWidget *widget, GdkEventMotion *event)
/* if the click is in the main tabs, tell them about it */
if (y >= index_panel->details->index_tabs->allocation.y) {
gint which_tab = nautilus_index_tabs_hit_test(index_tabs, (double) x, (double) y);
int which_tab = nautilus_index_tabs_hit_test(index_tabs, (double) x, (double) y);
nautilus_index_tabs_prelite_tab(index_tabs, which_tab);
}
/* also handle prelighting in the title tab if necessary */
if (index_panel->details->selected_index >= 0) {
gint title_top = index_panel->details->title_tab->allocation.y;
gint title_bottom = title_top + index_panel->details->title_tab->allocation.height;
int title_top = index_panel->details->title_tab->allocation.y;
int title_bottom = title_top + index_panel->details->title_tab->allocation.height;
if ((y >= title_top) && (y <= title_bottom)) {
gint which_tab = nautilus_index_tabs_hit_test(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), (double) x, (double) y);
int which_tab = nautilus_index_tabs_hit_test(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), (double) x, (double) y);
nautilus_index_tabs_prelite_tab(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), which_tab);
}
else
@ -408,15 +409,15 @@ nautilus_index_panel_leave_event (GtkWidget *widget, GdkEventCrossing *event)
static gboolean
nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
{
gint title_top, title_bottom;
int title_top, title_bottom;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL (widget);
NautilusIndexTabs *index_tabs = NAUTILUS_INDEX_TABS(index_panel->details->index_tabs);
NautilusIndexTabs *title_tab = NAUTILUS_INDEX_TABS(index_panel->details->title_tab);
gint rounded_y = floor(event->y + .5);
int rounded_y = floor(event->y + .5);
/* if the click is in the main tabs, tell them about it */
if (rounded_y >= index_panel->details->index_tabs->allocation.y) {
gint which_tab = nautilus_index_tabs_hit_test(index_tabs, event->x, event->y);
int which_tab = nautilus_index_tabs_hit_test(index_tabs, event->x, event->y);
if (which_tab >= 0) {
nautilus_index_tabs_select_tab(index_tabs, which_tab);
nautilus_index_panel_activate_meta_view(index_panel, which_tab);
@ -429,7 +430,7 @@ nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
title_top = index_panel->details->title_tab->allocation.y;
title_bottom = title_top + index_panel->details->title_tab->allocation.height;
if ((rounded_y >= title_top) && (rounded_y <= title_bottom)) {
gint which_tab = nautilus_index_tabs_hit_test(title_tab, event->x, event->y);
int which_tab = nautilus_index_tabs_hit_test(title_tab, event->x, event->y);
if (which_tab >= 0) {
/* the user clicked in the title tab, so deactivate the metaview */
nautilus_index_panel_deactivate_meta_view(index_panel);
@ -461,19 +462,24 @@ nautilus_index_panel_background_changed (NautilusIndexPanel *index_panel)
/* utility to fork a process to actually execute the button command */
static void
command_button_cb(GtkWidget *button, gchar* command_str)
command_button_cb (GtkWidget *button, char* command_str)
{
pid_t button_pid;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL(gtk_object_get_user_data(GTK_OBJECT(button)));
gchar *parameter_ptr = index_panel->details->uri;
if (nautilus_has_prefix(index_panel->details->uri, "file://"))
parameter_ptr += 7;
if (!(button_pid = fork())) {
execlp(command_str, command_str, parameter_ptr, NULL);
exit(0);
}
pid_t button_pid;
NautilusIndexPanel *index_panel;
char *parameter_ptr;
index_panel = NAUTILUS_INDEX_PANEL (gtk_object_get_user_data (GTK_OBJECT (button)));
parameter_ptr = index_panel->details->uri;
if (nautilus_str_has_prefix (parameter_ptr, "file://")) {
parameter_ptr += 7;
}
button_pid = fork();
if (button_pid == 0) {
execlp(command_str, command_str, parameter_ptr, NULL);
exit(0);
}
}
/* utility routine that allocates the command buttons from the command list */
@ -481,7 +487,7 @@ command_button_cb(GtkWidget *button, gchar* command_str)
static void
add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list)
{
gchar *command_string, *temp_str;
char *command_string, *temp_str;
GList *this_item = command_list;
GtkWidget *temp_button, *temp_label;
@ -501,10 +507,11 @@ add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list)
/* FIXME: we must quote the uri in case it has blanks */
if (nautilus_has_prefix(index_panel->details->uri, "file://"))
temp_str = index_panel->details->uri + 7;
else
temp_str = index_panel->details->uri;
if (nautilus_str_has_prefix (index_panel->details->uri, "file://")) {
temp_str = index_panel->details->uri + 7;
} else {
temp_str = index_panel->details->uri;
}
command_string = g_strdup_printf(info->command_string, temp_str);
gtk_signal_connect(GTK_OBJECT (temp_button), "clicked", GTK_SIGNAL_FUNC (command_button_cb), command_string);
@ -535,7 +542,7 @@ nautilus_index_panel_set_up_buttons (NautilusIndexPanel *index_panel, const char
file_object = nautilus_file_get(new_uri);
if (file_object) {
const gchar* mime_type = nautilus_file_get_mime_type(file_object);
const char* mime_type = nautilus_file_get_mime_type(file_object);
/* generate a command list from the mime-type */
if (mime_type) {

View file

@ -953,7 +953,7 @@ nautilus_window_change_location_2(NautilusNavigationInfo *navi, gpointer data)
*/
char * scheme_string;
scheme_string = nautilus_strdup_prefix (requested_uri, ":");
scheme_string = nautilus_str_get_prefix (requested_uri, ":");
g_assert (scheme_string != NULL); /* Shouldn't have gotten this error unless there's a : separator. */
error_message = g_strdup_printf ("Couldn't display \"%s\",\nbecause Nautilus cannot handle %s: locations.", requested_uri, scheme_string);
g_free (scheme_string);

View file

@ -25,14 +25,11 @@
*/
#include <config.h>
#include <math.h>
#include "ntl-index-panel.h"
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include "libnautilus/nautilus-mime-type.h"
#include <math.h>
#include <gnome.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
@ -42,7 +39,11 @@
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-metadata.h>
#include <libnautilus/nautilus-string.h>
#include <gnome.h>
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include <libnautilus/nautilus-mime-type.h>
struct _NautilusIndexPanelDetails {
GtkWidget *index_container;
@ -53,7 +54,7 @@ struct _NautilusIndexPanelDetails {
GtkWidget *button_box;
gboolean has_buttons;
char *uri;
gint selected_index;
int selected_index;
NautilusDirectory *directory;
int background_connection;
};
@ -67,7 +68,7 @@ static void nautilus_index_panel_destroy (GtkObject *object);
static void nautilus_index_panel_finalize (GtkObject *object);
static void nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data,
guint info, guint time);
@ -217,7 +218,7 @@ nautilus_index_panel_new (void)
static void
nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragContext *context,
gint x, gint y,
int x, int y,
GtkSelectionData *selection_data, guint info, guint time)
{
NautilusIndexPanel *index_panel;
@ -277,7 +278,7 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie
GtkWidget *label;
const char *description;
char cbuf[32];
gint page_num;
int page_num;
g_return_if_fail (NAUTILUS_IS_INDEX_PANEL (index_panel));
g_return_if_fail (NAUTILUS_IS_META_VIEW (meta_view));
@ -305,7 +306,7 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie
void
nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, NautilusView *meta_view)
{
gint page_num;
int page_num;
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view));
g_return_if_fail (page_num >= 0);
@ -314,7 +315,7 @@ nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nautilus
/* utility to activate the metaview corresponding to the passed in index */
static void
nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, gint which_view)
nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, int which_view)
{
char *title;
GtkNotebook *notebook = GTK_NOTEBOOK(index_panel->details->notebook);
@ -359,7 +360,7 @@ nautilus_index_panel_deactivate_meta_view(NautilusIndexPanel *index_panel)
static gboolean
nautilus_index_panel_motion_event (GtkWidget *widget, GdkEventMotion *event)
{
gint x, y;
int x, y;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL (widget);
NautilusIndexTabs *index_tabs = NAUTILUS_INDEX_TABS(index_panel->details->index_tabs);
@ -367,16 +368,16 @@ nautilus_index_panel_motion_event (GtkWidget *widget, GdkEventMotion *event)
/* if the click is in the main tabs, tell them about it */
if (y >= index_panel->details->index_tabs->allocation.y) {
gint which_tab = nautilus_index_tabs_hit_test(index_tabs, (double) x, (double) y);
int which_tab = nautilus_index_tabs_hit_test(index_tabs, (double) x, (double) y);
nautilus_index_tabs_prelite_tab(index_tabs, which_tab);
}
/* also handle prelighting in the title tab if necessary */
if (index_panel->details->selected_index >= 0) {
gint title_top = index_panel->details->title_tab->allocation.y;
gint title_bottom = title_top + index_panel->details->title_tab->allocation.height;
int title_top = index_panel->details->title_tab->allocation.y;
int title_bottom = title_top + index_panel->details->title_tab->allocation.height;
if ((y >= title_top) && (y <= title_bottom)) {
gint which_tab = nautilus_index_tabs_hit_test(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), (double) x, (double) y);
int which_tab = nautilus_index_tabs_hit_test(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), (double) x, (double) y);
nautilus_index_tabs_prelite_tab(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), which_tab);
}
else
@ -408,15 +409,15 @@ nautilus_index_panel_leave_event (GtkWidget *widget, GdkEventCrossing *event)
static gboolean
nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
{
gint title_top, title_bottom;
int title_top, title_bottom;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL (widget);
NautilusIndexTabs *index_tabs = NAUTILUS_INDEX_TABS(index_panel->details->index_tabs);
NautilusIndexTabs *title_tab = NAUTILUS_INDEX_TABS(index_panel->details->title_tab);
gint rounded_y = floor(event->y + .5);
int rounded_y = floor(event->y + .5);
/* if the click is in the main tabs, tell them about it */
if (rounded_y >= index_panel->details->index_tabs->allocation.y) {
gint which_tab = nautilus_index_tabs_hit_test(index_tabs, event->x, event->y);
int which_tab = nautilus_index_tabs_hit_test(index_tabs, event->x, event->y);
if (which_tab >= 0) {
nautilus_index_tabs_select_tab(index_tabs, which_tab);
nautilus_index_panel_activate_meta_view(index_panel, which_tab);
@ -429,7 +430,7 @@ nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
title_top = index_panel->details->title_tab->allocation.y;
title_bottom = title_top + index_panel->details->title_tab->allocation.height;
if ((rounded_y >= title_top) && (rounded_y <= title_bottom)) {
gint which_tab = nautilus_index_tabs_hit_test(title_tab, event->x, event->y);
int which_tab = nautilus_index_tabs_hit_test(title_tab, event->x, event->y);
if (which_tab >= 0) {
/* the user clicked in the title tab, so deactivate the metaview */
nautilus_index_panel_deactivate_meta_view(index_panel);
@ -461,19 +462,24 @@ nautilus_index_panel_background_changed (NautilusIndexPanel *index_panel)
/* utility to fork a process to actually execute the button command */
static void
command_button_cb(GtkWidget *button, gchar* command_str)
command_button_cb (GtkWidget *button, char* command_str)
{
pid_t button_pid;
NautilusIndexPanel *index_panel = NAUTILUS_INDEX_PANEL(gtk_object_get_user_data(GTK_OBJECT(button)));
gchar *parameter_ptr = index_panel->details->uri;
if (nautilus_has_prefix(index_panel->details->uri, "file://"))
parameter_ptr += 7;
if (!(button_pid = fork())) {
execlp(command_str, command_str, parameter_ptr, NULL);
exit(0);
}
pid_t button_pid;
NautilusIndexPanel *index_panel;
char *parameter_ptr;
index_panel = NAUTILUS_INDEX_PANEL (gtk_object_get_user_data (GTK_OBJECT (button)));
parameter_ptr = index_panel->details->uri;
if (nautilus_str_has_prefix (parameter_ptr, "file://")) {
parameter_ptr += 7;
}
button_pid = fork();
if (button_pid == 0) {
execlp(command_str, command_str, parameter_ptr, NULL);
exit(0);
}
}
/* utility routine that allocates the command buttons from the command list */
@ -481,7 +487,7 @@ command_button_cb(GtkWidget *button, gchar* command_str)
static void
add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list)
{
gchar *command_string, *temp_str;
char *command_string, *temp_str;
GList *this_item = command_list;
GtkWidget *temp_button, *temp_label;
@ -501,10 +507,11 @@ add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list)
/* FIXME: we must quote the uri in case it has blanks */
if (nautilus_has_prefix(index_panel->details->uri, "file://"))
temp_str = index_panel->details->uri + 7;
else
temp_str = index_panel->details->uri;
if (nautilus_str_has_prefix (index_panel->details->uri, "file://")) {
temp_str = index_panel->details->uri + 7;
} else {
temp_str = index_panel->details->uri;
}
command_string = g_strdup_printf(info->command_string, temp_str);
gtk_signal_connect(GTK_OBJECT (temp_button), "clicked", GTK_SIGNAL_FUNC (command_button_cb), command_string);
@ -535,7 +542,7 @@ nautilus_index_panel_set_up_buttons (NautilusIndexPanel *index_panel, const char
file_object = nautilus_file_get(new_uri);
if (file_object) {
const gchar* mime_type = nautilus_file_get_mime_type(file_object);
const char* mime_type = nautilus_file_get_mime_type(file_object);
/* generate a command list from the mime-type */
if (mime_type) {

View file

@ -953,7 +953,7 @@ nautilus_window_change_location_2(NautilusNavigationInfo *navi, gpointer data)
*/
char * scheme_string;
scheme_string = nautilus_strdup_prefix (requested_uri, ":");
scheme_string = nautilus_str_get_prefix (requested_uri, ":");
g_assert (scheme_string != NULL); /* Shouldn't have gotten this error unless there's a : separator. */
error_message = g_strdup_printf ("Couldn't display \"%s\",\nbecause Nautilus cannot handle %s: locations.", requested_uri, scheme_string);
g_free (scheme_string);