Mercurial > pidgin
changeset 11200:4295083cf489
[gaim-migrate @ 13328]
Added dbus capabilities to the mm plugin
committer: Tailor Script <tailor@pidgin.im>
author | Christian Muise <christian.muise@gmail.com> |
---|---|
date | Mon, 08 Aug 2005 01:40:41 +0000 |
parents | 30a3d97503be |
children | 07dc8c6a359f |
files | plugins/dbus-example.c plugins/musicmessaging/Makefile.am plugins/musicmessaging/musicmessaging.c src/dbus-client.c |
diffstat | 4 files changed, 259 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/dbus-example.c Sun Aug 07 20:42:25 2005 +0000 +++ b/plugins/dbus-example.c Mon Aug 08 01:40:41 2005 +0000 @@ -156,5 +156,3 @@ } GAIM_INIT_PLUGIN(dbus_example, init_plugin, info) - -
--- a/plugins/musicmessaging/Makefile.am Sun Aug 07 20:42:25 2005 +0000 +++ b/plugins/musicmessaging/Makefile.am Mon Aug 08 01:40:41 2005 +0000 @@ -14,6 +14,19 @@ musicmessaging_la_SOURCES = \ musicmessaging.c + + + +CLEANFILES = music-messaging-bindings.c +musicmessaging_la_LDFLAGS += $(DBUS_LIBS) + +music-messaging-bindings.c: ../../src/dbus-analyze-functions.py $(musicmessaging_la_SOURCES) $(musicmessaging_la_HEADERS) + cat $(musicmessaging_la_SOURCES) $(musicmessaging_la_HEADERS) | \ + $(PYTHON) ../../src/dbus-analyze-functions.py --export-only > $@ + +$(musicmessaging_la_OBJECTS) musicmessaging.so: music-messaging-bindings.c + + endif
--- a/plugins/musicmessaging/musicmessaging.c Sun Aug 07 20:42:25 2005 +0000 +++ b/plugins/musicmessaging/musicmessaging.c Mon Aug 08 01:40:41 2005 +0000 @@ -1,3 +1,24 @@ +/* + * Music messaging plugin for Gaim + * + * Copyright (C) 2005 Christian Muise. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + #include "internal.h" #include "gtkgaim.h" @@ -9,47 +30,150 @@ #include "notify.h" #include "version.h" - -#define MUSICMESSAGIN_PLUGIN_ID "gtk-hazure-musicmessaging" +#include "debug.h" -static gboolean start_session(void); -static void run_editor(void); -static void add_button (GaimConversation *conv); -static void remove_button (GtkWidget *button); +#define DBUS_API_SUBJECT_TO_CHANGE +#include <dbus/dbus.h> +#include "dbus-maybe.h" +#include "dbus-bindings.h" +#include "dbus-server.h" -typedef struct { - GaimBuddy *buddy; - GtkWidget *window; - /* Something for the ly file? */ - - /* Anything else needed for a session? */ - -} MMSession; +#define MUSICMESSAGING_PLUGIN_ID "gtk-hazure-musicmessaging" +#define MUSICMESSAGING_PREFIX "##MM##" +#define MUSICMESSAGING_START_TAG "<a href=mm-plugin>" +/* Globals */ /* List of sessions */ -GList *sessions; - -/* List of created buttons */ -GList *widgets; +GList *conversations; /* Pointer to this plugin */ GaimPlugin *plugin_pointer; +/* Define types needed for DBus */ + +/* Define the functions to export for use with DBus */ +DBUS_EXPORT void music_messaging_change_request (const char *command, const char *parameters); +DBUS_EXPORT void music_messaging_change_confirmed (const char *command, const char *parameters); +DBUS_EXPORT void music_messaging_change_failed (const char *id, const char *command, const char *parameters); +DBUS_EXPORT void music_messaging_done_session (void); + +/* This file has been generated by the #dbus-analize-functions.py + script. It contains dbus wrappers for the four functions declared + above. */ +#include "music-messaging-bindings.c" + +/* Exported functions */ +void music_messaging_change_request(const char *command, const char *parameters) +{ + gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, + parameters, NULL, NULL, NULL); +} + +void music_messaging_change_confirmed(const char *command, const char *parameters) +{ + gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, + parameters, NULL, NULL, NULL); +} + +void music_messaging_change_failed(const char *id, const char *command, const char *parameters) +{ + gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, + parameters, NULL, NULL, NULL); +} + +void music_messaging_done_session(void) +{ + gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, "Session", + "Session Complete", NULL, NULL, NULL); +} + +typedef struct { + GaimConversation *conv; /* pointer to the conversation */ + GtkWidget *seperator; /* seperator in the conversation */ + GtkWidget *button; /* button in the conversation */ + GPid pid; /* the pid of the score editor */ + + gboolean started; /* session has started and editor run */ + gboolean originator; /* started the mm session */ + gboolean requested; /* received a request to start a session */ + +} MMConversation; + +static gboolean start_session(MMConversation *mmconv); +static void run_editor(MMConversation *mmconv); +static void kill_editor(MMConversation *mmconv); +static void add_button (MMConversation *mmconv); +static void remove_widget (GtkWidget *button); +static void init_conversation (GaimConversation *conv); +static void conv_destroyed(GaimConversation *conv); +static void intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData); +static void intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags); + + +G_BEGIN_DECLS +DBusConnection *gaim_dbus_get_connection(void); +G_END_DECLS + +void send_change_request (const char *id, const char *command, const char *parameters) +{ + DBusMessage *signal; + signal = dbus_message_new_signal("/org/gscore/GScoreObject", "org.gscore.GScoreInterface", "gscore_change_request"); + + dbus_message_append_args(signal, + DBUS_TYPE_STRING, &id, + DBUS_TYPE_STRING, &command, + DBUS_TYPE_STRING, ¶meters, + DBUS_TYPE_INVALID); + + dbus_connection_send(gaim_dbus_get_connection(), signal, NULL); + dbus_message_unref(signal); +} + +void send_change_confirmed (const char *command, const char *parameters) +{ + DBusMessage *signal; + signal = dbus_message_new_signal("/org/gscore/GScoreObject", "org.gscore.GScoreInterface", "gscore_change_confirmed"); + + dbus_message_append_args(signal, + DBUS_TYPE_STRING, &command, + DBUS_TYPE_STRING, ¶meters, + DBUS_TYPE_INVALID); + + dbus_connection_send(gaim_dbus_get_connection(), signal, NULL); + dbus_message_unref(signal); +} + + static gboolean plugin_load(GaimPlugin *plugin) { - gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Welcome", + /* First, we have to register our four exported functions with the + main gaim dbus loop. Without this statement, the gaim dbus + code wouldn't know about our functions. */ + GAIM_DBUS_REGISTER_BINDINGS(plugin); + + gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Welcome", "Welcome to music messaging.", NULL, NULL, NULL); /* 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); + gaim_conversation_foreach (init_conversation); /* 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); + plugin, GAIM_CALLBACK(init_conversation), NULL); + + /* Listen for conversations that are ending */ + gaim_signal_connect(conv_list_handle, "deleting-conversation", + plugin, GAIM_CALLBACK(conv_destroyed), NULL); + + /* Listen for sending/receiving messages to replace tags */ + gaim_signal_connect(conv_list_handle, "writing-im-msg", + plugin, GAIM_CALLBACK(intercept_sent), NULL); + gaim_signal_connect(conv_list_handle, "receiving-im-msg", + plugin, GAIM_CALLBACK(intercept_received), NULL); return TRUE; } @@ -58,16 +182,52 @@ plugin_unload(GaimPlugin *plugin) { gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Unloaded", - gaim_prefs_get_string ("/plugins/gtk/musicmessaging/editor_path"), NULL, NULL, NULL); + DATADIR, NULL, NULL, NULL); - g_list_foreach(widgets, (GFunc) remove_button, NULL); + MMConversation *mmconv = NULL; + while (g_list_length(conversations) > 0) + { + mmconv = g_list_first(conversations)->data; + conv_destroyed(mmconv->conv); + } return TRUE; } +static void intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData) +{ + GaimConvIm *imData = gaim_conversation_get_im_data(conv); + GaimConnection *connection = gaim_conversation_get_gc(conv); + const char *convName = gaim_conversation_get_name(conv); + const char *who = gaim_account_get_username(account); + + if (0 == strncmp(*message, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX))) + { + message = 0; + gaim_debug(GAIM_DEBUG_MISC, "gaim-musicmessaging", "Received MM Message\n"); + send_change_confirmed("the command", "the params"); + } + else if (0 == strncmp(*message, MUSICMESSAGING_START_TAG, strlen(MUSICMESSAGING_START_TAG))) + { + + } + else + { + serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); + gaim_conv_im_write (imData, NULL, *message, GAIM_MESSAGE_SYSTEM, time(NULL)); + } +} + +static void intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags) +{ + +} + + static gboolean -start_session(void) +start_session(MMConversation *mmconv) { - run_editor(); + mmconv->started = TRUE; + run_editor(mmconv); return TRUE; } @@ -75,10 +235,9 @@ { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) { - start_session(); + start_session((MMConversation *) data); } else { - - /* kill program */ + kill_editor((MMConversation *) data); } } @@ -89,27 +248,77 @@ } -static void run_editor (void) +static void run_editor (MMConversation *mmconv) { 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))) + if (!(g_spawn_async (".", args, NULL, 12, NULL, NULL, &(mmconv->pid), &spawn_error))) { gaim_notify_error(plugin_pointer, "Error Running Editor", "The following error has occured:", spawn_error->message); } } -static void add_button (GaimConversation *conv) +static void kill_editor (MMConversation *mmconv) +{ + if (mmconv->pid) + { + kill(mmconv->pid, SIGINT); + mmconv->pid = 0; + } +} + +static void init_conversation (GaimConversation *conv) +{ + MMConversation *mmconv; + mmconv = g_malloc(sizeof(MMConversation)); + + mmconv->conv = conv; + mmconv->started = FALSE; + mmconv->originator = FALSE; + mmconv->requested = FALSE; + + add_button(mmconv); + + conversations = g_list_append(conversations, mmconv); +} + +static void conv_destroyed (GaimConversation *conv) { + MMConversation *mmconv_current = NULL; + MMConversation *mmconv = NULL; + guint i; + + for (i = 0; i < g_list_length(conversations); i++) + { + mmconv_current = (MMConversation *)g_list_nth_data(conversations, i); + if (conv == mmconv_current->conv) + { + mmconv = mmconv_current; + } + } + + remove_widget(mmconv->button); + remove_widget(mmconv->seperator); + if (mmconv->started) + { + kill_editor(mmconv); + } + conversations = g_list_remove(conversations, mmconv); +} + +static void add_button (MMConversation *mmconv) +{ + GaimConversation *conv = mmconv->conv; + GtkWidget *button, *image, *sep; button = gtk_toggle_button_new(); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); - g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(music_button_toggled), NULL); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(music_button_toggled), mmconv); gchar *file_path = g_build_filename (DATADIR, "pixmaps", "gaim", "buttons", "music.png", NULL); image = gtk_image_new_from_file("/usr/local/share/pixmaps/gaim/buttons/music.png"); @@ -118,8 +327,8 @@ sep = gtk_vseparator_new(); - g_list_append(widgets, sep); - g_list_append(widgets, button); + mmconv->seperator = sep; + mmconv->button = button; gtk_widget_show(sep); gtk_widget_show(image); @@ -129,7 +338,7 @@ gtk_box_pack_start(GTK_BOX(GAIM_GTK_CONVERSATION(conv)->toolbar), button, FALSE, FALSE, 0); } -static void remove_button (GtkWidget *button) +static void remove_widget (GtkWidget *button) { gtk_widget_hide(button); gtk_widget_destroy(button); @@ -186,7 +395,7 @@ NULL, GAIM_PRIORITY_DEFAULT, - MUSICMESSAGIN_PLUGIN_ID, + MUSICMESSAGING_PLUGIN_ID, "Music Messaging", VERSION, "Music Messaging Plugin for collabrative composition.",