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 {
|
|
114 char *username = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(name)->entry));
|
|
115 char *password = gtk_entry_get_text(GTK_ENTRY(pass));
|
|
116
|
|
117 if (query_state() != STATE_OFFLINE)
|
|
118 return;
|
|
119
|
|
120 if (!strlen(username)) {
|
|
121 hide_login_progress("Please enter your logon");
|
|
122 return;
|
|
123 }
|
|
124 if (!strlen(password)) {
|
|
125 hide_login_progress("You must give your password");
|
|
126 return;
|
|
127 }
|
|
128
|
|
129 #ifdef USE_APPLET
|
|
130 set_applet_draw_closed();
|
|
131 setUserState(signing_on);
|
|
132 #endif /* USE_APPLET */
|
|
133
|
|
134
|
|
135 if (serv_login(username, password) < 0)
|
|
136 return;
|
|
137
|
|
138 return;
|
|
139 }
|
|
140
|
|
141
|
|
142
|
|
143
|
|
144 void doenter(GtkWidget *widget, GtkWidget *w)
|
|
145 {
|
|
146 if (widget == name) {
|
|
147 gtk_entry_set_text(GTK_ENTRY(pass),"");
|
|
148 gtk_entry_select_region(GTK_ENTRY(GTK_COMBO(name)->entry), 0, 0);
|
|
149 gtk_window_set_focus(GTK_WINDOW(mainwindow), pass);
|
|
150 } else if (widget == pass) {
|
|
151 gtk_window_set_focus(GTK_WINDOW(mainwindow), signon);
|
|
152 } else {
|
|
153 g_print("what did you press enter on?\n");
|
|
154 }
|
|
155
|
|
156 }
|
|
157
|
|
158
|
|
159 static void combo_changed(GtkWidget *w, GtkWidget *combo)
|
|
160 {
|
|
161 char *txt = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(combo)->entry), 0, -1);
|
|
162 struct aim_user *u;
|
|
163
|
25
|
164 if (!(general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
165 g_free(txt);
|
1
|
166 return;
|
25
|
167 }
|
|
168
|
1
|
169 u = find_user(txt);
|
|
170
|
|
171 if (u != NULL) {
|
|
172 gtk_entry_set_text(GTK_ENTRY(pass), u->password);
|
|
173 } else {
|
|
174 gtk_entry_set_text(GTK_ENTRY(pass), "");
|
|
175 }
|
25
|
176
|
|
177 g_free(txt);
|
1
|
178 return;
|
|
179 }
|
|
180
|
|
181 static GList *combo_user_names()
|
|
182 {
|
|
183 GList *usr = aim_users;
|
|
184 GList *tmp = NULL;
|
|
185 struct aim_user *u;
|
|
186
|
|
187
|
|
188 if (!usr)
|
|
189 return g_list_append(NULL, "<unknown>");
|
|
190
|
|
191 while(usr) {
|
|
192 u = (struct aim_user *)usr->data;
|
|
193 tmp = g_list_append(tmp, g_strdup(u->username));
|
|
194 usr = usr->next;
|
|
195
|
|
196 }
|
|
197
|
|
198 return tmp;
|
|
199 }
|
|
200
|
|
201
|
|
202
|
|
203 void show_login()
|
|
204 {
|
|
205 GtkWidget *options;
|
|
206 GtkWidget *reg;
|
|
207 GtkWidget *bbox;
|
|
208 GtkWidget *sbox;
|
|
209 GtkWidget *label;
|
|
210 GtkWidget *table;
|
|
211 GtkWidget *remember;
|
|
212
|
|
213 #ifndef USE_APPLET
|
|
214 GtkWidget *pmw;
|
|
215 GdkPixmap *pm;
|
|
216 GtkStyle *style;
|
|
217 GdkBitmap *mask;
|
|
218 #endif /* USE_APPLET */
|
|
219
|
|
220 if (mainwindow) {
|
|
221 gtk_widget_show(mainwindow);
|
|
222 return;
|
|
223 }
|
|
224
|
|
225 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
226 signon = gtk_button_new_with_label("Signon");
|
|
227 cancel = gtk_button_new_with_label("Cancel");
|
|
228 reg = gtk_button_new_with_label("Register");
|
|
229 options = gtk_button_new_with_label("Options");
|
|
230 table = gtk_table_new(8, 2, FALSE);
|
|
231 name = gtk_combo_new();
|
|
232 pass = gtk_entry_new();
|
|
233 notice = gtk_statusbar_new();
|
|
234 progress = gtk_progress_bar_new();
|
|
235
|
|
236 gtk_combo_set_popdown_strings(GTK_COMBO(name), combo_user_names());
|
|
237
|
|
238 /* Make the buttons do stuff */
|
|
239 /* Clicking the button initiates a login */
|
|
240 gtk_signal_connect(GTK_OBJECT(signon), "clicked",
|
|
241 GTK_SIGNAL_FUNC(dologin), mainwindow);
|
|
242 gtk_signal_connect(GTK_OBJECT(cancel), "clicked",
|
|
243 GTK_SIGNAL_FUNC(cancel_logon), mainwindow);
|
|
244 /* Allow user to change prefs before logging in */
|
|
245 gtk_signal_connect(GTK_OBJECT(options), "clicked",
|
|
246 GTK_SIGNAL_FUNC(show_prefs), NULL);
|
|
247
|
|
248 /* Register opens the right URL */
|
|
249 gtk_signal_connect(GTK_OBJECT(reg), "clicked",
|
|
250 GTK_SIGNAL_FUNC(open_url), "http://www.aol.com/aim");
|
|
251 /* Enter in the username clears the password and sets
|
|
252 the pointer in the password field */
|
|
253 gtk_signal_connect(GTK_OBJECT(GTK_COMBO(name)->entry), "activate",
|
|
254 GTK_SIGNAL_FUNC(doenter), mainwindow);
|
|
255
|
|
256 gtk_signal_connect(GTK_OBJECT(GTK_COMBO(name)->entry), "changed",
|
|
257 GTK_SIGNAL_FUNC(combo_changed), name);
|
|
258
|
|
259 gtk_signal_connect(GTK_OBJECT(pass), "activate",
|
|
260 GTK_SIGNAL_FUNC(doenter), mainwindow);
|
|
261 gtk_signal_connect(GTK_OBJECT(mainwindow), "delete_event",
|
|
262 GTK_SIGNAL_FUNC(cancel_logon), mainwindow);
|
|
263 /* Homogenous spacing, 10 padding */
|
|
264 bbox = gtk_hbox_new(TRUE, 10);
|
|
265 sbox = gtk_vbox_new(TRUE, 10);
|
|
266
|
|
267 gtk_box_pack_start(GTK_BOX(bbox), reg, TRUE, TRUE, 0);
|
|
268 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0);
|
|
269 gtk_box_pack_start(GTK_BOX(bbox), signon, TRUE, TRUE, 0);
|
|
270
|
|
271 gtk_box_pack_start(GTK_BOX(sbox), bbox, TRUE, TRUE, 0);
|
|
272 gtk_box_pack_start(GTK_BOX(sbox), options, TRUE, TRUE, 0);
|
|
273
|
|
274 /* Labels for selectors and text boxes */
|
|
275 #if 0
|
|
276 label = gtk_label_new("TOC: ");
|
|
277 gtk_table_attach(GTK_TABLE(table), label, 0,1,1,2,0,0, 5, 5);
|
|
278 gtk_widget_show(label);
|
|
279 #endif
|
|
280 label = gtk_label_new("Screen Name: ");
|
|
281 gtk_table_attach(GTK_TABLE(table), label, 0,1,2,3,0,0, 5, 5);
|
|
282 gtk_widget_show(label);
|
|
283 label = gtk_label_new("Password: ");
|
|
284 gtk_table_attach(GTK_TABLE(table), label, 0,1,3,4,0,0, 5, 5);
|
|
285 gtk_widget_show(label);
|
|
286 remember = gtk_check_button_new_with_label("Remember Password");
|
|
287 gtk_table_attach(GTK_TABLE(table), remember, 0,2,4,5,0,0, 5, 5);
|
|
288 gtk_widget_show(remember);
|
|
289
|
|
290 gtk_widget_show(options);
|
|
291
|
|
292 /* Adjust sizes of inputs */
|
|
293 gtk_widget_set_usize(name,95,0);
|
|
294 gtk_widget_set_usize(pass,95,0);
|
|
295
|
|
296
|
|
297 /* Status and label */
|
|
298 gtk_widget_show(notice);
|
|
299
|
|
300 gtk_widget_set_usize(progress,150,0);
|
|
301
|
|
302 gtk_widget_show(progress);
|
|
303
|
|
304 gtk_table_attach(GTK_TABLE(table), progress, 0, 2, 6, 7, 0, 0, 5, 5);
|
|
305 gtk_widget_set_usize(GTK_STATUSBAR(notice)->label, 150, 0);
|
|
306 gtk_table_attach(GTK_TABLE(table), notice, 0, 2, 8, 9, 0, 0, 5, 5);
|
|
307
|
|
308 /* Attach the buttons at the bottom */
|
|
309 gtk_widget_show(signon);
|
|
310 gtk_widget_show(cancel);
|
|
311 gtk_widget_show(reg);
|
|
312 gtk_widget_show(bbox);
|
|
313 gtk_widget_show(sbox);
|
|
314 gtk_table_attach(GTK_TABLE(table), sbox, 0,2,7,8,0,0, 5, 5);
|
|
315
|
|
316 /* Text fields */
|
|
317
|
|
318 gtk_table_attach(GTK_TABLE(table),name,1,2,2,3,0,0,5,5);
|
|
319 gtk_widget_show(name);
|
|
320 gtk_table_attach(GTK_TABLE(table),pass,1,2,3,4,0,0,5,5);
|
|
321 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE);
|
|
322 gtk_widget_show(pass);
|
|
323
|
|
324 gtk_container_border_width(GTK_CONTAINER(sbox), 10);
|
|
325
|
|
326 gtk_container_add(GTK_CONTAINER(mainwindow),table );
|
|
327
|
|
328 gtk_widget_show(table);
|
|
329 gtk_window_set_title(GTK_WINDOW(mainwindow),"Gaim - Login");
|
|
330
|
|
331
|
|
332 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(remember), (general_options & OPT_GEN_REMEMBER_PASS));
|
|
333
|
|
334 if (current_user) {
|
|
335 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(name)->entry), current_user->username);
|
|
336 if ((general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
337 gtk_entry_set_text(GTK_ENTRY(pass), current_user->password);
|
|
338 }
|
|
339
|
|
340
|
|
341 gtk_widget_grab_focus(signon);
|
|
342 } else
|
|
343 gtk_widget_grab_focus(name);
|
|
344
|
|
345
|
|
346
|
|
347 gtk_signal_connect(GTK_OBJECT(remember), "clicked", GTK_SIGNAL_FUNC(set_general_option), (int *)OPT_GEN_REMEMBER_PASS);
|
|
348
|
|
349
|
|
350 gtk_widget_realize(mainwindow);
|
|
351
|
|
352 #ifndef USE_APPLET
|
|
353 /* Logo at the top */
|
|
354 style = gtk_widget_get_style(mainwindow);
|
|
355 pm = gdk_pixmap_create_from_xpm_d(mainwindow->window, &mask,
|
|
356 &style->bg[GTK_STATE_NORMAL], (gchar **)aol_logo);
|
|
357 pmw = gtk_pixmap_new( pm, mask);
|
|
358 gtk_table_attach(GTK_TABLE(table), pmw, 0,2,0,1,0,0,5,5);
|
|
359 gtk_widget_show(pmw);
|
|
360 #endif /* USE_APPLET */
|
|
361
|
|
362
|
|
363 aol_icon(mainwindow->window);
|
|
364 #ifndef _WIN32
|
|
365 gdk_window_set_group(mainwindow->window, mainwindow->window);
|
|
366 #endif
|
|
367
|
|
368
|
|
369 gtk_widget_show(mainwindow);
|
|
370
|
|
371 if((general_options & OPT_GEN_AUTO_LOGIN) &&
|
|
372 (general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
373 dologin(signon, NULL);
|
|
374 }
|
|
375 }
|
|
376
|
|
377
|
|
378 int main(int argc, char *argv[])
|
|
379 {
|
|
380 #ifdef USE_APPLET
|
|
381 InitAppletMgr( argc, argv );
|
|
382 #elif defined USE_THEMES
|
|
383 gnome_init("GAIM",NULL,argc,argv);
|
|
384 #else
|
|
385 gtk_init(&argc, &argv);
|
|
386 #endif /* USE_THEMES */
|
|
387
|
|
388
|
|
389 set_defaults();
|
|
390 load_prefs();
|
|
391
|
|
392 #ifdef USE_APPLET
|
|
393 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
394 "prefs",
|
|
395 _("Preferences"),
|
|
396 show_prefs,
|
|
397 NULL);
|
|
398 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
399 "signon",
|
|
400 _("Signon"),
|
|
401 applet_show_login,
|
|
402 NULL);
|
|
403
|
|
404 if((general_options & OPT_GEN_AUTO_LOGIN) &&
|
|
405 (general_options & OPT_GEN_REMEMBER_PASS)) {
|
|
406
|
|
407 applet_show_login(APPLET_WIDGET(applet), NULL);
|
|
408 }
|
|
409
|
|
410 applet_widget_gtk_main();
|
|
411 #else
|
|
412
|
|
413
|
|
414 show_login();
|
|
415 gtk_main();
|
|
416
|
|
417 #endif /* USE_APPLET */
|
|
418
|
|
419 return 0;
|
|
420
|
|
421 }
|