Mercurial > pidgin
annotate src/away.c @ 846:4b05985bae5e
[gaim-migrate @ 856]
plugging some leaks
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 06 Sep 2000 20:37:48 +0000 |
parents | 02250312c02d |
children | 2876c40108cd |
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; | |
780
c714def9cebb
[gaim-migrate @ 790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
746
diff
changeset
|
65 plugin_event(event_back, 0, 0, 0); |
1 | 66 } |
67 | |
68 void do_away_message(GtkWidget *w, struct away_message *a) | |
69 { | |
70 GtkWidget *back; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
133
diff
changeset
|
71 GtkWidget *awaytext; |
1 | 72 GtkWidget *vscrollbar; |
73 GtkWidget *bbox; | |
74 GtkWidget *vbox; | |
75 GtkWidget *topbox; | |
76 char *buf2; | |
77 char buf[BUF_LONG]; | |
78 GList *cnv = conversations; | |
79 struct conversation *c; | |
80 | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
81 if (!blist) |
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
82 return; |
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
83 |
18 | 84 #ifdef USE_APPLET |
85 remove_applet_away(); | |
86 applet_widget_register_callback(APPLET_WIDGET(applet), | |
87 "away", | |
88 _("Back"), | |
89 (AppletCallbackFunc) do_im_back, | |
746
5a908dd5cfc4
[gaim-migrate @ 756]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
652
diff
changeset
|
90 NULL); |
5a908dd5cfc4
[gaim-migrate @ 756]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
652
diff
changeset
|
91 set_user_state(away); |
18 | 92 #endif |
93 | |
1 | 94 if (!imaway) { |
95 imaway = gtk_window_new(GTK_WINDOW_DIALOG); | |
96 gtk_widget_realize(imaway); | |
97 aol_icon(imaway->window); | |
621 | 98 back = picture_button(imaway, _("I'm Back!"), join_xpm); |
1 | 99 bbox = gtk_hbox_new(TRUE, 10); |
100 topbox = gtk_hbox_new(FALSE, 5); | |
101 vbox = gtk_vbox_new(FALSE, 5); | |
102 | |
103 awaytext = gtk_text_new(NULL, NULL); | |
104 g_snprintf(buf, sizeof(buf), "%s", a->message); | |
105 vscrollbar = gtk_vscrollbar_new(GTK_TEXT(awaytext)->vadj); | |
106 gtk_widget_show(vscrollbar); | |
107 gtk_widget_set_usize(awaytext, 225, 75); | |
108 gtk_text_set_word_wrap(GTK_TEXT(awaytext), TRUE); | |
109 gtk_widget_show(awaytext); | |
110 gtk_text_freeze(GTK_TEXT(awaytext)); | |
111 gtk_text_insert(GTK_TEXT(awaytext), NULL, NULL, NULL, buf, -1); | |
112 gtk_widget_show(awaytext); | |
113 | |
535
f03f041c1aa9
[gaim-migrate @ 545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
114 if (display_options & OPT_DISP_COOL_LOOK) |
f03f041c1aa9
[gaim-migrate @ 545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
445
diff
changeset
|
115 gtk_button_set_relief(GTK_BUTTON(back), GTK_RELIEF_NONE); |
1 | 116 |
117 /* Put the buttons in the box */ | |
118 gtk_box_pack_start(GTK_BOX(bbox), back, TRUE, TRUE, 10); | |
119 | |
120 gtk_box_pack_start(GTK_BOX(topbox), awaytext, FALSE, FALSE, 5); | |
121 | |
122 /* And the boxes in the box */ | |
123 gtk_box_pack_start(GTK_BOX(vbox), topbox, TRUE, TRUE, 5); | |
124 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 5); | |
125 | |
126 /* Handle closes right */ | |
127 gtk_signal_connect(GTK_OBJECT(imaway), "destroy", | |
128 GTK_SIGNAL_FUNC(destroy_im_away), imaway); | |
129 gtk_signal_connect(GTK_OBJECT(back), "clicked", | |
130 GTK_SIGNAL_FUNC(do_im_back), imaway); | |
131 | |
132 /* Finish up */ | |
133 gtk_widget_show(back); | |
134 gtk_widget_show(topbox); | |
135 gtk_widget_show(bbox); | |
136 gtk_widget_show(vbox); | |
137 if (strlen(a->name)) | |
138 gtk_window_set_title(GTK_WINDOW(imaway), a->name); | |
139 else | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
140 gtk_window_set_title(GTK_WINDOW(imaway), _("Gaim - Away!")); |
1 | 141 gtk_window_set_focus(GTK_WINDOW(imaway), back); |
142 gtk_container_add(GTK_CONTAINER(imaway), vbox); | |
143 awaymessage = a; | |
144 | |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
145 } else { |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
146 destroy_im_away(); |
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
147 do_away_message(w, a); |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
148 return; |
445
e4c34ca88d9b
[gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
149 } |
1 | 150 |
151 /* New away message... Clear out the old sent_aways */ | |
152 while(cnv) { | |
153 c = (struct conversation *)cnv->data; | |
154 c->sent_away = 0; | |
155 cnv = cnv->next; | |
156 } | |
157 | |
158 | |
79 | 159 buf2 = g_malloc(strlen(awaymessage->message)*4 + 1); |
160 strcpy(buf2, awaymessage->message); | |
1 | 161 escape_text(buf2); |
162 serv_set_away(buf2); | |
79 | 163 g_free(buf2); |
1 | 164 gtk_widget_show(imaway); |
780
c714def9cebb
[gaim-migrate @ 790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
746
diff
changeset
|
165 plugin_event(event_away, 0, 0, 0); |
1 | 166 } |
167 | |
168 void rem_away_mess(GtkWidget *w, struct away_message *a) | |
169 { | |
18 | 170 #ifdef USE_APPLET |
171 char *awayname; | |
79 | 172 awayname = g_malloc(sizeof (*awayname) * (6 + strlen(a->name))); |
18 | 173 awayname[0] = '\0'; |
174 strcat(awayname, "away/"); | |
175 strcat(awayname, a->name); | |
176 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname); | |
177 #endif | |
1 | 178 away_messages = g_list_remove(away_messages, a); |
179 g_free(a); | |
180 do_away_menu(); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
181 save_prefs(); |
1 | 182 } |
183 | |
184 | |
185 void do_away_menu() | |
186 { | |
187 GtkWidget *menuitem; | |
188 static GtkWidget *remmenu; | |
189 GtkWidget *remitem; | |
190 GtkWidget *label; | |
191 GtkWidget *sep; | |
192 GList *l; | |
193 GtkWidget *list_item; | |
194 GList *awy = away_messages; | |
195 struct away_message *a; | |
196 | |
18 | 197 #ifdef USE_APPLET |
198 remove_applet_away(); | |
199 if (imaway) | |
200 applet_widget_register_callback(APPLET_WIDGET(applet), | |
201 "away", | |
202 _("Back"), | |
203 (AppletCallbackFunc)do_im_back, | |
204 NULL); | |
205 else | |
206 insert_applet_away(); | |
207 #endif | |
1 | 208 |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
209 if (prefs_away_list != NULL) { |
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
210 gtk_list_clear_items(GTK_LIST(prefs_away_list), 0, -1); |
1 | 211 while(awy) { |
212 a = (struct away_message *)awy->data; | |
213 label = gtk_label_new(a->name); | |
214 list_item = gtk_list_item_new(); | |
215 gtk_container_add(GTK_CONTAINER(list_item), label); | |
216 gtk_signal_connect(GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(away_list_clicked), a); | |
821 | 217 /* gtk_signal_connect(GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(away_list_unclicked), a);*/ |
1 | 218 gtk_object_set_user_data(GTK_OBJECT(list_item), a); |
219 | |
220 gtk_widget_show(label); | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
221 gtk_container_add(GTK_CONTAINER(prefs_away_list), list_item); |
1 | 222 gtk_widget_show(list_item); |
223 | |
224 awy = awy->next; | |
225 } | |
226 if (away_messages != NULL) | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
227 gtk_list_select_item(GTK_LIST(prefs_away_list), 0); |
1 | 228 } |
229 | |
652
4d3285caa191
[gaim-migrate @ 662]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
621
diff
changeset
|
230 if (!awaymenu) return; |
1 | 231 l = gtk_container_children(GTK_CONTAINER(awaymenu)); |
232 | |
233 while(l) { | |
234 gtk_widget_destroy(GTK_WIDGET(l->data)); | |
235 l = l->next; | |
236 } | |
237 | |
238 | |
239 remmenu = gtk_menu_new(); | |
240 | |
241 | |
242 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
243 menuitem = gtk_menu_item_new_with_label(_("New Away Message")); |
1 | 244 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
245 gtk_widget_show(menuitem); | |
246 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL); | |
247 | |
248 | |
22 | 249 awy = away_messages; |
1 | 250 while(awy) { |
251 a = (struct away_message *)awy->data; | |
252 | |
253 remitem = gtk_menu_item_new_with_label(a->name); | |
254 gtk_menu_append(GTK_MENU(remmenu), remitem); | |
255 gtk_widget_show(remitem); | |
256 gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a); | |
257 | |
258 awy = awy->next; | |
259 | |
260 } | |
261 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
262 menuitem = gtk_menu_item_new_with_label(_("Remove Away Message")); |
1 | 263 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
264 gtk_widget_show(menuitem); | |
265 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu); | |
266 gtk_widget_show(remmenu); | |
267 | |
268 | |
269 sep = gtk_hseparator_new(); | |
270 menuitem = gtk_menu_item_new(); | |
271 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
272 gtk_container_add(GTK_CONTAINER(menuitem), sep); | |
273 gtk_widget_set_sensitive(menuitem, FALSE); | |
274 gtk_widget_show(menuitem); | |
275 gtk_widget_show(sep); | |
276 | |
277 awy = away_messages; | |
278 | |
279 while(awy) { | |
280 a = (struct away_message *)awy->data; | |
281 | |
282 menuitem = gtk_menu_item_new_with_label(a->name); | |
283 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
284 gtk_widget_show(menuitem); | |
285 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a); | |
286 | |
287 awy = awy->next; | |
288 | |
289 } | |
290 | |
291 } | |
292 | |
293 | |
294 | |
295 | |
296 | |
297 |