]>
Commit | Line | Data |
---|---|---|
92806042 GB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifdef HAVE_CONFIG_H | |
23 | #include "config.h" | |
24 | #endif | |
25 | ||
26 | #include "vikexttool.h" | |
27 | ||
28 | #include <string.h> | |
29 | ||
30 | #include <glib/gi18n.h> | |
31 | ||
32 | static void ext_tool_class_init ( VikExtToolClass *klass ); | |
33 | static void ext_tool_init ( VikExtTool *vlp ); | |
34 | ||
35 | static GObjectClass *parent_class; | |
36 | ||
37 | static void ext_tool_finalize ( GObject *gob ); | |
38 | static gchar *ext_tool_get_label ( VikExtTool *vw ); | |
39 | ||
40 | typedef struct _VikExtToolPrivate VikExtToolPrivate; | |
41 | ||
42 | struct _VikExtToolPrivate | |
43 | { | |
44 | gint id; | |
45 | gchar *label; | |
46 | }; | |
47 | ||
48 | #define EXT_TOOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ | |
49 | VIK_EXT_TOOL_TYPE, \ | |
50 | VikExtToolPrivate)) | |
51 | ||
52 | GType vik_ext_tool_get_type() | |
53 | { | |
54 | static GType w_type = 0; | |
55 | ||
56 | if (!w_type) | |
57 | { | |
58 | static const GTypeInfo w_info = | |
59 | { | |
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), | |
67 | 0, | |
68 | (GInstanceInitFunc) ext_tool_init, | |
69 | }; | |
70 | w_type = g_type_register_static ( G_TYPE_OBJECT, "VikExtTool", &w_info, G_TYPE_FLAG_ABSTRACT ); | |
71 | } | |
72 | ||
73 | return w_type; | |
74 | } | |
75 | ||
76 | enum | |
77 | { | |
78 | PROP_0, | |
79 | ||
80 | PROP_ID, | |
81 | PROP_LABEL, | |
82 | }; | |
83 | ||
84 | static void | |
85 | ext_tool_set_property (GObject *object, | |
86 | guint property_id, | |
87 | const GValue *value, | |
88 | GParamSpec *pspec) | |
89 | { | |
90 | VikExtTool *self = VIK_EXT_TOOL (object); | |
91 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self); | |
92 | ||
93 | switch (property_id) | |
94 | { | |
95 | case PROP_ID: | |
96 | priv->id = g_value_get_uint (value); | |
97 | g_debug ("VikExtTool.id: %d", priv->id); | |
98 | break; | |
99 | ||
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; | |
105 | ||
106 | default: | |
107 | /* We don't have any other property... */ | |
108 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
109 | break; | |
110 | } | |
111 | } | |
112 | ||
113 | static void | |
114 | ext_tool_get_property (GObject *object, | |
115 | guint property_id, | |
116 | GValue *value, | |
117 | GParamSpec *pspec) | |
118 | { | |
119 | VikExtTool *self = VIK_EXT_TOOL (object); | |
120 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self); | |
121 | ||
122 | switch (property_id) | |
123 | { | |
124 | case PROP_ID: | |
125 | g_value_set_uint (value, priv->id); | |
126 | break; | |
127 | ||
128 | case PROP_LABEL: | |
129 | g_value_set_string (value, priv->label); | |
130 | break; | |
131 | ||
132 | default: | |
133 | /* We don't have any other property... */ | |
134 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
135 | break; | |
136 | } | |
137 | } | |
138 | ||
139 | static void ext_tool_class_init ( VikExtToolClass *klass ) | |
140 | { | |
141 | GObjectClass *gobject_class; | |
142 | GParamSpec *pspec; | |
143 | ||
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; | |
148 | ||
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); | |
157 | ||
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); | |
168 | ||
169 | klass->get_label = ext_tool_get_label; | |
170 | ||
171 | parent_class = g_type_class_peek_parent (klass); | |
172 | ||
173 | g_type_class_add_private (klass, sizeof (VikExtToolPrivate)); | |
174 | } | |
175 | ||
176 | VikExtTool *vik_ext_tool_new () | |
177 | { | |
178 | return VIK_EXT_TOOL ( g_object_new ( VIK_EXT_TOOL_TYPE, NULL ) ); | |
179 | } | |
180 | ||
181 | static void ext_tool_init ( VikExtTool *self ) | |
182 | { | |
183 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self); | |
184 | priv->label = NULL; | |
185 | } | |
186 | ||
187 | static void ext_tool_finalize ( GObject *gob ) | |
188 | { | |
189 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE ( gob ); | |
190 | g_free ( priv->label ); priv->label = NULL; | |
191 | G_OBJECT_CLASS(parent_class)->finalize(gob); | |
192 | } | |
193 | ||
194 | static gchar *ext_tool_get_label ( VikExtTool *self ) | |
195 | { | |
196 | VikExtToolPrivate *priv = NULL; | |
197 | priv = EXT_TOOL_GET_PRIVATE (self); | |
198 | return g_strdup ( priv->label ); | |
199 | } | |
200 | ||
201 | gchar *vik_ext_tool_get_label ( VikExtTool *w ) | |
202 | { | |
203 | return VIK_EXT_TOOL_GET_CLASS( w )->get_label( w ); | |
204 | } | |
205 | ||
206 | void vik_ext_tool_open ( VikExtTool *self, VikWindow *vwindow ) | |
207 | { | |
208 | VIK_EXT_TOOL_GET_CLASS( self )->open( self, vwindow ); | |
209 | } |