Mercurial > pidgin.yaz
annotate finch/gntconv.c @ 19002:daeca1b9ebdb
- Fix an incorrect assertion in GnuTLS plugin
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Sun, 08 Jul 2007 02:32:25 +0000 |
parents | 9eb2f4d27990 |
children | be8c4eba38f6 |
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 | |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18100
diff
changeset
|
27 #include "finch.h" |
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18100
diff
changeset
|
28 |
15818 | 29 #include <cmds.h> |
30 #include <idle.h> | |
31 #include <prefs.h> | |
32 #include <util.h> | |
33 | |
34 #include "gntaccount.h" | |
35 #include "gntblist.h" | |
36 #include "gntconv.h" | |
37 #include "gntdebug.h" | |
38 #include "gntplugin.h" | |
39 #include "gntprefs.h" | |
40 #include "gntstatus.h" | |
16903 | 41 #include "gntpounce.h" |
15818 | 42 |
43 #include "gnt.h" | |
44 #include "gntbox.h" | |
45 #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
|
46 #include "gntlabel.h" |
16903 | 47 #include "gntmenu.h" |
48 #include "gntmenuitem.h" | |
49 #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
|
50 #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
|
51 #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
|
52 #include "gntutils.h" |
16903 | 53 #include "gntwindow.h" |
15818 | 54 |
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
|
55 #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
|
56 #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
|
57 #define PREF_USERLIST PREF_CHAT "/userlist" |
15818 | 58 |
59 #include "config.h" | |
60 | |
17032
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
61 static void finch_write_common(PurpleConversation *conv, const char *who, |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
62 const char *message, PurpleMessageFlags flags, time_t mtime); |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
63 |
15818 | 64 static void |
65 send_typing_notification(GntWidget *w, FinchConv *ggconv) | |
66 { | |
67 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); | |
17529
289ac53f753f
Do not send typing notification if you are typing a /-command.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17275
diff
changeset
|
68 gboolean empty = (!text || !*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
|
69 if (purple_prefs_get_bool("/finch/conversations/notify_typing")) { |
15823 | 70 PurpleConversation *conv = ggconv->active_conv; |
71 PurpleConvIm *im = PURPLE_CONV_IM(conv); | |
15818 | 72 if (!empty) { |
15823 | 73 gboolean send = (purple_conv_im_get_send_typed_timeout(im) == 0); |
15818 | 74 |
15823 | 75 purple_conv_im_stop_send_typed_timeout(im); |
76 purple_conv_im_start_send_typed_timeout(im); | |
77 if (send || (purple_conv_im_get_type_again(im) != 0 && | |
78 time(NULL) > purple_conv_im_get_type_again(im))) { | |
15818 | 79 unsigned int timeout; |
15823 | 80 timeout = serv_send_typing(purple_conversation_get_gc(conv), |
81 purple_conversation_get_name(conv), | |
82 PURPLE_TYPING); | |
83 purple_conv_im_set_type_again(im, timeout); | |
15818 | 84 } |
85 } else { | |
15823 | 86 purple_conv_im_stop_send_typed_timeout(im); |
15818 | 87 |
15823 | 88 serv_send_typing(purple_conversation_get_gc(conv), |
89 purple_conversation_get_name(conv), | |
90 PURPLE_NOT_TYPING); | |
15818 | 91 } |
92 } | |
93 } | |
94 | |
95 static gboolean | |
96 entry_key_pressed(GntWidget *w, const char *key, FinchConv *ggconv) | |
97 { | |
98 if (key[0] == '\r' && key[1] == 0) | |
99 { | |
100 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); | |
101 if (*text == '/') | |
102 { | |
15823 | 103 PurpleConversation *conv = ggconv->active_conv; |
104 PurpleCmdStatus status; | |
15818 | 105 const char *cmdline = text + 1; |
106 char *error = NULL, *escape; | |
107 | |
108 escape = g_markup_escape_text(cmdline, -1); | |
15823 | 109 status = purple_cmd_do_command(conv, cmdline, escape, &error); |
15818 | 110 g_free(escape); |
111 | |
112 switch (status) | |
113 { | |
15823 | 114 case PURPLE_CMD_STATUS_OK: |
15818 | 115 break; |
15823 | 116 case PURPLE_CMD_STATUS_NOT_FOUND: |
117 purple_conversation_write(conv, "", _("No such command."), | |
118 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15818 | 119 break; |
15823 | 120 case PURPLE_CMD_STATUS_WRONG_ARGS: |
121 purple_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " | |
15818 | 122 "to that command."), |
15823 | 123 PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15818 | 124 break; |
15823 | 125 case PURPLE_CMD_STATUS_FAILED: |
126 purple_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), | |
127 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15818 | 128 break; |
15823 | 129 case PURPLE_CMD_STATUS_WRONG_TYPE: |
130 if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) | |
131 purple_conversation_write(conv, "", _("That command only works in chats, not IMs."), | |
132 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15818 | 133 else |
15823 | 134 purple_conversation_write(conv, "", _("That command only works in IMs, not chats."), |
135 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15818 | 136 break; |
15823 | 137 case PURPLE_CMD_STATUS_WRONG_PRPL: |
138 purple_conversation_write(conv, "", _("That command doesn't work on this protocol."), | |
139 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15818 | 140 break; |
141 } | |
142 g_free(error); | |
143 } | |
144 else | |
145 { | |
146 char *escape = g_markup_escape_text(text, -1); | |
15823 | 147 char *apos = purple_strreplace(escape, "'", "'"); |
15818 | 148 g_free(escape); |
149 escape = apos; | |
15823 | 150 switch (purple_conversation_get_type(ggconv->active_conv)) |
15818 | 151 { |
15823 | 152 case PURPLE_CONV_TYPE_IM: |
153 purple_conv_im_send_with_flags(PURPLE_CONV_IM(ggconv->active_conv), escape, PURPLE_MESSAGE_SEND); | |
15818 | 154 break; |
15823 | 155 case PURPLE_CONV_TYPE_CHAT: |
156 purple_conv_chat_send(PURPLE_CONV_CHAT(ggconv->active_conv), escape); | |
15818 | 157 break; |
158 default: | |
159 g_free(escape); | |
160 g_return_val_if_reached(FALSE); | |
161 } | |
162 g_free(escape); | |
15823 | 163 purple_idle_touch(); |
15818 | 164 } |
165 gnt_entry_add_to_history(GNT_ENTRY(ggconv->entry), text); | |
166 gnt_entry_clear(GNT_ENTRY(ggconv->entry)); | |
167 return TRUE; | |
168 } | |
169 | |
170 return FALSE; | |
171 } | |
172 | |
173 static void | |
174 closing_window(GntWidget *window, FinchConv *ggconv) | |
175 { | |
176 GList *list = ggconv->list; | |
177 ggconv->window = NULL; | |
178 while (list) { | |
15823 | 179 PurpleConversation *conv = list->data; |
15818 | 180 list = list->next; |
15823 | 181 purple_conversation_destroy(conv); |
15818 | 182 } |
183 } | |
184 | |
185 static void | |
186 size_changed_cb(GntWidget *widget, int width, int height) | |
187 { | |
188 int w, h; | |
189 gnt_widget_get_size(widget, &w, &h); | |
15823 | 190 purple_prefs_set_int(PREF_ROOT "/size/width", w); |
191 purple_prefs_set_int(PREF_ROOT "/size/height", h); | |
15818 | 192 } |
193 | |
194 static void | |
195 save_position_cb(GntWidget *w, int x, int y) | |
196 { | |
15823 | 197 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
198 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15818 | 199 } |
200 | |
15823 | 201 static PurpleConversation * |
202 find_conv_with_contact(PurpleConversation *conv) | |
15818 | 203 { |
15823 | 204 PurpleBlistNode *node; |
205 PurpleBuddy *buddy = purple_find_buddy(conv->account, conv->name); | |
206 PurpleConversation *ret = NULL; | |
15818 | 207 |
208 if (!buddy) | |
209 return NULL; | |
210 | |
15823 | 211 for (node = ((PurpleBlistNode*)buddy)->parent->child; node; node = node->next) { |
212 if (node == (PurpleBlistNode*)buddy) | |
15818 | 213 continue; |
15823 | 214 if ((ret = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
215 ((PurpleBuddy*)node)->name, ((PurpleBuddy*)node)->account)) != NULL) | |
15818 | 216 break; |
217 } | |
218 return ret; | |
219 } | |
220 | |
221 static char * | |
15823 | 222 get_conversation_title(PurpleConversation *conv, PurpleAccount *account) |
15818 | 223 { |
15823 | 224 return g_strdup_printf(_("%s (%s -- %s)"), purple_conversation_get_title(conv), |
225 purple_account_get_username(account), purple_account_get_protocol_name(account)); | |
15818 | 226 } |
227 | |
228 static void | |
15823 | 229 update_buddy_typing(PurpleAccount *account, const char *who, gpointer null) |
15818 | 230 { |
15823 | 231 PurpleConversation *conv; |
15818 | 232 FinchConv *ggc; |
15823 | 233 PurpleConvIm *im = NULL; |
15818 | 234 char *title, *str; |
235 | |
15823 | 236 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account); |
15818 | 237 |
238 if (!conv) | |
239 return; | |
240 | |
15823 | 241 im = PURPLE_CONV_IM(conv); |
15818 | 242 ggc = conv->ui_data; |
243 | |
15823 | 244 if (purple_conv_im_get_typing_state(im) == PURPLE_TYPING) { |
15818 | 245 int scroll; |
246 str = get_conversation_title(conv, account); | |
247 title = g_strdup_printf(_("%s [%s]"), str, | |
248 gnt_ascii_only() ? "T" : "\342\243\277"); | |
249 g_free(str); | |
250 | |
251 scroll = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggc->tv)); | |
15823 | 252 str = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15818 | 253 /* Updating is a little buggy. So just remove and add a new one */ |
254 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE); | |
255 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggc->tv), | |
256 str, GNT_TEXT_FLAG_DIM, "typing"); | |
257 g_free(str); | |
258 if (scroll <= 1) | |
259 gnt_text_view_scroll(GNT_TEXT_VIEW(ggc->tv), 0); | |
260 } else { | |
261 title = get_conversation_title(conv, account); | |
262 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE); | |
263 } | |
264 gnt_screen_rename_widget(ggc->window, title); | |
265 g_free(title); | |
266 } | |
267 | |
17032
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
268 static void |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
269 chat_left_cb(PurpleConversation *conv, gpointer null) |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
270 { |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
271 finch_write_common(conv, NULL, _("You have left this chat."), |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
272 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
273 } |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
274 |
15818 | 275 static gpointer |
276 finch_conv_get_handle() | |
277 { | |
278 static int handle; | |
279 return &handle; | |
280 } | |
281 | |
282 static void | |
16903 | 283 clear_scrollback_cb(GntMenuItem *item, gpointer ggconv) |
284 { | |
285 FinchConv *ggc = ggconv; | |
286 gnt_text_view_clear(GNT_TEXT_VIEW(ggc->tv)); | |
287 } | |
288 | |
289 static void | |
290 send_file_cb(GntMenuItem *item, gpointer ggconv) | |
291 { | |
292 FinchConv *ggc = ggconv; | |
293 serv_send_file(purple_conversation_get_gc(ggc->active_conv), | |
294 purple_conversation_get_name(ggc->active_conv), NULL); | |
295 } | |
296 | |
297 static void | |
298 add_pounce_cb(GntMenuItem *item, gpointer ggconv) | |
299 { | |
300 FinchConv *ggc = ggconv; | |
301 finch_pounce_editor_show( | |
302 purple_conversation_get_account(ggc->active_conv), | |
303 purple_conversation_get_name(ggc->active_conv), NULL); | |
304 } | |
305 | |
306 static void | |
307 get_info_cb(GntMenuItem *item, gpointer ggconv) | |
308 { | |
309 FinchConv *ggc = ggconv; | |
17275
319bcb73eb4e
Use utility functions to get user info. Closes #964.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
310 finch_retrieve_user_info(purple_conversation_get_gc(ggc->active_conv), |
16903 | 311 purple_conversation_get_name(ggc->active_conv)); |
312 } | |
313 | |
314 static void | |
315 toggle_timestamps_cb(GntMenuItem *item, gpointer ggconv) | |
316 { | |
317 purple_prefs_set_bool(PREF_ROOT "/timestamps", | |
318 !purple_prefs_get_bool(PREF_ROOT "/timestamps")); | |
319 } | |
320 | |
321 static void | |
322 send_to_cb(GntMenuItem *m, gpointer n) | |
323 { | |
324 PurpleAccount *account = g_object_get_data(G_OBJECT(m), "purple_account"); | |
325 gchar *buddy = g_object_get_data(G_OBJECT(m), "purple_buddy_name"); | |
326 PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, buddy); | |
327 finch_conversation_set_active(conv); | |
328 } | |
329 | |
330 static void | |
331 generate_send_to_menu(FinchConv *ggc) | |
332 { | |
333 GntWidget *sub, *menu = ggc->menu; | |
334 GntMenuItem *item; | |
335 GSList *buds; | |
336 GList *list = NULL; | |
337 | |
338 buds = purple_find_buddies(ggc->active_conv->account, ggc->active_conv->name); | |
339 if (!buds) | |
340 return; | |
341 | |
342 item = gnt_menuitem_new(_("Send To")); | |
343 gnt_menu_add_item(GNT_MENU(menu), item); | |
344 sub = gnt_menu_new(GNT_MENU_POPUP); | |
345 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
346 | |
347 for (; buds; buds = buds->next) { | |
348 PurpleBlistNode *node = (PurpleBlistNode *)purple_buddy_get_contact((PurpleBuddy *)buds->data); | |
349 for (node = node->child; node != NULL; node = node->next) { | |
350 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
351 PurpleAccount *account = purple_buddy_get_account(buddy); | |
352 if (purple_account_is_connected(account)) { | |
353 /* Use the PurplePresence to get unique buddies. */ | |
354 PurplePresence *presence = purple_buddy_get_presence(buddy); | |
355 if (!g_list_find(list, presence)) | |
356 list = g_list_prepend(list, presence); | |
357 } | |
358 } | |
359 } | |
360 for (list = g_list_last(list); list != NULL; list = list->prev) { | |
361 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
|
362 PurpleBuddy *buddy = purple_presence_get_buddy(pre); |
16903 | 363 PurpleAccount *account = purple_buddy_get_account(buddy); |
364 gchar *name = g_strdup(purple_buddy_get_name(buddy)); | |
365 gchar *text = g_strdup_printf("%s (%s)", purple_buddy_get_name(buddy), purple_account_get_username(account)); | |
366 item = gnt_menuitem_new(text); | |
367 g_free(text); | |
368 gnt_menu_add_item(GNT_MENU(sub), item); | |
369 gnt_menuitem_set_callback(item, send_to_cb, NULL); | |
370 g_object_set_data(G_OBJECT(item), "purple_account", account); | |
371 g_object_set_data_full(G_OBJECT(item), "purple_buddy_name", name, g_free); | |
372 } | |
373 g_list_free(list); | |
374 g_slist_free(buds); | |
375 } | |
376 | |
377 static void | |
378 gg_create_menu(FinchConv *ggc) | |
379 { | |
380 GntWidget *menu, *sub; | |
381 GntMenuItem *item; | |
382 | |
383 ggc->menu = menu = gnt_menu_new(GNT_MENU_TOPLEVEL); | |
384 gnt_window_set_menu(GNT_WINDOW(ggc->window), GNT_MENU(menu)); | |
385 | |
386 item = gnt_menuitem_new(_("Conversation")); | |
387 gnt_menu_add_item(GNT_MENU(menu), item); | |
388 | |
389 sub = gnt_menu_new(GNT_MENU_POPUP); | |
390 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
391 | |
392 item = gnt_menuitem_new(_("Clear Scrollback")); | |
393 gnt_menu_add_item(GNT_MENU(sub), item); | |
394 gnt_menuitem_set_callback(item, clear_scrollback_cb, ggc); | |
395 | |
396 item = gnt_menuitem_check_new(_("Show Timestamps")); | |
397 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), | |
398 purple_prefs_get_bool(PREF_ROOT "/timestamps")); | |
399 gnt_menu_add_item(GNT_MENU(sub), item); | |
400 gnt_menuitem_set_callback(item, toggle_timestamps_cb, ggc); | |
401 | |
402 if (purple_conversation_get_type(ggc->active_conv) == PURPLE_CONV_TYPE_IM) { | |
16969
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:
16941
diff
changeset
|
403 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:
16941
diff
changeset
|
404 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:
16941
diff
changeset
|
405 |
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:
16941
diff
changeset
|
406 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:
16941
diff
changeset
|
407 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:
16941
diff
changeset
|
408 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:
16941
diff
changeset
|
409 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:
16941
diff
changeset
|
410 } |
16903 | 411 |
412 item = gnt_menuitem_new(_("Add Buddy Pounce...")); | |
413 gnt_menu_add_item(GNT_MENU(sub), item); | |
414 gnt_menuitem_set_callback(item, add_pounce_cb, ggc); | |
415 | |
16969
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:
16941
diff
changeset
|
416 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:
16941
diff
changeset
|
417 (!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:
16941
diff
changeset
|
418 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:
16941
diff
changeset
|
419 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:
16941
diff
changeset
|
420 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:
16941
diff
changeset
|
421 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:
16941
diff
changeset
|
422 } |
16903 | 423 |
424 generate_send_to_menu(ggc); | |
425 } | |
426 } | |
427 | |
428 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
|
429 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
|
430 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
435 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
436 static void |
18100
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
437 gained_focus_cb(GntWindow *window, FinchConv *fc) |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
438 { |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
439 GList *iter; |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
440 for (iter = fc->list; iter; iter = iter->next) { |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
441 purple_conversation_set_data(iter->data, "unseen-count", 0); |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
442 purple_conversation_update(iter->data, PURPLE_CONV_UPDATE_UNSEEN); |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
443 } |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
444 } |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
445 |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
446 static void |
18383
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
447 completion_cb(GntEntry *entry, const char *start, const char *end) |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
448 { |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
449 if (start == entry->start) |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
450 gnt_widget_key_pressed(GNT_WIDGET(entry), ": "); |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
451 } |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
452 |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
453 static void |
15823 | 454 finch_create_conversation(PurpleConversation *conv) |
15818 | 455 { |
456 FinchConv *ggc = conv->ui_data; | |
457 char *title; | |
15823 | 458 PurpleConversationType type; |
459 PurpleConversation *cc; | |
460 PurpleAccount *account; | |
15818 | 461 |
462 if (ggc) | |
463 return; | |
464 | |
465 cc = find_conv_with_contact(conv); | |
466 if (cc && cc->ui_data) | |
467 ggc = cc->ui_data; | |
468 else | |
469 ggc = g_new0(FinchConv, 1); | |
470 | |
471 ggc->list = g_list_prepend(ggc->list, conv); | |
472 ggc->active_conv = conv; | |
473 conv->ui_data = ggc; | |
474 | |
475 if (cc && cc->ui_data) { | |
476 finch_conversation_set_active(conv); | |
477 return; | |
478 } | |
479 | |
15823 | 480 account = purple_conversation_get_account(conv); |
481 type = purple_conversation_get_type(conv); | |
15818 | 482 title = get_conversation_title(conv, account); |
483 | |
16903 | 484 ggc->window = gnt_vwindow_new(FALSE); |
15818 | 485 gnt_box_set_title(GNT_BOX(ggc->window), title); |
486 gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); | |
487 gnt_box_set_pad(GNT_BOX(ggc->window), 0); | |
18232
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
488 |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
489 switch(conv->type){ |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
490 case PURPLE_CONV_TYPE_UNKNOWN: |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
491 gnt_widget_set_name(ggc->window, "conversation-window-unknown" ); |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
492 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
493 case PURPLE_CONV_TYPE_IM: |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
494 gnt_widget_set_name(ggc->window, "conversation-window-im" ); |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
495 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
496 case PURPLE_CONV_TYPE_CHAT: |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
497 gnt_widget_set_name(ggc->window, "conversation-window-chat" ); |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
498 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
499 case PURPLE_CONV_TYPE_MISC: |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
500 gnt_widget_set_name(ggc->window, "conversation-window-misc" ); |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
501 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
502 case PURPLE_CONV_TYPE_ANY: |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
503 gnt_widget_set_name(ggc->window, "conversation-window-any" ); |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
504 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
505 } |
15818 | 506 |
16903 | 507 gg_create_menu(ggc); |
508 | |
15818 | 509 ggc->tv = gnt_text_view_new(); |
510 gnt_widget_set_name(ggc->tv, "conversation-window-textview"); | |
15823 | 511 gnt_widget_set_size(ggc->tv, purple_prefs_get_int(PREF_ROOT "/size/width"), |
512 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
15818 | 513 |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
514 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
|
515 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
|
516 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
|
517 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
|
518 gnt_box_set_pad(GNT_BOX(hbox), 0); |
17083
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
519 tree = fc->userlist = gnt_tree_new_with_columns(2); |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
520 gnt_tree_set_col_width(GNT_TREE(tree), 0, 1); /* The flag column */ |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
521 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 } else { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
530 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
|
531 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
532 |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
533 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
|
534 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
|
535 |
15818 | 536 ggc->entry = gnt_entry_new(NULL); |
537 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry); | |
538 gnt_widget_set_name(ggc->entry, "conversation-window-entry"); | |
539 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1); | |
540 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE); | |
541 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE); | |
542 | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
543 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(ggc->tv), ggc->entry); |
15818 | 544 g_signal_connect_after(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc); |
18383
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
545 g_signal_connect(G_OBJECT(ggc->entry), "completion", G_CALLBACK(completion_cb), NULL); |
15818 | 546 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); |
547 | |
15823 | 548 gnt_widget_set_position(ggc->window, purple_prefs_get_int(PREF_ROOT "/position/x"), |
549 purple_prefs_get_int(PREF_ROOT "/position/y")); | |
15818 | 550 gnt_widget_show(ggc->window); |
551 | |
552 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL); | |
553 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL); | |
554 | |
15823 | 555 if (type == PURPLE_CONV_TYPE_IM) { |
15818 | 556 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc); |
557 } | |
558 | |
559 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
|
560 gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry); |
18100
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
561 g_signal_connect(G_OBJECT(ggc->window), "gained-focus", G_CALLBACK(gained_focus_cb), ggc); |
15818 | 562 } |
563 | |
564 static void | |
15823 | 565 finch_destroy_conversation(PurpleConversation *conv) |
15818 | 566 { |
567 /* do stuff here */ | |
568 FinchConv *ggc = conv->ui_data; | |
569 ggc->list = g_list_remove(ggc->list, conv); | |
570 if (ggc->list && conv == ggc->active_conv) | |
571 ggc->active_conv = ggc->list->data; | |
572 | |
573 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
|
574 g_free(ggc->u.chat); |
18222
ef65d43190e5
Fix a few runtime warnings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
575 if (ggc->window) |
ef65d43190e5
Fix a few runtime warnings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
576 gnt_widget_destroy(ggc->window); |
15818 | 577 g_free(ggc); |
578 } | |
579 } | |
580 | |
581 static void | |
15823 | 582 finch_write_common(PurpleConversation *conv, const char *who, const char *message, |
583 PurpleMessageFlags flags, time_t mtime) | |
15818 | 584 { |
585 FinchConv *ggconv = conv->ui_data; | |
586 char *strip, *newline; | |
587 GntTextFormatFlags fl = 0; | |
588 int pos; | |
589 gboolean notify; | |
590 | |
591 g_return_if_fail(ggconv != NULL); | |
592 | |
593 if (ggconv->active_conv != conv) { | |
15823 | 594 if (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV)) |
15818 | 595 finch_conversation_set_active(conv); |
596 else | |
597 return; | |
598 } | |
599 | |
600 pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggconv->tv)); | |
601 | |
602 notify = !!gnt_text_view_tag_change(GNT_TEXT_VIEW(ggconv->tv), "typing", NULL, TRUE); | |
603 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), "\n", GNT_TEXT_FLAG_NORMAL); | |
604 | |
605 /* 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
|
606 if (purple_prefs_get_bool("/finch/conversations/timestamps")) |
15818 | 607 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
15823 | 608 purple_utf8_strftime("(%H:%M:%S) ", localtime(&mtime)), GNT_TEXT_FLAG_DIM); |
15818 | 609 |
15823 | 610 if (flags & PURPLE_MESSAGE_AUTO_RESP) |
15818 | 611 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
612 _("<AUTO-REPLY> "), GNT_TEXT_FLAG_BOLD); | |
613 | |
15823 | 614 if (who && *who && (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV))) |
15818 | 615 { |
616 char * name = NULL; | |
617 | |
15823 | 618 if (purple_message_meify((char*)message, -1)) |
15818 | 619 name = g_strdup_printf("*** %s ", who); |
620 else | |
621 name = g_strdup_printf("%s: ", who); | |
622 | |
623 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
624 name, GNT_TEXT_FLAG_BOLD); | |
625 g_free(name); | |
626 } | |
627 else | |
628 fl = GNT_TEXT_FLAG_DIM; | |
629 | |
15823 | 630 if (flags & PURPLE_MESSAGE_ERROR) |
15818 | 631 fl |= GNT_TEXT_FLAG_BOLD; |
15823 | 632 if (flags & PURPLE_MESSAGE_NICK) |
15818 | 633 fl |= GNT_TEXT_FLAG_UNDERLINE; |
634 | |
635 /* XXX: Remove this workaround when textview can parse messages. */ | |
15823 | 636 newline = purple_strdup_withhtml(message); |
637 strip = purple_markup_strip_html(newline); | |
15818 | 638 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
639 strip, fl); | |
640 | |
641 g_free(newline); | |
642 g_free(strip); | |
643 | |
644 if (notify) { | |
15823 | 645 strip = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15818 | 646 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggconv->tv), |
647 strip, GNT_TEXT_FLAG_DIM, "typing"); | |
648 g_free(strip); | |
649 } | |
650 | |
651 if (pos <= 1) | |
652 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); | |
653 | |
15823 | 654 if (flags & (PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_NICK | PURPLE_MESSAGE_ERROR)) |
15818 | 655 gnt_widget_set_urgent(ggconv->tv); |
18100
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
656 if (flags & PURPLE_MESSAGE_RECV && !gnt_widget_has_focus(ggconv->window)) { |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
657 int count = GPOINTER_TO_INT(purple_conversation_get_data(conv, "unseen-count")); |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
658 purple_conversation_set_data(conv, "unseen-count", GINT_TO_POINTER(count + 1)); |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
659 purple_conversation_update(conv, PURPLE_CONV_UPDATE_UNSEEN); |
f63b3a23280d
Provide a 'unseen-count' data for the conversations so the dbus-docklet can use that information.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17529
diff
changeset
|
660 } |
15818 | 661 } |
662 | |
663 static void | |
15823 | 664 finch_write_chat(PurpleConversation *conv, const char *who, const char *message, |
665 PurpleMessageFlags flags, time_t mtime) | |
15818 | 666 { |
15823 | 667 purple_conversation_write(conv, who, message, flags, mtime); |
15818 | 668 } |
669 | |
670 static void | |
15823 | 671 finch_write_im(PurpleConversation *conv, const char *who, const char *message, |
672 PurpleMessageFlags flags, time_t mtime) | |
15818 | 673 { |
15823 | 674 PurpleAccount *account = purple_conversation_get_account(conv); |
675 if (flags & PURPLE_MESSAGE_SEND) | |
15818 | 676 { |
15823 | 677 who = purple_connection_get_display_name(purple_account_get_connection(account)); |
15818 | 678 if (!who) |
15823 | 679 who = purple_account_get_alias(account); |
15818 | 680 if (!who) |
15823 | 681 who = purple_account_get_username(account); |
15818 | 682 } |
15823 | 683 else if (flags & PURPLE_MESSAGE_RECV) |
15818 | 684 { |
15823 | 685 PurpleBuddy *buddy; |
686 who = purple_conversation_get_name(conv); | |
687 buddy = purple_find_buddy(account, who); | |
15818 | 688 if (buddy) |
15823 | 689 who = purple_buddy_get_contact_alias(buddy); |
15818 | 690 } |
691 | |
15823 | 692 purple_conversation_write(conv, who, message, flags, mtime); |
15818 | 693 } |
694 | |
695 static void | |
15823 | 696 finch_write_conv(PurpleConversation *conv, const char *who, const char *alias, |
697 const char *message, PurpleMessageFlags flags, time_t mtime) | |
15818 | 698 { |
699 const char *name; | |
700 if (alias && *alias) | |
701 name = alias; | |
702 else if (who && *who) | |
703 name = who; | |
704 else | |
705 name = NULL; | |
706 | |
707 finch_write_common(conv, name, message, flags, mtime); | |
708 } | |
709 | |
17083
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
710 static const char * |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
711 chat_flag_text(PurpleConvChatBuddyFlags flags) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
712 { |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
713 if (flags & PURPLE_CBFLAGS_FOUNDER) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
714 return "~"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
715 if (flags & PURPLE_CBFLAGS_OP) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
716 return "@"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
717 if (flags & PURPLE_CBFLAGS_HALFOP) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
718 return "%"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
719 if (flags & PURPLE_CBFLAGS_VOICE) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
720 return "+"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
721 return " "; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
722 } |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
723 |
15818 | 724 static void |
15823 | 725 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals) |
15818 | 726 { |
727 FinchConv *ggc = conv->ui_data; | |
728 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
729 | |
730 if (!new_arrivals) | |
731 { | |
732 /* Print the list of users in the room */ | |
733 GString *string = g_string_new(_("List of users:\n")); | |
734 GList *iter; | |
735 | |
736 for (iter = users; iter; iter = iter->next) | |
737 { | |
15823 | 738 PurpleConvChatBuddy *cbuddy = iter->data; |
15818 | 739 char *str; |
740 | |
741 if ((str = cbuddy->alias) == NULL) | |
742 str = cbuddy->name; | |
743 g_string_append_printf(string, "[ %s ]", str); | |
744 } | |
745 | |
15823 | 746 purple_conversation_write(conv, NULL, string->str, |
747 PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
15818 | 748 g_string_free(string, TRUE); |
749 } | |
750 | |
751 for (; users; users = users->next) | |
752 { | |
15823 | 753 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
|
754 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15818 | 755 gnt_entry_add_suggest(entry, cbuddy->name); |
756 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
|
757 gnt_tree_add_row_after(tree, g_strdup(cbuddy->name), |
17083
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
758 gnt_tree_create_row(tree, chat_flag_text(cbuddy->flags), cbuddy->alias), NULL, NULL); |
15818 | 759 } |
760 } | |
761 | |
762 static void | |
15823 | 763 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a) |
15818 | 764 { |
765 /* Update the name for string completion */ | |
766 FinchConv *ggc = conv->ui_data; | |
767 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
|
768 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
17083
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
769 PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), new_n); |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
770 |
15818 | 771 gnt_entry_remove_suggest(entry, old); |
17083
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
772 gnt_tree_remove(tree, (gpointer)old); |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
773 |
15818 | 774 gnt_entry_add_suggest(entry, new_n); |
775 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
|
776 gnt_tree_add_row_after(tree, g_strdup(new_n), |
17083
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
777 gnt_tree_create_row(tree, chat_flag_text(cb->flags), new_a), NULL, NULL); |
15818 | 778 } |
779 | |
780 static void | |
17104
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
781 finch_chat_remove_users(PurpleConversation *conv, GList *list) |
15818 | 782 { |
783 /* Remove the name from string completion */ | |
784 FinchConv *ggc = conv->ui_data; | |
785 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
|
786 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
|
787 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15818 | 788 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
|
789 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
|
790 } |
15818 | 791 } |
792 | |
793 static void | |
15823 | 794 finch_chat_update_user(PurpleConversation *conv, const char *user) |
15818 | 795 { |
17083
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
796 PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), user); |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
797 FinchConv *ggc = conv->ui_data; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17032
diff
changeset
|
798 gnt_tree_change_text(GNT_TREE(ggc->u.chat->userlist), (gpointer)user, 0, chat_flag_text(cb->flags)); |
15818 | 799 } |
800 | |
15823 | 801 static PurpleConversationUiOps conv_ui_ops = |
15818 | 802 { |
17104
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
803 finch_create_conversation, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
804 finch_destroy_conversation, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
805 finch_write_chat, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
806 finch_write_im, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
807 finch_write_conv, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
808 finch_chat_add_users, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
809 finch_chat_rename_user, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
810 finch_chat_remove_users, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
811 finch_chat_update_user, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
812 NULL, /* present */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
813 NULL, /* has_focus */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
814 NULL, /* custom_smiley_add */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
815 NULL, /* custom_smiley_write */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
816 NULL, /* custom_smiley_close */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
817 NULL, /* send_confirm */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
818 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
819 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
820 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17083
diff
changeset
|
821 NULL |
15818 | 822 }; |
823 | |
15823 | 824 PurpleConversationUiOps *finch_conv_get_ui_ops() |
15818 | 825 { |
826 return &conv_ui_ops; | |
827 } | |
828 | |
829 /* Xerox */ | |
15823 | 830 static PurpleCmdRet |
831 say_command_cb(PurpleConversation *conv, | |
15818 | 832 const char *cmd, char **args, char **error, void *data) |
833 { | |
15823 | 834 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
835 purple_conv_im_send(PURPLE_CONV_IM(conv), args[0]); | |
836 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
837 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), args[0]); | |
15818 | 838 |
15823 | 839 return PURPLE_CMD_RET_OK; |
15818 | 840 } |
841 | |
842 /* Xerox */ | |
15823 | 843 static PurpleCmdRet |
844 me_command_cb(PurpleConversation *conv, | |
15818 | 845 const char *cmd, char **args, char **error, void *data) |
846 { | |
847 char *tmp; | |
848 | |
849 tmp = g_strdup_printf("/me %s", args[0]); | |
850 | |
15823 | 851 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
852 purple_conv_im_send(PURPLE_CONV_IM(conv), tmp); | |
853 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
854 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), tmp); | |
15818 | 855 |
856 g_free(tmp); | |
15823 | 857 return PURPLE_CMD_RET_OK; |
15818 | 858 } |
859 | |
860 /* Xerox */ | |
15823 | 861 static PurpleCmdRet |
862 debug_command_cb(PurpleConversation *conv, | |
15818 | 863 const char *cmd, char **args, char **error, void *data) |
864 { | |
865 char *tmp, *markup; | |
15823 | 866 PurpleCmdStatus status; |
15818 | 867 |
868 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
|
869 tmp = g_strdup_printf("me is using Finch v%s.", VERSION); |
15818 | 870 markup = g_markup_escape_text(tmp, -1); |
871 | |
15823 | 872 status = purple_cmd_do_command(conv, tmp, markup, error); |
15818 | 873 |
874 g_free(tmp); | |
875 g_free(markup); | |
876 return status; | |
877 } else { | |
15823 | 878 purple_conversation_write(conv, NULL, _("Supported debug options are: version"), |
879 PURPLE_MESSAGE_NO_LOG|PURPLE_MESSAGE_ERROR, time(NULL)); | |
880 return PURPLE_CMD_STATUS_OK; | |
15818 | 881 } |
882 } | |
883 | |
884 /* Xerox */ | |
15823 | 885 static PurpleCmdRet |
886 clear_command_cb(PurpleConversation *conv, | |
15818 | 887 const char *cmd, char **args, char **error, void *data) |
888 { | |
889 FinchConv *ggconv = conv->ui_data; | |
890 gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv)); | |
15823 | 891 return PURPLE_CMD_STATUS_OK; |
15818 | 892 } |
893 | |
894 /* Xerox */ | |
15823 | 895 static PurpleCmdRet |
896 help_command_cb(PurpleConversation *conv, | |
15818 | 897 const char *cmd, char **args, char **error, void *data) |
898 { | |
899 GList *l, *text; | |
900 GString *s; | |
901 | |
902 if (args[0] != NULL) { | |
903 s = g_string_new(""); | |
15823 | 904 text = purple_cmd_help(conv, args[0]); |
15818 | 905 |
906 if (text) { | |
907 for (l = text; l; l = l->next) | |
908 if (l->next) | |
909 g_string_append_printf(s, "%s\n", (char *)l->data); | |
910 else | |
911 g_string_append_printf(s, "%s", (char *)l->data); | |
912 } else { | |
913 g_string_append(s, _("No such command (in this context).")); | |
914 } | |
915 } else { | |
916 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" | |
917 "The following commands are available in this context:\n")); | |
918 | |
15823 | 919 text = purple_cmd_list(conv); |
15818 | 920 for (l = text; l; l = l->next) |
921 if (l->next) | |
922 g_string_append_printf(s, "%s, ", (char *)l->data); | |
923 else | |
924 g_string_append_printf(s, "%s.", (char *)l->data); | |
925 g_list_free(text); | |
926 } | |
927 | |
15823 | 928 purple_conversation_write(conv, NULL, s->str, PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15818 | 929 g_string_free(s, TRUE); |
930 | |
15823 | 931 return PURPLE_CMD_STATUS_OK; |
15818 | 932 } |
933 | |
15823 | 934 static PurpleCmdRet |
935 cmd_show_window(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) | |
15818 | 936 { |
937 void (*callback)() = data; | |
938 callback(); | |
15823 | 939 return PURPLE_CMD_STATUS_OK; |
15818 | 940 } |
941 | |
16904
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
942 static PurpleCmdRet |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
943 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
|
944 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
945 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
|
946 FinchConvChat *ch; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
947 if (!fc) |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
948 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
|
949 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
950 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
|
951 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
|
952 (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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16903
diff
changeset
|
958 |
15818 | 959 void finch_conversation_init() |
960 { | |
15823 | 961 purple_prefs_add_none(PREF_ROOT); |
962 purple_prefs_add_none(PREF_ROOT "/size"); | |
963 purple_prefs_add_int(PREF_ROOT "/size/width", 70); | |
964 purple_prefs_add_int(PREF_ROOT "/size/height", 20); | |
965 purple_prefs_add_none(PREF_ROOT "/position"); | |
966 purple_prefs_add_int(PREF_ROOT "/position/x", 0); | |
967 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
|
968 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
|
969 purple_prefs_add_bool(PREF_USERLIST, FALSE); |
15818 | 970 |
971 /* Xerox the commands */ | |
15823 | 972 purple_cmd_register("say", "S", PURPLE_CMD_P_DEFAULT, |
973 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 974 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); |
15823 | 975 purple_cmd_register("me", "S", PURPLE_CMD_P_DEFAULT, |
976 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 977 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); |
15823 | 978 purple_cmd_register("debug", "w", PURPLE_CMD_P_DEFAULT, |
979 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 980 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); |
15823 | 981 purple_cmd_register("clear", "", PURPLE_CMD_P_DEFAULT, |
982 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 983 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); |
15823 | 984 purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT, |
985 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, | |
15818 | 986 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
|
987 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
|
988 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
|
989 users_command_cb, _("users: Show the list of users in the chat."), NULL); |
15818 | 990 |
991 /* Now some commands to bring up some other windows */ | |
15823 | 992 purple_cmd_register("plugins", "", PURPLE_CMD_P_DEFAULT, |
993 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 994 cmd_show_window, _("plugins: Show the plugins window."), finch_plugins_show_all); |
15823 | 995 purple_cmd_register("buddylist", "", PURPLE_CMD_P_DEFAULT, |
996 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 997 cmd_show_window, _("buddylist: Show the buddylist."), finch_blist_show); |
15823 | 998 purple_cmd_register("accounts", "", PURPLE_CMD_P_DEFAULT, |
999 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 1000 cmd_show_window, _("accounts: Show the accounts window."), finch_accounts_show_all); |
15823 | 1001 purple_cmd_register("debugwin", "", PURPLE_CMD_P_DEFAULT, |
1002 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 1003 cmd_show_window, _("debugwin: Show the debug window."), finch_debug_window_show); |
15823 | 1004 purple_cmd_register("prefs", "", PURPLE_CMD_P_DEFAULT, |
1005 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 1006 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); |
15823 | 1007 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, |
1008 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15818 | 1009 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all); |
17032
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1010 |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1011 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(), |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1012 PURPLE_CALLBACK(update_buddy_typing), NULL); |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1013 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(), |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1014 PURPLE_CALLBACK(update_buddy_typing), NULL); |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1015 purple_signal_connect(purple_conversations_get_handle(), "chat-left", finch_conv_get_handle(), |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1016 PURPLE_CALLBACK(chat_left_cb), NULL); |
15818 | 1017 } |
1018 | |
1019 void finch_conversation_uninit() | |
1020 { | |
17032
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16989
diff
changeset
|
1021 purple_signals_disconnect_by_handle(finch_conv_get_handle()); |
15818 | 1022 } |
1023 | |
15823 | 1024 void finch_conversation_set_active(PurpleConversation *conv) |
15818 | 1025 { |
1026 FinchConv *ggconv = conv->ui_data; | |
15823 | 1027 PurpleAccount *account; |
15818 | 1028 char *title; |
1029 | |
1030 g_return_if_fail(ggconv); | |
1031 g_return_if_fail(g_list_find(ggconv->list, conv)); | |
1032 | |
1033 ggconv->active_conv = conv; | |
15823 | 1034 account = purple_conversation_get_account(conv); |
15818 | 1035 title = get_conversation_title(conv, account); |
1036 gnt_screen_rename_widget(ggconv->window, title); | |
1037 g_free(title); | |
1038 } | |
1039 | |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1040 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
|
1041 { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1042 FinchConv *fc = conv->ui_data; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1043 int height, width; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1044 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1045 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
|
1046 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1047 if (widget) { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1048 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
|
1049 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
|
1050 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1051 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1057 |