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