Add control buttons, and a title
[gmpc-fullscreeninfo.git] / src / plugin.c
blobc9e0c7be7f8ade83dcee491de7667153fb166128
1 /* gmpc-fullscreeninfo (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 <stdio.h>
21 #include <string.h>
22 #include <glib.h>
23 #include <gmpc/plugin.h>
24 #include <gmpc/gmpc-metaimage.h>
25 #include <gmpc/gmpc-connection.h>
26 #include <gdk/gdkkeysyms.h>
27 #include <config.h>
29 extern GmpcConnection *gmpcconn;
31 int plugin_api_version = PLUGIN_API_VERSION;
32 gulong signal_handler = 0;
34 GtkWidget *buttons[4] = {NULL, };
35 GtkWidget *label = NULL;
36 /**
37 * Get/Set enabled functions.
39 static int fullscreeninfo_get_enabled(void)
41 return cfg_get_single_value_as_int_with_default(config, "fullscreeninfo-plugin", "enable", TRUE);
43 static void fullscreeninfo_set_enabled(int enabled)
45 cfg_set_single_value_as_int(config, "fullscreeninfo-plugin", "enable", enabled);
49 static void gfi_button_press_event(GtkWidget *widevent, GdkEventButton *event, GtkWidget *window)
51 gtk_widget_destroy(window);
52 if(signal_handler)
53 g_signal_handler_disconnect(G_OBJECT(gmpcconn), signal_handler);
54 signal_handler = 0;
56 static gboolean gfi_window_fullscreen(GtkWidget *window)
58 gtk_window_fullscreen(GTK_WINDOW(window));
59 return FALSE;
61 static void gfi_size_allocate(GtkWidget *window, GtkAllocation *alloc, GtkWidget *image)
64 g_idle_add(gfi_window_fullscreen, window);
67 static void gfi_size_allocate_mi(GtkWidget *window, GtkAllocation *alloc, GtkWidget *image){
69 gmpc_metaimage_set_size(GMPC_METAIMAGE(image), (alloc->width < alloc->height)?alloc->width:alloc->height);
70 gmpc_metaimage_reload_image(GMPC_METAIMAGE(image));
72 static void play_pause(MpdObj *mi)
74 if(mpd_player_get_state(mi) == MPD_PLAYER_PLAY){
75 mpd_player_pause(mi);
76 }else{
77 mpd_player_play(mi);
80 static void status_changed(GmpcConnection *gmpcconn, MpdObj *mi, ChangedStatusType what, gpointer data)
82 if(what&MPD_CST_STATE){
83 GtkWidget *child = gtk_bin_get_child(GTK_BIN(buttons[2]));
85 if(mpd_player_get_state(connection) == MPD_PLAYER_PLAY){
86 gtk_image_set_from_stock(GTK_IMAGE(child),GTK_STOCK_MEDIA_PAUSE,GTK_ICON_SIZE_DIALOG);
87 }else{
88 gtk_image_set_from_stock(GTK_IMAGE(child),GTK_STOCK_MEDIA_PLAY,GTK_ICON_SIZE_DIALOG);
91 if(what&(MPD_CST_SONGID|MPD_CST_SONGPOS|MPD_CST_PLAYLIST|MPD_CST_STATE))
93 char buffer[512];
94 mpd_Song *song = mpd_playlist_get_current_song(mi);
95 if(song && mpd_player_get_state(mi) != MPD_PLAYER_STOP)
97 mpd_song_markup_escaped(buffer, 512, "<span size='xx-large'>[[%title% - &[%artist%]]|%shortfile%]</span>",song);
99 else{
100 snprintf(buffer, 512, "<span size='xx-large'>Gnome Music Player Client</span>");
102 gtk_label_set_markup(GTK_LABEL(label), buffer);
103 printf("%s\n", buffer);
107 static void gfi_fullscreen(void)
109 GtkWidget *popup = gtk_window_new(GTK_WINDOW_TOPLEVEL);
110 GtkWidget *metaimage = gmpc_metaimage_new(META_ALBUM_ART);
111 GtkWidget *vbox = gtk_vbox_new(FALSE, 6);
112 GtkWidget *hbox = gtk_hbox_new(TRUE, 6);
113 gtk_widget_set_has_tooltip(metaimage, FALSE);
115 /* Setup the meta image */
116 gmpc_metaimage_set_no_cover_icon(GMPC_METAIMAGE(metaimage),(char *)"gmpc");
117 gmpc_metaimage_set_squared(GMPC_METAIMAGE(metaimage), TRUE);
118 gmpc_metaimage_set_connection(GMPC_METAIMAGE(metaimage), connection);
119 gmpc_metaimage_update_cover(GMPC_METAIMAGE(metaimage), connection,MPD_CST_SONGID, NULL);
120 g_signal_connect(G_OBJECT(metaimage), "button-press-event", G_CALLBACK(gfi_button_press_event), popup);
123 gtk_container_add(GTK_CONTAINER(popup), vbox);
124 gtk_window_set_resizable(GTK_WINDOW(popup), TRUE);
126 g_signal_connect(G_OBJECT(popup), "size-allocate", G_CALLBACK(gfi_size_allocate), metaimage);
128 g_signal_connect(G_OBJECT(metaimage), "size-allocate", G_CALLBACK(gfi_size_allocate_mi), metaimage);
132 * Main title label
134 label = gtk_label_new("");
135 gtk_label_set_markup(GTK_LABEL(label), "<span size='xx-large'>Gnome Music Player Client</span>");
136 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
137 gtk_widget_ensure_style(label);
138 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &(label->style->white));
140 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE,0);
142 gtk_box_pack_start(GTK_BOX(vbox), metaimage, TRUE, TRUE, 0);
144 * Control buttons */
145 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE,0);
149 /* Prev */
150 buttons[0] = gtk_button_new();
151 gtk_container_add(GTK_CONTAINER(buttons[0]),
152 gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_DIALOG));
153 gtk_button_set_relief(GTK_BUTTON(buttons[0]), GTK_RELIEF_NONE);
154 gtk_box_pack_start(GTK_BOX(hbox), buttons[0], FALSE, TRUE, 0);
155 g_signal_connect_swapped(G_OBJECT(buttons[0]), "clicked", G_CALLBACK(mpd_player_prev), connection);
156 /* STOP */
157 buttons[1] = gtk_button_new();
158 gtk_container_add(GTK_CONTAINER(buttons[1]),
159 gtk_image_new_from_stock(GTK_STOCK_MEDIA_STOP, GTK_ICON_SIZE_DIALOG));
160 gtk_button_set_relief(GTK_BUTTON(buttons[1]), GTK_RELIEF_NONE);
161 gtk_box_pack_start(GTK_BOX(hbox), buttons[1], FALSE, TRUE, 0);
163 g_signal_connect_swapped(G_OBJECT(buttons[1]), "clicked", G_CALLBACK(mpd_player_stop), connection);
165 /* Play/Pause */
166 buttons[2] = gtk_button_new();
167 gtk_container_add(GTK_CONTAINER(buttons[2]),
168 gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_DIALOG));
169 gtk_button_set_relief(GTK_BUTTON(buttons[2]), GTK_RELIEF_NONE);
170 gtk_box_pack_start(GTK_BOX(hbox), buttons[2], FALSE, TRUE, 0);
172 g_signal_connect_swapped(G_OBJECT(buttons[2]), "clicked", G_CALLBACK(play_pause), connection);
174 /* Next */
175 buttons[3] = gtk_button_new();
176 gtk_container_add(GTK_CONTAINER(buttons[3]),
177 gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT, GTK_ICON_SIZE_DIALOG));
178 gtk_button_set_relief(GTK_BUTTON(buttons[3]), GTK_RELIEF_NONE);
179 gtk_box_pack_start(GTK_BOX(hbox), buttons[3], FALSE, TRUE, 0);
181 g_signal_connect_swapped(G_OBJECT(buttons[3]), "clicked", G_CALLBACK(mpd_player_next), connection);
183 gtk_widget_ensure_style(popup);
184 gtk_widget_modify_bg(popup, GTK_STATE_NORMAL, &(popup->style->black));
187 status_changed(gmpcconn, connection, MPD_CST_STATE|MPD_CST_SONGPOS, NULL);
188 signal_handler = g_signal_connect(G_OBJECT(gmpcconn), "status-changed", G_CALLBACK(status_changed), NULL);
189 gtk_widget_show_all(popup);
192 static int gfi_add_go_menu(GtkWidget *menu)
194 GtkWidget *item = NULL;
196 item = gtk_image_menu_item_new_with_label(("Fullscreen Info"));
197 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
198 gtk_image_new_from_icon_name("playlist-browser", GTK_ICON_SIZE_MENU));
199 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
200 gtk_widget_add_accelerator(GTK_WIDGET(item), "activate", gtk_menu_get_accel_group(GTK_MENU(menu)), GDK_F11, 0, GTK_ACCEL_VISIBLE);
201 g_signal_connect(G_OBJECT(item), "activate",
202 G_CALLBACK(gfi_fullscreen), NULL);
203 return 1;
205 gmpcPlBrowserPlugin gfi_gbp = {
206 .add_go_menu = gfi_add_go_menu,
208 /* main plugin_osd info */
209 gmpcPlugin plugin = {
210 .name = "Qball's Fullscreen status",
211 .version = {PLUGIN_MAJOR_VERSION,PLUGIN_MINOR_VERSION,PLUGIN_MICRO_VERSION},
212 .plugin_type = GMPC_PLUGIN_PL_BROWSER,
213 .browser = &gfi_gbp,
214 .get_enabled = fullscreeninfo_get_enabled,
215 .set_enabled = fullscreeninfo_set_enabled