A quick cleanup of how we use gnome-xml.

* libnautilus/Makefile.am:
	* libnautilus/nautilus-xml-extensions.c:
	* libnautilus/nautilus-xml-extensions.h:
	Added some new gnome-xml helper functions.

	* libnautilus/nautilus-directory.c:
	(nautilus_directory_get_file_metadata_node):
	* libnautilus/nautilus-file.c:
	(nautilus_file_get_keywords):
	(nautilus_file_set_keywords):
	* libnautilus/nautilus-icon-factory.c:
	(get_child_node_by_property):
	(get_themed_icon_file_path):
	* src/nautilus-bookmarklist.c:
	(nautilus_bookmarklist_load_file):
	Changed to use the new helper functions.

	* src/nautilus-bookmarklist.c:
	(nautilus_bookmarklist_save_file): Changed direct uses of root to
	use xmlDocGet/SetRootElement while I was editing the file.  I
	think this is the same change Pavel made but wasn't able to check
	in.

	* src/nautilus-bookmarklist.c:
	General cleanup.
This commit is contained in:
Darin Adler 2000-03-15 16:46:51 +00:00
parent bdf3c6c136
commit b84f3f1d7d
20 changed files with 618 additions and 337 deletions

View file

@ -1,3 +1,33 @@
2000-03-15 Darin Adler <darin@eazel.com>
A quick cleanup of how we use gnome-xml.
* libnautilus/Makefile.am:
* libnautilus/nautilus-xml-extensions.c:
* libnautilus/nautilus-xml-extensions.h:
Added some new gnome-xml helper functions.
* libnautilus/nautilus-directory.c:
(nautilus_directory_get_file_metadata_node):
* libnautilus/nautilus-file.c:
(nautilus_file_get_keywords):
(nautilus_file_set_keywords):
* libnautilus/nautilus-icon-factory.c:
(get_child_node_by_property):
(get_themed_icon_file_path):
* src/nautilus-bookmarklist.c:
(nautilus_bookmarklist_load_file):
Changed to use the new helper functions.
* src/nautilus-bookmarklist.c:
(nautilus_bookmarklist_save_file): Changed direct uses of root to
use xmlDocGet/SetRootElement while I was editing the file. I
think this is the same change Pavel made but wasn't able to check
in.
* src/nautilus-bookmarklist.c:
General cleanup.
2000-03-14 Darin Adler <darin@eazel.com>
Added additional data to icons so they can specify where the

View file

@ -51,6 +51,7 @@ libnautilusinclude_HEADERS= \
nautilus-self-checks.h \
nautilus-string-list.h \
nautilus-string.h \
nautilus-xml-extensions.h \
nautilus-zoomable.h \
nautilus.h \
ntl-content-view-frame.h \
@ -85,6 +86,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
nautilus-self-checks.c \
nautilus-string-list.c \
nautilus-string.c \
nautilus-xml-extensions.c \
nautilus-zoomable.c \
ntl-content-view-frame.c \
ntl-meta-view-frame.c \

View file

@ -35,6 +35,7 @@
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
#include "nautilus-xml-extensions.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-file-private.h"
@ -983,34 +984,26 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory,
gboolean create)
{
xmlNode *root, *child;
gboolean match;
xmlChar *property;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
/* The root itself represents the directory. */
root = xmlDocGetRootElement (directory->details->metafile_tree);
if (root != NULL) {
/* The children represent the files.
This linear search is temporary.
Eventually, we'll have a pointer from the NautilusFile right to
the corresponding XML node, or we won't have the XML tree
in memory at all.
*/
for (child = root->childs; child != NULL; child = child->next) {
if (strcmp (child->name, "FILE") == 0) {
property = xmlGetProp (child, "NAME");
match = nautilus_strcmp (property, file_name) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
/* The root itself represents the directory.
* The children represent the files.
* FIXME: This linear search is temporary.
* Eventually, we'll have a pointer from the NautilusFile right to
* the corresponding XML node, or we won't have the XML tree
* in memory at all.
*/
child = nautilus_xml_get_root_child_by_name_and_property
(directory->details->metafile_tree,
"FILE", "NAME", file_name);
if (child != NULL) {
return child;
}
/* Create if necessary. */
if (create) {
root = xmlDocGetRootElement (directory->details->metafile_tree);
if (root == NULL) {
root = nautilus_directory_create_metafile_tree_root (directory);
}
@ -1018,7 +1011,7 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory,
xmlSetProp (child, "NAME", file_name);
return child;
}
return NULL;
}

View file

@ -35,6 +35,7 @@
#include <xmlmemory.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-xml-extensions.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-string.h"
#include "nautilus-directory-private.h"
@ -874,15 +875,15 @@ nautilus_file_get_keywords (NautilusFile *file)
file_node = nautilus_directory_get_file_metadata_node (file->directory,
file->info->name,
FALSE);
if (file_node != NULL) {
for (child = file_node->childs; child != NULL; child = child->next) {
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
if (property != NULL) {
keywords = g_list_prepend (keywords,
g_strdup (property));
xmlFree (property);
}
for (child = nautilus_xml_get_children (file_node);
child != NULL;
child = child->next) {
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
if (property != NULL) {
keywords = g_list_prepend (keywords,
g_strdup (property));
xmlFree (property);
}
}
}
@ -913,11 +914,16 @@ nautilus_file_set_keywords (NautilusFile *file, GList *keywords)
file->info->name,
keywords != NULL);
need_write = FALSE;
if (file_node != NULL) {
if (file_node == NULL) {
g_assert (keywords == NULL);
} else {
p = keywords;
/* Remove any nodes except the ones we expect. */
for (child = file_node->childs; child != NULL; child = next) {
for (child = nautilus_xml_get_children (file_node);
child != NULL;
child = next) {
next = child->next;
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
@ -932,7 +938,7 @@ nautilus_file_set_keywords (NautilusFile *file, GList *keywords)
xmlFree (property);
}
}
/* Add any additional nodes needed. */
for (; p != NULL; p = p->next) {
child = xmlNewChild (file_node, NULL, "KEYWORD", NULL);

View file

@ -47,6 +47,7 @@
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-xml-extensions.h"
/* List of suffixes to search when looking for an icon file. */
static const char *icon_file_name_suffixes[] =
@ -446,32 +447,6 @@ nautilus_icon_factory_get_icon_name_for_file (NautilusFile *file)
}
}
static xmlNodePtr
get_child_node_by_property (xmlNodePtr parent,
const char *child_nodes_name,
const char *child_node_property,
const char *child_node_property_value)
{
xmlNodePtr child;
xmlChar *property;
gboolean match;
if (parent == NULL) {
return NULL;
}
for (child = parent->childs; child != NULL; child = child->next) {
if (strcmp (child->name, child_nodes_name) == 0) {
property = xmlGetProp (child, child_node_property);
match = nautilus_strcmp (property, child_node_property_value) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
return NULL;
}
/* Pick a particular icon to use, trying all the various suffixes.
* Return the path of the icon or NULL if no icon is found.
*/
@ -529,8 +504,8 @@ get_themed_icon_file_path (const char *theme_name,
g_free (xml_path);
size_as_string = g_strdup_printf ("%u", icon_size);
node = get_child_node_by_property (xmlDocGetRootElement (doc),
"ICON", "SIZE", size_as_string);
node = nautilus_xml_get_root_child_by_name_and_property
(doc, "ICON", "SIZE", size_as_string);
g_free (size_as_string);
property = xmlGetProp (node, "EMBEDDED_TEXT_RECTANGLE");

View file

@ -0,0 +1,85 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-xml-extensions.c - functions that extend gnome-xml
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Darin Adler <darin@eazel.com>
*/
#include <config.h>
#include "nautilus-xml-extensions.h"
#include <glib.h>
#include "nautilus-string.h"
#include <stdlib.h>
#include <xmlmemory.h>
xmlNodePtr
nautilus_xml_get_children (xmlNodePtr parent)
{
if (parent == NULL) {
return NULL;
}
return parent->childs;
}
xmlNodePtr
nautilus_xml_get_root_children (xmlDocPtr document)
{
return nautilus_xml_get_children (xmlDocGetRootElement (document));
}
xmlNodePtr
nautilus_xml_get_child_by_name_and_property (xmlNodePtr parent,
const char *child_name,
const char *property_name,
const char *property_value)
{
xmlNodePtr child;
xmlChar *property;
gboolean match;
if (parent == NULL) {
return NULL;
}
for (child = nautilus_xml_get_children (parent); child != NULL; child = child->next) {
if (strcmp (child->name, child_name) == 0) {
property = xmlGetProp (child, property_name);
match = nautilus_strcmp (property, property_value) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
return NULL;
}
xmlNodePtr
nautilus_xml_get_root_child_by_name_and_property (xmlDocPtr document,
const char *child_name,
const char *property_name,
const char *property_value)
{
return nautilus_xml_get_child_by_name_and_property
(xmlDocGetRootElement (document),
child_name,
property_name,
property_value);
}

View file

@ -0,0 +1,41 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-xml-extensions.h - functions that extend gnome-xml
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Darin Adler <darin@eazel.com>
*/
#ifndef NAUTILUS_XML_EXTENSIONS_H
#define NAUTILUS_XML_EXTENSIONS_H
#include <tree.h>
xmlNodePtr nautilus_xml_get_children (xmlNodePtr parent);
xmlNodePtr nautilus_xml_get_root_children (xmlDocPtr document);
xmlNodePtr nautilus_xml_get_child_by_name_and_property (xmlNodePtr parent,
const char *child_name,
const char *property_name,
const char *property_value);
xmlNodePtr nautilus_xml_get_root_child_by_name_and_property (xmlDocPtr document,
const char *child_name,
const char *property_name,
const char *property_value);
#endif /* NAUTILUS_XML_EXTENSIONS_H */

View file

@ -51,6 +51,7 @@ libnautilusinclude_HEADERS= \
nautilus-self-checks.h \
nautilus-string-list.h \
nautilus-string.h \
nautilus-xml-extensions.h \
nautilus-zoomable.h \
nautilus.h \
ntl-content-view-frame.h \
@ -85,6 +86,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
nautilus-self-checks.c \
nautilus-string-list.c \
nautilus-string.c \
nautilus-xml-extensions.c \
nautilus-zoomable.c \
ntl-content-view-frame.c \
ntl-meta-view-frame.c \

View file

@ -35,6 +35,7 @@
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
#include "nautilus-xml-extensions.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-file-private.h"
@ -983,34 +984,26 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory,
gboolean create)
{
xmlNode *root, *child;
gboolean match;
xmlChar *property;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
/* The root itself represents the directory. */
root = xmlDocGetRootElement (directory->details->metafile_tree);
if (root != NULL) {
/* The children represent the files.
This linear search is temporary.
Eventually, we'll have a pointer from the NautilusFile right to
the corresponding XML node, or we won't have the XML tree
in memory at all.
*/
for (child = root->childs; child != NULL; child = child->next) {
if (strcmp (child->name, "FILE") == 0) {
property = xmlGetProp (child, "NAME");
match = nautilus_strcmp (property, file_name) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
/* The root itself represents the directory.
* The children represent the files.
* FIXME: This linear search is temporary.
* Eventually, we'll have a pointer from the NautilusFile right to
* the corresponding XML node, or we won't have the XML tree
* in memory at all.
*/
child = nautilus_xml_get_root_child_by_name_and_property
(directory->details->metafile_tree,
"FILE", "NAME", file_name);
if (child != NULL) {
return child;
}
/* Create if necessary. */
if (create) {
root = xmlDocGetRootElement (directory->details->metafile_tree);
if (root == NULL) {
root = nautilus_directory_create_metafile_tree_root (directory);
}
@ -1018,7 +1011,7 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory,
xmlSetProp (child, "NAME", file_name);
return child;
}
return NULL;
}

View file

@ -35,6 +35,7 @@
#include <xmlmemory.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-xml-extensions.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-string.h"
#include "nautilus-directory-private.h"
@ -874,15 +875,15 @@ nautilus_file_get_keywords (NautilusFile *file)
file_node = nautilus_directory_get_file_metadata_node (file->directory,
file->info->name,
FALSE);
if (file_node != NULL) {
for (child = file_node->childs; child != NULL; child = child->next) {
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
if (property != NULL) {
keywords = g_list_prepend (keywords,
g_strdup (property));
xmlFree (property);
}
for (child = nautilus_xml_get_children (file_node);
child != NULL;
child = child->next) {
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
if (property != NULL) {
keywords = g_list_prepend (keywords,
g_strdup (property));
xmlFree (property);
}
}
}
@ -913,11 +914,16 @@ nautilus_file_set_keywords (NautilusFile *file, GList *keywords)
file->info->name,
keywords != NULL);
need_write = FALSE;
if (file_node != NULL) {
if (file_node == NULL) {
g_assert (keywords == NULL);
} else {
p = keywords;
/* Remove any nodes except the ones we expect. */
for (child = file_node->childs; child != NULL; child = next) {
for (child = nautilus_xml_get_children (file_node);
child != NULL;
child = next) {
next = child->next;
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
@ -932,7 +938,7 @@ nautilus_file_set_keywords (NautilusFile *file, GList *keywords)
xmlFree (property);
}
}
/* Add any additional nodes needed. */
for (; p != NULL; p = p->next) {
child = xmlNewChild (file_node, NULL, "KEYWORD", NULL);

View file

@ -47,6 +47,7 @@
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-xml-extensions.h"
/* List of suffixes to search when looking for an icon file. */
static const char *icon_file_name_suffixes[] =
@ -446,32 +447,6 @@ nautilus_icon_factory_get_icon_name_for_file (NautilusFile *file)
}
}
static xmlNodePtr
get_child_node_by_property (xmlNodePtr parent,
const char *child_nodes_name,
const char *child_node_property,
const char *child_node_property_value)
{
xmlNodePtr child;
xmlChar *property;
gboolean match;
if (parent == NULL) {
return NULL;
}
for (child = parent->childs; child != NULL; child = child->next) {
if (strcmp (child->name, child_nodes_name) == 0) {
property = xmlGetProp (child, child_node_property);
match = nautilus_strcmp (property, child_node_property_value) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
return NULL;
}
/* Pick a particular icon to use, trying all the various suffixes.
* Return the path of the icon or NULL if no icon is found.
*/
@ -529,8 +504,8 @@ get_themed_icon_file_path (const char *theme_name,
g_free (xml_path);
size_as_string = g_strdup_printf ("%u", icon_size);
node = get_child_node_by_property (xmlDocGetRootElement (doc),
"ICON", "SIZE", size_as_string);
node = nautilus_xml_get_root_child_by_name_and_property
(doc, "ICON", "SIZE", size_as_string);
g_free (size_as_string);
property = xmlGetProp (node, "EMBEDDED_TEXT_RECTANGLE");

View file

@ -0,0 +1,85 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-xml-extensions.c - functions that extend gnome-xml
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Darin Adler <darin@eazel.com>
*/
#include <config.h>
#include "nautilus-xml-extensions.h"
#include <glib.h>
#include "nautilus-string.h"
#include <stdlib.h>
#include <xmlmemory.h>
xmlNodePtr
nautilus_xml_get_children (xmlNodePtr parent)
{
if (parent == NULL) {
return NULL;
}
return parent->childs;
}
xmlNodePtr
nautilus_xml_get_root_children (xmlDocPtr document)
{
return nautilus_xml_get_children (xmlDocGetRootElement (document));
}
xmlNodePtr
nautilus_xml_get_child_by_name_and_property (xmlNodePtr parent,
const char *child_name,
const char *property_name,
const char *property_value)
{
xmlNodePtr child;
xmlChar *property;
gboolean match;
if (parent == NULL) {
return NULL;
}
for (child = nautilus_xml_get_children (parent); child != NULL; child = child->next) {
if (strcmp (child->name, child_name) == 0) {
property = xmlGetProp (child, property_name);
match = nautilus_strcmp (property, property_value) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
return NULL;
}
xmlNodePtr
nautilus_xml_get_root_child_by_name_and_property (xmlDocPtr document,
const char *child_name,
const char *property_name,
const char *property_value)
{
return nautilus_xml_get_child_by_name_and_property
(xmlDocGetRootElement (document),
child_name,
property_name,
property_value);
}

View file

@ -0,0 +1,41 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-xml-extensions.h - functions that extend gnome-xml
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Darin Adler <darin@eazel.com>
*/
#ifndef NAUTILUS_XML_EXTENSIONS_H
#define NAUTILUS_XML_EXTENSIONS_H
#include <tree.h>
xmlNodePtr nautilus_xml_get_children (xmlNodePtr parent);
xmlNodePtr nautilus_xml_get_root_children (xmlDocPtr document);
xmlNodePtr nautilus_xml_get_child_by_name_and_property (xmlNodePtr parent,
const char *child_name,
const char *property_name,
const char *property_value);
xmlNodePtr nautilus_xml_get_root_child_by_name_and_property (xmlDocPtr document,
const char *child_name,
const char *property_name,
const char *property_value);
#endif /* NAUTILUS_XML_EXTENSIONS_H */

View file

@ -51,6 +51,7 @@ libnautilusinclude_HEADERS= \
nautilus-self-checks.h \
nautilus-string-list.h \
nautilus-string.h \
nautilus-xml-extensions.h \
nautilus-zoomable.h \
nautilus.h \
ntl-content-view-frame.h \
@ -85,6 +86,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
nautilus-self-checks.c \
nautilus-string-list.c \
nautilus-string.c \
nautilus-xml-extensions.c \
nautilus-zoomable.c \
ntl-content-view-frame.c \
ntl-meta-view-frame.c \

View file

@ -35,6 +35,7 @@
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
#include "nautilus-xml-extensions.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-file-private.h"
@ -983,34 +984,26 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory,
gboolean create)
{
xmlNode *root, *child;
gboolean match;
xmlChar *property;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
/* The root itself represents the directory. */
root = xmlDocGetRootElement (directory->details->metafile_tree);
if (root != NULL) {
/* The children represent the files.
This linear search is temporary.
Eventually, we'll have a pointer from the NautilusFile right to
the corresponding XML node, or we won't have the XML tree
in memory at all.
*/
for (child = root->childs; child != NULL; child = child->next) {
if (strcmp (child->name, "FILE") == 0) {
property = xmlGetProp (child, "NAME");
match = nautilus_strcmp (property, file_name) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
/* The root itself represents the directory.
* The children represent the files.
* FIXME: This linear search is temporary.
* Eventually, we'll have a pointer from the NautilusFile right to
* the corresponding XML node, or we won't have the XML tree
* in memory at all.
*/
child = nautilus_xml_get_root_child_by_name_and_property
(directory->details->metafile_tree,
"FILE", "NAME", file_name);
if (child != NULL) {
return child;
}
/* Create if necessary. */
if (create) {
root = xmlDocGetRootElement (directory->details->metafile_tree);
if (root == NULL) {
root = nautilus_directory_create_metafile_tree_root (directory);
}
@ -1018,7 +1011,7 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory,
xmlSetProp (child, "NAME", file_name);
return child;
}
return NULL;
}

View file

@ -35,6 +35,7 @@
#include <xmlmemory.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-xml-extensions.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-string.h"
#include "nautilus-directory-private.h"
@ -874,15 +875,15 @@ nautilus_file_get_keywords (NautilusFile *file)
file_node = nautilus_directory_get_file_metadata_node (file->directory,
file->info->name,
FALSE);
if (file_node != NULL) {
for (child = file_node->childs; child != NULL; child = child->next) {
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
if (property != NULL) {
keywords = g_list_prepend (keywords,
g_strdup (property));
xmlFree (property);
}
for (child = nautilus_xml_get_children (file_node);
child != NULL;
child = child->next) {
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
if (property != NULL) {
keywords = g_list_prepend (keywords,
g_strdup (property));
xmlFree (property);
}
}
}
@ -913,11 +914,16 @@ nautilus_file_set_keywords (NautilusFile *file, GList *keywords)
file->info->name,
keywords != NULL);
need_write = FALSE;
if (file_node != NULL) {
if (file_node == NULL) {
g_assert (keywords == NULL);
} else {
p = keywords;
/* Remove any nodes except the ones we expect. */
for (child = file_node->childs; child != NULL; child = next) {
for (child = nautilus_xml_get_children (file_node);
child != NULL;
child = next) {
next = child->next;
if (strcmp (child->name, "KEYWORD") == 0) {
property = xmlGetProp (child, "NAME");
@ -932,7 +938,7 @@ nautilus_file_set_keywords (NautilusFile *file, GList *keywords)
xmlFree (property);
}
}
/* Add any additional nodes needed. */
for (; p != NULL; p = p->next) {
child = xmlNewChild (file_node, NULL, "KEYWORD", NULL);

View file

@ -47,6 +47,7 @@
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-xml-extensions.h"
/* List of suffixes to search when looking for an icon file. */
static const char *icon_file_name_suffixes[] =
@ -446,32 +447,6 @@ nautilus_icon_factory_get_icon_name_for_file (NautilusFile *file)
}
}
static xmlNodePtr
get_child_node_by_property (xmlNodePtr parent,
const char *child_nodes_name,
const char *child_node_property,
const char *child_node_property_value)
{
xmlNodePtr child;
xmlChar *property;
gboolean match;
if (parent == NULL) {
return NULL;
}
for (child = parent->childs; child != NULL; child = child->next) {
if (strcmp (child->name, child_nodes_name) == 0) {
property = xmlGetProp (child, child_node_property);
match = nautilus_strcmp (property, child_node_property_value) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
return NULL;
}
/* Pick a particular icon to use, trying all the various suffixes.
* Return the path of the icon or NULL if no icon is found.
*/
@ -529,8 +504,8 @@ get_themed_icon_file_path (const char *theme_name,
g_free (xml_path);
size_as_string = g_strdup_printf ("%u", icon_size);
node = get_child_node_by_property (xmlDocGetRootElement (doc),
"ICON", "SIZE", size_as_string);
node = nautilus_xml_get_root_child_by_name_and_property
(doc, "ICON", "SIZE", size_as_string);
g_free (size_as_string);
property = xmlGetProp (node, "EMBEDDED_TEXT_RECTANGLE");

View file

@ -0,0 +1,85 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-xml-extensions.c - functions that extend gnome-xml
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Darin Adler <darin@eazel.com>
*/
#include <config.h>
#include "nautilus-xml-extensions.h"
#include <glib.h>
#include "nautilus-string.h"
#include <stdlib.h>
#include <xmlmemory.h>
xmlNodePtr
nautilus_xml_get_children (xmlNodePtr parent)
{
if (parent == NULL) {
return NULL;
}
return parent->childs;
}
xmlNodePtr
nautilus_xml_get_root_children (xmlDocPtr document)
{
return nautilus_xml_get_children (xmlDocGetRootElement (document));
}
xmlNodePtr
nautilus_xml_get_child_by_name_and_property (xmlNodePtr parent,
const char *child_name,
const char *property_name,
const char *property_value)
{
xmlNodePtr child;
xmlChar *property;
gboolean match;
if (parent == NULL) {
return NULL;
}
for (child = nautilus_xml_get_children (parent); child != NULL; child = child->next) {
if (strcmp (child->name, child_name) == 0) {
property = xmlGetProp (child, property_name);
match = nautilus_strcmp (property, property_value) == 0;
xmlFree (property);
if (match) {
return child;
}
}
}
return NULL;
}
xmlNodePtr
nautilus_xml_get_root_child_by_name_and_property (xmlDocPtr document,
const char *child_name,
const char *property_name,
const char *property_value)
{
return nautilus_xml_get_child_by_name_and_property
(xmlDocGetRootElement (document),
child_name,
property_name,
property_value);
}

View file

@ -0,0 +1,41 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-xml-extensions.h - functions that extend gnome-xml
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Darin Adler <darin@eazel.com>
*/
#ifndef NAUTILUS_XML_EXTENSIONS_H
#define NAUTILUS_XML_EXTENSIONS_H
#include <tree.h>
xmlNodePtr nautilus_xml_get_children (xmlNodePtr parent);
xmlNodePtr nautilus_xml_get_root_children (xmlDocPtr document);
xmlNodePtr nautilus_xml_get_child_by_name_and_property (xmlNodePtr parent,
const char *child_name,
const char *property_name,
const char *property_value);
xmlNodePtr nautilus_xml_get_root_child_by_name_and_property (xmlDocPtr document,
const char *child_name,
const char *property_name,
const char *property_value);
#endif /* NAUTILUS_XML_EXTENSIONS_H */

View file

@ -22,10 +22,12 @@
Authors: John Sullivan <sullivan@eazel.com>
*/
#include "nautilus.h"
#include <config.h>
#include "nautilus-bookmarklist.h"
#include <libnautilus/nautilus-file-utilities.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-xml-extensions.h>
#include <parser.h>
#include <tree.h>
@ -38,52 +40,30 @@ enum {
/* forward declarations */
static void append_bookmark_node (gpointer list_element,
gpointer user_data);
static void destroy_bookmark (gpointer list_element,
gpointer user_data);
static const gchar *nautilus_bookmarklist_get_file_path (NautilusBookmarklist *bookmarks);
static void nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks);
static void nautilus_bookmarklist_save_file (NautilusBookmarklist *bookmarks);
static void set_window_geometry_internal (const gchar *string);
static void append_bookmark_node (gpointer list_element,
gpointer user_data);
static void destroy_bookmark (gpointer list_element,
gpointer user_data);
static const char *nautilus_bookmarklist_get_file_path (NautilusBookmarklist *bookmarks);
static void nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks);
static void nautilus_bookmarklist_save_file (NautilusBookmarklist *bookmarks);
static void set_window_geometry_internal (const char *string);
static GtkObjectClass *parent_class = NULL;
static guint bookmarklist_signals[LAST_SIGNAL] = { 0 };
static gchar *window_geometry = NULL;
const unsigned default_gnomad_directory_mode = 0755;
/* GtkObject methods. */
static void
nautilus_bookmarklist_destroy (GtkObject *object)
{
if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
static void
nautilus_bookmarklist_finalize (GtkObject *object)
{
if (GTK_OBJECT_CLASS (parent_class)->finalize != NULL)
(* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
}
static guint signals[LAST_SIGNAL];
static char *window_geometry;
/* Initialization. */
static void
nautilus_bookmarklist_class_init (NautilusBookmarklistClass *class)
nautilus_bookmarklist_initialize_class (NautilusBookmarklistClass *class)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (class);
parent_class = gtk_type_class (GTK_TYPE_OBJECT);
bookmarklist_signals[CONTENTS_CHANGED] =
signals[CONTENTS_CHANGED] =
gtk_signal_new ("contents_changed",
GTK_RUN_FIRST,
object_class->type,
@ -92,41 +72,18 @@ nautilus_bookmarklist_class_init (NautilusBookmarklistClass *class)
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, bookmarklist_signals, LAST_SIGNAL);
object_class->destroy = nautilus_bookmarklist_destroy;
object_class->finalize = nautilus_bookmarklist_finalize;
gtk_object_class_add_signals (object_class,
signals,
LAST_SIGNAL);
}
static void
nautilus_bookmarklist_init (NautilusBookmarklist *bookmarks)
nautilus_bookmarklist_initialize (NautilusBookmarklist *bookmarks)
{
bookmarks->list = NULL;
nautilus_bookmarklist_load_file(bookmarks);
nautilus_bookmarklist_load_file (bookmarks);
}
GtkType
nautilus_bookmarklist_get_type (void)
{
static GtkType type = 0;
if (type == 0) {
static GtkTypeInfo info = {
"NautilusBookmarklist",
sizeof (NautilusBookmarklist),
sizeof (NautilusBookmarklistClass),
(GtkClassInitFunc) nautilus_bookmarklist_class_init,
(GtkObjectInitFunc) nautilus_bookmarklist_init,
NULL,
NULL,
NULL
};
type = gtk_type_unique (GTK_TYPE_OBJECT, &info);
}
return type;
}
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusBookmarklist, nautilus_bookmarklist, GTK_TYPE_OBJECT)
/**
@ -139,17 +96,17 @@ nautilus_bookmarklist_get_type (void)
static void
append_bookmark_node (gpointer data, gpointer user_data)
{
xmlNodePtr root_node, bookmark_node;
xmlNodePtr root_node, bookmark_node;
NautilusBookmark *bookmark;
g_return_if_fail(NAUTILUS_IS_BOOKMARK(data));
g_assert (NAUTILUS_IS_BOOKMARK (data));
bookmark = NAUTILUS_BOOKMARK(data);
root_node = (xmlNodePtr)user_data;
bookmark = NAUTILUS_BOOKMARK (data);
root_node = (xmlNodePtr) user_data;
bookmark_node = xmlNewChild(root_node, NULL, "bookmark", NULL);
xmlSetProp(bookmark_node, "name", nautilus_bookmark_get_name(bookmark));
xmlSetProp(bookmark_node, "uri", nautilus_bookmark_get_uri(bookmark));
bookmark_node = xmlNewChild (root_node, NULL, "bookmark", NULL);
xmlSetProp (bookmark_node, "name", nautilus_bookmark_get_name (bookmark));
xmlSetProp (bookmark_node, "uri", nautilus_bookmark_get_uri (bookmark));
}
/**
@ -162,9 +119,9 @@ append_bookmark_node (gpointer data, gpointer user_data)
static void
destroy_bookmark (gpointer data, gpointer user_data)
{
g_return_if_fail(NAUTILUS_IS_BOOKMARK(data));
g_assert (NAUTILUS_IS_BOOKMARK (data));
gtk_object_destroy(GTK_OBJECT(data));
gtk_object_destroy (GTK_OBJECT (data));
}
/**
@ -181,9 +138,9 @@ nautilus_bookmarklist_append (NautilusBookmarklist *bookmarks,
g_return_if_fail (NAUTILUS_IS_BOOKMARKLIST (bookmarks));
g_return_if_fail (NAUTILUS_IS_BOOKMARK (bookmark));
bookmarks->list = g_list_append(bookmarks->list,
nautilus_bookmark_copy(bookmark));
nautilus_bookmarklist_contents_changed(bookmarks);
bookmarks->list = g_list_append (bookmarks->list,
nautilus_bookmark_copy (bookmark));
nautilus_bookmarklist_contents_changed (bookmarks);
}
/**
@ -197,14 +154,14 @@ nautilus_bookmarklist_append (NautilusBookmarklist *bookmarks,
**/
gboolean
nautilus_bookmarklist_contains (NautilusBookmarklist *bookmarks,
const NautilusBookmark *bookmark)
const NautilusBookmark *bookmark)
{
g_return_val_if_fail (NAUTILUS_IS_BOOKMARKLIST (bookmarks), FALSE);
g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), FALSE);
return g_list_find_custom(bookmarks->list,
(gpointer)bookmark,
nautilus_bookmark_compare_with)
return g_list_find_custom (bookmarks->list,
(gpointer)bookmark,
nautilus_bookmark_compare_with)
!= NULL;
}
@ -219,9 +176,9 @@ nautilus_bookmarklist_contents_changed (NautilusBookmarklist *bookmarks)
{
g_return_if_fail (NAUTILUS_IS_BOOKMARKLIST (bookmarks));
nautilus_bookmarklist_save_file(bookmarks);
gtk_signal_emit(GTK_OBJECT (bookmarks),
bookmarklist_signals[CONTENTS_CHANGED]);
nautilus_bookmarklist_save_file (bookmarks);
gtk_signal_emit (GTK_OBJECT (bookmarks),
signals[CONTENTS_CHANGED]);
}
/**
@ -251,15 +208,15 @@ nautilus_bookmarklist_delete_item_at (NautilusBookmarklist *bookmarks,
nautilus_bookmarklist_contents_changed (bookmarks);
}
static const gchar *
static const char *
nautilus_bookmarklist_get_file_path (NautilusBookmarklist *bookmarks)
{
/* currently hardwired */
static gchar *file_path = NULL;
if (file_path == NULL)
{
file_path = nautilus_make_path(nautilus_user_directory(),
"bookmarks.xml");
static char *file_path = NULL;
if (file_path == NULL) {
file_path = nautilus_make_path (nautilus_user_directory(),
"bookmarks.xml");
}
return file_path;
@ -275,7 +232,7 @@ nautilus_bookmarklist_get_file_path (NautilusBookmarklist *bookmarks)
* passing to gnome_parse_geometry(), or NULL if
* no window geometry has yet been saved for this bookmarklist.
**/
const gchar *
const char *
nautilus_bookmarklist_get_window_geometry (NautilusBookmarklist *bookmarks)
{
return window_geometry;
@ -294,14 +251,14 @@ nautilus_bookmarklist_insert_item (NautilusBookmarklist *bookmarks,
const NautilusBookmark* new_bookmark,
guint index)
{
g_return_if_fail(NAUTILUS_IS_BOOKMARKLIST (bookmarks));
g_return_if_fail(index <= g_list_length(bookmarks->list));
g_return_if_fail (NAUTILUS_IS_BOOKMARKLIST (bookmarks));
g_return_if_fail (index <= g_list_length (bookmarks->list));
bookmarks->list = g_list_insert(bookmarks->list,
nautilus_bookmark_copy(new_bookmark),
index);
bookmarks->list = g_list_insert (bookmarks->list,
nautilus_bookmark_copy (new_bookmark),
index);
nautilus_bookmarklist_contents_changed(bookmarks);
nautilus_bookmarklist_contents_changed (bookmarks);
}
/**
@ -316,10 +273,10 @@ nautilus_bookmarklist_insert_item (NautilusBookmarklist *bookmarks,
const NautilusBookmark *
nautilus_bookmarklist_item_at (NautilusBookmarklist *bookmarks, guint index)
{
g_return_val_if_fail(NAUTILUS_IS_BOOKMARKLIST(bookmarks), NULL);
g_return_val_if_fail(index < g_list_length(bookmarks->list), NULL);
g_return_val_if_fail (NAUTILUS_IS_BOOKMARKLIST (bookmarks), NULL);
g_return_val_if_fail (index < g_list_length (bookmarks->list), NULL);
return NAUTILUS_BOOKMARK(g_list_nth_data(bookmarks->list, index));
return NAUTILUS_BOOKMARK (g_list_nth_data (bookmarks->list, index));
}
/**
@ -333,9 +290,9 @@ nautilus_bookmarklist_item_at (NautilusBookmarklist *bookmarks, guint index)
guint
nautilus_bookmarklist_length (NautilusBookmarklist *bookmarks)
{
g_return_val_if_fail(NAUTILUS_IS_BOOKMARKLIST(bookmarks), 0);
g_return_val_if_fail (NAUTILUS_IS_BOOKMARKLIST(bookmarks), 0);
return g_list_length(bookmarks->list);
return g_list_length (bookmarks->list);
}
/**
@ -347,8 +304,8 @@ nautilus_bookmarklist_length (NautilusBookmarklist *bookmarks)
static void
nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks)
{
xmlDocPtr doc;
xmlNodePtr node;
xmlDocPtr doc;
xmlNodePtr node;
/* Wipe out old list. */
g_list_foreach (bookmarks->list, destroy_bookmark, NULL);
@ -356,16 +313,12 @@ nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks)
bookmarks->list = NULL;
/* Read new list from file */
doc = xmlParseFile(nautilus_bookmarklist_get_file_path(bookmarks));
doc = xmlParseFile (nautilus_bookmarklist_get_file_path (bookmarks));
for (node = nautilus_xml_get_root_children (doc);
node != NULL;
node = node->next) {
if (doc == NULL)
return;
node = doc->root->childs;
while (node != NULL)
{
if (strcmp(node->name, "bookmark") == 0)
{
if (strcmp(node->name, "bookmark") == 0) {
xmlChar *xml_name;
xmlChar *xml_uri;
@ -373,24 +326,21 @@ nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks)
xml_name = xmlGetProp (node, "name");
xml_uri = xmlGetProp (node, "uri");
bookmarks->list = g_list_append(
bookmarks->list,
nautilus_bookmark_new_with_name (xml_uri, xml_name));
bookmarks->list = g_list_append
(bookmarks->list,
nautilus_bookmark_new_with_name (xml_uri, xml_name));
xmlFree (xml_name);
xmlFree (xml_uri);
}
else if (strcmp (node->name, "window") == 0)
{
} else if (strcmp (node->name, "window") == 0) {
xmlChar *geometry_string;
geometry_string = xmlGetProp (node, "geometry");
set_window_geometry_internal (geometry_string);
xmlFree (geometry_string);
}
node = node->next;
}
xmlFreeDoc(doc);
}
@ -402,13 +352,9 @@ nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks)
* Return value: A pointer to the new widget.
**/
NautilusBookmarklist *
nautilus_bookmarklist_new ()
{
NautilusBookmarklist *new;
new = gtk_type_new (NAUTILUS_TYPE_BOOKMARKLIST);
return new;
nautilus_bookmarklist_new (void)
{
return gtk_type_new (NAUTILUS_TYPE_BOOKMARKLIST);
}
/**
@ -420,25 +366,24 @@ nautilus_bookmarklist_new ()
static void
nautilus_bookmarklist_save_file (NautilusBookmarklist *bookmarks)
{
xmlDocPtr doc;
xmlDocPtr doc;
xmlNodePtr root, node;
doc = xmlNewDoc("1.0");
doc->root = xmlNewDocNode(doc, NULL, "bookmarks", NULL);
doc = xmlNewDoc ("1.0");
root = xmlNewDocNode (doc, NULL, "bookmarks", NULL);
xmlDocSetRootElement (doc, root);
/* save window position */
if (window_geometry != NULL)
{
xmlNodePtr node;
node = xmlNewChild(doc->root, NULL, "window", NULL);
if (window_geometry != NULL) {
node = xmlNewChild (root, NULL, "window", NULL);
xmlSetProp (node, "geometry", window_geometry);
}
/* save bookmarks */
g_list_foreach (bookmarks->list, append_bookmark_node, doc->root);
g_list_foreach (bookmarks->list, append_bookmark_node, root);
xmlSaveFile(nautilus_bookmarklist_get_file_path(bookmarks), doc);
xmlFreeDoc(doc);
xmlSaveFile (nautilus_bookmarklist_get_file_path (bookmarks), doc);
xmlFreeDoc (doc);
}
/**
@ -452,7 +397,7 @@ nautilus_bookmarklist_save_file (NautilusBookmarklist *bookmarks)
**/
void
nautilus_bookmarklist_set_window_geometry (NautilusBookmarklist *bookmarks,
const gchar *geometry)
const char *geometry)
{
g_return_if_fail (NAUTILUS_IS_BOOKMARKLIST (bookmarks));
g_return_if_fail (geometry != NULL);
@ -463,7 +408,7 @@ nautilus_bookmarklist_set_window_geometry (NautilusBookmarklist *bookmarks,
}
static void
set_window_geometry_internal (const gchar *string)
set_window_geometry_internal (const char *string)
{
g_free (window_geometry);
window_geometry = g_strdup (string);