Skip to content

Commit

Permalink
Add --quit-after-play option. Closes: #230.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Feb 3, 2013
1 parent 1ae47d2 commit f3b76ba
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/audacious/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static struct {
bool_t play, stop, pause, fwd, rew, play_pause, show_jump_box;
bool_t enqueue, mainwin, remote;
bool_t enqueue_to_temp;
bool_t quit_after_play;
bool_t version;
bool_t verbose;
char *previous_session_id;
Expand Down Expand Up @@ -241,9 +242,10 @@ static GOptionEntry cmd_entries[] = {
{"enqueue", 'e', 0, G_OPTION_ARG_NONE, &options.enqueue, N_("Add files to the playlist"), NULL},
{"enqueue-to-temp", 'E', 0, G_OPTION_ARG_NONE, &options.enqueue_to_temp, N_("Add new files to a temporary playlist"), NULL},
{"show-main-window", 'm', 0, G_OPTION_ARG_NONE, &options.mainwin, N_("Display the main window"), NULL},
{"headless", 'h', 0, G_OPTION_ARG_NONE, & headless, N_("Headless mode"), NULL},
{"quit-after-play", 'q', 0, G_OPTION_ARG_NONE, &options.quit_after_play, N_("Quit on playback stop"), NULL},
{"version", 'v', 0, G_OPTION_ARG_NONE, &options.version, N_("Show version"), NULL},
{"verbose", 'V', 0, G_OPTION_ARG_NONE, &options.verbose, N_("Print debugging messages"), NULL},
{"headless", 'h', 0, G_OPTION_ARG_NONE, & headless, N_("Headless mode (beta)"), NULL},
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &options.filenames, N_("FILE..."), NULL},
{NULL},
};
Expand Down Expand Up @@ -544,6 +546,17 @@ bool_t do_autosave (void)
return TRUE;
}

static bool_t check_should_quit (void)
{
return options.quit_after_play && ! drct_get_playing () && ! playlist_add_in_progress (-1);
}

static void maybe_quit (void)
{
if (check_should_quit ())
gtk_main_quit ();
}

int main(int argc, char ** argv)
{
init_one ();
Expand All @@ -564,10 +577,20 @@ int main(int argc, char ** argv)
AUDDBG ("Startup complete.\n");
g_timeout_add_seconds (AUTOSAVE_INTERVAL, (GSourceFunc) do_autosave, NULL);

if (check_should_quit ())
goto QUIT;

hook_associate ("playback stop", (HookFunction) maybe_quit, NULL);
hook_associate ("playlist add complete", (HookFunction) maybe_quit, NULL);
hook_associate ("quit", (HookFunction) gtk_main_quit, NULL);

gtk_main ();

hook_dissociate ("playback stop", (HookFunction) maybe_quit);
hook_dissociate ("playlist add complete", (HookFunction) maybe_quit);
hook_dissociate ("quit", (HookFunction) gtk_main_quit);

QUIT:
shut_down ();
release_lock ();
return EXIT_SUCCESS;
Expand Down

0 comments on commit f3b76ba

Please sign in to comment.