Anna Schumaker
f855eaea58
But only if the library database is empty. This patch also changes the prompt of the dialog to "Add Music" so users know what is going on. Fixes #80: Pop up FileChooserDialog the first time Ocarina is run Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
/*
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/idle.h>
|
|
#include <core/playlist.h>
|
|
#include <gui/builder.h>
|
|
#include <gui/idle.h>
|
|
#include <gui/playlist.h>
|
|
#include <glib/gi18n.h>
|
|
|
|
static void __collection_add(GtkFileChooser *chooser)
|
|
{
|
|
gchar *filename = gtk_file_chooser_get_filename(chooser);
|
|
|
|
if (playlist_new(PL_LIBRARY, filename))
|
|
gui_playlist_add_library(library_lookup(filename));
|
|
|
|
gui_idle_enable();
|
|
g_free(filename);
|
|
}
|
|
|
|
void __collection_choose(GtkButton *button, gpointer data)
|
|
{
|
|
GtkFileFilter *filter;
|
|
GtkWidget *dialog;
|
|
gint res;
|
|
|
|
filter = gtk_file_filter_new();
|
|
gtk_file_filter_add_mime_type(filter, "inode/directory");
|
|
|
|
dialog = gtk_file_chooser_dialog_new("Add Music",
|
|
GTK_WINDOW(gui_builder_widget("o_window")),
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
_("_Open"), GTK_RESPONSE_ACCEPT,
|
|
NULL);
|
|
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
|
|
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
if (res == GTK_RESPONSE_ACCEPT)
|
|
__collection_add(GTK_FILE_CHOOSER(dialog));
|
|
|
|
gtk_widget_destroy(dialog);
|
|
}
|
|
|
|
bool __gui_collection_init_idle()
|
|
{
|
|
struct db_entry *library, *next;
|
|
|
|
db_for_each(library, next, library_db_get())
|
|
gui_playlist_add_library(LIBRARY(library));
|
|
|
|
if (library_db_get()->db_size == 0)
|
|
__collection_choose(NULL, NULL);
|
|
|
|
return true;
|
|
}
|
|
|
|
void gui_collection_init()
|
|
{
|
|
idle_schedule(IDLE_SYNC, __gui_collection_init_idle, NULL);
|
|
}
|