From: Darren S. <ds...@us...> - 2004-11-08 01:47:18
|
Update of /cvsroot/xine/gnome-xine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20504/src Modified Files: noskin_window.c utils.c utils.h Log Message: Add code to update play, pause etc. on a UI status update, and to handle UI status updates. Make speaker icon into a button. Index: noskin_window.c =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/noskin_window.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- noskin_window.c 3 Nov 2004 19:47:35 -0000 1.20 +++ noskin_window.c 8 Nov 2004 01:47:09 -0000 1.21 @@ -33,6 +33,7 @@ #include "utils.h" #include "engine.h" #include "key_events.h" +#include "player.h" #include "playlist.h" #include "mediamarks.h" #include "menu.h" @@ -62,6 +63,13 @@ static int no_rekursion; /* seeker */ static int have_video = 1; +#define PLAY 0 +#define FFWD 1 +#define PAUS 2 +#define STOP 3 +#define CONTROLS 4 + +static GtkWidget *controls[CONTROLS], *speaker; /* * callbacks */ @@ -70,7 +78,11 @@ char *cmd = (char *) data; - engine_exec (cmd, NULL, NULL); + if (!pthread_mutex_trylock (&status_lock)) + { + pthread_mutex_unlock (&status_lock); + engine_exec (cmd, NULL, NULL); + } /* take focus away from this button (pressing 'space' for pause tends to behave strangely otherwise */ @@ -78,12 +90,30 @@ } -void add_pix_button(GtkWidget *box, gchar **pixmap_array, char * cmd, char *tip) { +static void toggle_cb (GtkToggleButton *button, gpointer data) +{ + if (pthread_mutex_trylock (&status_lock)) + return; + pthread_mutex_unlock (&status_lock); + ui_set_status (UI_CURRENT_STATE); +} + +static GtkWidget *add_pix_button (GtkWidget *box, gchar **pixmap_array, + char * cmd, char *tip, gboolean toggle, + gboolean start) +{ GtkWidget *button, *icon; GdkPixmap *image; GdkBitmap *transparent; - button = gtk_button_new(); + if (toggle) + { + button = gtk_toggle_button_new (); + g_signal_connect (GTK_OBJECT(button), "toggled", + G_CALLBACK(toggle_cb), NULL); + } + else + button = gtk_button_new (); gtk_button_set_relief (GTK_BUTTON(button), GTK_RELIEF_NONE); image = gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_colormap_get_system(), &transparent, NULL, pixmap_array); @@ -91,7 +121,10 @@ gtk_container_add(GTK_CONTAINER(button), icon); /* gtk_container_add(GTK_CONTAINER(box), button); */ - gtk_box_pack_start (GTK_BOX(box), button, FALSE, FALSE, 2); + if (start) + gtk_box_pack_start (GTK_BOX(box), button, FALSE, FALSE, 2); + else + gtk_box_pack_end (GTK_BOX(box), button, FALSE, FALSE, 2); g_signal_connect (GTK_OBJECT(button), "clicked", G_CALLBACK(control_cb), @@ -102,6 +135,8 @@ gtk_widget_show(icon); gtk_widget_show(button); + + return button; } /* @@ -173,6 +208,45 @@ return(FALSE); } +void window_set_status (ui_status_t status) +{ + char states[CONTROLS] = { 0 }; + int live = player_live_stream (); + int i; + + switch (status) + { + case UI_STOP: states[STOP] = 1; break; + case UI_PAUSE: states[PAUS] = 1; break; + case UI_PLAY_SLOW: states[PLAY] = states[PAUS] = 1; break; + case UI_PLAY: states[PLAY] = 1; break; + case UI_FAST_FORWARD: states[FFWD] = 1; break; + default:; + } + + for (i = 0; i < CONTROLS; ++i) + { + gtk_widget_set_sensitive (controls[i], FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(controls[i]), states[i]); + if (!live || (i != PAUS && i != FFWD)) + gtk_widget_set_sensitive (controls[i], TRUE); + } +} + +void window_set_mute (int mute) +{ + gtk_widget_set_sensitive (speaker, FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(speaker), !mute); + gtk_widget_set_sensitive (speaker, TRUE); +} + +static void noskin_main_init_cb (void) +{ + ui_set_status (xine_get_param (stream, XINE_PARAM_AUDIO_MUTE) + ? UI_AUDIO_MUTE : UI_AUDIO_UNMUTE); +// engine_exec ("set_mute (get_mute ())", NULL, NULL); +} + void noskin_main_init (void) { GtkWidget *vbox; @@ -189,9 +263,7 @@ GtkWidget *ctrl; /* GtkWidget *menu, *item; */ - GtkWidget *audio_spinner, *icon; - GdkPixmap *image; - GdkBitmap *transparent; + GtkWidget *audio_spinner; time_widget_t *time_widget; @@ -285,12 +357,20 @@ /* buttons */ - add_pix_button (ctrl, play_xpm, "play ();", "play"); - add_pix_button (ctrl, fast_forward_xpm, "set_speed (16);", "fast-forward"); - add_pix_button (ctrl, pause_xpm, "pause ();", "pause"); - add_pix_button (ctrl, stop_xpm, "stop ();", "stop"); - add_pix_button (ctrl, playlist_xpm, "playlist_show ()", "playlist"); - add_pix_button (ctrl, sliders_xpm, "settings_show ()", "settings"); + controls[PLAY] = add_pix_button (ctrl, play_xpm, + "play ();", "Play", TRUE, TRUE); + controls[FFWD] = add_pix_button (ctrl, fast_forward_xpm, + "if (!is_live_stream ()) set_speed (16);", + "Fast forward", TRUE, TRUE); + controls[PAUS] = add_pix_button (ctrl, pause_xpm, + "if (!is_live_stream ()) pause ();", + "Pause", TRUE, TRUE); + controls[STOP] = add_pix_button (ctrl, stop_xpm, + "stop ();", "Stop", TRUE, TRUE); + add_pix_button (ctrl, playlist_xpm, + "playlist_show ()", "Playlist", FALSE, TRUE); + add_pix_button (ctrl, sliders_xpm, + "settings_show ()", "A/V settings", FALSE, TRUE); /* audio channel selection */ @@ -317,10 +397,8 @@ /* mute button */ - image = gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_colormap_get_system(), - &transparent, NULL, speaker_xpm); - icon = gtk_pixmap_new(image, transparent); - gtk_box_pack_end (GTK_BOX(ctrl), icon, FALSE, FALSE, 0); + speaker = add_pix_button (ctrl, speaker_xpm, + "set_mute ();", "Mute/unmute", TRUE, FALSE); gtk_box_pack_end (GTK_BOX(vbox), ctrl, FALSE, FALSE, 2); @@ -328,6 +406,8 @@ gtk_widget_show_all(app); + g_idle_add ((GSourceFunc) noskin_main_init_cb, NULL); + have_video = 1; #if 0 gtk_window_set_policy (GTK_WINDOW(app), TRUE, TRUE, FALSE); Index: utils.c =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/utils.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- utils.c 2 Nov 2004 00:41:43 -0000 1.22 +++ utils.c 8 Nov 2004 01:47:09 -0000 1.23 @@ -32,6 +32,8 @@ #include <fcntl.h> #include <string.h> +#include <pthread.h> + #include <glib.h> #include <gdk/gdk.h> #include <gdk/gdkx.h> @@ -435,3 +437,33 @@ return name; } +static ui_status_t status = UI_STOP; +pthread_mutex_t status_lock = PTHREAD_MUTEX_INITIALIZER; + +void ui_set_status (ui_status_t newstatus) +{ + pthread_mutex_lock (&status_lock); + + switch (newstatus) + { + case UI_CURRENT_STATE: + window_set_status (status); + break; + case UI_STOP: + case UI_PAUSE: + case UI_PLAY_SLOW: + case UI_PLAY: + case UI_FAST_FORWARD: + window_set_status (status = newstatus); + break; + case UI_AUDIO_UNMUTE: + window_set_mute (FALSE); + break; + case UI_AUDIO_MUTE: + window_set_mute (TRUE); + break; + default:; + } + + pthread_mutex_unlock (&status_lock); +} Index: utils.h =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/utils.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- utils.h 2 Nov 2004 00:41:43 -0000 1.14 +++ utils.h 8 Nov 2004 01:47:09 -0000 1.15 @@ -28,6 +28,7 @@ #include <gdk/gdk.h> #include <glib.h> #include <gdk-pixbuf/gdk-pixbuf.h> +#include <pthread.h> void utils_init (void); @@ -66,4 +67,23 @@ char *unique_name (char *base); + +typedef enum { + UI_CURRENT_STATE = -1, + UI_STOP = 0, + UI_PAUSE, + UI_PLAY_SLOW, + UI_PLAY, + UI_FAST_FORWARD, + UI_AUDIO_UNMUTE, + UI_AUDIO_MUTE, +} ui_status_t; + +extern pthread_mutex_t status_lock; +void ui_set_status (ui_status_t); + +/* In noskin_window.c, skin_window.c: */ +void window_set_status (ui_status_t); +void window_set_mute (gboolean); + #endif |