Update vala version.
[gmpc.git] / src / GUI / title_header.c
blob67c587f6c8b7cebbf2fccb675ee1dc753d1b3a8c
1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
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 <gtk/gtk.h>
21 #include "main.h"
22 #include "title_header.h"
23 #include "playlist3.h"
25 /* glue code */
26 extern GmpcBrowsersMetadata *browsers_metadata;
28 static GtkWidget *header_labels[5];
30 static void playlist3_header_song(void)
32 mpd_Song *song = mpd_playlist_get_current_song(connection);
33 if (song)
35 GtkTreeView *tree = (GtkTreeView *) gtk_builder_get_object(pl3_xml, "cat_tree");
36 gmpc_browsers_metadata_select_browser(browsers_metadata, tree);
37 gmpc_browsers_metadata_set_song(browsers_metadata, song);
42 static void playlist3_header_artist(void)
44 mpd_Song *song = mpd_playlist_get_current_song(connection);
45 if (song && song->artist)
47 GtkTreeView *tree = (GtkTreeView *) gtk_builder_get_object(pl3_xml, "cat_tree");
48 gmpc_browsers_metadata_select_browser(browsers_metadata, tree);
49 gmpc_browsers_metadata_set_artist(browsers_metadata, song->artist);
54 static void playlist3_header_album(void)
56 mpd_Song *song = mpd_playlist_get_current_song(connection);
57 if (song && song->artist && song->album)
59 GtkTreeView *tree = (GtkTreeView *) gtk_builder_get_object(pl3_xml, "cat_tree");
60 gmpc_browsers_metadata_select_browser(browsers_metadata, tree);
61 gmpc_browsers_metadata_set_album(browsers_metadata, song->artist, song->album);
64 static void playlist3_header_update_style(GtkWidget *widget, GtkStyle *prev, gpointer data)
66 /* TODO
67 gtk_widget_modify_text(header_labels[1], GTK_STATE_NORMAL, &(widget->style->text[GTK_STATE_INSENSITIVE]));
68 gtk_widget_modify_fg(header_labels[1], GTK_STATE_NORMAL, &(widget->style->text[GTK_STATE_INSENSITIVE]));
70 gtk_widget_modify_text(header_labels[3], GTK_STATE_NORMAL, &(widget->style->text[GTK_STATE_INSENSITIVE]));
71 gtk_widget_modify_fg(header_labels[3], GTK_STATE_NORMAL, &(widget->style->text[GTK_STATE_INSENSITIVE]));
75 void playlist3_new_header(void)
77 GtkWidget *hbox10 = GTK_WIDGET(gtk_builder_get_object(pl3_xml, "hbox10"));
78 if (hbox10)
80 GtkWidget *hbox = gtk_hbox_new(FALSE, 6);
81 GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
82 // expand in width, align in middle
83 GtkWidget *title_header_top_alignment;
84 title_header_top_alignment = gtk_alignment_new(0,0.5,1.0,0);
85 // set a 3 px top/bottom border (looks better then 6)
86 gtk_alignment_set_padding(GTK_ALIGNMENT(title_header_top_alignment), 3,3,0,0);
88 // set minimum width 300 pixels.
89 gtk_widget_set_size_request(title_header_top_alignment, 300, -1);
90 /** Title */
91 header_labels[0] = (GtkWidget *)gmpc_clicklabel_new("");
92 gmpc_clicklabel_font_size(GMPC_CLICKLABEL(header_labels[0]), 12);
93 gmpc_clicklabel_set_do_bold(GMPC_CLICKLABEL(header_labels[0]), TRUE);
94 gmpc_clicklabel_set_ellipsize(GMPC_CLICKLABEL(header_labels[0]), PANGO_ELLIPSIZE_END);
96 header_labels[1] = gtk_label_new(_("By"));
97 gtk_widget_set_name(header_labels[1], "by_label");
98 /** Artist */
99 header_labels[2] = (GtkWidget *)gmpc_clicklabel_new("");
100 gmpc_clicklabel_set_ellipsize(GMPC_CLICKLABEL(header_labels[2]), PANGO_ELLIPSIZE_END);
102 header_labels[3] = gtk_label_new(_("From"));
103 gtk_widget_set_name(header_labels[3], "from_label");
104 /** Albumr */
105 header_labels[4] = (GtkWidget *)gmpc_clicklabel_new("");
106 gmpc_clicklabel_set_ellipsize(GMPC_CLICKLABEL(header_labels[4]), PANGO_ELLIPSIZE_END);
111 gtk_box_pack_start(GTK_BOX(vbox), header_labels[0], FALSE, TRUE, 0);
112 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
114 gtk_box_pack_start(GTK_BOX(hbox), header_labels[1], FALSE, TRUE, 0);
115 gtk_box_pack_start(GTK_BOX(hbox), header_labels[2], FALSE, TRUE, 0);
116 gtk_box_pack_start(GTK_BOX(hbox), header_labels[3], FALSE, TRUE, 0);
117 gtk_box_pack_start(GTK_BOX(hbox), header_labels[4], FALSE, TRUE, 0);
119 g_signal_connect(G_OBJECT(header_labels[0]), "clicked", G_CALLBACK(playlist3_header_song), NULL);
120 g_signal_connect(G_OBJECT(header_labels[2]), "clicked", G_CALLBACK(playlist3_header_artist), NULL);
121 g_signal_connect(G_OBJECT(header_labels[4]), "clicked", G_CALLBACK(playlist3_header_album), NULL);
123 gtk_container_add(GTK_CONTAINER(title_header_top_alignment), vbox);
124 gtk_box_pack_start(GTK_BOX(hbox10), title_header_top_alignment, TRUE, TRUE, 0);
125 gtk_widget_show_all(hbox10);
127 g_signal_connect(G_OBJECT(hbox10), "style-set", G_CALLBACK(playlist3_header_update_style), NULL);
128 playlist3_header_update_style(hbox10, NULL, NULL);
133 void playlist3_update_header(void)
135 char buffer[1024];
136 if (header_labels[0] == NULL)
137 return;
139 if (mpd_check_connected(connection))
141 mpd_Song *song = mpd_playlist_get_current_song(connection);
142 /** Set new header */
143 if (mpd_player_get_state(connection) != MPD_STATUS_STATE_STOP && song)
145 mpd_song_markup(buffer, 1024, "[%title%|%shortfile%][ (%name%)]", song);
146 gmpc_clicklabel_set_text(GMPC_CLICKLABEL(header_labels[0]), buffer);
147 gmpc_clicklabel_set_sensitive(GMPC_CLICKLABEL(header_labels[0]), TRUE);
148 if (song->artist)
150 gtk_widget_show(header_labels[1]);
151 gtk_widget_show(header_labels[2]);
152 gmpc_clicklabel_set_text(GMPC_CLICKLABEL(header_labels[2]), song->artist);
153 } else
155 gtk_widget_hide(header_labels[1]);
156 gtk_widget_hide(header_labels[2]);
158 if (song->album)
160 gtk_widget_show(header_labels[3]);
161 gtk_widget_show(header_labels[4]);
162 if (song->date)
164 gchar *text = g_strdup_printf("%s (%s)", song->album, song->date);
165 gmpc_clicklabel_set_text(GMPC_CLICKLABEL(header_labels[4]), text);
166 g_free(text);
167 } else
169 gmpc_clicklabel_set_text(GMPC_CLICKLABEL(header_labels[4]), song->album);
172 } else
174 gtk_widget_hide(header_labels[3]);
175 gtk_widget_hide(header_labels[4]);
178 } else
180 gmpc_clicklabel_set_text(GMPC_CLICKLABEL(header_labels[0]), _("Not Playing"));
181 gmpc_clicklabel_set_sensitive(GMPC_CLICKLABEL(header_labels[0]), FALSE);
182 gtk_widget_hide(header_labels[1]);
183 gtk_widget_hide(header_labels[2]);
184 gtk_widget_hide(header_labels[3]);
185 gtk_widget_hide(header_labels[4]);
187 } else
189 gmpc_clicklabel_set_text(GMPC_CLICKLABEL(header_labels[0]), _("Not Connected"));
190 gmpc_clicklabel_set_sensitive(GMPC_CLICKLABEL(header_labels[0]), FALSE);
191 gtk_widget_hide(header_labels[1]);
192 gtk_widget_hide(header_labels[2]);
193 gtk_widget_hide(header_labels[3]);
194 gtk_widget_hide(header_labels[4]);