Mercurial > pidgin
annotate src/away.c @ 648:07165959309b
[gaim-migrate @ 658]
just for the record, it did break my system.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 09 Aug 2000 04:09:10 +0000 |
parents | 991bf4e3c9fe |
children | 4d3285caa191 |
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 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
23 #include "../config.h" |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
24 #endif |
1 | 25 #ifdef USE_APPLET |
26 #include <gnome.h> | |
27 #include <applet-widget.h> | |
28 #include "gnome_applet_mgr.h" | |
29 #endif /* USE_APPLET */ | |
30 #include <string.h> | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 #include <time.h> | |
34 | |
35 #include <gtk/gtk.h> | |
36 #include "gaim.h" | |
621 | 37 #include "pixmaps/join.xpm" |
1 | 38 |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
39 GtkWidget *imaway=NULL; |
84 | 40 #ifdef USE_APPLET |
41 extern enum gaim_user_states MRI_user_status; | |
42 #endif | |
1 | 43 |
44 GtkWidget *awaymenu; | |
45 struct away_message *awaymessage = NULL; | |
46 | |
47 static void destroy_im_away() | |
48 { | |
49 if (imaway) | |
50 gtk_widget_destroy(imaway); | |
51 imaway=NULL; | |
52 } | |
53 | |
54 void do_im_back(GtkWidget *w, GtkWidget *x) | |
55 { | |
56 #ifdef USE_APPLET | |
57 applet_widget_unregister_callback(APPLET_WIDGET(applet),"away"); | |
84 | 58 MRI_user_status = online; |
18 | 59 insert_applet_away(); |
1 | 60 #endif /* USE_APPLET */ |
61 if (imaway) { | |
62 gtk_widget_destroy(imaway); | |
63 imaway=NULL; | |
64 } | |
65 | |
66 serv_set_away(NULL); | |
67 awaymessage = NULL; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
68 #ifdef GAIM_PLUGINS |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
69 { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
70 GList *c = callbacks; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
71 struct gaim_callback *g; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
72 void (*function)(void *); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
73 while (c) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
74 g = (struct gaim_callback *)c->data; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
75 if (g->event == event_back && g->function != NULL) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
76 function = g->function; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
77 (*function)(g->data); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
78 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
79 c = c->next; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
80 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
81 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
82 #endif |
1 | 83 } |
84 | |
85 void do_away_message(GtkWidget *w, struct away_message *a) | |
86 { | |
87 GtkWidget *back; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
88 GtkWidget *awaytext; |
1 | 89 GtkWidget *vscrollbar; |
90 GtkWidget *bbox; | |
91 GtkWidget *vbox; | |
92 GtkWidget *topbox; | |
93 char *buf2; | |
94 char buf[BUF_LONG]; | |
95 GList *cnv = conversations; | |
96 struct conversation *c; | |
97 | |
18 | 98 #ifdef USE_APPLET |
99 remove_applet_away(); | |
100 applet_widget_register_callback(APPLET_WIDGET(applet), | |
101 "away", | |
102 _("Back"), | |
103 (AppletCallbackFunc) do_im_back, | |
104 NULL); | |
84 | 105 MRI_user_status = away; |
18 | 106 #endif |
107 | |
1 | 108 if (!imaway) { |
109 imaway = gtk_window_new(GTK_WINDOW_DIALOG); | |
110 gtk_widget_realize(imaway); | |
111 aol_icon(imaway->window); | |
621 | 112 back = picture_button(imaway, _("I'm Back!"), join_xpm); |
1 | 113 bbox = gtk_hbox_new(TRUE, 10); |
114 topbox = gtk_hbox_new(FALSE, 5); | |
115 vbox = gtk_vbox_new(FALSE, 5); | |
116 | |
117 awaytext = gtk_text_new(NULL, NULL); | |
118 g_snprintf(buf, sizeof(buf), "%s", a->message); | |
119 vscrollbar = gtk_vscrollbar_new(GTK_TEXT(awaytext)->vadj); | |
120 gtk_widget_show(vscrollbar); | |
121 gtk_widget_set_usize(awaytext, 225, 75); | |
122 gtk_text_set_word_wrap(GTK_TEXT(awaytext), TRUE); | |
123 gtk_widget_show(awaytext); | |
124 gtk_text_freeze(GTK_TEXT(awaytext)); | |
125 gtk_text_insert(GTK_TEXT(awaytext), NULL, NULL, NULL, buf, -1); | |
126 gtk_widget_show(awaytext); | |
127 | |
535
f03f041c1aa9
[gaim-migrate @ 545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
128 if (display_options & OPT_DISP_COOL_LOOK) |
f03f041c1aa9
[gaim-migrate @ 545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
129 gtk_button_set_relief(GTK_BUTTON(back), GTK_RELIEF_NONE); |
1 | 130 |
131 /* Put the buttons in the box */ | |
132 gtk_box_pack_start(GTK_BOX(bbox), back, TRUE, TRUE, 10); | |
133 | |
134 gtk_box_pack_start(GTK_BOX(topbox), awaytext, FALSE, FALSE, 5); | |
135 | |
136 /* And the boxes in the box */ | |
137 gtk_box_pack_start(GTK_BOX(vbox), topbox, TRUE, TRUE, 5); | |
138 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 5); | |
139 | |
140 /* Handle closes right */ | |
141 gtk_signal_connect(GTK_OBJECT(imaway), "destroy", | |
142 GTK_SIGNAL_FUNC(destroy_im_away), imaway); | |
143 gtk_signal_connect(GTK_OBJECT(back), "clicked", | |
144 GTK_SIGNAL_FUNC(do_im_back), imaway); | |
145 | |
146 /* Finish up */ | |
147 gtk_widget_show(back); | |
148 gtk_widget_show(topbox); | |
149 gtk_widget_show(bbox); | |
150 gtk_widget_show(vbox); | |
151 if (strlen(a->name)) | |
152 gtk_window_set_title(GTK_WINDOW(imaway), a->name); | |
153 else | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
154 gtk_window_set_title(GTK_WINDOW(imaway), _("Gaim - Away!")); |
1 | 155 gtk_window_set_focus(GTK_WINDOW(imaway), back); |
156 gtk_container_add(GTK_CONTAINER(imaway), vbox); | |
157 awaymessage = a; | |
158 | |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
159 } else { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
160 destroy_im_away(); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
161 do_away_message(w, a); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
162 } |
1 | 163 |
164 /* New away message... Clear out the old sent_aways */ | |
165 while(cnv) { | |
166 c = (struct conversation *)cnv->data; | |
167 c->sent_away = 0; | |
168 cnv = cnv->next; | |
169 } | |
170 | |
171 | |
79 | 172 buf2 = g_malloc(strlen(awaymessage->message)*4 + 1); |
173 strcpy(buf2, awaymessage->message); | |
1 | 174 escape_text(buf2); |
175 serv_set_away(buf2); | |
79 | 176 g_free(buf2); |
1 | 177 gtk_widget_show(imaway); |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
178 #ifdef GAIM_PLUGINS |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
179 { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
180 GList *c = callbacks; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
181 struct gaim_callback *g; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
182 void (*function)(void *); |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
183 while (c) { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
184 g = (struct gaim_callback *)c->data; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
185 if (g->event == event_away && g->function != NULL) { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
186 function = g->function; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
187 (*function)(g->data); |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
188 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
189 c = c->next; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
190 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
191 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
192 #endif |
1 | 193 } |
194 | |
195 void rem_away_mess(GtkWidget *w, struct away_message *a) | |
196 { | |
18 | 197 #ifdef USE_APPLET |
198 char *awayname; | |
79 | 199 awayname = g_malloc(sizeof (*awayname) * (6 + strlen(a->name))); |
18 | 200 awayname[0] = '\0'; |
201 strcat(awayname, "away/"); | |
202 strcat(awayname, a->name); | |
203 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname); | |
204 #endif | |
1 | 205 away_messages = g_list_remove(away_messages, a); |
206 g_free(a); | |
207 do_away_menu(); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
208 save_prefs(); |
1 | 209 } |
210 | |
211 | |
212 void do_away_menu() | |
213 { | |
214 GtkWidget *menuitem; | |
215 static GtkWidget *remmenu; | |
216 GtkWidget *remitem; | |
217 GtkWidget *label; | |
218 GtkWidget *sep; | |
219 GList *l; | |
220 GtkWidget *list_item; | |
221 GList *awy = away_messages; | |
222 struct away_message *a; | |
223 | |
18 | 224 #ifdef USE_APPLET |
225 remove_applet_away(); | |
226 if (imaway) | |
227 applet_widget_register_callback(APPLET_WIDGET(applet), | |
228 "away", | |
229 _("Back"), | |
230 (AppletCallbackFunc)do_im_back, | |
231 NULL); | |
232 else | |
233 insert_applet_away(); | |
234 #endif | |
1 | 235 |
236 if (pd != NULL) { | |
237 gtk_list_clear_items(GTK_LIST(pd->away_list), 0, -1); | |
238 while(awy) { | |
239 a = (struct away_message *)awy->data; | |
240 label = gtk_label_new(a->name); | |
241 list_item = gtk_list_item_new(); | |
242 gtk_container_add(GTK_CONTAINER(list_item), label); | |
243 gtk_signal_connect(GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(away_list_clicked), a); | |
244 gtk_signal_connect(GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(away_list_unclicked), a); | |
245 gtk_object_set_user_data(GTK_OBJECT(list_item), a); | |
246 | |
247 gtk_widget_show(label); | |
248 gtk_container_add(GTK_CONTAINER(pd->away_list), list_item); | |
249 gtk_widget_show(list_item); | |
250 | |
251 awy = awy->next; | |
252 } | |
253 if (away_messages != NULL) | |
254 gtk_list_select_item(GTK_LIST(pd->away_list), 0); | |
255 } | |
256 | |
257 | |
258 l = gtk_container_children(GTK_CONTAINER(awaymenu)); | |
259 | |
260 while(l) { | |
261 gtk_widget_destroy(GTK_WIDGET(l->data)); | |
262 l = l->next; | |
263 } | |
264 | |
265 | |
266 remmenu = gtk_menu_new(); | |
267 | |
268 | |
269 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
270 menuitem = gtk_menu_item_new_with_label(_("New Away Message")); |
1 | 271 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
272 gtk_widget_show(menuitem); | |
273 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL); | |
274 | |
275 | |
22 | 276 awy = away_messages; |
1 | 277 while(awy) { |
278 a = (struct away_message *)awy->data; | |
279 | |
280 remitem = gtk_menu_item_new_with_label(a->name); | |
281 gtk_menu_append(GTK_MENU(remmenu), remitem); | |
282 gtk_widget_show(remitem); | |
283 gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a); | |
284 | |
285 awy = awy->next; | |
286 | |
287 } | |
288 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
289 menuitem = gtk_menu_item_new_with_label(_("Remove Away Message")); |
1 | 290 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
291 gtk_widget_show(menuitem); | |
292 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu); | |
293 gtk_widget_show(remmenu); | |
294 | |
295 | |
296 sep = gtk_hseparator_new(); | |
297 menuitem = gtk_menu_item_new(); | |
298 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
299 gtk_container_add(GTK_CONTAINER(menuitem), sep); | |
300 gtk_widget_set_sensitive(menuitem, FALSE); | |
301 gtk_widget_show(menuitem); | |
302 gtk_widget_show(sep); | |
303 | |
304 awy = away_messages; | |
305 | |
306 while(awy) { | |
307 a = (struct away_message *)awy->data; | |
308 | |
309 menuitem = gtk_menu_item_new_with_label(a->name); | |
310 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
311 gtk_widget_show(menuitem); | |
312 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a); | |
313 | |
314 awy = awy->next; | |
315 | |
316 } | |
317 | |
318 } | |
319 | |
320 | |
321 | |
322 | |
323 | |
324 |