2015-12-29 09:45:15 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-04-29 17:03:44 -04:00
|
|
|
#include <core/idle.h>
|
2016-01-21 10:16:37 -05:00
|
|
|
#include <core/playlist.h>
|
2016-02-18 08:34:28 -05:00
|
|
|
#include <gui/idle.h>
|
2016-08-31 09:41:42 -04:00
|
|
|
#include <gui/playlists/library.h>
|
|
|
|
#include <gui/sidebar.h>
|
2016-08-19 08:06:16 -04:00
|
|
|
#include <gui/window.h>
|
2016-05-11 10:20:21 -04:00
|
|
|
#include <glib/gi18n.h>
|
2015-12-29 09:45:15 -05:00
|
|
|
|
2016-08-31 09:01:33 -04:00
|
|
|
void __gui_pl_library_choose(GtkButton *button, gpointer data)
|
2016-05-11 10:20:21 -04:00
|
|
|
{
|
|
|
|
GtkFileFilter *filter;
|
2016-08-31 08:08:26 -04:00
|
|
|
const gchar *music;
|
2016-05-11 10:20:21 -04:00
|
|
|
GtkWidget *dialog;
|
2016-08-31 08:08:26 -04:00
|
|
|
gchar *path;
|
2016-05-11 10:20:21 -04:00
|
|
|
gint res;
|
|
|
|
|
|
|
|
filter = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_add_mime_type(filter, "inode/directory");
|
|
|
|
|
2016-08-19 08:06:16 -04:00
|
|
|
dialog = gtk_file_chooser_dialog_new("Add Music", gui_window(),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Open"), GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
2016-08-31 15:35:10 -04:00
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
2016-05-11 10:20:21 -04:00
|
|
|
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
|
|
|
2016-08-31 08:08:26 -04:00
|
|
|
music = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
|
|
|
|
if (music)
|
2016-08-30 07:47:07 -04:00
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
|
2016-08-31 08:08:26 -04:00
|
|
|
music);
|
2016-08-30 07:47:07 -04:00
|
|
|
|
2016-05-11 10:20:21 -04:00
|
|
|
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
2016-08-31 08:08:26 -04:00
|
|
|
if (res == GTK_RESPONSE_ACCEPT) {
|
|
|
|
path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
|
|
|
gui_pl_library_add(path);
|
|
|
|
g_free(path);
|
|
|
|
}
|
2016-05-11 10:20:21 -04:00
|
|
|
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
|
|
|
|
2016-08-31 09:41:42 -04:00
|
|
|
static bool __gui_pl_library_header(GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
if (gui_sidebar_iter_first(iter))
|
|
|
|
return gui_sidebar_iter_find(iter, "Library", PL_MAX_TYPE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-31 09:01:33 -04:00
|
|
|
static bool __gui_pl_library_init_idle()
|
2015-12-29 09:45:15 -05:00
|
|
|
{
|
2015-12-31 09:35:11 -05:00
|
|
|
struct db_entry *library, *next;
|
2016-08-25 14:40:45 -04:00
|
|
|
struct playlist *playlist;
|
2016-08-31 09:41:42 -04:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (!__gui_pl_library_header(&iter))
|
|
|
|
return false;
|
2016-04-29 17:03:44 -04:00
|
|
|
|
2016-08-25 14:40:45 -04:00
|
|
|
db_for_each(library, next, library_db_get()) {
|
2016-08-31 09:41:42 -04:00
|
|
|
playlist = LIBRARY(library)->li_playlist;
|
|
|
|
gui_sidebar_iter_sort_child(&iter, playlist, "folder");
|
2016-08-25 14:40:45 -04:00
|
|
|
}
|
2016-05-11 10:44:12 -04:00
|
|
|
|
2016-08-31 08:08:26 -04:00
|
|
|
#ifndef CONFIG_TESTING
|
2016-08-16 13:38:58 -04:00
|
|
|
if (library_db_get()->db_size == 0)
|
2016-08-31 09:01:33 -04:00
|
|
|
__gui_pl_library_choose(NULL, NULL);
|
2016-08-31 08:08:26 -04:00
|
|
|
#endif /* CONFIG_TESTING */
|
2016-08-16 13:38:58 -04:00
|
|
|
|
2016-05-02 18:42:38 -04:00
|
|
|
return true;
|
2016-04-29 17:03:44 -04:00
|
|
|
}
|
|
|
|
|
2016-08-31 09:01:33 -04:00
|
|
|
void gui_pl_library_init()
|
2016-04-29 17:03:44 -04:00
|
|
|
{
|
2016-08-31 09:01:33 -04:00
|
|
|
idle_schedule(IDLE_SYNC, __gui_pl_library_init_idle, NULL);
|
2015-12-30 10:38:32 -05:00
|
|
|
}
|
2016-08-31 08:08:26 -04:00
|
|
|
|
|
|
|
bool gui_pl_library_add(const gchar *filename)
|
|
|
|
{
|
|
|
|
struct playlist *playlist;
|
2016-08-31 09:41:42 -04:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (!__gui_pl_library_header(&iter))
|
|
|
|
return false;
|
|
|
|
if (!playlist_new(PL_LIBRARY, filename))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
playlist = playlist_get(PL_LIBRARY, filename);
|
|
|
|
gui_sidebar_iter_sort_child(&iter, playlist, "folder");
|
|
|
|
gui_idle_enable();
|
|
|
|
return true;
|
2016-08-31 08:08:26 -04:00
|
|
|
}
|