Mercurial > pidgin
annotate finch/gntconv.c @ 16970:a520e48dbfef
Patch from ticket #819 from vampire
Here's a quick fix for the disappearing buddy icons bug. Looks like this happens in purple_buddy_icons_find() when caching is disabled, and purple_buddy_icon_update() then removes the settings from the blist.
Fixes #491
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 09 May 2007 19:05:19 +0000 |
parents | 1a336cfc410e |
children | d637851abeb8 |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntconv.c GNT Conversation API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
16128
diff
changeset
|
3 * @ingroup finch |
15817 | 4 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
5 * finch |
15817 | 6 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <string.h> | |
26 | |
27 #include <cmds.h> | |
28 #include <idle.h> | |
29 #include <prefs.h> | |
30 #include <util.h> | |
31 | |
15822 | 32 #include "finch.h" |
15817 | 33 #include "gntaccount.h" |
34 #include "gntblist.h" | |
35 #include "gntconv.h" | |
36 #include "gntdebug.h" | |
37 #include "gntplugin.h" | |
38 #include "gntprefs.h" | |
39 #include "gntstatus.h" | |
16892 | 40 #include "gntpounce.h" |
15817 | 41 |
42 #include "gnt.h" | |
43 #include "gntbox.h" | |
44 #include "gntentry.h" | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
45 #include "gntlabel.h" |
16892 | 46 #include "gntmenu.h" |
47 #include "gntmenuitem.h" | |
48 #include "gntmenuitemcheck.h" | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
49 #include "gnttextview.h" |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
50 #include "gnttree.h" |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
51 #include "gntutils.h" |
16892 | 52 #include "gntwindow.h" |
15817 | 53 |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
54 #define PREF_ROOT "/finch/conversations" |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
55 #define PREF_CHAT PREF_ROOT "/chats" |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
56 #define PREF_USERLIST PREF_CHAT "/userlist" |
15817 | 57 |
58 #include "config.h" | |
59 | |
60 static void | |
61 send_typing_notification(GntWidget *w, FinchConv *ggconv) | |
62 { | |
63 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); | |
64 gboolean empty = (!text || !*text); | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
65 if (purple_prefs_get_bool("/finch/conversations/notify_typing")) { |
15822 | 66 PurpleConversation *conv = ggconv->active_conv; |
67 PurpleConvIm *im = PURPLE_CONV_IM(conv); | |
15817 | 68 if (!empty) { |
15822 | 69 gboolean send = (purple_conv_im_get_send_typed_timeout(im) == 0); |
15817 | 70 |
15822 | 71 purple_conv_im_stop_send_typed_timeout(im); |
72 purple_conv_im_start_send_typed_timeout(im); | |
73 if (send || (purple_conv_im_get_type_again(im) != 0 && | |
74 time(NULL) > purple_conv_im_get_type_again(im))) { | |
15817 | 75 unsigned int timeout; |
15822 | 76 timeout = serv_send_typing(purple_conversation_get_gc(conv), |
77 purple_conversation_get_name(conv), | |
78 PURPLE_TYPING); | |
79 purple_conv_im_set_type_again(im, timeout); | |
15817 | 80 } |
81 } else { | |
15822 | 82 purple_conv_im_stop_send_typed_timeout(im); |
15817 | 83 |
15822 | 84 serv_send_typing(purple_conversation_get_gc(conv), |
85 purple_conversation_get_name(conv), | |
86 PURPLE_NOT_TYPING); | |
15817 | 87 } |
88 } | |
89 } | |
90 | |
91 static gboolean | |
92 entry_key_pressed(GntWidget *w, const char *key, FinchConv *ggconv) | |
93 { | |
94 if (key[0] == '\r' && key[1] == 0) | |
95 { | |
96 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); | |
97 if (*text == '/') | |
98 { | |
15822 | 99 PurpleConversation *conv = ggconv->active_conv; |
100 PurpleCmdStatus status; | |
15817 | 101 const char *cmdline = text + 1; |
102 char *error = NULL, *escape; | |
103 | |
104 escape = g_markup_escape_text(cmdline, -1); | |
15822 | 105 status = purple_cmd_do_command(conv, cmdline, escape, &error); |
15817 | 106 g_free(escape); |
107 | |
108 switch (status) | |
109 { | |
15822 | 110 case PURPLE_CMD_STATUS_OK: |
15817 | 111 break; |
15822 | 112 case PURPLE_CMD_STATUS_NOT_FOUND: |
113 purple_conversation_write(conv, "", _("No such command."), | |
114 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 115 break; |
15822 | 116 case PURPLE_CMD_STATUS_WRONG_ARGS: |
117 purple_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " | |
15817 | 118 "to that command."), |
15822 | 119 PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15817 | 120 break; |
15822 | 121 case PURPLE_CMD_STATUS_FAILED: |
122 purple_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), | |
123 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 124 break; |
15822 | 125 case PURPLE_CMD_STATUS_WRONG_TYPE: |
126 if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) | |
127 purple_conversation_write(conv, "", _("That command only works in chats, not IMs."), | |
128 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 129 else |
15822 | 130 purple_conversation_write(conv, "", _("That command only works in IMs, not chats."), |
131 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 132 break; |
15822 | 133 case PURPLE_CMD_STATUS_WRONG_PRPL: |
134 purple_conversation_write(conv, "", _("That command doesn't work on this protocol."), | |
135 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 136 break; |
137 } | |
138 g_free(error); | |
139 #if 0 | |
140 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
141 _("Commands are not supported yet. Message was NOT sent."), | |
142 GNT_TEXT_FLAG_DIM | GNT_TEXT_FLAG_UNDERLINE); | |
143 gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv)); | |
144 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); | |
145 #endif | |
146 } | |
147 else | |
148 { | |
149 char *escape = g_markup_escape_text(text, -1); | |
15822 | 150 char *apos = purple_strreplace(escape, "'", "'"); |
15817 | 151 g_free(escape); |
152 escape = apos; | |
15822 | 153 switch (purple_conversation_get_type(ggconv->active_conv)) |
15817 | 154 { |
15822 | 155 case PURPLE_CONV_TYPE_IM: |
156 purple_conv_im_send_with_flags(PURPLE_CONV_IM(ggconv->active_conv), escape, PURPLE_MESSAGE_SEND); | |
15817 | 157 break; |
15822 | 158 case PURPLE_CONV_TYPE_CHAT: |
159 purple_conv_chat_send(PURPLE_CONV_CHAT(ggconv->active_conv), escape); | |
15817 | 160 break; |
161 default: | |
162 g_free(escape); | |
163 g_return_val_if_reached(FALSE); | |
164 } | |
165 g_free(escape); | |
15822 | 166 purple_idle_touch(); |
15817 | 167 } |
168 gnt_entry_add_to_history(GNT_ENTRY(ggconv->entry), text); | |
169 gnt_entry_clear(GNT_ENTRY(ggconv->entry)); | |
170 return TRUE; | |
171 } | |
172 | |
173 return FALSE; | |
174 } | |
175 | |
176 static void | |
177 closing_window(GntWidget *window, FinchConv *ggconv) | |
178 { | |
179 GList *list = ggconv->list; | |
180 ggconv->window = NULL; | |
181 while (list) { | |
15822 | 182 PurpleConversation *conv = list->data; |
15817 | 183 list = list->next; |
15822 | 184 purple_conversation_destroy(conv); |
15817 | 185 } |
186 } | |
187 | |
188 static void | |
189 size_changed_cb(GntWidget *widget, int width, int height) | |
190 { | |
191 int w, h; | |
192 gnt_widget_get_size(widget, &w, &h); | |
15822 | 193 purple_prefs_set_int(PREF_ROOT "/size/width", w); |
194 purple_prefs_set_int(PREF_ROOT "/size/height", h); | |
15817 | 195 } |
196 | |
197 static void | |
198 save_position_cb(GntWidget *w, int x, int y) | |
199 { | |
15822 | 200 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
201 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15817 | 202 } |
203 | |
15822 | 204 static PurpleConversation * |
205 find_conv_with_contact(PurpleConversation *conv) | |
15817 | 206 { |
15822 | 207 PurpleBlistNode *node; |
208 PurpleBuddy *buddy = purple_find_buddy(conv->account, conv->name); | |
209 PurpleConversation *ret = NULL; | |
15817 | 210 |
211 if (!buddy) | |
212 return NULL; | |
213 | |
15822 | 214 for (node = ((PurpleBlistNode*)buddy)->parent->child; node; node = node->next) { |
215 if (node == (PurpleBlistNode*)buddy) | |
15817 | 216 continue; |
15822 | 217 if ((ret = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
218 ((PurpleBuddy*)node)->name, ((PurpleBuddy*)node)->account)) != NULL) | |
15817 | 219 break; |
220 } | |
221 return ret; | |
222 } | |
223 | |
224 static char * | |
15822 | 225 get_conversation_title(PurpleConversation *conv, PurpleAccount *account) |
15817 | 226 { |
15822 | 227 return g_strdup_printf(_("%s (%s -- %s)"), purple_conversation_get_title(conv), |
228 purple_account_get_username(account), purple_account_get_protocol_name(account)); | |
15817 | 229 } |
230 | |
231 static void | |
15822 | 232 update_buddy_typing(PurpleAccount *account, const char *who, gpointer null) |
15817 | 233 { |
15822 | 234 PurpleConversation *conv; |
15817 | 235 FinchConv *ggc; |
15822 | 236 PurpleConvIm *im = NULL; |
15817 | 237 char *title, *str; |
238 | |
15822 | 239 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account); |
15817 | 240 |
241 if (!conv) | |
242 return; | |
243 | |
15822 | 244 im = PURPLE_CONV_IM(conv); |
15817 | 245 ggc = conv->ui_data; |
246 | |
15822 | 247 if (purple_conv_im_get_typing_state(im) == PURPLE_TYPING) { |
15817 | 248 int scroll; |
249 str = get_conversation_title(conv, account); | |
250 title = g_strdup_printf(_("%s [%s]"), str, | |
251 gnt_ascii_only() ? "T" : "\342\243\277"); | |
252 g_free(str); | |
253 | |
254 scroll = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggc->tv)); | |
15822 | 255 str = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15817 | 256 /* Updating is a little buggy. So just remove and add a new one */ |
257 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE); | |
258 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggc->tv), | |
259 str, GNT_TEXT_FLAG_DIM, "typing"); | |
260 g_free(str); | |
261 if (scroll <= 1) | |
262 gnt_text_view_scroll(GNT_TEXT_VIEW(ggc->tv), 0); | |
263 } else { | |
264 title = get_conversation_title(conv, account); | |
265 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE); | |
266 } | |
267 gnt_screen_rename_widget(ggc->window, title); | |
268 g_free(title); | |
269 } | |
270 | |
271 static gpointer | |
272 finch_conv_get_handle() | |
273 { | |
274 static int handle; | |
275 return &handle; | |
276 } | |
277 | |
278 static void | |
16892 | 279 clear_scrollback_cb(GntMenuItem *item, gpointer ggconv) |
280 { | |
281 FinchConv *ggc = ggconv; | |
282 gnt_text_view_clear(GNT_TEXT_VIEW(ggc->tv)); | |
283 } | |
284 | |
285 static void | |
286 send_file_cb(GntMenuItem *item, gpointer ggconv) | |
287 { | |
288 FinchConv *ggc = ggconv; | |
289 serv_send_file(purple_conversation_get_gc(ggc->active_conv), | |
290 purple_conversation_get_name(ggc->active_conv), NULL); | |
291 } | |
292 | |
293 static void | |
294 add_pounce_cb(GntMenuItem *item, gpointer ggconv) | |
295 { | |
296 FinchConv *ggc = ggconv; | |
297 finch_pounce_editor_show( | |
298 purple_conversation_get_account(ggc->active_conv), | |
299 purple_conversation_get_name(ggc->active_conv), NULL); | |
300 } | |
301 | |
302 static void | |
303 get_info_cb(GntMenuItem *item, gpointer ggconv) | |
304 { | |
305 FinchConv *ggc = ggconv; | |
306 serv_get_info(purple_conversation_get_gc(ggc->active_conv), | |
307 purple_conversation_get_name(ggc->active_conv)); | |
308 } | |
309 | |
310 static void | |
311 toggle_timestamps_cb(GntMenuItem *item, gpointer ggconv) | |
312 { | |
313 purple_prefs_set_bool(PREF_ROOT "/timestamps", | |
314 !purple_prefs_get_bool(PREF_ROOT "/timestamps")); | |
315 } | |
316 | |
317 static void | |
318 send_to_cb(GntMenuItem *m, gpointer n) | |
319 { | |
320 PurpleAccount *account = g_object_get_data(G_OBJECT(m), "purple_account"); | |
321 gchar *buddy = g_object_get_data(G_OBJECT(m), "purple_buddy_name"); | |
322 PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, buddy); | |
323 finch_conversation_set_active(conv); | |
324 } | |
325 | |
326 static void | |
327 generate_send_to_menu(FinchConv *ggc) | |
328 { | |
329 GntWidget *sub, *menu = ggc->menu; | |
330 GntMenuItem *item; | |
331 GSList *buds; | |
332 GList *list = NULL; | |
333 | |
334 buds = purple_find_buddies(ggc->active_conv->account, ggc->active_conv->name); | |
335 if (!buds) | |
336 return; | |
337 | |
338 item = gnt_menuitem_new(_("Send To")); | |
339 gnt_menu_add_item(GNT_MENU(menu), item); | |
340 sub = gnt_menu_new(GNT_MENU_POPUP); | |
341 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
342 | |
343 for (; buds; buds = buds->next) { | |
344 PurpleBlistNode *node = (PurpleBlistNode *)purple_buddy_get_contact((PurpleBuddy *)buds->data); | |
345 for (node = node->child; node != NULL; node = node->next) { | |
346 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
347 PurpleAccount *account = purple_buddy_get_account(buddy); | |
348 if (purple_account_is_connected(account)) { | |
349 /* Use the PurplePresence to get unique buddies. */ | |
350 PurplePresence *presence = purple_buddy_get_presence(buddy); | |
351 if (!g_list_find(list, presence)) | |
352 list = g_list_prepend(list, presence); | |
353 } | |
354 } | |
355 } | |
356 for (list = g_list_last(list); list != NULL; list = list->prev) { | |
357 PurplePresence *pre = list->data; | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
358 PurpleBuddy *buddy = purple_presence_get_buddy(pre); |
16892 | 359 PurpleAccount *account = purple_buddy_get_account(buddy); |
360 gchar *name = g_strdup(purple_buddy_get_name(buddy)); | |
361 gchar *text = g_strdup_printf("%s (%s)", purple_buddy_get_name(buddy), purple_account_get_username(account)); | |
362 item = gnt_menuitem_new(text); | |
363 g_free(text); | |
364 gnt_menu_add_item(GNT_MENU(sub), item); | |
365 gnt_menuitem_set_callback(item, send_to_cb, NULL); | |
366 g_object_set_data(G_OBJECT(item), "purple_account", account); | |
367 g_object_set_data_full(G_OBJECT(item), "purple_buddy_name", name, g_free); | |
368 } | |
369 g_list_free(list); | |
370 g_slist_free(buds); | |
371 } | |
372 | |
373 static void | |
374 gg_create_menu(FinchConv *ggc) | |
375 { | |
376 GntWidget *menu, *sub; | |
377 GntMenuItem *item; | |
378 | |
379 ggc->menu = menu = gnt_menu_new(GNT_MENU_TOPLEVEL); | |
380 gnt_window_set_menu(GNT_WINDOW(ggc->window), GNT_MENU(menu)); | |
381 | |
382 item = gnt_menuitem_new(_("Conversation")); | |
383 gnt_menu_add_item(GNT_MENU(menu), item); | |
384 | |
385 sub = gnt_menu_new(GNT_MENU_POPUP); | |
386 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
387 | |
388 item = gnt_menuitem_new(_("Clear Scrollback")); | |
389 gnt_menu_add_item(GNT_MENU(sub), item); | |
390 gnt_menuitem_set_callback(item, clear_scrollback_cb, ggc); | |
391 | |
392 item = gnt_menuitem_check_new(_("Show Timestamps")); | |
393 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), | |
394 purple_prefs_get_bool(PREF_ROOT "/timestamps")); | |
395 gnt_menu_add_item(GNT_MENU(sub), item); | |
396 gnt_menuitem_set_callback(item, toggle_timestamps_cb, ggc); | |
397 | |
398 if (purple_conversation_get_type(ggc->active_conv) == PURPLE_CONV_TYPE_IM) { | |
16958
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
399 PurpleAccount *account = purple_conversation_get_account(ggc->active_conv); |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
400 PurplePluginProtocolInfo *pinfo = account->gc ? PURPLE_PLUGIN_PROTOCOL_INFO(account->gc->prpl) : NULL; |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
401 |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
402 if (pinfo && pinfo->get_info) { |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
403 item = gnt_menuitem_new(_("Get Info")); |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
404 gnt_menu_add_item(GNT_MENU(sub), item); |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
405 gnt_menuitem_set_callback(item, get_info_cb, ggc); |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
406 } |
16892 | 407 |
408 item = gnt_menuitem_new(_("Add Buddy Pounce...")); | |
409 gnt_menu_add_item(GNT_MENU(sub), item); | |
410 gnt_menuitem_set_callback(item, add_pounce_cb, ggc); | |
411 | |
16958
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
412 if (pinfo && pinfo->send_file && |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
413 (!pinfo->can_receive_file || |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
414 pinfo->can_receive_file(account->gc, purple_conversation_get_name(ggc->active_conv)))) { |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
415 item = gnt_menuitem_new(_("Send File")); |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
416 gnt_menu_add_item(GNT_MENU(sub), item); |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
417 gnt_menuitem_set_callback(item, send_file_cb, ggc); |
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16930
diff
changeset
|
418 } |
16892 | 419 |
420 generate_send_to_menu(ggc); | |
421 } | |
422 } | |
423 | |
424 static void | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
425 create_conv_from_userlist(GntWidget *widget, FinchConv *fc) |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
426 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
427 PurpleAccount *account = purple_conversation_get_account(fc->active_conv); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
428 char *name = gnt_tree_get_selection_data(GNT_TREE(widget)); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
429 purple_conversation_new(PURPLE_CONV_TYPE_IM, account, name); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
430 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
431 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
432 static void |
15822 | 433 finch_create_conversation(PurpleConversation *conv) |
15817 | 434 { |
435 FinchConv *ggc = conv->ui_data; | |
436 char *title; | |
15822 | 437 PurpleConversationType type; |
438 PurpleConversation *cc; | |
439 PurpleAccount *account; | |
15817 | 440 |
441 if (ggc) | |
442 return; | |
443 | |
444 cc = find_conv_with_contact(conv); | |
445 if (cc && cc->ui_data) | |
446 ggc = cc->ui_data; | |
447 else | |
448 ggc = g_new0(FinchConv, 1); | |
449 | |
450 ggc->list = g_list_prepend(ggc->list, conv); | |
451 ggc->active_conv = conv; | |
452 conv->ui_data = ggc; | |
453 | |
454 if (cc && cc->ui_data) { | |
455 finch_conversation_set_active(conv); | |
456 return; | |
457 } | |
458 | |
15822 | 459 account = purple_conversation_get_account(conv); |
460 type = purple_conversation_get_type(conv); | |
15817 | 461 title = get_conversation_title(conv, account); |
462 | |
16892 | 463 ggc->window = gnt_vwindow_new(FALSE); |
15817 | 464 gnt_box_set_title(GNT_BOX(ggc->window), title); |
465 gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); | |
466 gnt_box_set_pad(GNT_BOX(ggc->window), 0); | |
467 gnt_widget_set_name(ggc->window, "conversation-window"); | |
468 | |
16892 | 469 gg_create_menu(ggc); |
470 | |
15817 | 471 ggc->tv = gnt_text_view_new(); |
472 gnt_widget_set_name(ggc->tv, "conversation-window-textview"); | |
15822 | 473 gnt_widget_set_size(ggc->tv, purple_prefs_get_int(PREF_ROOT "/size/width"), |
474 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
15817 | 475 |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
476 if (type == PURPLE_CONV_TYPE_CHAT) { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
477 GntWidget *hbox, *tree; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
478 FinchConvChat *fc = ggc->u.chat = g_new0(FinchConvChat, 1); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
479 hbox = gnt_hbox_new(FALSE); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
480 gnt_box_set_pad(GNT_BOX(hbox), 0); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
481 tree = fc->userlist = gnt_tree_new(); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
482 gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)g_utf8_collate); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
483 gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
484 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
485 gnt_box_add_widget(GNT_BOX(hbox), ggc->tv); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
486 gnt_box_add_widget(GNT_BOX(hbox), tree); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
487 gnt_box_add_widget(GNT_BOX(ggc->window), hbox); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
488 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(create_conv_from_userlist), ggc); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
489 gnt_widget_set_visible(tree, purple_prefs_get_bool(PREF_USERLIST)); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
490 } else { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
491 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
492 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
493 |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
494 ggc->info = gnt_vbox_new(FALSE); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
495 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->info); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
496 |
15817 | 497 ggc->entry = gnt_entry_new(NULL); |
498 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry); | |
499 gnt_widget_set_name(ggc->entry, "conversation-window-entry"); | |
500 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1); | |
501 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE); | |
502 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE); | |
503 | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
504 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(ggc->tv), ggc->entry); |
15817 | 505 g_signal_connect_after(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc); |
506 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); | |
507 | |
15822 | 508 gnt_widget_set_position(ggc->window, purple_prefs_get_int(PREF_ROOT "/position/x"), |
509 purple_prefs_get_int(PREF_ROOT "/position/y")); | |
15817 | 510 gnt_widget_show(ggc->window); |
511 | |
512 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL); | |
513 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL); | |
514 | |
15822 | 515 if (type == PURPLE_CONV_TYPE_IM) { |
15817 | 516 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc); |
15822 | 517 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(), |
518 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
519 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(), | |
520 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
15817 | 521 } |
522 | |
523 g_free(title); | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
524 gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry); |
15817 | 525 } |
526 | |
527 static void | |
15822 | 528 finch_destroy_conversation(PurpleConversation *conv) |
15817 | 529 { |
530 /* do stuff here */ | |
531 FinchConv *ggc = conv->ui_data; | |
532 ggc->list = g_list_remove(ggc->list, conv); | |
533 if (ggc->list && conv == ggc->active_conv) | |
534 ggc->active_conv = ggc->list->data; | |
535 | |
536 if (ggc->list == NULL) { | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
537 g_free(ggc->u.chat); |
15817 | 538 gnt_widget_destroy(ggc->window); |
539 g_free(ggc); | |
540 } | |
541 } | |
542 | |
543 static void | |
15822 | 544 finch_write_common(PurpleConversation *conv, const char *who, const char *message, |
545 PurpleMessageFlags flags, time_t mtime) | |
15817 | 546 { |
547 FinchConv *ggconv = conv->ui_data; | |
548 char *strip, *newline; | |
549 GntTextFormatFlags fl = 0; | |
550 int pos; | |
551 gboolean notify; | |
552 | |
553 g_return_if_fail(ggconv != NULL); | |
554 | |
555 if (ggconv->active_conv != conv) { | |
15822 | 556 if (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV)) |
15817 | 557 finch_conversation_set_active(conv); |
558 else | |
559 return; | |
560 } | |
561 | |
562 pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggconv->tv)); | |
563 | |
564 notify = !!gnt_text_view_tag_change(GNT_TEXT_VIEW(ggconv->tv), "typing", NULL, TRUE); | |
565 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), "\n", GNT_TEXT_FLAG_NORMAL); | |
566 | |
567 /* Unnecessary to print the timestamp for delayed message */ | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
568 if (purple_prefs_get_bool("/finch/conversations/timestamps")) |
15817 | 569 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
15822 | 570 purple_utf8_strftime("(%H:%M:%S) ", localtime(&mtime)), GNT_TEXT_FLAG_DIM); |
15817 | 571 |
15822 | 572 if (flags & PURPLE_MESSAGE_AUTO_RESP) |
15817 | 573 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
574 _("<AUTO-REPLY> "), GNT_TEXT_FLAG_BOLD); | |
575 | |
15822 | 576 if (who && *who && (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV))) |
15817 | 577 { |
578 char * name = NULL; | |
579 | |
15822 | 580 if (purple_message_meify((char*)message, -1)) |
15817 | 581 name = g_strdup_printf("*** %s ", who); |
582 else | |
583 name = g_strdup_printf("%s: ", who); | |
584 | |
585 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
586 name, GNT_TEXT_FLAG_BOLD); | |
587 g_free(name); | |
588 } | |
589 else | |
590 fl = GNT_TEXT_FLAG_DIM; | |
591 | |
15822 | 592 if (flags & PURPLE_MESSAGE_ERROR) |
15817 | 593 fl |= GNT_TEXT_FLAG_BOLD; |
15822 | 594 if (flags & PURPLE_MESSAGE_NICK) |
15817 | 595 fl |= GNT_TEXT_FLAG_UNDERLINE; |
596 | |
597 /* XXX: Remove this workaround when textview can parse messages. */ | |
15822 | 598 newline = purple_strdup_withhtml(message); |
599 strip = purple_markup_strip_html(newline); | |
15817 | 600 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
601 strip, fl); | |
602 | |
603 g_free(newline); | |
604 g_free(strip); | |
605 | |
606 if (notify) { | |
15822 | 607 strip = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15817 | 608 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggconv->tv), |
609 strip, GNT_TEXT_FLAG_DIM, "typing"); | |
610 g_free(strip); | |
611 } | |
612 | |
613 if (pos <= 1) | |
614 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); | |
615 | |
15822 | 616 if (flags & (PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_NICK | PURPLE_MESSAGE_ERROR)) |
15817 | 617 gnt_widget_set_urgent(ggconv->tv); |
618 } | |
619 | |
620 static void | |
15822 | 621 finch_write_chat(PurpleConversation *conv, const char *who, const char *message, |
622 PurpleMessageFlags flags, time_t mtime) | |
15817 | 623 { |
15822 | 624 purple_conversation_write(conv, who, message, flags, mtime); |
15817 | 625 } |
626 | |
627 static void | |
15822 | 628 finch_write_im(PurpleConversation *conv, const char *who, const char *message, |
629 PurpleMessageFlags flags, time_t mtime) | |
15817 | 630 { |
15822 | 631 PurpleAccount *account = purple_conversation_get_account(conv); |
632 if (flags & PURPLE_MESSAGE_SEND) | |
15817 | 633 { |
15822 | 634 who = purple_connection_get_display_name(purple_account_get_connection(account)); |
15817 | 635 if (!who) |
15822 | 636 who = purple_account_get_alias(account); |
15817 | 637 if (!who) |
15822 | 638 who = purple_account_get_username(account); |
15817 | 639 } |
15822 | 640 else if (flags & PURPLE_MESSAGE_RECV) |
15817 | 641 { |
15822 | 642 PurpleBuddy *buddy; |
643 who = purple_conversation_get_name(conv); | |
644 buddy = purple_find_buddy(account, who); | |
15817 | 645 if (buddy) |
15822 | 646 who = purple_buddy_get_contact_alias(buddy); |
15817 | 647 } |
648 | |
15822 | 649 purple_conversation_write(conv, who, message, flags, mtime); |
15817 | 650 } |
651 | |
652 static void | |
15822 | 653 finch_write_conv(PurpleConversation *conv, const char *who, const char *alias, |
654 const char *message, PurpleMessageFlags flags, time_t mtime) | |
15817 | 655 { |
656 const char *name; | |
657 if (alias && *alias) | |
658 name = alias; | |
659 else if (who && *who) | |
660 name = who; | |
661 else | |
662 name = NULL; | |
663 | |
664 finch_write_common(conv, name, message, flags, mtime); | |
665 } | |
666 | |
667 static void | |
15822 | 668 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals) |
15817 | 669 { |
670 FinchConv *ggc = conv->ui_data; | |
671 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
672 | |
673 if (!new_arrivals) | |
674 { | |
675 /* Print the list of users in the room */ | |
676 GString *string = g_string_new(_("List of users:\n")); | |
677 GList *iter; | |
678 | |
679 for (iter = users; iter; iter = iter->next) | |
680 { | |
15822 | 681 PurpleConvChatBuddy *cbuddy = iter->data; |
15817 | 682 char *str; |
683 | |
684 if ((str = cbuddy->alias) == NULL) | |
685 str = cbuddy->name; | |
686 g_string_append_printf(string, "[ %s ]", str); | |
687 } | |
688 | |
15822 | 689 purple_conversation_write(conv, NULL, string->str, |
690 PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
15817 | 691 g_string_free(string, TRUE); |
692 } | |
693 | |
694 for (; users; users = users->next) | |
695 { | |
15822 | 696 PurpleConvChatBuddy *cbuddy = users->data; |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
697 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15817 | 698 gnt_entry_add_suggest(entry, cbuddy->name); |
699 gnt_entry_add_suggest(entry, cbuddy->alias); | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
700 gnt_tree_add_row_after(tree, g_strdup(cbuddy->name), |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
701 gnt_tree_create_row(tree, cbuddy->alias), NULL, NULL); |
15817 | 702 } |
703 } | |
704 | |
705 static void | |
15822 | 706 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a) |
15817 | 707 { |
708 /* Update the name for string completion */ | |
709 FinchConv *ggc = conv->ui_data; | |
710 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
711 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15817 | 712 gnt_entry_remove_suggest(entry, old); |
713 gnt_entry_add_suggest(entry, new_n); | |
714 gnt_entry_add_suggest(entry, new_a); | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
715 gnt_tree_remove(tree, (gpointer)old); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
716 gnt_tree_add_row_after(tree, g_strdup(new_n), |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
717 gnt_tree_create_row(tree, new_a), NULL, NULL); |
15817 | 718 } |
719 | |
720 static void | |
15822 | 721 finch_chat_remove_user(PurpleConversation *conv, GList *list) |
15817 | 722 { |
723 /* Remove the name from string completion */ | |
724 FinchConv *ggc = conv->ui_data; | |
725 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
726 for (; list; list = list->next) { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
727 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15817 | 728 gnt_entry_remove_suggest(entry, list->data); |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
729 gnt_tree_remove(tree, list->data); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
730 } |
15817 | 731 } |
732 | |
733 static void | |
15822 | 734 finch_chat_update_user(PurpleConversation *conv, const char *user) |
15817 | 735 { |
736 } | |
737 | |
15822 | 738 static PurpleConversationUiOps conv_ui_ops = |
15817 | 739 { |
740 .create_conversation = finch_create_conversation, | |
741 .destroy_conversation = finch_destroy_conversation, | |
742 .write_chat = finch_write_chat, | |
743 .write_im = finch_write_im, | |
744 .write_conv = finch_write_conv, | |
745 .chat_add_users = finch_chat_add_users, | |
746 .chat_rename_user = finch_chat_rename_user, | |
747 .chat_remove_users = finch_chat_remove_user, | |
748 .chat_update_user = finch_chat_update_user, | |
749 .present = NULL, | |
750 .has_focus = NULL, | |
751 .custom_smiley_add = NULL, | |
752 .custom_smiley_write = NULL, | |
753 .custom_smiley_close = NULL | |
754 }; | |
755 | |
15822 | 756 PurpleConversationUiOps *finch_conv_get_ui_ops() |
15817 | 757 { |
758 return &conv_ui_ops; | |
759 } | |
760 | |
761 /* Xerox */ | |
15822 | 762 static PurpleCmdRet |
763 say_command_cb(PurpleConversation *conv, | |
15817 | 764 const char *cmd, char **args, char **error, void *data) |
765 { | |
15822 | 766 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
767 purple_conv_im_send(PURPLE_CONV_IM(conv), args[0]); | |
768 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
769 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), args[0]); | |
15817 | 770 |
15822 | 771 return PURPLE_CMD_RET_OK; |
15817 | 772 } |
773 | |
774 /* Xerox */ | |
15822 | 775 static PurpleCmdRet |
776 me_command_cb(PurpleConversation *conv, | |
15817 | 777 const char *cmd, char **args, char **error, void *data) |
778 { | |
779 char *tmp; | |
780 | |
781 tmp = g_strdup_printf("/me %s", args[0]); | |
782 | |
15822 | 783 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
784 purple_conv_im_send(PURPLE_CONV_IM(conv), tmp); | |
785 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
786 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), tmp); | |
15817 | 787 |
788 g_free(tmp); | |
15822 | 789 return PURPLE_CMD_RET_OK; |
15817 | 790 } |
791 | |
792 /* Xerox */ | |
15822 | 793 static PurpleCmdRet |
794 debug_command_cb(PurpleConversation *conv, | |
15817 | 795 const char *cmd, char **args, char **error, void *data) |
796 { | |
797 char *tmp, *markup; | |
15822 | 798 PurpleCmdStatus status; |
15817 | 799 |
800 if (!g_ascii_strcasecmp(args[0], "version")) { | |
16930
00c24829e243
Patch #751 from 'Dustin Howett' to change the output string from /debug version.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16893
diff
changeset
|
801 tmp = g_strdup_printf("me is using Finch v%s.", VERSION); |
15817 | 802 markup = g_markup_escape_text(tmp, -1); |
803 | |
15822 | 804 status = purple_cmd_do_command(conv, tmp, markup, error); |
15817 | 805 |
806 g_free(tmp); | |
807 g_free(markup); | |
808 return status; | |
809 } else { | |
15822 | 810 purple_conversation_write(conv, NULL, _("Supported debug options are: version"), |
811 PURPLE_MESSAGE_NO_LOG|PURPLE_MESSAGE_ERROR, time(NULL)); | |
812 return PURPLE_CMD_STATUS_OK; | |
15817 | 813 } |
814 } | |
815 | |
816 /* Xerox */ | |
15822 | 817 static PurpleCmdRet |
818 clear_command_cb(PurpleConversation *conv, | |
15817 | 819 const char *cmd, char **args, char **error, void *data) |
820 { | |
821 FinchConv *ggconv = conv->ui_data; | |
822 gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv)); | |
15822 | 823 return PURPLE_CMD_STATUS_OK; |
15817 | 824 } |
825 | |
826 /* Xerox */ | |
15822 | 827 static PurpleCmdRet |
828 help_command_cb(PurpleConversation *conv, | |
15817 | 829 const char *cmd, char **args, char **error, void *data) |
830 { | |
831 GList *l, *text; | |
832 GString *s; | |
833 | |
834 if (args[0] != NULL) { | |
835 s = g_string_new(""); | |
15822 | 836 text = purple_cmd_help(conv, args[0]); |
15817 | 837 |
838 if (text) { | |
839 for (l = text; l; l = l->next) | |
840 if (l->next) | |
841 g_string_append_printf(s, "%s\n", (char *)l->data); | |
842 else | |
843 g_string_append_printf(s, "%s", (char *)l->data); | |
844 } else { | |
845 g_string_append(s, _("No such command (in this context).")); | |
846 } | |
847 } else { | |
848 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" | |
849 "The following commands are available in this context:\n")); | |
850 | |
15822 | 851 text = purple_cmd_list(conv); |
15817 | 852 for (l = text; l; l = l->next) |
853 if (l->next) | |
854 g_string_append_printf(s, "%s, ", (char *)l->data); | |
855 else | |
856 g_string_append_printf(s, "%s.", (char *)l->data); | |
857 g_list_free(text); | |
858 } | |
859 | |
15822 | 860 purple_conversation_write(conv, NULL, s->str, PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15817 | 861 g_string_free(s, TRUE); |
862 | |
15822 | 863 return PURPLE_CMD_STATUS_OK; |
15817 | 864 } |
865 | |
15822 | 866 static PurpleCmdRet |
867 cmd_show_window(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) | |
15817 | 868 { |
869 void (*callback)() = data; | |
870 callback(); | |
15822 | 871 return PURPLE_CMD_STATUS_OK; |
15817 | 872 } |
873 | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
874 static PurpleCmdRet |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
875 users_command_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
876 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
877 FinchConv *fc = conv->ui_data; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
878 FinchConvChat *ch; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
879 if (!fc) |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
880 return PURPLE_CMD_STATUS_FAILED; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
881 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
882 ch = fc->u.chat; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
883 gnt_widget_set_visible(ch->userlist, |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
884 (GNT_WIDGET_IS_FLAG_SET(ch->userlist, GNT_WIDGET_INVISIBLE))); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
885 gnt_box_readjust(GNT_BOX(fc->window)); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
886 gnt_box_give_focus_to_child(GNT_BOX(fc->window), fc->entry); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
887 purple_prefs_set_bool(PREF_USERLIST, !(GNT_WIDGET_IS_FLAG_SET(ch->userlist, GNT_WIDGET_INVISIBLE))); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
888 return PURPLE_CMD_STATUS_OK; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
889 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
890 |
15817 | 891 void finch_conversation_init() |
892 { | |
15822 | 893 purple_prefs_add_none(PREF_ROOT); |
894 purple_prefs_add_none(PREF_ROOT "/size"); | |
895 purple_prefs_add_int(PREF_ROOT "/size/width", 70); | |
896 purple_prefs_add_int(PREF_ROOT "/size/height", 20); | |
897 purple_prefs_add_none(PREF_ROOT "/position"); | |
898 purple_prefs_add_int(PREF_ROOT "/position/x", 0); | |
899 purple_prefs_add_int(PREF_ROOT "/position/y", 0); | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
900 purple_prefs_add_none(PREF_CHAT); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
901 purple_prefs_add_bool(PREF_USERLIST, FALSE); |
15817 | 902 |
903 /* Xerox the commands */ | |
15822 | 904 purple_cmd_register("say", "S", PURPLE_CMD_P_DEFAULT, |
905 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 906 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); |
15822 | 907 purple_cmd_register("me", "S", PURPLE_CMD_P_DEFAULT, |
908 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 909 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); |
15822 | 910 purple_cmd_register("debug", "w", PURPLE_CMD_P_DEFAULT, |
911 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 912 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); |
15822 | 913 purple_cmd_register("clear", "", PURPLE_CMD_P_DEFAULT, |
914 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 915 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); |
15822 | 916 purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT, |
917 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, | |
15817 | 918 help_command_cb, _("help <command>: Help on a specific command."), NULL); |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
919 purple_cmd_register("users", "", PURPLE_CMD_P_DEFAULT, |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
920 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
921 users_command_cb, _("users: Show the list of users in the chat."), NULL); |
15817 | 922 |
923 /* Now some commands to bring up some other windows */ | |
15822 | 924 purple_cmd_register("plugins", "", PURPLE_CMD_P_DEFAULT, |
925 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 926 cmd_show_window, _("plugins: Show the plugins window."), finch_plugins_show_all); |
15822 | 927 purple_cmd_register("buddylist", "", PURPLE_CMD_P_DEFAULT, |
928 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 929 cmd_show_window, _("buddylist: Show the buddylist."), finch_blist_show); |
15822 | 930 purple_cmd_register("accounts", "", PURPLE_CMD_P_DEFAULT, |
931 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 932 cmd_show_window, _("accounts: Show the accounts window."), finch_accounts_show_all); |
15822 | 933 purple_cmd_register("debugwin", "", PURPLE_CMD_P_DEFAULT, |
934 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 935 cmd_show_window, _("debugwin: Show the debug window."), finch_debug_window_show); |
15822 | 936 purple_cmd_register("prefs", "", PURPLE_CMD_P_DEFAULT, |
937 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 938 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); |
15822 | 939 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, |
940 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 941 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all); |
942 } | |
943 | |
944 void finch_conversation_uninit() | |
945 { | |
946 } | |
947 | |
15822 | 948 void finch_conversation_set_active(PurpleConversation *conv) |
15817 | 949 { |
950 FinchConv *ggconv = conv->ui_data; | |
15822 | 951 PurpleAccount *account; |
15817 | 952 char *title; |
953 | |
954 g_return_if_fail(ggconv); | |
955 g_return_if_fail(g_list_find(ggconv->list, conv)); | |
956 | |
957 ggconv->active_conv = conv; | |
15822 | 958 account = purple_conversation_get_account(conv); |
15817 | 959 title = get_conversation_title(conv, account); |
960 gnt_screen_rename_widget(ggconv->window, title); | |
961 g_free(title); | |
962 } | |
963 | |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
964 void finch_conversation_set_info_widget(PurpleConversation *conv, GntWidget *widget) |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
965 { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
966 FinchConv *fc = conv->ui_data; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
967 int height, width; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
968 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
969 gnt_box_remove_all(GNT_BOX(fc->info)); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
970 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
971 if (widget) { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
972 gnt_box_add_widget(GNT_BOX(fc->info), widget); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
973 gnt_box_readjust(GNT_BOX(fc->info)); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
974 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
975 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
976 gnt_widget_get_size(fc->window, &width, &height); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
977 gnt_box_readjust(GNT_BOX(fc->window)); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
978 gnt_screen_resize_widget(fc->window, width, height); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
979 gnt_box_give_focus_to_child(GNT_BOX(fc->window), fc->entry); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
980 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
981 |