Mercurial > pidgin.yaz
changeset 1009:d496fe2614a6
[gaim-migrate @ 1019]
command-line options for the app. not for the applet because most of the time you don't run it from the command line anyway. thanks bmiller
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 20 Oct 2000 00:35:30 +0000 |
parents | 1b99caffcd98 |
children | 4dca3277ea15 |
files | src/about.c src/aim.c src/gaim.h src/multi.c src/util.c |
diffstat | 5 files changed, 238 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/about.c Thu Oct 19 22:34:22 2000 +0000 +++ b/src/about.c Fri Oct 20 00:35:30 2000 +0000 @@ -121,14 +121,17 @@ button = gtk_button_new_with_label("Close"); - if (null == NULL) /* there's a mindtrip */ + if (null == NULL) {/* there's a mindtrip */ gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(destroy_about), GTK_OBJECT(about)); - else + gtk_signal_connect(GTK_OBJECT(about), "destroy", + GTK_SIGNAL_FUNC(destroy_about), GTK_OBJECT(about)); + } else { gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(version_exit), NULL); - gtk_signal_connect(GTK_OBJECT(about), "destroy", - GTK_SIGNAL_FUNC(destroy_about), GTK_OBJECT(about)); + gtk_signal_connect(GTK_OBJECT(about), "destroy", + GTK_SIGNAL_FUNC(version_exit), NULL); + } if (display_options & OPT_DISP_COOL_LOOK) gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
--- a/src/aim.c Thu Oct 19 22:34:22 2000 +0000 +++ b/src/aim.c Fri Oct 20 00:35:30 2000 +0000 @@ -53,6 +53,9 @@ #endif #include "locale.h" #include "gtkticker.h" +#ifndef USE_GNOME +#include <getopt.h> +#endif static GtkWidget *name; static GtkWidget *pass; @@ -73,6 +76,7 @@ char toc_addy[16]; char *quad_addr = NULL; + void cancel_logon(void) { #ifdef USE_APPLET @@ -430,8 +434,39 @@ } #endif + int main(int argc, char *argv[]) { + char opt, i; + int opt_acct = 0, opt_help = 0, opt_version = 0, + opt_user = 0, opt_login = 0, do_login_ret = -1; + char *opt_user_arg = NULL, *opt_login_arg = NULL; + +#ifdef USE_GNOME + poptContext popt_context; + struct poptOption popt_options[] = + { + {"acct", 'a', POPT_ARG_NONE, &opt_acct, 'a', + "Display account editor window", NULL}, + {"login", 'l', POPT_ARG_STRING, NULL, 'l', + "Automatically login (optional argument NAME specifies account(s) to use)", "[NAME]"}, + {"user", 'u', POPT_ARG_STRING, &opt_user_arg, 'u', + "Use account NAME", "NAME"}, + {0, 0, 0, 0, 0, 0, 0} + }; +#else + struct option long_options[] = + { + {"acct", no_argument, NULL, 'a'}, + {"help", no_argument, NULL, 'h'}, + {"login", optional_argument, NULL, 'l'}, + {"user", required_argument, NULL, 'u'}, + {"version", no_argument, NULL, 'v'}, + {0, 0, 0, 0} + }; +#endif /* USE_GNOME */ + + #ifdef ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); @@ -442,7 +477,84 @@ /* signal(SIGSEGV, sighandler); */ #endif - if (argc > 1 && !strcmp(argv[1], "--version")) { + +#ifdef USE_APPLET + init_applet_mgr(argc, argv); +#elif defined USE_GNOME + for (i = 0; i < argc; i++) { + /* --login option */ + if (strstr (argv[i], "--l") == argv[i]) { + char *equals; + opt_login = 1; + if ((equals = strchr(argv[i], '=')) != NULL) { + /* --login=NAME */ + opt_login_arg = g_strdup (equals+1); + } else if (i+1 < argc && argv[i+1][0] != '-') { + /* --login NAME */ + opt_login_arg = g_strdup (argv[i+1]); + strcpy (argv[i+1], " "); + } + strcpy (argv[i], " "); + } + /* -l option */ + else if (strstr (argv[i], "-l") == argv[i]) { + opt_login = 1; + if (strlen (argv[i]) > 2) { + /* -lNAME */ + opt_login_arg = g_strdup (argv[i]+2); + } else if (i+1 < argc && argv[i+1][0] != '-') { + /* -l NAME */ + opt_login_arg = g_strdup (argv[i+1]); + strcpy (argv[i+1], " "); + } + strcpy (argv[i], " "); + } + } + + gnome_init_with_popt_table(PACKAGE,VERSION,argc,argv, + popt_options,0,NULL); +#else + gtk_init(&argc, &argv); + + /* scan command-line options */ + opterr = 1; + while ((opt = getopt_long (argc, argv, /*"ahl::u:v"*/"ahl::u:v", + long_options, NULL)) != -1) { + switch (opt) { + case 'u': /* set user */ + opt_user = 1; + opt_user_arg = g_strdup (optarg); + break; + case 'l': + opt_login = 1; + opt_login_arg = g_strdup (optarg); + break; + case 'a': /* account editor */ + opt_acct = 1; + break; + case 'v': /* version */ + opt_version = 1; + break; + case 'h': /* help */ + opt_help = 1; + break; + case '?': + default: + show_usage(1, argv[0]); + return 0; + break; + } + } + +#endif /* USE_GNOME */ + + /* show help message */ + if (opt_help) { + show_usage(0, argv[0]); + return 0; + } + /* show version window */ + if (opt_version) { gtk_init(&argc, &argv); set_defaults(FALSE); /* needed for open_url_nw */ load_prefs(); @@ -451,17 +563,19 @@ return 0; } -#ifdef USE_APPLET - init_applet_mgr(argc, argv); -#elif defined USE_GNOME - gnome_init(PACKAGE,VERSION,argc,argv); -#else - gtk_init(&argc, &argv); -#endif /* USE_GNOME */ set_defaults(FALSE); load_prefs(); + /* set the default username */ + if (opt_user_arg != NULL) { + set_first_user (opt_user_arg); +#ifndef USE_GNOME + g_free (opt_user_arg); + opt_user_arg = NULL; +#endif /* USE_GNOME */ + } + if (general_options & OPT_GEN_DEBUG) show_debug(NULL); @@ -471,9 +585,19 @@ perl_init(); perl_autoload(); #endif + static_proto_init(); - static_proto_init(); - auto_login(); + /* deal with --login */ + if (opt_login) { + do_login_ret = do_auto_login (opt_login_arg); + if (opt_login_arg != NULL) { + g_free (opt_login_arg); + opt_login_arg = NULL; + } + } + + if (!opt_acct) + auto_login(); #ifdef USE_APPLET applet_widget_register_callback(APPLET_WIDGET(applet), @@ -499,7 +623,10 @@ applet_widget_gtk_main(); #else - show_login(); + if (opt_acct) { + account_editor (NULL, NULL); + } else if (do_login_ret == -1) + show_login(); gtk_main(); #endif /* USE_APPLET */
--- a/src/gaim.h Thu Oct 19 22:34:22 2000 +0000 +++ b/src/gaim.h Fri Oct 20 00:35:30 2000 +0000 @@ -625,6 +625,9 @@ extern void translate_blt (FILE *, char *); extern char *stylize(gchar *, int); extern int set_dispstyle (int); +extern void show_usage (int, char *); +extern void set_first_user (char *); +extern int do_auto_login (char *); /* Functions in server.c */ /* input to serv */
--- a/src/multi.c Thu Oct 19 22:34:22 2000 +0000 +++ b/src/multi.c Fri Oct 20 00:35:30 2000 +0000 @@ -96,11 +96,15 @@ gtk_widget_destroy(acctedit); } acctedit = NULL; + if (d == NULL && blist == NULL) + exit(0); } static gint acctedit_close(GtkWidget *w, gpointer d) { gtk_widget_destroy(acctedit); + if (d == NULL && blist == NULL) + exit(0); return FALSE; } @@ -559,7 +563,7 @@ gtk_container_border_width(GTK_CONTAINER(acctedit), 10); gtk_widget_set_usize(acctedit, -1, 200); gtk_signal_connect(GTK_OBJECT(acctedit), "destroy", - GTK_SIGNAL_FUNC(delete_acctedit), NULL); + GTK_SIGNAL_FUNC(delete_acctedit), W); frame = gtk_frame_new(_("Account Editor")); gtk_container_add(GTK_CONTAINER(acctedit), frame); @@ -594,7 +598,7 @@ button = picture_button(acctedit, _("Close"), gnome_close_xpm); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); - gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(acctedit_close), NULL); + gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(acctedit_close), W); gtk_widget_show(acctedit); }
--- a/src/util.c Thu Oct 19 22:34:22 2000 +0000 +++ b/src/util.c Fri Oct 20 00:35:30 2000 +0000 @@ -1180,3 +1180,87 @@ } return dispstyle; } + + +void show_usage (int mode, char *name) +{ + switch (mode) { + case 0: /* full help text */ + printf ("Usage: %s [OPTION]...\n\n" + " -a, --acct display account editor window\n" + " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" + " account(s) to use)\n" + " -u, --user=NAME use account NAME\n" + " -v, --version display version information window\n" + " -h, --help display this help and exit\n", name); + break; + case 1: /* short message */ + printf ("Try `%s -h' for more information.\n", name); + break; + } +} + + +void set_first_user (char *name) +{ + struct aim_user *u; + + u = find_user (name); + + if (!u) { /* new user */ + u = g_new0(struct aim_user, 1); + g_snprintf(u->username, sizeof(u->username), "%s", name); + u->protocol = 0 /* PROTO_TOC */; + aim_users = g_list_prepend (aim_users, u); + } else { /* user already exists */ + aim_users = g_list_remove (aim_users, u); + aim_users = g_list_prepend (aim_users, u); + } + save_prefs(); +} + + +/* <name> is a comma-separated list of names, or NULL + if NULL and there is at least one user defined in .gaimrc, try to login. + if not NULL, parse <name> into separate strings, look up each one in + .gaimrc and, if it's there, try to login. + returns: 0 if successful + -1 if no user was found that had a saved password +*/ +int do_auto_login (char *name) +{ + struct aim_user *u; + char **names, **n, *first = NULL; + int retval = -1; + + if (name != NULL) { /* list of names given */ + names = g_strsplit (name, ",", 32); + for (n = names; *n != NULL; n++) { + printf ("user %s...\n", *n); + u = find_user(*n); + if (u) { /* found a user */ + if (first == NULL) + first = g_strdup (*n); + if (u->options & OPT_USR_REM_PASS) { + printf ("got user %s\n", *n); + retval = 0; + serv_login(u); + } + } + } + /* make the first user listed the default */ + if (first != NULL) + set_first_user (first); + g_strfreev (names); + g_free (first); + } else { /* no name given, use default */ + u = (struct aim_user *)aim_users->data; + if (u->options & OPT_USR_REM_PASS) { + retval = 0; + serv_login(u); + } + } + + return retval; +} +