gmpc-extraplaylist version 0.17.96
[gmpc-extraplaylist.git] / src / main.c
blobf5b47b034a8130b87779d5855ce6b267d57095dc
1 /* gmpc-extraplaylist (GMPC plugin)
2 * Copyright (C) 2006-2009 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpcwiki.sarine.nl/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <string.h>
21 #include <glade/glade.h>
22 #include <gmpc/plugin.h>
23 #include <config.h>
24 /* External pointer + function, there internal from gmpc */
25 extern GladeXML *pl3_xml;
26 GtkWidget *extraplaylist = NULL;
27 static GtkWidget *extraplaylist_paned = NULL;
29 extern gmpcPlugin current_playlist_plug;
30 static void extra_playlist_row_changed(GtkTreeSelection *sel, gpointer data)
32 GtkTreeIter iter;
33 GtkTreeModel *model = (GtkTreeModel *)playlist3_get_category_tree_store();
34 if(extraplaylist == NULL)
35 return;
36 if(cfg_get_single_value_as_int_with_default(config,"extraplaylist", "enabled", 0) == 0)
37 return;
39 if(gtk_tree_selection_get_selected(sel, &model, &iter))
41 int type;
42 gtk_tree_model_get(model, &iter, 0,&type, -1);
44 if(type == current_playlist_plug.id){
45 if(gtk_bin_get_child(GTK_BIN(extraplaylist)))
46 current_playlist_plug.browser->unselected(extraplaylist);
47 gtk_widget_hide(extraplaylist);
52 static void extra_playlist_row_changed_after(GtkTreeSelection *sel, gpointer data)
54 GtkTreeIter iter;
55 GtkTreeModel *model = (GtkTreeModel *)playlist3_get_category_tree_store();
56 if(extraplaylist == NULL)
57 return;
58 if(cfg_get_single_value_as_int_with_default(config,"extraplaylist", "enabled", 0) == 0)
59 return;
61 if(gtk_tree_selection_get_selected(sel, &model, &iter))
63 int type;
64 gtk_tree_model_get(model, &iter, 0,&type, -1);
66 if(type != current_playlist_plug.id){
67 if ( gtk_bin_get_child(GTK_BIN(extraplaylist)) == NULL) {
68 /* Can't do this yet, because it is still packaged */
69 current_playlist_plug.browser->selected(extraplaylist);
70 gtk_widget_show(extraplaylist);
76 static void extra_playlist_destroy() {
77 if(extraplaylist) {
78 int pos = gtk_paned_get_position(GTK_PANED(extraplaylist_paned));
79 printf("pos is: %i\n",pos);
80 if(pos>0)
81 cfg_set_single_value_as_int(config, "extraplaylist", "paned-pos", pos);
85 static void extra_playlist_add() {
87 if(pl3_xml == NULL) return;
90 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(playlist3_get_category_tree_view()));
93 g_signal_connect(G_OBJECT(sel), "changed",G_CALLBACK(extra_playlist_row_changed), NULL);
94 g_signal_connect_after(G_OBJECT(sel), "changed",G_CALLBACK(extra_playlist_row_changed_after), NULL);
96 /**
97 * Hack it into the main view
99 extraplaylist = gtk_event_box_new();
101 GtkWidget *temp = glade_xml_get_widget(pl3_xml, "hpaned1");
102 g_object_ref(temp);
103 extraplaylist_paned = gtk_vpaned_new();
104 gtk_container_remove(GTK_CONTAINER(glade_xml_get_widget(pl3_xml,"vbox_control")),temp);
108 gtk_paned_pack1(GTK_PANED(extraplaylist_paned), temp, TRUE, TRUE);
109 gtk_box_pack_start(GTK_BOX(glade_xml_get_widget(pl3_xml, "vbox_control")), extraplaylist_paned, TRUE, TRUE, 0);
110 gtk_paned_pack2(GTK_PANED(extraplaylist_paned), extraplaylist, TRUE, TRUE);
112 gtk_paned_set_position(GTK_PANED(extraplaylist_paned),cfg_get_single_value_as_int_with_default(config, "extraplaylist", "paned-pos", 400));
114 gtk_widget_show(extraplaylist_paned);
115 gtk_widget_hide(extraplaylist);
117 extra_playlist_row_changed(sel,NULL);
121 static void extra_playlist_init(void ) {
122 if( cfg_get_single_value_as_int_with_default(config,"extraplaylist", "enabled", 1)) {
123 gtk_init_add((GtkFunction )extra_playlist_add, NULL);
126 static int get_enabled() {
127 return cfg_get_single_value_as_int_with_default(config,"extraplaylist", "enabled", 0);
129 static void set_enabled(int enable) {
130 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(playlist3_get_category_tree_view()));
131 cfg_set_single_value_as_int(config,"extraplaylist", "enabled", enable);
132 if(enable)
134 if(!extraplaylist) {
135 extra_playlist_add();
136 } else {
137 extra_playlist_row_changed_after(sel,NULL);
140 } else if(extraplaylist){
141 gtk_widget_hide(extraplaylist);
142 if(gtk_bin_get_child(GTK_BIN(extraplaylist)))
143 current_playlist_plug.browser->unselected(extraplaylist);
147 gmpcPlugin plugin = {
148 .name = "Exta Playlist View",
149 .version = {PLUGIN_MAJOR_VERSION, PLUGIN_MINOR_VERSION, PLUGIN_MICRO_VERSION},
150 .plugin_type = GMPC_PLUGIN_NO_GUI,
151 .init = extra_playlist_init, /* initialization */
152 .destroy = extra_playlist_destroy, /* Destroy */
153 .get_enabled = get_enabled,
154 .set_enabled = set_enabled
156 int plugin_api_version = PLUGIN_API_VERSION;