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
|
|
22 #ifdef USE_APPLET
|
|
23 #include <gnome.h>
|
|
24 #include <applet-widget.h>
|
|
25 #include "gnome_applet_mgr.h"
|
|
26 #endif /* USE_APPLET */
|
|
27 #include <string.h>
|
|
28 #include <stdio.h>
|
|
29 #include <stdlib.h>
|
|
30 #include <time.h>
|
|
31
|
|
32 #include <gtk/gtk.h>
|
|
33 #include "gaim.h"
|
|
34
|
|
35 static GtkWidget *imaway=NULL;
|
84
|
36 #ifdef USE_APPLET
|
|
37 extern enum gaim_user_states MRI_user_status;
|
|
38 #endif
|
1
|
39
|
|
40 GtkWidget *awaymenu;
|
|
41 struct away_message *awaymessage = NULL;
|
|
42
|
|
43 static void destroy_im_away()
|
|
44 {
|
|
45 if (imaway)
|
|
46 gtk_widget_destroy(imaway);
|
|
47 imaway=NULL;
|
|
48 }
|
|
49
|
|
50 void do_im_back(GtkWidget *w, GtkWidget *x)
|
|
51 {
|
|
52 #ifdef USE_APPLET
|
18
|
53 if(!blist) applet_widget_unregister_callback(APPLET_WIDGET(applet),"buddy");
|
1
|
54 applet_widget_unregister_callback(APPLET_WIDGET(applet),"away");
|
|
55 if(!blist) {
|
|
56 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
57 "buddy",
|
|
58 _("Buddy List"),
|
|
59 (AppletCallbackFunc)make_buddy,
|
|
60 NULL);
|
|
61 }
|
84
|
62 MRI_user_status = online;
|
18
|
63 insert_applet_away();
|
1
|
64 #endif /* USE_APPLET */
|
|
65 if (imaway) {
|
|
66 gtk_widget_destroy(imaway);
|
|
67 imaway=NULL;
|
|
68 }
|
|
69
|
|
70 serv_set_away(NULL);
|
|
71 awaymessage = NULL;
|
|
72 }
|
|
73
|
|
74 void do_away_message(GtkWidget *w, struct away_message *a)
|
|
75 {
|
|
76 GtkWidget *back;
|
|
77 GtkWidget *awaytext;
|
|
78 GtkWidget *vscrollbar;
|
|
79 GtkWidget *bbox;
|
|
80 GtkWidget *vbox;
|
|
81 GtkWidget *topbox;
|
|
82 char *buf2;
|
|
83 char buf[BUF_LONG];
|
|
84 GList *cnv = conversations;
|
|
85 struct conversation *c;
|
|
86
|
18
|
87 #ifdef USE_APPLET
|
|
88 if(!blist) applet_widget_unregister_callback(APPLET_WIDGET(applet),"buddy");
|
|
89 remove_applet_away();
|
|
90 if(!blist) applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
91 "buddy",
|
|
92 _("Buddy List"),
|
|
93 (AppletCallbackFunc)make_buddy,
|
|
94 NULL);
|
|
95 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
96 "away",
|
|
97 _("Back"),
|
|
98 (AppletCallbackFunc) do_im_back,
|
|
99 NULL);
|
84
|
100 MRI_user_status = away;
|
18
|
101 #endif
|
|
102
|
1
|
103 if (!imaway) {
|
|
104 imaway = gtk_window_new(GTK_WINDOW_DIALOG);
|
|
105 gtk_widget_realize(imaway);
|
|
106 aol_icon(imaway->window);
|
|
107 back = gtk_button_new_with_label("I'm Back!");
|
|
108 bbox = gtk_hbox_new(TRUE, 10);
|
|
109 topbox = gtk_hbox_new(FALSE, 5);
|
|
110 vbox = gtk_vbox_new(FALSE, 5);
|
|
111
|
|
112 awaytext = gtk_text_new(NULL, NULL);
|
|
113 g_snprintf(buf, sizeof(buf), "%s", a->message);
|
|
114 vscrollbar = gtk_vscrollbar_new(GTK_TEXT(awaytext)->vadj);
|
|
115 gtk_widget_show(vscrollbar);
|
|
116 gtk_widget_set_usize(awaytext, 225, 75);
|
|
117 gtk_text_set_word_wrap(GTK_TEXT(awaytext), TRUE);
|
|
118 gtk_widget_show(awaytext);
|
|
119 gtk_text_freeze(GTK_TEXT(awaytext));
|
|
120 gtk_text_insert(GTK_TEXT(awaytext), NULL, NULL, NULL, buf, -1);
|
|
121 gtk_widget_show(awaytext);
|
|
122
|
|
123
|
|
124 /* Put the buttons in the box */
|
|
125 gtk_box_pack_start(GTK_BOX(bbox), back, TRUE, TRUE, 10);
|
|
126
|
|
127 gtk_box_pack_start(GTK_BOX(topbox), awaytext, FALSE, FALSE, 5);
|
|
128
|
|
129 /* And the boxes in the box */
|
|
130 gtk_box_pack_start(GTK_BOX(vbox), topbox, TRUE, TRUE, 5);
|
|
131 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 5);
|
|
132
|
|
133 /* Handle closes right */
|
|
134 gtk_signal_connect(GTK_OBJECT(imaway), "destroy",
|
|
135 GTK_SIGNAL_FUNC(destroy_im_away), imaway);
|
|
136 gtk_signal_connect(GTK_OBJECT(back), "clicked",
|
|
137 GTK_SIGNAL_FUNC(do_im_back), imaway);
|
|
138
|
|
139 /* Finish up */
|
|
140 gtk_widget_show(back);
|
|
141 gtk_widget_show(topbox);
|
|
142 gtk_widget_show(bbox);
|
|
143 gtk_widget_show(vbox);
|
|
144 if (strlen(a->name))
|
|
145 gtk_window_set_title(GTK_WINDOW(imaway), a->name);
|
|
146 else
|
|
147 gtk_window_set_title(GTK_WINDOW(imaway), "Gaim - Away!");
|
|
148 gtk_window_set_focus(GTK_WINDOW(imaway), back);
|
|
149 gtk_container_add(GTK_CONTAINER(imaway), vbox);
|
|
150 awaymessage = a;
|
|
151
|
|
152 }
|
|
153
|
|
154 /* New away message... Clear out the old sent_aways */
|
|
155 while(cnv) {
|
|
156 c = (struct conversation *)cnv->data;
|
|
157 c->sent_away = 0;
|
|
158 cnv = cnv->next;
|
|
159 }
|
|
160
|
|
161
|
79
|
162 buf2 = g_malloc(strlen(awaymessage->message)*4 + 1);
|
|
163 strcpy(buf2, awaymessage->message);
|
1
|
164 escape_text(buf2);
|
|
165 serv_set_away(buf2);
|
79
|
166 g_free(buf2);
|
1
|
167 gtk_widget_show(imaway);
|
|
168 }
|
|
169
|
|
170 void rem_away_mess(GtkWidget *w, struct away_message *a)
|
|
171 {
|
18
|
172 #ifdef USE_APPLET
|
|
173 char *awayname;
|
79
|
174 awayname = g_malloc(sizeof (*awayname) * (6 + strlen(a->name)));
|
18
|
175 awayname[0] = '\0';
|
|
176 strcat(awayname, "away/");
|
|
177 strcat(awayname, a->name);
|
|
178 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname);
|
|
179 #endif
|
1
|
180 away_messages = g_list_remove(away_messages, a);
|
|
181 g_free(a);
|
|
182 do_away_menu();
|
|
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
|
|
210 if (pd != NULL) {
|
|
211 gtk_list_clear_items(GTK_LIST(pd->away_list), 0, -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);
|
|
218 gtk_signal_connect(GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(away_list_unclicked), a);
|
|
219 gtk_object_set_user_data(GTK_OBJECT(list_item), a);
|
|
220
|
|
221 gtk_widget_show(label);
|
|
222 gtk_container_add(GTK_CONTAINER(pd->away_list), list_item);
|
|
223 gtk_widget_show(list_item);
|
|
224
|
|
225 awy = awy->next;
|
|
226 }
|
|
227 if (away_messages != NULL)
|
|
228 gtk_list_select_item(GTK_LIST(pd->away_list), 0);
|
|
229 }
|
|
230
|
|
231
|
|
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
|
|
244 menuitem = gtk_menu_item_new_with_label("New Away Message");
|
|
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
|
|
263 menuitem = gtk_menu_item_new_with_label("Remove Away Message");
|
|
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
|