Author: rolf
Date: 2008-02-20 13:13:32 -0500 (Wed, 20 Feb 2008)
New Revision: 96283
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/plugin-debug.cpp
trunk/moon/plugin/plugin-debug.h
trunk/moon/plugin/plugin.cpp
trunk/moon/plugin/plugin.h
Log:
* plugin/plugin.cpp, plugin/plugin.h, plugin/plugin-debug.cpp,
plugin/plugin-debug.h: Add a 'Sources' entry to the plugin context
menu, shows a list of all the files the plugin has loaded, with the
ability to open the files.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2008-02-20 18:10:29 UTC (rev 96282)
+++ trunk/moon/plugin/ChangeLog 2008-02-20 18:13:32 UTC (rev 96283)
@@ -1,5 +1,11 @@
2008-02-20 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
+ * plugin.cpp, plugin.h, plugin-debug.cpp, plugin-debug.h: Add a
'Sources'
+ entry to the plugin context menu, shows a list of all the files the
+ plugin has loaded, with the ability to open the files.
+
+2008-02-20 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
+
* plugin.mdp: Updated.
2008-02-20 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
Modified: trunk/moon/plugin/plugin-debug.cpp
===================================================================
--- trunk/moon/plugin/plugin-debug.cpp 2008-02-20 18:10:29 UTC (rev 96282)
+++ trunk/moon/plugin/plugin-debug.cpp 2008-02-20 18:13:32 UTC (rev 96283)
@@ -129,4 +129,121 @@
gtk_widget_show_all (tree_win);
}
+static void
+populate_tree_from_surface (PluginInstance *plugin, GtkTreeStore *store,
GtkTreeIter *parent)
+{
+ if (plugin == NULL)
+ return;
+
+ GtkTreeIter iter;
+ PluginInstance::moon_source *src = (PluginInstance::moon_source*)
plugin->GetSources ()->First ();
+ for (; src != NULL; src = (PluginInstance::moon_source*) src->next) {
+ gtk_tree_store_append (store, &iter, parent);
+
+ gtk_tree_store_set (store, &iter,
+ 0, src->uri,
+ 1, src->filename,
+ 2, src,
+ -1);
+
+ }
+}
+
+PluginInstance::moon_source *selected_source = NULL;
+
+static void
+selection_changed_sources (GtkTreeSelection *selection, PluginInstance *plugin)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ selected_source = NULL;
+
+ if (!gtk_tree_selection_get_selected (selection,
+ &model,
+ &iter)) {
+ return;
+ }
+
+ gtk_tree_model_get (model, &iter,
+ 2, &selected_source,
+ -1);
+
+}
+
+static void clicked_callback (GtkWidget *widget, gpointer data)
+{
+ if (selected_source == NULL) {
+ printf ("Select a source first.\n");
+ } else {
+ gchar* argv [3];
+ argv [0] = (gchar*) "xdg-open";
+ argv [1] = (gchar*) selected_source->filename;
+ argv [2] = NULL;
+ g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
NULL, NULL, NULL);
+ }
+}
+
+void
+plugin_sources (PluginInstance *plugin)
+{
+ GtkWidget *tree_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (tree_win), "Sources");
+ gtk_window_set_default_size (GTK_WINDOW (tree_win), 600, 400);
+ GtkBox *vbox = GTK_BOX (gtk_vbox_new (false, 0));
+
+ GtkTreeStore *tree_store = gtk_tree_store_new (3,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_POINTER);
+
+ populate_tree_from_surface (plugin, tree_store, NULL);
+
+ GtkWidget* tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL
(tree_store));
+
+ GtkTreeSelection *selection = gtk_tree_view_get_selection
(GTK_TREE_VIEW (tree_view));
+
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+
+ g_signal_connect (G_OBJECT (selection), "changed",
+ G_CALLBACK (selection_changed_sources), plugin);
+
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
+ GtkTreeViewColumn *col;
+
+ /* The Name column */
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_title(col, "Uri");
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+
+ gtk_tree_view_column_pack_start(col, renderer, TRUE);
+ gtk_tree_view_column_add_attribute (col, renderer, "text", 0);
+
+ /* The Type column */
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_title(col, "Filename");
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+
+ gtk_tree_view_column_pack_start(col, renderer, TRUE);
+ gtk_tree_view_column_add_attribute (col, renderer, "text", 1);
+
+ GtkWidget *scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ gtk_container_add (GTK_CONTAINER (scrolled), tree_view);
+ //gtk_container_add (GTK_CONTAINER (tree_win), scrolled);
+
+ GtkWidget *button = gtk_button_new_with_label ("Open file");
+ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK
(clicked_callback), NULL);
+
+ gtk_box_pack_start (vbox, scrolled, TRUE, TRUE, 0);
+ gtk_box_pack_start (vbox, button, FALSE, FALSE, 0);
+
+ gtk_container_add (GTK_CONTAINER (tree_win), GTK_WIDGET (vbox));
+
+ gtk_widget_show_all (tree_win);
+}
+
#endif
Modified: trunk/moon/plugin/plugin-debug.h
===================================================================
--- trunk/moon/plugin/plugin-debug.h 2008-02-20 18:10:29 UTC (rev 96282)
+++ trunk/moon/plugin/plugin-debug.h 2008-02-20 18:13:32 UTC (rev 96283)
@@ -15,6 +15,7 @@
G_BEGIN_DECLS
void plugin_debug (PluginInstance *plugin);
+void plugin_sources (PluginInstance *plugin);
G_END_DECLS
Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp 2008-02-20 18:10:29 UTC (rev 96282)
+++ trunk/moon/plugin/plugin.cpp 2008-02-20 18:13:32 UTC (rev 96283)
@@ -91,6 +91,10 @@
menu_item = gtk_menu_item_new_with_label ("Debug");
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
g_signal_connect_swapped (G_OBJECT(menu_item), "activate", G_CALLBACK
(plugin_debug), plugin);
+
+ menu_item = gtk_menu_item_new_with_label ("Sources");
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ g_signal_connect_swapped (G_OBJECT(menu_item), "activate", G_CALLBACK
(plugin_sources), plugin);
#endif
gtk_widget_show_all (menu);
@@ -317,6 +321,10 @@
/* back pointer to us */
instance->pdata = this;
+
+#if DEBUG
+ moon_sources = NULL;
+#endif
}
PluginInstance::~PluginInstance ()
@@ -358,9 +366,33 @@
if (plugin_unload)
plugin_unload (this);
+
+#if DEBUG
+ delete moon_sources;
+ moon_sources = NULL;
+#endif
}
+#if DEBUG
void
+PluginInstance::AddSource (const char *uri, const char *filename)
+{
+ moon_source *src = new moon_source ();
+ src->uri = g_strdup (uri);
+ src->filename = g_strdup (filename);
+ if (moon_sources == NULL)
+ moon_sources = new List ();
+ moon_sources->Append (src);
+}
+
+List*
+PluginInstance::GetSources ()
+{
+ return moon_sources;
+}
+#endif
+
+void
PluginInstance::SetUnloadCallback (plugin_unload_callback* puc)
{
plugin_unload = puc;
@@ -880,6 +912,10 @@
{
// DEBUGMSG ("StreamAsFile: %s", fname);
+#if DEBUG
+ AddSource (stream->url, fname);
+#endif
+
if (IS_NOTIFY_SOURCE (stream->notifyData)) {
// DEBUGMSG ("LoadFromXaml: %s", fname);
if (xaml_loader)
Modified: trunk/moon/plugin/plugin.h
===================================================================
--- trunk/moon/plugin/plugin.h 2008-02-20 18:10:29 UTC (rev 96282)
+++ trunk/moon/plugin/plugin.h 2008-02-20 18:13:32 UTC (rev 96283)
@@ -67,8 +67,24 @@
static void ReportFPS (Surface *surface, int nframes, float nsecs, void
*user_data);
static void properties_dialog_response (GtkWidget *dialog, int
response, PluginInstance *plugin);
+
+ public:
+
+#if DEBUG
+ struct moon_source : List::Node {
+ char *uri;
+ char *filename;
+ virtual ~moon_source ()
+ {
+ g_free (uri);
+ g_free (filename);
+ }
+ };
+ List *moon_sources;
+ void AddSource (const char *uri, const char *filename);
+ List *GetSources ();
+#endif
- public:
PluginInstance (NPP instance, uint16_t mode);
~PluginInstance ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches