]>
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 | ||
92806042 GB |
32 | static GObjectClass *parent_class; |
33 | ||
34 | static void ext_tool_finalize ( GObject *gob ); | |
35 | static gchar *ext_tool_get_label ( VikExtTool *vw ); | |
36 | ||
37 | typedef struct _VikExtToolPrivate VikExtToolPrivate; | |
38 | ||
39 | struct _VikExtToolPrivate | |
40 | { | |
41 | gint id; | |
42 | gchar *label; | |
43 | }; | |
44 | ||
45 | #define EXT_TOOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ | |
46 | VIK_EXT_TOOL_TYPE, \ | |
47 | VikExtToolPrivate)) | |
48 | ||
c1644367 | 49 | G_DEFINE_ABSTRACT_TYPE (VikExtTool, vik_ext_tool, G_TYPE_OBJECT) |
92806042 GB |
50 | |
51 | enum | |
52 | { | |
53 | PROP_0, | |
54 | ||
55 | PROP_ID, | |
56 | PROP_LABEL, | |
57 | }; | |
58 | ||
59 | static void | |
60 | ext_tool_set_property (GObject *object, | |
61 | guint property_id, | |
62 | const GValue *value, | |
63 | GParamSpec *pspec) | |
64 | { | |
65 | VikExtTool *self = VIK_EXT_TOOL (object); | |
66 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self); | |
67 | ||
68 | switch (property_id) | |
69 | { | |
70 | case PROP_ID: | |
71 | priv->id = g_value_get_uint (value); | |
72 | g_debug ("VikExtTool.id: %d", priv->id); | |
73 | break; | |
74 | ||
75 | case PROP_LABEL: | |
76 | g_free (priv->label); | |
77 | priv->label = g_value_dup_string (value); | |
78 | g_debug ("VikExtTool.label: %s", priv->label); | |
79 | break; | |
80 | ||
81 | default: | |
82 | /* We don't have any other property... */ | |
83 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
84 | break; | |
85 | } | |
86 | } | |
87 | ||
88 | static void | |
89 | ext_tool_get_property (GObject *object, | |
90 | guint property_id, | |
91 | GValue *value, | |
92 | GParamSpec *pspec) | |
93 | { | |
94 | VikExtTool *self = VIK_EXT_TOOL (object); | |
95 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self); | |
96 | ||
97 | switch (property_id) | |
98 | { | |
99 | case PROP_ID: | |
100 | g_value_set_uint (value, priv->id); | |
101 | break; | |
102 | ||
103 | case PROP_LABEL: | |
104 | g_value_set_string (value, priv->label); | |
105 | break; | |
106 | ||
107 | default: | |
108 | /* We don't have any other property... */ | |
109 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
110 | break; | |
111 | } | |
112 | } | |
113 | ||
c1644367 | 114 | static void vik_ext_tool_class_init ( VikExtToolClass *klass ) |
92806042 GB |
115 | { |
116 | GObjectClass *gobject_class; | |
117 | GParamSpec *pspec; | |
118 | ||
119 | gobject_class = G_OBJECT_CLASS (klass); | |
120 | gobject_class->finalize = ext_tool_finalize; | |
121 | gobject_class->set_property = ext_tool_set_property; | |
122 | gobject_class->get_property = ext_tool_get_property; | |
123 | ||
124 | pspec = g_param_spec_string ("label", | |
125 | "Label", | |
126 | "Set the label", | |
127 | "<no-set>" /* default value */, | |
128 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
129 | g_object_class_install_property (gobject_class, | |
130 | PROP_LABEL, | |
131 | pspec); | |
132 | ||
133 | pspec = g_param_spec_uint ("id", | |
134 | "Id of the tool", | |
135 | "Set the id", | |
136 | 0 /* minimum value */, | |
137 | G_MAXUINT16 /* maximum value */, | |
138 | 0 /* default value */, | |
139 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
140 | g_object_class_install_property (gobject_class, | |
141 | PROP_ID, | |
142 | pspec); | |
143 | ||
144 | klass->get_label = ext_tool_get_label; | |
145 | ||
146 | parent_class = g_type_class_peek_parent (klass); | |
147 | ||
148 | g_type_class_add_private (klass, sizeof (VikExtToolPrivate)); | |
149 | } | |
150 | ||
c1644367 | 151 | static void vik_ext_tool_init ( VikExtTool *self ) |
92806042 GB |
152 | { |
153 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self); | |
154 | priv->label = NULL; | |
155 | } | |
156 | ||
157 | static void ext_tool_finalize ( GObject *gob ) | |
158 | { | |
159 | VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE ( gob ); | |
160 | g_free ( priv->label ); priv->label = NULL; | |
161 | G_OBJECT_CLASS(parent_class)->finalize(gob); | |
162 | } | |
163 | ||
164 | static gchar *ext_tool_get_label ( VikExtTool *self ) | |
165 | { | |
166 | VikExtToolPrivate *priv = NULL; | |
167 | priv = EXT_TOOL_GET_PRIVATE (self); | |
168 | return g_strdup ( priv->label ); | |
169 | } | |
170 | ||
171 | gchar *vik_ext_tool_get_label ( VikExtTool *w ) | |
172 | { | |
173 | return VIK_EXT_TOOL_GET_CLASS( w )->get_label( w ); | |
174 | } | |
175 | ||
176 | void vik_ext_tool_open ( VikExtTool *self, VikWindow *vwindow ) | |
177 | { | |
178 | VIK_EXT_TOOL_GET_CLASS( self )->open( self, vwindow ); | |
179 | } |