6 #include <glade/glade.h>
7 #include <gmpc/plugin.h>
8 #include <libmpd/debug_printf.h>
11 /* External pointer + function, there internal from gmpc */
12 extern GladeXML
*pl3_xml
;
14 void pl3_option_menu_activate();
16 static int get_enabled() {
17 return cfg_get_single_value_as_int_with_default(config
,"random-playlist", "enabled",TRUE
);
19 static void set_enabled(int enabled
) {
20 cfg_set_single_value_as_int(config
,"random-playlist", "enabled", enabled
);
21 pl3_option_menu_activate();
23 static void rp_start()
25 MpdData
*data
= mpd_database_get_complete(connection
);
26 GRand
*rand
= g_rand_new();
27 int value
, pos
= cfg_get_single_value_as_int_with_default(config
, "random-playlist", "addfact",20)*100;
28 mpd_playlist_clear(connection
);
29 for(;data
;data
= mpd_data_get_next(data
))
31 value
= g_rand_int_range(rand
, 0,10000);
35 mpd_playlist_queue_add(connection
, data
->song
->file
);
38 mpd_playlist_queue_commit(connection
);
39 if(cfg_get_single_value_as_int_with_default(config
, "random-playlist", "shuffle",TRUE
))
41 mpd_playlist_shuffle(connection
);
47 static int rp_right_mouse_menu(GtkWidget
*menu
, int type
, GtkWidget
*tree
, GdkEventButton
*event
)
49 gmpcPlugin
*plug
= plugin_get_from_id(type
);
50 if(!cfg_get_single_value_as_int_with_default(config
, "random-playlist", "enabled", TRUE
)) {
53 debug_printf(DEBUG_INFO
,"Random playlist right mouse clicked");
54 if(!strcmp(plug
->name
, "Current Playlist Browser"))
57 item
= gtk_image_menu_item_new_with_label("Generate Random Playlist");
58 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
59 gtk_image_new_from_stock(GTK_STOCK_ADD
, GTK_ICON_SIZE_MENU
));
60 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
61 g_signal_connect(G_OBJECT(item
), "activate", G_CALLBACK(rp_start
), NULL
);
69 gmpcPlBrowserPlugin rp_gpb
= {
70 .cat_right_mouse_menu
= rp_right_mouse_menu
75 .name
= "Random Playlist",
76 .version
= {PLUGIN_MAJOR_VERSION
,PLUGIN_MINOR_VERSION
,PLUGIN_MICRO_VERSION
},
77 .plugin_type
= GMPC_PLUGIN_PL_BROWSER
,
78 .browser
= &rp_gpb
, /* browser intergration */
79 .get_enabled
= get_enabled
,
80 .set_enabled
= set_enabled
82 int plugin_api_version
= PLUGIN_API_VERSION
;