Mercurial > pidgin.yaz
comparison src/aim.c @ 3630:9682c0e022c6
[gaim-migrate @ 3753]
Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 11 Oct 2002 03:14:01 +0000 |
parents | cd938f18f3f8 |
children | f09193608fd3 |
comparison
equal
deleted
inserted
replaced
3629:afc5bb164c5a | 3630:9682c0e022c6 |
---|---|
21 | 21 |
22 #ifdef HAVE_CONFIG_H | 22 #ifdef HAVE_CONFIG_H |
23 #include <config.h> | 23 #include <config.h> |
24 #endif | 24 #endif |
25 #ifdef GAIM_PLUGINS | 25 #ifdef GAIM_PLUGINS |
26 #ifndef _WIN32 | |
26 #include <dlfcn.h> | 27 #include <dlfcn.h> |
28 #endif | |
27 #endif /* GAIM_PLUGINS */ | 29 #endif /* GAIM_PLUGINS */ |
28 #include <gtk/gtk.h> | 30 #include <gtk/gtk.h> |
31 #ifdef _WIN32 | |
32 #include <winsock.h> | |
33 #else | |
29 #include <gdk/gdkx.h> | 34 #include <gdk/gdkx.h> |
30 #include <gdk/gdk.h> | |
31 #include <unistd.h> | 35 #include <unistd.h> |
32 #include <sys/types.h> | |
33 #include <sys/socket.h> | 36 #include <sys/socket.h> |
34 #include <sys/stat.h> | |
35 #include <netinet/in.h> | 37 #include <netinet/in.h> |
36 #include <arpa/inet.h> | 38 #include <arpa/inet.h> |
37 #include <errno.h> | |
38 #include <sys/un.h> | 39 #include <sys/un.h> |
39 #include <sys/wait.h> | 40 #include <sys/wait.h> |
41 #endif /* _WIN32 */ | |
42 #include <gdk/gdk.h> | |
43 #include <sys/types.h> | |
44 #include <sys/stat.h> | |
45 #include <errno.h> | |
40 #include <stdio.h> | 46 #include <stdio.h> |
41 #include <string.h> | 47 #include <string.h> |
42 #include <stdarg.h> | 48 #include <stdarg.h> |
43 #include <stdlib.h> | 49 #include <stdlib.h> |
44 #include <ctype.h> | 50 #include <ctype.h> |
49 #include <signal.h> | 55 #include <signal.h> |
50 #endif | 56 #endif |
51 #include "locale.h" | 57 #include "locale.h" |
52 #include "gtkspell.h" | 58 #include "gtkspell.h" |
53 #include <getopt.h> | 59 #include <getopt.h> |
60 #ifdef _WIN32 | |
61 #include "win32dep.h" | |
62 #endif | |
54 | 63 |
55 static gchar *aspell_cmd[] = { "aspell", "--sug-mode=fast","-a", NULL }; | 64 static gchar *aspell_cmd[] = { "aspell", "--sug-mode=fast","-a", NULL }; |
56 static gchar *ispell_cmd[] = { "ispell", "-a", NULL }; | 65 static gchar *ispell_cmd[] = { "ispell", "-a", NULL }; |
57 | 66 |
58 static GtkWidget *name; | 67 static GtkWidget *name; |
70 | 79 |
71 int opt_away = 0; | 80 int opt_away = 0; |
72 char *opt_away_arg = NULL; | 81 char *opt_away_arg = NULL; |
73 char *opt_rcfile_arg = NULL; | 82 char *opt_rcfile_arg = NULL; |
74 int opt_debug = 0; | 83 int opt_debug = 0; |
84 #ifdef _WIN32 | |
85 int opt_gdebug = 0; | |
86 #endif | |
75 | 87 |
76 #if HAVE_SIGNAL_H | 88 #if HAVE_SIGNAL_H |
77 /* | 89 /* |
78 * Lists of signals we wish to catch and those we wish to ignore. | 90 * Lists of signals we wish to catch and those we wish to ignore. |
79 * Each list terminated with -1 | 91 * Each list terminated with -1 |
241 gtk_window_present(GTK_WINDOW(mainwindow)); | 253 gtk_window_present(GTK_WINDOW(mainwindow)); |
242 return; | 254 return; |
243 } | 255 } |
244 | 256 |
245 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 257 mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
258 | |
246 gtk_window_set_wmclass(GTK_WINDOW(mainwindow), "login", "Gaim"); | 259 gtk_window_set_wmclass(GTK_WINDOW(mainwindow), "login", "Gaim"); |
247 gtk_window_set_policy(GTK_WINDOW(mainwindow), FALSE, FALSE, TRUE); | 260 gtk_window_set_policy(GTK_WINDOW(mainwindow), FALSE, FALSE, TRUE); |
248 gtk_signal_connect(GTK_OBJECT(mainwindow), "delete_event", | 261 gtk_signal_connect(GTK_OBJECT(mainwindow), "delete_event", |
249 GTK_SIGNAL_FUNC(cancel_logon), mainwindow); | 262 GTK_SIGNAL_FUNC(cancel_logon), mainwindow); |
250 gtk_window_set_title(GTK_WINDOW(mainwindow), _("Gaim - Login")); | 263 gtk_window_set_title(GTK_WINDOW(mainwindow), _("Gaim - Login")); |
425 exit(0); | 438 exit(0); |
426 } | 439 } |
427 } | 440 } |
428 #endif | 441 #endif |
429 | 442 |
443 #ifndef _WIN32 | |
430 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer ud) | 444 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer ud) |
431 { | 445 { |
432 guchar type; | 446 guchar type; |
433 guchar subtype; | 447 guchar subtype; |
434 guint32 len; | 448 guint32 len; |
478 char name[256]; | 492 char name[256]; |
479 GList *icons = NULL; | 493 GList *icons = NULL; |
480 GdkPixbuf *icon = NULL; | 494 GdkPixbuf *icon = NULL; |
481 | 495 |
482 /* use the nice PNG icon for all the windows */ | 496 /* use the nice PNG icon for all the windows */ |
483 icon = gdk_pixbuf_new_from_file(DATADIR "/pixmaps/gaim.png",NULL); | 497 icon = gdk_pixbuf_new_from_file(DATADIR G_DIR_SEPARATOR_S "pixmaps" G_DIR_SEPARATOR_S "gaim.png",NULL); |
484 if (icon) { | 498 if (icon) { |
485 icons = g_list_append(icons,icon); | 499 icons = g_list_append(icons,icon); |
486 gtk_window_set_default_icon_list(icons); | 500 gtk_window_set_default_icon_list(icons); |
487 g_object_unref(G_OBJECT(icon)); | 501 g_object_unref(G_OBJECT(icon)); |
488 } else { | 502 } else { |
489 debug_printf("Failed to load icon from %s/pixmaps/gaim.png\n",DATADIR); | 503 debug_printf("Failed to load icon from %s" G_DIR_SEPARATOR_S "pixmaps" G_DIR_SEPARATOR_S "gaim.png\n",DATADIR); |
490 } | 504 } |
491 | 505 |
492 g_snprintf(name, sizeof(name), "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); | 506 g_snprintf(name, sizeof(name), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); |
493 | 507 |
494 UI_fd = gaim_connect_to_session(0); | 508 UI_fd = gaim_connect_to_session(0); |
495 if (UI_fd < 0) | 509 if (UI_fd < 0) |
496 return 1; | 510 return 1; |
497 | 511 |
498 channel = g_io_channel_unix_new(UI_fd); | 512 channel = g_io_channel_unix_new(UI_fd); |
499 g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, socket_readable, NULL); | 513 g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, socket_readable, NULL); |
500 return 0; | 514 return 0; |
501 } | 515 } |
516 #endif /* _WIN32 */ | |
502 | 517 |
503 static void set_first_user(char *name) | 518 static void set_first_user(char *name) |
504 { | 519 { |
505 struct aim_user *u; | 520 struct aim_user *u; |
506 | 521 |
516 aim_users = g_slist_prepend(aim_users, u); | 531 aim_users = g_slist_prepend(aim_users, u); |
517 } | 532 } |
518 save_prefs(); | 533 save_prefs(); |
519 } | 534 } |
520 | 535 |
536 #ifdef _WIN32 | |
537 /* WIN32 print and log handlers */ | |
538 | |
539 static void gaim_dummy_print( const gchar* string ) { | |
540 return; | |
541 } | |
542 | |
543 static void gaim_dummy_log_handler (const gchar *domain, | |
544 GLogLevelFlags flags, | |
545 const gchar *msg, | |
546 gpointer user_data) { | |
547 return; | |
548 } | |
549 | |
550 static void gaim_log_handler (const gchar *domain, | |
551 GLogLevelFlags flags, | |
552 const gchar *msg, | |
553 gpointer user_data) { | |
554 debug_printf("%s - %s\n", domain, msg); | |
555 g_log_default_handler(domain, flags, msg, user_data); | |
556 } | |
557 #endif | |
558 | |
521 /* FUCKING GET ME A TOWEL! */ | 559 /* FUCKING GET ME A TOWEL! */ |
560 #ifdef _WIN32 | |
561 int gaim_main(int argc, char *argv[]) | |
562 #else | |
522 int main(int argc, char *argv[]) | 563 int main(int argc, char *argv[]) |
564 #endif | |
523 { | 565 { |
524 int opt_acct = 0, opt_help = 0, opt_version = 0, opt_login = 0, opt_nologin = 0, do_login_ret = -1; | 566 int opt_acct = 0, opt_help = 0, opt_version = 0, opt_login = 0, opt_nologin = 0, do_login_ret = -1; |
525 char *opt_user_arg = NULL, *opt_login_arg = NULL; | 567 char *opt_user_arg = NULL, *opt_login_arg = NULL; |
526 #if HAVE_SIGNAL_H | 568 #if HAVE_SIGNAL_H |
527 int sig_indx; /* for setting up signal catching */ | 569 int sig_indx; /* for setting up signal catching */ |
670 gtk_set_locale(); | 712 gtk_set_locale(); |
671 gtk_init(&argc, &argv); | 713 gtk_init(&argc, &argv); |
672 | 714 |
673 /* scan command-line options */ | 715 /* scan command-line options */ |
674 opterr = 1; | 716 opterr = 1; |
675 while ((opt = getopt_long(argc, argv, "adhu:f:vn", long_options, NULL)) != -1) { | 717 while ((opt = getopt_long(argc, argv, |
718 #ifndef _WIN32 | |
719 "adhu:f:vn", | |
720 #else | |
721 "adghu:f:vn", | |
722 #endif | |
723 long_options, NULL)) != -1) { | |
676 switch (opt) { | 724 switch (opt) { |
677 case 'u': /* set user */ | 725 case 'u': /* set user */ |
678 opt_user = 1; | 726 opt_user = 1; |
679 opt_user_arg = g_strdup(optarg); | 727 opt_user_arg = g_strdup(optarg); |
680 break; | 728 break; |
694 opt_help = 1; | 742 opt_help = 1; |
695 break; | 743 break; |
696 case 'n': /* don't autologin */ | 744 case 'n': /* don't autologin */ |
697 opt_nologin = 1; | 745 opt_nologin = 1; |
698 break; | 746 break; |
747 #ifdef _WIN32 | |
748 case 'g': /* debug GTK and GLIB */ | |
749 opt_gdebug = 1; | |
750 break; | |
751 #endif | |
699 case '?': | 752 case '?': |
700 default: | 753 default: |
701 show_usage(1, argv[0]); | 754 show_usage(1, argv[0]); |
702 return 0; | 755 return 0; |
703 break; | 756 break; |
704 } | 757 } |
705 } | 758 } |
706 | 759 |
760 #ifdef _WIN32 | |
761 /* We don't want a console window.. */ | |
762 /* | |
763 * Any calls to the glib logging functions, result in a call to AllocConsole(). | |
764 * ME and 98 will in such cases produce a console window (2000 not), despite | |
765 * being built as a windows app rather than a console app. So we should either | |
766 * ignore messages by setting dummy log handlers, or redirect messages. | |
767 * This requires setting handlers for all domains (any lib which uses g_logging). | |
768 */ | |
769 | |
770 g_log_set_handler ("Gdk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
771 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
772 NULL); | |
773 g_log_set_handler ("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
774 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
775 NULL); | |
776 g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
777 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
778 NULL); | |
779 g_log_set_handler ("GModule", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
780 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
781 NULL); | |
782 g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
783 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
784 NULL); | |
785 g_log_set_handler ("GThread", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, | |
786 (opt_gdebug ? gaim_log_handler : gaim_dummy_log_handler), | |
787 NULL); | |
788 | |
789 /* g_print also makes a call to AllocConsole(), therefore a handler needs to be | |
790 set here aswell */ | |
791 if(!opt_debug) | |
792 g_set_print_handler( gaim_dummy_print ); | |
793 | |
794 #endif | |
795 | |
707 /* show help message */ | 796 /* show help message */ |
708 if (opt_help) { | 797 if (opt_help) { |
709 show_usage(0, argv[0]); | 798 show_usage(0, argv[0]); |
710 return 0; | 799 return 0; |
711 } | 800 } |
718 #if GAIM_PLUGINS || USE_PERL | 807 #if GAIM_PLUGINS || USE_PERL |
719 gaim_probe_plugins(); | 808 gaim_probe_plugins(); |
720 #endif | 809 #endif |
721 load_prefs(); | 810 load_prefs(); |
722 core_main(); | 811 core_main(); |
812 #ifndef _WIN32 | |
723 ui_main(); | 813 ui_main(); |
814 #endif | |
724 | 815 |
725 /* set the default username */ | 816 /* set the default username */ |
726 if (opt_user_arg != NULL) { | 817 if (opt_user_arg != NULL) { |
727 set_first_user(opt_user_arg); | 818 set_first_user(opt_user_arg); |
728 g_free(opt_user_arg); | 819 g_free(opt_user_arg); |
729 opt_user_arg = NULL; | 820 opt_user_arg = NULL; |
730 } | 821 } |
731 | 822 |
732 if (misc_options & OPT_MISC_DEBUG) | 823 if (misc_options & OPT_MISC_DEBUG) |
733 show_debug(); | 824 show_debug(); |
825 #ifndef _WIN32 | |
734 /*If ispell fails to start, try using aspell in ispell compatibitity mode. | 826 /*If ispell fails to start, try using aspell in ispell compatibitity mode. |
735 Gabber does this the same way -- lorien420@myrealbox.com*/ | 827 Gabber does this the same way -- lorien420@myrealbox.com*/ |
736 if (convo_options & OPT_CONVO_CHECK_SPELLING){ | 828 if (convo_options & OPT_CONVO_CHECK_SPELLING){ |
737 if (gtkspell_start(NULL, ispell_cmd)<0){ | 829 if (gtkspell_start(NULL, ispell_cmd)<0){ |
738 debug_printf("gtkspell failed to start when using ispell\n"); | 830 debug_printf("gtkspell failed to start when using ispell\n"); |
742 debug_printf("gtkspell started with aspell\n"); | 834 debug_printf("gtkspell started with aspell\n"); |
743 } else { | 835 } else { |
744 debug_printf("gtkspell started with ispell\n"); | 836 debug_printf("gtkspell started with ispell\n"); |
745 } | 837 } |
746 } | 838 } |
747 | 839 #endif |
748 static_proto_init(); | 840 static_proto_init(); |
749 | 841 |
750 /* deal with --login */ | 842 /* deal with --login */ |
751 if (opt_login) { | 843 if (opt_login) { |
752 do_login_ret = do_auto_login(opt_login_arg); | 844 do_login_ret = do_auto_login(opt_login_arg); |
761 | 853 |
762 if (opt_acct) { | 854 if (opt_acct) { |
763 account_editor(NULL, NULL); | 855 account_editor(NULL, NULL); |
764 } else if ((do_login_ret == -1) && !connections) | 856 } else if ((do_login_ret == -1) && !connections) |
765 show_login(); | 857 show_login(); |
858 #ifdef _WIN32 | |
859 /* Various win32 initializations */ | |
860 wgaim_init(); | |
861 #endif | |
766 | 862 |
767 gtk_main(); | 863 gtk_main(); |
768 | 864 #ifndef _WIN32 |
769 if (convo_options & OPT_CONVO_CHECK_SPELLING) | 865 if (convo_options & OPT_CONVO_CHECK_SPELLING) |
770 gtkspell_stop(); | 866 gtkspell_stop(); |
867 #endif | |
771 core_quit(); | 868 core_quit(); |
772 /* don't need ui_quit here because ui doesn't create anything */ | 869 /* don't need ui_quit here because ui doesn't create anything */ |
773 | 870 |
774 return 0; | 871 return 0; |
775 | 872 |