2 * @file purple-groupchat.c
6 * Copyright (C) 2010-2013 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "sipe-common.h"
31 #include "conversation.h"
35 #if PURPLE_VERSION_CHECK(3,0,0)
36 #include "conversations.h"
38 #define purple_roomlist_get_account(r) r->account
41 #include "sipe-backend.h"
42 #include "sipe-core.h"
45 #include "purple-private.h"
47 GList
*sipe_purple_chat_info(SIPE_UNUSED_PARAMETER PurpleConnection
*gc
)
50 struct proto_chat_entry
*pce
;
52 pce
= g_new0(struct proto_chat_entry
, 1);
53 pce
->label
= _("_URI:");
54 pce
->identifier
= "uri";
56 m
= g_list_append(m
, pce
);
62 * This callback is called for two reasons:
64 * a) generate the defaults for the "Add chat..." dialog initiated from the
65 * roomlist (applies only to group chat)
66 * b) generate the components for the creation of a PurpleChat object
69 GHashTable
*sipe_purple_chat_info_defaults(PurpleConnection
*gc
,
70 const char *chat_name
)
72 GHashTable
*defaults
= g_hash_table_new(g_str_hash
, g_str_equal
);
74 if (chat_name
!= NULL
) {
75 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
76 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
77 GHashTable
*uri_map
= purple_private
->roomlist_map
;
78 const gchar
*uri
= uri_map
!= NULL
?
79 g_hash_table_lookup(uri_map
, chat_name
) :
81 #if PURPLE_VERSION_CHECK(3,0,0)
82 PurpleChatConversation
*conv
= purple_conversations_find_chat_with_account(
84 PurpleConversation
*conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT
,
87 purple_private
->account
);
88 /* Group Chat rooms have a valid URI */
90 g_hash_table_insert(defaults
, "uri", (gpointer
)uri
);
94 * Remember the PurpleConversation
96 * libpurple API is so brain-dead that we don't receive this
97 * information when it is known and we need it. Make our life
98 * easier by remembering it here for later lookup....
101 g_hash_table_insert(defaults
,
102 SIPE_PURPLE_COMPONENT_KEY_CONVERSATION
,
110 void sipe_purple_chat_join(PurpleConnection
*gc
, GHashTable
*data
)
112 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
113 const gchar
*uri
= g_hash_table_lookup(data
, "uri");
116 SIPE_DEBUG_INFO("sipe_purple_chat_join: uri '%s'", uri
);
117 sipe_core_groupchat_join(sipe_public
, uri
);
121 static void clear_roomlist(struct sipe_backend_private
*purple_private
)
123 #if PURPLE_VERSION_CHECK(3,0,0)
124 g_object_unref(purple_private
->roomlist
);
126 purple_roomlist_unref(purple_private
->roomlist
);
128 purple_private
->roomlist
= NULL
;
131 PurpleRoomlist
*sipe_purple_roomlist_get_list(PurpleConnection
*gc
)
133 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
134 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
135 PurpleAccount
*account
= purple_private
->account
;
136 PurpleRoomlist
*roomlist
;
137 GList
*fields
= NULL
;
138 PurpleRoomlistField
*f
;
140 SIPE_DEBUG_INFO_NOFORMAT("sipe_purple_roomlist_get_list");
142 if (purple_private
->roomlist
)
143 clear_roomlist(purple_private
);
144 if (purple_private
->roomlist_map
)
145 g_hash_table_destroy(purple_private
->roomlist_map
);
147 purple_private
->roomlist
= roomlist
= purple_roomlist_new(account
);
148 purple_private
->roomlist_map
= g_hash_table_new_full(g_str_hash
,
152 /* The order needs to be kept in-sync with sipe_backend_groupchat_room_add() */
153 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING
,
155 fields
= g_list_append(fields
, f
);
156 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_INT
,
157 _("Users"), "users", FALSE
);
158 fields
= g_list_append(fields
, f
);
159 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_BOOL
,
160 _("Invite"), "invite", FALSE
);
161 fields
= g_list_append(fields
, f
);
162 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_BOOL
,
163 _("Private"), "private", FALSE
);
164 fields
= g_list_append(fields
, f
);
165 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_BOOL
,
166 _("Log"), "logged", FALSE
);
167 fields
= g_list_append(fields
, f
);
168 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING
,
169 _("Description"), "description", FALSE
);
170 fields
= g_list_append(fields
, f
);
172 purple_roomlist_set_fields(roomlist
, fields
);
173 purple_roomlist_set_in_progress(roomlist
, TRUE
);
175 if (!sipe_core_groupchat_query_rooms(sipe_public
)) {
176 sipe_purple_roomlist_cancel(roomlist
);
183 void sipe_purple_roomlist_cancel(PurpleRoomlist
*roomlist
)
185 PurpleAccount
*account
= purple_roomlist_get_account(roomlist
);
186 struct sipe_core_public
*sipe_public
= PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
;
187 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
189 SIPE_DEBUG_INFO_NOFORMAT("sipe_purple_roomlist_cancel");
191 purple_roomlist_set_in_progress(roomlist
, FALSE
);
193 if (purple_private
->roomlist
== roomlist
)
194 clear_roomlist(purple_private
);
197 void sipe_backend_groupchat_room_add(struct sipe_core_public
*sipe_public
,
200 const gchar
*description
,
204 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
205 PurpleRoomlist
*roomlist
= purple_private
->roomlist
;
207 PurpleRoomlistRoom
*room
= purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM
,
210 /* The order needs to be kept in-sync with sipe_roomlist_get_list() */
211 purple_roomlist_room_add_field(roomlist
, room
,
213 purple_roomlist_room_add_field(roomlist
, room
,
214 GUINT_TO_POINTER(users
));
215 purple_roomlist_room_add_field(roomlist
, room
,
216 GUINT_TO_POINTER(flags
& SIPE_GROUPCHAT_ROOM_INVITE
));
217 purple_roomlist_room_add_field(roomlist
, room
,
218 GUINT_TO_POINTER(flags
& SIPE_GROUPCHAT_ROOM_PRIVATE
));
219 purple_roomlist_room_add_field(roomlist
, room
,
220 GUINT_TO_POINTER(flags
& SIPE_GROUPCHAT_ROOM_LOGGED
));
221 purple_roomlist_room_add_field(roomlist
, room
,
224 /* libpurple API only gives us the channel name */
225 g_hash_table_insert(purple_private
->roomlist_map
,
226 g_strdup(name
), g_strdup(uri
));
228 purple_roomlist_room_add(roomlist
, room
);
232 void sipe_backend_groupchat_room_terminate(struct sipe_core_public
*sipe_public
)
234 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
235 PurpleRoomlist
*roomlist
= purple_private
->roomlist
;
237 purple_roomlist_set_in_progress(roomlist
, FALSE
);
238 clear_roomlist(purple_private
);