Anna Schumaker
00c4c8a418
This gives users the ability to add new library paths by pressing the "Enter" key instead of needing to click a button with their mouse. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
70 lines
1.7 KiB
C
70 lines
1.7 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;
|
|
const gchar *path;
|
|
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_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
|
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
|
|
path = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
|
|
if (path)
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
|
|
path);
|
|
|
|
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);
|
|
}
|