From 9789235dca8f8f997f9aca295a1f6c0702281cd5 Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Sat, 14 Mar 2009 21:58:03 +0100 Subject: [PATCH] Update fullscreen info to use the new Gobject based system --- configure.ac | 2 +- src/plugin.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 96 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 082db7a..ba3d922 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ PKG_CHECK_MODULES([gmpcfullscreeninfo], cairo libxml-2.0 libmpd >= 0.17.0 - gmpc >= 0.17.0 + gmpc >= 0.18.1 ]) AC_SUBST(gmpcfullscreeninfo_LIBS) AC_SUBST(gmpcfullscreeninfo_CFLAGS) diff --git a/src/plugin.c b/src/plugin.c index 3c745d2..0e945ae 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1,4 +1,4 @@ -/* gmpc-fullscreeninfo (GMPC plugin) +/* gmpc-fullscreen_info (GMPC plugin) * Copyright (C) 2006-2009 Qball Cow * Project homepage: http://gmpcwiki.sarine.nl/ @@ -23,12 +23,26 @@ #include #include #include +#include #include #include + +typedef struct _FullscreenInfoPlugin FullscreenInfoPlugin; +typedef struct _FullscreenInfoPluginClass FullscreenInfoPluginClass; + +struct _FullscreenInfoPlugin +{ + GmpcPluginBase parent_instance; +}; + +struct _FullscreenInfoPluginClass +{ + GmpcPluginBaseClass parent_class; +}; + extern GmpcConnection *gmpcconn; -int plugin_api_version = PLUGIN_API_VERSION; gulong signal_handler = 0; GtkWidget *buttons[4] = {NULL, }; @@ -36,13 +50,13 @@ GtkWidget *label = NULL; /** * Get/Set enabled functions. */ -static int fullscreeninfo_get_enabled(void) +static gboolean fullscreen_info_get_enabled(GmpcPluginBase *plug) { - return cfg_get_single_value_as_int_with_default(config, "fullscreeninfo-plugin", "enable", TRUE); + return cfg_get_single_value_as_int_with_default(config, "fullscreen_info-plugin", "enable", TRUE); } -static void fullscreeninfo_set_enabled(int enabled) +static void fullscreen_info_set_enabled(GmpcPluginBase *plug, int enabled) { - cfg_set_single_value_as_int(config, "fullscreeninfo-plugin", "enable", enabled); + cfg_set_single_value_as_int(config, "fullscreen_info-plugin", "enable", enabled); } @@ -60,8 +74,7 @@ static gboolean gfi_window_fullscreen(GtkWidget *window) } static void gfi_size_allocate(GtkWidget *window, GtkAllocation *alloc, GtkWidget *image) { - - g_idle_add(gfi_window_fullscreen, window); + g_idle_add((GSourceFunc)gfi_window_fullscreen, window); } static void gfi_size_allocate_mi(GtkWidget *window, GtkAllocation *alloc, GtkWidget *image){ @@ -112,7 +125,7 @@ static void gfi_fullscreen(void) GtkWidget *hbox = gtk_hbox_new(TRUE, 6); gtk_widget_set_has_tooltip(metaimage, FALSE); - gtk_window_set_keep_above(popup, TRUE); + gtk_window_set_keep_above(GTK_WINDOW(popup), TRUE); /* Setup the meta image */ gmpc_metaimage_set_no_cover_icon(GMPC_METAIMAGE(metaimage),(char *)"gmpc"); gmpc_metaimage_set_squared(GMPC_METAIMAGE(metaimage), TRUE); @@ -190,7 +203,7 @@ static void gfi_fullscreen(void) gtk_widget_show_all(popup); } -static int gfi_add_go_menu(GtkWidget *menu) +static int gfi_add_tool_menu(GmpcPluginToolMenuIface *plug, GtkMenu *menu) { GtkWidget *item = NULL; @@ -204,12 +217,75 @@ static int gfi_add_go_menu(GtkWidget *menu) return 1; } -/* main plugin_osd info */ -gmpcPlugin plugin = { - .name = "Qball's Fullscreen status", - .version = {PLUGIN_MAJOR_VERSION,PLUGIN_MINOR_VERSION,PLUGIN_MICRO_VERSION}, - .plugin_type = GMPC_PLUGIN_NO_GUI, - .get_enabled = fullscreeninfo_get_enabled, - .set_enabled = fullscreeninfo_set_enabled, - .tool_menu_integration = gfi_add_go_menu -}; +/** + * Gobject plugin + */ +static void fullscreen_info_plugin_class_init (FullscreenInfoPluginClass *klass); +GType fullscreen_info_plugin_get_type(void); + +static int *fullscreen_info_plugin_get_version(GmpcPluginBase *plug, int *length) +{ + static int version[3] = {PLUGIN_MAJOR_VERSION,PLUGIN_MINOR_VERSION,PLUGIN_MICRO_VERSION}; + if(length) *length = 3; + return (int *)version; +} + +static const char *fullscreen_info_plugin_get_name(GmpcPluginBase *plug) +{ + return "Fullscreen info plugin"; +} +static GObject *fullscreen_info_plugin_constructor(GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) { + FullscreenInfoPluginClass * klass; + FullscreenInfoPlugin *self; + GObjectClass * parent_class; + klass = (g_type_class_peek (fullscreen_info_plugin_get_type())); + parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); + self = (FullscreenInfoPlugin *) parent_class->constructor (type, n_construct_properties, construct_properties); + + /* Make it an internal plugin */ + GMPC_PLUGIN_BASE(self)->plugin_type = GMPC_PLUGIN_NO_GUI; + + return G_OBJECT(self); +} + + +static void fullscreen_info_plugin_class_init (FullscreenInfoPluginClass *klass) +{ + G_OBJECT_CLASS(klass)->constructor = fullscreen_info_plugin_constructor; + /* Connect plugin functions */ + GMPC_PLUGIN_BASE_CLASS(klass)->get_version = fullscreen_info_plugin_get_version; + GMPC_PLUGIN_BASE_CLASS(klass)->get_name = fullscreen_info_plugin_get_name; + + GMPC_PLUGIN_BASE_CLASS(klass)->get_enabled = fullscreen_info_get_enabled; + GMPC_PLUGIN_BASE_CLASS(klass)->set_enabled = fullscreen_info_set_enabled; +} + +static void fullscreen_info_plugin_gmpc_plugin_tool_menu_iface_interface_init (GmpcPluginToolMenuIfaceIface * iface) { + iface->tool_menu_integration = gfi_add_tool_menu; +} + +GType fullscreen_info_plugin_get_type(void) { + static GType fullscreen_info_plugin_type_id = 0; + if(fullscreen_info_plugin_type_id == 0) { + static const GTypeInfo info = { + .class_size = sizeof(FullscreenInfoPluginClass), + .class_init = (GClassInitFunc)fullscreen_info_plugin_class_init, + .instance_size = sizeof(FullscreenInfoPlugin), + .n_preallocs = 0 + }; + + static const GInterfaceInfo iface_info = { (GInterfaceInitFunc) fullscreen_info_plugin_gmpc_plugin_tool_menu_iface_interface_init, + (GInterfaceFinalizeFunc) NULL, NULL}; + + fullscreen_info_plugin_type_id = g_type_register_static(GMPC_PLUGIN_TYPE_BASE, "FullscreenInfosPlugin", &info, 0); + + g_type_add_interface_static (fullscreen_info_plugin_type_id, GMPC_PLUGIN_TYPE_TOOL_MENU_IFACE, &iface_info); + } + return fullscreen_info_plugin_type_id; +} + +G_MODULE_EXPORT GType plugin_get_type(void) +{ + printf("Type\n"); + return fullscreen_info_plugin_get_type(); +} -- 2.11.4.GIT