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;
|
|
36
|
|
37 GtkWidget *awaymenu;
|
|
38 struct away_message *awaymessage = NULL;
|
|
39
|
|
40 static void destroy_im_away()
|
|
41 {
|
|
42 if (imaway)
|
|
43 gtk_widget_destroy(imaway);
|
|
44 imaway=NULL;
|
|
45 }
|
|
46
|
|
47 void do_im_back(GtkWidget *w, GtkWidget *x)
|
|
48 {
|
|
49 #ifdef USE_APPLET
|
18
|
50 if(!blist) applet_widget_unregister_callback(APPLET_WIDGET(applet),"buddy");
|
1
|
51 applet_widget_unregister_callback(APPLET_WIDGET(applet),"away");
|
|
52 if(!blist) {
|
|
53 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
54 "buddy",
|
|
55 _("Buddy List"),
|
|
56 (AppletCallbackFunc)make_buddy,
|
|
57 NULL);
|
|
58 }
|
18
|
59 insert_applet_away();
|
1
|
60 #endif /* USE_APPLET */
|
|
61 if (imaway) {
|
|
62 gtk_widget_destroy(imaway);
|
|
63 imaway=NULL;
|
|
64 }
|
|
65
|
|
66 serv_set_away(NULL);
|
|
67 awaymessage = NULL;
|
|
68 }
|
|
69
|
|
70 void do_away_message(GtkWidget *w, struct away_message *a)
|
|
71 {
|
|
72 GtkWidget *back;
|
|
73 GtkWidget *awaytext;
|
|
74 GtkWidget *vscrollbar;
|
|
75 GtkWidget *bbox;
|
|
76 GtkWidget *vbox;
|
|
77 GtkWidget *topbox;
|
|
78 char *buf2;
|
|
79 char buf[BUF_LONG];
|
|
80 GList *cnv = conversations;
|
|
81 struct conversation *c;
|
|
82
|
18
|
83 #ifdef USE_APPLET
|
|
84 if(!blist) applet_widget_unregister_callback(APPLET_WIDGET(applet),"buddy");
|
|
85 remove_applet_away();
|
|
86 if(!blist) applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
87 "buddy",
|
|
88 _("Buddy List"),
|
|
89 (AppletCallbackFunc)make_buddy,
|
|
90 NULL);
|
|
91 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
92 "away",
|
|
93 _("Back"),
|
|
94 (AppletCallbackFunc) do_im_back,
|
|
95 NULL);
|
|
96 #endif
|
|
97
|
1
|
98 if (!imaway) {
|
|
99 imaway = gtk_window_new(GTK_WINDOW_DIALOG);
|
|
100 gtk_widget_realize(imaway);
|
|
101 aol_icon(imaway->window);
|
|
102 back = gtk_button_new_with_label("I'm Back!");
|
|
103 bbox = gtk_hbox_new(TRUE, 10);
|
|
104 topbox = gtk_hbox_new(FALSE, 5);
|
|
105 vbox = gtk_vbox_new(FALSE, 5);
|
|
106
|
|
107 awaytext = gtk_text_new(NULL, NULL);
|
|
108 g_snprintf(buf, sizeof(buf), "%s", a->message);
|
|
109 vscrollbar = gtk_vscrollbar_new(GTK_TEXT(awaytext)->vadj);
|
|
110 gtk_widget_show(vscrollbar);
|
|
111 gtk_widget_set_usize(awaytext, 225, 75);
|
|
112 gtk_text_set_word_wrap(GTK_TEXT(awaytext), TRUE);
|
|
113 gtk_widget_show(awaytext);
|
|
114 gtk_text_freeze(GTK_TEXT(awaytext));
|
|
115 gtk_text_insert(GTK_TEXT(awaytext), NULL, NULL, NULL, buf, -1);
|
|
116 gtk_widget_show(awaytext);
|
|
117
|
|
118
|
|
119 /* Put the buttons in the box */
|
|
120 gtk_box_pack_start(GTK_BOX(bbox), back, TRUE, TRUE, 10);
|
|
121
|
|
122 gtk_box_pack_start(GTK_BOX(topbox), awaytext, FALSE, FALSE, 5);
|
|
123
|
|
124 /* And the boxes in the box */
|
|
125 gtk_box_pack_start(GTK_BOX(vbox), topbox, TRUE, TRUE, 5);
|
|
126 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 5);
|
|
127
|
|
128 /* Handle closes right */
|
|
129 gtk_signal_connect(GTK_OBJECT(imaway), "destroy",
|
|
130 GTK_SIGNAL_FUNC(destroy_im_away), imaway);
|
|
131 gtk_signal_connect(GTK_OBJECT(back), "clicked",
|
|
132 GTK_SIGNAL_FUNC(do_im_back), imaway);
|
|
133
|
|
134 /* Finish up */
|
|
135 gtk_widget_show(back);
|
|
136 gtk_widget_show(topbox);
|
|
137 gtk_widget_show(bbox);
|
|
138 gtk_widget_show(vbox);
|
|
139 if (strlen(a->name))
|
|
140 gtk_window_set_title(GTK_WINDOW(imaway), a->name);
|
|
141 else
|
|
142 gtk_window_set_title(GTK_WINDOW(imaway), "Gaim - Away!");
|
|
143 gtk_window_set_focus(GTK_WINDOW(imaway), back);
|
|
144 gtk_container_add(GTK_CONTAINER(imaway), vbox);
|
|
145 awaymessage = a;
|
|
146
|
|
147 }
|
|
148
|
|
149 /* New away message... Clear out the old sent_aways */
|
|
150 while(cnv) {
|
|
151 c = (struct conversation *)cnv->data;
|
|
152 c->sent_away = 0;
|
|
153 cnv = cnv->next;
|
|
154 }
|
|
155
|
|
156
|
|
157 buf2 = g_strdup(awaymessage->message);
|
|
158 escape_text(buf2);
|
|
159 serv_set_away(buf2);
|
|
160 // g_free(buf2);
|
|
161 gtk_widget_show(imaway);
|
|
162 }
|
|
163
|
|
164 void rem_away_mess(GtkWidget *w, struct away_message *a)
|
|
165 {
|
18
|
166 #ifdef USE_APPLET
|
|
167 char *awayname;
|
|
168 awayname = malloc(sizeof *awayname * (6 + strlen(a->name)));
|
|
169 awayname[0] = '\0';
|
|
170 strcat(awayname, "away/");
|
|
171 strcat(awayname, a->name);
|
|
172 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname);
|
|
173 #endif
|
1
|
174 away_messages = g_list_remove(away_messages, a);
|
|
175 g_free(a);
|
|
176 do_away_menu();
|
|
177 }
|
|
178
|
|
179
|
|
180 void do_away_menu()
|
|
181 {
|
|
182 GtkWidget *menuitem;
|
|
183 static GtkWidget *remmenu;
|
|
184 GtkWidget *remitem;
|
|
185 GtkWidget *label;
|
|
186 GtkWidget *sep;
|
|
187 GList *l;
|
|
188 GtkWidget *list_item;
|
|
189 GList *awy = away_messages;
|
|
190 struct away_message *a;
|
|
191
|
18
|
192 #ifdef USE_APPLET
|
|
193 remove_applet_away();
|
|
194 if (imaway)
|
|
195 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
196 "away",
|
|
197 _("Back"),
|
|
198 (AppletCallbackFunc)do_im_back,
|
|
199 NULL);
|
|
200 else
|
|
201 insert_applet_away();
|
|
202 #endif
|
1
|
203
|
|
204 if (pd != NULL) {
|
|
205 gtk_list_clear_items(GTK_LIST(pd->away_list), 0, -1);
|
|
206 while(awy) {
|
|
207 a = (struct away_message *)awy->data;
|
|
208 label = gtk_label_new(a->name);
|
|
209 list_item = gtk_list_item_new();
|
|
210 gtk_container_add(GTK_CONTAINER(list_item), label);
|
|
211 gtk_signal_connect(GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(away_list_clicked), a);
|
|
212 gtk_signal_connect(GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(away_list_unclicked), a);
|
|
213 gtk_object_set_user_data(GTK_OBJECT(list_item), a);
|
|
214
|
|
215 gtk_widget_show(label);
|
|
216 gtk_container_add(GTK_CONTAINER(pd->away_list), list_item);
|
|
217 gtk_widget_show(list_item);
|
|
218
|
|
219 awy = awy->next;
|
|
220 }
|
|
221 if (away_messages != NULL)
|
|
222 gtk_list_select_item(GTK_LIST(pd->away_list), 0);
|
|
223 }
|
|
224
|
|
225
|
|
226 l = gtk_container_children(GTK_CONTAINER(awaymenu));
|
|
227
|
|
228 while(l) {
|
|
229 gtk_widget_destroy(GTK_WIDGET(l->data));
|
|
230 l = l->next;
|
|
231 }
|
|
232
|
|
233
|
|
234 remmenu = gtk_menu_new();
|
|
235
|
|
236
|
|
237
|
|
238 menuitem = gtk_menu_item_new_with_label("New Away Message");
|
|
239 gtk_menu_append(GTK_MENU(awaymenu), menuitem);
|
|
240 gtk_widget_show(menuitem);
|
|
241 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL);
|
|
242
|
|
243
|
22
|
244 awy = away_messages;
|
1
|
245 while(awy) {
|
|
246 a = (struct away_message *)awy->data;
|
|
247
|
|
248 remitem = gtk_menu_item_new_with_label(a->name);
|
|
249 gtk_menu_append(GTK_MENU(remmenu), remitem);
|
|
250 gtk_widget_show(remitem);
|
|
251 gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a);
|
|
252
|
|
253 awy = awy->next;
|
|
254
|
|
255 }
|
|
256
|
|
257 menuitem = gtk_menu_item_new_with_label("Remove Away Message");
|
|
258 gtk_menu_append(GTK_MENU(awaymenu), menuitem);
|
|
259 gtk_widget_show(menuitem);
|
|
260 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu);
|
|
261 gtk_widget_show(remmenu);
|
|
262
|
|
263
|
|
264 sep = gtk_hseparator_new();
|
|
265 menuitem = gtk_menu_item_new();
|
|
266 gtk_menu_append(GTK_MENU(awaymenu), menuitem);
|
|
267 gtk_container_add(GTK_CONTAINER(menuitem), sep);
|
|
268 gtk_widget_set_sensitive(menuitem, FALSE);
|
|
269 gtk_widget_show(menuitem);
|
|
270 gtk_widget_show(sep);
|
|
271
|
|
272 awy = away_messages;
|
|
273
|
|
274 while(awy) {
|
|
275 a = (struct away_message *)awy->data;
|
|
276
|
|
277 menuitem = gtk_menu_item_new_with_label(a->name);
|
|
278 gtk_menu_append(GTK_MENU(awaymenu), menuitem);
|
|
279 gtk_widget_show(menuitem);
|
|
280 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a);
|
|
281
|
|
282 awy = awy->next;
|
|
283
|
|
284 }
|
|
285
|
|
286 }
|
|
287
|
|
288
|
|
289
|
|
290
|
|
291
|
|
292
|