-
Notifications
You must be signed in to change notification settings - Fork 2
/
sb-revision.c
180 lines (149 loc) · 4.25 KB
/
sb-revision.c
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
/* This file is part of source browser
*
* AUTHORS
* Sven Herzberg <herzi@gnome-de.org>
*
* Copyright (C) 2007 Sven Herzberg
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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
*/
#include "sb-revision.h"
#include "sb-comparable.h"
struct _SbRevisionPrivate {
gchar* name;
gchar* summary;
};
enum {
PROP_0,
PROP_NAME
};
static void implement_comparable (SbComparableIface* iface);
G_DEFINE_TYPE_WITH_CODE (SbRevision, sb_revision, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (SB_TYPE_COMPARABLE, implement_comparable););
static void
sb_revision_init (SbRevision* self)
{
self->_private = G_TYPE_INSTANCE_GET_PRIVATE (self,
SB_TYPE_REVISION,
SbRevisionPrivate);
}
static void
revision_finalize (GObject* object)
{
SbRevision* self = SB_REVISION (object);
g_free (self->_private->name);
g_free (self->_private->summary);
G_OBJECT_CLASS (sb_revision_parent_class)->finalize (object);
}
static void
revision_get_property (GObject * object,
guint prop_id,
GValue * value,
GParamSpec* pspec)
{
SbRevision* self = SB_REVISION (object);
switch (prop_id) {
case PROP_NAME:
g_value_set_string (value, sb_revision_get_name (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
revision_set_property (GObject * object,
guint prop_id,
GValue const* value,
GParamSpec * pspec)
{
SbRevision* self = SB_REVISION (object);
switch (prop_id) {
case PROP_NAME:
self->_private->name = g_value_dup_string (value);
g_object_notify (object, "name");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
sb_revision_class_init (SbRevisionClass* self_class)
{
GObjectClass* object_class = G_OBJECT_CLASS (self_class);
object_class->finalize = revision_finalize;
object_class->get_property = revision_get_property;
object_class->set_property = revision_set_property;
g_object_class_install_property (object_class,
PROP_NAME,
g_param_spec_string ("name", "name", "name",
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (self_class, sizeof (SbRevisionPrivate));
}
SbRevision*
sb_revision_new (gchar const* name)
{
return g_object_new (SB_TYPE_REVISION,
"name", name,
NULL);
}
gchar const*
sb_revision_get_name (SbRevision const* self)
{
g_return_val_if_fail (SB_IS_REVISION (self), NULL);
return self->_private->name;
}
gchar const*
sb_revision_get_summary (SbRevision const* self)
{
g_return_val_if_fail (SB_IS_REVISION (self), NULL);
return self->_private->summary;
}
void
sb_revision_set_summary (SbRevision * self,
gchar const* summary)
{
g_return_if_fail (SB_IS_REVISION (self));
if (self->_private->summary == summary) {
return;
}
g_free (self->_private->summary);
self->_private->summary = g_strdup (summary);
// FIXME: make a GObject property
// g_object_notify (G_OBJECT (self), "summary");
}
/* SbComparableIface */
static gboolean
revision_equals (SbComparable const* comparable,
SbComparable const* other)
{
SbRevision* self = SB_REVISION (comparable);
return SB_IS_REVISION (other) &&
!strcmp (self->_private->name, SB_REVISION (other)->_private->name);
}
static guint
revision_hash (SbComparable const* comparable)
{
SbRevision const* self = SB_REVISION (comparable);
return g_str_hash (self->_private->name); // FIXME: has also on a repository somehow
}
static void
implement_comparable (SbComparableIface* iface)
{
iface->equals = revision_equals;
iface->hash = revision_hash;
}