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_THEMES
|
|
23 #include <gnome.h>
|
|
24 #else
|
|
25 #ifdef USE_APPLET
|
|
26 #include "gnome_applet_mgr.h"
|
|
27 #include <gnome.h>
|
|
28 #endif /* USE_APPLET */
|
|
29 #endif /* USE_THEMES */
|
|
30 #include <gtk/gtk.h>
|
|
31 #include <gdk/gdkx.h>
|
|
32 #include <unistd.h>
|
|
33 #include <netinet/in.h>
|
|
34 #include <arpa/inet.h>
|
|
35 #include <sys/wait.h>
|
|
36 #include <stdio.h>
|
|
37 #include <string.h>
|
|
38 #include <stdarg.h>
|
|
39 #include <stdlib.h>
|
|
40 #include "gaim.h"
|
|
41 #ifndef USE_APPLET
|
|
42 #include "pixmaps/logo.xpm"
|
|
43 #endif /* USE_APPLET */
|
|
44
|
|
45 static GtkWidget *name;
|
|
46 static GtkWidget *pass;
|
|
47 static GtkWidget *signon;
|
|
48 static GtkWidget *cancel;
|
|
49 static GtkWidget *progress;
|
|
50 static GtkWidget *notice;
|
|
51
|
|
52 GList *permit = NULL;
|
|
53 GList *deny = NULL;
|
|
54 GList *log_conversations = NULL;
|
|
55 GList *buddy_pounces = NULL;
|
|
56 GList *away_messages = NULL;
|
|
57 GList *groups = NULL;
|
|
58 GList *buddy_chats = NULL;
|
|
59 GList *conversations = NULL;
|
|
60 GList *chat_rooms = NULL;
|
|
61
|
|
62 GtkWidget *mainwindow = NULL;
|
|
63
|
|
64 char toc_addy[16];
|
26
|
65 char *quad_addr = NULL;
|
1
|
66
|
|
67
|
|
68 void cancel_logon(void)
|
|
69 {
|
|
70 #ifdef USE_APPLET
|
|
71 set_applet_draw_closed();
|
|
72 AppletCancelLogon();
|
|
73 gtk_widget_hide(mainwindow);
|
|
74 #else
|
|
75 exit(0);
|
|
76 #endif /* USE_APPLET */
|
|
77 }
|
|
78
|
|
79 void set_login_progress(int howfar, char *whattosay)
|
|
80 {
|
|
81 gtk_progress_bar_update(GTK_PROGRESS_BAR(progress),
|
|
82 ((float)howfar / (float)LOGIN_STEPS));
|
|
83 gtk_statusbar_pop(GTK_STATUSBAR(notice), 1);
|
|
84 gtk_statusbar_push(GTK_STATUSBAR(notice), 1, whattosay);
|
|
85
|
|
86 while (gtk_events_pending())
|
|
87 gtk_main_iteration();
|
|
88
|
|
89 /* Why do I need these? */
|
|
90 usleep(10);
|
|
91 while (gtk_events_pending())
|
|
92 gtk_main_iteration();
|
|
93
|
|
94 }
|
|
95
|
|
96 void hide_login_progress(char *why)
|
|
97 {
|
|
98 gtk_progress_bar_update(GTK_PROGRESS_BAR(progress),
|
|
99 0);
|
|
100 gtk_statusbar_pop(GTK_STATUSBAR(notice), 1);
|
|
101 gtk_statusbar_push(GTK_STATUSBAR(notice), 1, why);
|
|
102
|
|
103 while (gtk_events_pending())
|
|
104 gtk_main_iteration();
|
|
105
|
|
106 /* Why do I need these? */
|
|
107 usleep(10);
|
|
108 while (gtk_events_pending())
|
|
109 gtk_main_iteration();
|
|
110 }
|
|
111
|
|
112 void dologin(GtkWidget *widget, GtkWidget *w)
|
|
113 {
|
84
|
114 static gboolean running = FALSE;
|
1
|
115 char *username = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(name)->entry));
|
|
116 char *password = gtk_entry_get_text(GTK_ENTRY(pass));
|
|
117
|
|
118 if (query_state() != STATE_OFFLINE)
|
|
119 return;
|
|
120
|
|
121 if (!strlen(username)) {
|
|
122 hide_login_progress("Please enter your logon");
|
|
123 return;
|
|
124 }
|
|
125 if (!strlen(password)) {
|
|
126 hide_login_progress("You must give your password");
|
|
127 return;
|
|
128 }
|
|
129
|
|
130 #ifdef USE_APPLET
|
|
131 set_applet_draw_closed();
|
|
132 setUserState(signing_on);
|
|
133 #endif /* USE_APPLET */
|
|
134
|
84
|
135 if (running) return;
|
|
136 running = TRUE;
|
1
|
137
|
84
|
138 if (serv_login(username, password) < 0) {
|
|
139 running = FALSE;
|
1
|
140 return;
|
84
|
141 }
|
1
|
142
|
84
|
143 #ifdef USE_APPLET
|
|
144 applet_widget_unregister_callback(APPLET_WIDGET(applet),"signon");
|
|
145 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
146 "buddy",
|
|
147 _("Buddy List"),
|
|
148 (AppletCallbackFunc)make_buddy,
|
|
149 NULL);
|
|
150 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
151 "signoff",
|
|
152 _("Signoff"),
|
|
153 signoff,
|
|
154 NULL);
|
|
155 #endif
|
|
156 running = FALSE;
|
|
157 return;
|
1
|
158 }
|
|
159
|
|
160
|
|
161
|
|
162
|
|
163 void doenter(GtkWidget *widget, GtkWidget *w)
|
|
164 {
|
|
165 if (widget == name) {
|
|
166 gtk_entry_set_text(GTK_ENTRY(pass),"");
|
|
167 gtk_entry_select_region(GTK_ENTRY(GTK_COMBO(name)->entry), 0, 0);
|
|
168 gtk_window_set_focus(GTK_WINDOW(mainwindow), pass);
|
|
169 } else if (widget == pass) {
|
|
170 gtk_window_set_focus(GTK_WINDOW(mainwindow), signon);
|
|
171 } else {
|
|
172 g_print("what did you press enter on?\n");
|
|
173 }
|
|
174
|
|
175 }
|
|
176
|
|
177
|
|
178 static void combo_changed(GtkWidget *w, GtkWidget *combo)
|
|
179 {
|
|
180 char *txt = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(combo)->entry), 0, -1);
|
|
181 struct aim_user *u;
|
|
182
|
25
|
183 if (!(general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
184 g_free(txt);
|
1
|
185 return;
|
25
|
186 }
|
|
187
|
1
|
188 u = find_user(txt);
|
|
189
|
|
190 if (u != NULL) {
|
|
191 gtk_entry_set_text(GTK_ENTRY(pass), u->password);
|
|
192 } else {
|
|
193 gtk_entry_set_text(GTK_ENTRY(pass), "");
|
|
194 }
|
25
|
195
|
|
196 g_free(txt);
|
1
|
197 return;
|
|
198 }
|
|
199
|
|
200 static GList *combo_user_names()
|
|
201 {
|
|
202 GList *usr = aim_users;
|
|
203 GList *tmp = NULL;
|
|
204 struct aim_user *u;
|
|
205
|
|
206
|
|
207 if (!usr)
|
|
208 return g_list_append(NULL, "<unknown>");
|
|
209
|
|
210 while(usr) {
|
|
211 u = (struct aim_user *)usr->data;
|
|
212 tmp = g_list_append(tmp, g_strdup(u->username));
|
|
213 usr = usr->next;
|
|
214
|
|
215 }
|
|
216
|
|
217 return tmp;
|
|
218 }
|
|
219
|
|
220
|
|
221
|
|
222 void show_login()
|
|
223 {
|
|
224 GtkWidget *options;
|
|
225 GtkWidget *reg;
|
|
226 GtkWidget *bbox;
|
|
227 GtkWidget *sbox;
|
|
228 GtkWidget *label;
|
|
229 GtkWidget *table;
|
|
230 GtkWidget *remember;
|
|
231
|
|
232 #ifndef USE_APPLET
|
|
233 GtkWidget *pmw;
|
|
234 GdkPixmap *pm;
|
|
235 GtkStyle *style;
|
|
236 GdkBitmap *mask;
|
|
237 #endif /* USE_APPLET */
|
|
238
|
|
239 if (mainwindow) {
|
|
240 gtk_widget_show(mainwindow);
|
|
241 return;
|
|
242 }
|
|
243
|
|
244 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
245 signon = gtk_button_new_with_label("Signon");
|
|
246 cancel = gtk_button_new_with_label("Cancel");
|
|
247 reg = gtk_button_new_with_label("Register");
|
|
248 options = gtk_button_new_with_label("Options");
|
|
249 table = gtk_table_new(8, 2, FALSE);
|
|
250 name = gtk_combo_new();
|
|
251 pass = gtk_entry_new();
|
|
252 notice = gtk_statusbar_new();
|
|
253 progress = gtk_progress_bar_new();
|
|
254
|
|
255 gtk_combo_set_popdown_strings(GTK_COMBO(name), combo_user_names());
|
|
256
|
|
257 /* Make the buttons do stuff */
|
|
258 /* Clicking the button initiates a login */
|
|
259 gtk_signal_connect(GTK_OBJECT(signon), "clicked",
|
|
260 GTK_SIGNAL_FUNC(dologin), mainwindow);
|
|
261 gtk_signal_connect(GTK_OBJECT(cancel), "clicked",
|
|
262 GTK_SIGNAL_FUNC(cancel_logon), mainwindow);
|
|
263 /* Allow user to change prefs before logging in */
|
|
264 gtk_signal_connect(GTK_OBJECT(options), "clicked",
|
|
265 GTK_SIGNAL_FUNC(show_prefs), NULL);
|
|
266
|
|
267 /* Register opens the right URL */
|
|
268 gtk_signal_connect(GTK_OBJECT(reg), "clicked",
|
|
269 GTK_SIGNAL_FUNC(open_url), "http://www.aol.com/aim");
|
|
270 /* Enter in the username clears the password and sets
|
|
271 the pointer in the password field */
|
|
272 gtk_signal_connect(GTK_OBJECT(GTK_COMBO(name)->entry), "activate",
|
|
273 GTK_SIGNAL_FUNC(doenter), mainwindow);
|
|
274
|
|
275 gtk_signal_connect(GTK_OBJECT(GTK_COMBO(name)->entry), "changed",
|
|
276 GTK_SIGNAL_FUNC(combo_changed), name);
|
|
277
|
|
278 gtk_signal_connect(GTK_OBJECT(pass), "activate",
|
|
279 GTK_SIGNAL_FUNC(doenter), mainwindow);
|
|
280 gtk_signal_connect(GTK_OBJECT(mainwindow), "delete_event",
|
|
281 GTK_SIGNAL_FUNC(cancel_logon), mainwindow);
|
|
282 /* Homogenous spacing, 10 padding */
|
|
283 bbox = gtk_hbox_new(TRUE, 10);
|
|
284 sbox = gtk_vbox_new(TRUE, 10);
|
|
285
|
|
286 gtk_box_pack_start(GTK_BOX(bbox), reg, TRUE, TRUE, 0);
|
|
287 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0);
|
|
288 gtk_box_pack_start(GTK_BOX(bbox), signon, TRUE, TRUE, 0);
|
|
289
|
|
290 gtk_box_pack_start(GTK_BOX(sbox), bbox, TRUE, TRUE, 0);
|
|
291 gtk_box_pack_start(GTK_BOX(sbox), options, TRUE, TRUE, 0);
|
|
292
|
|
293 /* Labels for selectors and text boxes */
|
|
294 #if 0
|
|
295 label = gtk_label_new("TOC: ");
|
|
296 gtk_table_attach(GTK_TABLE(table), label, 0,1,1,2,0,0, 5, 5);
|
|
297 gtk_widget_show(label);
|
|
298 #endif
|
|
299 label = gtk_label_new("Screen Name: ");
|
|
300 gtk_table_attach(GTK_TABLE(table), label, 0,1,2,3,0,0, 5, 5);
|
|
301 gtk_widget_show(label);
|
|
302 label = gtk_label_new("Password: ");
|
|
303 gtk_table_attach(GTK_TABLE(table), label, 0,1,3,4,0,0, 5, 5);
|
|
304 gtk_widget_show(label);
|
|
305 remember = gtk_check_button_new_with_label("Remember Password");
|
|
306 gtk_table_attach(GTK_TABLE(table), remember, 0,2,4,5,0,0, 5, 5);
|
|
307 gtk_widget_show(remember);
|
|
308
|
|
309 gtk_widget_show(options);
|
|
310
|
|
311 /* Adjust sizes of inputs */
|
|
312 gtk_widget_set_usize(name,95,0);
|
|
313 gtk_widget_set_usize(pass,95,0);
|
|
314
|
|
315
|
|
316 /* Status and label */
|
|
317 gtk_widget_show(notice);
|
|
318
|
|
319 gtk_widget_set_usize(progress,150,0);
|
|
320
|
|
321 gtk_widget_show(progress);
|
|
322
|
|
323 gtk_table_attach(GTK_TABLE(table), progress, 0, 2, 6, 7, 0, 0, 5, 5);
|
|
324 gtk_widget_set_usize(GTK_STATUSBAR(notice)->label, 150, 0);
|
|
325 gtk_table_attach(GTK_TABLE(table), notice, 0, 2, 8, 9, 0, 0, 5, 5);
|
|
326
|
|
327 /* Attach the buttons at the bottom */
|
|
328 gtk_widget_show(signon);
|
|
329 gtk_widget_show(cancel);
|
|
330 gtk_widget_show(reg);
|
|
331 gtk_widget_show(bbox);
|
|
332 gtk_widget_show(sbox);
|
|
333 gtk_table_attach(GTK_TABLE(table), sbox, 0,2,7,8,0,0, 5, 5);
|
|
334
|
|
335 /* Text fields */
|
|
336
|
|
337 gtk_table_attach(GTK_TABLE(table),name,1,2,2,3,0,0,5,5);
|
|
338 gtk_widget_show(name);
|
|
339 gtk_table_attach(GTK_TABLE(table),pass,1,2,3,4,0,0,5,5);
|
|
340 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE);
|
|
341 gtk_widget_show(pass);
|
|
342
|
|
343 gtk_container_border_width(GTK_CONTAINER(sbox), 10);
|
|
344
|
|
345 gtk_container_add(GTK_CONTAINER(mainwindow),table );
|
|
346
|
|
347 gtk_widget_show(table);
|
|
348 gtk_window_set_title(GTK_WINDOW(mainwindow),"Gaim - Login");
|
|
349
|
|
350
|
|
351 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(remember), (general_options & OPT_GEN_REMEMBER_PASS));
|
|
352
|
|
353 if (current_user) {
|
|
354 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(name)->entry), current_user->username);
|
|
355 if ((general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
356 gtk_entry_set_text(GTK_ENTRY(pass), current_user->password);
|
|
357 }
|
|
358
|
|
359
|
|
360 gtk_widget_grab_focus(signon);
|
|
361 } else
|
|
362 gtk_widget_grab_focus(name);
|
|
363
|
|
364
|
|
365
|
|
366 gtk_signal_connect(GTK_OBJECT(remember), "clicked", GTK_SIGNAL_FUNC(set_general_option), (int *)OPT_GEN_REMEMBER_PASS);
|
|
367
|
|
368
|
|
369 gtk_widget_realize(mainwindow);
|
|
370
|
|
371 #ifndef USE_APPLET
|
|
372 /* Logo at the top */
|
|
373 style = gtk_widget_get_style(mainwindow);
|
|
374 pm = gdk_pixmap_create_from_xpm_d(mainwindow->window, &mask,
|
|
375 &style->bg[GTK_STATE_NORMAL], (gchar **)aol_logo);
|
|
376 pmw = gtk_pixmap_new( pm, mask);
|
|
377 gtk_table_attach(GTK_TABLE(table), pmw, 0,2,0,1,0,0,5,5);
|
|
378 gtk_widget_show(pmw);
|
|
379 #endif /* USE_APPLET */
|
|
380
|
|
381
|
|
382 aol_icon(mainwindow->window);
|
|
383 #ifndef _WIN32
|
|
384 gdk_window_set_group(mainwindow->window, mainwindow->window);
|
|
385 #endif
|
|
386
|
|
387
|
|
388 gtk_widget_show(mainwindow);
|
|
389
|
|
390 if((general_options & OPT_GEN_AUTO_LOGIN) &&
|
|
391 (general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
392 dologin(signon, NULL);
|
|
393 }
|
|
394 }
|
|
395
|
|
396
|
|
397 int main(int argc, char *argv[])
|
|
398 {
|
|
399 #ifdef USE_APPLET
|
|
400 InitAppletMgr( argc, argv );
|
|
401 #elif defined USE_THEMES
|
|
402 gnome_init("GAIM",NULL,argc,argv);
|
|
403 #else
|
|
404 gtk_init(&argc, &argv);
|
|
405 #endif /* USE_THEMES */
|
|
406
|
|
407
|
|
408 set_defaults();
|
|
409 load_prefs();
|
|
410
|
|
411 #ifdef USE_APPLET
|
|
412 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
413 "prefs",
|
|
414 _("Preferences"),
|
|
415 show_prefs,
|
|
416 NULL);
|
|
417 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
418 "signon",
|
|
419 _("Signon"),
|
|
420 applet_show_login,
|
|
421 NULL);
|
|
422
|
|
423 if((general_options & OPT_GEN_AUTO_LOGIN) &&
|
|
424 (general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
425
|
|
426 applet_show_login(APPLET_WIDGET(applet), NULL);
|
|
427 }
|
82
|
428
|
|
429 update_pixmaps();
|
1
|
430
|
|
431 applet_widget_gtk_main();
|
|
432 #else
|
|
433
|
|
434
|
|
435 show_login();
|
|
436 gtk_main();
|
|
437
|
|
438 #endif /* USE_APPLET */
|
|
439
|
|
440 return 0;
|
|
441
|
|
442 }
|