Mercurial > pidgin.yaz
annotate finch/gntconv.c @ 16947:f6de19624575
added mercurial ignore lines
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Tue, 08 May 2007 02:44:49 +0000 |
parents | 00c24829e243 |
children | 1a336cfc410e |
rev | line source |
---|---|
15818 | 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 |
15818 | 4 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 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 | |
15823 | 32 #include "finch.h" |
15818 | 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" | |
16903 | 40 #include "gntpounce.h" |
15818 | 41 |
42 #include "gnt.h" | |
43 #include "gntbox.h" | |
44 #include "gntentry.h" | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
45 #include "gntlabel.h" |
16903 | 46 #include "gntmenu.h" |
47 #include "gntmenuitem.h" | |
48 #include "gntmenuitemcheck.h" | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
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:
16903
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:
16903
diff
changeset
|
51 #include "gntutils.h" |
16903 | 52 #include "gntwindow.h" |
15818 | 53 |
16427
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" |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
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:
16903
diff
changeset
|
56 #define PREF_USERLIST PREF_CHAT "/userlist" |
15818 | 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); | |
16427
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")) { |
15823 | 66 PurpleConversation *conv = ggconv->active_conv; |
67 PurpleConvIm *im = PURPLE_CONV_IM(conv); | |
15818 | 68 if (!empty) { |
15823 | 69 gboolean send = (purple_conv_im_get_send_typed_timeout(im) == 0); |
15818 | 70 |
15823 | 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))) { | |
15818 | 75 unsigned int timeout; |
15823 | 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); | |
15818 | 80 } |
81 } else { | |
15823 | 82 purple_conv_im_stop_send_typed_timeout(im); |
15818 | 83 |
15823 | 84 serv_send_typing(purple_conversation_get_gc(conv), |
85 purple_conversation_get_name(conv), | |
86 PURPLE_NOT_TYPING); | |
15818 | 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 { | |
15823 | 99 PurpleConversation *conv = ggconv->active_conv; |
100 PurpleCmdStatus status; | |
15818 | 101 const char *cmdline = text + 1; |
102 char *error = NULL, *escape; | |
103 | |
104 escape = g_markup_escape_text(cmdline, -1); | |
15823 | 105 status = purple_cmd_do_command(conv, cmdline, escape, &error); |
15818 | 106 g_free(escape); |
107 | |
108 switch (status) | |
109 { | |
15823 | 110 case PURPLE_CMD_STATUS_OK: |
15818 | 111 break; |
15823 | 112 case PURPLE_CMD_STATUS_NOT_FOUND: |
113 purple_conversation_write(conv, "", _("No such command."), | |
114 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15818 | 115 break; |
15823 | 116 case PURPLE_CMD_STATUS_WRONG_ARGS: |
117 purple_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " | |
15818 | 118 "to that command."), |
15823 | 119 PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15818 | 120 break; |
15823 | 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)); | |
15818 | 124 break; |
15823 | 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)); | |
15818 | 129 else |
15823 | 130 purple_conversation_write(conv, "", _("That command only works in IMs, not chats."), |
131 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15818 | 132 break; |
15823 | 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)); | |
15818 | 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); | |
15823 | 150 char *apos = purple_strreplace(escape, "'", "'"); |
15818 | 151 g_free(escape); |
152 escape = apos; | |
15823 | 153 switch (purple_conversation_get_type(ggconv->active_conv)) |
15818 | 154 { |
15823 | 155 case PURPLE_CONV_TYPE_IM: |
156 purple_conv_im_send_with_flags(PURPLE_CONV_IM(ggconv->active_conv), escape, PURPLE_MESSAGE_SEND); | |
15818 | 157 break; |
15823 | 158 case PURPLE_CONV_TYPE_CHAT: |
159 purple_conv_chat_send(PURPLE_CONV_CHAT(ggconv->active_conv), escape); | |
15818 | 160 break; |
161 default: | |
162 g_free(escape); | |
163 g_return_val_if_reached(FALSE); | |
164 } | |
165 g_free(escape); | |
15823 | 166 purple_idle_touch(); |
15818 | 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) { | |
15823 | 182 PurpleConversation *conv = list->data; |
15818 | 183 list = list->next; |
15823 | 184 purple_conversation_destroy(conv); |
15818 | 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); | |
15823 | 193 purple_prefs_set_int(PREF_ROOT "/size/width", w); |
194 purple_prefs_set_int(PREF_ROOT "/size/height", h); | |
15818 | 195 } |
196 | |
197 static void | |
198 save_position_cb(GntWidget *w, int x, int y) | |
199 { | |
15823 | 200 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
201 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15818 | 202 } |
203 | |
15823 | 204 static PurpleConversation * |
205 find_conv_with_contact(PurpleConversation *conv) | |
15818 | 206 { |
15823 | 207 PurpleBlistNode *node; |
208 PurpleBuddy *buddy = purple_find_buddy(conv->account, conv->name); | |
209 PurpleConversation *ret = NULL; | |
15818 | 210 |
211 if (!buddy) | |
212 return NULL; | |
213 | |
15823 | 214 for (node = ((PurpleBlistNode*)buddy)->parent->child; node; node = node->next) { |
215 if (node == (PurpleBlistNode*)buddy) | |
15818 | 216 continue; |
15823 | 217 if ((ret = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
218 ((PurpleBuddy*)node)->name, ((PurpleBuddy*)node)->account)) != NULL) | |
15818 | 219 break; |
220 } | |
221 return ret; | |
222 } | |
223 | |
224 static char * | |
15823 | 225 get_conversation_title(PurpleConversation *conv, PurpleAccount *account) |
15818 | 226 { |
15823 | 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)); | |
15818 | 229 } |
230 | |
231 static void | |
15823 | 232 update_buddy_typing(PurpleAccount *account, const char *who, gpointer null) |
15818 | 233 { |
15823 | 234 PurpleConversation *conv; |
15818 | 235 FinchConv *ggc; |
15823 | 236 PurpleConvIm *im = NULL; |
15818 | 237 char *title, *str; |
238 | |
15823 | 239 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account); |
15818 | 240 |
241 if (!conv) | |
242 return; | |
243 | |
15823 | 244 im = PURPLE_CONV_IM(conv); |
15818 | 245 ggc = conv->ui_data; |
246 | |
15823 | 247 if (purple_conv_im_get_typing_state(im) == PURPLE_TYPING) { |
15818 | 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)); | |
15823 | 255 str = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15818 | 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 | |
16903 | 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; | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
358 PurpleBuddy *buddy = purple_presence_get_buddy(pre); |
16903 | 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) { | |
399 item = gnt_menuitem_new(_("Send File")); | |
400 gnt_menu_add_item(GNT_MENU(sub), item); | |
401 gnt_menuitem_set_callback(item, send_file_cb, ggc); | |
402 | |
403 item = gnt_menuitem_new(_("Add Buddy Pounce...")); | |
404 gnt_menu_add_item(GNT_MENU(sub), item); | |
405 gnt_menuitem_set_callback(item, add_pounce_cb, ggc); | |
406 | |
407 item = gnt_menuitem_new(_("Get Info")); | |
408 gnt_menu_add_item(GNT_MENU(sub), item); | |
409 gnt_menuitem_set_callback(item, get_info_cb, ggc); | |
410 | |
411 generate_send_to_menu(ggc); | |
412 } | |
413 } | |
414 | |
415 static void | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
416 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:
16903
diff
changeset
|
417 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
418 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:
16903
diff
changeset
|
419 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:
16903
diff
changeset
|
420 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:
16903
diff
changeset
|
421 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
422 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
423 static void |
15823 | 424 finch_create_conversation(PurpleConversation *conv) |
15818 | 425 { |
426 FinchConv *ggc = conv->ui_data; | |
427 char *title; | |
15823 | 428 PurpleConversationType type; |
429 PurpleConversation *cc; | |
430 PurpleAccount *account; | |
15818 | 431 |
432 if (ggc) | |
433 return; | |
434 | |
435 cc = find_conv_with_contact(conv); | |
436 if (cc && cc->ui_data) | |
437 ggc = cc->ui_data; | |
438 else | |
439 ggc = g_new0(FinchConv, 1); | |
440 | |
441 ggc->list = g_list_prepend(ggc->list, conv); | |
442 ggc->active_conv = conv; | |
443 conv->ui_data = ggc; | |
444 | |
445 if (cc && cc->ui_data) { | |
446 finch_conversation_set_active(conv); | |
447 return; | |
448 } | |
449 | |
15823 | 450 account = purple_conversation_get_account(conv); |
451 type = purple_conversation_get_type(conv); | |
15818 | 452 title = get_conversation_title(conv, account); |
453 | |
16903 | 454 ggc->window = gnt_vwindow_new(FALSE); |
15818 | 455 gnt_box_set_title(GNT_BOX(ggc->window), title); |
456 gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); | |
457 gnt_box_set_pad(GNT_BOX(ggc->window), 0); | |
458 gnt_widget_set_name(ggc->window, "conversation-window"); | |
459 | |
16903 | 460 gg_create_menu(ggc); |
461 | |
15818 | 462 ggc->tv = gnt_text_view_new(); |
463 gnt_widget_set_name(ggc->tv, "conversation-window-textview"); | |
15823 | 464 gnt_widget_set_size(ggc->tv, purple_prefs_get_int(PREF_ROOT "/size/width"), |
465 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
15818 | 466 |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
467 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:
16903
diff
changeset
|
468 GntWidget *hbox, *tree; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
469 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:
16903
diff
changeset
|
470 hbox = gnt_hbox_new(FALSE); |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
471 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:
16903
diff
changeset
|
472 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:
16903
diff
changeset
|
473 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:
16903
diff
changeset
|
474 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:
16903
diff
changeset
|
475 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:
16903
diff
changeset
|
476 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:
16903
diff
changeset
|
477 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:
16903
diff
changeset
|
478 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:
16903
diff
changeset
|
479 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:
16903
diff
changeset
|
480 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:
16903
diff
changeset
|
481 } else { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
482 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:
16903
diff
changeset
|
483 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
484 |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
485 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
|
486 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
|
487 |
15818 | 488 ggc->entry = gnt_entry_new(NULL); |
489 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry); | |
490 gnt_widget_set_name(ggc->entry, "conversation-window-entry"); | |
491 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1); | |
492 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE); | |
493 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE); | |
494 | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
495 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(ggc->tv), ggc->entry); |
15818 | 496 g_signal_connect_after(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc); |
497 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); | |
498 | |
15823 | 499 gnt_widget_set_position(ggc->window, purple_prefs_get_int(PREF_ROOT "/position/x"), |
500 purple_prefs_get_int(PREF_ROOT "/position/y")); | |
15818 | 501 gnt_widget_show(ggc->window); |
502 | |
503 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL); | |
504 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL); | |
505 | |
15823 | 506 if (type == PURPLE_CONV_TYPE_IM) { |
15818 | 507 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc); |
15823 | 508 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(), |
509 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
510 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(), | |
511 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
15818 | 512 } |
513 | |
514 g_free(title); | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
515 gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry); |
15818 | 516 } |
517 | |
518 static void | |
15823 | 519 finch_destroy_conversation(PurpleConversation *conv) |
15818 | 520 { |
521 /* do stuff here */ | |
522 FinchConv *ggc = conv->ui_data; | |
523 ggc->list = g_list_remove(ggc->list, conv); | |
524 if (ggc->list && conv == ggc->active_conv) | |
525 ggc->active_conv = ggc->list->data; | |
526 | |
527 if (ggc->list == NULL) { | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
528 g_free(ggc->u.chat); |
15818 | 529 gnt_widget_destroy(ggc->window); |
530 g_free(ggc); | |
531 } | |
532 } | |
533 | |
534 static void | |
15823 | 535 finch_write_common(PurpleConversation *conv, const char *who, const char *message, |
536 PurpleMessageFlags flags, time_t mtime) | |
15818 | 537 { |
538 FinchConv *ggconv = conv->ui_data; | |
539 char *strip, *newline; | |
540 GntTextFormatFlags fl = 0; | |
541 int pos; | |
542 gboolean notify; | |
543 | |
544 g_return_if_fail(ggconv != NULL); | |
545 | |
546 if (ggconv->active_conv != conv) { | |
15823 | 547 if (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV)) |
15818 | 548 finch_conversation_set_active(conv); |
549 else | |
550 return; | |
551 } | |
552 | |
553 pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggconv->tv)); | |
554 | |
555 notify = !!gnt_text_view_tag_change(GNT_TEXT_VIEW(ggconv->tv), "typing", NULL, TRUE); | |
556 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), "\n", GNT_TEXT_FLAG_NORMAL); | |
557 | |
558 /* Unnecessary to print the timestamp for delayed message */ | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
559 if (purple_prefs_get_bool("/finch/conversations/timestamps")) |
15818 | 560 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
15823 | 561 purple_utf8_strftime("(%H:%M:%S) ", localtime(&mtime)), GNT_TEXT_FLAG_DIM); |
15818 | 562 |
15823 | 563 if (flags & PURPLE_MESSAGE_AUTO_RESP) |
15818 | 564 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
565 _("<AUTO-REPLY> "), GNT_TEXT_FLAG_BOLD); | |
566 | |
15823 | 567 if (who && *who && (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV))) |
15818 | 568 { |
569 char * name = NULL; | |
570 | |
15823 | 571 if (purple_message_meify((char*)message, -1)) |
15818 | 572 name = g_strdup_printf("*** %s ", who); |
573 else | |
574 name = g_strdup_printf("%s: ", who); | |
575 | |
576 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
577 name, GNT_TEXT_FLAG_BOLD); | |
578 g_free(name); | |
579 } | |
580 else | |
581 fl = GNT_TEXT_FLAG_DIM; | |
582 | |
15823 | 583 if (flags & PURPLE_MESSAGE_ERROR) |
15818 | 584 fl |= GNT_TEXT_FLAG_BOLD; |
15823 | 585 if (flags & PURPLE_MESSAGE_NICK) |
15818 | 586 fl |= GNT_TEXT_FLAG_UNDERLINE; |
587 | |
588 /* XXX: Remove this workaround when textview can parse messages. */ | |
15823 | 589 newline = purple_strdup_withhtml(message); |
590 strip = purple_markup_strip_html(newline); | |
15818 | 591 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
592 strip, fl); | |
593 | |
594 g_free(newline); | |
595 g_free(strip); | |
596 | |
597 if (notify) { | |
15823 | 598 strip = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15818 | 599 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggconv->tv), |
600 strip, GNT_TEXT_FLAG_DIM, "typing"); | |
601 g_free(strip); | |
602 } | |
603 | |
604 if (pos <= 1) | |
605 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); | |
606 | |
15823 | 607 if (flags & (PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_NICK | PURPLE_MESSAGE_ERROR)) |
15818 | 608 gnt_widget_set_urgent(ggconv->tv); |
609 } | |
610 | |
611 static void | |
15823 | 612 finch_write_chat(PurpleConversation *conv, const char *who, const char *message, |
613 PurpleMessageFlags flags, time_t mtime) | |
15818 | 614 { |
15823 | 615 purple_conversation_write(conv, who, message, flags, mtime); |
15818 | 616 } |
617 | |
618 static void | |
15823 | 619 finch_write_im(PurpleConversation *conv, const char *who, const char *message, |
620 PurpleMessageFlags flags, time_t mtime) | |
15818 | 621 { |
15823 | 622 PurpleAccount *account = purple_conversation_get_account(conv); |
623 if (flags & PURPLE_MESSAGE_SEND) | |
15818 | 624 { |
15823 | 625 who = purple_connection_get_display_name(purple_account_get_connection(account)); |
15818 | 626 if (!who) |
15823 | 627 who = purple_account_get_alias(account); |
15818 | 628 if (!who) |
15823 | 629 who = purple_account_get_username(account); |
15818 | 630 } |
15823 | 631 else if (flags & PURPLE_MESSAGE_RECV) |
15818 | 632 { |
15823 | 633 PurpleBuddy *buddy; |
634 who = purple_conversation_get_name(conv); | |
635 buddy = purple_find_buddy(account, who); | |
15818 | 636 if (buddy) |
15823 | 637 who = purple_buddy_get_contact_alias(buddy); |
15818 | 638 } |
639 | |
15823 | 640 purple_conversation_write(conv, who, message, flags, mtime); |
15818 | 641 } |
642 | |
643 static void | |
15823 | 644 finch_write_conv(PurpleConversation *conv, const char *who, const char *alias, |
645 const char *message, PurpleMessageFlags flags, time_t mtime) | |
15818 | 646 { |
647 const char *name; | |
648 if (alias && *alias) | |
649 name = alias; | |
650 else if (who && *who) | |
651 name = who; | |
652 else | |
653 name = NULL; | |
654 | |
655 finch_write_common(conv, name, message, flags, mtime); | |
656 } | |
657 | |
658 static void | |
15823 | 659 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals) |
15818 | 660 { |
661 FinchConv *ggc = conv->ui_data; | |
662 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
663 | |
664 if (!new_arrivals) | |
665 { | |
666 /* Print the list of users in the room */ | |
667 GString *string = g_string_new(_("List of users:\n")); | |
668 GList *iter; | |
669 | |
670 for (iter = users; iter; iter = iter->next) | |
671 { | |
15823 | 672 PurpleConvChatBuddy *cbuddy = iter->data; |
15818 | 673 char *str; |
674 | |
675 if ((str = cbuddy->alias) == NULL) | |
676 str = cbuddy->name; | |
677 g_string_append_printf(string, "[ %s ]", str); | |
678 } | |
679 | |
15823 | 680 purple_conversation_write(conv, NULL, string->str, |
681 PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
15818 | 682 g_string_free(string, TRUE); |
683 } | |
684 | |
685 for (; users; users = users->next) | |
686 { | |
15823 | 687 PurpleConvChatBuddy *cbuddy = users->data; |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
688 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15818 | 689 gnt_entry_add_suggest(entry, cbuddy->name); |
690 gnt_entry_add_suggest(entry, cbuddy->alias); | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
691 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:
16903
diff
changeset
|
692 gnt_tree_create_row(tree, cbuddy->alias), NULL, NULL); |
15818 | 693 } |
694 } | |
695 | |
696 static void | |
15823 | 697 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a) |
15818 | 698 { |
699 /* Update the name for string completion */ | |
700 FinchConv *ggc = conv->ui_data; | |
701 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
702 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15818 | 703 gnt_entry_remove_suggest(entry, old); |
704 gnt_entry_add_suggest(entry, new_n); | |
705 gnt_entry_add_suggest(entry, new_a); | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
706 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:
16903
diff
changeset
|
707 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:
16903
diff
changeset
|
708 gnt_tree_create_row(tree, new_a), NULL, NULL); |
15818 | 709 } |
710 | |
711 static void | |
15823 | 712 finch_chat_remove_user(PurpleConversation *conv, GList *list) |
15818 | 713 { |
714 /* Remove the name from string completion */ | |
715 FinchConv *ggc = conv->ui_data; | |
716 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
717 for (; list; list = list->next) { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
718 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15818 | 719 gnt_entry_remove_suggest(entry, list->data); |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
720 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:
16903
diff
changeset
|
721 } |
15818 | 722 } |
723 | |
724 static void | |
15823 | 725 finch_chat_update_user(PurpleConversation *conv, const char *user) |
15818 | 726 { |
727 } | |
728 | |
15823 | 729 static PurpleConversationUiOps conv_ui_ops = |
15818 | 730 { |
731 .create_conversation = finch_create_conversation, | |
732 .destroy_conversation = finch_destroy_conversation, | |
733 .write_chat = finch_write_chat, | |
734 .write_im = finch_write_im, | |
735 .write_conv = finch_write_conv, | |
736 .chat_add_users = finch_chat_add_users, | |
737 .chat_rename_user = finch_chat_rename_user, | |
738 .chat_remove_users = finch_chat_remove_user, | |
739 .chat_update_user = finch_chat_update_user, | |
740 .present = NULL, | |
741 .has_focus = NULL, | |
742 .custom_smiley_add = NULL, | |
743 .custom_smiley_write = NULL, | |
744 .custom_smiley_close = NULL | |
745 }; | |
746 | |
15823 | 747 PurpleConversationUiOps *finch_conv_get_ui_ops() |
15818 | 748 { |
749 return &conv_ui_ops; | |
750 } | |
751 | |
752 /* Xerox */ | |
15823 | 753 static PurpleCmdRet |
754 say_command_cb(PurpleConversation *conv, | |
15818 | 755 const char *cmd, char **args, char **error, void *data) |
756 { | |
15823 | 757 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
758 purple_conv_im_send(PURPLE_CONV_IM(conv), args[0]); | |
759 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
760 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), args[0]); | |
15818 | 761 |
15823 | 762 return PURPLE_CMD_RET_OK; |
15818 | 763 } |
764 | |
765 /* Xerox */ | |
15823 | 766 static PurpleCmdRet |
767 me_command_cb(PurpleConversation *conv, | |
15818 | 768 const char *cmd, char **args, char **error, void *data) |
769 { | |
770 char *tmp; | |
771 | |
772 tmp = g_strdup_printf("/me %s", args[0]); | |
773 | |
15823 | 774 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
775 purple_conv_im_send(PURPLE_CONV_IM(conv), tmp); | |
776 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
777 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), tmp); | |
15818 | 778 |
779 g_free(tmp); | |
15823 | 780 return PURPLE_CMD_RET_OK; |
15818 | 781 } |
782 | |
783 /* Xerox */ | |
15823 | 784 static PurpleCmdRet |
785 debug_command_cb(PurpleConversation *conv, | |
15818 | 786 const char *cmd, char **args, char **error, void *data) |
787 { | |
788 char *tmp, *markup; | |
15823 | 789 PurpleCmdStatus status; |
15818 | 790 |
791 if (!g_ascii_strcasecmp(args[0], "version")) { | |
16941
00c24829e243
Patch #751 from 'Dustin Howett' to change the output string from /debug version.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16904
diff
changeset
|
792 tmp = g_strdup_printf("me is using Finch v%s.", VERSION); |
15818 | 793 markup = g_markup_escape_text(tmp, -1); |
794 | |
15823 | 795 status = purple_cmd_do_command(conv, tmp, markup, error); |
15818 | 796 |
797 g_free(tmp); | |
798 g_free(markup); | |
799 return status; | |
800 } else { | |
15823 | 801 purple_conversation_write(conv, NULL, _("Supported debug options are: version"), |
802 PURPLE_MESSAGE_NO_LOG|PURPLE_MESSAGE_ERROR, time(NULL)); | |
803 return PURPLE_CMD_STATUS_OK; | |
15818 | 804 } |
805 } | |
806 | |
807 /* Xerox */ | |
15823 | 808 static PurpleCmdRet |
809 clear_command_cb(PurpleConversation *conv, | |
15818 | 810 const char *cmd, char **args, char **error, void *data) |
811 { | |
812 FinchConv *ggconv = conv->ui_data; | |
813 gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv)); | |
15823 | 814 return PURPLE_CMD_STATUS_OK; |
15818 | 815 } |
816 | |
817 /* Xerox */ | |
15823 | 818 static PurpleCmdRet |
819 help_command_cb(PurpleConversation *conv, | |
15818 | 820 const char *cmd, char **args, char **error, void *data) |
821 { | |
822 GList *l, *text; | |
823 GString *s; | |
824 | |
825 if (args[0] != NULL) { | |
826 s = g_string_new(""); | |
15823 | 827 text = purple_cmd_help(conv, args[0]); |
15818 | 828 |
829 if (text) { | |
830 for (l = text; l; l = l->next) | |
831 if (l->next) | |
832 g_string_append_printf(s, "%s\n", (char *)l->data); | |
833 else | |
834 g_string_append_printf(s, "%s", (char *)l->data); | |
835 } else { | |
836 g_string_append(s, _("No such command (in this context).")); | |
837 } | |
838 } else { | |
839 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" | |
840 "The following commands are available in this context:\n")); | |
841 | |
15823 | 842 text = purple_cmd_list(conv); |
15818 | 843 for (l = text; l; l = l->next) |
844 if (l->next) | |
845 g_string_append_printf(s, "%s, ", (char *)l->data); | |
846 else | |
847 g_string_append_printf(s, "%s.", (char *)l->data); | |
848 g_list_free(text); | |
849 } | |
850 | |
15823 | 851 purple_conversation_write(conv, NULL, s->str, PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15818 | 852 g_string_free(s, TRUE); |
853 | |
15823 | 854 return PURPLE_CMD_STATUS_OK; |
15818 | 855 } |
856 | |
15823 | 857 static PurpleCmdRet |
858 cmd_show_window(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) | |
15818 | 859 { |
860 void (*callback)() = data; | |
861 callback(); | |
15823 | 862 return PURPLE_CMD_STATUS_OK; |
15818 | 863 } |
864 | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
865 static PurpleCmdRet |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
866 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:
16903
diff
changeset
|
867 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
868 FinchConv *fc = conv->ui_data; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
869 FinchConvChat *ch; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
870 if (!fc) |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
871 return PURPLE_CMD_STATUS_FAILED; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
872 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
873 ch = fc->u.chat; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
874 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:
16903
diff
changeset
|
875 (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:
16903
diff
changeset
|
876 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:
16903
diff
changeset
|
877 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:
16903
diff
changeset
|
878 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:
16903
diff
changeset
|
879 return PURPLE_CMD_STATUS_OK; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
880 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
881 |
15818 | 882 void finch_conversation_init() |
883 { | |
15823 | 884 purple_prefs_add_none(PREF_ROOT); |
885 purple_prefs_add_none(PREF_ROOT "/size"); | |
886 purple_prefs_add_int(PREF_ROOT "/size/width", 70); | |
887 purple_prefs_add_int(PREF_ROOT "/size/height", 20); | |
888 purple_prefs_add_none(PREF_ROOT "/position"); | |
889 purple_prefs_add_int(PREF_ROOT "/position/x", 0); | |
890 purple_prefs_add_int(PREF_ROOT "/position/y", 0); | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
891 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:
16903
diff
changeset
|
892 purple_prefs_add_bool(PREF_USERLIST, FALSE); |
15818 | 893 |
894 /* Xerox the commands */ | |
15823 | 895 purple_cmd_register("say", "S", PURPLE_CMD_P_DEFAULT, |
896 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 897 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); |
15823 | 898 purple_cmd_register("me", "S", PURPLE_CMD_P_DEFAULT, |
899 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 900 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); |
15823 | 901 purple_cmd_register("debug", "w", PURPLE_CMD_P_DEFAULT, |
902 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 903 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); |
15823 | 904 purple_cmd_register("clear", "", PURPLE_CMD_P_DEFAULT, |
905 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 906 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); |
15823 | 907 purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT, |
908 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, | |
15818 | 909 help_command_cb, _("help <command>: Help on a specific command."), NULL); |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
910 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:
16903
diff
changeset
|
911 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:
16903
diff
changeset
|
912 users_command_cb, _("users: Show the list of users in the chat."), NULL); |
15818 | 913 |
914 /* Now some commands to bring up some other windows */ | |
15823 | 915 purple_cmd_register("plugins", "", PURPLE_CMD_P_DEFAULT, |
916 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 917 cmd_show_window, _("plugins: Show the plugins window."), finch_plugins_show_all); |
15823 | 918 purple_cmd_register("buddylist", "", PURPLE_CMD_P_DEFAULT, |
919 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 920 cmd_show_window, _("buddylist: Show the buddylist."), finch_blist_show); |
15823 | 921 purple_cmd_register("accounts", "", PURPLE_CMD_P_DEFAULT, |
922 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 923 cmd_show_window, _("accounts: Show the accounts window."), finch_accounts_show_all); |
15823 | 924 purple_cmd_register("debugwin", "", PURPLE_CMD_P_DEFAULT, |
925 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 926 cmd_show_window, _("debugwin: Show the debug window."), finch_debug_window_show); |
15823 | 927 purple_cmd_register("prefs", "", PURPLE_CMD_P_DEFAULT, |
928 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 929 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); |
15823 | 930 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, |
931 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 932 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all); |
933 } | |
934 | |
935 void finch_conversation_uninit() | |
936 { | |
937 } | |
938 | |
15823 | 939 void finch_conversation_set_active(PurpleConversation *conv) |
15818 | 940 { |
941 FinchConv *ggconv = conv->ui_data; | |
15823 | 942 PurpleAccount *account; |
15818 | 943 char *title; |
944 | |
945 g_return_if_fail(ggconv); | |
946 g_return_if_fail(g_list_find(ggconv->list, conv)); | |
947 | |
948 ggconv->active_conv = conv; | |
15823 | 949 account = purple_conversation_get_account(conv); |
15818 | 950 title = get_conversation_title(conv, account); |
951 gnt_screen_rename_widget(ggconv->window, title); | |
952 g_free(title); | |
953 } | |
954 | |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
955 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
|
956 { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
957 FinchConv *fc = conv->ui_data; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
958 int height, width; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
959 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
960 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
|
961 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
962 if (widget) { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
963 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
|
964 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
|
965 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
966 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 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
|
971 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
972 |