Index: src/main.c =================================================================== RCS file: /cvs/gnome/jamboree/src/main.c,v retrieving revision 1.14 diff -u -p -r1.14 main.c --- src/main.c 2 Feb 2004 17:53:42 -0000 1.14 +++ src/main.c 3 Feb 2004 17:40:32 -0000 @@ -48,50 +48,147 @@ static char *arg_remote = NULL; #endif -static int arg_version = FALSE; - GConfClient *gconf_client; -static struct poptOption options[] = { - { - NULL, - '\0', - POPT_ARG_INCLUDE_TABLE, - poptHelpOptions, - 0, - N_("Help options"), - NULL - }, +enum { + ARG_VERSION=1, + ARG_REMOTE +}; + +static void +_jamboree_popt_callback (poptContext context, enum poptCallbackReason reason, + const GstPoptOption *option, const char *arg, void *data) +{ + switch (reason) + { + case POPT_CALLBACK_REASON_PRE: + case POPT_CALLBACK_REASON_POST: + break; + case POPT_CALLBACK_REASON_OPTION: + switch (option->val) + { + case ARG_VERSION: + g_print ("%s\n", VERSION); + exit (0); + +#ifdef HAVE_DBUS + case ARG_REMOTE: + if (arg_remote) + { + if (strcmp (arg_remote, "play") == 0) + dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_PLAY); + else if (strcmp (arg_remote, "stop") == 0) + dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_STOP); + else if (strcmp (arg_remote, "prev") == 0) + dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_PREV); + else if (strcmp (arg_remote, "next") == 0) + dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_NEXT); + else if (strcmp (arg_remote, "pop-mute") == 0) + dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_POP_MUTE); + else if (strcmp (arg_remote, "push-mute") == 0) + dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_PUSH_MUTE); + else if (strcmp (arg_remote, "current-song") == 0) + { + DBusMessage *reply; + Song *song; + + reply = dbus_send_remote_cmd_with_reply (JAMBOREE_DBUS_PLAYER_GET_CURRENT_SONG); + + if (!reply) + { + g_printerr ("Couldn't contact Jamboree service.\n"); + exit (1); + } + + song = dbus_message_to_song (reply); + g_print ("%s - %s\n", + string_entry_get_str (song->title), + string_entry_get_str (song->artist)); + + dbus_message_unref (reply); + } + else if (strcmp (arg_remote, "quit") == 0) + dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_QUIT); + else + { + poptPrintUsage (context, stdout, 0); + exit (1); + } + + exit (0); + } + + if (!dbus_init_service ()) + { + g_printerr ("Couldn't init Jamboree service.\n"); + return FALSE; + } + + dbus_init_handler (); +#endif + } + } + +} + +static struct poptOption jamboree_options[] = { + { + NULL, + '\0', + POPT_ARG_CALLBACK, + (void *) &_jamboree_popt_callback, + 0, + NULL, + NULL + }, #ifdef HAVE_DBUS { "remote", 'r', POPT_ARG_STRING, &arg_remote, - 0, + ARG_REMOTE, N_("Specify a command to pass to an already running instance of Jamboree."), - N_("play|stop|prev|next|pop-mute|push-mute|quit|current-song") + N_("play|stop|prev|next|pop-mute| push-mute|quit|current-song") }, #endif { "version", 'v', POPT_ARG_NONE, - &arg_version, - 0, + NULL, + ARG_VERSION, N_("Print version"), NULL }, + POPT_TABLEEND +}; + +#ifndef HAVE_GST +/* if we can't have GStreamer do our popt stuff we need to make a complete + * popt table ourselves */ +static struct poptOption options[] = { { NULL, '\0', + POPT_ARG_INCLUDE_TABLE, + poptHelpOptions, 0, + "Help options:", + NULL + }, + { NULL, + '\0', + POPT_ARG_INCLUDE_TABLE, + jamboree_options, 0, - NULL, + "Application options:", NULL - } + }, + POPT_TABLEEND }; +#endif static void @@ -133,12 +230,20 @@ main (int argc, char **argv) SongDB *db; GtkWidget *window; char *filename; + +#ifndef HAVE_GST poptContext ctx; int nextopt; +#endif bindtextdomain (GETTEXT_PACKAGE, JAMBOREE_LOCALEDIR); textdomain (GETTEXT_PACKAGE); +#ifdef HAVE_GST + gst_init_with_popt_table (&argc, &argv, (GstPoptOption *) &jamboree_options); +#else + /* if we don't have GStreamer we need to process the popt table manually */ + ctx = poptGetContext ("jamboree", argc, (const char **) argv, options, 0); poptReadDefaultConfig (ctx, TRUE); @@ -159,82 +264,18 @@ main (int argc, char **argv) return 1; } - if (arg_version) - { - g_print ("%s\n", VERSION); - return 0; - } -#ifdef HAVE_DBUS - if (arg_remote) - { - if (strcmp (arg_remote, "play") == 0) - dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_PLAY); - else if (strcmp (arg_remote, "stop") == 0) - dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_STOP); - else if (strcmp (arg_remote, "prev") == 0) - dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_PREV); - else if (strcmp (arg_remote, "next") == 0) - dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_NEXT); - else if (strcmp (arg_remote, "pop-mute") == 0) - dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_POP_MUTE); - else if (strcmp (arg_remote, "push-mute") == 0) - dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_PUSH_MUTE); - else if (strcmp (arg_remote, "current-song") == 0) - { - DBusMessage *reply; - Song *song; - - reply = dbus_send_remote_cmd_with_reply (JAMBOREE_DBUS_PLAYER_GET_CURRENT_SONG); - - if (!reply) - { - g_printerr ("Couldn't contact Jamboree service.\n"); - exit (1); - } - - song = dbus_message_to_song (reply); - g_print ("%s - %s\n", - string_entry_get_str (song->title), - string_entry_get_str (song->artist)); - - dbus_message_unref (reply); - } - else if (strcmp (arg_remote, "quit") == 0) - dbus_send_remote_cmd (JAMBOREE_DBUS_PLAYER_QUIT); - else - { - poptPrintUsage (ctx, stdout, 0); - return 1; - } - - return 0; - } - - if (!dbus_init_service ()) - { - g_printerr ("Couldn't init Jamboree service.\n"); - return FALSE; - } - - dbus_init_handler (); - -#endif g_random_set_seed (time (NULL)); + gst_control_init (&argc, &argv); + +#endif /* HAVE_GST */ + gtk_init (&argc, &argv); stock_icons_register (); -#ifdef HAVE_GST - gst_init (&argc, &argv); - gst_control_init (&argc, &argv); - - /* FIXME: Work around broken i18n in GStreamer until bug #133086 is fixed. */ - textdomain (GETTEXT_PACKAGE); -#endif - string_entry_init (); ensure_dir ();