Mercurial > pidgin.yaz
annotate src/away.c @ 157:aad89d9bce85
[gaim-migrate @ 167]
Uh huh
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 24 Apr 2000 03:06:25 +0000 |
parents | 4e91b92f91a7 |
children | 83dd297aa363 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #ifdef USE_APPLET | |
23 #include <gnome.h> | |
24 #include <applet-widget.h> | |
25 #include "gnome_applet_mgr.h" | |
26 #endif /* USE_APPLET */ | |
27 #include <string.h> | |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 #include <time.h> | |
31 | |
32 #include <gtk/gtk.h> | |
33 #include "gaim.h" | |
34 | |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
35 GtkWidget *imaway=NULL; |
84 | 36 #ifdef USE_APPLET |
37 extern enum gaim_user_states MRI_user_status; | |
38 #endif | |
1 | 39 |
40 GtkWidget *awaymenu; | |
41 struct away_message *awaymessage = NULL; | |
42 | |
43 static void destroy_im_away() | |
44 { | |
45 if (imaway) | |
46 gtk_widget_destroy(imaway); | |
47 imaway=NULL; | |
48 } | |
49 | |
50 void do_im_back(GtkWidget *w, GtkWidget *x) | |
51 { | |
52 #ifdef USE_APPLET | |
18 | 53 if(!blist) applet_widget_unregister_callback(APPLET_WIDGET(applet),"buddy"); |
1 | 54 applet_widget_unregister_callback(APPLET_WIDGET(applet),"away"); |
55 if(!blist) { | |
56 applet_widget_register_callback(APPLET_WIDGET(applet), | |
57 "buddy", | |
58 _("Buddy List"), | |
107
55faf2e3a134
[gaim-migrate @ 117]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
59 (AppletCallbackFunc)createOnlinePopup, |
1 | 60 NULL); |
61 } | |
84 | 62 MRI_user_status = online; |
18 | 63 insert_applet_away(); |
1 | 64 #endif /* USE_APPLET */ |
65 if (imaway) { | |
66 gtk_widget_destroy(imaway); | |
67 imaway=NULL; | |
68 } | |
69 | |
70 serv_set_away(NULL); | |
71 awaymessage = NULL; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
72 #ifdef GAIM_PLUGINS |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
73 { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
74 GList *c = callbacks; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
75 struct gaim_callback *g; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
76 void (*function)(void *); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
77 while (c) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
78 g = (struct gaim_callback *)c->data; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
79 if (g->event == event_back && g->function != NULL) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
80 function = g->function; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
81 (*function)(g->data); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
82 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
83 c = c->next; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
84 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
85 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
86 #endif |
1 | 87 } |
88 | |
89 void do_away_message(GtkWidget *w, struct away_message *a) | |
90 { | |
91 GtkWidget *back; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
92 GtkWidget *awaytext; |
1 | 93 GtkWidget *vscrollbar; |
94 GtkWidget *bbox; | |
95 GtkWidget *vbox; | |
96 GtkWidget *topbox; | |
97 char *buf2; | |
98 char buf[BUF_LONG]; | |
99 GList *cnv = conversations; | |
100 struct conversation *c; | |
101 | |
18 | 102 #ifdef USE_APPLET |
103 if(!blist) applet_widget_unregister_callback(APPLET_WIDGET(applet),"buddy"); | |
104 remove_applet_away(); | |
105 if(!blist) applet_widget_register_callback(APPLET_WIDGET(applet), | |
106 "buddy", | |
107 _("Buddy List"), | |
107
55faf2e3a134
[gaim-migrate @ 117]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
108 (AppletCallbackFunc)createOnlinePopup, |
18 | 109 NULL); |
110 applet_widget_register_callback(APPLET_WIDGET(applet), | |
111 "away", | |
112 _("Back"), | |
113 (AppletCallbackFunc) do_im_back, | |
114 NULL); | |
84 | 115 MRI_user_status = away; |
18 | 116 #endif |
117 | |
1 | 118 if (!imaway) { |
119 imaway = gtk_window_new(GTK_WINDOW_DIALOG); | |
120 gtk_widget_realize(imaway); | |
121 aol_icon(imaway->window); | |
122 back = gtk_button_new_with_label("I'm Back!"); | |
123 bbox = gtk_hbox_new(TRUE, 10); | |
124 topbox = gtk_hbox_new(FALSE, 5); | |
125 vbox = gtk_vbox_new(FALSE, 5); | |
126 | |
127 awaytext = gtk_text_new(NULL, NULL); | |
128 g_snprintf(buf, sizeof(buf), "%s", a->message); | |
129 vscrollbar = gtk_vscrollbar_new(GTK_TEXT(awaytext)->vadj); | |
130 gtk_widget_show(vscrollbar); | |
131 gtk_widget_set_usize(awaytext, 225, 75); | |
132 gtk_text_set_word_wrap(GTK_TEXT(awaytext), TRUE); | |
133 gtk_widget_show(awaytext); | |
134 gtk_text_freeze(GTK_TEXT(awaytext)); | |
135 gtk_text_insert(GTK_TEXT(awaytext), NULL, NULL, NULL, buf, -1); | |
136 gtk_widget_show(awaytext); | |
137 | |
138 | |
139 /* Put the buttons in the box */ | |
140 gtk_box_pack_start(GTK_BOX(bbox), back, TRUE, TRUE, 10); | |
141 | |
142 gtk_box_pack_start(GTK_BOX(topbox), awaytext, FALSE, FALSE, 5); | |
143 | |
144 /* And the boxes in the box */ | |
145 gtk_box_pack_start(GTK_BOX(vbox), topbox, TRUE, TRUE, 5); | |
146 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 5); | |
147 | |
148 /* Handle closes right */ | |
149 gtk_signal_connect(GTK_OBJECT(imaway), "destroy", | |
150 GTK_SIGNAL_FUNC(destroy_im_away), imaway); | |
151 gtk_signal_connect(GTK_OBJECT(back), "clicked", | |
152 GTK_SIGNAL_FUNC(do_im_back), imaway); | |
153 | |
154 /* Finish up */ | |
155 gtk_widget_show(back); | |
156 gtk_widget_show(topbox); | |
157 gtk_widget_show(bbox); | |
158 gtk_widget_show(vbox); | |
159 if (strlen(a->name)) | |
160 gtk_window_set_title(GTK_WINDOW(imaway), a->name); | |
161 else | |
162 gtk_window_set_title(GTK_WINDOW(imaway), "Gaim - Away!"); | |
163 gtk_window_set_focus(GTK_WINDOW(imaway), back); | |
164 gtk_container_add(GTK_CONTAINER(imaway), vbox); | |
165 awaymessage = a; | |
166 | |
167 } | |
168 | |
169 /* New away message... Clear out the old sent_aways */ | |
170 while(cnv) { | |
171 c = (struct conversation *)cnv->data; | |
172 c->sent_away = 0; | |
173 cnv = cnv->next; | |
174 } | |
175 | |
176 | |
79 | 177 buf2 = g_malloc(strlen(awaymessage->message)*4 + 1); |
178 strcpy(buf2, awaymessage->message); | |
1 | 179 escape_text(buf2); |
180 serv_set_away(buf2); | |
79 | 181 g_free(buf2); |
1 | 182 gtk_widget_show(imaway); |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
183 #ifdef GAIM_PLUGINS |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
184 { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
185 GList *c = callbacks; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
186 struct gaim_callback *g; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
187 void (*function)(void *); |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
188 while (c) { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
189 g = (struct gaim_callback *)c->data; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
190 if (g->event == event_away && g->function != NULL) { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
191 function = g->function; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
192 (*function)(g->data); |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
193 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
194 c = c->next; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
195 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
196 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
197 #endif |
1 | 198 } |
199 | |
200 void rem_away_mess(GtkWidget *w, struct away_message *a) | |
201 { | |
18 | 202 #ifdef USE_APPLET |
203 char *awayname; | |
79 | 204 awayname = g_malloc(sizeof (*awayname) * (6 + strlen(a->name))); |
18 | 205 awayname[0] = '\0'; |
206 strcat(awayname, "away/"); | |
207 strcat(awayname, a->name); | |
208 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname); | |
209 #endif | |
1 | 210 away_messages = g_list_remove(away_messages, a); |
211 g_free(a); | |
212 do_away_menu(); | |
213 } | |
214 | |
215 | |
216 void do_away_menu() | |
217 { | |
218 GtkWidget *menuitem; | |
219 static GtkWidget *remmenu; | |
220 GtkWidget *remitem; | |
221 GtkWidget *label; | |
222 GtkWidget *sep; | |
223 GList *l; | |
224 GtkWidget *list_item; | |
225 GList *awy = away_messages; | |
226 struct away_message *a; | |
227 | |
18 | 228 #ifdef USE_APPLET |
229 remove_applet_away(); | |
230 if (imaway) | |
231 applet_widget_register_callback(APPLET_WIDGET(applet), | |
232 "away", | |
233 _("Back"), | |
234 (AppletCallbackFunc)do_im_back, | |
235 NULL); | |
236 else | |
237 insert_applet_away(); | |
238 #endif | |
1 | 239 |
240 if (pd != NULL) { | |
241 gtk_list_clear_items(GTK_LIST(pd->away_list), 0, -1); | |
242 while(awy) { | |
243 a = (struct away_message *)awy->data; | |
244 label = gtk_label_new(a->name); | |
245 list_item = gtk_list_item_new(); | |
246 gtk_container_add(GTK_CONTAINER(list_item), label); | |
247 gtk_signal_connect(GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(away_list_clicked), a); | |
248 gtk_signal_connect(GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(away_list_unclicked), a); | |
249 gtk_object_set_user_data(GTK_OBJECT(list_item), a); | |
250 | |
251 gtk_widget_show(label); | |
252 gtk_container_add(GTK_CONTAINER(pd->away_list), list_item); | |
253 gtk_widget_show(list_item); | |
254 | |
255 awy = awy->next; | |
256 } | |
257 if (away_messages != NULL) | |
258 gtk_list_select_item(GTK_LIST(pd->away_list), 0); | |
259 } | |
260 | |
261 | |
262 l = gtk_container_children(GTK_CONTAINER(awaymenu)); | |
263 | |
264 while(l) { | |
265 gtk_widget_destroy(GTK_WIDGET(l->data)); | |
266 l = l->next; | |
267 } | |
268 | |
269 | |
270 remmenu = gtk_menu_new(); | |
271 | |
272 | |
273 | |
274 menuitem = gtk_menu_item_new_with_label("New Away Message"); | |
275 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
276 gtk_widget_show(menuitem); | |
277 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL); | |
278 | |
279 | |
22 | 280 awy = away_messages; |
1 | 281 while(awy) { |
282 a = (struct away_message *)awy->data; | |
283 | |
284 remitem = gtk_menu_item_new_with_label(a->name); | |
285 gtk_menu_append(GTK_MENU(remmenu), remitem); | |
286 gtk_widget_show(remitem); | |
287 gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a); | |
288 | |
289 awy = awy->next; | |
290 | |
291 } | |
292 | |
293 menuitem = gtk_menu_item_new_with_label("Remove Away Message"); | |
294 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
295 gtk_widget_show(menuitem); | |
296 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu); | |
297 gtk_widget_show(remmenu); | |
298 | |
299 | |
300 sep = gtk_hseparator_new(); | |
301 menuitem = gtk_menu_item_new(); | |
302 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
303 gtk_container_add(GTK_CONTAINER(menuitem), sep); | |
304 gtk_widget_set_sensitive(menuitem, FALSE); | |
305 gtk_widget_show(menuitem); | |
306 gtk_widget_show(sep); | |
307 | |
308 awy = away_messages; | |
309 | |
310 while(awy) { | |
311 a = (struct away_message *)awy->data; | |
312 | |
313 menuitem = gtk_menu_item_new_with_label(a->name); | |
314 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
315 gtk_widget_show(menuitem); | |
316 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a); | |
317 | |
318 awy = awy->next; | |
319 | |
320 } | |
321 | |
322 } | |
323 | |
324 | |
325 | |
326 | |
327 | |
328 |