changeset 3323:c4402812b3e3 trunk

Automated merge with ssh://hg.atheme.org//hg/audacious
author William Pitcock <nenolod@atheme-project.org>
date Fri, 10 Aug 2007 19:43:31 -0500
parents de29bf952b77 (current diff) a6a76ab7ce0a (diff)
children e5cc5e8b7021
files
diffstat 5 files changed, 104 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playback.c	Fri Aug 10 19:43:25 2007 -0500
+++ b/src/audacious/playback.c	Fri Aug 10 19:43:31 2007 -0500
@@ -61,6 +61,27 @@
 
 static int song_info_timeout_source = 0;
 
+
+static gint
+playback_set_pb_ready(InputPlayback *playback)
+{
+    g_mutex_lock(playback->pb_ready_mutex);
+    playback->pb_ready_val = 1;
+    g_cond_signal(playback->pb_ready_cond);
+    g_mutex_unlock(playback->pb_ready_mutex);
+    return 0;
+}
+
+static gint
+playback_wait_for_pb_ready(InputPlayback *playback)
+{
+    g_mutex_lock(playback->pb_ready_mutex);
+    while (playback->pb_ready_val != 1)
+        g_cond_wait(playback->pb_ready_cond, playback->pb_ready_mutex);
+    g_mutex_unlock(playback->pb_ready_mutex);
+    return 0;
+}
+
 void
 playback_eof(void)
 {
@@ -186,6 +207,10 @@
 
     if (ip_data.playing)
     {
+        /* wait for plugin to signal it has reached
+           the 'playback safe state' before stopping */
+        playback_wait_for_pb_ready(playback);
+
         if (playback_get_paused() == TRUE)
         {
             if (get_written_time() > 0)
@@ -193,7 +218,7 @@
             playback_pause();
         }
 
-        ip_data.playing = FALSE; 
+        ip_data.playing = FALSE;
 
         if (playback->plugin->stop)
             playback->plugin->stop(playback);
@@ -204,9 +229,14 @@
         free_vis_data();
         ip_data.paused = FALSE;
 
-	g_free(playback->filename);
-	g_free(playback);
-	set_current_input_playback(NULL);
+        if (playback->pb_ready_mutex)
+            g_mutex_free(playback->pb_ready_mutex);
+        if (playback->pb_ready_cond)
+            g_cond_free(playback->pb_ready_cond);
+
+        g_free(playback->filename);
+        g_free(playback);
+        set_current_input_playback(NULL);
     }
 
     ip_data.buffering = FALSE;
@@ -245,6 +275,10 @@
 
     playback->plugin->play_file(playback);
 
+    /* if play_file has not reached the 'safe state' before returning (an error
+       occurred), set the playback ready value to 1 now, to allow for proper stop */
+    playback_set_pb_ready(playback);
+
     if (!playback->error && ip_data.playing)
         playback_eof();
     else if (playback->error)
@@ -301,6 +335,10 @@
     playback->output = &psuedo_output_plugin;
     playback->filename = g_strdup(entry->filename);
     playback->thread = g_thread_self();
+    playback->pb_ready_mutex = g_mutex_new();
+    playback->pb_ready_cond = g_cond_new();
+    playback->pb_ready_val = 0;
+    playback->set_pb_ready = playback_set_pb_ready;
     
     set_current_input_playback(playback);
 
--- a/src/audacious/plugin.h	Fri Aug 10 19:43:25 2007 -0500
+++ b/src/audacious/plugin.h	Fri Aug 10 19:43:31 2007 -0500
@@ -214,6 +214,11 @@
     gboolean eof;
 
     GThread *thread;
+    
+    GMutex *pb_ready_mutex;
+    GCond *pb_ready_cond;
+    gint pb_ready_val;    
+    gint (*set_pb_ready) (InputPlayback*);
 };
 
 struct _InputPlugin {
--- a/src/audacious/ui/playlist.ui	Fri Aug 10 19:43:25 2007 -0500
+++ b/src/audacious/ui/playlist.ui	Fri Aug 10 19:43:31 2007 -0500
@@ -10,6 +10,10 @@
 			<menuitem action="playlist remove all" />
 			<separator />
 			<menuitem action="queue toggle" />
+			<separator />
+			<menu action="plugins" name="plugins-menu">
+			   <menuitem action="dummy" name="plugins-menu-dummy" />
+			</menu>
 		</menu>
 
 		<menu action="dummy" name="add-menu">
@@ -83,7 +87,6 @@
 			   <menuitem action="dummy" name="plugins-menu-dummy" />
 			</menu>
 			<separator />
-			<separator />
 			<menuitem action="playlist refresh" />
 			<separator />
 <!--			<menuitem action="playlist delete" /> -->
--- a/src/audacious/ui_manager.c	Fri Aug 10 19:43:25 2007 -0500
+++ b/src/audacious/ui_manager.c	Fri Aug 10 19:43:31 2007 -0500
@@ -699,6 +699,7 @@
 
   /* initialize plugins-menu for playlist-menus */
   ui_manager_create_menus_init_pmenu( "/playlist-menus/playlist-menu/plugins-menu" );
+  ui_manager_create_menus_init_pmenu( "/playlist-menus/playlist-rightclick-menu/plugins-menu" );
 
   gtk_ui_manager_add_ui_from_file( ui_manager , DATA_DIR "/ui/equalizer.ui" , &gerr );
 
@@ -777,31 +778,44 @@
 {
   if ( menu_created )
   {
+    GtkWidget *plugins_menu = NULL;
+    GtkWidget *plugins_menu_item = NULL;
+
     switch (menu_id)
     {
       case AUDACIOUS_MENU_MAIN:
-      {
-        GtkWidget *plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
+        plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
           "/mainwin-menus/main-menu/plugins-menu" );
-        GtkWidget *plugins_menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(plugins_menu_item) );
-        gtk_menu_shell_append( GTK_MENU_SHELL(plugins_menu) , item );
-        gtk_widget_show( plugins_menu_item );
-        return 0;
-      }
+        break;
 
       case AUDACIOUS_MENU_PLAYLIST:
-      {
-        GtkWidget *plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
+        plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
           "/playlist-menus/playlist-menu/plugins-menu" );
-        GtkWidget *plugins_menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(plugins_menu_item) );
-        gtk_menu_shell_append( GTK_MENU_SHELL(plugins_menu) , item );
-        gtk_widget_show( plugins_menu_item );
-        return 0;
-      }
+        break;
+
+      case AUDACIOUS_MENU_PLAYLIST_RCLICK:
+        plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
+          "/playlist-menus/playlist-rightclick-menu/plugins-menu" );
+        break;
 
       default:
         return -1;
     }
+
+    if ( plugins_menu_item )
+    {
+      plugins_menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(plugins_menu_item) );
+      if ( plugins_menu )
+      {
+        gtk_menu_shell_append( GTK_MENU_SHELL(plugins_menu) , item );
+        gtk_widget_show( plugins_menu_item );
+        return 0; /* success */
+      }
+      else
+        return -1;
+    }
+    else
+      return -1;
   }
   else
     return -1;
@@ -820,37 +834,42 @@
     switch (menu_id)
     {
       case AUDACIOUS_MENU_MAIN:
-      {
         plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
           "/mainwin-menus/main-menu/plugins-menu" );
-        plugins_menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(plugins_menu_item) );
-        gtk_container_remove( GTK_CONTAINER(plugins_menu) , item );
         break;
-      }
 
       case AUDACIOUS_MENU_PLAYLIST:
-      {
         plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
           "/playlist-menus/playlist-menu/plugins-menu" );
-        plugins_menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(plugins_menu_item) );
-        gtk_container_remove( GTK_CONTAINER(plugins_menu) , item );
         break;
-      }
+
+      case AUDACIOUS_MENU_PLAYLIST_RCLICK:
+        plugins_menu_item = gtk_ui_manager_get_widget( ui_manager ,
+          "/playlist-menus/playlist-rightclick-menu/plugins-menu" );
+        break;
 
       default:
         return -1;
     }
 
-    if ( plugins_menu )
+    if ( plugins_menu_item )
     {
-      /* check the current number of items in plugins-menu against its initial count
-         of items; if these are equal, it means that the menu is "empty", so hide it */
-      gint ic = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(plugins_menu),"ic"));
-      plugins_menu_children = gtk_container_get_children( GTK_CONTAINER(plugins_menu) );
-      if ( ic == g_list_length(plugins_menu_children) )
-        gtk_widget_hide( plugins_menu_item );
-      g_list_free( plugins_menu_children );
-      return 0;
+      plugins_menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(plugins_menu_item) );
+      if ( plugins_menu )
+      {
+        /* remove the plugin-added entry */
+        gtk_container_remove( GTK_CONTAINER(plugins_menu) , item );
+        /* check the current number of items in plugins-menu against its initial count
+           of items; if these are equal, it means that the menu is "empty", so hide it */
+        gint ic = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(plugins_menu),"ic"));
+        plugins_menu_children = gtk_container_get_children( GTK_CONTAINER(plugins_menu) );
+        if ( ic == g_list_length(plugins_menu_children) )
+          gtk_widget_hide( plugins_menu_item );
+        g_list_free( plugins_menu_children );
+        return 0; /* success */
+      }
+      else
+        return -1;
     }
     else
       return -1;
--- a/src/audacious/ui_plugin_menu.h	Fri Aug 10 19:43:25 2007 -0500
+++ b/src/audacious/ui_plugin_menu.h	Fri Aug 10 19:43:31 2007 -0500
@@ -28,8 +28,9 @@
 #include <gtk/gtk.h>
 
 
-#define AUDACIOUS_MENU_MAIN        0
-#define AUDACIOUS_MENU_PLAYLIST    1
+#define AUDACIOUS_MENU_MAIN             0
+#define AUDACIOUS_MENU_PLAYLIST         1
+#define AUDACIOUS_MENU_PLAYLIST_RCLICK  2
 
 gint audacious_menu_plugin_item_add( gint , GtkWidget * );
 gint audacious_menu_plugin_item_remove( gint , GtkWidget * );