| 104 static void kill_editor(MMConversation *mmconv); |
105 static void kill_editor(MMConversation *mmconv); |
| 105 static void add_button (MMConversation *mmconv); |
106 static void add_button (MMConversation *mmconv); |
| 106 static void remove_widget (GtkWidget *button); |
107 static void remove_widget (GtkWidget *button); |
| 107 static void init_conversation (GaimConversation *conv); |
108 static void init_conversation (GaimConversation *conv); |
| 108 static void conv_destroyed(GaimConversation *conv); |
109 static void conv_destroyed(GaimConversation *conv); |
| 109 static void intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData); |
110 static gboolean intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData); |
| 110 static void intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags); |
111 static gboolean intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags); |
| 111 |
112 |
| 112 |
113 |
| 113 /* DBus commands that can be sent to the editor */ |
114 /* DBus commands that can be sent to the editor */ |
| 114 G_BEGIN_DECLS |
115 G_BEGIN_DECLS |
| 115 DBusConnection *gaim_dbus_get_connection(void); |
116 DBusConnection *gaim_dbus_get_connection(void); |
| 116 G_END_DECLS |
117 G_END_DECLS |
| 117 |
118 |
| 118 void send_change_request (const char *id, const char *command, const char *parameters) |
119 void send_change_request (const char *id, const char *command, const char *parameters) |
| 119 { |
120 { |
| 120 DBusMessage *signal; |
121 DBusMessage *method_call; |
| 121 signal = dbus_message_new_signal("/org/gscore/GScoreObject", "org.gscore.GScoreInterface", "gscore_change_request"); |
122 method_call = dbus_message_new_method_call(NULL, "/org/gscore/GScoreObject", "org.gscore.GScoreInterface", "gscore_change_request"); |
| 122 |
123 |
| 123 dbus_message_append_args(signal, |
124 dbus_message_append_args(method_call, |
| 124 DBUS_TYPE_STRING, &id, |
125 DBUS_TYPE_STRING, &id, |
| 125 DBUS_TYPE_STRING, &command, |
126 DBUS_TYPE_STRING, &command, |
| 126 DBUS_TYPE_STRING, ¶meters, |
127 DBUS_TYPE_STRING, ¶meters, |
| 127 DBUS_TYPE_INVALID); |
128 DBUS_TYPE_INVALID); |
| 128 |
129 |
| 129 dbus_connection_send(gaim_dbus_get_connection(), signal, NULL); |
130 dbus_connection_send(gaim_dbus_get_connection(), method_call, NULL); |
| 130 dbus_message_unref(signal); |
131 dbus_message_unref(method_call); |
| 131 } |
132 } |
| 132 |
133 |
| 133 void send_change_confirmed (const char *command, const char *parameters) |
134 void send_change_confirmed (const char *command, const char *parameters) |
| 134 { |
135 { |
| 135 DBusMessage *signal; |
136 DBusMessage *method_call; |
| 136 signal = dbus_message_new_signal("/org/gscore/GScoreObject", "org.gscore.GScoreInterface", "gscore_change_confirmed"); |
137 method_call = dbus_message_new_method_call(NULL, "/org/gscore/GScoreObject", "org.gscore.GScoreInterface", "gscore_change_confirmed"); |
| 137 |
138 |
| 138 dbus_message_append_args(signal, |
139 dbus_message_append_args(method_call, |
| 139 DBUS_TYPE_STRING, &command, |
140 DBUS_TYPE_STRING, &command, |
| 140 DBUS_TYPE_STRING, ¶meters, |
141 DBUS_TYPE_STRING, ¶meters, |
| 141 DBUS_TYPE_INVALID); |
142 DBUS_TYPE_INVALID); |
| 142 |
143 |
| 143 dbus_connection_send(gaim_dbus_get_connection(), signal, NULL); |
144 dbus_connection_send(gaim_dbus_get_connection(), method_call, NULL); |
| 144 dbus_message_unref(signal); |
145 dbus_message_unref(method_call); |
| 145 } |
146 } |
| 146 |
147 |
| |
148 |
| |
149 static MMConversation* |
| |
150 mmconv_from_conv(GaimConversation *conv) |
| |
151 { |
| |
152 MMConversation *mmconv_current = NULL; |
| |
153 guint i; |
| |
154 |
| |
155 for (i = 0; i < g_list_length(conversations); i++) |
| |
156 { |
| |
157 mmconv_current = (MMConversation *)g_list_nth_data(conversations, i); |
| |
158 if (conv == mmconv_current->conv) |
| |
159 { |
| |
160 return mmconv_current; |
| |
161 } |
| |
162 } |
| |
163 return NULL; |
| |
164 } |
| 147 |
165 |
| 148 static gboolean |
166 static gboolean |
| 149 plugin_load(GaimPlugin *plugin) { |
167 plugin_load(GaimPlugin *plugin) { |
| 150 /* First, we have to register our four exported functions with the |
168 /* First, we have to register our four exported functions with the |
| 151 main gaim dbus loop. Without this statement, the gaim dbus |
169 main gaim dbus loop. Without this statement, the gaim dbus |
| 192 conv_destroyed(mmconv->conv); |
210 conv_destroyed(mmconv->conv); |
| 193 } |
211 } |
| 194 return TRUE; |
212 return TRUE; |
| 195 } |
213 } |
| 196 |
214 |
| 197 static void intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData) |
215 |
| 198 { |
216 |
| 199 GaimConvIm *imData = gaim_conversation_get_im_data(conv); |
217 static gboolean |
| |
218 intercept_sent(GaimAccount *account, GaimConversation *conv, char **message, void* pData) |
| |
219 { |
| 200 GaimConnection *connection = gaim_conversation_get_gc(conv); |
220 GaimConnection *connection = gaim_conversation_get_gc(conv); |
| 201 const char *convName = gaim_conversation_get_name(conv); |
221 const char *convName = gaim_conversation_get_name(conv); |
| 202 /* const char *who = gaim_account_get_username(account); */ |
|
| 203 |
222 |
| 204 if (0 == strncmp(*message, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX))) |
223 if (0 == strncmp(*message, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX))) |
| 205 { |
224 { |
| |
225 gaim_debug_misc("gaim-musicmessaging", "Sent MM Message: %s\n", *message); |
| |
226 serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); |
| 206 message = 0; |
227 message = 0; |
| 207 gaim_debug(GAIM_DEBUG_MISC, "gaim-musicmessaging", "Received MM Message\n"); |
228 } |
| 208 } |
229 else if (0 == strncmp(*message, MUSICMESSAGING_START_MSG, strlen(MUSICMESSAGING_START_MSG))) |
| 209 else if (0 == strncmp(*message, MUSICMESSAGING_START_TAG, strlen(MUSICMESSAGING_START_TAG))) |
230 { |
| 210 { |
231 gaim_debug_misc("gaim-musicmessaging", "Sent MM request.\n"); |
| |
232 serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); |
| |
233 message = 0; |
| |
234 } |
| |
235 else if (0 == strncmp(*message, MUSICMESSAGING_CONFIRM_MSG, strlen(MUSICMESSAGING_CONFIRM_MSG))) |
| |
236 { |
| |
237 gaim_debug_misc("gaim-musicmessagin", "Sent MM confirm.\n"); |
| |
238 serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); |
| |
239 message = 0; |
| |
240 } |
| |
241 else |
| |
242 { |
| |
243 return FALSE; |
| |
244 /* Do nothing...procceed as normal */ |
| |
245 } |
| |
246 return TRUE; |
| |
247 } |
| |
248 |
| |
249 static gboolean |
| |
250 intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags) |
| |
251 { |
| |
252 MMConversation *mmconv = mmconv_from_conv(conv); |
| |
253 |
| |
254 gaim_debug_misc("gaim-musicmessaging", "Intercepted: %s\n", *message); |
| |
255 if (strstr(*message, MUSICMESSAGING_PREFIX)) |
| |
256 { |
| |
257 gaim_debug_misc("gaim-musicmessaging", "Received MM Message: %s\n", |
| |
258 strtok(strstr(*message, MUSICMESSAGING_PREFIX), "<")); |
| |
259 |
| |
260 /* DEAL WITH A MM MESSAGE */ |
| 211 |
261 |
| |
262 message = 0; |
| |
263 } |
| |
264 else if (strstr(*message, MUSICMESSAGING_START_MSG)) |
| |
265 { |
| |
266 message = 0; |
| |
267 gaim_debug_misc("gaim-musicmessaging", "Received MM request.\n"); |
| |
268 if (!(mmconv->originator)) |
| |
269 { |
| |
270 mmconv->requested = TRUE; |
| |
271 return FALSE; |
| |
272 } |
| |
273 |
| |
274 } |
| |
275 else if (strstr(*message, MUSICMESSAGING_CONFIRM_MSG)) |
| |
276 { |
| |
277 message = 0; |
| |
278 gaim_debug_misc("gaim-musicmessagin", "Received MM confirm.\n"); |
| |
279 |
| |
280 if (mmconv->originator) |
| |
281 { |
| |
282 start_session(mmconv); |
| |
283 } |
| 212 } |
284 } |
| 213 else |
285 else |
| 214 { |
286 { |
| 215 serv_send_im(connection, convName, *message, GAIM_MESSAGE_SEND); |
287 return FALSE; |
| 216 gaim_conv_im_write (imData, NULL, *message, GAIM_MESSAGE_SEND, time(NULL)); |
288 /* Do nothing. */ |
| 217 } |
289 } |
| 218 } |
290 return TRUE; |
| 219 |
291 } |
| 220 static void intercept_received(GaimAccount *account, char **sender, char **message, GaimConversation *conv, int *flags) |
292 |
| 221 { |
293 static void send_request(MMConversation *mmconv) |
| 222 |
294 { |
| 223 } |
295 GaimConnection *connection = gaim_conversation_get_gc(mmconv->conv); |
| 224 |
296 const char *convName = gaim_conversation_get_name(mmconv->conv); |
| |
297 serv_send_im(connection, convName, MUSICMESSAGING_START_MSG, GAIM_MESSAGE_SEND); |
| |
298 } |
| |
299 |
| |
300 static void send_request_confirmed(MMConversation *mmconv) |
| |
301 { |
| |
302 GaimConnection *connection = gaim_conversation_get_gc(mmconv->conv); |
| |
303 const char *convName = gaim_conversation_get_name(mmconv->conv); |
| |
304 serv_send_im(connection, convName, MUSICMESSAGING_CONFIRM_MSG, GAIM_MESSAGE_SEND); |
| |
305 } |
| |
306 |
| 225 |
307 |
| 226 static gboolean |
308 static gboolean |
| 227 start_session(MMConversation *mmconv) |
309 start_session(MMConversation *mmconv) |
| 228 { |
310 { |
| 229 if (!mmconv->requested) |
|
| 230 { |
|
| 231 mmconv->originator = TRUE; |
|
| 232 } |
|
| 233 |
|
| 234 run_editor(mmconv); |
311 run_editor(mmconv); |
| 235 return TRUE; |
312 return TRUE; |
| 236 } |
313 } |
| 237 |
314 |
| 238 static void music_button_toggled (GtkWidget *widget, gpointer data) |
315 static void music_button_toggled (GtkWidget *widget, gpointer data) |
| 239 { |
316 { |
| 240 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) |
317 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) |
| 241 { |
318 { |
| 242 start_session((MMConversation *) data); |
319 if (((MMConversation *) data)->requested) |
| |
320 { |
| |
321 start_session((MMConversation *) data); |
| |
322 send_request_confirmed((MMConversation *) data); |
| |
323 } |
| |
324 else |
| |
325 { |
| |
326 ((MMConversation *) data)->originator = TRUE; |
| |
327 send_request((MMConversation *) data); |
| |
328 } |
| 243 } else { |
329 } else { |
| 244 ((MMConversation *)data)->started = FALSE; |
330 ((MMConversation *)data)->started = FALSE; |
| |
331 ((MMConversation *)data)->originator = FALSE; |
| |
332 ((MMConversation *)data)->requested = FALSE; |
| 245 kill_editor((MMConversation *) data); |
333 kill_editor((MMConversation *) data); |
| 246 } |
334 } |
| 247 } |
335 } |
| 248 |
336 |
| 249 static void set_editor_path (GtkWidget *button, GtkWidget *text_field) |
337 static void set_editor_path (GtkWidget *button, GtkWidget *text_field) |