Mercurial > pidgin.yaz
comparison console/gntconv.c @ 13885:582aaa4e287e
[gaim-migrate @ 16365]
Add ui for conversation. It 'works', but it's broken. So don't use it just yet.
I probably will not be able to touch it in the next couple of days. So feel
free to fix the brokenness :)
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 28 Jun 2006 05:52:23 +0000 |
parents | |
children | 90eb736b4c26 |
comparison
equal
deleted
inserted
replaced
13884:eac18261c6f0 | 13885:582aaa4e287e |
---|---|
1 #include <util.h> | |
2 | |
3 #include "gntgaim.h" | |
4 #include "gntconv.h" | |
5 | |
6 #include "gnt.h" | |
7 #include "gntbox.h" | |
8 #include "gntentry.h" | |
9 #include "gnttextview.h" | |
10 | |
11 GHashTable *ggconvs; | |
12 | |
13 typedef struct _GGConv GGConv; | |
14 typedef struct _GGConvChat GGConvChat; | |
15 typedef struct _GGConvIm GGConvIm; | |
16 | |
17 struct _GGConv | |
18 { | |
19 GaimConversation *conv; | |
20 | |
21 GntWidget *window; /* the container */ | |
22 GntWidget *entry; /* entry */ | |
23 GntWidget *tv; /* text-view */ | |
24 | |
25 union | |
26 { | |
27 GGConvChat *chat; | |
28 GGConvIm *im; | |
29 } u; | |
30 }; | |
31 | |
32 struct _GGConvChat | |
33 { | |
34 GntWidget *userlist; /* the userlist */ | |
35 }; | |
36 | |
37 struct _GGConvIm | |
38 { | |
39 void *nothing_for_now; | |
40 }; | |
41 | |
42 static gboolean | |
43 entry_key_pressed(GntWidget *w, const char *key, GGConv *ggconv) | |
44 { | |
45 if (key[0] == '\r' && key[1] == 0) | |
46 { | |
47 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); | |
48 switch (gaim_conversation_get_type(ggconv->conv)) | |
49 { | |
50 case GAIM_CONV_TYPE_IM: | |
51 gaim_conv_im_send_with_flags(GAIM_CONV_IM(ggconv->conv), text, GAIM_MESSAGE_SEND); | |
52 break; | |
53 case GAIM_CONV_TYPE_CHAT: | |
54 gaim_conv_chat_send(GAIM_CONV_CHAT(ggconv->conv), text); | |
55 break; | |
56 default: | |
57 g_return_val_if_reached(FALSE); | |
58 } | |
59 gnt_entry_clear(GNT_ENTRY(ggconv->entry)); | |
60 return TRUE; | |
61 } | |
62 | |
63 return FALSE; | |
64 } | |
65 | |
66 static void | |
67 closing_window(GntWidget *window, GGConv *ggconv) | |
68 { | |
69 ggconv->window = NULL; | |
70 gaim_conversation_destroy(ggconv->conv); | |
71 } | |
72 | |
73 static void | |
74 gg_create_conversation(GaimConversation *conv) | |
75 { | |
76 GGConv *ggc = g_hash_table_lookup(ggconvs, conv); | |
77 char *title; | |
78 GaimConversationType type; | |
79 | |
80 if (ggc) | |
81 return; | |
82 | |
83 ggc = g_new0(GGConv, 1); | |
84 g_hash_table_insert(ggconvs, conv, ggc); | |
85 | |
86 ggc->conv = conv; | |
87 | |
88 type = gaim_conversation_get_type(conv); | |
89 title = g_strdup_printf(_("Conversation: %s"), gaim_conversation_get_name(conv)); | |
90 ggc->window = gnt_box_new(FALSE, TRUE); | |
91 gnt_box_set_title(GNT_BOX(ggc->window), title); | |
92 gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); | |
93 gnt_widget_set_name(ggc->window, "conversation-window"); | |
94 | |
95 ggc->tv = gnt_text_view_new(); | |
96 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv); | |
97 gnt_widget_set_name(ggc->tv, "conversation-window-textview"); | |
98 gnt_widget_set_size(ggc->tv, getmaxx(stdscr) - 40, getmaxy(stdscr) - 15); | |
99 | |
100 ggc->entry = gnt_entry_new(NULL); | |
101 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry); | |
102 gnt_widget_set_name(ggc->entry, "conversation-window-entry"); | |
103 gnt_widget_set_size(ggc->entry, getmaxx(stdscr) - 40, 1); | |
104 | |
105 g_signal_connect(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc); | |
106 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); | |
107 | |
108 gnt_widget_set_position(ggc->window, 32, 0); | |
109 gnt_widget_show(ggc->window); | |
110 | |
111 g_free(title); | |
112 } | |
113 | |
114 static void | |
115 gg_destroy_conversation(GaimConversation *conv) | |
116 { | |
117 g_hash_table_remove(ggconvs, conv); | |
118 } | |
119 | |
120 static void | |
121 gg_write_chat(GaimConversation *conv, const char *who, const char *message, | |
122 GaimMessageFlags flags, time_t mtime) | |
123 { | |
124 GGConv *ggconv = g_hash_table_lookup(ggconvs, conv); | |
125 char *name, *strip; | |
126 | |
127 g_return_if_fail(ggconv != NULL); | |
128 | |
129 name = g_strdup_printf("%s: ", who); | |
130 strip = gaim_markup_strip_html(message); | |
131 | |
132 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
133 name, GNT_TEXT_FLAG_BOLD); | |
134 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
135 strip, (flags & GAIM_MESSAGE_NICK) ? GNT_TEXT_FLAG_UNDERLINE : 0); | |
136 gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv)); | |
137 | |
138 g_free(name); | |
139 g_free(strip); | |
140 } | |
141 | |
142 static void | |
143 gg_write_im(GaimConversation *conv, const char *who, const char *message, | |
144 GaimMessageFlags flags, time_t mtime) | |
145 { | |
146 GGConv *ggconv = g_hash_table_lookup(ggconvs, conv); | |
147 char *strip; | |
148 char *name; | |
149 | |
150 g_return_if_fail(ggconv != NULL); | |
151 | |
152 if (flags & GAIM_MESSAGE_SEND) | |
153 { | |
154 who = gaim_connection_get_display_name(conv->account->gc); | |
155 if (!who) | |
156 who = gaim_account_get_alias(conv->account); | |
157 if (!who) | |
158 who = gaim_account_get_username(conv->account); | |
159 } | |
160 else if (flags & GAIM_MESSAGE_RECV) | |
161 who = gaim_conversation_get_name(conv); | |
162 | |
163 name = g_strdup_printf("%s: ", who); | |
164 | |
165 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
166 name, GNT_TEXT_FLAG_BOLD); | |
167 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
168 (strip = gaim_markup_strip_html(message)), 0); | |
169 gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv)); | |
170 g_free(strip); | |
171 g_free(name); | |
172 } | |
173 | |
174 static void | |
175 gg_write_conv(GaimConversation *conv, const char *who, const char *message, | |
176 GaimMessageFlags flags, time_t mtime) | |
177 { | |
178 GGConv *ggconv = g_hash_table_lookup(ggconvs, conv); | |
179 char *strip; | |
180 char *name; | |
181 | |
182 g_return_if_fail(ggconv != NULL); | |
183 | |
184 strip = gaim_markup_strip_html(message); | |
185 name = g_strdup_printf("%s: ", who); | |
186 | |
187 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
188 name, GNT_TEXT_FLAG_BOLD); | |
189 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
190 strip, 0); | |
191 gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv)); | |
192 | |
193 g_free(strip); | |
194 } | |
195 | |
196 static void | |
197 gg_chat_add_users(GaimConversation *conv, GList *users, GList *flags, GList *aliases, gboolean new_arrivals) | |
198 {} | |
199 | |
200 static void | |
201 gg_chat_rename_user(GaimConversation *conv, const char *old, const char *new_n, const char *new_a) | |
202 {} | |
203 | |
204 static void | |
205 gg_chat_remove_user(GaimConversation *conv, GList *list) | |
206 {} | |
207 | |
208 static void | |
209 gg_chat_update_user(GaimConversation *conv, const char *user) | |
210 {} | |
211 | |
212 static GaimConversationUiOps conv_ui_ops = | |
213 { | |
214 .create_conversation = gg_create_conversation, | |
215 .destroy_conversation = gg_destroy_conversation, | |
216 .write_chat = gg_write_chat, | |
217 .write_im = gg_write_im, | |
218 .write_chat = gg_write_conv, | |
219 .chat_add_users = gg_chat_add_users, | |
220 .chat_rename_user = gg_chat_rename_user, | |
221 .chat_remove_users = gg_chat_remove_user, | |
222 .chat_update_user = gg_chat_update_user, | |
223 .present = NULL, | |
224 .has_focus = NULL, | |
225 .custom_smiley_add = NULL, | |
226 .custom_smiley_write = NULL, | |
227 .custom_smiley_close = NULL | |
228 }; | |
229 | |
230 static void | |
231 destroy_ggconv(gpointer data) | |
232 { | |
233 GGConv *conv = data; | |
234 gnt_widget_destroy(conv->window); | |
235 g_free(conv); | |
236 } | |
237 | |
238 GaimConversationUiOps *gg_conv_get_ui_ops() | |
239 { | |
240 return &conv_ui_ops; | |
241 } | |
242 | |
243 | |
244 void gg_conversation_init() | |
245 { | |
246 ggconvs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_ggconv); | |
247 } | |
248 |