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