oops, I shifted the wrong value.
[swfdec.git] / swfdec / swfdec_system.c
blobc61329c79260258c7708e239dd895f38929a2358
1 /* Swfdec
2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "swfdec_system.h"
25 #include "swfdec_debug.h"
27 /*** gtk-doc ***/
29 /**
30 * SECTION:SwfdecSystem
31 * @title: SwfdecSystem
32 * @short_description: object holding system settings
33 * @see_also: SwfdecPlayer
35 * This object is used to provide information about the system Swfdec currently
36 * runs on.
38 * Almost all of this information can be categorized into three types:
39 * Information about the current playback engine like manufacturer or version,
40 * information about the current operating system and capabilities of the output
41 * capabilities of the System like screen size.
43 * The information provided by this object is used by the Actionscript
44 * System.capabilities.Query() function that is usually only run once during
45 * initialization of the Flash player. If you want to set custom properties and
46 * have them affect a running #SwfdecPlayer, you should change them before the
47 * player gets initialized.
49 * Note that the System.capabilites object in Flash provides more functionality
50 * than provided by this object. That information can be and is determined
51 * automatically by Swfdec.
54 /**
55 * SwfdecSystem:
57 * This is the object used for holding information about the current system. See
58 * the introduction for details.
61 /*** SwfdecSystem ***/
63 enum {
64 PROP_0,
65 PROP_DEBUGGER,
66 PROP_MANUFACTURER,
67 PROP_SERVER_MANUFACTURER,
68 PROP_OS,
69 PROP_OS_TYPE,
70 PROP_PLAYER_TYPE,
71 PROP_VERSION,
72 PROP_LANGUAGE,
73 PROP_SCREEN_WIDTH,
74 PROP_SCREEN_HEIGHT,
75 PROP_PAR,
76 PROP_DPI,
77 PROP_COLOR_MODE,
78 PROP_UTC_OFFSET
81 G_DEFINE_TYPE (SwfdecSystem, swfdec_system, G_TYPE_OBJECT)
83 static void
84 swfdec_system_get_property (GObject *object, guint param_id, GValue *value,
85 GParamSpec * pspec)
87 SwfdecSystem *system = SWFDEC_SYSTEM (object);
89 switch (param_id) {
90 case PROP_DEBUGGER:
91 g_value_set_boolean (value, system->debugger);
92 break;
93 case PROP_MANUFACTURER:
94 g_value_set_string (value, system->manufacturer);
95 break;
96 case PROP_SERVER_MANUFACTURER:
97 g_value_set_string (value, system->server_manufacturer);
98 break;
99 case PROP_OS:
100 g_value_set_string (value, system->os);
101 break;
102 case PROP_OS_TYPE:
103 g_value_set_string (value, system->os_type);
104 break;
105 case PROP_PLAYER_TYPE:
106 g_value_set_string (value, system->player_type);
107 break;
108 case PROP_VERSION:
109 g_value_set_string (value, system->version);
110 break;
111 case PROP_LANGUAGE:
112 g_value_set_string (value, system->language);
113 break;
114 case PROP_SCREEN_WIDTH:
115 g_value_set_uint (value, system->screen_width);
116 break;
117 case PROP_SCREEN_HEIGHT:
118 g_value_set_uint (value, system->screen_height);
119 break;
120 case PROP_PAR:
121 g_value_set_double (value, system->par);
122 break;
123 case PROP_DPI:
124 g_value_set_uint (value, system->dpi);
125 break;
126 case PROP_COLOR_MODE:
127 g_value_set_string (value, system->color_mode);
128 break;
129 case PROP_UTC_OFFSET:
130 g_value_set_int (value, system->utc_offset);
131 break;
132 default:
133 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
134 break;
138 static void
139 swfdec_system_set_property (GObject *object, guint param_id, const GValue *value,
140 GParamSpec *pspec)
142 SwfdecSystem *system = SWFDEC_SYSTEM (object);
143 char *s;
145 switch (param_id) {
146 case PROP_DEBUGGER:
147 system->debugger = g_value_get_boolean (value);
148 break;
149 case PROP_MANUFACTURER:
150 s = g_value_dup_string (value);
151 if (s) {
152 g_free (system->manufacturer);
153 system->manufacturer = s;
155 break;
156 case PROP_SERVER_MANUFACTURER:
157 s = g_value_dup_string (value);
158 if (s) {
159 g_free (system->server_manufacturer);
160 system->server_manufacturer = s;
162 break;
163 case PROP_OS:
164 s = g_value_dup_string (value);
165 if (s) {
166 g_free (system->os);
167 system->os = s;
169 break;
170 case PROP_OS_TYPE:
171 s = g_value_dup_string (value);
172 if (s) {
173 g_free (system->os_type);
174 system->os_type = s;
176 break;
177 case PROP_PLAYER_TYPE:
178 s = g_value_dup_string (value);
179 if (s) {
180 g_free (system->player_type);
181 system->player_type = s;
183 break;
184 case PROP_VERSION:
185 s = g_value_dup_string (value);
186 if (s) {
187 g_free (system->version);
188 system->version = s;
190 break;
191 case PROP_LANGUAGE:
192 s = g_value_dup_string (value);
193 if (s) {
194 g_free (system->language);
195 system->language = s;
197 break;
198 case PROP_SCREEN_WIDTH:
199 system->screen_width = g_value_get_uint (value);
200 break;
201 case PROP_SCREEN_HEIGHT:
202 system->screen_height = g_value_get_uint (value);
203 break;
204 case PROP_PAR:
205 system->par = g_value_get_double (value);
206 break;
207 case PROP_DPI:
208 system->dpi = g_value_get_uint (value);
209 break;
210 case PROP_COLOR_MODE:
211 s = g_value_dup_string (value);
212 if (s) {
213 g_free (system->color_mode);
214 system->color_mode = s;
216 break;
217 case PROP_UTC_OFFSET:
218 system->utc_offset = g_value_get_int (value);
219 break;
220 default:
221 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
222 break;
226 static void
227 swfdec_system_finalize (GObject *object)
229 SwfdecSystem *system = SWFDEC_SYSTEM (object);
231 g_free (system->manufacturer);
232 g_free (system->server_manufacturer);
233 g_free (system->os);
234 g_free (system->os_type);
235 g_free (system->player_type);
236 g_free (system->version);
237 g_free (system->language);
238 g_free (system->color_mode);
240 G_OBJECT_CLASS (swfdec_system_parent_class)->finalize (object);
243 static void
244 swfdec_system_class_init (SwfdecSystemClass *klass)
246 GObjectClass *object_class = G_OBJECT_CLASS (klass);
248 object_class->finalize = swfdec_system_finalize;
249 object_class->get_property = swfdec_system_get_property;
250 object_class->set_property = swfdec_system_set_property;
252 g_object_class_install_property (object_class, PROP_DEBUGGER,
253 g_param_spec_boolean ("debugger", "debugger", "TRUE if this player is supposed to be a debugger",
254 FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
255 g_object_class_install_property (object_class, PROP_MANUFACTURER,
256 g_param_spec_string ("manufacturer", "manufacturer", "string describing the manufacturer of this system",
257 "Macromedia Windows", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
258 g_object_class_install_property (object_class, PROP_SERVER_MANUFACTURER,
259 g_param_spec_string ("server-manufacturer", "server-manufacturer", "manufacturer of this system as used in serverString",
260 "Adobe Windows", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
261 g_object_class_install_property (object_class, PROP_OS,
262 g_param_spec_string ("os", "os", "description of the operating system",
263 "Windows XP", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
264 g_object_class_install_property (object_class, PROP_OS_TYPE,
265 g_param_spec_string ("os-type", "os type", "the operating system type: WIN, LIN or MAC",
266 "WIN", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
267 g_object_class_install_property (object_class, PROP_PLAYER_TYPE,
268 g_param_spec_string ("player-type", "player type", "\"StandAlone\", \"External\", \"PlugIn\" or \"ActiveX\"",
269 "StandAlone", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
270 g_object_class_install_property (object_class, PROP_VERSION,
271 g_param_spec_string ("version", "version", "version string",
272 "WIN 9,0,999,0", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
273 g_object_class_install_property (object_class, PROP_LANGUAGE,
274 g_param_spec_string ("language", "language", "ISO 639-1 language code",
275 "en", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
276 g_object_class_install_property (object_class, PROP_SCREEN_WIDTH,
277 g_param_spec_uint ("screen-width", "screen width", "width of the screen in pixels",
278 0, G_MAXUINT, 1024, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
279 g_object_class_install_property (object_class, PROP_SCREEN_HEIGHT,
280 g_param_spec_uint ("screen-height", "screen height", "height of the screen in pixels",
281 0, G_MAXUINT, 768, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
282 g_object_class_install_property (object_class, PROP_PAR,
283 g_param_spec_double ("pixel-aspect-ratio", "pixel aspect ratio", "the screen's pixel aspect ratio",
284 G_MINDOUBLE, G_MAXDOUBLE, 1.0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
285 g_object_class_install_property (object_class, PROP_DPI,
286 g_param_spec_uint ("dpi", "dpi", "DPI setting of screen",
287 0, G_MAXUINT, 96, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
288 g_object_class_install_property (object_class, PROP_COLOR_MODE,
289 g_param_spec_string ("color-mode", "color mode", "\"color\", \"gray\" or \"bw\"",
290 "color", G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
291 g_object_class_install_property (object_class, PROP_UTC_OFFSET,
292 g_param_spec_int ("utc-offset", "utc offset",
293 "Difference between UTC and local timezone in minutes",
294 -12 * 60, 12 * 60, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
297 static void
298 swfdec_system_init (SwfdecSystem *system)
303 * swfdec_system_new:
305 * Creates a new #SwfdecSystem object using default settings. These settings are
306 * mirroring the most common settings used by a Flash player. Currently this is
307 * equivalent to a Flash player running on Windows XP.
309 * Returns: a new #SwfdecSystem object
311 SwfdecSystem *
312 swfdec_system_new (void)
314 return g_object_new (SWFDEC_TYPE_SYSTEM, NULL);