2
* Zapping (TV viewer for the Gnome Desktop)
4
* Copyright (C) 2001 I�aki Garc�a Etxebarria
5
* Copyright (C) 2003 Michael H. Schimek
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
/* $Id: subtitle.c,v 1.3 2004/11/03 06:42:17 mschimek Exp $ */
36
#ifndef ZVBI_CAPTION_DEBUG
37
#define ZVBI_CAPTION_DEBUG 0
41
caption_key = "/zapping/internal/callbacks/closed_caption";
43
/* used by osd.c; use py_closed_caption to change this var. */
44
vbi_pgno zvbi_caption_pgno = 0;
47
on_subtitle_menu_activate (GtkWidget * menu_item,
54
if (!(vbi = zvbi_get_object ()))
57
pgno = GPOINTER_TO_INT (user_data);
59
classf = vbi_classify_page (vbi, pgno, NULL, NULL);
61
if (VBI_SUBTITLE_PAGE == classf
62
|| (VBI_NORMAL_PAGE == classf
63
&& (pgno >= 5 && pgno <= 8)))
65
zvbi_caption_pgno = pgno;
67
python_command_printf (menu_item, "zapping.closed_caption(1)");
72
subtitles_uiinfo [] = {
74
GNOME_APP_UI_ITEM, N_("_Disable"), NULL,
75
G_CALLBACK (on_python_command1), "zapping.closed_caption(0)", NULL,
76
GNOME_APP_PIXMAP_NONE, NULL,
77
0, (GdkModifierType) 0, NULL
83
subtitle_menu_new (void)
90
if (!(vbi = zvbi_get_object ()))
93
menu = GTK_MENU_SHELL (gtk_menu_new ());
95
gnome_app_fill_menu (menu, subtitles_uiinfo,
102
for (pgno = 1; pgno <= 0x899;
103
pgno = (pgno == 8) ? 0x100 : vbi_add_bcd (pgno, 0x001))
105
vbi_page_type classf;
108
GtkWidget *menu_item;
110
classf = vbi_classify_page (vbi, pgno, NULL, &language);
112
if (classf != VBI_SUBTITLE_PAGE
113
&& (pgno > 8 || classf != VBI_NORMAL_PAGE))
117
language = g_convert (language, strlen (language),
118
"UTF-8", "ISO-8859-1",
125
if (classf == VBI_SUBTITLE_PAGE)
126
buffer = g_strdup_printf (("Caption %x - %s"),
129
buffer = g_strdup_printf (("Text %x - %s"),
133
if (classf == VBI_SUBTITLE_PAGE)
134
buffer = g_strdup_printf (("Caption %x"), pgno);
136
buffer = g_strdup_printf (("Text %x"), pgno - 4);
141
buffer = g_strdup (language);
143
buffer = g_strdup_printf (_("Page %x"), pgno);
146
menu_item = gtk_menu_item_new_with_label (buffer);
149
gtk_widget_show (menu_item);
151
if (pgno >= 0x100 && language)
155
g_snprintf (buffer, sizeof (buffer), "%x", pgno);
156
z_tooltip_set (menu_item, buffer);
159
g_signal_connect (G_OBJECT (menu_item), "activate",
160
G_CALLBACK (on_subtitle_menu_activate),
161
GINT_TO_POINTER (pgno));
164
gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
166
gtk_menu_shell_append (menu, menu_item);
173
return menu ? GTK_WIDGET (menu) : NULL;
177
find_subtitle_page (void)
182
if (!(vbi = zvbi_get_object ()))
185
for (pgno = 1; pgno <= 0x899;
186
pgno = (pgno == 4) ? 0x100 : vbi_add_bcd (pgno, 0x001))
188
vbi_page_type classf;
190
classf = vbi_classify_page (vbi, pgno, NULL, NULL);
192
if (VBI_SUBTITLE_PAGE == classf)
200
py_closed_caption (PyObject * self _unused_,
203
static int block = 0;
208
block = 1; /* XXX should be fixed elsewhere, toolbar button? */
210
active = -1; /* toggle */
212
if (!ParseTuple (args, "|i", &active))
213
g_error ("zapping.closed_caption(|i)");
216
active = !zconf_get_boolean (NULL, caption_key);
218
if (ZVBI_CAPTION_DEBUG)
219
fprintf (stderr, "CC active: %d\n", active);
221
zconf_set_boolean (active, caption_key);
228
/* In Teletext mode, overlay currently displayed page. */
229
if (/* have */ _teletext_view_from_widget
230
&& (view = _teletext_view_from_widget (GTK_WIDGET (zapping)))
231
&& 0 != (pgno = view->cur_pgno (view)))
233
zvbi_caption_pgno = pgno;
235
if (ZVBI_CAPTION_DEBUG)
236
fprintf (stderr, "CC Teletext pgno %x\n", zvbi_caption_pgno);
238
zmisc_restore_previous_mode (zapping->info);
240
/* In video mode, use previous page or find subtitles. */
241
else if (zvbi_caption_pgno <= 0)
243
zvbi_caption_pgno = find_subtitle_page ();
245
if (ZVBI_CAPTION_DEBUG)
246
fprintf (stderr, "CC lookup pgno %x\n", zvbi_caption_pgno);
248
if (zvbi_caption_pgno <= 0)
251
zconf_set_boolean (FALSE, caption_key);
256
if (ZVBI_CAPTION_DEBUG)
257
fprintf (stderr, "CC previous pgno %x\n", zvbi_caption_pgno);
271
shutdown_subtitle (void)
277
startup_subtitle (void)
279
zconf_create_boolean (FALSE, "Display subtitles", caption_key);
281
cmd_register ("closed_caption", py_closed_caption, METH_VARARGS,
282
("Closed Caption on/off"), "zapping.closed_caption()");
285
#else /* !HAVE_LIBZVBI */
288
subtitle_menu_new (void)
294
shutdown_subtitle (void)
299
startup_subtitle (void)
303
#endif /* !HAVE_LIBZVBI */