⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 musicmessaging.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
{	MMConversation *mmconv = mmconv_from_conv(conv);		purple_debug_misc("purple-musicmessaging", "Intercepted: %s\n", *message);	if (strstr(*message, MUSICMESSAGING_PREFIX))	{		char *parsed_message = strtok(strstr(*message, MUSICMESSAGING_PREFIX), "<");		purple_debug_misc("purple-musicmessaging", "Received an MM Message: %s\n", parsed_message);						if (mmconv->started)		{			if (strstr(parsed_message, "request"))			{				if (mmconv->originator)				{					int session = mmconv_from_conv_loc(conv);					char *id = (mmconv->conv)->name;					char *command;					char *parameters;										purple_debug_misc("purple-musicmessaging", "Sending request to gscore.\n");										/* Get past the first two terms - '##MM##' and 'request' */					strtok(parsed_message, " "); /* '##MM##' */					strtok(NULL, " "); /* 'request' */										command = strtok(NULL, " ");					parameters = strtok(NULL, "#");										send_change_request (session, id, command, parameters);									}			} else if (strstr(parsed_message, "confirm"))			{				if (!mmconv->originator)				{					int session = mmconv_from_conv_loc(conv);					char *command;					char *parameters;										purple_debug_misc("purple-musicmessaging", "Sending confirmation to gscore.\n");										/* Get past the first two terms - '##MM##' and 'confirm' */					strtok(parsed_message, " "); /* '##MM##' */					strtok(NULL, " "); /* 'confirm' */										command = strtok(NULL, " ");					parameters = strtok(NULL, "#");										send_change_confirmed (session, command, parameters);				}			} else if (strstr(parsed_message, "failed"))			{				char *id;				char *command;								/* Get past the first two terms - '##MM##' and 'confirm' */				strtok(parsed_message, " "); /* '##MM##' */				strtok(NULL, " "); /* 'failed' */								id = strtok(NULL, " ");				command = strtok(NULL, " ");				/* char *parameters = strtok(NULL, "#"); DONT NEED PARAMETERS */								if ((mmconv->conv)->name == id)				{					purple_notify_message(plugin_pointer, PURPLE_NOTIFY_MSG_ERROR, 							    _("Music Messaging"),							    _("There was a conflict in running the command:"), command, NULL, NULL);				}			}		}				message = 0;	}	else if (strstr(*message, MUSICMESSAGING_START_MSG))	{		purple_debug_misc("purple-musicmessaging", "Received MM request.\n");		if (!(mmconv->originator))		{			mmconv->requested = TRUE;			return FALSE;		}			}	else if (strstr(*message, MUSICMESSAGING_CONFIRM_MSG))	{		purple_debug_misc("purple-musicmessagin", "Received MM confirm.\n");				if (mmconv->originator)		{			start_session(mmconv);			return FALSE;		}	}	else	{		return FALSE;		/* Do nothing. */	}	return TRUE;}static void send_request(MMConversation *mmconv){	PurpleConnection *connection = purple_conversation_get_gc(mmconv->conv);	const char *convName = purple_conversation_get_name(mmconv->conv);	serv_send_im(connection, convName, MUSICMESSAGING_START_MSG, PURPLE_MESSAGE_SEND);}static void send_request_confirmed(MMConversation *mmconv){	PurpleConnection *connection = purple_conversation_get_gc(mmconv->conv);	const char *convName = purple_conversation_get_name(mmconv->conv);	serv_send_im(connection, convName, MUSICMESSAGING_CONFIRM_MSG, PURPLE_MESSAGE_SEND);}	static gbooleanstart_session(MMConversation *mmconv){		run_editor(mmconv);	return TRUE;}static void session_end (MMConversation *mmconv){	mmconv->started = FALSE;	mmconv->originator = FALSE;	mmconv->requested = FALSE;	kill_editor(mmconv);}static void music_button_toggled (GtkWidget *widget, gpointer data){	MMConversation *mmconv = mmconv_from_conv(((MMConversation *) data)->conv);	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))     {		if (((MMConversation *) data)->requested)		{			start_session(mmconv);			send_request_confirmed(mmconv);		}		else		{			((MMConversation *) data)->originator = TRUE;			send_request((MMConversation *) data);		}    } else {		session_end((MMConversation *)data);    }}static void set_editor_path (GtkWidget *button, GtkWidget *text_field){	const char * path = gtk_entry_get_text((GtkEntry*)text_field);	purple_prefs_set_string("/plugins/gtk/musicmessaging/editor_path", path);	}static void run_editor (MMConversation *mmconv){	GError *spawn_error = NULL;	GString *session_id;	gchar * args[4];	args[0] = (gchar *)purple_prefs_get_string("/plugins/gtk/musicmessaging/editor_path");		args[1] = "-session_id";	session_id = g_string_new("");	g_string_sprintfa(session_id, "%d", mmconv_from_conv_loc(mmconv->conv));	args[2] = session_id->str;		args[3] = NULL;		if (!(g_spawn_async (".", args, NULL, 4, NULL, NULL, &(mmconv->pid), &spawn_error)))	{		purple_notify_error(plugin_pointer, _("Error Running Editor"),				  _("The following error has occurred:"), spawn_error->message);		mmconv->started = FALSE;	}	else	{		mmconv->started = TRUE;	}}static void kill_editor (MMConversation *mmconv){	if (mmconv->pid)	{		kill(mmconv->pid, SIGINT);		mmconv->pid = 0;	}}static void init_conversation (PurpleConversation *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 (PurpleConversation *conv){	MMConversation *mmconv = mmconv_from_conv(conv);		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){	PurpleConversation *conv = mmconv->conv;		GtkWidget *button, *image, *sep;	gchar *file_path;	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), mmconv);	file_path = g_build_filename(DATADIR, "pixmaps", "purple", "buttons",										"music.png", NULL);	image = gtk_image_new_from_file(file_path);	g_free(file_path);	gtk_container_add((GtkContainer *)button, image);		sep = gtk_vseparator_new();		mmconv->seperator = sep;	mmconv->button = button;		gtk_widget_show(sep);	gtk_widget_show(image);	gtk_widget_show(button);		gtk_box_pack_start(GTK_BOX(PIDGIN_CONVERSATION(conv)->toolbar), sep, FALSE, FALSE, 0);	gtk_box_pack_start(GTK_BOX(PIDGIN_CONVERSATION(conv)->toolbar), button, FALSE, FALSE, 0);}static void remove_widget (GtkWidget *button){	gtk_widget_hide(button);	gtk_widget_destroy(button);		}static GtkWidget *get_config_frame(PurplePlugin *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);	/* Configuration frame */	vbox = pidgin_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;}static PidginPluginUiInfo ui_info ={	get_config_frame,	0, /* page_num (reserved) */	/* padding */	NULL,	NULL,	NULL,	NULL};static PurplePluginInfo info = {    PURPLE_PLUGIN_MAGIC,    PURPLE_MAJOR_VERSION,    PURPLE_MINOR_VERSION,    PURPLE_PLUGIN_STANDARD,                                /**< type           */    PIDGIN_PLUGIN_TYPE,                                /**< ui_requirement */    0,                                                   /**< flags          */    NULL,                                                /**< dependencies   */    PURPLE_PRIORITY_DEFAULT,                               /**< priority       */    MUSICMESSAGING_PLUGIN_ID,                            /**< id             */    "Music Messaging",	                                 /**< name           */    VERSION,                                             /**< version        */    N_("Music Messaging Plugin for collaborative composition."),                                                         /**  summary        */    N_("The Music Messaging Plugin allows a number of users to simultaneously work on a piece of music by editting a common score in real-time."),	                                                 /**  description    */    "Christian Muise <christian.muise@gmail.com>",       /**< author         */    PURPLE_WEBSITE,                                        /**< homepage       */    plugin_load,                                         /**< load           */    plugin_unload,                                       /**< unload         */    NULL,                                                /**< destroy        */    &ui_info,                                            /**< ui_info        */    NULL,                                                /**< extra_info     */    NULL,    NULL,	/* padding */	NULL,	NULL,	NULL,	NULL};static voidinit_plugin(PurplePlugin *plugin) {	purple_prefs_add_none("/plugins/gtk/musicmessaging");	purple_prefs_add_string("/plugins/gtk/musicmessaging/editor_path", "/usr/bin/gscore");}PURPLE_INIT_PLUGIN(musicmessaging, init_plugin, info);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -