changeset 3037:91d50f13948a

Get plugin services working again for 2.0 (bug #8)
author John Lindgren <john.lindgren@tds.net>
date Sun, 12 Apr 2009 17:23:45 -0400
parents b0f8da03187b
children 327225adf175
files src/skins/ui_manager.c
diffstat 1 files changed, 27 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/src/skins/ui_manager.c	Sat Apr 11 08:26:51 2009 -0400
+++ b/src/skins/ui_manager.c	Sun Apr 12 17:23:45 2009 -0400
@@ -43,8 +43,6 @@
 #include <audlegacy/ui_plugin_menu.h>
 
 static GtkUIManager *ui_manager = NULL;
-static gboolean menu_created = FALSE;
-
 
 /* toggle action entries */
 
@@ -173,7 +171,7 @@
 static GtkActionEntry action_entries_playback[] = {
 
 	{ "playback", NULL, N_("Playback") },
-	
+
 	{ "playback play", GTK_STOCK_MEDIA_PLAY , N_("Play"), "X",
 	  N_("Play"), G_CALLBACK(action_playback_play) },
 
@@ -272,7 +270,7 @@
 };
 
 static GtkActionEntry action_entries_playlist_delete[] = {
-	{ "playlist remove all", GTK_STOCK_CLEAR, N_("Remove All"), NULL, 
+	{ "playlist remove all", GTK_STOCK_CLEAR, N_("Remove All"), NULL,
 	  N_("Removes all entries from the playlist."),
 	  G_CALLBACK(action_playlist_remove_all) },
 
@@ -290,11 +288,11 @@
 	  N_("Removes duplicate entries from the playlist by title."),
 	  G_CALLBACK(action_playlist_remove_dupes_by_title) },
 
-	{ "playlist remove dups by filename", NULL , N_("By Filename"), NULL, 
+	{ "playlist remove dups by filename", NULL , N_("By Filename"), NULL,
 	  N_("Removes duplicate entries from the playlist by filename."),
 	  G_CALLBACK(action_playlist_remove_dupes_by_filename) },
 
-	{ "playlist remove dups by full path", NULL , N_("By Path + Filename"), NULL, 
+	{ "playlist remove dups by full path", NULL , N_("By Path + Filename"), NULL,
 	  N_("Removes duplicate entries from the playlist by their full path."),
 	  G_CALLBACK(action_playlist_remove_dupes_by_full_path) },
 
@@ -302,7 +300,7 @@
 	  N_("Remove unselected entries from the playlist."),
 	  G_CALLBACK(action_playlist_remove_unselected) },
 
-	{ "playlist remove selected", GTK_STOCK_REMOVE, N_("Remove Selected"), "Delete", 
+	{ "playlist remove selected", GTK_STOCK_REMOVE, N_("Remove Selected"), "Delete",
 	  N_("Remove selected entries from the playlist."),
 	  G_CALLBACK(action_playlist_remove_selected) },
 };
@@ -425,7 +423,7 @@
 	{ "jump to time", GTK_STOCK_JUMP_TO , N_("Jump to Time"), "<Ctrl>J",
 	  N_("Jump to Time"), G_CALLBACK(action_jump_to_time) },
 
-	{ "queue toggle", AUD_STOCK_QUEUETOGGLE , N_("Queue Toggle"), "Q", 
+	{ "queue toggle", AUD_STOCK_QUEUETOGGLE , N_("Queue Toggle"), "Q",
 	  N_("Enables/disables the entry in the playlist's queue."),
 	  G_CALLBACK(action_queue_toggle) },
 };
@@ -636,20 +634,6 @@
 static GtkWidget *carbon_menubar;
 #endif
 
-static void
-ui_manager_create_menus_init_pmenu( gchar * path )
-{
-  GtkWidget *plugins_menu_item = gtk_ui_manager_get_widget( ui_manager , path );
-  if ( plugins_menu_item )
-  {
-    /* initially set count of items under plugins_menu_item to 0 */
-    g_object_set_data( G_OBJECT(plugins_menu_item) , "ic" , GINT_TO_POINTER(0) );
-    /* and since it's 0, hide the plugins_menu_item */
-    gtk_widget_hide( plugins_menu_item );
-  }
-  return;
-}
-
 
 void
 ui_manager_create_menus ( void )
@@ -674,8 +658,9 @@
   mainwin_view_menu = ui_manager_get_popup_menu( ui_manager , "/mainwin-menus/main-menu/view" );
   mainwin_general_menu = ui_manager_get_popup_menu( ui_manager , "/mainwin-menus/main-menu" );
 
-  /* initialize plugins-menu for mainwin-menus */
-  ui_manager_create_menus_init_pmenu( "/mainwin-menus/main-menu/plugins-menu" );
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget
+   (ui_manager, "/mainwin-menus/main-menu/plugins-menu")), aud_get_plugin_menu
+   (AUDACIOUS_MENU_MAIN));
 
 #ifdef GDK_WINDOWING_QUARTZ
   gtk_ui_manager_add_ui_from_file( ui_manager , DATA_DIR "/ui/carbon-menubar.ui" , &gerr );
@@ -708,13 +693,24 @@
   playlistwin_plsort_menu = ui_manager_get_popup_menu(ui_manager, "/playlist-menus/misc-menu");
   playlistwin_pllist_menu = ui_manager_get_popup_menu(ui_manager, "/playlist-menus/playlist-menu");
 
-  /* 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/add-menu/plugins-menu" );
-  ui_manager_create_menus_init_pmenu( "/playlist-menus/del-menu/plugins-menu" );
-  ui_manager_create_menus_init_pmenu( "/playlist-menus/select-menu/plugins-menu" );
-  ui_manager_create_menus_init_pmenu( "/playlist-menus/misc-menu/plugins-menu" );
-  ui_manager_create_menus_init_pmenu( "/playlist-menus/playlist-rightclick-menu/plugins-menu" );
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget
+   (ui_manager, "/playlist-menus/playlist-menu/plugins-menu")),
+   aud_get_plugin_menu (AUDACIOUS_MENU_PLAYLIST));
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget
+   (ui_manager, "/playlist-menus/playlist-rightclick-menu/plugins-menu")),
+   aud_get_plugin_menu (AUDACIOUS_MENU_PLAYLIST_RCLICK));
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget
+   (ui_manager, "/playlist-menus/add-menu/plugins-menu")), aud_get_plugin_menu
+   (AUDACIOUS_MENU_PLAYLIST_ADD));
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget
+   (ui_manager, "/playlist-menus/del-menu/plugins-menu")), aud_get_plugin_menu
+   (AUDACIOUS_MENU_PLAYLIST_REMOVE));
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget
+   (ui_manager, "/playlist-menus/select-menu/plugins-menu")),
+   aud_get_plugin_menu (AUDACIOUS_MENU_PLAYLIST_SELECT));
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget
+   (ui_manager, "/playlist-menus/misc-menu/plugins-menu")), aud_get_plugin_menu
+   (AUDACIOUS_MENU_PLAYLIST_MISC));
 
   gtk_ui_manager_add_ui_from_file( ui_manager , DATA_DIR "/ui/equalizer.ui" , &gerr );
 
@@ -726,9 +722,6 @@
   }
 
   equalizerwin_presets_menu = ui_manager_get_popup_menu(ui_manager, "/equalizer-menus/preset-menu");
-
-  menu_created = TRUE;
-
   return;
 }
 
@@ -782,100 +775,6 @@
     (GtkMenuPositionFunc) menu_popup_pos_func , pos , button , time );
 }
 
-
-
-/******************************/
-/* plugin-available functions */
-
-#define _MP_GWID(y) gtk_ui_manager_get_widget( ui_manager , y )
-
-static GtkWidget*
-audacious_menu_plugin_menuwid( menu_id )
-{
-  switch (menu_id)
-  {
-    case AUDACIOUS_MENU_MAIN:
-      return _MP_GWID("/mainwin-menus/main-menu/plugins-menu");
-    case AUDACIOUS_MENU_PLAYLIST:
-      return _MP_GWID("/playlist-menus/playlist-menu/plugins-menu");
-    case AUDACIOUS_MENU_PLAYLIST_RCLICK:
-      return _MP_GWID("/playlist-menus/playlist-rightclick-menu/plugins-menu");
-    case AUDACIOUS_MENU_PLAYLIST_ADD:
-      return _MP_GWID("/playlist-menus/add-menu/plugins-menu");
-    case AUDACIOUS_MENU_PLAYLIST_REMOVE:
-      return _MP_GWID("/playlist-menus/del-menu/plugins-menu");
-    case AUDACIOUS_MENU_PLAYLIST_SELECT:
-      return _MP_GWID("/playlist-menus/select-menu/plugins-menu");
-    case AUDACIOUS_MENU_PLAYLIST_MISC:
-      return _MP_GWID("/playlist-menus/misc-menu/plugins-menu");
-    default:
-      return NULL;
-  }
-}
-
-
-gint
-menu_plugin_item_add( gint menu_id , GtkWidget * item )
-{
-  if ( menu_created )
-  {
-    GtkWidget *plugins_menu = NULL;
-    GtkWidget *plugins_menu_item = audacious_menu_plugin_menuwid( menu_id );
-    if ( plugins_menu_item )
-    {
-      gint ic = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(plugins_menu_item),"ic"));
-      if ( ic == 0 ) /* no items under plugins_menu_item, create the submenu */
-      {
-        plugins_menu = gtk_menu_new();
-        gtk_menu_item_set_submenu( GTK_MENU_ITEM(plugins_menu_item), plugins_menu );
-      }
-      else /* items available under plugins_menu_item, pick the existing submenu */
-      {
-        plugins_menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(plugins_menu_item) );
-        if ( !plugins_menu ) return -1;
-      }
-      gtk_menu_shell_append( GTK_MENU_SHELL(plugins_menu) , item );
-      gtk_widget_show( plugins_menu_item );
-      g_object_set_data( G_OBJECT(plugins_menu_item) , "ic" , GINT_TO_POINTER(++ic) );
-      return 0; /* success */
-    }
-  }
-  return -1; /* failure */
-}
-
-
-gint
-menu_plugin_item_remove( gint menu_id , GtkWidget * item )
-{
-  if ( menu_created )
-  {
-    GtkWidget *plugins_menu = NULL;
-    GtkWidget *plugins_menu_item = audacious_menu_plugin_menuwid( menu_id );
-    if ( plugins_menu_item )
-    {
-      gint ic = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(plugins_menu_item),"ic"));
-      if ( ic > 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 );
-          g_object_set_data( G_OBJECT(plugins_menu_item) , "ic" , GINT_TO_POINTER(--ic) );
-          if ( ic == 0 ) /* if the menu is empty now, destroy it */
-          {
-            gtk_menu_item_remove_submenu( GTK_MENU_ITEM(plugins_menu_item) );
-            gtk_widget_destroy( plugins_menu );
-            gtk_widget_hide( plugins_menu_item );
-          }
-          return 0; /* success */
-        }
-      }
-    }
-  }
-  return -1; /* failure */
-}
-
 void
 ui_manager_destroy( void )
 {