Document previous patch
[viking.git] / src / vikexttool.c
blob66fb3566a02275a0c71852406f0fb067aa3c9117
1 /*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include "vikexttool.h"
28 #include <string.h>
30 #include <glib/gi18n.h>
32 static void ext_tool_class_init ( VikExtToolClass *klass );
33 static void ext_tool_init ( VikExtTool *vlp );
35 static GObjectClass *parent_class;
37 static void ext_tool_finalize ( GObject *gob );
38 static gchar *ext_tool_get_label ( VikExtTool *vw );
40 typedef struct _VikExtToolPrivate VikExtToolPrivate;
42 struct _VikExtToolPrivate
44 gint id;
45 gchar *label;
48 #define EXT_TOOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
49 VIK_EXT_TOOL_TYPE, \
50 VikExtToolPrivate))
52 GType vik_ext_tool_get_type()
54 static GType w_type = 0;
56 if (!w_type)
58 static const GTypeInfo w_info =
60 sizeof (VikExtToolClass),
61 NULL, /* base_init */
62 NULL, /* base_finalize */
63 (GClassInitFunc) ext_tool_class_init,
64 NULL, /* class_finalize */
65 NULL, /* class_data */
66 sizeof (VikExtTool),
68 (GInstanceInitFunc) ext_tool_init,
70 w_type = g_type_register_static ( G_TYPE_OBJECT, "VikExtTool", &w_info, G_TYPE_FLAG_ABSTRACT );
73 return w_type;
76 enum
78 PROP_0,
80 PROP_ID,
81 PROP_LABEL,
84 static void
85 ext_tool_set_property (GObject *object,
86 guint property_id,
87 const GValue *value,
88 GParamSpec *pspec)
90 VikExtTool *self = VIK_EXT_TOOL (object);
91 VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
93 switch (property_id)
95 case PROP_ID:
96 priv->id = g_value_get_uint (value);
97 g_debug ("VikExtTool.id: %d", priv->id);
98 break;
100 case PROP_LABEL:
101 g_free (priv->label);
102 priv->label = g_value_dup_string (value);
103 g_debug ("VikExtTool.label: %s", priv->label);
104 break;
106 default:
107 /* We don't have any other property... */
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
109 break;
113 static void
114 ext_tool_get_property (GObject *object,
115 guint property_id,
116 GValue *value,
117 GParamSpec *pspec)
119 VikExtTool *self = VIK_EXT_TOOL (object);
120 VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
122 switch (property_id)
124 case PROP_ID:
125 g_value_set_uint (value, priv->id);
126 break;
128 case PROP_LABEL:
129 g_value_set_string (value, priv->label);
130 break;
132 default:
133 /* We don't have any other property... */
134 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
135 break;
139 static void ext_tool_class_init ( VikExtToolClass *klass )
141 GObjectClass *gobject_class;
142 GParamSpec *pspec;
144 gobject_class = G_OBJECT_CLASS (klass);
145 gobject_class->finalize = ext_tool_finalize;
146 gobject_class->set_property = ext_tool_set_property;
147 gobject_class->get_property = ext_tool_get_property;
149 pspec = g_param_spec_string ("label",
150 "Label",
151 "Set the label",
152 "<no-set>" /* default value */,
153 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
154 g_object_class_install_property (gobject_class,
155 PROP_LABEL,
156 pspec);
158 pspec = g_param_spec_uint ("id",
159 "Id of the tool",
160 "Set the id",
161 0 /* minimum value */,
162 G_MAXUINT16 /* maximum value */,
163 0 /* default value */,
164 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
165 g_object_class_install_property (gobject_class,
166 PROP_ID,
167 pspec);
169 klass->get_label = ext_tool_get_label;
171 parent_class = g_type_class_peek_parent (klass);
173 g_type_class_add_private (klass, sizeof (VikExtToolPrivate));
176 VikExtTool *vik_ext_tool_new ()
178 return VIK_EXT_TOOL ( g_object_new ( VIK_EXT_TOOL_TYPE, NULL ) );
181 static void ext_tool_init ( VikExtTool *self )
183 VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
184 priv->label = NULL;
187 static void ext_tool_finalize ( GObject *gob )
189 VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE ( gob );
190 g_free ( priv->label ); priv->label = NULL;
191 G_OBJECT_CLASS(parent_class)->finalize(gob);
194 static gchar *ext_tool_get_label ( VikExtTool *self )
196 VikExtToolPrivate *priv = NULL;
197 priv = EXT_TOOL_GET_PRIVATE (self);
198 return g_strdup ( priv->label );
201 gchar *vik_ext_tool_get_label ( VikExtTool *w )
203 return VIK_EXT_TOOL_GET_CLASS( w )->get_label( w );
206 void vik_ext_tool_open ( VikExtTool *self, VikWindow *vwindow )
208 VIK_EXT_TOOL_GET_CLASS( self )->open( self, vwindow );