/cpw/tomkiewicz/gg11: 16ee13f507a0: Gadu-Gadu: room list

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Sep 11 09:17:53 EDT 2012


Changeset: 16ee13f507a0ebfed4873ccc4ab76dbf9b2f51a3
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-09-11 15:17 +0200
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/16ee13f507a0

Description:

Gadu-Gadu: room list

diffstat:

 libpurple/protocols/gg/Makefile.am |   3 +-
 libpurple/protocols/gg/chat.c      |  80 ++++++++++++++++++++++++++++++++++++-
 libpurple/protocols/gg/chat.h      |   4 +
 libpurple/protocols/gg/gg.c        |   6 +-
 4 files changed, 84 insertions(+), 9 deletions(-)

diffs (199 lines):

diff --git a/libpurple/protocols/gg/Makefile.am b/libpurple/protocols/gg/Makefile.am
--- a/libpurple/protocols/gg/Makefile.am
+++ b/libpurple/protocols/gg/Makefile.am
@@ -1,4 +1,5 @@
 #V=0
+#CFLAGS = -g -O0
 GADU_EXTRA = -Wall -Wextra -Werror -fno-inline
 
 pkgdir = $(libdir)/purple-$(PURPLE_MAJOR_VERSION)
@@ -124,5 +125,3 @@ AM_CPPFLAGS = \
 	$(GLIB_CFLAGS) \
 	$(DEBUG_CFLAGS) \
 	$(GADU_EXTRA)
-
-CFLAGS = -g -O0
diff --git a/libpurple/protocols/gg/chat.c b/libpurple/protocols/gg/chat.c
--- a/libpurple/protocols/gg/chat.c
+++ b/libpurple/protocols/gg/chat.c
@@ -32,7 +32,7 @@ static void ggp_chat_joined(ggp_chat_loc
 	gboolean new_arrival);
 static void ggp_chat_left(ggp_chat_local_info *chat, uin_t uin);
 static const gchar * ggp_chat_get_name_from_id(uint64_t id);
-/*static uint64_t ggp_chat_get_id_from_name(const gchar * name);*/
+static uint64_t ggp_chat_get_id_from_name(const gchar * name);
 
 static inline ggp_chat_session_data *
 ggp_chat_get_sdata(PurpleConnection *gc)
@@ -87,7 +87,7 @@ static ggp_chat_local_info * ggp_chat_ne
 		return chat;
 	}
 
-	chat->conv = serv_got_joined_chat(gc, local_id,
+	chat->conv = serv_got_joined_chat(gc, chat->local_id,
 		ggp_chat_get_name_from_id(id));
 	if (chat->previously_joined)
 	{
@@ -217,6 +217,18 @@ GList * ggp_chat_info(PurpleConnection *
 	return m;
 }
 
+GHashTable * ggp_chat_info_defaults(PurpleConnection *gc, const char *chat_name)
+{
+	GHashTable *defaults;
+
+	defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
+
+	if (chat_name != NULL && ggp_chat_get_id_from_name(chat_name) != 0)
+		g_hash_table_insert(defaults, "id", g_strdup(chat_name));
+
+	return defaults;
+}
+
 char * ggp_chat_get_name(GHashTable *components)
 {
 	return g_strdup((gchar*)g_hash_table_lookup(components, "id"));
@@ -229,7 +241,6 @@ static const gchar * ggp_chat_get_name_f
 	return buff;
 }
 
-# if 0
 static uint64_t ggp_chat_get_id_from_name(const gchar * name)
 {
 	uint64_t id;
@@ -245,7 +256,6 @@ static uint64_t ggp_chat_get_id_from_nam
 
 	return id;
 }
-#endif
 
 void ggp_chat_join(PurpleConnection *gc, GHashTable *components)
 {
@@ -255,12 +265,14 @@ void ggp_chat_join(PurpleConnection *gc,
 	id = g_hash_table_lookup(components, "id");
 	if (id == NULL || id[0] != '\0')
 	{
+		purple_debug_error("gg", "ggp_chat_join; cannot join\n");
 		purple_serv_got_join_chat_failed(gc, components);
 		return;
 	}
 
 	if (gg_chat_create(info->session) < 0)
 	{
+		purple_debug_error("gg", "ggp_chat_join; cannot create\n");
 		purple_serv_got_join_chat_failed(gc, components);
 		return;
 	}
@@ -363,3 +375,63 @@ void ggp_chat_got_message(PurpleConnecti
 			PURPLE_MESSAGE_RECV, message, time);
 	}
 }
+
+static gboolean ggp_chat_roomlist_get_list_finish(gpointer roomlist)
+{
+	purple_roomlist_set_in_progress((PurpleRoomlist*)roomlist, FALSE);
+	return FALSE;
+}
+
+PurpleRoomlist * ggp_chat_roomlist_get_list(PurpleConnection *gc)
+{
+	ggp_chat_session_data *sdata = ggp_chat_get_sdata(gc);
+	PurpleRoomlist *roomlist;
+	GList *fields = NULL;
+	int i;
+
+	purple_debug_info("gg", "ggp_chat_roomlist_get_list\n");
+
+	roomlist = purple_roomlist_new(purple_connection_get_account(gc));
+
+	fields = g_list_append(fields, purple_roomlist_field_new(
+		PURPLE_ROOMLIST_FIELD_STRING, _("Conference identifier"), "id",
+		TRUE));
+
+	fields = g_list_append(fields, purple_roomlist_field_new(
+		PURPLE_ROOMLIST_FIELD_STRING, _("Start Date"), "date",
+		FALSE));
+
+	fields = g_list_append(fields, purple_roomlist_field_new(
+		PURPLE_ROOMLIST_FIELD_INT, _("User Count"), "users",
+		FALSE));
+
+	fields = g_list_append(fields, purple_roomlist_field_new(
+		PURPLE_ROOMLIST_FIELD_STRING, _("Status"), "status",
+		FALSE));
+
+	purple_roomlist_set_fields(roomlist, fields);
+
+	for (i = sdata->chats_count - 1; i >= 0 ; i--)
+	{
+		PurpleRoomlistRoom *room;
+		ggp_chat_local_info *chat = &sdata->chats[i];
+		const gchar *name;
+		time_t date;
+		
+		date = (uint32_t)(chat->id >> 32);
+		
+		name = ggp_chat_get_name_from_id(chat->id);
+		room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM,
+			name, NULL);
+		purple_roomlist_room_add_field(roomlist, room, name);
+		purple_roomlist_room_add_field(roomlist, room, purple_date_format_full(localtime(&date)));
+		purple_roomlist_room_add_field(roomlist, room, GINT_TO_POINTER(123));
+		purple_roomlist_room_add_field(roomlist, room, _("Unknown"));
+		purple_roomlist_room_add(roomlist, room);
+	}
+
+	//TODO
+	//purple_roomlist_set_in_progress(roomlist, FALSE);
+	purple_timeout_add(1, ggp_chat_roomlist_get_list_finish, roomlist);
+	return roomlist;
+}
diff --git a/libpurple/protocols/gg/chat.h b/libpurple/protocols/gg/chat.h
--- a/libpurple/protocols/gg/chat.h
+++ b/libpurple/protocols/gg/chat.h
@@ -12,6 +12,8 @@ void ggp_chat_cleanup(PurpleConnection *
 void ggp_chat_got_event(PurpleConnection *gc, const struct gg_event *ev);
 
 GList * ggp_chat_info(PurpleConnection *gc);
+GHashTable * ggp_chat_info_defaults(PurpleConnection *gc,
+	const char *chat_name);
 char * ggp_chat_get_name(GHashTable *components);
 void ggp_chat_join(PurpleConnection *gc, GHashTable *components);
 void ggp_chat_leave(PurpleConnection *gc, int local_id);
@@ -23,4 +25,6 @@ int ggp_chat_send(PurpleConnection *gc, 
 void ggp_chat_got_message(PurpleConnection *gc, uint64_t chat_id,
 	const char *message, time_t time, uin_t who);
 
+PurpleRoomlist * ggp_chat_roomlist_get_list(PurpleConnection *gc);
+
 #endif /* _GGP_CHAT_H */
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -1191,7 +1191,7 @@ static PurplePluginProtocolInfo prpl_inf
 	ggp_status_types,		/* status_types */
 	NULL,				/* blist_node_menu */
 	ggp_chat_info,			/* chat_info */
-	NULL,				/* chat_info_defaults */
+	ggp_chat_info_defaults,		/* chat_info_defaults */
 	ggp_login,			/* login */
 	ggp_close,			/* close */
 	ggp_send_im,			/* send_im */
@@ -1211,7 +1211,7 @@ static PurplePluginProtocolInfo prpl_inf
 	ggp_rem_deny,			/* rem_deny */
 	NULL,				/* set_permit_deny */
 	ggp_chat_join,			/* join_chat */
-	NULL,				/* reject_chat */
+	NULL, /* TODO */		/* reject_chat */
 	ggp_chat_get_name,		/* get_chat_name */
 	ggp_chat_invite,		/* chat_invite */
 	ggp_chat_leave,			/* chat_leave */
@@ -1231,7 +1231,7 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL,				/* get_cb_real_name */
 	NULL,				/* set_chat_topic */
 	NULL,				/* find_blist_chat */
-	NULL,				/* roomlist_get_list */
+	ggp_chat_roomlist_get_list,	/* roomlist_get_list */
 	NULL,				/* roomlist_cancel */
 	NULL,				/* roomlist_expand_category */
 	NULL,				/* can_receive_file */



More information about the Commits mailing list