From: Darren S. <ds...@us...> - 2005-01-19 18:24:21
|
Update of /cvsroot/xine/gnome-xine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6758/src Modified Files: post.c Log Message: Make chain config dbox non-modal. Allow both video and audio chain dboxes to be open at once, but prevent multiple instances. Index: post.c =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/post.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- post.c 17 Jan 2005 20:21:28 -0000 1.14 +++ post.c 19 Jan 2005 18:23:49 -0000 1.15 @@ -34,20 +34,25 @@ #include "gtkvideo.h" #include "utils.h" -typedef struct { - char *name, *parameters; - xine_post_t *plugin; - GtkWidget *box, *pref; -} gxine_post_t; - typedef enum { POST_CHAIN_VIDEO, POST_CHAIN_AUDIO, + POST_CHAIN_LAST, } post_chain_t; -static GSList *plugins = NULL; /* list of gxine_post_t */ -static post_chain_t chain_type; -static const char *const *plugin_list; +typedef struct { + post_chain_t type; + GtkWidget *dbox; + GSList *plugins; /* list of gxine_post_t */ + const char **names; +} gxine_chain_t; + +typedef struct { + gxine_chain_t *parent; + char *name, *parameters; + xine_post_t *plugin; + GtkWidget *box, *pref; +} gxine_post_t; static xine_post_t *plugin_current = NULL; static xine_post_in_t *plugin_info = NULL; @@ -55,6 +60,8 @@ static char *plugin_params = NULL; static gboolean plugin_configured; +static gxine_chain_t chains[] = { { POST_CHAIN_VIDEO }, { POST_CHAIN_AUDIO } }; + static const void *const empty[] = { NULL }; static const char *const chain_title[] = { @@ -570,7 +577,7 @@ } static xine_post_t * -post_config_post_init_plugin (const char *name) +post_config_post_init_plugin (post_chain_t chain_type, const char *name) { logprintf ("post_config: creating plugin '%s'\n", name); switch (chain_type) @@ -582,26 +589,27 @@ } case POST_CHAIN_AUDIO: return xine_post_init (xine, name, 0, &audio_port, NULL); + default: + return NULL; /* shouldn't happen */ } - return NULL; /* shouldn't happen */ } /* plugin chain config window */ static void -reconfigure_plugins (void) +reconfigure_plugins (gxine_chain_t *chain) { static const char *cfgname[] = { "gui.post_plugins.video", "gui.post_plugins.audio" }; char *params = NULL; - GSList *info = plugins; + GSList *info = chain->plugins; xine_cfg_entry_t entry; logprintf ("post_config: configuring plugins\n"); - if (!xine_config_lookup_entry (xine, cfgname[chain_type], &entry)) + if (!xine_config_lookup_entry (xine, cfgname[chain->type], &entry)) return; for (; info; info = info->next) @@ -620,7 +628,8 @@ static void post_config_post_chain_set_plugin (GtkOptionMenu *menu, gxine_post_t *info) { - const char *name = plugin_list[gtk_option_menu_get_history (menu)]; + gxine_chain_t *chain = info->parent; + const char *name = chain->names[gtk_option_menu_get_history (menu)]; xine_post_t *newplugin; if (!strcmp (name, info->name)) @@ -630,10 +639,10 @@ } logprintf ("post_config: replacing old plugin '%s'\n", info->name); - newplugin = post_config_post_init_plugin (name); + newplugin = post_config_post_init_plugin (chain->type, name); if (!newplugin) { - display_error (gettext (chain_title[chain_type]), NULL, + display_error (gettext (chain_title[chain->type]), NULL, _("Couldn't initialise plugin '%s' for configuration"), name); return; @@ -671,31 +680,32 @@ free (info->parameters); xine_post_dispose (xine, info->plugin); gtk_container_remove (GTK_CONTAINER(info->box->parent), info->box); - plugins = g_slist_remove (plugins, info); + info->parent->plugins = g_slist_remove (info->parent->plugins, info); free (info); } static void -post_config_post_add_plugin (GtkDialog *dbox, xine_post_t *post, char *name, - char *params) +post_config_post_add_plugin (gxine_chain_t *chain, xine_post_t *post, + char *name, char *params) { gxine_post_t *info = malloc (sizeof (gxine_post_t)); GtkWidget *w, *m; int i, history = 0; logprintf ("post_config: adding plugin '%s'\n", name); + info->parent = chain; info->name = name; info->parameters = params; info->plugin = post; info->box = gtk_hbox_new (FALSE, 2); m = gtk_menu_new (); - for (i = 0; plugin_list[i]; ++i) + for (i = 0; chain->names[i]; ++i) { - if (!strcmp (plugin_list[i], name)) + if (!strcmp (chain->names[i], name)) history = i; gtk_menu_shell_append (GTK_MENU_SHELL(m), - gtk_menu_item_new_with_label (plugin_list[i])); + gtk_menu_item_new_with_label (chain->names[i])); } w = gtk_option_menu_new (); @@ -717,79 +727,113 @@ g_signal_connect (G_OBJECT(w), "clicked", G_CALLBACK(post_config_post_chain_edit_plugin), info); - gtk_box_pack_start (GTK_BOX(dbox->vbox), info->box, FALSE, TRUE, 2); + gtk_box_pack_start (GTK_BOX(GTK_DIALOG(chain->dbox)->vbox), info->box, + FALSE, TRUE, 2); gtk_widget_show_all (info->box); - plugins = g_slist_append (plugins, info); + chain->plugins = g_slist_append (chain->plugins, info); } static void -post_config_post_chain_add (GtkButton *button, GtkDialog *dbox) +post_config_post_chain_add (GtkButton *button, gxine_chain_t *chain) { - xine_post_t *plugin = post_config_post_init_plugin (plugin_list[0]); + xine_post_t *plugin = + post_config_post_init_plugin (chain->type, chain->names[0]); if (plugin) - post_config_post_add_plugin (dbox, plugin, strdup (plugin_list[0]), + post_config_post_add_plugin (chain, plugin, strdup (chain->names[0]), strdup ("")); else - display_error (gettext (chain_title[chain_type]), NULL, + display_error (gettext (chain_title[chain->type]), NULL, _("Couldn't initialise plugin '%s' for configuration"), - plugin_list[0]); + chain->names[0]); +} + +static void +post_config_post_chain_dispose (gxine_chain_t *chain) +{ + GSList *item; + logprintf ("post_config: done\n"); + gtk_widget_destroy (chain->dbox); + for (item = chain->plugins; item; item = item->next) + { + gxine_post_t *info = item->data; + free (info->name); + free (info->parameters); + xine_post_dispose (xine, info->plugin); + free (info); + } + g_slist_free (chain->plugins); + free (chain->names); + chain->plugins = NULL; + chain->names = NULL; + chain->dbox = NULL; } static void -post_config_post_chain_response (GtkDialog *dbox, gint response, gpointer data) +post_config_post_chain_response (GtkDialog *dbox, gint response, + gxine_chain_t *chain) { switch (response) { case GTK_RESPONSE_APPLY: - reconfigure_plugins (); + reconfigure_plugins (chain); break; case GTK_RESPONSE_CLOSE: - reconfigure_plugins (); - gtk_main_quit (); - break; + reconfigure_plugins (chain); + /* fall through */ default: - gtk_main_quit (); + post_config_post_chain_dispose (chain); break; } } -static void -post_config_post_chain_window (post_chain_t chain, const char *config) +static JSBool +post_config_post_chain_window (post_chain_t chain_type, const char *config) { static const int post_type[] = { XINE_POST_TYPE_VIDEO_FILTER, XINE_POST_TYPE_AUDIO_FILTER }; - GtkWidget *dbox, *hbox, *w; - GSList *item; + gxine_chain_t *chain = &chains[chain_type]; + GtkWidget *hbox, *w; + const char *const *plugin_list; + int i; + + if (chain->dbox) + return JS_TRUE; /* FIXME: report already open? */ - plugin_list = xine_list_post_plugins_typed (xine, post_type[chain]); + plugin_list = xine_list_post_plugins_typed (xine, post_type[chain_type]); if (!plugin_list || !plugin_list[0]) { - display_error (gettext (chain_title[chain]), NULL, + display_error (gettext (chain_title[chain_type]), NULL, _("No available plugins - nothing to configure")); - return; + return JS_FALSE; } + /* clone the plugin list (pointers only); xine-lib may reuse that memory */ + for (i = 0; plugin_list[i]; ++i) /**/; + chain->names = malloc (i = (i + 1) * sizeof (const char *)); + memcpy (chain->names, plugin_list, i); + logprintf ("post_config: start\n"); - chain_type = chain; - dbox = gtk_dialog_new_with_buttons (gettext (chain_title[chain]), NULL,0, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); - hide_on_delete (dbox, NULL); - g_signal_connect (G_OBJECT(dbox), "response", - G_CALLBACK(post_config_post_chain_response), NULL); + chain->dbox = gtk_dialog_new_with_buttons + (gettext (chain_title[chain_type]), NULL, 0, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + NULL); + hide_on_delete (chain->dbox, NULL); + g_signal_connect (G_OBJECT(chain->dbox), "response", + G_CALLBACK(post_config_post_chain_response), chain); hbox = gtk_hbox_new (FALSE, 2); - gtk_box_pack_end (GTK_BOX(GTK_DIALOG(dbox)->vbox), hbox, FALSE, TRUE, 5); + gtk_box_pack_end (GTK_BOX(GTK_DIALOG(chain->dbox)->vbox), hbox, + FALSE, TRUE, 5); w = gtk_button_new_from_stock (GTK_STOCK_ADD); g_signal_connect (G_OBJECT(w), "clicked", - G_CALLBACK(post_config_post_chain_add), dbox); + G_CALLBACK(post_config_post_chain_add), chain); gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 5); while (config) @@ -805,9 +849,9 @@ next = (char *)config + strlen (config); name = g_strndup (config, first - config); - post = post_config_post_init_plugin (name); + post = post_config_post_init_plugin (chain_type, name); if (post) - post_config_post_add_plugin (GTK_DIALOG(dbox), post, name, + post_config_post_add_plugin (chain, post, name, g_strndup (first + 1, next - first + 1)); else free (name); @@ -817,23 +861,8 @@ config = next + 1; } - gtk_window_set_modal (GTK_WINDOW(dbox), TRUE); - gtk_widget_show_all (dbox); - gtk_main (); - gtk_widget_destroy ((GtkWidget *)dbox); - - logprintf ("post_config: done\n"); - for (item = plugins; item; item = item->next) - { - gxine_post_t *info = item->data; - free (info->name); - free (info->parameters); - xine_post_dispose (xine, info->plugin); - free (info); - } - g_slist_free (plugins); - plugins = NULL; - plugin_list = NULL; + gtk_widget_show_all (chain->dbox); + return JS_TRUE; } static JSBool @@ -844,7 +873,7 @@ xine_cfg_entry_t entry; se_log_fncall ("deinterlace_show"); - if (plugin_current || plugin_list) + if (plugin_current) return JS_FALSE; if (!xine_config_lookup_entry (xine, "gui.post_plugins.deinterlace", &entry)) @@ -866,11 +895,9 @@ js_pp_common_show (post_chain_t chain, const char *cfgitem) { xine_cfg_entry_t entry; - if (plugin_current || plugin_list || - !xine_config_lookup_entry (xine, cfgitem, &entry)) + if (!xine_config_lookup_entry (xine, cfgitem, &entry)) return JS_FALSE; - post_config_post_chain_window (chain, entry.str_value); - return JS_TRUE; + return post_config_post_chain_window (chain, entry.str_value); } static JSBool |