soc.2009.transport: 833b1281: Move jabber:x:data functions to dataform...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Wed Jun 24 07:36:05 EDT 2009


-----------------------------------------------------------------
Revision: 833b128159ed7640f5bc52267549581e704448cc
Ancestor: 39a68c8a24f4e5ba656613ef6f3128de3fa50cd7
Author: hanzz at soc.pidgin.im
Date: 2009-06-24T11:29:32
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/833b128159ed7640f5bc52267549581e704448cc

Added files:
        dataforms.cpp dataforms.h
Modified files:
        CMakeLists.txt adhocrepeater.cpp main.cpp searchrepeater.cpp

ChangeLog: 

Move jabber:x:data functions to dataforms.cpp.

-------------- next part --------------
============================================================
--- dataforms.cpp	63d2869271bc9a26b3e417c9574c428131ddfa62
+++ dataforms.cpp	63d2869271bc9a26b3e417c9574c428131ddfa62
@@ -0,0 +1,74 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#include "dataforms.h"
+#include <iostream>
+#include <sstream>
+#include <string>
+
+
+Tag * xdataFromRequestInput(const std::string &title, const std::string &primaryString, const std::string &value, gboolean multiline) {
+	Tag *xdata = new Tag("x");
+	xdata->addAttribute("xmlns","jabber:x:data");
+	xdata->addAttribute("type","form");
+	xdata->addChild(new Tag("title",title));
+	xdata->addChild(new Tag("instructions",primaryString));
+
+	Tag *field = new Tag("field");
+	if (multiline)
+		field->addAttribute("type","text-multi");
+	else
+		field->addAttribute("type","text-single");
+	field->addAttribute("label","Field:");
+	field->addAttribute("var","result");
+	field->addChild(new Tag("value",value));
+	xdata->addChild(field);
+
+	return xdata;
+}
+
+Tag * xdataFromRequestAction(const std::string &title, const std::string &primaryString, size_t action_count, va_list acts) {
+	Tag *xdata = new Tag("x");
+	xdata->addAttribute("xmlns","jabber:x:data");
+	xdata->addAttribute("type","form");
+	xdata->addChild(new Tag("title",title));
+	xdata->addChild(new Tag("instructions",primaryString));
+
+	Tag *field = new Tag("field");
+	field->addAttribute("type","list-single");
+	field->addAttribute("label","Actions");
+
+	for (unsigned int i = 0; i < action_count; i++) {
+		Tag *option;
+		std::ostringstream os;
+		os << i;
+		std::string name(va_arg(acts, char *));
+		if (i == 0)
+			field->addChild(new Tag("value",os.str()));
+		option = new Tag("option");
+		option->addAttribute("label",name);
+		option->addChild( new Tag("value",os.str()) );
+		field->addChild(option);
+	}
+	field->addAttribute("var","result");
+	xdata->addChild(field);
+	
+	return xdata;
+}
============================================================
--- dataforms.h	015fac2ba22be73f037b174d030701b307d6b959
+++ dataforms.h	015fac2ba22be73f037b174d030701b307d6b959
@@ -0,0 +1,32 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#ifndef _HI_DATAFORMS_H
+#define _HI_DATAFORMS_H
+
+#include <glib.h>
+#include "gloox/tag.h"
+
+using namespace gloox;
+
+Tag * xdataFromRequestInput(const std::string &title, const std::string &primaryString, const std::string &value, gboolean multiline);
+Tag * xdataFromRequestAction(const std::string &title, const std::string &primaryString, size_t action_count, va_list acts);
+
+#endif
============================================================
--- CMakeLists.txt	d88485fb15b2dd1d59bc694ffa5e0bb02ac72aa0
+++ CMakeLists.txt	ed71cfac2085a29b4f45be9009f2aac690cabc0a
@@ -93,6 +93,7 @@
 	adhocsettings.cpp
 	searchhandler.cpp
 	searchrepeater.cpp
+	dataforms.cpp
 	protocols/icq.cpp
 	protocols/facebook.cpp
 	protocols/gg.cpp
@@ -129,6 +130,7 @@
 	searchhandler.h
 	searchrepeater.h
 	abstractpurplerequest.h
+	dataforms.h
 	protocols/abstractprotocol.h
 	protocols/icq.h
 	protocols/facebook.h
============================================================
--- adhocrepeater.cpp	5e26e9b73e6d7498466932e4ee840641deb450f4
+++ adhocrepeater.cpp	bfb256cc1d99284582391cc849f8bd0f0f6c2388
@@ -21,6 +21,7 @@
 #include "adhocrepeater.h"
 #include "gloox/stanza.h"
 #include "log.h"
+#include "dataforms.h"
  
 static gboolean removeRepeater(gpointer data){
 	AdhocRepeater *repeater = (AdhocRepeater*) data;
@@ -56,23 +57,7 @@ AdhocRepeater::AdhocRepeater(GlooxMessag
 	actions->addChild(new Tag("complete"));
 	c->addChild(actions);
 
-	Tag *xdata = new Tag("x");
-	xdata->addAttribute("xmlns","jabber:x:data");
-	xdata->addAttribute("type","form");
-	xdata->addChild(new Tag("title",title));
-	xdata->addChild(new Tag("instructions",primaryString));
-
-	Tag *field = new Tag("field");
-	if (multiline)
-		field->addAttribute("type","text-multi");
-	else
-		field->addAttribute("type","text-single");
-	field->addAttribute("label","Field:");
-	field->addAttribute("var","result");
-	field->addChild(new Tag("value",value));
-	xdata->addChild(field);
-
-	c->addChild(xdata);
+	c->addChild( xdataFromRequestInput(title, primaryString, value, multiline) );
 	response->addChild(c);
 	main->j->send(response);
 
@@ -113,32 +98,10 @@ AdhocRepeater::AdhocRepeater(GlooxMessag
 	actions->addChild(new Tag("complete"));
 	c->addChild(actions);
 
-	Tag *xdata = new Tag("x");
-	xdata->addAttribute("xmlns","jabber:x:data");
-	xdata->addAttribute("type","form");
-	xdata->addChild(new Tag("title",title));
-	xdata->addChild(new Tag("instructions",primaryString));
-
-	Tag *field = new Tag("field");
-	field->addAttribute("type","list-single");
-	field->addAttribute("label","Actions");
-	for (unsigned int i = 0; i < action_count; i++) {
-		Tag *option;
-		std::ostringstream os;
-		os << i;
-		std::string name(va_arg(acts, char *));
-		if (i == 0)
-			field->addChild(new Tag("value",os.str()));
+	for (unsigned int i = 0; i < action_count; i++)
 		m_actions[i] = va_arg(acts, GCallback);
-		option = new Tag("option");
-		option->addAttribute("label",name);
-		option->addChild( new Tag("value",os.str()) );
-		field->addChild(option);
-	}
-	field->addAttribute("var","result");
-	xdata->addChild(field);
 
-	c->addChild(xdata);
+	c->addChild( xdataFromRequestAction(title, primaryString, action_count, acts) );
 	response->addChild(c);
 	main->j->send(response);
 
============================================================
--- main.cpp	bea78c0670edeb7b44112511498223bcbcfdc9d9
+++ main.cpp	1259a601d235276da055d88c795b4f3f88f4a7c1
@@ -822,6 +822,7 @@ void GlooxMessageHandler::loadConfigFile
 	{
 // 		g_error (error->message);
 		Log().Get("gloox") << "Can't load highflyer.cfg!!!";
+		g_key_file_free(keyfile);
 		return;
 	}
 	
============================================================
--- searchrepeater.cpp	b6dcbe7ab7046fe2116551bc126b0f617d2ea6c1
+++ searchrepeater.cpp	7bd6afc3e06f9aba5ba513136aa3fbebdfbf2e21
@@ -22,6 +22,7 @@
 #include "gloox/stanza.h"
 #include "log.h"
 #include "protocols/abstractprotocol.h"
+#include "dataforms.h"
  
 static gboolean removeRepeater(gpointer data){
 	SearchRepeater *repeater = (SearchRepeater*) data;
@@ -73,23 +74,8 @@ SearchRepeater::SearchRepeater(GlooxMess
 	query->addAttribute("xmlns", "jabber:iq:search");
 	query->addChild( new Tag("instructions", "<instructions>You need an x:data capable client to search</instructions>") );
 	
-	Tag *xdata = new Tag("x");
-	xdata->addAttribute("xmlns","jabber:x:data");
-	xdata->addAttribute("type","form");
-	xdata->addChild(new Tag("title",title));
-	xdata->addChild(new Tag("instructions",primaryString));
+	query->addChild( xdataFromRequestInput(title, primaryString, value, multiline) );
 
-	Tag *field = new Tag("field");
-	if (multiline)
-		field->addAttribute("type","text-multi");
-	else
-		field->addAttribute("type","text-single");
-	field->addAttribute("label","Search field");
-	field->addAttribute("var","result");
-	field->addChild(new Tag("value",value));
-	
-	xdata->addChild(field);
-	query->addChild(xdata);
 	response->addChild(query);
 	main->j->send(response);
 }


More information about the Commits mailing list