Mercurial > pidgin
annotate src/main.c @ 4998:13c4752e7138
[gaim-migrate @ 5333]
order from chaos
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 04 Apr 2003 20:58:09 +0000 |
parents | 307c16c4b57e |
children | 8e55a4d362a3 |
rev | line source |
---|---|
4489 | 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 HAVE_CONFIG_H | |
23 #include <config.h> | |
24 #endif | |
25 #ifdef GAIM_PLUGINS | |
26 #ifndef _WIN32 | |
27 #include <dlfcn.h> | |
28 #endif | |
29 #endif /* GAIM_PLUGINS */ | |
30 #include <gtk/gtk.h> | |
31 #ifndef _WIN32 | |
32 #include <gdk/gdkx.h> | |
33 #include <unistd.h> | |
34 #include <sys/socket.h> | |
35 #include <netinet/in.h> | |
36 #include <arpa/inet.h> | |
37 #include <sys/un.h> | |
38 #include <sys/wait.h> | |
39 #endif /* !_WIN32 */ | |
40 #include <gdk/gdk.h> | |
41 #include <sys/types.h> | |
42 #include <sys/stat.h> | |
43 #include <errno.h> | |
44 #include <stdio.h> | |
45 #include <string.h> | |
46 #include <stdarg.h> | |
47 #include <stdlib.h> | |
48 #include <ctype.h> | |
49 #include "prpl.h" | |
4561 | 50 #include "sound.h" |
4489 | 51 #include "gaim.h" |
52 #include "gaim-socket.h" | |
4687 | 53 #include "gtklist.h" |
4489 | 54 #if HAVE_SIGNAL_H |
55 #include <signal.h> | |
56 #endif | |
57 #include "locale.h" | |
58 #include <getopt.h> | |
59 | |
60 #ifdef _WIN32 | |
61 #include "win32dep.h" | |
62 #endif | |
63 | |
64 static GtkWidget *name; | |
65 static GtkWidget *pass; | |
66 | |
67 GList *log_conversations = NULL; | |
68 GList *buddy_pounces = NULL; | |
69 GSList *away_messages = NULL; | |
70 GSList *message_queue = NULL; | |
71 GSList *unread_message_queue = NULL; | |
72 GSList *away_time_queue = NULL; | |
73 | |
74 GtkWidget *mainwindow = NULL; | |
75 | |
4561 | 76 |
4489 | 77 int opt_away = 0; |
4687 | 78 int docklet_count = 0; |
4489 | 79 char *opt_away_arg = NULL; |
80 char *opt_rcfile_arg = NULL; | |
81 int opt_debug = 0; | |
82 #ifdef _WIN32 | |
83 int opt_gdebug = 0; | |
84 #endif | |
85 | |
86 #if HAVE_SIGNAL_H | |
87 /* | |
88 * Lists of signals we wish to catch and those we wish to ignore. | |
89 * Each list terminated with -1 | |
90 */ | |
91 static int catch_sig_list[] = { | |
92 SIGSEGV, | |
93 SIGHUP, | |
94 SIGINT, | |
95 SIGTERM, | |
96 SIGQUIT, | |
97 SIGCHLD, | |
98 -1 | |
99 }; | |
100 | |
101 static int ignore_sig_list[] = { | |
102 SIGPIPE, | |
103 -1 | |
104 }; | |
105 #endif | |
106 | |
107 void do_quit() | |
108 { | |
109 /* captain's log, stardate... */ | |
110 system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); | |
111 | |
112 /* the self destruct sequence has been initiated */ | |
113 plugin_event(event_quit); | |
114 | |
115 /* transmission ends */ | |
116 signoff_all(); | |
117 | |
118 /* record what we have before we blow it away... */ | |
119 save_prefs(); | |
120 | |
121 #ifdef GAIM_PLUGINS | |
122 /* jettison cargo */ | |
123 remove_all_plugins(); | |
124 #endif | |
125 | |
126 #ifdef USE_PERL | |
127 /* yup, perl too */ | |
128 perl_end(); | |
129 #endif | |
130 | |
131 #ifdef USE_SM | |
132 /* unplug */ | |
133 session_end(); | |
134 #endif | |
135 | |
136 /* and end it all... */ | |
137 gtk_main_quit(); | |
138 } | |
139 | |
4561 | 140 static guint snd_tmout = 0; |
4489 | 141 static gboolean sound_timeout(gpointer data) |
142 { | |
4561 | 143 gaim_sound_set_login_mute(FALSE); |
144 snd_tmout = 0; | |
4489 | 145 return FALSE; |
146 } | |
147 | |
148 /* we need to do this for Oscar because serv_login only starts the login | |
149 * process, it doesn't end there. gaim_setup will be called later from | |
150 * oscar.c, after the buddy list is made and serv_finish_login is called */ | |
151 void gaim_setup(struct gaim_connection *gc) | |
152 { | |
153 if ((sound_options & OPT_SOUND_LOGIN) && (sound_options & OPT_SOUND_SILENT_SIGNON)) { | |
4561 | 154 if(snd_tmout) { |
155 g_source_remove(snd_tmout); | |
156 } | |
157 gaim_sound_set_login_mute(TRUE); | |
4489 | 158 snd_tmout = g_timeout_add(10000, sound_timeout, NULL); |
159 } | |
160 } | |
161 | |
162 static gboolean domiddleclick(GtkWidget *w, GdkEventButton *event, gpointer null) | |
163 { | |
164 if (event->button != 2) | |
165 return FALSE; | |
166 | |
167 auto_login(); | |
168 return TRUE; | |
169 } | |
170 | |
171 static void dologin(GtkWidget *widget, GtkWidget *w) | |
172 { | |
4491 | 173 struct gaim_account *account; |
4489 | 174 const char *username = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(name)->entry)); |
175 const char *password = gtk_entry_get_text(GTK_ENTRY(pass)); | |
176 | |
177 if (!strlen(username)) { | |
178 do_error_dialog(_("Please enter your login."), NULL, GAIM_ERROR); | |
179 return; | |
180 } | |
181 | |
182 /* if there is more than one user of the same name, then fuck | |
183 * them, they just have to use the account editor to sign in | |
184 * the second one */ | |
185 | |
4491 | 186 account = gaim_account_find(username, -1); |
187 if (!account) | |
188 account = gaim_account_new(username, DEFAULT_PROTO, OPT_ACCT_REM_PASS); | |
189 g_snprintf(account->password, sizeof account->password, "%s", password); | |
4489 | 190 save_prefs(); |
4491 | 191 serv_login(account); |
4489 | 192 } |
193 | |
194 /* <name> is a comma-separated list of names, or NULL | |
195 if NULL and there is at least one user defined in .gaimrc, try to login. | |
196 if not NULL, parse <name> into separate strings, look up each one in | |
197 .gaimrc and, if it's there, try to login. | |
198 returns: 0 if successful | |
199 -1 if no user was found that had a saved password | |
200 */ | |
201 static int dologin_named(char *name) | |
202 { | |
4491 | 203 struct gaim_account *account; |
4489 | 204 char **names, **n; |
205 int retval = -1; | |
206 | |
207 if (name !=NULL) { /* list of names given */ | |
208 names = g_strsplit(name, ",", 32); | |
209 for (n = names; *n != NULL; n++) { | |
4491 | 210 account = gaim_account_find(*n, -1); |
211 if (account) { /* found a user */ | |
212 if (account->options & OPT_ACCT_REM_PASS) { | |
4489 | 213 retval = 0; |
4491 | 214 serv_login(account); |
4489 | 215 } |
216 } | |
217 } | |
218 g_strfreev(names); | |
219 } else { /* no name given, use default */ | |
4491 | 220 account = (struct gaim_account *)gaim_accounts->data; |
221 if (account->options & OPT_ACCT_REM_PASS) { | |
4489 | 222 retval = 0; |
4491 | 223 serv_login(account); |
4489 | 224 } |
225 } | |
226 | |
227 return retval; | |
228 } | |
229 | |
230 | |
231 static void doenter(GtkWidget *widget, GtkWidget *w) | |
232 { | |
233 if (widget == name) { | |
234 gtk_entry_set_text(GTK_ENTRY(pass), ""); | |
4635 | 235 gtk_editable_select_region(GTK_EDITABLE(GTK_COMBO(name)->entry), 0, 0); |
4489 | 236 gtk_widget_grab_focus(pass); |
237 } else if (widget == pass) { | |
238 dologin(widget, w); | |
239 } | |
240 } | |
241 | |
242 | |
243 static void combo_changed(GtkWidget *w, GtkWidget *combo) | |
244 { | |
245 const char *txt = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); | |
4491 | 246 struct gaim_account *account; |
4489 | 247 |
4491 | 248 account = gaim_account_find(txt, -1); |
4489 | 249 |
4491 | 250 if (account && account->options & OPT_ACCT_REM_PASS) { |
251 gtk_entry_set_text(GTK_ENTRY(pass), account->password); | |
4489 | 252 } else { |
253 gtk_entry_set_text(GTK_ENTRY(pass), ""); | |
254 } | |
255 } | |
256 | |
257 | |
258 static GList *combo_user_names() | |
259 { | |
4491 | 260 GSList *accts = gaim_accounts; |
4489 | 261 GList *tmp = NULL; |
4491 | 262 struct gaim_account *account; |
4489 | 263 |
4491 | 264 if (!accts) |
4489 | 265 return g_list_append(NULL, _("<New User>")); |
266 | |
4491 | 267 while (accts) { |
268 account = (struct gaim_account *)accts->data; | |
269 tmp = g_list_append(tmp, account->username); | |
270 accts = accts->next; | |
4489 | 271 } |
272 | |
273 return tmp; | |
274 } | |
275 | |
276 static void login_window_closed(GtkWidget *w, GdkEvent *ev, gpointer d) | |
277 { | |
278 if(docklet_count) { | |
4880
9b51c090236a
[gaim-migrate @ 5210]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4800
diff
changeset
|
279 #ifdef _WIN32 |
4489 | 280 wgaim_systray_minimize(mainwindow); |
281 #endif | |
282 gtk_widget_hide(mainwindow); | |
283 } else | |
284 do_quit(); | |
285 } | |
286 | |
287 void show_login() | |
288 { | |
289 GtkWidget *image; | |
290 GtkWidget *vbox; | |
291 GtkWidget *button; | |
292 GtkWidget *hbox; | |
293 GtkWidget *label; | |
294 GtkWidget *vbox2; | |
295 GList *tmp; | |
4978 | 296 char *filename; |
4489 | 297 |
298 /* Do we already have a main window opened? If so, bring it back, baby... ribs... yeah */ | |
299 if (mainwindow) { | |
300 gtk_window_present(GTK_WINDOW(mainwindow)); | |
301 return; | |
302 } | |
303 | |
304 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
305 | |
306 gtk_window_set_role(GTK_WINDOW(mainwindow), "login"); | |
4635 | 307 gtk_window_set_resizable(GTK_WINDOW(mainwindow), FALSE); |
4703 | 308 gtk_window_set_title(GTK_WINDOW(mainwindow), _("Login")); |
4489 | 309 gtk_widget_realize(mainwindow); |
310 gdk_window_set_group(mainwindow->window, mainwindow->window); | |
311 gtk_container_set_border_width(GTK_CONTAINER(mainwindow), 5); | |
312 g_signal_connect(G_OBJECT(mainwindow), "delete_event", | |
313 G_CALLBACK(login_window_closed), mainwindow); | |
314 | |
315 vbox = gtk_vbox_new(FALSE, 0); | |
316 gtk_container_add(GTK_CONTAINER(mainwindow), vbox); | |
317 | |
4978 | 318 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "logo.png", NULL); |
319 image = gtk_image_new_from_file(filename); | |
320 g_free(filename); | |
4489 | 321 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); |
322 | |
323 vbox2 = gtk_vbox_new(FALSE, 0); | |
324 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5); | |
325 | |
326 label = gtk_label_new(_("Screen Name:")); | |
327 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
328 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
329 | |
330 name = gtk_combo_new(); | |
331 tmp = combo_user_names(); | |
332 gtk_combo_set_popdown_strings(GTK_COMBO(name), tmp); | |
333 g_list_free(tmp); | |
334 g_signal_connect(G_OBJECT(GTK_COMBO(name)->entry), "activate", | |
335 G_CALLBACK(doenter), mainwindow); | |
336 g_signal_connect(G_OBJECT(GTK_COMBO(name)->entry), "changed", | |
337 G_CALLBACK(combo_changed), name); | |
338 gtk_box_pack_start(GTK_BOX(vbox2), name, FALSE, TRUE, 0); | |
339 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0); | |
340 | |
341 vbox2 = gtk_vbox_new(FALSE, 0); | |
342 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 5); | |
343 | |
344 label = gtk_label_new(_("Password:")); | |
345 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
346 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
347 | |
348 pass = gtk_entry_new(); | |
349 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE); | |
350 g_signal_connect(G_OBJECT(pass), "activate", | |
351 G_CALLBACK(doenter), mainwindow); | |
352 gtk_box_pack_start(GTK_BOX(vbox2), pass, FALSE, TRUE, 0); | |
353 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, TRUE, 0); | |
354 | |
355 /* Now for the button box */ | |
356 hbox = gtk_hbox_new(TRUE, 0); | |
357 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 5); | |
358 | |
359 /* And now for the buttons */ | |
4589 | 360 button = gaim_pixbuf_button(_("Accounts"), "accounts.png", GAIM_BUTTON_VERTICAL); |
4489 | 361 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
362 g_signal_connect(G_OBJECT(button), "clicked", | |
363 G_CALLBACK(account_editor), mainwindow); | |
364 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
365 | |
366 #ifdef NO_MULTI | |
367 gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); | |
368 #endif | |
369 | |
4589 | 370 button = gaim_pixbuf_button(_("Settings"), "preferences.png", GAIM_BUTTON_VERTICAL); |
4489 | 371 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
372 g_signal_connect(G_OBJECT(button), "clicked", | |
373 G_CALLBACK(show_prefs), mainwindow); | |
374 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
375 | |
4589 | 376 button = gaim_pixbuf_button(_("Sign On"), "signon.png", GAIM_BUTTON_VERTICAL); |
4489 | 377 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
378 g_signal_connect(G_OBJECT(button), "clicked", | |
379 G_CALLBACK(dologin), mainwindow); | |
380 g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(domiddleclick), NULL); | |
381 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
382 | |
383 /* Now grab the focus that we need */ | |
4491 | 384 if (gaim_accounts) { |
385 struct gaim_account *account = gaim_accounts->data; | |
386 if (account->options & OPT_ACCT_REM_PASS) { | |
4489 | 387 combo_changed(NULL, name); |
388 gtk_widget_grab_focus(button); | |
389 } else { | |
390 gtk_widget_grab_focus(pass); | |
391 } | |
392 } else { | |
393 gtk_widget_grab_focus(name); | |
394 } | |
395 | |
396 /* And raise the curtain! */ | |
397 gtk_widget_show_all(mainwindow); | |
398 | |
399 } | |
400 | |
401 #if HAVE_SIGNAL_H | |
402 void sighandler(int sig) | |
403 { | |
404 switch (sig) { | |
405 case SIGHUP: | |
406 debug_printf("caught signal %d\n", sig); | |
407 signoff_all(NULL, NULL); | |
408 break; | |
409 case SIGSEGV: | |
410 core_quit(); | |
411 #ifndef DEBUG | |
412 fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" | |
413 "This is a bug in the software and has happened through\n" | |
414 "no fault of your own.\n\n" | |
415 "It is possible that this bug is already fixed in CVS.\n" | |
416 "You can get a tarball of CVS from the Gaim website, at\n" | |
417 WEBSITE "gaim-CVS.tar.gz.\n\n" | |
418 "If you are already using CVS, or can reproduce the crash\n" | |
419 "using the CVS version, please notify the gaim maintainers\n" | |
420 "by reporting a bug at\n" | |
421 WEBSITE "bug.php\n\n" | |
422 "Please make sure to specify what you were doing at the time,\n" | |
423 "and post the backtrace from the core file. If you do not know\n" | |
424 "how to get the backtrace, please get instructions at\n" | |
425 WEBSITE "gdb.php. If you need further\n" | |
426 "assistance, please IM either RobFlynn or SeanEgn and\n" | |
427 "they can help you.\n"); | |
428 #else | |
429 fprintf(stderr, "Oh no! Segmentation fault!\n"); | |
4703 | 430 /*g_on_error_query (g_get_prgname());*/ |
4489 | 431 exit(1); |
432 #endif | |
433 abort(); | |
434 break; | |
435 case SIGCHLD: | |
436 clean_pid(); | |
437 #if HAVE_SIGNAL_H | |
438 signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ | |
439 #endif | |
440 break; | |
441 default: | |
442 debug_printf("caught signal %d\n", sig); | |
443 signoff_all(NULL, NULL); | |
444 #ifdef GAIM_PLUGINS | |
445 remove_all_plugins(); | |
446 #endif | |
447 if (gtk_main_level()) | |
448 gtk_main_quit(); | |
449 core_quit(); | |
450 exit(0); | |
451 } | |
452 } | |
453 #endif | |
454 | |
455 #ifndef _WIN32 | |
456 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer ud) | |
457 { | |
458 guchar type; | |
459 guchar subtype; | |
460 guint32 len; | |
461 guchar *data; | |
462 guint32 x; | |
4793 | 463 GError *error; |
4489 | 464 |
465 debug_printf("Core says: "); | |
4793 | 466 g_io_channel_read_chars(source, &type, sizeof(type), &x, &error); |
467 if(error) | |
4800 | 468 g_error_free(error); |
4489 | 469 if (x == 0) { |
470 debug_printf("CORE IS GONE!\n"); | |
4793 | 471 g_io_channel_shutdown(source, TRUE, &error); |
472 if(error) | |
473 g_free(error); | |
4489 | 474 return FALSE; |
475 } | |
476 debug_printf("%d ", type); | |
4793 | 477 g_io_channel_read_chars(source, &subtype, sizeof(subtype), &x, &error); |
478 if(error) | |
4800 | 479 g_error_free(error); |
4489 | 480 if (x == 0) { |
481 debug_printf("CORE IS GONE!\n"); | |
4793 | 482 g_io_channel_shutdown(source, TRUE, &error); |
483 if(error) | |
4800 | 484 g_error_free(error); |
4489 | 485 return FALSE; |
486 } | |
487 debug_printf("%d ", subtype); | |
4793 | 488 g_io_channel_read_chars(source, (guchar *)&len, sizeof(len), &x, &error); |
489 if(error) | |
4800 | 490 g_error_free(error); |
4489 | 491 if (x == 0) { |
492 debug_printf("CORE IS GONE!\n"); | |
4793 | 493 g_io_channel_shutdown(source, TRUE, &error); |
494 if(error) | |
4800 | 495 g_error_free(error); |
4489 | 496 return FALSE; |
497 } | |
498 debug_printf("(%d bytes)\n", len); | |
499 | |
500 data = g_malloc(len); | |
4793 | 501 g_io_channel_read_chars(source, data, len, &x, &error); |
502 if(error) | |
4800 | 503 g_error_free(error); |
4489 | 504 if (x != len) { |
505 debug_printf("CORE IS GONE! (read %d/%d bytes)\n", x, len); | |
506 g_free(data); | |
4793 | 507 g_io_channel_shutdown(source, TRUE, &error); |
508 if(error) | |
4800 | 509 g_error_free(error); |
4489 | 510 return FALSE; |
511 } | |
512 | |
513 g_free(data); | |
514 return TRUE; | |
515 } | |
516 #endif /* _WIN32 */ | |
517 | |
518 static int ui_main() | |
519 { | |
520 #ifndef _WIN32 | |
521 GIOChannel *channel; | |
522 int UI_fd; | |
523 char name[256]; | |
524 GList *icons = NULL; | |
525 GdkPixbuf *icon = NULL; | |
526 char *icon_path; | |
527 #endif | |
4978 | 528 |
4489 | 529 if (current_smiley_theme == NULL) { |
530 smiley_theme_probe(); | |
531 if (smiley_themes) { | |
532 struct smiley_theme *smile = smiley_themes->data; | |
533 load_smiley_theme(smile->path, TRUE); | |
534 } | |
535 } | |
536 | |
537 setup_stock(); | |
538 | |
539 #ifndef _WIN32 | |
540 /* use the nice PNG icon for all the windows */ | |
541 icon_path = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); | |
542 icon = gdk_pixbuf_new_from_file(icon_path, NULL); | |
543 g_free(icon_path); | |
544 if (icon) { | |
545 icons = g_list_append(icons,icon); | |
546 gtk_window_set_default_icon_list(icons); | |
547 g_object_unref(G_OBJECT(icon)); | |
4978 | 548 g_list_free(icons); |
4489 | 549 } else { |
4978 | 550 debug_printf("Failed to load default window icon!\n"); |
4489 | 551 } |
552 | |
553 g_snprintf(name, sizeof(name), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); | |
554 UI_fd = gaim_connect_to_session(0); | |
555 if (UI_fd < 0) | |
556 return 1; | |
557 | |
558 channel = g_io_channel_unix_new(UI_fd); | |
559 g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, socket_readable, NULL); | |
560 #endif | |
4978 | 561 |
4489 | 562 return 0; |
563 } | |
564 | |
565 static void set_first_user(char *name) | |
566 { | |
4491 | 567 struct gaim_account *account; |
4489 | 568 |
4491 | 569 account = gaim_account_find(name, -1); |
4489 | 570 |
4491 | 571 if (!account) { /* new user */ |
572 account = g_new0(struct gaim_account, 1); | |
573 g_snprintf(account->username, sizeof(account->username), "%s", name); | |
574 account->protocol = DEFAULT_PROTO; | |
575 gaim_accounts = g_slist_prepend(gaim_accounts, account); | |
4489 | 576 } else { /* user already exists */ |
4491 | 577 gaim_accounts = g_slist_remove(gaim_accounts, account); |
578 gaim_accounts = g_slist_prepend(gaim_accounts, account); | |
4489 | 579 } |
580 save_prefs(); | |
581 } | |
582 | |
583 #ifdef _WIN32 | |
584 /* WIN32 print and log handlers */ | |
585 | |
586 static void gaim_dummy_print( const gchar* string ) { | |
587 return; | |
588 } | |
589 | |
590 static void gaim_dummy_log_handler (const gchar *domain, | |
591 GLogLevelFlags flags, | |
592 const gchar *msg, | |
593 gpointer user_data) { | |
594 return; | |
595 } | |
596 | |
597 static void gaim_log_handler (const gchar *domain, | |
598 GLogLevelFlags flags, | |
599 const gchar *msg, | |
600 gpointer user_data) { | |
601 debug_printf("%s - %s\n", domain, msg); | |
602 g_log_default_handler(domain, flags, msg, user_data); | |
603 } | |
604 #endif /* _WIN32 */ | |
605 | |
606 /* FUCKING GET ME A TOWEL! */ | |
607 #ifdef _WIN32 | |
608 int gaim_main(int argc, char *argv[]) | |
609 #else | |
610 int main(int argc, char *argv[]) | |
611 #endif | |
612 { | |
613 int opt_acct = 0, opt_help = 0, opt_version = 0, opt_login = 0, opt_nologin = 0, dologin_ret = -1; | |
614 char *opt_user_arg = NULL, *opt_login_arg = NULL; | |
615 char *opt_session_arg = NULL; | |
616 #if HAVE_SIGNAL_H | |
617 int sig_indx; /* for setting up signal catching */ | |
618 sigset_t sigset; | |
619 void (*prev_sig_disp)(); | |
620 #endif | |
621 int opt, opt_user = 0; | |
622 int i; | |
623 | |
624 struct option long_options[] = { | |
625 {"acct", no_argument, NULL, 'a'}, | |
626 /*{"away", optional_argument, NULL, 'w'}, */ | |
627 {"help", no_argument, NULL, 'h'}, | |
628 /*{"login", optional_argument, NULL, 'l'}, */ | |
629 {"loginwin", no_argument, NULL, 'n'}, | |
630 {"user", required_argument, NULL, 'u'}, | |
631 {"file", required_argument, NULL, 'f'}, | |
632 {"debug", no_argument, NULL, 'd'}, | |
633 {"version", no_argument, NULL, 'v'}, | |
634 {"session", required_argument, NULL, 's'}, | |
635 {0, 0, 0, 0} | |
636 }; | |
637 | |
638 #ifdef DEBUG | |
639 opt_debug = 1; | |
640 #endif | |
641 | |
642 #ifdef ENABLE_NLS | |
643 bindtextdomain(PACKAGE, LOCALEDIR); | |
644 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
645 textdomain(PACKAGE); | |
646 #endif | |
647 | |
648 #if HAVE_SIGNAL_H | |
649 /* Let's not violate any PLA's!!!! */ | |
650 /* jseymour: whatever the fsck that means */ | |
651 /* Robot101: for some reason things like gdm like to block * | |
652 * useful signals like SIGCHLD, so we unblock all the ones we * | |
653 * declare a handler for. thanks JSeymour and Vann. */ | |
654 if (sigemptyset(&sigset)) { | |
655 char errmsg[BUFSIZ]; | |
656 sprintf(errmsg, "Warning: couldn't initialise empty signal set"); | |
657 perror(errmsg); | |
658 } | |
659 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { | |
660 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { | |
661 char errmsg[BUFSIZ]; | |
662 sprintf(errmsg, "Warning: couldn't set signal %d for catching", | |
663 catch_sig_list[sig_indx]); | |
664 perror(errmsg); | |
665 } | |
666 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { | |
667 char errmsg[BUFSIZ]; | |
668 sprintf(errmsg, "Warning: couldn't include signal %d for unblocking", | |
669 catch_sig_list[sig_indx]); | |
670 perror(errmsg); | |
671 } | |
672 } | |
673 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { | |
674 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { | |
675 char errmsg[BUFSIZ]; | |
676 sprintf(errmsg, "Warning: couldn't set signal %d to ignore", | |
677 ignore_sig_list[sig_indx]); | |
678 perror(errmsg); | |
679 } | |
680 } | |
681 | |
682 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { | |
683 char errmsg[BUFSIZ]; | |
684 sprintf(errmsg, "Warning: couldn't unblock signals"); | |
685 perror(errmsg); | |
686 } | |
687 #endif | |
688 | |
689 for (i = 0; i < argc; i++) { | |
690 /* --login option */ | |
691 if (strstr(argv[i], "--l") == argv[i]) { | |
692 char *equals; | |
693 opt_login = 1; | |
694 if ((equals = strchr(argv[i], '=')) != NULL) { | |
695 /* --login=NAME */ | |
696 opt_login_arg = g_strdup(equals + 1); | |
697 if (strlen(opt_login_arg) == 0) { | |
698 g_free(opt_login_arg); | |
699 opt_login_arg = NULL; | |
700 } | |
701 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
702 /* --login NAME */ | |
703 opt_login_arg = g_strdup(argv[i + 1]); | |
704 strcpy(argv[i + 1], " "); | |
705 } | |
706 strcpy(argv[i], " "); | |
707 } | |
708 /* -l option */ | |
709 else if (strstr(argv[i], "-l") == argv[i]) { | |
710 opt_login = 1; | |
711 if (strlen(argv[i]) > 2) { | |
712 /* -lNAME */ | |
713 opt_login_arg = g_strdup(argv[i] + 2); | |
714 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
715 /* -l NAME */ | |
716 opt_login_arg = g_strdup(argv[i + 1]); | |
717 strcpy(argv[i + 1], " "); | |
718 } | |
719 strcpy(argv[i], " "); | |
720 } | |
721 /* --away option */ | |
722 else if (strstr(argv[i], "--aw") == argv[i]) { | |
723 char *equals; | |
724 opt_away = 1; | |
725 if ((equals = strchr(argv[i], '=')) != NULL) { | |
726 /* --away=MESG */ | |
727 opt_away_arg = g_strdup(equals + 1); | |
728 if (strlen(opt_away_arg) == 0) { | |
729 g_free(opt_away_arg); | |
730 opt_away_arg = NULL; | |
731 } | |
732 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
733 /* --away MESG */ | |
734 opt_away_arg = g_strdup(argv[i + 1]); | |
735 strcpy(argv[i + 1], " "); | |
736 } | |
737 strcpy(argv[i], " "); | |
738 } | |
739 /* -w option */ | |
740 else if (strstr(argv[i], "-w") == argv[i]) { | |
741 opt_away = 1; | |
742 if (strlen(argv[i]) > 2) { | |
743 /* -wMESG */ | |
744 opt_away_arg = g_strdup(argv[i] + 2); | |
745 } else if (i + 1 < argc && argv[i + 1][0] != '-') { | |
746 /* -w MESG */ | |
747 opt_away_arg = g_strdup(argv[i + 1]); | |
748 strcpy(argv[i + 1], " "); | |
749 } | |
750 strcpy(argv[i], " "); | |
751 } | |
752 } | |
753 /* | |
754 if (opt_login) { | |
755 printf ("--login given with arg %s\n", | |
756 opt_login_arg ? opt_login_arg : "NULL"); | |
757 exit(0); | |
758 } | |
759 */ | |
760 | |
761 gtk_set_locale(); | |
762 gtk_init(&argc, &argv); | |
763 | |
764 /* scan command-line options */ | |
765 opterr = 1; | |
766 while ((opt = getopt_long(argc, argv, | |
767 #ifndef _WIN32 | |
768 "adhu:f:vns:", | |
769 #else | |
770 "adghu:f:vn", | |
771 #endif | |
772 long_options, NULL)) != -1) { | |
773 switch (opt) { | |
774 case 'u': /* set user */ | |
775 opt_user = 1; | |
776 opt_user_arg = g_strdup(optarg); | |
777 break; | |
778 case 'a': /* account editor */ | |
779 opt_acct = 1; | |
780 break; | |
781 case 'd': /* debug */ | |
782 opt_debug = 1; | |
783 break; | |
784 case 'f': | |
785 opt_rcfile_arg = g_strdup(optarg); | |
786 break; | |
787 case 's': /* use existing session ID */ | |
788 opt_session_arg = g_strdup(optarg); | |
789 break; | |
790 case 'v': /* version */ | |
791 opt_version = 1; | |
792 break; | |
793 case 'h': /* help */ | |
794 opt_help = 1; | |
795 break; | |
796 case 'n': /* don't autologin */ | |
797 opt_nologin = 1; | |
798 break; | |
799 #ifdef _WIN32 | |
800 case 'g': /* debug GTK and GLIB */ | |
801 opt_gdebug = 1; | |
802 break; | |
803 #endif | |
804 case '?': | |
805 default: | |
806 show_usage(1, argv[0]); | |
807 return 0; | |
808 break; | |
809 } | |
810 } | |
811 | |
812 #ifdef _WIN32 | |
813 /* We don't want a console window.. */ | |
814 /* | |
815 * Any calls to the glib logging functions, result in a call to AllocConsole(). | |
816 * ME and 98 will in such cases produce a console window (2000 not), despite | |
817 * being built as a windows app rather than a console app. So we should either | |
818 * ignore messages by setting dummy log handlers, or redirect messages. | |
819 * This requires setting handlers for all domains (any lib which uses g_logging). | |
820 */ | |
821 | |
822 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
823 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
824 NULL); | |
825 g_log_set_handler ("Gdk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
826 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
827 NULL); | |
828 g_log_set_handler ("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
829 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
830 NULL); | |
831 g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
832 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
833 NULL); | |
834 g_log_set_handler ("GModule", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
835 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
836 NULL); | |
837 g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
838 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
839 NULL); | |
840 g_log_set_handler ("GThread", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
841 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
842 NULL); | |
843 | |
844 /* g_print also makes a call to AllocConsole(), therefore a handler needs to be | |
845 set here aswell */ | |
846 if(!opt_debug) | |
847 g_set_print_handler( gaim_dummy_print ); | |
848 | |
849 #endif | |
850 | |
851 /* show help message */ | |
852 if (opt_help) { | |
853 show_usage(0, argv[0]); | |
854 return 0; | |
855 } | |
856 /* show version message */ | |
857 if (opt_version) { | |
858 printf("Gaim %s\n",VERSION); | |
859 return 0; | |
860 } | |
861 | |
862 #if GAIM_PLUGINS || USE_PERL | |
863 gaim_probe_plugins(); | |
864 #endif | |
865 | |
866 #ifdef _WIN32 | |
867 /* Various win32 initializations */ | |
868 wgaim_init(); | |
869 #endif | |
870 | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
871 /* Set the UI operation structures. */ |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
872 gaim_set_win_ui_ops(gaim_get_gtk_window_ui_ops()); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
873 gaim_set_xfer_ui_ops(gaim_get_gtk_xfer_ui_ops()); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
874 gaim_set_blist_ui_ops(gaim_get_gtk_blist_ui_ops()); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
875 |
4489 | 876 load_prefs(); |
877 core_main(); | |
878 ui_main(); | |
879 | |
880 #ifdef USE_SM | |
881 session_init(argv[0], opt_session_arg); | |
882 #endif | |
883 if (opt_session_arg != NULL) { | |
884 g_free(opt_session_arg); | |
885 opt_session_arg = NULL; | |
886 }; | |
887 | |
888 /* set the default username */ | |
889 if (opt_user_arg != NULL) { | |
890 set_first_user(opt_user_arg); | |
891 g_free(opt_user_arg); | |
892 opt_user_arg = NULL; | |
893 } | |
894 | |
895 if (misc_options & OPT_MISC_DEBUG) | |
896 show_debug(); | |
897 | |
898 static_proto_init(); | |
899 | |
900 /* deal with --login */ | |
901 if (opt_login) { | |
902 dologin_ret = dologin_named(opt_login_arg); | |
903 if (opt_login_arg != NULL) { | |
904 g_free(opt_login_arg); | |
905 opt_login_arg = NULL; | |
906 } | |
907 } | |
908 | |
909 if (!opt_acct && !opt_nologin && gaim_session == 0) | |
910 auto_login(); | |
911 | |
912 if (opt_acct) { | |
913 account_editor(NULL, NULL); | |
914 } else if ((dologin_ret == -1) && !connections) | |
915 show_login(); | |
916 | |
917 gtk_main(); | |
918 core_quit(); | |
4561 | 919 gaim_sound_quit(); |
4489 | 920 #ifdef _WIN32 |
921 wgaim_cleanup(); | |
922 #endif | |
923 return 0; | |
924 | |
925 } |