26
26
#include "playlist3.h"
27
27
#include "playlist3-file-browser.h"
28
#include "playlist3-find2-browser.h"
29
#include "advanced-search.h"
28
30
#include "gmpc-mpddata-model.h"
29
31
#include "gmpc-mpddata-treeview.h"
30
32
#include "playlist3-playlist-editor.h"
31
#include "gmpc-paned-size-group.h"
33
#include "gmpc-extras.h"
35
#define LOG_DOMAIN "FileBrowser"
37
static void pl3_file_browser_plugin_init(void);
39
static gboolean pl3_file_browser_is_field_supported(int tag);
40
static MpdData * pl3_file_browser_is_search(const int num_field ,const gchar *search_string, GError **error);
33
42
static void pl3_file_browser_destroy(void);
34
43
static void pl3_file_browser_add(GtkWidget *cat_tree);
92
101
.selected = pl3_file_browser_selected,
93
102
.unselected = pl3_file_browser_unselected,
94
103
.add_go_menu = pl3_file_browser_add_go_menu,
104
.integrate_search_field_supported = pl3_file_browser_is_field_supported,
105
.integrate_search = pl3_file_browser_is_search
97
108
gmpcPlugin file_browser_plug = {
98
.name = N_("File Browser"),
109
.name = N_("Database"),
99
110
.version = {1,1,1},
100
111
.plugin_type = GMPC_PLUGIN_PL_BROWSER|GMPC_INTERNALL,
112
.init = pl3_file_browser_plugin_init,
101
113
.destroy = pl3_file_browser_destroy,
102
114
.browser = &file_browser_gbp,
103
115
.mpd_status_changed = pl3_file_browser_status_changed,
157
169
sw = gtk_scrolled_window_new(NULL, NULL);
158
170
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
159
171
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN);
160
pl3_fb_dir_tree = tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(pl3_fb_dir_store));
161
gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(tree), TRUE);
162
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
172
pl3_fb_dir_tree = tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(pl3_fb_dir_store));
173
gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(tree), TRUE);
174
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
163
175
column = gtk_tree_view_column_new();
164
176
gtk_tree_view_column_set_title(column, _("Directories"));
165
177
renderer = gtk_cell_renderer_pixbuf_new();
166
178
gtk_tree_view_column_pack_start(column, renderer, FALSE);
167
gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(tree), TRUE);
168
gtk_tree_view_column_add_attribute(column, renderer, "icon-name",PL3_FB_ICON);
169
gtk_tree_view_column_set_sizing(column , GTK_TREE_VIEW_COLUMN_FIXED);
179
gtk_tree_view_column_add_attribute(column, renderer, "icon-name",PL3_FB_ICON);
180
gtk_tree_view_column_set_sizing(column , GTK_TREE_VIEW_COLUMN_FIXED);
170
181
renderer = gtk_cell_renderer_text_new();
171
182
gtk_tree_view_column_pack_start(column, renderer, TRUE);
172
183
gtk_tree_view_column_add_attribute(column, renderer, "text", PL3_FB_NAME);
173
184
gtk_tree_view_insert_column(GTK_TREE_VIEW(tree),column, -1);
175
gtk_tree_view_set_search_column(GTK_TREE_VIEW(pl3_fb_dir_tree), PL3_FB_NAME);
186
gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(tree), TRUE);
187
gtk_tree_view_set_search_column(GTK_TREE_VIEW(pl3_fb_dir_tree), PL3_FB_NAME);
176
188
/* set the search column */
177
189
gtk_tree_view_set_search_column(GTK_TREE_VIEW(tree), PL3_FB_NAME);
207
219
gtk_box_pack_start(GTK_BOX(vbox), pl3_fb_sw, TRUE, TRUE,0);
208
220
gtk_widget_show_all(pl3_fb_sw);
210
/* Warning box for when there is no music */
211
pl3_fb_warning_box = gtk_label_new("");
212
gtk_label_set_markup(GTK_LABEL(pl3_fb_warning_box),
213
_("It seems you have no music in your database.\n"
214
"To add music, copy the music to your <i>music_directory</i> as specified in your mpd config file.\n"
215
"Then update the database. (Server->Update Database)"));
216
gtk_misc_set_alignment(GTK_MISC(pl3_fb_warning_box), 0.0,0.0);
217
gtk_misc_set_padding(GTK_MISC(pl3_fb_warning_box), 12,12);
222
/* Warning box for when there is no music */
223
pl3_fb_warning_box = gtk_label_new("");
224
gtk_label_set_markup(GTK_LABEL(pl3_fb_warning_box),
225
_("It seems you have no music in your database.\n"
226
"To add music, copy the music to your <i>music_directory</i> as specified in your mpd config file.\n"
227
"Then update the database. (Server->Update Database)"));
228
gtk_misc_set_alignment(GTK_MISC(pl3_fb_warning_box), 0.0,0.0);
229
gtk_misc_set_padding(GTK_MISC(pl3_fb_warning_box), 12,12);
218
230
gtk_widget_set_no_show_all(pl3_fb_warning_box, TRUE);
219
231
gtk_box_pack_end(GTK_BOX(vbox), pl3_fb_warning_box, FALSE, TRUE,0);
221
233
gtk_paned_add2(GTK_PANED(pl3_fb_vbox), vbox);
222
234
/* set initial state */
223
debug_printf(DEBUG_INFO,"initialized current playlist treeview\n");
224
235
gtk_widget_show(vbox);
225
236
gtk_widget_show(pl3_fb_vbox);
226
g_object_ref(G_OBJECT(pl3_fb_vbox));
237
g_object_ref_sink(G_OBJECT(pl3_fb_vbox));
229
240
static void pl3_file_browser_add_folder(void)
332
343
playlist3_insert_browser(&iter, pos);
333
344
gtk_list_store_set(GTK_LIST_STORE(pl3_tree), &iter,
334
345
PL3_CAT_TYPE, file_browser_plug.id,
335
PL3_CAT_TITLE, _("File Browser"),
336
PL3_CAT_ICON_ID, "gtk-open",
346
PL3_CAT_TITLE, _("Database"),
347
PL3_CAT_ICON_ID, "gmpc-database",
338
349
/* add fantom child for lazy tree */
395
414
GtkTreeIter child, child2,child3;
396
415
data = mpd_database_get_directory(connection,path);
398
data = misc_sort_mpddata(data,(GCompareDataFunc)directory_sort_func,NULL);
416
data = misc_sort_mpddata(data,(GCompareDataFunc)directory_sort_func,NULL);
400
418
if(gtk_tree_model_iter_children(model, &child, iter))
402
420
gchar *test_path = NULL;
528
546
if(strcmp("media-playlist",icon))
530
548
data = mpd_database_get_directory(connection, path);
531
data = misc_sort_mpddata(data,(GCompareDataFunc)directory_sort_func,NULL);
534
debug_printf(DEBUG_INFO,"View Playlist\n");
535
551
data = mpd_database_get_playlist_content(connection, path);
537
553
/* Check, and set the up arrow in the model */
560
576
/* add phantom child */
561
577
gtk_tree_store_append(pl3_fb_dir_store, &child, iter);
564
579
static void pl3_file_browser_fill_tree(GtkWidget *tree,GtkTreeIter *iter, GtkTreePath *tpath, gpointer user_data)
567
582
MpdData *data = NULL;
568
GtkTreeIter child,child2;
583
GtkTreeIter child,child2, dummy;
570
585
gtk_tree_model_get(GTK_TREE_MODEL(pl3_fb_dir_store),iter, PL3_FB_PATH, &path, PL3_FB_OPEN, &open,-1);
571
586
gtk_tree_store_set(pl3_fb_dir_store, iter, PL3_FB_OPEN, TRUE, -1);
572
587
if(open == FALSE)
589
GTimer *tim = g_timer_new();
574
590
data = mpd_database_get_directory(connection, path);
575
data = misc_sort_mpddata(data,(GCompareDataFunc)directory_sort_func,NULL);
591
/* Do a reverse sort, because adding it to the gtk view by prepending is faster
593
data = misc_sort_mpddata(data,(GCompareDataFunc)directory_sort_func_inv,NULL);
594
g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Elapsed time sorting before adding: %f\n",
595
g_timer_elapsed(tim, NULL));
597
if(gtk_tree_model_iter_children(GTK_TREE_MODEL(pl3_fb_dir_store), &dummy, iter))
578
if (data->type == MPD_DATA_TYPE_DIRECTORY)
581
g_path_get_basename (data->directory);
582
gtk_tree_store_append (pl3_fb_dir_store, &child, iter);
583
gtk_tree_store_set (pl3_fb_dir_store, &child,
584
PL3_FB_ICON, "gtk-open",
585
PL3_FB_NAME, basename,
586
PL3_FB_PATH, data->directory,
589
gtk_tree_store_append(pl3_fb_dir_store, &child2, &child);
601
if (data->type == MPD_DATA_TYPE_DIRECTORY)
603
gchar *basename = g_path_get_basename (data->directory);
604
gtk_tree_store_prepend(pl3_fb_dir_store, &child, iter);
605
gtk_tree_store_set (pl3_fb_dir_store, &child,
606
PL3_FB_ICON, "gtk-open",
607
PL3_FB_NAME, basename,
608
PL3_FB_PATH, data->directory,
611
gtk_tree_store_append(pl3_fb_dir_store, &child2, &child);
615
data = mpd_data_get_next(data);
593
data = mpd_data_get_next(data);
595
if(gtk_tree_model_iter_children(GTK_TREE_MODEL(pl3_fb_dir_store), &child, iter))
597
gtk_tree_store_remove(pl3_fb_dir_store, &child);
618
gtk_tree_store_remove(pl3_fb_dir_store, &dummy);
621
g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Elapsed time sorting after adding: %f\n",
622
g_timer_elapsed(tim, NULL));
623
g_timer_destroy(tim);
624
651
g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(pl3_file_browser_replace_folder), NULL);
627
GtkTreeView *tree = GTK_TREE_VIEW(pl3_fb_dir_tree);
628
GtkTreeModel *model = (GtkTreeModel *)pl3_fb_dir_store;
654
GtkTreeView *tree = GTK_TREE_VIEW(pl3_fb_dir_tree);
655
GtkTreeModel *model = (GtkTreeModel *)pl3_fb_dir_store;
629
656
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree);
630
657
GtkTreeIter iter;
631
658
if(gtk_tree_selection_get_selected(selection, &model, &iter))
1190
1217
if(!pl3_file_browser_get_enabled())
1193
item = gtk_image_menu_item_new_with_label(_("File Browser"));
1220
item = gtk_image_menu_item_new_with_label(_("Database"));
1194
1221
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
1195
gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_MENU));
1222
gtk_image_new_from_icon_name("gmpc-database", GTK_ICON_SIZE_MENU));
1196
1223
gtk_widget_add_accelerator(GTK_WIDGET(item),
1198
1225
gtk_menu_get_accel_group(GTK_MENU(menu)),
1258
1290
gint *indices = gtk_tree_path_get_indices(path);
1259
debug_printf(DEBUG_INFO,"Saving myself to position: %i\n", indices[0]);
1291
g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving myself to position: %i\n", indices[0]);
1260
1292
cfg_set_single_value_as_int(config, "file-browser","position",indices[0]);
1261
1293
gtk_tree_path_free(path);
1352
static gboolean pl3_file_browser_is_field_supported(int tag)
1354
if(tag == MPD_TAG_NUM_OF_ITEM_TYPES) return TRUE;
1355
return mpd_server_tag_supported(connection, tag);
1358
static MpdData * pl3_file_browser_is_search(const int num_field , const gchar *search_string, GError **error)
1360
MpdData *data_t = NULL;
1361
if(num_field == MPD_TAG_NUM_OF_ITEM_TYPES){
1362
data_t = advanced_search(search_string, FALSE);
1364
gchar ** splitted = tokenize_string(search_string);
1366
gboolean found = FALSE;
1367
for(i=0;splitted && splitted[i];i++) {
1369
mpd_database_search_start(connection, FALSE);
1372
mpd_database_search_add_constraint(connection, num_field, splitted[i]);
1375
g_strfreev(splitted);
1377
data_t = mpd_database_search_commit(connection);
1383
void pl3_find2_ec_database(gpointer user_data, const char *param)
1385
pl3_find2_select_plugin_id(file_browser_plug.id);
1386
pl3_find2_do_search_any(param);
1389
static void pl3_file_browser_plugin_init(void)
1391
gmpc_easy_command_add_entry(gmpc_easy_command,
1392
_("search database"), ".*",
1393
_("Search database <query>"),
1394
(GmpcEasyCommandCallback *)pl3_find2_ec_database, NULL);