soc.2009.transport: 38a0566d: Added support for PURPLE_REQUEST_FIELDS ...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Sat Jun 27 05:20:21 EDT 2009


-----------------------------------------------------------------
Revision: 38a0566dc2f65d492ba8decb664ee4d68b1369d8
Ancestor: 018f30333ae2dfb4dc75448acedfa7d7c3f7fb97
Author: hanzz at soc.pidgin.im
Date: 2009-06-27T09:18:43
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/38a0566dc2f65d492ba8decb664ee4d68b1369d8

Modified files:
        main.cpp searchrepeater.cpp searchrepeater.h

ChangeLog: 

Added support for PURPLE_REQUEST_FIELDS to SearchRepeater

-------------- next part --------------
============================================================
--- main.cpp	c96d309a2b582a7ce8978ce44c101fce44b4e520
+++ main.cpp	2692cc5d95ca9b9bed6acb24075bcc22c8a5a3a6
@@ -283,12 +283,19 @@ static void *requestFields(const char *t
 static void *requestFields(const char *title, const char *primary, const char *secondary, PurpleRequestFields *fields, const char *ok_text, GCallback ok_cb, const char *cancel_text, GCallback cancel_cb, PurpleAccount *account, const char *who, PurpleConversation *conv, void *user_data) {
 	User *user = GlooxMessageHandler::instance()->userManager()->getUserByAccount(account);
 	if (user && !user->adhocData().id.empty()) {
-		AdhocRepeater *repeater = new AdhocRepeater(GlooxMessageHandler::instance(), user, title ? std::string(title):std::string(), primary ? std::string(primary):std::string(), secondary ? std::string(secondary):std::string(), fields, ok_cb, cancel_cb, user_data);
-		GlooxMessageHandler::instance()->adhoc()->registerSession(user->adhocData().from, repeater);
-		AdhocData data;
-		data.id="";
-		user->setAdhocData(data);
-		return repeater;
+		if (user->adhocData().callerType == CALLER_ADHOC) {
+			AdhocRepeater *repeater = new AdhocRepeater(GlooxMessageHandler::instance(), user, title ? std::string(title):std::string(), primary ? std::string(primary):std::string(), secondary ? std::string(secondary):std::string(), fields, ok_cb, cancel_cb, user_data);
+			GlooxMessageHandler::instance()->adhoc()->registerSession(user->adhocData().from, repeater);
+			AdhocData data;
+			data.id="";
+			user->setAdhocData(data);
+			return repeater;
+		}
+		else if (user->adhocData().callerType == CALLER_SEARCH) {
+			SearchRepeater *repeater = new SearchRepeater(GlooxMessageHandler::instance(), user, title ? std::string(title):std::string(), primary ? std::string(primary):std::string(), secondary ? std::string(secondary):std::string(), fields, ok_cb, cancel_cb, user_data);
+			GlooxMessageHandler::instance()->searchHandler()->registerSession(user->adhocData().from, repeater);
+			return repeater;
+		}
 	}
 
 	return NULL;
============================================================
--- searchrepeater.cpp	7bd6afc3e06f9aba5ba513136aa3fbebdfbf2e21
+++ searchrepeater.cpp	bfa8aec544c5eb5e220edfc4616f8a4380fa944c
@@ -80,6 +80,38 @@ SearchRepeater::SearchRepeater(GlooxMess
 	main->j->send(response);
 }
 
+SearchRepeater::SearchRepeater(GlooxMessageHandler *m, User *user, const std::string &title, const std::string &primaryString, const std::string &secondaryString, PurpleRequestFields *fields, GCallback ok_cb, GCallback cancel_cb, void * user_data) {
+	setType(PURPLE_REQUEST_FIELDS);
+	main = m;
+	m_user = user;
+	m_ok_cb = ok_cb;
+	m_cancel_cb = cancel_cb;
+	m_fields = fields;
+	m_requestData = user_data;
+	AdhocData data = user->adhocData();
+	m_from = data.from;
+	setRequestType(CALLER_SEARCH);
+	
+	IQ _response(IQ::Result, data.from, data.id);
+	Tag *response = _response.tag();
+	response->addAttribute("from",main->jid());
+
+	Tag *c = new Tag("command");
+	c->addAttribute("xmlns","http://jabber.org/protocol/commands");
+	c->addAttribute("sessionid",main->j->getID());
+	c->addAttribute("node",data.node);
+	c->addAttribute("status","executing");
+
+	Tag *actions = new Tag("actions");
+	actions->addAttribute("execute","complete");
+	actions->addChild(new Tag("complete"));
+	c->addChild(actions);
+	
+	c->addChild( xdataFromRequestFields(title, primaryString, fields) );
+	response->addChild(c);
+	main->j->send(response);
+}
+
 SearchRepeater::~SearchRepeater() {
 	if (m_lastTag)
 		delete m_lastTag;
@@ -167,18 +199,21 @@ bool SearchRepeater::handleIq(const IQ &
 
 	Tag *x = tag->findChildWithAttrib("xmlns","jabber:x:data");
 	if (x) {
-		std::string result("");
-		for(std::list<Tag*>::const_iterator it = x->children().begin(); it != x->children().end(); ++it){
-			if ((*it)->hasAttribute("var","result")){
-				result = (*it)->findChild("value")->cdata();
-				break;
-			}
+		if (m_type == PURPLE_REQUEST_FIELDS) {
+			setRequestFields(m_fields, x);
+			((PurpleRequestFieldsCb) m_ok_cb) (m_requestData, m_fields);
 		}
+		else if (m_type == PURPLE_REQUEST_INPUT) {
+			std::string result("");
+			for(std::list<Tag*>::const_iterator it = x->children().begin(); it != x->children().end(); ++it){
+				if ((*it)->hasAttribute("var","result")){
+					result = (*it)->findChild("value")->cdata();
+					break;
+				}
+			}
 
-		if (m_type == PURPLE_REQUEST_INPUT) {
 			((PurpleRequestInputCb) m_ok_cb)(m_requestData, result.c_str());
-		}
-				
+		}	
 	}
 
 	m_lastTag = stanzaTag;
============================================================
--- searchrepeater.h	47dc0a40ec702402816130b6a389ab806b81906a
+++ searchrepeater.h	a510a45b707f3dff7bae31da6e5a0ef8b7a24326
@@ -34,7 +34,10 @@ class SearchRepeater : public AbstractPu
 class SearchRepeater : public AbstractPurpleRequest
 {
 	public:
+		// Request input
 		SearchRepeater(GlooxMessageHandler *m, User *user, const std::string &title, const std::string &primaryString, const std::string &secondaryString, const std::string &value, gboolean multiline, gboolean masked, GCallback ok_cb, GCallback cancel_cb, void * user_data);
+		// Request fields
+		SearchRepeater(GlooxMessageHandler *m, User *user, const std::string &title, const std::string &primaryString, const std::string &secondaryString, PurpleRequestFields *fields, GCallback ok_cb, GCallback cancel_cb, void * user_data);
 		~SearchRepeater();
 		bool handleIq(const IQ &iq);
 		void sendSearchResults(PurpleNotifySearchResults *results);
@@ -52,6 +55,7 @@ class SearchRepeater : public AbstractPu
 		PurpleRequestType m_type;
 		std::string m_from;
 		std::map<int, GCallback> m_actions;
+		PurpleRequestFields *m_fields;
 };
 
 #endif


More information about the Commits mailing list