summaryrefslogtreecommitdiff
path: root/components/tree/nautilus-tree-node.c
blob: 543fe08d21a52343541a9d2c8751861f9e32bfc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* 
 * Copyright (C) 2000 Eazel, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Maciej Stachowiak <mjs@eazel.com>
 */

/* nautilus-tree-model.c - model for the tree view */

#include <config.h>
#include "nautilus-tree-node.h"

#include "nautilus-tree-node-private.h"
#include <libnautilus-extensions/nautilus-directory.h>
#include <libnautilus-extensions/nautilus-file.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>


static void               nautilus_tree_node_destroy          (GtkObject   *object);
static void               nautilus_tree_node_initialize       (gpointer     object,
								gpointer     klass);
static void               nautilus_tree_node_initialize_class (gpointer     klass);



NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusTreeNode, nautilus_tree_node, GTK_TYPE_OBJECT)


static void
nautilus_tree_node_initialize_class (gpointer klass)
{
	GtkObjectClass *object_class;

	object_class = GTK_OBJECT_CLASS (klass);
	
	object_class->destroy = nautilus_tree_node_destroy;
}

static void
nautilus_tree_node_initialize (gpointer object, gpointer klass)
{
	NautilusTreeNode *node;

	node = NAUTILUS_TREE_NODE (object);

	node->details = g_new0 (NautilusTreeNodeDetails, 1);
}


static void
nautilus_tree_node_destroy (GtkObject *object)
{
	NautilusTreeNode *node;

	node = NAUTILUS_TREE_NODE (object);

	nautilus_directory_unref (node->details->directory);
	nautilus_file_unref (node->details->file);
	g_list_free (node->details->children);
	g_free (node->details->uri);
	g_free (node->details);

	NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}

NautilusTreeNode *
nautilus_tree_node_new (NautilusFile *file)
{
	NautilusTreeNode *node;

	node = NAUTILUS_TREE_NODE (gtk_object_new (NAUTILUS_TYPE_TREE_NODE, NULL));
	gtk_object_ref (GTK_OBJECT (node));
	gtk_object_sink (GTK_OBJECT (node));

	node->details->file = nautilus_file_ref (file);
	node->details->uri = nautilus_file_get_uri (file);

	return node;
}



NautilusTreeNode *
nautilus_tree_node_get_parent (NautilusTreeNode   *node)
{
	return node->details->parent;
}

GList *
nautilus_tree_node_get_children  (NautilusTreeNode   *node)
{
	return node->details->children;
}

NautilusFile *
nautilus_tree_node_get_file      (NautilusTreeNode   *node)
{
	return node->details->file;
}

char *
nautilus_tree_node_get_uri      (NautilusTreeNode   *node)
{
	return g_strdup (node->details->uri);
}


NautilusDirectory *
nautilus_tree_node_get_directory (NautilusTreeNode   *node)
{
	return node->details->directory;
}

void
nautilus_tree_node_set_parent (NautilusTreeNode   *node,
			       NautilusTreeNode   *parent)
{
	g_return_if_fail (node->details->parent == NULL);

	node->details->parent = parent;
	parent->details->children = g_list_append (parent->details->children, node);
}


void
nautilus_tree_node_remove_from_parent (NautilusTreeNode *node)
{
	if (node->details->parent != NULL) {
		node->details->parent->details->children = g_list_remove
			(node->details->parent->details->children, node);
		node->details->parent = NULL;
	}
}