Mercurial > pidgin
annotate src/away.c @ 1000:91b7377e7b45
[gaim-migrate @ 1010]
Plugins work again, I think. There may still be some bugginess.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 16 Oct 2000 20:11:18 +0000 |
parents | fa681641643d |
children | 77b6bc7288d3 |
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; | |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
960
diff
changeset
|
65 plugin_event(event_back, 0, 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", | |
939 | 129 GTK_SIGNAL_FUNC(do_im_back), imaway); |
1 | 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 serv_set_away(buf2); |
79 | 163 g_free(buf2); |
1 | 164 gtk_widget_show(imaway); |
1000
91b7377e7b45
[gaim-migrate @ 1010]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
960
diff
changeset
|
165 plugin_event(event_away, 0, 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 | |
940 | 178 away_messages = g_slist_remove(away_messages, a); |
1 | 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; | |
940 | 194 GSList *awy = away_messages; |
1 | 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 | |
940 | 224 awy = g_slist_next(awy); |
1 | 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 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
241 menuitem = gtk_menu_item_new_with_label(_("New Away Message")); |
1 | 242 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
243 gtk_widget_show(menuitem); | |
244 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL); | |
245 | |
22 | 246 awy = away_messages; |
1 | 247 while(awy) { |
248 a = (struct away_message *)awy->data; | |
249 | |
250 remitem = gtk_menu_item_new_with_label(a->name); | |
251 gtk_menu_append(GTK_MENU(remmenu), remitem); | |
252 gtk_widget_show(remitem); | |
253 gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a); | |
254 | |
940 | 255 awy = g_slist_next(awy); |
1 | 256 |
257 } | |
258 | |
350
fd3cc0a28d5d
[gaim-migrate @ 360]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
259 menuitem = gtk_menu_item_new_with_label(_("Remove Away Message")); |
1 | 260 gtk_menu_append(GTK_MENU(awaymenu), menuitem); |
261 gtk_widget_show(menuitem); | |
262 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu); | |
263 gtk_widget_show(remmenu); | |
264 | |
265 sep = gtk_hseparator_new(); | |
266 menuitem = gtk_menu_item_new(); | |
267 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
268 gtk_container_add(GTK_CONTAINER(menuitem), sep); | |
269 gtk_widget_set_sensitive(menuitem, FALSE); | |
270 gtk_widget_show(menuitem); | |
271 gtk_widget_show(sep); | |
272 | |
273 awy = away_messages; | |
274 | |
275 while(awy) { | |
276 a = (struct away_message *)awy->data; | |
277 | |
278 menuitem = gtk_menu_item_new_with_label(a->name); | |
279 gtk_menu_append(GTK_MENU(awaymenu), menuitem); | |
280 gtk_widget_show(menuitem); | |
281 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a); | |
282 | |
940 | 283 awy = g_slist_next(awy); |
1 | 284 |
285 } | |
286 | |
287 } | |
288 | |
289 | |
290 | |
291 | |
292 | |
293 |