changeset 11166:268d5c498b64

[gaim-migrate @ 13267] Tried adding the button and the method to start the score editor. committer: Tailor Script <tailor@pidgin.im>
author Christian Muise <christian.muise@gmail.com>
date Fri, 29 Jul 2005 03:26:59 +0000
parents f20813369fe8
children c3e60a3cd783
files plugins/musicmessaging/musicmessaging.c
diffstat 1 files changed, 109 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/musicmessaging/musicmessaging.c	Fri Jul 29 01:51:07 2005 +0000
+++ b/plugins/musicmessaging/musicmessaging.c	Fri Jul 29 03:26:59 2005 +0000
@@ -1,6 +1,8 @@
 #include "internal.h"
 #include "gtkgaim.h"
 
+#include "conversation.h"
+
 #include "gtkconv.h"
 #include "gtkplugin.h"
 #include "gtkutils.h"
@@ -10,34 +12,118 @@
 
 #define MUSICMESSAGIN_PLUGIN_ID "gtk-hazure-musicmessaging"
 
+static gboolean start_session(void);
+static void run_editor(void);
+static void add_button (GaimConversation *conv);
+
+typedef struct {
+	GaimBuddy *buddy;
+	GtkWidget *window;
+	/* Something for the ly file? */
+	
+	/* Anything else needed for a session? */
+	
+} MMSession;
+
+/* List of sessions */
+GList *sessions;
+
+/* Pointer to this plugin */
+GaimPlugin *plugin_pointer;
+
 static gboolean
 plugin_load(GaimPlugin *plugin) {
     gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Welcome",
                         "Welcome to music messaging.", NULL, NULL, NULL);
-
-    return TRUE;
+	/* Keep the plugin for reference (needed for notify's) */
+	plugin_pointer = plugin;
+	
+	/* Add the button to all the current conversations */
+	gaim_conversation_foreach (add_button);
+	
+	/* Listen for any new conversations */
+	void *conv_list_handle = gaim_conversations_get_handle();
+	
+	gaim_signal_connect(conv_list_handle, "conversation-created", 
+					plugin, GAIM_CALLBACK(add_button), NULL);
+	
+	return TRUE;
 }
 
 static gboolean
 plugin_unload(GaimPlugin *plugin) {
+	
 	gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Unloaded",
-						"The MM plugin has been unloaded.", NULL, NULL, NULL);
+						gaim_prefs_get_string ("/plugins/gtk/musicmessaging/editor_path"), NULL, NULL, NULL);
+	
+	
 	return TRUE;
 }
 
 static gboolean
-plugin_destroyed(GaimPlugin *plugin) {
-	gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Destroyed",
-						"The MM plugin has been destroyed.", NULL, NULL, NULL);
+start_session(void)
+{
+	run_editor();
 	return TRUE;
 }
 
+static void set_editor_path (GtkWidget *button, GtkWidget *text_field)
+{
+	const char * path = gtk_entry_get_text((GtkEntry*)text_field);
+	gaim_prefs_set_string("/plugins/gtk/musicmessaging/editor_path", path);
+	
+	/*Testing*
+	start_session();
+	*/
+	
+}
+
+static void run_editor (void)
+{
+	GError *spawn_error = NULL;
+	gchar * args[2];
+	args[0] = (gchar *)gaim_prefs_get_string("/plugins/gtk/musicmessaging/editor_path");
+	args[1] = NULL;
+	if (!(g_spawn_async (".", args, NULL, 0, NULL, NULL, NULL, &spawn_error)))
+	{
+		gaim_notify_error(plugin_pointer, "Error Running Editor",
+						"The following error has occured:", spawn_error->message);
+	}
+}
+
+static void add_button (GaimConversation *conv)
+{
+	GtkWidget *button, *image, *bbox;
+
+	button = gtk_toggle_button_new();
+	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
+
+	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(start_session), NULL);
+
+	bbox = gtk_vbox_new(FALSE, 0);
+
+	gtk_container_add (GTK_CONTAINER(button), bbox);
+
+	gchar *file_path = g_build_filename (DATADIR, "pixmaps", "gaim", "buttons", "music.png", NULL);
+	image = gtk_image_new_from_file(file_path);
+
+	gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 0);
+
+	gtk_widget_show_all(bbox);
+
+	gtk_box_pack_start(GTK_BOX(GAIM_GTK_CONVERSATION(conv)->toolbar), button, FALSE, FALSE, 0);
+}
+
 static GtkWidget *
 get_config_frame(GaimPlugin *plugin)
 {
 	GtkWidget *ret;
 	GtkWidget *vbox;
 	
+	GtkWidget *editor_path;
+	GtkWidget *editor_path_label;
+	GtkWidget *editor_path_button;
+	
 	/* Outside container */
 	ret = gtk_vbox_new(FALSE, 18);
 	gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
@@ -45,6 +131,20 @@
 	/* Configuration frame */
 	vbox = gaim_gtk_make_frame(ret, _("Music Messaging Configuration"));
 	
+	/* Path to the score editor */
+	editor_path = gtk_entry_new();
+	editor_path_label = gtk_label_new("Score Editor Path");
+	editor_path_button = gtk_button_new_with_mnemonic(_("_Apply"));
+	
+	gtk_entry_set_text((GtkEntry*)editor_path, "/usr/local/bin/gscore");
+	
+	g_signal_connect(G_OBJECT(editor_path_button), "clicked",
+					 G_CALLBACK(set_editor_path), editor_path);
+					 
+	gtk_box_pack_start(GTK_BOX(vbox), editor_path_label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), editor_path, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), editor_path_button, FALSE, FALSE, 0);
+	
 	gtk_widget_show_all(ret);
 
 	return ret;
@@ -74,7 +174,7 @@
     GAIM_WEBSITE,
     plugin_load,
     plugin_unload,
-    plugin_destroyed,
+    NULL,
     &ui_info,
     NULL,
     NULL,
@@ -83,6 +183,8 @@
 
 static void
 init_plugin(GaimPlugin *plugin) {
+	gaim_prefs_add_none("/plugins/gtk/musicmessaging");
+	gaim_prefs_add_string("/plugins/gtk/musicmessaging/editor_path", "/usr/local/bin/gscore");
 }
 
 GAIM_INIT_PLUGIN(musicmessaging, init_plugin, info);