Mercurial > pidgin
annotate src/away.c @ 754:bcae3ff49680
[gaim-migrate @ 764]
You can now optionally tell gaim to display text in the convo window buttons.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Thu, 24 Aug 2000 17:37:25 +0000 |
parents | 5a908dd5cfc4 |
children | c714def9cebb |
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; |
1 | 40 |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
41 GtkWidget *awaymenu = NULL; |
1 | 42 struct away_message *awaymessage = NULL; |
43 | |
44 static void destroy_im_away() | |
45 { | |
46 if (imaway) | |
47 gtk_widget_destroy(imaway); | |
48 imaway=NULL; | |
49 } | |
50 | |
51 void do_im_back(GtkWidget *w, GtkWidget *x) | |
52 { | |
53 #ifdef USE_APPLET | |
746
5a908dd5cfc4
[gaim-migrate @ 756]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
652
diff
changeset
|
54 applet_widget_unregister_callback(APPLET_WIDGET(applet),"away"); |
5a908dd5cfc4
[gaim-migrate @ 756]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
652
diff
changeset
|
55 set_user_state(online); |
5a908dd5cfc4
[gaim-migrate @ 756]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
652
diff
changeset
|
56 insert_applet_away(); |
1 | 57 #endif /* USE_APPLET */ |
58 if (imaway) { | |
59 gtk_widget_destroy(imaway); | |
60 imaway=NULL; | |
61 } | |
62 | |
63 serv_set_away(NULL); | |
64 awaymessage = NULL; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
65 #ifdef GAIM_PLUGINS |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
66 { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
67 GList *c = callbacks; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
68 struct gaim_callback *g; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
69 void (*function)(void *); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
70 while (c) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
71 g = (struct gaim_callback *)c->data; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
72 if (g->event == event_back && g->function != NULL) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
73 function = g->function; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
74 (*function)(g->data); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
75 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
76 c = c->next; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
77 } |
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 #endif |
1 | 80 } |
81 | |
82 void do_away_message(GtkWidget *w, struct away_message *a) | |
83 { | |
84 GtkWidget *back; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
85 GtkWidget *awaytext; |
1 | 86 GtkWidget *vscrollbar; |
87 GtkWidget *bbox; | |
88 GtkWidget *vbox; | |
89 GtkWidget *topbox; | |
90 char *buf2; | |
91 char buf[BUF_LONG]; | |
92 GList *cnv = conversations; | |
93 struct conversation *c; | |
94 | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
95 if (!blist) |
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
96 return; |
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
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, | |
746
5a908dd5cfc4
[gaim-migrate @ 756]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
652
diff
changeset
|
104 NULL); |
5a908dd5cfc4
[gaim-migrate @ 756]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
652
diff
changeset
|
105 set_user_state(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); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
162 return; |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
163 } |
1 | 164 |
165 /* New away message... Clear out the old sent_aways */ | |
166 while(cnv) { | |
167 c = (struct conversation *)cnv->data; | |
168 c->sent_away = 0; | |
169 cnv = cnv->next; | |
170 } | |
171 | |
172 | |
79 | 173 buf2 = g_malloc(strlen(awaymessage->message)*4 + 1); |
174 strcpy(buf2, awaymessage->message); | |
1 | 175 escape_text(buf2); |
176 serv_set_away(buf2); | |
79 | 177 g_free(buf2); |
1 | 178 gtk_widget_show(imaway); |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
179 #ifdef GAIM_PLUGINS |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
180 { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
181 GList *c = callbacks; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
182 struct gaim_callback *g; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
183 void (*function)(void *); |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
184 while (c) { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
185 g = (struct gaim_callback *)c->data; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
186 if (g->event == event_away && g->function != NULL) { |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
187 function = g->function; |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
188 (*function)(g->data); |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
189 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
190 c = c->next; |
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 } |
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
107
diff
changeset
|
193 #endif |
1 | 194 } |
195 | |
196 void rem_away_mess(GtkWidget *w, struct away_message *a) | |
197 { | |
18 | 198 #ifdef USE_APPLET |
199 char *awayname; | |
79 | 200 awayname = g_malloc(sizeof (*awayname) * (6 + strlen(a->name))); |
18 | 201 awayname[0] = '\0'; |
202 strcat(awayname, "away/"); | |
203 strcat(awayname, a->name); | |
204 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname); | |
205 #endif | |
1 | 206 away_messages = g_list_remove(away_messages, a); |
207 g_free(a); | |
208 do_away_menu(); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
209 save_prefs(); |
1 | 210 } |
211 | |
212 | |
213 void do_away_menu() | |
214 { | |
215 GtkWidget *menuitem; | |
216 static GtkWidget *remmenu; | |
217 GtkWidget *remitem; | |
218 GtkWidget *label; | |
219 GtkWidget *sep; | |
220 GList *l; | |
221 GtkWidget *list_item; | |
222 GList *awy = away_messages; | |
223 struct away_message *a; | |
224 | |
18 | 225 #ifdef USE_APPLET |
226 remove_applet_away(); | |
227 if (imaway) | |
228 applet_widget_register_callback(APPLET_WIDGET(applet), | |
229 "away", | |
230 _("Back"), | |
231 (AppletCallbackFunc)do_im_back, | |
232 NULL); | |
233 else | |
234 insert_applet_away(); | |
235 #endif | |
1 | 236 |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
237 if (prefs_away_list != NULL) { |
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
238 gtk_list_clear_items(GTK_LIST(prefs_away_list), 0, -1); |
1 | 239 while(awy) { |
240 a = (struct away_message *)awy->data; | |
241 label = gtk_label_new(a->name); | |
242 list_item = gtk_list_item_new(); | |
243 gtk_container_add(GTK_CONTAINER(list_item), label); | |
244 gtk_signal_connect(GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(away_list_clicked), a); | |
245 gtk_signal_connect(GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(away_list_unclicked), a); | |
246 gtk_object_set_user_data(GTK_OBJECT(list_item), a); | |
247 | |
248 gtk_widget_show(label); | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
249 gtk_container_add(GTK_CONTAINER(prefs_away_list), list_item); |
1 | 250 gtk_widget_show(list_item); |
251 | |
252 awy = awy->next; | |
253 } | |
254 if (away_messages != NULL) | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
255 gtk_list_select_item(GTK_LIST(prefs_away_list), 0); |
1 | 256 } |
257 | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
258 if (!awaymenu) return; |
1 | 259 l = gtk_container_children(GTK_CONTAINER(awaymenu)); |
260 | |
261 while(l) { | |
262 gtk_widget_destroy(GTK_WIDGET(l->data)); | |
263 l = l->next; | |
264 } | |
265 | |
266 | |
267 remmenu = gtk_menu_new(); | |
268 | |
269 | |
270 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
271 menuitem = gtk_menu_item_new_with_label(_("New Away Message")); |
1 | 272 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
273 gtk_widget_show(menuitem); | |
274 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL); | |
275 | |
276 | |
22 | 277 awy = away_messages; |
1 | 278 while(awy) { |
279 a = (struct away_message *)awy->data; | |
280 | |
281 remitem = gtk_menu_item_new_with_label(a->name); | |
282 gtk_menu_append(GTK_MENU(remmenu), remitem); | |
283 gtk_widget_show(remitem); | |
284 gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a); | |
285 | |
286 awy = awy->next; | |
287 | |
288 } | |
289 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
290 menuitem = gtk_menu_item_new_with_label(_("Remove Away Message")); |
1 | 291 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
292 gtk_widget_show(menuitem); | |
293 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu); | |
294 gtk_widget_show(remmenu); | |
295 | |
296 | |
297 sep = gtk_hseparator_new(); | |
298 menuitem = gtk_menu_item_new(); | |
299 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
300 gtk_container_add(GTK_CONTAINER(menuitem), sep); | |
301 gtk_widget_set_sensitive(menuitem, FALSE); | |
302 gtk_widget_show(menuitem); | |
303 gtk_widget_show(sep); | |
304 | |
305 awy = away_messages; | |
306 | |
307 while(awy) { | |
308 a = (struct away_message *)awy->data; | |
309 | |
310 menuitem = gtk_menu_item_new_with_label(a->name); | |
311 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
312 gtk_widget_show(menuitem); | |
313 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a); | |
314 | |
315 awy = awy->next; | |
316 | |
317 } | |
318 | |
319 } | |
320 | |
321 | |
322 | |
323 | |
324 | |
325 |