Mercurial > audlegacy
comparison src/audacious/main.c @ 2411:ffbac11b3a77 trunk
[svn] - use GOption instead of getopt.
- remove nolonger used GNU getopt code
author | nenolod |
---|---|
date | Fri, 26 Jan 2007 07:32:55 -0800 |
parents | 15fc0d852633 |
children | f0d65a33bf64 |
comparison
equal
deleted
inserted
replaced
2410:79b4e8e4e2a7 | 2411:ffbac11b3a77 |
---|---|
85 | 85 |
86 const gchar *application_name = N_("Audacious"); | 86 const gchar *application_name = N_("Audacious"); |
87 | 87 |
88 | 88 |
89 struct _BmpCmdLineOpt { | 89 struct _BmpCmdLineOpt { |
90 GList *filenames; | 90 gchar **filenames; |
91 gint session; | 91 gint session; |
92 gboolean play, stop, pause, fwd, rew, play_pause, playcd, show_jump_box; | 92 gboolean play, stop, pause, fwd, rew, play_pause, playcd, show_jump_box; |
93 gboolean enqueue, mainwin, remote, activate; | 93 gboolean enqueue, mainwin, remote, activate; |
94 gboolean load_skins; | 94 gboolean load_skins; |
95 gboolean headless; | 95 gboolean headless; |
96 gboolean no_log; | 96 gboolean no_log; |
97 gboolean enqueue_to_temp; | 97 gboolean enqueue_to_temp; |
98 gboolean version; | |
98 gchar *previous_session_id; | 99 gchar *previous_session_id; |
99 }; | 100 }; |
100 | 101 |
101 typedef struct _BmpCmdLineOpt BmpCmdLineOpt; | 102 typedef struct _BmpCmdLineOpt BmpCmdLineOpt; |
102 | 103 |
820 | 821 |
821 gtk_icon_factory_add_default( iconfactory ); | 822 gtk_icon_factory_add_default( iconfactory ); |
822 g_object_unref( iconfactory ); | 823 g_object_unref( iconfactory ); |
823 } | 824 } |
824 | 825 |
825 static void | 826 static GOptionEntry cmd_entries[] = { |
826 display_usage(void) | 827 {"session", 'n', 0, G_OPTION_ARG_INT, &options.session, "Select which Audacious session ID to use", NULL}, |
827 { | 828 {"rew", 'r', 0, G_OPTION_ARG_NONE, &options.rew, "Skip backwards in playlist", NULL}, |
828 g_print(_("Usage: audacious [options] [files] ...\n\n" | 829 {"play", 'p', 0, G_OPTION_ARG_NONE, &options.play, "Start playing current playlist", NULL}, |
829 "Options:\n" | 830 {"pause", 'u', 0, G_OPTION_ARG_NONE, &options.pause, "Pause current song", NULL}, |
830 "--------\n")); | 831 {"stop", 's', 0, G_OPTION_ARG_NONE, &options.pause, "Stop current song", NULL}, |
831 g_print("\n-h, --help "); | 832 {"play-pause", 't', 0, G_OPTION_ARG_NONE, &options.pause, "Pause if playing, play otherwise", NULL}, |
832 /* -h, --help switch */ | 833 {"fwd", 'f', 0, G_OPTION_ARG_NONE, &options.fwd, "Skip forward in playlist", NULL}, |
833 g_print(_("Display this text and exit")); | 834 {"show-jump-box", 'j', 0, G_OPTION_ARG_NONE, &options.show_jump_box, "Display Jump to File dialog", NULL}, |
834 g_print("\n-n, --session "); | 835 {"enqueue", 'e', 0, G_OPTION_ARG_NONE, &options.enqueue, "Don't clear the playlist", NULL}, |
835 /* -n, --session switch */ | 836 {"enqueue-to-temp", 'E', 0, G_OPTION_ARG_NONE, &options.enqueue_to_temp, "Add new files to a temporary playlist", NULL}, |
836 g_print(_("Select Audacious/BMP/XMMS session (Default: 0)")); | 837 {"show-main-window", 'm', 0, G_OPTION_ARG_NONE, &options.mainwin, "Display the main window", NULL}, |
837 g_print("\n-r, --rew "); | 838 {"activate", 'a', 0, G_OPTION_ARG_NONE, &options.activate, "Display all open Audacious windows", NULL}, |
838 /* -r, --rew switch */ | 839 {"headless", 'H', 0, G_OPTION_ARG_NONE, &options.headless, "Enable headless operation", NULL}, |
839 g_print(_("Skip backwards in playlist")); | 840 {"no-log", 'N', 0, G_OPTION_ARG_NONE, &options.no_log, "Print all errors and warnings to stdout", NULL}, |
840 g_print("\n-p, --play "); | 841 {"version", 'v', 0, G_OPTION_ARG_NONE, &options.version, "Show version and builtin features", NULL}, |
841 /* -p, --play switch */ | 842 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &options.filenames, N_("FILE..."), NULL}, |
842 g_print(_("Start playing current playlist")); | 843 {NULL}, |
843 g_print("\n-u, --pause "); | 844 }; |
844 /* -u, --pause switch */ | |
845 g_print(_("Pause current song")); | |
846 g_print("\n-s, --stop "); | |
847 /* -s, --stop switch */ | |
848 g_print(_("Stop current song")); | |
849 g_print("\n-t, --play-pause "); | |
850 /* -t, --play-pause switch */ | |
851 g_print(_("Pause if playing, play otherwise")); | |
852 g_print("\n-f, --fwd "); | |
853 /* -f, --fwd switch */ | |
854 g_print(_("Skip forward in playlist")); | |
855 g_print("\n-j, --show-jump-box "); | |
856 /* -j, --show-jump-box switch */ | |
857 g_print(_("Display Jump to file dialog")); | |
858 g_print("\n-e, --enqueue "); | |
859 /* -e, --enqueue switch */ | |
860 g_print(_("Don't clear the playlist")); | |
861 g_print("\n-m, --show-main-window "); | |
862 /* -m, --show-main-window switch */ | |
863 g_print(_("Show the main window")); | |
864 g_print("\n-a, --activate "); | |
865 /* -a, --activate switch */ | |
866 g_print(_("Activate Audacious")); | |
867 g_print("\n-i, --sm-client-id "); | |
868 /* -i, --sm-client-id switch */ | |
869 g_print(_("Previous session ID")); | |
870 g_print("\n-H, --headless "); | |
871 /* -h, --headless switch */ | |
872 g_print(_("Headless operation [experimental]")); | |
873 g_print("\n-N, --no-log "); | |
874 /* -N, --no-log switch */ | |
875 g_print(_("Disable error/warning interception (logging)")); | |
876 g_print("\n-v, --version "); | |
877 /* -v, --version switch */ | |
878 g_print(_("Print version number and exit\n")); | |
879 | |
880 exit(EXIT_SUCCESS); | |
881 } | |
882 | |
883 static void | |
884 parse_cmd_line(gint argc, | |
885 gchar ** argv, | |
886 BmpCmdLineOpt * options) | |
887 { | |
888 static struct option long_options[] = { | |
889 {"help", 0, NULL, 'h'}, | |
890 {"session", 1, NULL, 'n'}, | |
891 {"rew", 0, NULL, 'r'}, | |
892 {"play", 0, NULL, 'p'}, | |
893 {"pause", 0, NULL, 'u'}, | |
894 {"play-pause", 0, NULL, 't'}, | |
895 {"stop", 0, NULL, 's'}, | |
896 {"fwd", 0, NULL, 'f'}, | |
897 {"show-jump-box", 0, NULL, 'j'}, | |
898 {"enqueue", 0, NULL, 'e'}, | |
899 {"enqueue-to-temp", 0, NULL, 'E'}, | |
900 {"show-main-window", 0, NULL, 'm'}, | |
901 {"activate", 0, NULL, 'a'}, | |
902 {"version", 0, NULL, 'v'}, | |
903 {"sm-client-id", 1, NULL, 'i'}, | |
904 {"xmms", 0, NULL, 'x'}, | |
905 {"headless", 0, NULL, 'H'}, | |
906 {"no-log", 0, NULL, 'N'}, | |
907 {0, 0, 0, 0} | |
908 }; | |
909 | |
910 gchar *filename, *current_dir; | |
911 gint c, i; | |
912 | |
913 memset(options, 0, sizeof(BmpCmdLineOpt)); | |
914 options->session = -1; | |
915 | |
916 while ((c = getopt_long(argc, argv, "chn:HrpusfemavtLSjE", long_options, | |
917 NULL)) != -1) { | |
918 switch (c) { | |
919 case 'h': | |
920 display_usage(); | |
921 break; | |
922 case 'n': | |
923 options->session = atoi(optarg); | |
924 break; | |
925 case 'H': | |
926 options->headless = TRUE; | |
927 break; | |
928 case 'r': | |
929 options->rew = TRUE; | |
930 break; | |
931 case 'p': | |
932 options->play = TRUE; | |
933 break; | |
934 case 'u': | |
935 options->pause = TRUE; | |
936 break; | |
937 case 's': | |
938 options->stop = TRUE; | |
939 break; | |
940 case 'f': | |
941 options->fwd = TRUE; | |
942 break; | |
943 case 't': | |
944 options->play_pause = TRUE; | |
945 break; | |
946 case 'j': | |
947 options->show_jump_box = TRUE; | |
948 break; | |
949 case 'm': | |
950 options->mainwin = TRUE; | |
951 break; | |
952 case 'a': | |
953 options->activate = TRUE; | |
954 break; | |
955 case 'E': | |
956 options->enqueue_to_temp = TRUE; | |
957 break; | |
958 case 'e': | |
959 options->enqueue = TRUE; | |
960 break; | |
961 case 'v': | |
962 dump_version(); | |
963 exit(EXIT_SUCCESS); | |
964 break; | |
965 case 'i': | |
966 options->previous_session_id = g_strdup(optarg); | |
967 break; | |
968 case 'c': | |
969 options->playcd = TRUE; | |
970 break; | |
971 case 'S': | |
972 options->load_skins = TRUE; | |
973 break; | |
974 case 'N': | |
975 options->no_log = TRUE; | |
976 break; | |
977 } | |
978 } | |
979 | |
980 current_dir = g_get_current_dir(); | |
981 | |
982 for (i = optind; i < argc; i++) { | |
983 if (argv[i][0] == '/' || strstr(argv[i], "://")) | |
984 filename = g_strdup(argv[i]); | |
985 else | |
986 filename = g_build_filename(current_dir, argv[i], NULL); | |
987 | |
988 options->filenames = g_list_prepend(options->filenames, filename); | |
989 } | |
990 | |
991 options->filenames = g_list_reverse(options->filenames); | |
992 | |
993 g_free(current_dir); | |
994 } | |
995 | 845 |
996 static void | 846 static void |
997 handle_cmd_line_options(BmpCmdLineOpt * options, | 847 handle_cmd_line_options(BmpCmdLineOpt * options, |
998 gboolean remote) | 848 gboolean remote) |
999 { | 849 { |
1000 GList *filenames = options->filenames; | 850 gchar **filenames = options->filenames; |
1001 gint session = options->session; | 851 gint session = options->session; |
852 | |
853 if (options->version) | |
854 { | |
855 dump_version(); | |
856 exit(EXIT_SUCCESS); | |
857 } | |
1002 | 858 |
1003 if (session == -1) { | 859 if (session == -1) { |
1004 if (!remote) | 860 if (!remote) |
1005 session = ctrlsocket_get_session_id(); | 861 session = ctrlsocket_get_session_id(); |
1006 else | 862 else |
1007 session = 0; | 863 session = 0; |
1008 } | 864 } |
1009 | 865 |
1010 if (filenames) { | 866 if (filenames != NULL) |
867 { | |
1011 gint pos = 0; | 868 gint pos = 0; |
1012 | 869 gint i = 0; |
1013 if (options->load_skins) { | 870 |
1014 xmms_remote_set_skin(session, filenames->data); | 871 for (i = 0; filenames[i] != NULL; i++) |
1015 skin_install_skin(filenames->data); | 872 { |
873 if (options->load_skins) | |
874 { | |
875 xmms_remote_set_skin(session, filenames[i]); | |
876 skin_install_skin(filenames[i]); | |
877 } | |
878 else | |
879 { | |
880 if (options->enqueue_to_temp) | |
881 xmms_remote_playlist_enqueue_to_temp(session, filenames[i]); | |
882 | |
883 if (options->enqueue && options->play) | |
884 pos = xmms_remote_get_playlist_length(session); | |
885 | |
886 if (!options->enqueue) | |
887 xmms_remote_playlist_clear(session); | |
888 | |
889 xmms_remote_playlist_add_url_string(session, filenames[i]); | |
890 | |
891 if (options->enqueue && options->play && | |
892 xmms_remote_get_playlist_length(session) > pos) | |
893 xmms_remote_set_playlist_pos(session, pos); | |
894 | |
895 if (!options->enqueue) | |
896 xmms_remote_play(session); | |
897 } | |
1016 } | 898 } |
1017 else { | 899 |
1018 if (options->enqueue_to_temp) | 900 g_strfreev(filenames); |
1019 xmms_remote_playlist_enqueue_to_temp(session, filenames->data); | |
1020 | |
1021 if (options->enqueue && options->play) | |
1022 pos = xmms_remote_get_playlist_length(session); | |
1023 | |
1024 if (!options->enqueue) | |
1025 xmms_remote_playlist_clear(session); | |
1026 | |
1027 xmms_remote_playlist_add(session, filenames); | |
1028 | |
1029 if (options->enqueue && options->play && | |
1030 xmms_remote_get_playlist_length(session) > pos) | |
1031 xmms_remote_set_playlist_pos(session, pos); | |
1032 | |
1033 if (!options->enqueue) | |
1034 xmms_remote_play(session); | |
1035 } | |
1036 | |
1037 g_list_foreach(filenames, (GFunc) g_free, NULL); | |
1038 g_list_free(filenames); | |
1039 } | 901 } |
1040 | 902 |
1041 if (options->rew) | 903 if (options->rew) |
1042 xmms_remote_playlist_prev(session); | 904 xmms_remote_playlist_prev(session); |
1043 | 905 |
1122 gint | 984 gint |
1123 main(gint argc, gchar ** argv) | 985 main(gint argc, gchar ** argv) |
1124 { | 986 { |
1125 gboolean gtk_init_check_ok; | 987 gboolean gtk_init_check_ok; |
1126 Playlist *playlist; | 988 Playlist *playlist; |
989 GOptionContext *context; | |
990 GError *error = NULL; | |
1127 | 991 |
1128 /* Setup l10n early so we can print localized error messages */ | 992 /* Setup l10n early so we can print localized error messages */ |
1129 gtk_set_locale(); | 993 gtk_set_locale(); |
1130 bindtextdomain(PACKAGE_NAME, LOCALEDIR); | 994 bindtextdomain(PACKAGE_NAME, LOCALEDIR); |
1131 bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"); | 995 bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"); |
1160 | 1024 |
1161 cond_scan = g_cond_new(); | 1025 cond_scan = g_cond_new(); |
1162 mutex_scan = g_mutex_new(); | 1026 mutex_scan = g_mutex_new(); |
1163 | 1027 |
1164 gtk_init_check_ok = gtk_init_check(&argc, &argv); | 1028 gtk_init_check_ok = gtk_init_check(&argc, &argv); |
1165 /* Now let's parse the command line options first. */ | 1029 |
1166 parse_cmd_line(argc, argv, &options); | 1030 context = g_option_context_new(_("- play multimedia files")); |
1031 g_option_context_add_main_entries(context, cmd_entries, PACKAGE_NAME); | |
1032 g_option_context_add_group(context, gtk_get_option_group(TRUE)); | |
1033 g_option_context_parse(context, &argc, &argv, &error); | |
1034 | |
1167 if (!gtk_init_check_ok) { | 1035 if (!gtk_init_check_ok) { |
1168 if (argc < 2) { | 1036 if (argc < 2) { |
1169 /* GTK check failed, and no arguments passed to indicate | 1037 /* GTK check failed, and no arguments passed to indicate |
1170 that user is intending to only remote control a running | 1038 that user is intending to only remote control a running |
1171 session */ | 1039 session */ |