fix jsut committed crasher by rewriting startDrag action
[swfdec.git] / libswfdec / swfdec_system_as.c
blobf9e4e5bfd23cc2f191c799ff7cf0fe61b19f3a10
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_string.h"
26 #include "swfdec_as_strings.h"
27 #include "swfdec_codec_audio.h"
28 #include "swfdec_debug.h"
29 #include "swfdec_player_internal.h"
31 static void
32 swfdec_system_has_audio (SwfdecPlayer *player, SwfdecAsValue *ret)
34 /* FIXME: allow setting this? */
35 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
38 static void
39 swfdec_system_has_streaming_audio (SwfdecPlayer *player, SwfdecAsValue *ret)
41 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
44 static void
45 swfdec_system_has_streaming_video (SwfdecPlayer *player, SwfdecAsValue *ret)
47 /* FIXME: check if video decoders got compiled in? */
48 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
51 static void
52 swfdec_system_has_embedded_video (SwfdecPlayer *player, SwfdecAsValue *ret)
54 /* FIXME: what's this? */
55 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
58 static void
59 swfdec_system_has_mp3 (SwfdecPlayer *player, SwfdecAsValue *ret)
61 SwfdecAudioDecoder *dec = swfdec_audio_decoder_new (SWFDEC_AUDIO_FORMAT_MP3, TRUE, SWFDEC_AUDIO_OUT_STEREO_44100);
63 if (dec) {
64 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);
65 swfdec_audio_decoder_free (dec);
66 } else {
67 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
71 static void
72 swfdec_system_has_audio_encoder (SwfdecPlayer *player, SwfdecAsValue *ret)
74 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
77 static void
78 swfdec_system_has_video_encoder (SwfdecPlayer *player, SwfdecAsValue *ret)
80 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
83 static void
84 swfdec_system_has_accessibility (SwfdecPlayer *player, SwfdecAsValue *ret)
86 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
89 static void
90 swfdec_system_has_printing (SwfdecPlayer *player, SwfdecAsValue *ret)
92 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
95 static void
96 swfdec_system_has_screen_broadcast (SwfdecPlayer *player, SwfdecAsValue *ret)
98 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
101 static void
102 swfdec_system_has_screen_playback (SwfdecPlayer *player, SwfdecAsValue *ret)
104 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
107 static void
108 swfdec_system_is_debugger (SwfdecPlayer *player, SwfdecAsValue *ret)
110 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, player->system->debugger);
113 static void
114 swfdec_system_version (SwfdecPlayer *player, SwfdecAsValue *ret)
116 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
117 SWFDEC_AS_CONTEXT (player), player->system->version));
120 static void
121 swfdec_system_manufacturer (SwfdecPlayer *player, SwfdecAsValue *ret)
123 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
124 SWFDEC_AS_CONTEXT (player), player->system->manufacturer));
127 static void
128 swfdec_system_screen_width (SwfdecPlayer *player, SwfdecAsValue *ret)
130 SWFDEC_AS_VALUE_SET_INT (ret, player->system->screen_width);
133 static void
134 swfdec_system_screen_height (SwfdecPlayer *player, SwfdecAsValue *ret)
136 SWFDEC_AS_VALUE_SET_INT (ret, player->system->screen_height);
139 static void
140 swfdec_system_screen_dpi (SwfdecPlayer *player, SwfdecAsValue *ret)
142 SWFDEC_AS_VALUE_SET_INT (ret, player->system->dpi);
145 static void
146 swfdec_system_screen_color (SwfdecPlayer *player, SwfdecAsValue *ret)
148 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
149 SWFDEC_AS_CONTEXT (player), player->system->color_mode));
152 static void
153 swfdec_system_screen_par (SwfdecPlayer *player, SwfdecAsValue *ret)
155 SWFDEC_AS_VALUE_SET_NUMBER (ret, player->system->par);
158 static void
159 swfdec_system_os (SwfdecPlayer *player, SwfdecAsValue *ret)
161 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
162 SWFDEC_AS_CONTEXT (player), player->system->os));
165 static void
166 swfdec_system_language (SwfdecPlayer *player, SwfdecAsValue *ret)
168 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
169 SWFDEC_AS_CONTEXT (player), player->system->language));
172 static void
173 swfdec_system_has_ime (SwfdecPlayer *player, SwfdecAsValue *ret)
175 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
178 static void
179 swfdec_system_player_type (SwfdecPlayer *player, SwfdecAsValue *ret)
181 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
182 SWFDEC_AS_CONTEXT (player), player->system->player_type));
185 static void
186 swfdec_system_av_disabled (SwfdecPlayer *player, SwfdecAsValue *ret)
188 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
191 static void
192 swfdec_system_local_file_disabled (SwfdecPlayer *player, SwfdecAsValue *ret)
194 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
197 static void
198 swfdec_system_windowless_disabled (SwfdecPlayer *player, SwfdecAsValue *ret)
200 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
203 static void
204 swfdec_system_has_tls (SwfdecPlayer *player, SwfdecAsValue *ret)
206 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, FALSE);
209 /* NB: ordered for the query string order */
210 const struct {
211 const char * name;
212 const char * server_string;
213 void (* get) (SwfdecPlayer *player, SwfdecAsValue *ret);
214 } queries[] = {
215 { SWFDEC_AS_STR_hasAudio, "A", swfdec_system_has_audio },
216 { SWFDEC_AS_STR_hasStreamingAudio, "SA", swfdec_system_has_streaming_audio },
217 { SWFDEC_AS_STR_hasStreamingVideo, "SV", swfdec_system_has_streaming_video },
218 { SWFDEC_AS_STR_hasEmbeddedVideo, "SV", swfdec_system_has_embedded_video },
219 { SWFDEC_AS_STR_hasMP3, "MP3", swfdec_system_has_mp3 },
220 { SWFDEC_AS_STR_hasAudioEncoder, "AE", swfdec_system_has_audio_encoder },
221 { SWFDEC_AS_STR_hasVideoEncoder, "VE", swfdec_system_has_video_encoder },
222 { SWFDEC_AS_STR_hasAccessibility, "ACC", swfdec_system_has_accessibility },
223 { SWFDEC_AS_STR_hasPrinting, "PR", swfdec_system_has_printing },
224 { SWFDEC_AS_STR_hasScreenPlayback, "SP", swfdec_system_has_screen_playback },
225 { SWFDEC_AS_STR_hasScreenBroadcast, "SB", swfdec_system_has_screen_broadcast },
226 { SWFDEC_AS_STR_isDebugger, "DEB", swfdec_system_is_debugger },
227 { SWFDEC_AS_STR_version, "V", swfdec_system_version },
228 { SWFDEC_AS_STR_manufacturer, "M", swfdec_system_manufacturer },
229 { SWFDEC_AS_STR_screenResolutionX, "R", swfdec_system_screen_width },
230 { SWFDEC_AS_STR_screenResolutionY, NULL, swfdec_system_screen_height },
231 { SWFDEC_AS_STR_screenDPI, "DP", swfdec_system_screen_dpi },
232 { SWFDEC_AS_STR_screenColor, "COL", swfdec_system_screen_color },
233 { SWFDEC_AS_STR_pixelAspectRatio, NULL, swfdec_system_screen_par },
234 { SWFDEC_AS_STR_os, "OS", swfdec_system_os },
235 { SWFDEC_AS_STR_language, "L", swfdec_system_language },
236 { SWFDEC_AS_STR_hasIME, "IME", swfdec_system_has_ime },
237 { SWFDEC_AS_STR_playerType, "PT", swfdec_system_player_type },
238 { SWFDEC_AS_STR_avHardwareDisable, "AVD", swfdec_system_av_disabled },
239 { SWFDEC_AS_STR_localFileReadDisable, "LFD", swfdec_system_local_file_disabled },
240 { SWFDEC_AS_STR_windowlessDisable, "WD", swfdec_system_windowless_disabled },
241 { SWFDEC_AS_STR_hasTLS, "TLS", swfdec_system_has_tls },
244 SWFDEC_AS_NATIVE (11, 0, swfdec_system_query)
245 void
246 swfdec_system_query (SwfdecAsContext *cx, SwfdecAsObject *object,
247 guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
249 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
250 SwfdecAsValue val;
251 guint i;
252 GString *server;
254 if (object == NULL) {
255 SWFDEC_WARNING ("no this object in Query()");
256 return;
259 server = g_string_new ("");
260 for (i = 0; i < G_N_ELEMENTS (queries); i++) {
261 queries[i].get (player, &val);
262 swfdec_as_object_set_variable (object, queries[i].name, &val);
263 if (queries[i].name == SWFDEC_AS_STR_screenResolutionY) {
264 g_string_append_printf (server, "x%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (&val));
265 } else if (queries[i].name == SWFDEC_AS_STR_pixelAspectRatio) {
266 g_string_append_printf (server, "&AR=%.1g", SWFDEC_AS_VALUE_GET_NUMBER (&val));
267 } else {
268 g_assert (queries[i].server_string);
269 if (i > 0)
270 g_string_append_c (server, '&');
271 g_string_append (server, queries[i].server_string);
272 g_string_append_c (server, '=');
273 if (SWFDEC_AS_VALUE_IS_BOOLEAN (&val)) {
274 g_string_append_c (server, SWFDEC_AS_VALUE_GET_BOOLEAN (&val) ? 't' : 'f');
275 } else if (SWFDEC_AS_VALUE_IS_NUMBER (&val)) {
276 g_string_append_printf (server, "%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (&val));
277 } else if (SWFDEC_AS_VALUE_IS_STRING (&val)) {
278 char *s = swfdec_as_string_escape (cx, SWFDEC_AS_VALUE_GET_STRING (&val));
279 g_string_append (server, s);
280 g_free (s);
281 } else {
282 g_assert_not_reached ();
286 SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, g_string_free (server, FALSE)));
287 swfdec_as_object_set_variable (object, SWFDEC_AS_STR_serverString, &val);