Mercurial > pidgin
annotate src/away.c @ 319:cea40691706c
[gaim-migrate @ 329]
A few good oscar changes before release.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 02 Jun 2000 19:45:16 +0000 |
parents | 83dd297aa363 |
children | 9d258a0aa560 |
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(); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
213 save_prefs(); |
1 | 214 } |
215 | |
216 | |
217 void do_away_menu() | |
218 { | |
219 GtkWidget *menuitem; | |
220 static GtkWidget *remmenu; | |
221 GtkWidget *remitem; | |
222 GtkWidget *label; | |
223 GtkWidget *sep; | |
224 GList *l; | |
225 GtkWidget *list_item; | |
226 GList *awy = away_messages; | |
227 struct away_message *a; | |
228 | |
18 | 229 #ifdef USE_APPLET |
230 remove_applet_away(); | |
231 if (imaway) | |
232 applet_widget_register_callback(APPLET_WIDGET(applet), | |
233 "away", | |
234 _("Back"), | |
235 (AppletCallbackFunc)do_im_back, | |
236 NULL); | |
237 else | |
238 insert_applet_away(); | |
239 #endif | |
1 | 240 |
241 if (pd != NULL) { | |
242 gtk_list_clear_items(GTK_LIST(pd->away_list), 0, -1); | |
243 while(awy) { | |
244 a = (struct away_message *)awy->data; | |
245 label = gtk_label_new(a->name); | |
246 list_item = gtk_list_item_new(); | |
247 gtk_container_add(GTK_CONTAINER(list_item), label); | |
248 gtk_signal_connect(GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(away_list_clicked), a); | |
249 gtk_signal_connect(GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(away_list_unclicked), a); | |
250 gtk_object_set_user_data(GTK_OBJECT(list_item), a); | |
251 | |
252 gtk_widget_show(label); | |
253 gtk_container_add(GTK_CONTAINER(pd->away_list), list_item); | |
254 gtk_widget_show(list_item); | |
255 | |
256 awy = awy->next; | |
257 } | |
258 if (away_messages != NULL) | |
259 gtk_list_select_item(GTK_LIST(pd->away_list), 0); | |
260 } | |
261 | |
262 | |
263 l = gtk_container_children(GTK_CONTAINER(awaymenu)); | |
264 | |
265 while(l) { | |
266 gtk_widget_destroy(GTK_WIDGET(l->data)); | |
267 l = l->next; | |
268 } | |
269 | |
270 | |
271 remmenu = gtk_menu_new(); | |
272 | |
273 | |
274 | |
275 menuitem = gtk_menu_item_new_with_label("New Away Message"); | |
276 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
277 gtk_widget_show(menuitem); | |
278 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL); | |
279 | |
280 | |
22 | 281 awy = away_messages; |
1 | 282 while(awy) { |
283 a = (struct away_message *)awy->data; | |
284 | |
285 remitem = gtk_menu_item_new_with_label(a->name); | |
286 gtk_menu_append(GTK_MENU(remmenu), remitem); | |
287 gtk_widget_show(remitem); | |
288 gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a); | |
289 | |
290 awy = awy->next; | |
291 | |
292 } | |
293 | |
294 menuitem = gtk_menu_item_new_with_label("Remove Away Message"); | |
295 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
296 gtk_widget_show(menuitem); | |
297 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu); | |
298 gtk_widget_show(remmenu); | |
299 | |
300 | |
301 sep = gtk_hseparator_new(); | |
302 menuitem = gtk_menu_item_new(); | |
303 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
304 gtk_container_add(GTK_CONTAINER(menuitem), sep); | |
305 gtk_widget_set_sensitive(menuitem, FALSE); | |
306 gtk_widget_show(menuitem); | |
307 gtk_widget_show(sep); | |
308 | |
309 awy = away_messages; | |
310 | |
311 while(awy) { | |
312 a = (struct away_message *)awy->data; | |
313 | |
314 menuitem = gtk_menu_item_new_with_label(a->name); | |
315 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
316 gtk_widget_show(menuitem); | |
317 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a); | |
318 | |
319 awy = awy->next; | |
320 | |
321 } | |
322 | |
323 } | |
324 | |
325 | |
326 | |
327 | |
328 | |
329 |