summaryrefslogtreecommitdiff
path: root/src/nautilus-bookmark.c
blob: d04e6d5272a3f59fbc2bd91f48153adbcbf53bf6 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-bookmark.c - implementation of individual bookmarks.

   Copyright (C) 1999 Eazel, Inc.

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: John Sullivan <sullivan@eazel.com>
*/

#include "nautilus.h"
#include "nautilus-bookmark.h"


static GtkObjectClass *parent_class = NULL;

/* GtkObject methods.  */

static void
nautilus_bookmark_destroy (GtkObject *object)
{
	NautilusBookmark *bookmark;

	g_return_if_fail(NAUTILUS_IS_BOOKMARK (object));

	bookmark = NAUTILUS_BOOKMARK(object);
	g_string_free(bookmark->name, TRUE);
	g_string_free(bookmark->uri, TRUE);

	/* Chain up */
	if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
		(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}

static void
nautilus_bookmark_finalize (GtkObject *object)
{
	/* Chain up */
	if (GTK_OBJECT_CLASS (parent_class)->finalize != NULL)
		(* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
}


/* Initialization.  */

static void
class_init (NautilusBookmarkClass *class)
{
	GtkObjectClass *object_class;

	object_class = GTK_OBJECT_CLASS (class);
	parent_class = gtk_type_class (GTK_TYPE_OBJECT);

	object_class->destroy = nautilus_bookmark_destroy;
	object_class->finalize = nautilus_bookmark_finalize;
}

static void
init (NautilusBookmark *bookmark)
{
	g_assert(bookmark->name == NULL);
	g_assert(bookmark->uri == NULL);

	bookmark->name = g_string_new(NULL);
	bookmark->uri = g_string_new(NULL);
}


GtkType
nautilus_bookmark_get_type (void)
{
	static GtkType type = 0;

	if (type == 0) {
		static GtkTypeInfo info = {
			"NautilusBookmark",
			sizeof (NautilusBookmark),
			sizeof (NautilusBookmarkClass),
			(GtkClassInitFunc) class_init,
			(GtkObjectInitFunc) init,
			NULL,
			NULL,
			NULL
		};

		type = gtk_type_unique (GTK_TYPE_OBJECT, &info);
	}

	return type;
}


/**
 * nautilus_bookmark_compare_with:
 *
 * Check whether two bookmarks are considered identical.
 * @a: first NautilusBookmark*.
 * @b: second NautilusBookmark*.
 * 
 * Return value: 0 if @a and @b have same name and uri, 1 otherwise 
 * (GCompareFunc style)
 **/
gint		    
nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b)
{
	NautilusBookmark *bookmark_a;
	NautilusBookmark *bookmark_b;

	g_return_val_if_fail(NAUTILUS_IS_BOOKMARK(a), 1);
	g_return_val_if_fail(NAUTILUS_IS_BOOKMARK(b), 1);

	bookmark_a = NAUTILUS_BOOKMARK(a);
	bookmark_b = NAUTILUS_BOOKMARK(b);

	if (strcmp(nautilus_bookmark_get_name(bookmark_a),
		   nautilus_bookmark_get_name(bookmark_b)) != 0)
	{
		return 1;
	}
	
	if (strcmp(nautilus_bookmark_get_uri(bookmark_a),
		   nautilus_bookmark_get_uri(bookmark_b)) != 0)
	{
		return 1;
	}
	
	return 0;
}

NautilusBookmark *
nautilus_bookmark_copy (const NautilusBookmark *bookmark)
{
	g_return_val_if_fail(NAUTILUS_IS_BOOKMARK (bookmark), NULL);

	return nautilus_bookmark_new(
			nautilus_bookmark_get_name(bookmark),
			nautilus_bookmark_get_uri(bookmark));
}

const gchar *
nautilus_bookmark_get_name (const NautilusBookmark *bookmark)
{
	g_return_val_if_fail(NAUTILUS_IS_BOOKMARK (bookmark), NULL);

	return bookmark->name->str;
}

const gchar *
nautilus_bookmark_get_uri (const NautilusBookmark *bookmark)
{
	g_return_val_if_fail(NAUTILUS_IS_BOOKMARK (bookmark), NULL);

	return bookmark->uri->str;
}

NautilusBookmark *
nautilus_bookmark_new (const gchar *name, const gchar *uri)
{
	NautilusBookmark *new_bookmark;

	new_bookmark = gtk_type_new (NAUTILUS_TYPE_BOOKMARK);
	g_string_assign(new_bookmark->name, name);
	g_string_assign(new_bookmark->uri, uri);

	return new_bookmark;
}