Mercurial > pidgin
annotate finch/gntconv.c @ 19770:ebf4fe12ad10
merge of '568fa1d06eec5b85c215976c97bba59da8c139a7'
and 'b5d08ea2ffcf40d88397c533814778a4675f6cf5'
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 12 Sep 2007 13:00:42 +0000 |
parents | 44b4e8bd759b |
children | 959b3aaba0b6 |
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 | |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19632
diff
changeset
|
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15817 | 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" | |
19447
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
40 #include "gntsound.h" |
15817 | 41 #include "gntstatus.h" |
16892 | 42 #include "gntpounce.h" |
15817 | 43 |
44 #include "gnt.h" | |
45 #include "gntbox.h" | |
46 #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
|
47 #include "gntlabel.h" |
16892 | 48 #include "gntmenu.h" |
49 #include "gntmenuitem.h" | |
50 #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
|
51 #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
|
52 #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
|
53 #include "gntutils.h" |
16892 | 54 #include "gntwindow.h" |
15817 | 55 |
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
|
56 #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
|
57 #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
|
58 #define PREF_USERLIST PREF_CHAT "/userlist" |
15817 | 59 |
60 #include "config.h" | |
61 | |
17021
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16978
diff
changeset
|
62 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
|
63 const char *message, PurpleMessageFlags flags, time_t mtime); |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
64 static void generate_send_to_menu(FinchConv *ggc); |
17021
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16978
diff
changeset
|
65 |
15817 | 66 static void |
67 send_typing_notification(GntWidget *w, FinchConv *ggconv) | |
68 { | |
69 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
|
70 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
|
71 if (purple_prefs_get_bool("/finch/conversations/notify_typing")) { |
15822 | 72 PurpleConversation *conv = ggconv->active_conv; |
73 PurpleConvIm *im = PURPLE_CONV_IM(conv); | |
15817 | 74 if (!empty) { |
15822 | 75 gboolean send = (purple_conv_im_get_send_typed_timeout(im) == 0); |
15817 | 76 |
15822 | 77 purple_conv_im_stop_send_typed_timeout(im); |
78 purple_conv_im_start_send_typed_timeout(im); | |
79 if (send || (purple_conv_im_get_type_again(im) != 0 && | |
80 time(NULL) > purple_conv_im_get_type_again(im))) { | |
15817 | 81 unsigned int timeout; |
15822 | 82 timeout = serv_send_typing(purple_conversation_get_gc(conv), |
83 purple_conversation_get_name(conv), | |
84 PURPLE_TYPING); | |
85 purple_conv_im_set_type_again(im, timeout); | |
15817 | 86 } |
87 } else { | |
15822 | 88 purple_conv_im_stop_send_typed_timeout(im); |
15817 | 89 |
15822 | 90 serv_send_typing(purple_conversation_get_gc(conv), |
91 purple_conversation_get_name(conv), | |
92 PURPLE_NOT_TYPING); | |
15817 | 93 } |
94 } | |
95 } | |
96 | |
97 static gboolean | |
98 entry_key_pressed(GntWidget *w, const char *key, FinchConv *ggconv) | |
99 { | |
100 if (key[0] == '\r' && key[1] == 0) | |
101 { | |
102 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); | |
103 if (*text == '/') | |
104 { | |
15822 | 105 PurpleConversation *conv = ggconv->active_conv; |
106 PurpleCmdStatus status; | |
15817 | 107 const char *cmdline = text + 1; |
108 char *error = NULL, *escape; | |
109 | |
110 escape = g_markup_escape_text(cmdline, -1); | |
15822 | 111 status = purple_cmd_do_command(conv, cmdline, escape, &error); |
15817 | 112 g_free(escape); |
113 | |
114 switch (status) | |
115 { | |
15822 | 116 case PURPLE_CMD_STATUS_OK: |
15817 | 117 break; |
15822 | 118 case PURPLE_CMD_STATUS_NOT_FOUND: |
119 purple_conversation_write(conv, "", _("No such command."), | |
120 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 121 break; |
15822 | 122 case PURPLE_CMD_STATUS_WRONG_ARGS: |
123 purple_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " | |
15817 | 124 "to that command."), |
15822 | 125 PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15817 | 126 break; |
15822 | 127 case PURPLE_CMD_STATUS_FAILED: |
128 purple_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), | |
129 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 130 break; |
15822 | 131 case PURPLE_CMD_STATUS_WRONG_TYPE: |
132 if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) | |
133 purple_conversation_write(conv, "", _("That command only works in chats, not IMs."), | |
134 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 135 else |
15822 | 136 purple_conversation_write(conv, "", _("That command only works in IMs, not chats."), |
137 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 138 break; |
15822 | 139 case PURPLE_CMD_STATUS_WRONG_PRPL: |
140 purple_conversation_write(conv, "", _("That command doesn't work on this protocol."), | |
141 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 142 break; |
143 } | |
144 g_free(error); | |
145 } | |
19370
9c03677be7c5
Notify the user if a message is not sent in a conversation because he's disconnected.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19321
diff
changeset
|
146 else if (!purple_account_is_connected(ggconv->active_conv->account)) |
9c03677be7c5
Notify the user if a message is not sent in a conversation because he's disconnected.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19321
diff
changeset
|
147 { |
9c03677be7c5
Notify the user if a message is not sent in a conversation because he's disconnected.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19321
diff
changeset
|
148 purple_conversation_write(ggconv->active_conv, "", _("Message was not sent, because you are not signed on."), |
9c03677be7c5
Notify the user if a message is not sent in a conversation because he's disconnected.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19321
diff
changeset
|
149 PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_NO_LOG, time(NULL)); |
9c03677be7c5
Notify the user if a message is not sent in a conversation because he's disconnected.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19321
diff
changeset
|
150 } |
15817 | 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 * |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
209 find_conv_with_contact(PurpleAccount *account, const char *name) |
15817 | 210 { |
15822 | 211 PurpleBlistNode *node; |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
212 PurpleBuddy *buddy = purple_find_buddy(account, name); |
15822 | 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); | |
18637
3597903cf8ff
Just show an empty line, instead of bouncing the text down when the user
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18427
diff
changeset
|
269 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", " ", TRUE); |
15817 | 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 |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
282 static void |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
283 buddy_signed_on_off(PurpleBuddy *buddy, gpointer null) |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
284 { |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
285 PurpleConversation *conv = find_conv_with_contact(buddy->account, buddy->name); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
286 if (conv == NULL) |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
287 return; |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
288 generate_send_to_menu(conv->ui_data); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
289 } |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
290 |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
291 static void |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
292 account_signed_on_off(PurpleConnection *gc, gpointer null) |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
293 { |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
294 GList *ims = purple_get_ims(); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
295 while (ims) { |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
296 PurpleConversation *conv = ims->data; |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
297 PurpleConversation *cc = find_conv_with_contact(conv->account, conv->name); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
298 if (cc) |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
299 generate_send_to_menu(cc->ui_data); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
300 ims = ims->next; |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
301 } |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
302 } |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
303 |
15817 | 304 static gpointer |
305 finch_conv_get_handle() | |
306 { | |
307 static int handle; | |
308 return &handle; | |
309 } | |
310 | |
311 static void | |
16892 | 312 clear_scrollback_cb(GntMenuItem *item, gpointer ggconv) |
313 { | |
314 FinchConv *ggc = ggconv; | |
315 gnt_text_view_clear(GNT_TEXT_VIEW(ggc->tv)); | |
316 } | |
317 | |
318 static void | |
319 send_file_cb(GntMenuItem *item, gpointer ggconv) | |
320 { | |
321 FinchConv *ggc = ggconv; | |
322 serv_send_file(purple_conversation_get_gc(ggc->active_conv), | |
323 purple_conversation_get_name(ggc->active_conv), NULL); | |
324 } | |
325 | |
326 static void | |
327 add_pounce_cb(GntMenuItem *item, gpointer ggconv) | |
328 { | |
329 FinchConv *ggc = ggconv; | |
330 finch_pounce_editor_show( | |
331 purple_conversation_get_account(ggc->active_conv), | |
332 purple_conversation_get_name(ggc->active_conv), NULL); | |
333 } | |
334 | |
335 static void | |
336 get_info_cb(GntMenuItem *item, gpointer ggconv) | |
337 { | |
338 FinchConv *ggc = ggconv; | |
17750
319bcb73eb4e
Use utility functions to get user info. Closes #964.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
339 finch_retrieve_user_info(purple_conversation_get_gc(ggc->active_conv), |
16892 | 340 purple_conversation_get_name(ggc->active_conv)); |
341 } | |
342 | |
343 static void | |
344 toggle_timestamps_cb(GntMenuItem *item, gpointer ggconv) | |
345 { | |
346 purple_prefs_set_bool(PREF_ROOT "/timestamps", | |
347 !purple_prefs_get_bool(PREF_ROOT "/timestamps")); | |
348 } | |
349 | |
350 static void | |
19445
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
351 toggle_logging_cb(GntMenuItem *item, gpointer ggconv) |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
352 { |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
353 FinchConv *fc = ggconv; |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
354 PurpleConversation *conv = fc->active_conv; |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
355 gboolean logging = gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item)); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
356 GList *iter; |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
357 |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
358 if (logging == purple_conversation_is_logging(conv)) |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
359 return; |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
360 |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
361 /* Xerox */ |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
362 if (logging) { |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
363 /* Enable logging first so the message below can be logged. */ |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
364 purple_conversation_set_logging(conv, TRUE); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
365 |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
366 purple_conversation_write(conv, NULL, |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
367 _("Logging started. Future messages in this conversation will be logged."), |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
368 conv->logs ? (PURPLE_MESSAGE_SYSTEM) : |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
369 (PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG), |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
370 time(NULL)); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
371 } else { |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
372 purple_conversation_write(conv, NULL, |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
373 _("Logging stopped. Future messages in this conversation will not be logged."), |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
374 conv->logs ? (PURPLE_MESSAGE_SYSTEM) : |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
375 (PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG), |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
376 time(NULL)); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
377 |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
378 /* Disable the logging second, so that the above message can be logged. */ |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
379 purple_conversation_set_logging(conv, FALSE); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
380 } |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
381 |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
382 /* Each conversation with the same person will have the same logging setting */ |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
383 for (iter = fc->list; iter; iter = iter->next) { |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
384 if (iter->data == conv) |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
385 continue; |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
386 purple_conversation_set_logging(iter->data, logging); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
387 } |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
388 } |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
389 |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
390 static void |
19447
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
391 toggle_sound_cb(GntMenuItem *item, gpointer ggconv) |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
392 { |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
393 FinchConv *fc = ggconv; |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
394 fc->flags ^= FINCH_CONV_NO_SOUND; |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
395 } |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
396 |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
397 static void |
16892 | 398 send_to_cb(GntMenuItem *m, gpointer n) |
399 { | |
400 PurpleAccount *account = g_object_get_data(G_OBJECT(m), "purple_account"); | |
401 gchar *buddy = g_object_get_data(G_OBJECT(m), "purple_buddy_name"); | |
402 PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, buddy); | |
403 finch_conversation_set_active(conv); | |
404 } | |
405 | |
406 static void | |
407 generate_send_to_menu(FinchConv *ggc) | |
408 { | |
409 GntWidget *sub, *menu = ggc->menu; | |
410 GntMenuItem *item; | |
411 GSList *buds; | |
412 GList *list = NULL; | |
413 | |
414 buds = purple_find_buddies(ggc->active_conv->account, ggc->active_conv->name); | |
415 if (!buds) | |
416 return; | |
417 | |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
418 if ((item = ggc->u.im->sendto) == NULL) { |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
419 item = gnt_menuitem_new(_("Send To")); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
420 gnt_menu_add_item(GNT_MENU(menu), item); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
421 ggc->u.im->sendto = item; |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
422 } |
16892 | 423 sub = gnt_menu_new(GNT_MENU_POPUP); |
424 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
425 | |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
426 for (; buds; buds = g_slist_delete_link(buds, buds)) { |
16892 | 427 PurpleBlistNode *node = (PurpleBlistNode *)purple_buddy_get_contact((PurpleBuddy *)buds->data); |
428 for (node = node->child; node != NULL; node = node->next) { | |
429 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
430 PurpleAccount *account = purple_buddy_get_account(buddy); | |
431 if (purple_account_is_connected(account)) { | |
432 /* Use the PurplePresence to get unique buddies. */ | |
433 PurplePresence *presence = purple_buddy_get_presence(buddy); | |
434 if (!g_list_find(list, presence)) | |
435 list = g_list_prepend(list, presence); | |
436 } | |
437 } | |
438 } | |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
439 for (list = g_list_reverse(list); list != NULL; list = g_list_delete_link(list, list)) { |
16892 | 440 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
|
441 PurpleBuddy *buddy = purple_presence_get_buddy(pre); |
16892 | 442 PurpleAccount *account = purple_buddy_get_account(buddy); |
443 gchar *name = g_strdup(purple_buddy_get_name(buddy)); | |
444 gchar *text = g_strdup_printf("%s (%s)", purple_buddy_get_name(buddy), purple_account_get_username(account)); | |
445 item = gnt_menuitem_new(text); | |
446 g_free(text); | |
447 gnt_menu_add_item(GNT_MENU(sub), item); | |
448 gnt_menuitem_set_callback(item, send_to_cb, NULL); | |
449 g_object_set_data(G_OBJECT(item), "purple_account", account); | |
450 g_object_set_data_full(G_OBJECT(item), "purple_buddy_name", name, g_free); | |
451 } | |
452 } | |
453 | |
454 static void | |
455 gg_create_menu(FinchConv *ggc) | |
456 { | |
457 GntWidget *menu, *sub; | |
458 GntMenuItem *item; | |
459 | |
460 ggc->menu = menu = gnt_menu_new(GNT_MENU_TOPLEVEL); | |
461 gnt_window_set_menu(GNT_WINDOW(ggc->window), GNT_MENU(menu)); | |
462 | |
463 item = gnt_menuitem_new(_("Conversation")); | |
464 gnt_menu_add_item(GNT_MENU(menu), item); | |
465 | |
466 sub = gnt_menu_new(GNT_MENU_POPUP); | |
467 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
468 | |
469 item = gnt_menuitem_new(_("Clear Scrollback")); | |
470 gnt_menu_add_item(GNT_MENU(sub), item); | |
471 gnt_menuitem_set_callback(item, clear_scrollback_cb, ggc); | |
472 | |
473 item = gnt_menuitem_check_new(_("Show Timestamps")); | |
474 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), | |
475 purple_prefs_get_bool(PREF_ROOT "/timestamps")); | |
476 gnt_menu_add_item(GNT_MENU(sub), item); | |
477 gnt_menuitem_set_callback(item, toggle_timestamps_cb, ggc); | |
478 | |
479 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
|
480 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
|
481 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
|
482 |
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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 } |
16892 | 488 |
489 item = gnt_menuitem_new(_("Add Buddy Pounce...")); | |
490 gnt_menu_add_item(GNT_MENU(sub), item); | |
491 gnt_menuitem_set_callback(item, add_pounce_cb, ggc); | |
492 | |
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
|
493 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
|
494 (!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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 } |
16892 | 500 |
501 generate_send_to_menu(ggc); | |
502 } | |
19445
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
503 |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
504 item = gnt_menuitem_check_new(_("Enable Logging")); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
505 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
506 purple_conversation_is_logging(ggc->active_conv)); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
507 gnt_menu_add_item(GNT_MENU(sub), item); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
508 gnt_menuitem_set_callback(item, toggle_logging_cb, ggc); |
19447
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
509 |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
510 item = gnt_menuitem_check_new(_("Enable Sounds")); |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
511 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
512 !(ggc->flags & FINCH_CONV_NO_SOUND)); |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
513 gnt_menu_add_item(GNT_MENU(sub), item); |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
514 gnt_menuitem_set_callback(item, toggle_sound_cb, ggc); |
16892 | 515 } |
516 | |
517 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
|
518 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
|
519 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
520 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
|
521 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
|
522 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
|
523 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
524 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
525 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
|
526 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
|
527 { |
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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 } |
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
|
533 } |
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
|
534 |
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
|
535 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
|
536 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
|
537 { |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
538 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
|
539 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
|
540 } |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
541 |
9eb2f4d27990
Use the completion-signal to append a ': ' after a tab-completed nick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18232
diff
changeset
|
542 static void |
15822 | 543 finch_create_conversation(PurpleConversation *conv) |
15817 | 544 { |
545 FinchConv *ggc = conv->ui_data; | |
546 char *title; | |
15822 | 547 PurpleConversationType type; |
548 PurpleConversation *cc; | |
549 PurpleAccount *account; | |
15817 | 550 |
551 if (ggc) | |
552 return; | |
553 | |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
554 cc = find_conv_with_contact(conv->account, conv->name); |
15817 | 555 if (cc && cc->ui_data) |
556 ggc = cc->ui_data; | |
557 else | |
558 ggc = g_new0(FinchConv, 1); | |
559 | |
19445
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
560 /* Each conversation with the same person will have the same logging setting */ |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
561 if (ggc->list) { |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
562 purple_conversation_set_logging(conv, |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
563 purple_conversation_is_logging(ggc->list->data)); |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
564 } |
6759eb4387a5
Separate logging support for each conversation.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
565 |
15817 | 566 ggc->list = g_list_prepend(ggc->list, conv); |
567 ggc->active_conv = conv; | |
568 conv->ui_data = ggc; | |
569 | |
570 if (cc && cc->ui_data) { | |
571 finch_conversation_set_active(conv); | |
572 return; | |
573 } | |
574 | |
15822 | 575 account = purple_conversation_get_account(conv); |
576 type = purple_conversation_get_type(conv); | |
15817 | 577 title = get_conversation_title(conv, account); |
578 | |
16892 | 579 ggc->window = gnt_vwindow_new(FALSE); |
15817 | 580 gnt_box_set_title(GNT_BOX(ggc->window), title); |
581 gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); | |
582 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
|
583 |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
588 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
|
589 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
|
590 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
591 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
|
592 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
|
593 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
594 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
|
595 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
|
596 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
597 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
|
598 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
|
599 break; |
2b1af79e768f
Plucked revision from finchfeat to give different names to windows for
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
600 } |
15817 | 601 |
602 ggc->tv = gnt_text_view_new(); | |
603 gnt_widget_set_name(ggc->tv, "conversation-window-textview"); | |
15822 | 604 gnt_widget_set_size(ggc->tv, purple_prefs_get_int(PREF_ROOT "/size/width"), |
605 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
15817 | 606 |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free); |
19632
61473f8a5e2b
Use the proper column for searching users in the chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19509
diff
changeset
|
616 gnt_tree_set_search_column(GNT_TREE(tree), 1); |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
617 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
|
618 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
|
619 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
|
620 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
|
621 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
|
622 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
|
623 } else { |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
624 ggc->u.im = g_new0(FinchConvIm, 1); |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
625 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
|
626 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
627 |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
628 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
|
629 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
|
630 |
15817 | 631 ggc->entry = gnt_entry_new(NULL); |
632 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry); | |
633 gnt_widget_set_name(ggc->entry, "conversation-window-entry"); | |
634 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1); | |
635 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE); | |
636 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE); | |
637 | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
638 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(ggc->tv), ggc->entry); |
18427
be8c4eba38f6
Use the utility function for the conversation and debug windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18383
diff
changeset
|
639 gnt_text_view_attach_pager_widget(GNT_TEXT_VIEW(ggc->tv), ggc->entry); |
be8c4eba38f6
Use the utility function for the conversation and debug windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18383
diff
changeset
|
640 |
15817 | 641 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
|
642 g_signal_connect(G_OBJECT(ggc->entry), "completion", G_CALLBACK(completion_cb), NULL); |
15817 | 643 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); |
644 | |
15822 | 645 gnt_widget_set_position(ggc->window, purple_prefs_get_int(PREF_ROOT "/position/x"), |
646 purple_prefs_get_int(PREF_ROOT "/position/y")); | |
15817 | 647 gnt_widget_show(ggc->window); |
648 | |
649 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL); | |
650 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL); | |
651 | |
15822 | 652 if (type == PURPLE_CONV_TYPE_IM) { |
15817 | 653 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc); |
654 } | |
655 | |
19447
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
656 if (!finch_sound_is_enabled()) |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
657 ggc->flags |= FINCH_CONV_NO_SOUND; |
1a9b30a95fa6
Fix #2767 (per-conversation/chat mute option).
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19446
diff
changeset
|
658 |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
659 gg_create_menu(ggc); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
660 |
15817 | 661 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
|
662 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
|
663 g_signal_connect(G_OBJECT(ggc->window), "gained-focus", G_CALLBACK(gained_focus_cb), ggc); |
15817 | 664 } |
665 | |
666 static void | |
15822 | 667 finch_destroy_conversation(PurpleConversation *conv) |
15817 | 668 { |
669 /* do stuff here */ | |
670 FinchConv *ggc = conv->ui_data; | |
671 ggc->list = g_list_remove(ggc->list, conv); | |
672 if (ggc->list && conv == ggc->active_conv) | |
673 ggc->active_conv = ggc->list->data; | |
674 | |
675 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
|
676 g_free(ggc->u.chat); |
18222
ef65d43190e5
Fix a few runtime warnings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
677 if (ggc->window) |
ef65d43190e5
Fix a few runtime warnings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
678 gnt_widget_destroy(ggc->window); |
15817 | 679 g_free(ggc); |
680 } | |
681 } | |
682 | |
683 static void | |
15822 | 684 finch_write_common(PurpleConversation *conv, const char *who, const char *message, |
685 PurpleMessageFlags flags, time_t mtime) | |
15817 | 686 { |
687 FinchConv *ggconv = conv->ui_data; | |
688 char *strip, *newline; | |
689 GntTextFormatFlags fl = 0; | |
690 int pos; | |
691 | |
692 g_return_if_fail(ggconv != NULL); | |
693 | |
694 if (ggconv->active_conv != conv) { | |
15822 | 695 if (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV)) |
15817 | 696 finch_conversation_set_active(conv); |
697 else | |
698 return; | |
699 } | |
700 | |
701 pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggconv->tv)); | |
702 | |
18637
3597903cf8ff
Just show an empty line, instead of bouncing the text down when the user
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18427
diff
changeset
|
703 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggconv->tv), "typing", NULL, TRUE); |
15817 | 704 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), "\n", GNT_TEXT_FLAG_NORMAL); |
705 | |
706 /* 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
|
707 if (purple_prefs_get_bool("/finch/conversations/timestamps")) |
15817 | 708 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
15822 | 709 purple_utf8_strftime("(%H:%M:%S) ", localtime(&mtime)), GNT_TEXT_FLAG_DIM); |
15817 | 710 |
15822 | 711 if (flags & PURPLE_MESSAGE_AUTO_RESP) |
15817 | 712 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
713 _("<AUTO-REPLY> "), GNT_TEXT_FLAG_BOLD); | |
714 | |
15822 | 715 if (who && *who && (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV))) |
15817 | 716 { |
717 char * name = NULL; | |
718 | |
15822 | 719 if (purple_message_meify((char*)message, -1)) |
15817 | 720 name = g_strdup_printf("*** %s ", who); |
721 else | |
722 name = g_strdup_printf("%s: ", who); | |
723 | |
724 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
725 name, GNT_TEXT_FLAG_BOLD); | |
726 g_free(name); | |
727 } | |
728 else | |
729 fl = GNT_TEXT_FLAG_DIM; | |
730 | |
15822 | 731 if (flags & PURPLE_MESSAGE_ERROR) |
15817 | 732 fl |= GNT_TEXT_FLAG_BOLD; |
15822 | 733 if (flags & PURPLE_MESSAGE_NICK) |
15817 | 734 fl |= GNT_TEXT_FLAG_UNDERLINE; |
735 | |
736 /* XXX: Remove this workaround when textview can parse messages. */ | |
15822 | 737 newline = purple_strdup_withhtml(message); |
738 strip = purple_markup_strip_html(newline); | |
15817 | 739 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
740 strip, fl); | |
741 | |
742 g_free(newline); | |
743 g_free(strip); | |
744 | |
18637
3597903cf8ff
Just show an empty line, instead of bouncing the text down when the user
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18427
diff
changeset
|
745 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM && |
3597903cf8ff
Just show an empty line, instead of bouncing the text down when the user
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18427
diff
changeset
|
746 purple_conv_im_get_typing_state(PURPLE_CONV_IM(conv)) == PURPLE_TYPING) { |
15822 | 747 strip = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15817 | 748 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggconv->tv), |
749 strip, GNT_TEXT_FLAG_DIM, "typing"); | |
750 g_free(strip); | |
751 } | |
752 | |
753 if (pos <= 1) | |
754 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); | |
755 | |
15822 | 756 if (flags & (PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_NICK | PURPLE_MESSAGE_ERROR)) |
15817 | 757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 } |
15817 | 763 } |
764 | |
765 static void | |
15822 | 766 finch_write_chat(PurpleConversation *conv, const char *who, const char *message, |
767 PurpleMessageFlags flags, time_t mtime) | |
15817 | 768 { |
15822 | 769 purple_conversation_write(conv, who, message, flags, mtime); |
15817 | 770 } |
771 | |
772 static void | |
15822 | 773 finch_write_im(PurpleConversation *conv, const char *who, const char *message, |
774 PurpleMessageFlags flags, time_t mtime) | |
15817 | 775 { |
15822 | 776 PurpleAccount *account = purple_conversation_get_account(conv); |
777 if (flags & PURPLE_MESSAGE_SEND) | |
15817 | 778 { |
15822 | 779 who = purple_connection_get_display_name(purple_account_get_connection(account)); |
15817 | 780 if (!who) |
15822 | 781 who = purple_account_get_alias(account); |
15817 | 782 if (!who) |
15822 | 783 who = purple_account_get_username(account); |
15817 | 784 } |
15822 | 785 else if (flags & PURPLE_MESSAGE_RECV) |
15817 | 786 { |
15822 | 787 PurpleBuddy *buddy; |
788 who = purple_conversation_get_name(conv); | |
789 buddy = purple_find_buddy(account, who); | |
15817 | 790 if (buddy) |
15822 | 791 who = purple_buddy_get_contact_alias(buddy); |
15817 | 792 } |
793 | |
15822 | 794 purple_conversation_write(conv, who, message, flags, mtime); |
15817 | 795 } |
796 | |
797 static void | |
15822 | 798 finch_write_conv(PurpleConversation *conv, const char *who, const char *alias, |
799 const char *message, PurpleMessageFlags flags, time_t mtime) | |
15817 | 800 { |
801 const char *name; | |
802 if (alias && *alias) | |
803 name = alias; | |
804 else if (who && *who) | |
805 name = who; | |
806 else | |
807 name = NULL; | |
808 | |
809 finch_write_common(conv, name, message, flags, mtime); | |
810 } | |
811 | |
17070
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
812 static const char * |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
813 chat_flag_text(PurpleConvChatBuddyFlags flags) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
814 { |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
815 if (flags & PURPLE_CBFLAGS_FOUNDER) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
816 return "~"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
817 if (flags & PURPLE_CBFLAGS_OP) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
818 return "@"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
819 if (flags & PURPLE_CBFLAGS_HALFOP) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
820 return "%"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
821 if (flags & PURPLE_CBFLAGS_VOICE) |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
822 return "+"; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
823 return " "; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
824 } |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
825 |
15817 | 826 static void |
15822 | 827 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals) |
15817 | 828 { |
829 FinchConv *ggc = conv->ui_data; | |
830 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
831 | |
832 if (!new_arrivals) | |
833 { | |
834 /* Print the list of users in the room */ | |
835 GString *string = g_string_new(_("List of users:\n")); | |
836 GList *iter; | |
837 | |
838 for (iter = users; iter; iter = iter->next) | |
839 { | |
15822 | 840 PurpleConvChatBuddy *cbuddy = iter->data; |
15817 | 841 char *str; |
842 | |
843 if ((str = cbuddy->alias) == NULL) | |
844 str = cbuddy->name; | |
845 g_string_append_printf(string, "[ %s ]", str); | |
846 } | |
847 | |
15822 | 848 purple_conversation_write(conv, NULL, string->str, |
849 PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
15817 | 850 g_string_free(string, TRUE); |
851 } | |
852 | |
853 for (; users; users = users->next) | |
854 { | |
15822 | 855 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
|
856 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15817 | 857 gnt_entry_add_suggest(entry, cbuddy->name); |
858 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
|
859 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
|
860 gnt_tree_create_row(tree, chat_flag_text(cbuddy->flags), cbuddy->alias), NULL, NULL); |
15817 | 861 } |
862 } | |
863 | |
864 static void | |
15822 | 865 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a) |
15817 | 866 { |
867 /* Update the name for string completion */ | |
868 FinchConv *ggc = conv->ui_data; | |
869 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
|
870 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
|
871 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
|
872 |
15817 | 873 gnt_entry_remove_suggest(entry, old); |
17070
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
874 gnt_tree_remove(tree, (gpointer)old); |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
875 |
15817 | 876 gnt_entry_add_suggest(entry, new_n); |
877 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
|
878 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
|
879 gnt_tree_create_row(tree, chat_flag_text(cb->flags), new_a), NULL, NULL); |
15817 | 880 } |
881 | |
882 static void | |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
883 finch_chat_remove_users(PurpleConversation *conv, GList *list) |
15817 | 884 { |
885 /* Remove the name from string completion */ | |
886 FinchConv *ggc = conv->ui_data; | |
887 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
|
888 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
|
889 GntTree *tree = GNT_TREE(ggc->u.chat->userlist); |
15817 | 890 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
|
891 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
|
892 } |
15817 | 893 } |
894 | |
895 static void | |
15822 | 896 finch_chat_update_user(PurpleConversation *conv, const char *user) |
15817 | 897 { |
17070
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
898 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
|
899 FinchConv *ggc = conv->ui_data; |
f2137f75fd10
Show user flags in chat userlist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17021
diff
changeset
|
900 gnt_tree_change_text(GNT_TREE(ggc->u.chat->userlist), (gpointer)user, 0, chat_flag_text(cb->flags)); |
15817 | 901 } |
902 | |
19446
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
903 static void |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
904 finch_conv_present(PurpleConversation *conv) |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
905 { |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
906 FinchConv *fc = FINCH_CONV(conv); |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
907 if (fc && fc->window) |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
908 return gnt_window_present(fc->window); |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
909 } |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
910 |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
911 static gboolean |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
912 finch_conv_has_focus(PurpleConversation *conv) |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
913 { |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
914 FinchConv *fc = FINCH_CONV(conv); |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
915 if (fc && fc->window) |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
916 return gnt_widget_has_focus(fc->window); |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
917 return FALSE; |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
918 } |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
919 |
15822 | 920 static PurpleConversationUiOps conv_ui_ops = |
15817 | 921 { |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
922 finch_create_conversation, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
923 finch_destroy_conversation, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
924 finch_write_chat, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
925 finch_write_im, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
926 finch_write_conv, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
927 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
|
928 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
|
929 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
|
930 finch_chat_update_user, |
19446
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
931 finch_conv_present, /* present */ |
5d200fce4170
Add two missing conversation-uiops functions. (has_focus and present)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19445
diff
changeset
|
932 finch_conv_has_focus, /* has_focus */ |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
933 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
|
934 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
|
935 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
|
936 NULL, /* send_confirm */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
937 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
938 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
939 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
17070
diff
changeset
|
940 NULL |
15817 | 941 }; |
942 | |
15822 | 943 PurpleConversationUiOps *finch_conv_get_ui_ops() |
15817 | 944 { |
945 return &conv_ui_ops; | |
946 } | |
947 | |
948 /* Xerox */ | |
15822 | 949 static PurpleCmdRet |
950 say_command_cb(PurpleConversation *conv, | |
15817 | 951 const char *cmd, char **args, char **error, void *data) |
952 { | |
15822 | 953 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
954 purple_conv_im_send(PURPLE_CONV_IM(conv), args[0]); | |
955 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
956 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), args[0]); | |
15817 | 957 |
15822 | 958 return PURPLE_CMD_RET_OK; |
15817 | 959 } |
960 | |
961 /* Xerox */ | |
15822 | 962 static PurpleCmdRet |
963 me_command_cb(PurpleConversation *conv, | |
15817 | 964 const char *cmd, char **args, char **error, void *data) |
965 { | |
966 char *tmp; | |
967 | |
968 tmp = g_strdup_printf("/me %s", args[0]); | |
969 | |
15822 | 970 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
971 purple_conv_im_send(PURPLE_CONV_IM(conv), tmp); | |
972 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
973 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), tmp); | |
15817 | 974 |
975 g_free(tmp); | |
15822 | 976 return PURPLE_CMD_RET_OK; |
15817 | 977 } |
978 | |
979 /* Xerox */ | |
15822 | 980 static PurpleCmdRet |
981 debug_command_cb(PurpleConversation *conv, | |
15817 | 982 const char *cmd, char **args, char **error, void *data) |
983 { | |
984 char *tmp, *markup; | |
15822 | 985 PurpleCmdStatus status; |
15817 | 986 |
987 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
|
988 tmp = g_strdup_printf("me is using Finch v%s.", VERSION); |
15817 | 989 markup = g_markup_escape_text(tmp, -1); |
990 | |
15822 | 991 status = purple_cmd_do_command(conv, tmp, markup, error); |
15817 | 992 |
993 g_free(tmp); | |
994 g_free(markup); | |
995 return status; | |
996 } else { | |
15822 | 997 purple_conversation_write(conv, NULL, _("Supported debug options are: version"), |
998 PURPLE_MESSAGE_NO_LOG|PURPLE_MESSAGE_ERROR, time(NULL)); | |
999 return PURPLE_CMD_STATUS_OK; | |
15817 | 1000 } |
1001 } | |
1002 | |
1003 /* Xerox */ | |
15822 | 1004 static PurpleCmdRet |
1005 clear_command_cb(PurpleConversation *conv, | |
15817 | 1006 const char *cmd, char **args, char **error, void *data) |
1007 { | |
1008 FinchConv *ggconv = conv->ui_data; | |
1009 gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv)); | |
19422
a277162b976e
Clear the message history in the /clear callback.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19370
diff
changeset
|
1010 purple_conversation_clear_message_history(conv); |
15822 | 1011 return PURPLE_CMD_STATUS_OK; |
15817 | 1012 } |
1013 | |
1014 /* Xerox */ | |
15822 | 1015 static PurpleCmdRet |
1016 help_command_cb(PurpleConversation *conv, | |
15817 | 1017 const char *cmd, char **args, char **error, void *data) |
1018 { | |
1019 GList *l, *text; | |
1020 GString *s; | |
1021 | |
1022 if (args[0] != NULL) { | |
1023 s = g_string_new(""); | |
15822 | 1024 text = purple_cmd_help(conv, args[0]); |
15817 | 1025 |
1026 if (text) { | |
1027 for (l = text; l; l = l->next) | |
1028 if (l->next) | |
1029 g_string_append_printf(s, "%s\n", (char *)l->data); | |
1030 else | |
1031 g_string_append_printf(s, "%s", (char *)l->data); | |
1032 } else { | |
1033 g_string_append(s, _("No such command (in this context).")); | |
1034 } | |
1035 } else { | |
1036 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" | |
1037 "The following commands are available in this context:\n")); | |
1038 | |
15822 | 1039 text = purple_cmd_list(conv); |
15817 | 1040 for (l = text; l; l = l->next) |
1041 if (l->next) | |
1042 g_string_append_printf(s, "%s, ", (char *)l->data); | |
1043 else | |
1044 g_string_append_printf(s, "%s.", (char *)l->data); | |
1045 g_list_free(text); | |
1046 } | |
1047 | |
15822 | 1048 purple_conversation_write(conv, NULL, s->str, PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15817 | 1049 g_string_free(s, TRUE); |
1050 | |
15822 | 1051 return PURPLE_CMD_STATUS_OK; |
15817 | 1052 } |
1053 | |
15822 | 1054 static PurpleCmdRet |
1055 cmd_show_window(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) | |
15817 | 1056 { |
1057 void (*callback)() = data; | |
1058 callback(); | |
15822 | 1059 return PURPLE_CMD_STATUS_OK; |
15817 | 1060 } |
1061 | |
16893
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
1062 static PurpleCmdRet |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
1063 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
|
1064 { |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
1065 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
|
1066 FinchConvChat *ch; |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
1067 if (!fc) |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
1068 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
|
1069 |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
1070 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
|
1071 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
|
1072 (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
|
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 } |
b799918b6cdc
Add a /users command to toggle the userlist in chat windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16892
diff
changeset
|
1078 |
15817 | 1079 void finch_conversation_init() |
1080 { | |
15822 | 1081 purple_prefs_add_none(PREF_ROOT); |
1082 purple_prefs_add_none(PREF_ROOT "/size"); | |
1083 purple_prefs_add_int(PREF_ROOT "/size/width", 70); | |
1084 purple_prefs_add_int(PREF_ROOT "/size/height", 20); | |
1085 purple_prefs_add_none(PREF_ROOT "/position"); | |
1086 purple_prefs_add_int(PREF_ROOT "/position/x", 0); | |
1087 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
|
1088 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
|
1089 purple_prefs_add_bool(PREF_USERLIST, FALSE); |
15817 | 1090 |
1091 /* Xerox the commands */ | |
15822 | 1092 purple_cmd_register("say", "S", PURPLE_CMD_P_DEFAULT, |
1093 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1094 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); |
15822 | 1095 purple_cmd_register("me", "S", PURPLE_CMD_P_DEFAULT, |
1096 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1097 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); |
15822 | 1098 purple_cmd_register("debug", "w", PURPLE_CMD_P_DEFAULT, |
1099 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1100 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); |
15822 | 1101 purple_cmd_register("clear", "", PURPLE_CMD_P_DEFAULT, |
1102 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1103 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); |
15822 | 1104 purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT, |
1105 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, | |
15817 | 1106 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
|
1107 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
|
1108 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
|
1109 users_command_cb, _("users: Show the list of users in the chat."), NULL); |
15817 | 1110 |
1111 /* Now some commands to bring up some other windows */ | |
15822 | 1112 purple_cmd_register("plugins", "", PURPLE_CMD_P_DEFAULT, |
1113 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1114 cmd_show_window, _("plugins: Show the plugins window."), finch_plugins_show_all); |
15822 | 1115 purple_cmd_register("buddylist", "", PURPLE_CMD_P_DEFAULT, |
1116 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1117 cmd_show_window, _("buddylist: Show the buddylist."), finch_blist_show); |
15822 | 1118 purple_cmd_register("accounts", "", PURPLE_CMD_P_DEFAULT, |
1119 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1120 cmd_show_window, _("accounts: Show the accounts window."), finch_accounts_show_all); |
15822 | 1121 purple_cmd_register("debugwin", "", PURPLE_CMD_P_DEFAULT, |
1122 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1123 cmd_show_window, _("debugwin: Show the debug window."), finch_debug_window_show); |
15822 | 1124 purple_cmd_register("prefs", "", PURPLE_CMD_P_DEFAULT, |
1125 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1126 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); |
15822 | 1127 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, |
1128 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 1129 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
|
1130 |
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16978
diff
changeset
|
1131 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
|
1132 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
|
1133 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
|
1134 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
|
1135 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
|
1136 PURPLE_CALLBACK(chat_left_cb), NULL); |
19321
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1137 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", finch_conv_get_handle(), |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1138 PURPLE_CALLBACK(buddy_signed_on_off), NULL); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1139 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", finch_conv_get_handle(), |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1140 PURPLE_CALLBACK(buddy_signed_on_off), NULL); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1141 purple_signal_connect(purple_connections_get_handle(), "signed-on", finch_conv_get_handle(), |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1142 PURPLE_CALLBACK(account_signed_on_off), NULL); |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1143 purple_signal_connect(purple_connections_get_handle(), "signed-off", finch_conv_get_handle(), |
39d3a81a5850
Update the 'send to' menu in conversation windows when necessary.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18637
diff
changeset
|
1144 PURPLE_CALLBACK(account_signed_on_off), NULL); |
15817 | 1145 } |
1146 | |
1147 void finch_conversation_uninit() | |
1148 { | |
17021
d6e855aedc30
Notify when you leave a chat, after /part or /kick.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16978
diff
changeset
|
1149 purple_signals_disconnect_by_handle(finch_conv_get_handle()); |
15817 | 1150 } |
1151 | |
15822 | 1152 void finch_conversation_set_active(PurpleConversation *conv) |
15817 | 1153 { |
1154 FinchConv *ggconv = conv->ui_data; | |
15822 | 1155 PurpleAccount *account; |
15817 | 1156 char *title; |
1157 | |
1158 g_return_if_fail(ggconv); | |
1159 g_return_if_fail(g_list_find(ggconv->list, conv)); | |
1160 | |
1161 ggconv->active_conv = conv; | |
15822 | 1162 account = purple_conversation_get_account(conv); |
15817 | 1163 title = get_conversation_title(conv, account); |
1164 gnt_screen_rename_widget(ggconv->window, title); | |
1165 g_free(title); | |
1166 } | |
1167 | |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1168 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
|
1169 { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1170 FinchConv *fc = conv->ui_data; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1171 int height, width; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1172 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1173 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
|
1174 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1175 if (widget) { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1176 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
|
1177 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
|
1178 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1179 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1180 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
|
1181 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
|
1182 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
|
1183 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
|
1184 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1185 |