soc.2009.transport: 459cb52d: Added Cmds for settings and moved them t...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Fri Jul 3 02:55:34 EDT 2009


-----------------------------------------------------------------
Revision: 459cb52d23b83d20086c35ecb780216a6c2e4d76
Ancestor: 403309f64ae2a9a5e5271e96f4c952340156c8f9
Author: hanzz at soc.pidgin.im
Date: 2009-07-03T06:52:06
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/459cb52d23b83d20086c35ecb780216a6c2e4d76

Added files:
        commands.cpp commands.h
Modified files:
        CMakeLists.txt adhocsettings.cpp main.cpp user.h

ChangeLog: 

Added Cmds for settings and moved them to separate file.

-------------- next part --------------
============================================================
--- commands.cpp	0c87a8dc0da024e7c64ce50acae4c5e226b9121a
+++ commands.cpp	0c87a8dc0da024e7c64ce50acae4c5e226b9121a
@@ -0,0 +1,132 @@
+/**
+ * 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 "commands.h"
+#include <iostream>
+#include <sstream>
+#include <string>
+#include "cmds.h"
+#include "user.h"
+#include "usermanager.h"
+
+static PurpleCmdRet settings_command_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, void *data) {
+	GString *s = NULL;
+	User *user = GlooxMessageHandler::instance()->userManager()->getUserByAccount(purple_conversation_get_account(conv));
+	if (!user)
+		return PURPLE_CMD_RET_OK;
+	if (args[0] != NULL) {
+		std::string cmd(args[0]);
+		if (cmd == "list") {
+			s = g_string_new("Transport: ");
+			GHashTable *settings = user->settings();
+			GHashTableIter iter;
+			gpointer key, value;
+			g_hash_table_iter_init (&iter, settings);
+			while (g_hash_table_iter_next (&iter, &key, &value)) {
+				PurpleValue *value = (PurpleValue *) value;
+				if (purple_value_get_boolean(value))
+					g_string_append_printf(s, "%s = True \n", (char *) key);
+				else
+					g_string_append_printf(s, "%s = False \n", (char *) key);
+			}
+		}
+		else if (cmd == "set") {
+			if (args[1] != NULL) {
+				s = g_string_new("Transport: ");
+				PurpleValue *value = user->getSetting(args[1]);
+				if (value) {
+					if (purple_value_get_type(value) == PURPLE_TYPE_BOOLEAN) {
+						value = purple_value_new(PURPLE_TYPE_BOOLEAN);
+						purple_value_set_boolean(value, atoi(args[2]));
+						user->updateSetting(args[1], value);
+						if (purple_value_get_boolean(value))
+							g_string_append_printf(s, "%s is now True \n", args[1]);
+						else
+							g_string_append_printf(s, "%s is now False \n", args[1]);
+					}
+				}
+				else {
+					g_string_append_printf(s, " This setting key doesn't exist. Try to use \"/transport settings list\" to get settings keys.\n");
+				}
+			}
+		}
+	}
+	if (s) {
+		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;
+}
+
+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;
+}
+
+void purple_commands_init() {
+	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);
+	purple_cmd_register("settings", "www", PURPLE_CMD_P_DEFAULT, (PurpleCmdFlag) (PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM), NULL, settings_command_cb, _("settings set &lt;command&gt; settings list:  Configure transport."), NULL);
+	purple_cmd_register("settings", "w", PURPLE_CMD_P_DEFAULT, (PurpleCmdFlag) (PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM), NULL, settings_command_cb, _("settings set &lt;command&gt; settings list:  Configure transport."), NULL);
+}
============================================================
--- commands.h	61175a37931c95a3aedcc770c6a8bc6a9dd21912
+++ commands.h	61175a37931c95a3aedcc770c6a8bc6a9dd21912
@@ -0,0 +1,29 @@
+/**
+ * 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_COMMANDS_H
+#define _HI_COMMANDS_H
+
+#include <glib.h>
+class GlooxMessageHandler;
+
+void purple_commands_init();
+
+#endif
============================================================
--- CMakeLists.txt	d5396752ac1c03d8acb4a2a5e59a7c12c2f5e9d8
+++ CMakeLists.txt	2894bb61d0b14dbee5a2f84165e2d40a4b4c9097
@@ -95,6 +95,7 @@
 	searchrepeater.cpp
 	dataforms.cpp
 	parser.cpp
+	commands.cpp
 	protocols/icq.cpp
 	protocols/facebook.cpp
 	protocols/gg.cpp
@@ -138,6 +139,7 @@
 	abstractpurplerequest.h
 	dataforms.h
 	parser.h
+	commands.h
 	protocols/abstractprotocol.h
 	protocols/icq.h
 	protocols/facebook.h
============================================================
--- adhocsettings.cpp	0bc07fb98f2bacc89a4ebd68b50c6fbc6be56638
+++ adhocsettings.cpp	a61ba0885ccdb1be9b8e7cd95c245d9bb79c1bb1
@@ -128,7 +128,7 @@ bool AdhocSettings::handleIq(const IQ &s
 	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){
+		for(std::list<Tag*>::const_iterator it = x->children().begin(); it != x->children().end(); ++it) {
 			std::string key = (*it)->findAttribute("var");
 			if (key.empty()) continue;
 			
============================================================
--- main.cpp	8820215b8cab1366e06ed4633c2fdf022af95809
+++ main.cpp	f46041ac93f13d8539a87a80f8a16df860bdcfd9
@@ -29,6 +29,7 @@
 #include "searchhandler.h"
 #include "searchrepeater.h"
 #include "parser.h"
+#include "commands.h"
 #include "protocols/abstractprotocol.h"
 #include "protocols/icq.h"
 #include "protocols/facebook.h"
@@ -100,51 +101,6 @@ 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)
  */
@@ -1441,9 +1397,9 @@ bool GlooxMessageHandler::initPurple(){
 		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_conversations_get_handle(), "chat-topic-changed", &conversation_handle, PURPLE_CALLBACK(conv_chat_topic_changed), NULL);
+	
+		purple_commands_init();
 
-		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.h	457b3b35fc6245ae24cb5130918e62b61fd4c8f1
+++ user.h	1f241651ccca6844d64b4cd5c47ad2ec79f49a8a
@@ -158,6 +158,7 @@ class User {
 		std::map<std::string,RosterRow> & roster() { return m_roster; }
 		const char *getLang() { return m_lang; }
 		void setLang(const char *lang) { m_lang = lang; }
+		GHashTable *settings() { return m_settings; }
 		
 		GlooxMessageHandler *p;
 	


More information about the Commits mailing list