Anna Schumaker
7558a32940
If multiple paths are passed, then only load the first one to keep things simple. Implements #102: Allow outside tracks Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
152 lines
4.5 KiB
C
152 lines
4.5 KiB
C
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/core.h>
|
|
#include <gui/audio.h>
|
|
#include <gui/builder.h>
|
|
#include <gui/filter.h>
|
|
#include <gui/idle.h>
|
|
#include <gui/model.h>
|
|
#include <gui/playlist.h>
|
|
#include <gui/sidebar.h>
|
|
#include <gui/treeview.h>
|
|
#include <gui/window.h>
|
|
|
|
#define OCARINA_FLAGS (G_APPLICATION_HANDLES_COMMAND_LINE)
|
|
|
|
static const GOptionEntry ocarina_options[] = {
|
|
{ "next", 'n', 0, G_OPTION_ARG_NONE, NULL, "Play next track", NULL },
|
|
{ "pause", 'P', 0, G_OPTION_ARG_NONE, NULL, "Pause playback", NULL },
|
|
{ "play", 'p', 0, G_OPTION_ARG_NONE, NULL, "Start playback", NULL },
|
|
{ "previous", 'N', 0, G_OPTION_ARG_NONE, NULL, "Play previous track", NULL },
|
|
{ "sync", 's', 0, G_OPTION_ARG_NONE, NULL, "Don't run background tasks", NULL },
|
|
{ "toggle", 't', 0, G_OPTION_ARG_NONE, NULL, "Toggle playback state", NULL },
|
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, NULL, "Print version and exit", NULL },
|
|
{ NULL },
|
|
};
|
|
|
|
#ifndef CONFIG_DEBUG
|
|
const static gchar *OCARINA_APP = "org.gtk.ocarina";
|
|
#else
|
|
const static gchar *OCARINA_APP = "org.gtk.ocarina-debug";
|
|
#endif
|
|
|
|
static enum idle_sync_t idle_sync = IDLE_ASYNC;
|
|
static int startup_argc;
|
|
static char **startup_argv;
|
|
|
|
static gchar *find_file_path(const gchar *file)
|
|
{
|
|
gchar *path = g_strjoin("/", "share", "ocarina", file, NULL);
|
|
|
|
if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
|
|
return path;
|
|
g_free(path);
|
|
|
|
return g_strjoin("/", "/usr", "share", "ocarina", file, NULL);
|
|
}
|
|
|
|
static void __ocarina_activate(GApplication *application, gpointer data)
|
|
{
|
|
gtk_application_add_window(GTK_APPLICATION(application), gui_window());
|
|
}
|
|
|
|
static int __ocarina_local_options(GApplication *application,
|
|
GVariantDict *options, gpointer data)
|
|
{
|
|
if (g_variant_dict_contains(options, "sync"))
|
|
idle_sync = IDLE_SYNC;
|
|
if (!g_variant_dict_contains(options, "version"))
|
|
return -1;
|
|
g_printf("Ocarina %s\n", get_version());
|
|
g_printf("GTK+ %u.%u.%u\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
|
|
g_printf("%s\n", gst_version_string());
|
|
g_printf("%s, %s\n", __DATE__, __TIME__);
|
|
return 0;
|
|
}
|
|
|
|
static int __ocarina_command_line(GApplication *application,
|
|
GApplicationCommandLine *command,
|
|
gpointer data)
|
|
{
|
|
GVariantDict *options;
|
|
gchar **args;
|
|
|
|
g_application_activate(application);
|
|
|
|
args = g_application_command_line_get_arguments(command, NULL);
|
|
if (args && args[1]) {
|
|
audio_load_filepath(args[1]);
|
|
g_strfreev(args);
|
|
}
|
|
|
|
options = g_application_command_line_get_options_dict(command);
|
|
if (g_variant_dict_contains(options, "next"))
|
|
audio_next();
|
|
else if (g_variant_dict_contains(options, "pause"))
|
|
audio_pause();
|
|
else if (g_variant_dict_contains(options, "play"))
|
|
audio_play();
|
|
else if (g_variant_dict_contains(options, "previous"))
|
|
audio_prev();
|
|
else if (g_variant_dict_contains(options, "toggle")) {
|
|
if (audio_cur_state() == GST_STATE_PLAYING)
|
|
audio_pause();
|
|
else
|
|
audio_play();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void __ocarina_startup(GApplication *application, gpointer data)
|
|
{
|
|
gchar *ui = find_file_path("ocarina.ui");
|
|
gchar *icon = find_file_path("ocarina.png");
|
|
|
|
gui_builder_init(ui);
|
|
core_init(&startup_argc, &startup_argv, &playlist_cb, &audio_cb, idle_sync);
|
|
gui_window_init(icon);
|
|
gui_model_init();
|
|
gui_filter_init();
|
|
gui_treeview_init();
|
|
gui_sidebar_init();
|
|
gui_playlist_init();
|
|
gui_audio_init();
|
|
|
|
gui_idle_enable();
|
|
|
|
g_free(ui);
|
|
g_free(icon);
|
|
}
|
|
|
|
static void __ocarina_shutdown(GApplication *application, gpointer data)
|
|
{
|
|
gui_idle_disable();
|
|
gui_audio_deinit();
|
|
core_deinit();
|
|
|
|
gui_treeview_deinit();
|
|
gui_filter_deinit();
|
|
gui_model_deinit();
|
|
gui_window_deinit();
|
|
gui_builder_deinit();
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
GtkApplication *ocarina = gtk_application_new(OCARINA_APP, OCARINA_FLAGS);
|
|
startup_argc = argc;
|
|
startup_argv = argv;
|
|
|
|
g_application_add_main_option_entries(G_APPLICATION(ocarina), ocarina_options);
|
|
g_application_add_option_group(G_APPLICATION(ocarina), gst_init_get_option_group());
|
|
|
|
g_signal_connect(G_APPLICATION(ocarina), "activate", (GCallback)__ocarina_activate, NULL);
|
|
g_signal_connect(G_APPLICATION(ocarina), "handle-local-options",
|
|
(GCallback)__ocarina_local_options, NULL);
|
|
g_signal_connect(G_APPLICATION(ocarina), "command-line", (GCallback)__ocarina_command_line, NULL);
|
|
g_signal_connect(G_APPLICATION(ocarina), "startup", (GCallback)__ocarina_startup, NULL);
|
|
g_signal_connect(G_APPLICATION(ocarina), "shutdown", (GCallback)__ocarina_shutdown, NULL);
|
|
return g_application_run(G_APPLICATION(ocarina), argc, argv);
|
|
}
|