Fix few bugs in SwfdecGtkSocket that made it unusable
[swfdec.git] / swfdec / swfdec_system_as.c
bloba385060d43dc5d1b56f42ea30091e89abebe0803
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.h"
25 #include "swfdec_as_internal.h"
26 #include "swfdec_as_string.h"
27 #include "swfdec_as_strings.h"
28 #include "swfdec_audio_decoder.h"
29 #include "swfdec_debug.h"
30 #include "swfdec_player_internal.h"
32 SWFDEC_AS_NATIVE (1066, 0, swfdec_system_setClipboard)
33 void
34 swfdec_system_setClipboard (SwfdecAsContext *cx, SwfdecAsObject *object,
35 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
37 SWFDEC_STUB ("System.setClipboard (static)");
40 SWFDEC_AS_NATIVE (2107, 0, swfdec_system_showSettings)
41 void
42 swfdec_system_showSettings (SwfdecAsContext *cx, SwfdecAsObject *object,
43 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
45 SWFDEC_STUB ("System.showSettings (static)");
48 SWFDEC_AS_NATIVE (2107, 1, swfdec_system_get_exactSettings)
49 void
50 swfdec_system_get_exactSettings (SwfdecAsContext *cx, SwfdecAsObject *object,
51 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
53 SWFDEC_STUB ("System.exactSettings (static, get)");
56 SWFDEC_AS_NATIVE (2107, 2, swfdec_system_set_exactSettings)
57 void
58 swfdec_system_set_exactSettings (SwfdecAsContext *cx, SwfdecAsObject *object,
59 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
61 SWFDEC_STUB ("System.exactSettings (static, set)");
64 SWFDEC_AS_NATIVE (2107, 3, swfdec_system_get_useCodepage)
65 void
66 swfdec_system_get_useCodepage (SwfdecAsContext *cx, SwfdecAsObject *object,
67 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
69 SWFDEC_STUB ("System.useCodepage (static, get)");
72 SWFDEC_AS_NATIVE (2107, 4, swfdec_system_set_useCodepage)
73 void
74 swfdec_system_set_useCodepage (SwfdecAsContext *cx, SwfdecAsObject *object,
75 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
77 SWFDEC_STUB ("System.useCodepage (static, set)");
80 static void
81 swfdec_system_has_audio (SwfdecPlayer *player, SwfdecAsValue *ret)
83 /* FIXME: allow setting this? */
84 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
87 static void
88 swfdec_system_has_streaming_audio (SwfdecPlayer *player, SwfdecAsValue *ret)
90 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
93 static void
94 swfdec_system_has_streaming_video (SwfdecPlayer *player, SwfdecAsValue *ret)
96 /* FIXME: check if video decoders got compiled in? */
97 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
100 static void
101 swfdec_system_has_embedded_video (SwfdecPlayer *player, SwfdecAsValue *ret)
103 /* FIXME: what's this? */
104 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
107 static void
108 swfdec_system_has_mp3 (SwfdecPlayer *player, SwfdecAsValue *ret)
110 gboolean result = swfdec_audio_decoder_prepare (SWFDEC_AUDIO_CODEC_MP3,
111 swfdec_audio_format_new (44100, 2, TRUE), NULL);
113 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, result);
116 static void
117 swfdec_system_has_audio_encoder (SwfdecPlayer *player, SwfdecAsValue *ret)
119 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
122 static void
123 swfdec_system_has_video_encoder (SwfdecPlayer *player, SwfdecAsValue *ret)
125 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
128 static void
129 swfdec_system_has_accessibility (SwfdecPlayer *player, SwfdecAsValue *ret)
131 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
134 static void
135 swfdec_system_has_printing (SwfdecPlayer *player, SwfdecAsValue *ret)
137 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
140 static void
141 swfdec_system_has_screen_broadcast (SwfdecPlayer *player, SwfdecAsValue *ret)
143 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
146 static void
147 swfdec_system_has_screen_playback (SwfdecPlayer *player, SwfdecAsValue *ret)
149 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
152 static void
153 swfdec_system_is_debugger (SwfdecPlayer *player, SwfdecAsValue *ret)
155 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, player->priv->system->debugger);
158 static void
159 swfdec_system_version (SwfdecPlayer *player, SwfdecAsValue *ret)
161 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
162 SWFDEC_AS_CONTEXT (player), player->priv->system->version));
165 static void
166 swfdec_system_manufacturer (SwfdecPlayer *player, SwfdecAsValue *ret)
168 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
169 SWFDEC_AS_CONTEXT (player), player->priv->system->manufacturer));
172 static void
173 swfdec_system_screen_width (SwfdecPlayer *player, SwfdecAsValue *ret)
175 SWFDEC_AS_VALUE_SET_INT (ret, player->priv->system->screen_width);
178 static void
179 swfdec_system_screen_height (SwfdecPlayer *player, SwfdecAsValue *ret)
181 SWFDEC_AS_VALUE_SET_INT (ret, player->priv->system->screen_height);
184 static void
185 swfdec_system_screen_dpi (SwfdecPlayer *player, SwfdecAsValue *ret)
187 SWFDEC_AS_VALUE_SET_INT (ret, player->priv->system->dpi);
190 static void
191 swfdec_system_screen_color (SwfdecPlayer *player, SwfdecAsValue *ret)
193 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
194 SWFDEC_AS_CONTEXT (player), player->priv->system->color_mode));
197 static void
198 swfdec_system_screen_par (SwfdecPlayer *player, SwfdecAsValue *ret)
200 SWFDEC_AS_VALUE_SET_NUMBER (ret, player->priv->system->par);
203 static void
204 swfdec_system_os (SwfdecPlayer *player, SwfdecAsValue *ret)
206 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
207 SWFDEC_AS_CONTEXT (player), player->priv->system->os));
210 static void
211 swfdec_system_language (SwfdecPlayer *player, SwfdecAsValue *ret)
213 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
214 SWFDEC_AS_CONTEXT (player), player->priv->system->language));
217 static void
218 swfdec_system_has_ime (SwfdecPlayer *player, SwfdecAsValue *ret)
220 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
223 static void
224 swfdec_system_player_type (SwfdecPlayer *player, SwfdecAsValue *ret)
226 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
227 SWFDEC_AS_CONTEXT (player), player->priv->system->player_type));
230 static void
231 swfdec_system_av_disabled (SwfdecPlayer *player, SwfdecAsValue *ret)
233 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
236 static void
237 swfdec_system_local_file_disabled (SwfdecPlayer *player, SwfdecAsValue *ret)
239 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
242 static void
243 swfdec_system_windowless_disabled (SwfdecPlayer *player, SwfdecAsValue *ret)
245 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
248 static void
249 swfdec_system_has_tls (SwfdecPlayer *player, SwfdecAsValue *ret)
251 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
254 /* NB: ordered for the query string order */
255 const struct {
256 const char * name;
257 const char * server_string;
258 void (* get) (SwfdecPlayer *player, SwfdecAsValue *ret);
259 } queries[] = {
260 { SWFDEC_AS_STR_hasAudio, "A", swfdec_system_has_audio },
261 { SWFDEC_AS_STR_hasStreamingAudio, "SA", swfdec_system_has_streaming_audio },
262 { SWFDEC_AS_STR_hasStreamingVideo, "SV", swfdec_system_has_streaming_video },
263 { SWFDEC_AS_STR_hasEmbeddedVideo, "EV", swfdec_system_has_embedded_video },
264 { SWFDEC_AS_STR_hasMP3, "MP3", swfdec_system_has_mp3 },
265 { SWFDEC_AS_STR_hasAudioEncoder, "AE", swfdec_system_has_audio_encoder },
266 { SWFDEC_AS_STR_hasVideoEncoder, "VE", swfdec_system_has_video_encoder },
267 { SWFDEC_AS_STR_hasAccessibility, "ACC", swfdec_system_has_accessibility },
268 { SWFDEC_AS_STR_hasPrinting, "PR", swfdec_system_has_printing },
269 { SWFDEC_AS_STR_hasScreenPlayback, "SP", swfdec_system_has_screen_playback },
270 { SWFDEC_AS_STR_hasScreenBroadcast, "SB", swfdec_system_has_screen_broadcast },
271 { SWFDEC_AS_STR_isDebugger, "DEB", swfdec_system_is_debugger },
272 { SWFDEC_AS_STR_version, "V", swfdec_system_version },
273 { SWFDEC_AS_STR_manufacturer, NULL, swfdec_system_manufacturer },
274 { SWFDEC_AS_STR_screenResolutionX, "R", swfdec_system_screen_width },
275 { SWFDEC_AS_STR_screenResolutionY, NULL, swfdec_system_screen_height },
276 { SWFDEC_AS_STR_screenDPI, "DP", swfdec_system_screen_dpi },
277 { SWFDEC_AS_STR_screenColor, "COL", swfdec_system_screen_color },
278 { SWFDEC_AS_STR_pixelAspectRatio, NULL, swfdec_system_screen_par },
279 { SWFDEC_AS_STR_os, "OS", swfdec_system_os },
280 { SWFDEC_AS_STR_language, "L", swfdec_system_language },
281 { SWFDEC_AS_STR_hasIME, "IME", swfdec_system_has_ime },
282 { SWFDEC_AS_STR_playerType, "PT", swfdec_system_player_type },
283 { SWFDEC_AS_STR_avHardwareDisable, "AVD", swfdec_system_av_disabled },
284 { SWFDEC_AS_STR_localFileReadDisable, "LFD", swfdec_system_local_file_disabled },
285 { SWFDEC_AS_STR_windowlessDisable, "WD", swfdec_system_windowless_disabled },
286 { SWFDEC_AS_STR_hasTLS, "TLS", swfdec_system_has_tls },
289 SWFDEC_AS_NATIVE (11, 0, swfdec_system_query)
290 void
291 swfdec_system_query (SwfdecAsContext *cx, SwfdecAsObject *object,
292 guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
294 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
295 SwfdecAsValue val;
296 guint i;
297 GString *server;
299 if (object == NULL) {
300 SWFDEC_WARNING ("no this object in Query()");
301 return;
304 server = g_string_new ("");
305 for (i = 0; i < G_N_ELEMENTS (queries); i++) {
306 queries[i].get (player, &val);
307 swfdec_as_object_set_variable (object, queries[i].name, &val);
308 if (queries[i].name == SWFDEC_AS_STR_screenResolutionY) {
309 g_string_append_printf (server, "x%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (&val));
310 } else if (queries[i].name == SWFDEC_AS_STR_pixelAspectRatio) {
311 char buffer[10];
312 g_ascii_formatd (buffer, sizeof (buffer), "%.1f",
313 SWFDEC_AS_VALUE_GET_NUMBER (&val));
314 g_string_append (server, "&AR=");
315 g_string_append (server, buffer);
316 } else if (queries[i].name == SWFDEC_AS_STR_manufacturer) {
317 char *s = swfdec_as_string_escape (cx, player->priv->system->server_manufacturer);
318 g_string_append_printf (server, "&M=%s", s);
319 g_free (s);
320 } else {
321 g_assert (queries[i].server_string);
322 if (i > 0)
323 g_string_append_c (server, '&');
324 g_string_append (server, queries[i].server_string);
325 g_string_append_c (server, '=');
326 if (SWFDEC_AS_VALUE_IS_BOOLEAN (&val)) {
327 g_string_append_c (server, SWFDEC_AS_VALUE_GET_BOOLEAN (&val) ? 't' : 'f');
328 } else if (SWFDEC_AS_VALUE_IS_NUMBER (&val)) {
329 g_string_append_printf (server, "%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (&val));
330 } else if (SWFDEC_AS_VALUE_IS_STRING (&val)) {
331 char *s = swfdec_as_string_escape (cx, SWFDEC_AS_VALUE_GET_STRING (&val));
332 g_string_append (server, s);
333 g_free (s);
334 } else {
335 g_assert_not_reached ();
339 SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, g_string_free (server, FALSE)));
340 swfdec_as_object_set_variable (object, SWFDEC_AS_STR_serverString, &val);