2 * @file purple-groupchat.c
6 * Copyright (C) 2010-2015 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
)
51 #if PURPLE_VERSION_CHECK(3,0,0)
52 PurpleProtocolChatEntry
*pce
= g_new0(PurpleProtocolChatEntry
, 1);
54 struct proto_chat_entry
*pce
= g_new0(struct proto_chat_entry
, 1);
56 pce
->label
= _("_URI:");
57 pce
->identifier
= "uri";
59 m
= g_list_append(m
, pce
);
65 * This callback is called for two reasons:
67 * a) generate the defaults for the "Add chat..." dialog initiated from the
68 * roomlist (applies only to group chat)
69 * b) generate the components for the creation of a PurpleChat object
72 GHashTable
*sipe_purple_chat_info_defaults(PurpleConnection
*gc
,
73 const char *chat_name
)
75 GHashTable
*defaults
= g_hash_table_new(g_str_hash
, g_str_equal
);
77 if (chat_name
!= NULL
) {
78 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
79 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
80 GHashTable
*uri_map
= purple_private
->roomlist_map
;
81 const gchar
*uri
= uri_map
!= NULL
?
82 g_hash_table_lookup(uri_map
, chat_name
) :
84 #if PURPLE_VERSION_CHECK(3,0,0)
85 PurpleChatConversation
*conv
= purple_conversations_find_chat_with_account(
87 PurpleConversation
*conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT
,
90 purple_private
->account
);
91 /* Group Chat rooms have a valid URI */
93 g_hash_table_insert(defaults
, "uri", (gpointer
)uri
);
97 * Remember the PurpleConversation
99 * libpurple API is so brain-dead that we don't receive this
100 * information when it is known and we need it. Make our life
101 * easier by remembering it here for later lookup....
104 g_hash_table_insert(defaults
,
105 SIPE_PURPLE_COMPONENT_KEY_CONVERSATION
,
113 void sipe_purple_chat_join(PurpleConnection
*gc
, GHashTable
*data
)
115 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
116 const gchar
*uri
= g_hash_table_lookup(data
, "uri");
119 SIPE_DEBUG_INFO("sipe_purple_chat_join: uri '%s'", uri
);
120 sipe_core_groupchat_join(sipe_public
, uri
);
124 static void clear_roomlist(struct sipe_backend_private
*purple_private
)
126 #if PURPLE_VERSION_CHECK(3,0,0)
127 g_object_unref(purple_private
->roomlist
);
129 purple_roomlist_unref(purple_private
->roomlist
);
131 purple_private
->roomlist
= NULL
;
134 PurpleRoomlist
*sipe_purple_roomlist_get_list(PurpleConnection
*gc
)
136 struct sipe_core_public
*sipe_public
= PURPLE_GC_TO_SIPE_CORE_PUBLIC
;
137 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
138 PurpleAccount
*account
= purple_private
->account
;
139 PurpleRoomlist
*roomlist
;
140 GList
*fields
= NULL
;
141 PurpleRoomlistField
*f
;
143 SIPE_DEBUG_INFO_NOFORMAT("sipe_purple_roomlist_get_list");
145 if (purple_private
->roomlist
)
146 clear_roomlist(purple_private
);
147 if (purple_private
->roomlist_map
)
148 g_hash_table_destroy(purple_private
->roomlist_map
);
150 purple_private
->roomlist
= roomlist
= purple_roomlist_new(account
);
151 purple_private
->roomlist_map
= g_hash_table_new_full(g_str_hash
,
155 /* The order needs to be kept in-sync with sipe_backend_groupchat_room_add() */
156 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING
,
158 fields
= g_list_append(fields
, f
);
159 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_INT
,
160 _("Users"), "users", FALSE
);
161 fields
= g_list_append(fields
, f
);
162 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_BOOL
,
163 _("Invite"), "invite", FALSE
);
164 fields
= g_list_append(fields
, f
);
165 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_BOOL
,
166 _("Private"), "private", FALSE
);
167 fields
= g_list_append(fields
, f
);
168 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_BOOL
,
169 _("Log"), "logged", FALSE
);
170 fields
= g_list_append(fields
, f
);
171 f
= purple_roomlist_field_new(PURPLE_ROOMLIST_FIELD_STRING
,
172 _("Description"), "description", FALSE
);
173 fields
= g_list_append(fields
, f
);
175 purple_roomlist_set_fields(roomlist
, fields
);
176 purple_roomlist_set_in_progress(roomlist
, TRUE
);
178 if (!sipe_core_groupchat_query_rooms(sipe_public
)) {
179 sipe_purple_roomlist_cancel(roomlist
);
186 void sipe_purple_roomlist_cancel(PurpleRoomlist
*roomlist
)
188 PurpleAccount
*account
= purple_roomlist_get_account(roomlist
);
189 struct sipe_core_public
*sipe_public
= PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC
;
190 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
192 SIPE_DEBUG_INFO_NOFORMAT("sipe_purple_roomlist_cancel");
194 purple_roomlist_set_in_progress(roomlist
, FALSE
);
196 if (purple_private
->roomlist
== roomlist
)
197 clear_roomlist(purple_private
);
200 void sipe_backend_groupchat_room_add(struct sipe_core_public
*sipe_public
,
203 const gchar
*description
,
207 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
208 PurpleRoomlist
*roomlist
= purple_private
->roomlist
;
210 PurpleRoomlistRoom
*room
= purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM
,
213 /* The order needs to be kept in-sync with sipe_roomlist_get_list() */
214 purple_roomlist_room_add_field(roomlist
, room
,
216 purple_roomlist_room_add_field(roomlist
, room
,
217 GUINT_TO_POINTER(users
));
218 purple_roomlist_room_add_field(roomlist
, room
,
219 GUINT_TO_POINTER(flags
& SIPE_GROUPCHAT_ROOM_INVITE
));
220 purple_roomlist_room_add_field(roomlist
, room
,
221 GUINT_TO_POINTER(flags
& SIPE_GROUPCHAT_ROOM_PRIVATE
));
222 purple_roomlist_room_add_field(roomlist
, room
,
223 GUINT_TO_POINTER(flags
& SIPE_GROUPCHAT_ROOM_LOGGED
));
224 purple_roomlist_room_add_field(roomlist
, room
,
227 /* libpurple API only gives us the channel name */
228 g_hash_table_insert(purple_private
->roomlist_map
,
229 g_strdup(name
), g_strdup(uri
));
231 purple_roomlist_room_add(roomlist
, room
);
235 void sipe_backend_groupchat_room_terminate(struct sipe_core_public
*sipe_public
)
237 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
238 PurpleRoomlist
*roomlist
= purple_private
->roomlist
;
240 purple_roomlist_set_in_progress(roomlist
, FALSE
);
241 clear_roomlist(purple_private
);