| 1 /** |
|
| 2 * @file confer.c |
|
| 3 * |
|
| 4 * purple |
|
| 5 * |
|
| 6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us> |
|
| 7 * |
|
| 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. |
|
| 12 * |
|
| 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. |
|
| 17 * |
|
| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
| 21 */ |
|
| 22 |
|
| 23 |
|
| 24 #include <libgadu.h> |
|
| 25 #include "gg.h" |
|
| 26 #include "gg-utils.h" |
|
| 27 #include "confer.h" |
|
| 28 |
|
| 29 /* PurpleConversation *ggp_confer_find_by_name(PurpleConnection *gc, const gchar *name) {{{ */ |
|
| 30 PurpleConversation *ggp_confer_find_by_name(PurpleConnection *gc, const gchar *name) |
|
| 31 { |
|
| 32 g_return_val_if_fail(gc != NULL, NULL); |
|
| 33 g_return_val_if_fail(name != NULL, NULL); |
|
| 34 |
|
| 35 return purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, name, |
|
| 36 purple_connection_get_account(gc)); |
|
| 37 } |
|
| 38 /* }}} */ |
|
| 39 |
|
| 40 /* void ggp_confer_participants_add_uin(PurpleConnection *gc, const gchar *chat_name, const uin_t uin) {{{ */ |
|
| 41 void ggp_confer_participants_add_uin(PurpleConnection *gc, const gchar *chat_name, |
|
| 42 const uin_t uin) |
|
| 43 { |
|
| 44 PurpleConversation *conv; |
|
| 45 GGPInfo *info = gc->proto_data; |
|
| 46 GGPChat *chat; |
|
| 47 GList *l; |
|
| 48 gchar *str_uin; |
|
| 49 |
|
| 50 for (l = info->chats; l != NULL; l = l->next) { |
|
| 51 chat = l->data; |
|
| 52 |
|
| 53 if (g_utf8_collate(chat->name, chat_name) != 0) |
|
| 54 continue; |
|
| 55 |
|
| 56 if (g_list_find(chat->participants, GINT_TO_POINTER(uin)) == NULL) { |
|
| 57 chat->participants = g_list_append( |
|
| 58 chat->participants, GINT_TO_POINTER(uin)); |
|
| 59 |
|
| 60 str_uin = g_strdup_printf("%lu", (unsigned long int)uin); |
|
| 61 conv = ggp_confer_find_by_name(gc, chat_name); |
|
| 62 purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv), str_uin, NULL, |
|
| 63 PURPLE_CBFLAGS_NONE, TRUE); |
|
| 64 |
|
| 65 g_free(str_uin); |
|
| 66 } |
|
| 67 break; |
|
| 68 } |
|
| 69 } |
|
| 70 /* }}} */ |
|
| 71 |
|
| 72 /* void ggp_confer_participants_add(PurpleConnection *gc, const gchar *chat_name, const uin_t *recipients, int count) {{{ */ |
|
| 73 void ggp_confer_participants_add(PurpleConnection *gc, const gchar *chat_name, |
|
| 74 const uin_t *recipients, int count) |
|
| 75 { |
|
| 76 GGPInfo *info = gc->proto_data; |
|
| 77 GList *l; |
|
| 78 gchar *str_uin; |
|
| 79 |
|
| 80 for (l = info->chats; l != NULL; l = l->next) { |
|
| 81 GGPChat *chat = l->data; |
|
| 82 int i; |
|
| 83 |
|
| 84 if (g_utf8_collate(chat->name, chat_name) != 0) |
|
| 85 continue; |
|
| 86 |
|
| 87 for (i = 0; i < count; i++) { |
|
| 88 PurpleConversation *conv; |
|
| 89 |
|
| 90 if (g_list_find(chat->participants, |
|
| 91 GINT_TO_POINTER(recipients[i])) != NULL) { |
|
| 92 continue; |
|
| 93 } |
|
| 94 |
|
| 95 chat->participants = g_list_append(chat->participants, |
|
| 96 GINT_TO_POINTER(recipients[i])); |
|
| 97 |
|
| 98 str_uin = g_strdup_printf("%lu", (unsigned long int)recipients[i]); |
|
| 99 conv = ggp_confer_find_by_name(gc, chat_name); |
|
| 100 purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv), |
|
| 101 str_uin, NULL, |
|
| 102 PURPLE_CBFLAGS_NONE, TRUE); |
|
| 103 g_free(str_uin); |
|
| 104 } |
|
| 105 break; |
|
| 106 } |
|
| 107 } |
|
| 108 /* }}} */ |
|
| 109 |
|
| 110 /* const char *ggp_confer_find_by_participants(PurpleConnection *gc, const uin_t *recipients, int count) {{{ */ |
|
| 111 const char *ggp_confer_find_by_participants(PurpleConnection *gc, |
|
| 112 const uin_t *recipients, int count) |
|
| 113 { |
|
| 114 GGPInfo *info = gc->proto_data; |
|
| 115 GGPChat *chat = NULL; |
|
| 116 GList *l; |
|
| 117 int matches; |
|
| 118 |
|
| 119 g_return_val_if_fail(info->chats != NULL, NULL); |
|
| 120 |
|
| 121 for (l = info->chats; l != NULL; l = l->next) { |
|
| 122 GList *m; |
|
| 123 |
|
| 124 chat = l->data; |
|
| 125 matches = 0; |
|
| 126 |
|
| 127 for (m = chat->participants; m != NULL; m = m->next) { |
|
| 128 uin_t uin = GPOINTER_TO_INT(m->data); |
|
| 129 int i; |
|
| 130 |
|
| 131 for (i = 0; i < count; i++) |
|
| 132 if (uin == recipients[i]) |
|
| 133 matches++; |
|
| 134 } |
|
| 135 |
|
| 136 if (matches == count) |
|
| 137 break; |
|
| 138 |
|
| 139 chat = NULL; |
|
| 140 } |
|
| 141 |
|
| 142 if (chat == NULL) |
|
| 143 return NULL; |
|
| 144 else |
|
| 145 return chat->name; |
|
| 146 } |
|
| 147 /* }}} */ |
|
| 148 |
|
| 149 /* const char *ggp_confer_add_new(PurpleConnection *gc, const char *name) {{{ */ |
|
| 150 const char *ggp_confer_add_new(PurpleConnection *gc, const char *name) |
|
| 151 { |
|
| 152 GGPInfo *info = gc->proto_data; |
|
| 153 GGPChat *chat; |
|
| 154 |
|
| 155 chat = g_new0(GGPChat, 1); |
|
| 156 |
|
| 157 if (name == NULL) |
|
| 158 chat->name = g_strdup_printf("conf#%d", info->chats_count++); |
|
| 159 else |
|
| 160 chat->name = g_strdup(name); |
|
| 161 |
|
| 162 chat->participants = NULL; |
|
| 163 |
|
| 164 info->chats = g_list_append(info->chats, chat); |
|
| 165 |
|
| 166 return chat->name; |
|
| 167 } |
|
| 168 /* }}} */ |
|
| 169 |
|
| 170 /* vim: set ts=8 sts=0 sw=8 noet: */ |
|