From 19960d14f621cd336b88bafbb027cc4dc546eeb6 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 21 Nov 2013 04:43:21 +0100 Subject: [PATCH] Factored some more code --- tools/helper.c | 27 +++++++++++++++++++++++++++ tools/notify.c | 23 +---------------------- tools/test.c | 23 +---------------------- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/tools/helper.c b/tools/helper.c index 6c20f5e..6dcad41 100644 --- a/tools/helper.c +++ b/tools/helper.c @@ -91,6 +91,8 @@ static void _helper_init(PanelAppletHelper * helper, Panel * panel, /* useful */ #define HELPER_POSITION_MENU_WIDGET #include "../src/helper.c" +static int _helper_append(PanelAppletHelper * helper, char const * applet, + GtkWidget * box); /* public */ @@ -209,3 +211,28 @@ static void _helper_init(PanelAppletHelper * helper, Panel * panel, helper->shutdown_dialog = _panel_helper_shutdown_dialog; helper->suspend = _panel_helper_suspend; } + + +/* useful */ +/* helper_append */ +static int _helper_append(PanelAppletHelper * helper, char const * applet, + GtkWidget * box) +{ + Plugin * plugin; + PanelAppletDefinition * pad; + PanelApplet * pa; + GtkWidget * widget; + + if((plugin = plugin_new(LIBDIR, "Panel", "applets", applet)) == NULL) + return error_print(PROGNAME); + if((pad = plugin_lookup(plugin, "applet")) == NULL) + { + plugin_delete(plugin); + return error_print(PROGNAME); + } + widget = NULL; + if((pa = pad->init(helper, &widget)) != NULL && widget != NULL) + gtk_box_pack_start(GTK_BOX(box), widget, pad->expand, pad->fill, + 0); + return 0; +} diff --git a/tools/notify.c b/tools/notify.c index 225a36c..99d8b52 100644 --- a/tools/notify.c +++ b/tools/notify.c @@ -68,12 +68,8 @@ static int _notify(GtkIconSize iconsize, int timeout, char * applets[]) PanelWindow top; char * filename; GtkWidget * box; - GtkWidget * widget; size_t i; - Plugin * plugin; PanelAppletHelper helper; - PanelAppletDefinition * pad; - PanelApplet * pa; GdkScreen * screen; GdkWindow * root; GdkRectangle rect; @@ -104,24 +100,7 @@ static int _notify(GtkIconSize iconsize, int timeout, char * applets[]) box = gtk_hbox_new(FALSE, 4); _helper_init(&helper, &panel, PANEL_APPLET_TYPE_NOTIFICATION, iconsize); for(i = 0; applets[i] != NULL; i++) - { - if((plugin = plugin_new(LIBDIR, "Panel", "applets", applets[i])) - == NULL) - { - error_print(PROGNAME); - continue; - } - if((pad = plugin_lookup(plugin, "applet")) == NULL) - { - plugin_delete(plugin); - continue; - } - widget = NULL; - if((pa = pad->init(&helper, &widget)) != NULL - && widget != NULL) - gtk_box_pack_start(GTK_BOX(box), widget, pad->expand, - pad->fill, 0); - } + _helper_append(&helper, applets[i], box); gtk_container_add(GTK_CONTAINER(panel.window), box); gtk_widget_show_all(panel.window); panel.timeout = 0; diff --git a/tools/test.c b/tools/test.c index 71c686a..df9023b 100644 --- a/tools/test.c +++ b/tools/test.c @@ -64,12 +64,8 @@ static int _test(GtkIconSize iconsize, char * applets[]) PanelWindow top; char * filename; GtkWidget * box; - GtkWidget * widget; size_t i; - Plugin * plugin; PanelAppletHelper helper; - PanelAppletDefinition * pad; - PanelApplet * pa; GdkScreen * screen; GdkWindow * root; GdkRectangle rect; @@ -92,24 +88,7 @@ static int _test(GtkIconSize iconsize, char * applets[]) box = gtk_hbox_new(FALSE, 4); _helper_init(&helper, &panel, PANEL_APPLET_TYPE_NORMAL, iconsize); for(i = 0; applets[i] != NULL; i++) - { - if((plugin = plugin_new(LIBDIR, "Panel", "applets", applets[i])) - == NULL) - { - error_print(PROGNAME); - continue; - } - if((pad = plugin_lookup(plugin, "applet")) == NULL) - { - plugin_delete(plugin); - continue; - } - widget = NULL; - if((pa = pad->init(&helper, &widget)) != NULL - && widget != NULL) - gtk_box_pack_start(GTK_BOX(box), widget, pad->expand, - pad->fill, 0); - } + _helper_append(&helper, applets[i], box); gtk_container_add(GTK_CONTAINER(panel.window), box); gtk_widget_show_all(panel.window); panel.timeout = 0;