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