Mercurial > pidgin
comparison plugins/musicmessaging/musicmessaging.c @ 11417:a9ec436535bc
[gaim-migrate @ 13654]
- Fixed up for dbus
- Receives MM specific messages.
- Handshaking protocol complete.
NOTE: stuff is commented for testing. Will be fixed shortly.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Muise <christian.muise@gmail.com> |
---|---|
date | Fri, 02 Sep 2005 00:40:22 +0000 |
parents | 817e52833803 |
children | 29aaa7d29015 |
comparison
equal
deleted
inserted
replaced
11416:f0b84eb8f0cb | 11417:a9ec436535bc |
---|---|
42 #define MUSICMESSAGING_PLUGIN_ID "gtk-hazure-musicmessaging" | 42 #define MUSICMESSAGING_PLUGIN_ID "gtk-hazure-musicmessaging" |
43 #define MUSICMESSAGING_PREFIX "##MM##" | 43 #define MUSICMESSAGING_PREFIX "##MM##" |
44 #define MUSICMESSAGING_START_MSG "A music messaging session has been requested. Please click the MM icon to accept." | 44 #define MUSICMESSAGING_START_MSG "A music messaging session has been requested. Please click the MM icon to accept." |
45 #define MUSICMESSAGING_CONFIRM_MSG "Music messaging session confirmed." | 45 #define MUSICMESSAGING_CONFIRM_MSG "Music messaging session confirmed." |
46 | 46 |
47 /* Globals */ | |
48 /* List of sessions */ | |
49 GList *conversations; | |
50 | |
51 /* Pointer to this plugin */ | |
52 GaimPlugin *plugin_pointer; | |
53 | |
54 /* Define types needed for DBus */ | |
55 DBusGConnection *connection; | |
56 DBusGProxy *proxy; | |
57 #define DBUS_SERVICE_GSCORE "org.gscore.GScoreService" | |
58 #define DBUS_PATH_GSCORE "/org/gscore/GScoreObject" | |
59 #define DBUS_INTERFACE_GSCORE "org.gscore.GScoreInterface" | |
60 | |
61 /* Define the functions to export for use with DBus */ | |
62 DBUS_EXPORT void music_messaging_change_request (const char *command, const char *parameters); | |
63 DBUS_EXPORT void music_messaging_change_confirmed (const char *command, const char *parameters); | |
64 DBUS_EXPORT void music_messaging_change_failed (const char *id, const char *command, const char *parameters); | |
65 DBUS_EXPORT void music_messaging_done_session (void); | |
66 | |
67 /* This file has been generated by the #dbus-analize-functions.py | |
68 script. It contains dbus wrappers for the four functions declared | |
69 above. */ | |
70 #include "music-messaging-bindings.c" | |
71 | |
72 /* Exported functions */ | |
73 void music_messaging_change_request(const char *command, const char *parameters) | |
74 { | |
75 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, | |
76 parameters, NULL, NULL, NULL); | |
77 } | |
78 | |
79 void music_messaging_change_confirmed(const char *command, const char *parameters) | |
80 { | |
81 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, | |
82 parameters, NULL, NULL, NULL); | |
83 } | |
84 | |
85 void music_messaging_change_failed(const char *id, const char *command, const char *parameters) | |
86 { | |
87 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, | |
88 parameters, NULL, NULL, NULL); | |
89 } | |
90 | |
91 void music_messaging_done_session(void) | |
92 { | |
93 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, "Session", | |
94 "Session Complete", NULL, NULL, NULL); | |
95 } | |
96 | |
97 typedef struct { | 47 typedef struct { |
98 GaimConversation *conv; /* pointer to the conversation */ | 48 GaimConversation *conv; /* pointer to the conversation */ |
99 GtkWidget *seperator; /* seperator in the conversation */ | 49 GtkWidget *seperator; /* seperator in the conversation */ |
100 GtkWidget *button; /* button in the conversation */ | 50 GtkWidget *button; /* button in the conversation */ |
101 GPid pid; /* the pid of the score editor */ | 51 GPid pid; /* the pid of the score editor */ |
113 static void remove_widget (GtkWidget *button); | 63 static void remove_widget (GtkWidget *button); |
114 static void init_conversation (GaimConversation *conv); | 64 static void init_conversation (GaimConversation *conv); |
115 static void conv_destroyed(GaimConversation *conv); | 65 static void conv_destroyed(GaimConversation *conv); |
116 static gboolean intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData); | 66 static gboolean intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData); |
117 static gboolean intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags); | 67 static gboolean intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags); |
68 static gboolean send_change_request (const int session, const char *id, const char *command, const char *parameters); | |
69 static gboolean send_change_confirmed (const int session, const char *command, const char *parameters); | |
70 static void session_end (MMConversation *mmconv); | |
71 | |
72 /* Globals */ | |
73 /* List of sessions */ | |
74 GList *conversations; | |
75 | |
76 /* Pointer to this plugin */ | |
77 GaimPlugin *plugin_pointer; | |
78 | |
79 /* Define types needed for DBus */ | |
80 DBusGConnection *connection; | |
81 DBusGProxy *proxy; | |
82 #define DBUS_SERVICE_GSCORE "org.gscore.GScoreService" | |
83 #define DBUS_PATH_GSCORE "/org/gscore/GScoreObject" | |
84 #define DBUS_INTERFACE_GSCORE "org.gscore.GScoreInterface" | |
85 | |
86 /* Define the functions to export for use with DBus */ | |
87 DBUS_EXPORT void music_messaging_change_request (const int session, const char *command, const char *parameters); | |
88 DBUS_EXPORT void music_messaging_change_confirmed (const int session, const char *command, const char *parameters); | |
89 DBUS_EXPORT void music_messaging_change_failed (const int session, const char *id, const char *command, const char *parameters); | |
90 DBUS_EXPORT void music_messaging_done_session (const int session); | |
91 | |
92 /* This file has been generated by the #dbus-analize-functions.py | |
93 script. It contains dbus wrappers for the four functions declared | |
94 above. */ | |
95 #include "music-messaging-bindings.c" | |
96 | |
97 /* Exported functions */ | |
98 void music_messaging_change_request(const int session, const char *command, const char *parameters) | |
99 { | |
100 | |
101 MMConversation *mmconv = (MMConversation *)g_list_nth_data(conversations, session); | |
102 | |
103 if (mmconv->started) | |
104 { | |
105 if (mmconv->originator) | |
106 { | |
107 char *name = (mmconv->conv)->name; | |
108 send_change_request (session, name, command, parameters); | |
109 } else | |
110 { | |
111 GString *to_send = g_string_new(""); | |
112 g_string_append_printf(to_send, "##MM## request %s %s##MM##", command, parameters); | |
113 | |
114 gaim_conv_im_send(GAIM_CONV_IM(mmconv->conv), to_send->str); | |
115 | |
116 gaim_debug_misc("Sent request: %s\n", to_send->str); | |
117 } | |
118 } | |
119 | |
120 } | |
121 | |
122 void music_messaging_change_confirmed(const int session, const char *command, const char *parameters) | |
123 { | |
124 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, | |
125 parameters, NULL, NULL, NULL); | |
126 | |
127 MMConversation *mmconv = (MMConversation *)g_list_nth_data(conversations, session); | |
128 | |
129 if (mmconv->started) | |
130 { | |
131 if (mmconv->originator) | |
132 { | |
133 GString *to_send = g_string_new(""); | |
134 g_string_append_printf(to_send, "##MM## confirm %s %s##MM##", command, parameters); | |
135 | |
136 gaim_conv_im_send(GAIM_CONV_IM(mmconv->conv), to_send->str); | |
137 send_change_confirmed(session, command, parameters); | |
138 } else | |
139 { | |
140 /* Do nothing. If they aren't the originator, then they can't confirm. */ | |
141 } | |
142 } | |
143 | |
144 } | |
145 | |
146 void music_messaging_change_failed(const int session, const char *id, const char *command, const char *parameters) | |
147 { | |
148 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, command, | |
149 parameters, NULL, NULL, NULL); | |
150 | |
151 MMConversation *mmconv = (MMConversation *)g_list_nth_data(conversations, session); | |
152 | |
153 if (mmconv->started) | |
154 { | |
155 if (mmconv->originator) | |
156 { | |
157 GString *to_send = g_string_new(""); | |
158 g_string_append_printf(to_send, "##MM## failed %s %s %s##MM##", id, command, parameters); | |
159 | |
160 gaim_conv_im_send(GAIM_CONV_IM(mmconv->conv), to_send->str); | |
161 } else | |
162 { | |
163 /* Do nothing. If they aren't the originator, then they can't confirm. */ | |
164 } | |
165 } | |
166 } | |
167 | |
168 void music_messaging_done_session(const int session) | |
169 { | |
170 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_INFO, "Session", | |
171 "Session Complete", NULL, NULL, NULL); | |
172 | |
173 MMConversation *mmconv = (MMConversation *)g_list_nth_data(conversations, session); | |
174 | |
175 session_end(mmconv); | |
176 } | |
118 | 177 |
119 | 178 |
120 /* DBus commands that can be sent to the editor */ | 179 /* DBus commands that can be sent to the editor */ |
121 | 180 G_BEGIN_DECLS |
122 void send_change_request (const char *id, const char *command, const char *parameters) | 181 DBusConnection *gaim_dbus_get_connection(void); |
123 { | 182 G_END_DECLS |
124 dbus_g_proxy_call_no_reply(proxy, "GscoreChangeRequest", | 183 |
125 G_TYPE_STRING, &id, | 184 static gboolean send_change_request (const int session, const char *id, const char *command, const char *parameters) |
126 G_TYPE_STRING, &command, | 185 { |
127 G_TYPE_STRING, ¶meters, | 186 DBusMessage *message; |
128 G_TYPE_INVALID); | 187 |
129 } | 188 /* Create the signal we need */ |
130 | 189 message = dbus_message_new_signal (DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, "GscoreChangeRequest"); |
131 void send_change_confirmed (const char *command, const char *parameters) | 190 |
132 { | 191 /* Append the string "Ping!" to the signal */ |
133 dbus_g_proxy_call_no_reply(proxy, "GscoreChangeConfirmed", | 192 dbus_message_append_args (message, |
134 G_TYPE_STRING, &command, | 193 DBUS_TYPE_INT32, &session, |
135 G_TYPE_STRING, ¶meters, | 194 DBUS_TYPE_STRING, &id, |
136 G_TYPE_INVALID); | 195 DBUS_TYPE_STRING, &command, |
137 } | 196 DBUS_TYPE_STRING, ¶meters, |
138 | 197 DBUS_TYPE_INVALID); |
198 | |
199 /* Send the signal */ | |
200 dbus_connection_send (gaim_dbus_get_connection(), message, NULL); | |
201 | |
202 /* Free the signal now we have finished with it */ | |
203 dbus_message_unref (message); | |
204 | |
205 /* Tell the user we sent a signal */ | |
206 g_printerr("Sent change request signal: %d %s %s %s\n", session, id, command, parameters); | |
207 | |
208 return TRUE; | |
209 } | |
210 | |
211 static gboolean send_change_confirmed (const int session, const char *command, const char *parameters) | |
212 { | |
213 DBusMessage *message; | |
214 | |
215 /* Create the signal we need */ | |
216 message = dbus_message_new_signal (DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, "GscoreChangeConfirmed"); | |
217 | |
218 /* Append the string "Ping!" to the signal */ | |
219 dbus_message_append_args (message, | |
220 DBUS_TYPE_INT32, &session, | |
221 DBUS_TYPE_STRING, &command, | |
222 DBUS_TYPE_STRING, ¶meters, | |
223 DBUS_TYPE_INVALID); | |
224 | |
225 /* Send the signal */ | |
226 dbus_connection_send (gaim_dbus_get_connection(), message, NULL); | |
227 | |
228 /* Free the signal now we have finished with it */ | |
229 dbus_message_unref (message); | |
230 | |
231 /* Tell the user we sent a signal */ | |
232 g_printerr("Sent change confirmed signal.\n"); | |
233 | |
234 return TRUE; | |
235 } | |
236 | |
237 | |
238 static int | |
239 mmconv_from_conv_loc(GaimConversation *conv) | |
240 { | |
241 MMConversation *mmconv_current = NULL; | |
242 guint i; | |
243 | |
244 for (i = 0; i < g_list_length(conversations); i++) | |
245 { | |
246 mmconv_current = (MMConversation *)g_list_nth_data(conversations, i); | |
247 if (conv == mmconv_current->conv) | |
248 { | |
249 return i; | |
250 } | |
251 } | |
252 return -1; | |
253 } | |
139 | 254 |
140 static MMConversation* | 255 static MMConversation* |
141 mmconv_from_conv(GaimConversation *conv) | 256 mmconv_from_conv(GaimConversation *conv) |
142 { | 257 { |
143 MMConversation *mmconv_current = NULL; | 258 return (MMConversation *)g_list_nth_data(conversations, mmconv_from_conv_loc(conv)); |
144 guint i; | |
145 | |
146 for (i = 0; i < g_list_length(conversations); i++) | |
147 { | |
148 mmconv_current = (MMConversation *)g_list_nth_data(conversations, i); | |
149 if (conv == mmconv_current->conv) | |
150 { | |
151 return mmconv_current; | |
152 } | |
153 } | |
154 return NULL; | |
155 } | |
156 | |
157 static gboolean | |
158 init_mm_dbus_connection() | |
159 { | |
160 GError *error = NULL; | |
161 g_type_init (); | |
162 | |
163 connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); | |
164 if (!connection) | |
165 { | |
166 g_printerr ("Failed to open connection to bus: %s\n", error->message); | |
167 g_error_free (error); | |
168 return FALSE; | |
169 } | |
170 | |
171 proxy = dbus_g_proxy_new_for_name (connection, | |
172 DBUS_SERVICE_GSCORE, | |
173 DBUS_PATH_GSCORE, | |
174 DBUS_INTERFACE_GSCORE); | |
175 if (!proxy) | |
176 { | |
177 g_printerr("Failed to create the proxy: %s\n", error->message); | |
178 return FALSE; | |
179 } | |
180 | |
181 return TRUE; | |
182 } | 259 } |
183 | 260 |
184 static gboolean | 261 static gboolean |
185 plugin_load(GaimPlugin *plugin) { | 262 plugin_load(GaimPlugin *plugin) { |
186 /* First, we have to register our four exported functions with the | 263 /* First, we have to register our four exported functions with the |
187 main gaim dbus loop. Without this statement, the gaim dbus | 264 main gaim dbus loop. Without this statement, the gaim dbus |
188 code wouldn't know about our functions. */ | 265 code wouldn't know about our functions. */ |
189 GAIM_DBUS_REGISTER_BINDINGS(plugin); | 266 GAIM_DBUS_REGISTER_BINDINGS(plugin); |
190 | 267 |
191 /* We need to initialize the dbus stuff */ | |
192 init_mm_dbus_connection(); | |
193 | 268 |
194 gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Welcome", | 269 gaim_notify_message(plugin, GAIM_NOTIFY_MSG_INFO, "Welcome", |
195 "Welcome to music messaging.", NULL, NULL, NULL); | 270 "Welcome to music messaging.", NULL, NULL, NULL); |
196 /* Keep the plugin for reference (needed for notify's) */ | 271 /* Keep the plugin for reference (needed for notify's) */ |
197 plugin_pointer = plugin; | 272 plugin_pointer = plugin; |
208 /* Listen for conversations that are ending */ | 283 /* Listen for conversations that are ending */ |
209 gaim_signal_connect(conv_list_handle, "deleting-conversation", | 284 gaim_signal_connect(conv_list_handle, "deleting-conversation", |
210 plugin, GAIM_CALLBACK(conv_destroyed), NULL); | 285 plugin, GAIM_CALLBACK(conv_destroyed), NULL); |
211 | 286 |
212 /* Listen for sending/receiving messages to replace tags */ | 287 /* Listen for sending/receiving messages to replace tags */ |
213 gaim_signal_connect(conv_list_handle, "writing-im-msg", | 288 gaim_signal_connect(conv_list_handle, "displaying-im-msg", |
214 plugin, GAIM_CALLBACK(intercept_sent), NULL); | 289 plugin, GAIM_CALLBACK(intercept_sent), NULL); |
215 gaim_signal_connect(conv_list_handle, "receiving-im-msg", | 290 gaim_signal_connect(conv_list_handle, "receiving-im-msg", |
216 plugin, GAIM_CALLBACK(intercept_received), NULL); | 291 plugin, GAIM_CALLBACK(intercept_received), NULL); |
217 | 292 |
218 return TRUE; | 293 return TRUE; |
236 | 311 |
237 | 312 |
238 static gboolean | 313 static gboolean |
239 intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData) | 314 intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData) |
240 { | 315 { |
241 GaimConnection *connection = gaim_conversation_get_gc(conv); | |
242 const char *convName = gaim_conversation_get_name(conv); | |
243 | 316 |
244 if (0 == strncmp(*message, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX))) | 317 if (0 == strncmp(*message, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX))) |
245 { | 318 { |
246 gaim_debug_misc("gaim-musicmessaging", "Sent MM Message: %s\n", *message); | 319 gaim_debug_misc("gaim-musicmessaging", "Sent MM Message: %s\n", *message); |
247 serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); | |
248 message = 0; | 320 message = 0; |
249 } | 321 } |
250 else if (0 == strncmp(*message, MUSICMESSAGING_START_MSG, strlen(MUSICMESSAGING_START_MSG))) | 322 else if (0 == strncmp(*message, MUSICMESSAGING_START_MSG, strlen(MUSICMESSAGING_START_MSG))) |
251 { | 323 { |
252 gaim_debug_misc("gaim-musicmessaging", "Sent MM request.\n"); | 324 gaim_debug_misc("gaim-musicmessaging", "Sent MM request.\n"); |
253 serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); | |
254 message = 0; | 325 message = 0; |
255 } | 326 } |
256 else if (0 == strncmp(*message, MUSICMESSAGING_CONFIRM_MSG, strlen(MUSICMESSAGING_CONFIRM_MSG))) | 327 else if (0 == strncmp(*message, MUSICMESSAGING_CONFIRM_MSG, strlen(MUSICMESSAGING_CONFIRM_MSG))) |
257 { | 328 { |
258 gaim_debug_misc("gaim-musicmessaging", "Sent MM confirm.\n"); | 329 gaim_debug_misc("gaim-musicmessaging", "Sent MM confirm.\n"); |
259 serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); | |
260 message = 0; | 330 message = 0; |
261 } | 331 } |
262 else if (0 == strncmp(*message, "test1", strlen("test1"))) | 332 else if (0 == strncmp(*message, "test1", strlen("test1"))) |
263 { | 333 { |
264 gaim_debug_misc("gaim-musicmessaging", "\n\nTEST 1\n\n"); | 334 gaim_debug_misc("gaim-musicmessaging", "\n\nTEST 1\n\n"); |
265 send_change_request("test-id", "test-command", "test-parameters"); | 335 send_change_request(0, "test-id", "test-command", "test-parameters"); |
266 return FALSE; | 336 return FALSE; |
267 } | 337 } |
268 else if (0 == strncmp(*message, "test2", strlen("test2"))) | 338 else if (0 == strncmp(*message, "test2", strlen("test2"))) |
269 { | 339 { |
270 gaim_debug_misc("gaim-musicmessaging", "\n\nTEST 2\n\n"); | 340 gaim_debug_misc("gaim-musicmessaging", "\n\nTEST 2\n\n"); |
271 send_change_confirmed("test-command", "test-parameters"); | 341 send_change_confirmed(1, "test-command", "test-parameters"); |
272 return FALSE; | 342 return FALSE; |
273 } | 343 } |
274 else | 344 else |
275 { | 345 { |
276 return FALSE; | 346 return FALSE; |
285 MMConversation *mmconv = mmconv_from_conv(conv); | 355 MMConversation *mmconv = mmconv_from_conv(conv); |
286 | 356 |
287 gaim_debug_misc("gaim-musicmessaging", "Intercepted: %s\n", *message); | 357 gaim_debug_misc("gaim-musicmessaging", "Intercepted: %s\n", *message); |
288 if (strstr(*message, MUSICMESSAGING_PREFIX)) | 358 if (strstr(*message, MUSICMESSAGING_PREFIX)) |
289 { | 359 { |
290 gaim_debug_misc("gaim-musicmessaging", "Received MM Message: %s\n", | 360 char *parsed_message = strtok(strstr(*message, MUSICMESSAGING_PREFIX), "<"); |
291 strtok(strstr(*message, MUSICMESSAGING_PREFIX), "<")); | 361 gaim_debug_misc("gaim-musicmessaging", "Received an MM Message: %s\n", parsed_message); |
292 | 362 |
293 /* DEAL WITH A MM MESSAGE */ | 363 if (mmconv->started) |
364 { | |
365 if (strstr(parsed_message, "request")) | |
366 { | |
367 if (mmconv->originator) | |
368 { | |
369 gaim_debug_misc("gaim-musicmessaging", "Sending request to gscore.\n"); | |
370 | |
371 int session = mmconv_from_conv_loc(conv); | |
372 char *id = (mmconv->conv)->name; | |
373 | |
374 /* Get past the first two terms - '##MM##' and 'request' */ | |
375 strtok(parsed_message, " "); /* '##MM##' */ | |
376 strtok(NULL, " "); /* 'request' */ | |
377 | |
378 char *command = strtok(NULL, " "); | |
379 char *parameters = strtok(NULL, "#"); | |
380 | |
381 send_change_request (session, id, command, parameters); | |
382 | |
383 } | |
384 } else if (strstr(parsed_message, "confirm")) | |
385 { | |
386 if (!mmconv->originator) | |
387 { | |
388 gaim_debug_misc("gaim-musicmessaging", "Sending confirmation to gscore.\n"); | |
389 | |
390 int session = mmconv_from_conv_loc(conv); | |
391 | |
392 /* Get past the first two terms - '##MM##' and 'confirm' */ | |
393 strtok(parsed_message, " "); /* '##MM##' */ | |
394 strtok(NULL, " "); /* 'confirm' */ | |
395 | |
396 char *command = strtok(NULL, " "); | |
397 char *parameters = strtok(NULL, "#"); | |
398 | |
399 send_change_confirmed (session, command, parameters); | |
400 } | |
401 } else if (strstr(parsed_message, "failed")) | |
402 { | |
403 /* Get past the first two terms - '##MM##' and 'confirm' */ | |
404 strtok(parsed_message, " "); /* '##MM##' */ | |
405 strtok(NULL, " "); /* 'failed' */ | |
406 | |
407 char *id = strtok(NULL, " "); | |
408 char *command = strtok(NULL, " "); | |
409 /* char *parameters = strtok(NULL, "#"); DONT NEED PARAMETERS */ | |
410 | |
411 if ((mmconv->conv)->name == id) | |
412 { | |
413 gaim_notify_message(plugin_pointer, GAIM_NOTIFY_MSG_ERROR, "Music Messaging", | |
414 "There was a conflict in running the command:", command, NULL, NULL); | |
415 } | |
416 } | |
417 } | |
294 | 418 |
295 message = 0; | 419 message = 0; |
296 } | 420 } |
297 else if (strstr(*message, MUSICMESSAGING_START_MSG)) | 421 else if (strstr(*message, MUSICMESSAGING_START_MSG)) |
298 { | 422 { |
343 { | 467 { |
344 run_editor(mmconv); | 468 run_editor(mmconv); |
345 return TRUE; | 469 return TRUE; |
346 } | 470 } |
347 | 471 |
472 static void session_end (MMConversation *mmconv) | |
473 { | |
474 mmconv->started = FALSE; | |
475 mmconv->originator = FALSE; | |
476 mmconv->requested = FALSE; | |
477 kill_editor(mmconv); | |
478 } | |
479 | |
348 static void music_button_toggled (GtkWidget *widget, gpointer data) | 480 static void music_button_toggled (GtkWidget *widget, gpointer data) |
349 { | 481 { |
482 MMConversation *mmconv = mmconv_from_conv(((MMConversation *) data)->conv); | |
350 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) | 483 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) |
351 { | 484 { |
352 if (((MMConversation *) data)->requested) | 485 //if (((MMConversation *) data)->requested) |
353 { | 486 //{ |
354 start_session((MMConversation *) data); | 487 if (!mmconv){ g_printerr("DEBUG: About to bust\n"); } |
355 send_request_confirmed((MMConversation *) data); | 488 start_session(mmconv); |
356 } | 489 send_request_confirmed(mmconv); |
490 /*} | |
357 else | 491 else |
358 { | 492 { |
359 ((MMConversation *) data)->originator = TRUE; | 493 ((MMConversation *) data)->originator = TRUE; |
360 send_request((MMConversation *) data); | 494 send_request((MMConversation *) data); |
361 } | 495 }*/ |
362 } else { | 496 } else { |
363 ((MMConversation *)data)->started = FALSE; | 497 session_end((MMConversation *)data); |
364 ((MMConversation *)data)->originator = FALSE; | |
365 ((MMConversation *)data)->requested = FALSE; | |
366 kill_editor((MMConversation *) data); | |
367 } | 498 } |
368 } | 499 } |
369 | 500 |
370 static void set_editor_path (GtkWidget *button, GtkWidget *text_field) | 501 static void set_editor_path (GtkWidget *button, GtkWidget *text_field) |
371 { | 502 { |
375 } | 506 } |
376 | 507 |
377 static void run_editor (MMConversation *mmconv) | 508 static void run_editor (MMConversation *mmconv) |
378 { | 509 { |
379 GError *spawn_error = NULL; | 510 GError *spawn_error = NULL; |
380 gchar * args[2]; | 511 gchar * args[4]; |
381 args[0] = (gchar *)gaim_prefs_get_string("/plugins/gtk/musicmessaging/editor_path"); | 512 args[0] = (gchar *)gaim_prefs_get_string("/plugins/gtk/musicmessaging/editor_path"); |
382 args[1] = NULL; | 513 |
383 if (!(g_spawn_async (".", args, NULL, 12, NULL, NULL, &(mmconv->pid), &spawn_error))) | 514 args[1] = "-session_id"; |
515 GString *session_id = g_string_new(""); | |
516 g_string_sprintfa(session_id, "%d", mmconv_from_conv_loc(mmconv->conv)); | |
517 args[2] = session_id->str; | |
518 | |
519 args[3] = NULL; | |
520 | |
521 if (!(g_spawn_async (".", args, NULL, 4, NULL, NULL, &(mmconv->pid), &spawn_error))) | |
384 { | 522 { |
385 gaim_notify_error(plugin_pointer, "Error Running Editor", | 523 gaim_notify_error(plugin_pointer, "Error Running Editor", |
386 "The following error has occured:", spawn_error->message); | 524 "The following error has occured:", spawn_error->message); |
387 mmconv->started = FALSE; | 525 mmconv->started = FALSE; |
388 } | 526 } |