soc.2009.transport: 5a34f69b: Working PurpleCmd

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Thu Jun 11 04:35:33 EDT 2009


-----------------------------------------------------------------
Revision: 5a34f69b622b868539e1dd2d634291590b43572a
Ancestor: af7f11c24eada1ea8c8cb553c1e1b605f62f92f8
Author: hanzz at soc.pidgin.im
Date: 2009-06-11T08:33:27
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/5a34f69b622b868539e1dd2d634291590b43572a

Modified files:
        caps.cpp main.cpp user.cpp

ChangeLog: 

Working PurpleCmd

-------------- next part --------------
============================================================
--- caps.cpp	3c878dff7896ed1a85825accbc31ac0ddc6c304f
+++ caps.cpp	5a849ea713156c015883216cd37c1a935fb04e9a
@@ -82,10 +82,14 @@ void GlooxDiscoHandler::handleDiscoInfo(
 		std::cout << "no user?! wtf...";
 	}
 	else{
+		std::cout << "1" << "\n";
 		if (user->capsVersion().empty()){
+			std::cout << "2" << "\n";
 			user->setCapsVersion(versions[context]);
-			if (user->readyForConnect())
+			if (user->readyForConnect()) {
+				std::cout << "3" << "\n";
 				user->connect();
+			}
 		}
 	}
 	// TODO: CACHE CAPS IN DATABASE ACCORDING TO VERSION
============================================================
--- main.cpp	1e1599c31facbb39a8ba6f828a599164a4ef601f
+++ main.cpp	00e803cc42128985d84e0d104b2c2b7c9e0a7b5f
@@ -33,6 +33,7 @@
 #include "protocols/msn.h"
 #include "protocols/irc.h"
 #include "blistsaving.h"
+#include "cmds.h"
 
 #include <gloox/tlsbase.h>
 #include <gloox/compressionbase.h>
@@ -92,6 +93,51 @@ namespace gloox {
     };
 };
 
+static PurpleCmdRet help_command_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, void *data) {
+	GList *l, *text;
+	GString *s;
+	User *user = GlooxMessageHandler::instance()->userManager()->getUserByAccount(purple_conversation_get_account(conv));
+	if (!user)
+		return PURPLE_CMD_RET_OK;
+
+	if (args[0] != NULL) {
+		s = g_string_new("Transport: ");
+		text = purple_cmd_help(conv, args[0]);
+
+		if (text) {
+			for (l = text; l; l = l->next)
+				if (l->next)
+					g_string_append_printf(s, "%s\n", tr(user->getLang(),(char *)l->data));
+				else
+					g_string_append_printf(s, "%s", tr(user->getLang(),(char *)l->data));
+		} else {
+			g_string_append(s, tr(user->getLang(),_("No such command (in this context).")));
+		}
+	} else {
+		s = g_string_new(tr(user->getLang(),_("Use \"/transport help &lt;command&gt;\" for help on a specific command.\n"
+											 "The following commands are available in this context:\n")));
+
+		text = purple_cmd_list(conv);
+		for (l = text; l; l = l->next)
+			if (l->next)
+				g_string_append_printf(s, "%s, ", tr(user->getLang(),(char *)l->data));
+			else
+				g_string_append_printf(s, "%s.", tr(user->getLang(),(char *)l->data));
+		g_list_free(text);
+	}
+
+	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
+		purple_conv_im_write(PURPLE_CONV_IM(conv), purple_conversation_get_name(conv), s->str, PURPLE_MESSAGE_RECV, time(NULL));
+	}
+	else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) {
+		purple_conv_chat_write(PURPLE_CONV_CHAT(conv), "transport", s->str, PURPLE_MESSAGE_RECV, time(NULL));
+	}
+	g_string_free(s, TRUE);
+
+	return PURPLE_CMD_RET_OK;
+}
+
+
 /*
  * New message from legacy network received (we can create conversation here)
  */
@@ -112,6 +158,15 @@ static void conv_write_chat(PurpleConver
 	GlooxMessageHandler::instance()->purpleConversationWriteChat(conv,who,message,flags,mtime);
 }
 
+static void conv_write_conv(PurpleConversation *conv, const char *who, const char *alias,const char *message, PurpleMessageFlags flags, time_t mtime) {
+	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
+		conv_write_im(conv, who, message, flags, mtime);
+	}
+	else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) {
+		conv_write_chat(conv, who, message, flags, mtime);
+	}
+}
+
 static void conv_chat_add_users(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
 	GlooxMessageHandler::instance()->purpleChatAddUsers(conv, cbuddies, new_arrivals);
 }
@@ -393,7 +448,7 @@ static PurpleConversationUiOps conversat
 	NULL,//pidgin_conv_destroy,              /* destroy_conversation */
 	conv_write_chat,                              /* write_chat           */
 	conv_write_im,             /* write_im             */
-	NULL,//pidgin_conv_write_conv,           /* write_conv           */
+	conv_write_conv,           /* write_conv           */
 	conv_chat_add_users,       /* chat_add_users       */
 	conv_chat_rename_user,     /* chat_rename_user     */
 	conv_chat_remove_users,    /* chat_remove_users    */
@@ -1230,16 +1285,10 @@ bool GlooxMessageHandler::initPurple(){
 		purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", &xfer_handle, PURPLE_CALLBACK(newXfer), NULL);
 		purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", &xfer_handle, PURPLE_CALLBACK(XferComplete), NULL);
 		purple_signal_connect(purple_connections_get_handle(), "signed-on", &conn_handle,PURPLE_CALLBACK(signed_on), NULL);
-		purple_signal_connect(purple_blist_get_handle(), "buddy-removed", &blist_handle,PURPLE_CALLBACK(buddyRemoved), NULL);
-// 		purple_signal_connect(purple_connections_get_handle(), "connection-error", &conn_handle,PURPLE_CALLBACK(connection_error_cb), NULL);
-// 		base64Dir = std::string(g_build_filename(userDir.c_str(), "base64", NULL));
-// 		if (!g_file_test(base64Dir.c_str(), G_FILE_TEST_IS_DIR))
-// 		{
-// 			if (mkdir(base64Dir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) == -1){
-// 				std::cout << "!!! Can't make base64 cache dir\n";
-// 			}
-// 		}
+		purple_signal_connect(purple_blist_get_handle(), "buddy-removed", &blist_handle,PURPLE_CALLBACK(buddyRemoved), NULL);				
 
+		purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT, (PurpleCmdFlag) (PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS), NULL, help_command_cb, _("help &lt;command&gt;:  Help on a specific command."), NULL);
+
 	}
 	return ret;
 }
============================================================
--- user.cpp	c98029abb8d2339b62c30857ddc5570ec4dff862
+++ user.cpp	9cf517924a9a1be728bc6db3adea3d2255713d78
@@ -649,9 +649,38 @@ void User::receivedMessage(const Message
 	
 	if (body.find("/transport ") == 0) {
 		PurpleCmdStatus status;
-		char *error;
+		char *error = NULL;
 		body.erase(0,11);
 		status = purple_cmd_do_command(conv, body.c_str(), body.c_str(), &error);
+
+		switch (status) {
+			case PURPLE_CMD_STATUS_OK:
+				break;
+			case PURPLE_CMD_STATUS_NOT_FOUND:
+				{
+					purple_conversation_write(conv, "transport", tr(getLang(),_("Transport: Unknown command.")), PURPLE_MESSAGE_RECV, time(NULL));
+					break;
+				}
+			case PURPLE_CMD_STATUS_WRONG_ARGS:
+				purple_conversation_write(conv, "transport", tr(getLang(),_("Syntax Error:  You typed the wrong number of arguments to that command.")), PURPLE_MESSAGE_RECV, time(NULL));
+				break;
+			case PURPLE_CMD_STATUS_FAILED:
+				purple_conversation_write(conv, "transport", tr(getLang(),error ? error : _("Your command failed for an unknown reason.")), PURPLE_MESSAGE_RECV, time(NULL));
+				break;
+			case PURPLE_CMD_STATUS_WRONG_TYPE:
+				if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
+					purple_conversation_write(conv, "transport", tr(getLang(),_("That command only works in Groupchats, not IMs.")), PURPLE_MESSAGE_RECV, time(NULL));
+				else
+					purple_conversation_write(conv, "transport", tr(getLang(),_("That command only works in IMs, not Groupchats.")), PURPLE_MESSAGE_RECV, time(NULL));
+				break;
+			case PURPLE_CMD_STATUS_WRONG_PRPL:
+				purple_conversation_write(conv, "transport", tr(getLang(),_("That command doesn't work on this protocol.")), PURPLE_MESSAGE_RECV, time(NULL));
+				break;
+		}
+
+		if (error)
+			g_free(error);
+		return;
 	}
 	
 	// send this message
@@ -959,7 +988,7 @@ void User::receivedPresence(const Presen
 					purple_account_disconnect(m_account);
 				}
 			}
-		} else if(stanza.subtype() == Presence::Available) {
+		} else {
 			m_resource=stanza.from().resource();
 			std::map<std::string,int> ::iterator iter = m_resources.begin();
 			iter = m_resources.find(m_resource);


More information about the Commits mailing list