1 /* gmpc-fullscreen_info (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.
23 #include <gmpc/plugin.h>
24 #include <gmpc/gmpc-metaimage.h>
25 #include <gmpc/gmpc-connection.h>
26 #include <gmpc/gmpc-plugin.h>
27 #include <gdk/gdkkeysyms.h>
31 typedef struct _FullscreenInfoPlugin FullscreenInfoPlugin
;
32 typedef struct _FullscreenInfoPluginClass FullscreenInfoPluginClass
;
34 struct _FullscreenInfoPlugin
36 GmpcPluginBase parent_instance
;
39 struct _FullscreenInfoPluginClass
41 GmpcPluginBaseClass parent_class
;
44 extern GmpcConnection
*gmpcconn
;
46 gulong signal_handler
= 0;
48 GtkWidget
*buttons
[4] = {NULL
, };
49 GtkWidget
*label
= NULL
;
51 * Get/Set enabled functions.
53 static gboolean
fullscreen_info_get_enabled(GmpcPluginBase
*plug
)
55 return cfg_get_single_value_as_int_with_default(config
, "fullscreen_info-plugin", "enable", TRUE
);
57 static void fullscreen_info_set_enabled(GmpcPluginBase
*plug
, int enabled
)
59 cfg_set_single_value_as_int(config
, "fullscreen_info-plugin", "enable", enabled
);
63 static void gfi_button_press_event(GtkWidget
*widevent
, GdkEventButton
*event
, GtkWidget
*window
)
65 gtk_widget_destroy(window
);
67 g_signal_handler_disconnect(G_OBJECT(gmpcconn
), signal_handler
);
70 static gboolean
gfi_window_fullscreen(GtkWidget
*window
)
72 gtk_window_fullscreen(GTK_WINDOW(window
));
75 static void gfi_size_allocate(GtkWidget
*window
, GtkAllocation
*alloc
, GtkWidget
*image
)
77 g_idle_add((GSourceFunc
)gfi_window_fullscreen
, window
);
80 static void gfi_size_allocate_mi(GtkWidget
*window
, GtkAllocation
*alloc
, GtkWidget
*image
){
82 gmpc_metaimage_set_size(GMPC_METAIMAGE(image
), (alloc
->width
< alloc
->height
)?alloc
->width
:alloc
->height
);
83 gmpc_metaimage_reload_image(GMPC_METAIMAGE(image
));
85 static void play_pause(MpdObj
*mi
)
87 if(mpd_player_get_state(mi
) == MPD_PLAYER_PLAY
){
93 static void status_changed(GmpcConnection
*gmpcconn
, MpdObj
*mi
, ChangedStatusType what
, gpointer data
)
95 if(what
&MPD_CST_STATE
){
96 GtkWidget
*child
= gtk_bin_get_child(GTK_BIN(buttons
[2]));
98 if(mpd_player_get_state(connection
) == MPD_PLAYER_PLAY
){
99 gtk_image_set_from_stock(GTK_IMAGE(child
),GTK_STOCK_MEDIA_PAUSE
,GTK_ICON_SIZE_DIALOG
);
101 gtk_image_set_from_stock(GTK_IMAGE(child
),GTK_STOCK_MEDIA_PLAY
,GTK_ICON_SIZE_DIALOG
);
104 if(what
&(MPD_CST_SONGID
|MPD_CST_SONGPOS
|MPD_CST_PLAYLIST
|MPD_CST_STATE
))
107 mpd_Song
*song
= mpd_playlist_get_current_song(mi
);
108 if(song
&& mpd_player_get_state(mi
) != MPD_PLAYER_STOP
)
110 mpd_song_markup_escaped(buffer
, 512, "<span size='xx-large'>[[%title% - &[%artist%]]|%shortfile%]</span>",song
);
113 snprintf(buffer
, 512, "<span size='xx-large'>Gnome Music Player Client</span>");
115 gtk_label_set_markup(GTK_LABEL(label
), buffer
);
116 printf("%s\n", buffer
);
120 static void gfi_fullscreen(void)
122 GtkWidget
*popup
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
123 GtkWidget
*metaimage
= gmpc_metaimage_new(META_ALBUM_ART
);
124 GtkWidget
*vbox
= gtk_vbox_new(FALSE
, 6);
125 GtkWidget
*hbox
= gtk_hbox_new(TRUE
, 6);
126 gtk_widget_set_has_tooltip(metaimage
, FALSE
);
128 gtk_window_set_keep_above(GTK_WINDOW(popup
), TRUE
);
129 /* Setup the meta image */
130 gmpc_metaimage_set_no_cover_icon(GMPC_METAIMAGE(metaimage
),(char *)"gmpc");
131 gmpc_metaimage_set_squared(GMPC_METAIMAGE(metaimage
), TRUE
);
132 gmpc_metaimage_set_connection(GMPC_METAIMAGE(metaimage
), connection
);
133 gmpc_metaimage_update_cover(GMPC_METAIMAGE(metaimage
), connection
,MPD_CST_SONGID
, NULL
);
134 g_signal_connect(G_OBJECT(metaimage
), "button-press-event", G_CALLBACK(gfi_button_press_event
), popup
);
137 gtk_container_add(GTK_CONTAINER(popup
), vbox
);
138 gtk_window_set_resizable(GTK_WINDOW(popup
), TRUE
);
140 g_signal_connect(G_OBJECT(popup
), "size-allocate", G_CALLBACK(gfi_size_allocate
), metaimage
);
142 g_signal_connect(G_OBJECT(metaimage
), "size-allocate", G_CALLBACK(gfi_size_allocate_mi
), metaimage
);
148 label
= gtk_label_new("");
149 gtk_label_set_markup(GTK_LABEL(label
), "<span size='xx-large'>Gnome Music Player Client</span>");
150 gtk_label_set_ellipsize(GTK_LABEL(label
), PANGO_ELLIPSIZE_END
);
151 gtk_widget_ensure_style(label
);
152 gtk_widget_modify_fg(label
, GTK_STATE_NORMAL
, &(label
->style
->white
));
154 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
,0);
156 gtk_box_pack_start(GTK_BOX(vbox
), metaimage
, TRUE
, TRUE
, 0);
159 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
,0);
164 buttons
[0] = gtk_button_new();
165 gtk_container_add(GTK_CONTAINER(buttons
[0]),
166 gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS
, GTK_ICON_SIZE_DIALOG
));
167 gtk_button_set_relief(GTK_BUTTON(buttons
[0]), GTK_RELIEF_NONE
);
168 gtk_box_pack_start(GTK_BOX(hbox
), buttons
[0], FALSE
, TRUE
, 0);
169 g_signal_connect_swapped(G_OBJECT(buttons
[0]), "clicked", G_CALLBACK(mpd_player_prev
), connection
);
171 buttons
[1] = gtk_button_new();
172 gtk_container_add(GTK_CONTAINER(buttons
[1]),
173 gtk_image_new_from_stock(GTK_STOCK_MEDIA_STOP
, GTK_ICON_SIZE_DIALOG
));
174 gtk_button_set_relief(GTK_BUTTON(buttons
[1]), GTK_RELIEF_NONE
);
175 gtk_box_pack_start(GTK_BOX(hbox
), buttons
[1], FALSE
, TRUE
, 0);
177 g_signal_connect_swapped(G_OBJECT(buttons
[1]), "clicked", G_CALLBACK(mpd_player_stop
), connection
);
180 buttons
[2] = gtk_button_new();
181 gtk_container_add(GTK_CONTAINER(buttons
[2]),
182 gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY
, GTK_ICON_SIZE_DIALOG
));
183 gtk_button_set_relief(GTK_BUTTON(buttons
[2]), GTK_RELIEF_NONE
);
184 gtk_box_pack_start(GTK_BOX(hbox
), buttons
[2], FALSE
, TRUE
, 0);
186 g_signal_connect_swapped(G_OBJECT(buttons
[2]), "clicked", G_CALLBACK(play_pause
), connection
);
189 buttons
[3] = gtk_button_new();
190 gtk_container_add(GTK_CONTAINER(buttons
[3]),
191 gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT
, GTK_ICON_SIZE_DIALOG
));
192 gtk_button_set_relief(GTK_BUTTON(buttons
[3]), GTK_RELIEF_NONE
);
193 gtk_box_pack_start(GTK_BOX(hbox
), buttons
[3], FALSE
, TRUE
, 0);
195 g_signal_connect_swapped(G_OBJECT(buttons
[3]), "clicked", G_CALLBACK(mpd_player_next
), connection
);
197 gtk_widget_ensure_style(popup
);
198 gtk_widget_modify_bg(popup
, GTK_STATE_NORMAL
, &(popup
->style
->black
));
201 status_changed(gmpcconn
, connection
, MPD_CST_STATE
|MPD_CST_SONGPOS
, NULL
);
202 signal_handler
= g_signal_connect(G_OBJECT(gmpcconn
), "status-changed", G_CALLBACK(status_changed
), NULL
);
203 gtk_widget_show_all(popup
);
206 static int gfi_add_tool_menu(GmpcPluginToolMenuIface
*plug
, GtkMenu
*menu
)
208 GtkWidget
*item
= NULL
;
210 item
= gtk_image_menu_item_new_with_label(("Fullscreen Info"));
211 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
212 gtk_image_new_from_icon_name("playlist-browser", GTK_ICON_SIZE_MENU
));
213 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
214 gtk_widget_add_accelerator(GTK_WIDGET(item
), "activate", gtk_menu_get_accel_group(GTK_MENU(menu
)), GDK_F11
, 0, GTK_ACCEL_VISIBLE
);
215 g_signal_connect(G_OBJECT(item
), "activate",
216 G_CALLBACK(gfi_fullscreen
), NULL
);
223 static void fullscreen_info_plugin_class_init (FullscreenInfoPluginClass
*klass
);
224 GType
fullscreen_info_plugin_get_type(void);
226 static int *fullscreen_info_plugin_get_version(GmpcPluginBase
*plug
, int *length
)
228 static int version
[3] = {PLUGIN_MAJOR_VERSION
,PLUGIN_MINOR_VERSION
,PLUGIN_MICRO_VERSION
};
229 if(length
) *length
= 3;
230 return (int *)version
;
233 static const char *fullscreen_info_plugin_get_name(GmpcPluginBase
*plug
)
235 return "Fullscreen info plugin";
237 static GObject
*fullscreen_info_plugin_constructor(GType type
, guint n_construct_properties
, GObjectConstructParam
* construct_properties
) {
238 FullscreenInfoPluginClass
* klass
;
239 FullscreenInfoPlugin
*self
;
240 GObjectClass
* parent_class
;
241 klass
= (g_type_class_peek (fullscreen_info_plugin_get_type()));
242 parent_class
= G_OBJECT_CLASS (g_type_class_peek_parent (klass
));
243 self
= (FullscreenInfoPlugin
*) parent_class
->constructor (type
, n_construct_properties
, construct_properties
);
245 /* Make it an internal plugin */
246 GMPC_PLUGIN_BASE(self
)->plugin_type
= GMPC_PLUGIN_NO_GUI
;
248 return G_OBJECT(self
);
252 static void fullscreen_info_plugin_class_init (FullscreenInfoPluginClass
*klass
)
254 G_OBJECT_CLASS(klass
)->constructor
= fullscreen_info_plugin_constructor
;
255 /* Connect plugin functions */
256 GMPC_PLUGIN_BASE_CLASS(klass
)->get_version
= fullscreen_info_plugin_get_version
;
257 GMPC_PLUGIN_BASE_CLASS(klass
)->get_name
= fullscreen_info_plugin_get_name
;
259 GMPC_PLUGIN_BASE_CLASS(klass
)->get_enabled
= fullscreen_info_get_enabled
;
260 GMPC_PLUGIN_BASE_CLASS(klass
)->set_enabled
= fullscreen_info_set_enabled
;
263 static void fullscreen_info_plugin_gmpc_plugin_tool_menu_iface_interface_init (GmpcPluginToolMenuIfaceIface
* iface
) {
264 iface
->tool_menu_integration
= gfi_add_tool_menu
;
267 GType
fullscreen_info_plugin_get_type(void) {
268 static GType fullscreen_info_plugin_type_id
= 0;
269 if(fullscreen_info_plugin_type_id
== 0) {
270 static const GTypeInfo info
= {
271 .class_size
= sizeof(FullscreenInfoPluginClass
),
272 .class_init
= (GClassInitFunc
)fullscreen_info_plugin_class_init
,
273 .instance_size
= sizeof(FullscreenInfoPlugin
),
277 static const GInterfaceInfo iface_info
= { (GInterfaceInitFunc
) fullscreen_info_plugin_gmpc_plugin_tool_menu_iface_interface_init
,
278 (GInterfaceFinalizeFunc
) NULL
, NULL
};
280 fullscreen_info_plugin_type_id
= g_type_register_static(GMPC_PLUGIN_TYPE_BASE
, "FullscreenInfosPlugin", &info
, 0);
282 g_type_add_interface_static (fullscreen_info_plugin_type_id
, GMPC_PLUGIN_TYPE_TOOL_MENU_IFACE
, &iface_info
);
284 return fullscreen_info_plugin_type_id
;
287 G_MODULE_EXPORT GType
plugin_get_type(void)
290 return fullscreen_info_plugin_get_type();