Largely improved the test utility
This commit is contained in:
parent
edbda6e74d
commit
3b863cd974
|
@ -12,4 +12,4 @@ sources=test.c
|
|||
install=$(BINDIR)
|
||||
|
||||
[test.c]
|
||||
depends=../config.h
|
||||
depends=../src/common.h,../config.h
|
||||
|
|
83
tools/test.c
83
tools/test.c
|
@ -24,7 +24,9 @@
|
|||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <System.h>
|
||||
#include "Panel.h"
|
||||
#include "../src/common.h"
|
||||
#include "../config.h"
|
||||
|
||||
|
||||
|
@ -35,9 +37,18 @@
|
|||
|
||||
|
||||
/* private */
|
||||
/* types */
|
||||
struct _Panel
|
||||
{
|
||||
Config * config;
|
||||
GtkWidget * window;
|
||||
};
|
||||
|
||||
|
||||
/* prototypes */
|
||||
static int _test(char * applets[]);
|
||||
static int _test_list(void);
|
||||
static char * _config_get_filename(void);
|
||||
static int _error(char const * message, int ret);
|
||||
static int _usage(void);
|
||||
|
||||
|
@ -46,12 +57,15 @@ static int _usage(void);
|
|||
static char const * _helper_config_get(Panel * panel, char const * section,
|
||||
char const * variable);
|
||||
static int _helper_error(Panel * panel, char const * message, int ret);
|
||||
static void _helper_position_menu(Panel * panel, GtkMenu * menu, gint * x,
|
||||
gint * y, gboolean * push_in);
|
||||
|
||||
static int _test(char * applets[])
|
||||
{
|
||||
Panel panel;
|
||||
char * filename;
|
||||
char const path[] = PREFIX "/lib/Panel/applets/";
|
||||
char const so[] = ".so";
|
||||
GtkWidget * window;
|
||||
GtkWidget * box;
|
||||
GtkWidget * widget;
|
||||
size_t i;
|
||||
|
@ -62,15 +76,23 @@ static int _test(char * applets[])
|
|||
PanelAppletHelper helper;
|
||||
PanelApplet * pa;
|
||||
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(
|
||||
if((panel.config = config_new()) == NULL)
|
||||
return error_print("panel_test");
|
||||
if((filename = _config_get_filename()) != NULL
|
||||
&& config_load(panel.config, filename) != 0)
|
||||
error_print("panel_test");
|
||||
free(filename);
|
||||
panel.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect(G_OBJECT(panel.window), "delete-event", G_CALLBACK(
|
||||
gtk_main_quit), NULL);
|
||||
gtk_window_set_title(GTK_WINDOW(window), "Applet tester");
|
||||
gtk_window_set_title(GTK_WINDOW(panel.window), "Applet tester");
|
||||
box = gtk_hbox_new(FALSE, 4);
|
||||
memset(&helper, 0, sizeof(helper));
|
||||
helper.panel = &panel;
|
||||
helper.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
|
||||
helper.config_get = _helper_config_get;
|
||||
helper.error = _helper_error;
|
||||
helper.position_menu = _helper_position_menu;
|
||||
for(i = 0; applets[i] != NULL; i++)
|
||||
{
|
||||
len = sizeof(path) + strlen(applets[i]) + sizeof(so);
|
||||
|
@ -79,7 +101,11 @@ static int _test(char * applets[])
|
|||
p = q;
|
||||
snprintf(p, len, "%s%s%s", path, applets[i], so);
|
||||
if((dl = dlopen(p, RTLD_LAZY)) == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: %s\n", "panel_test",
|
||||
applets[i], dlerror());
|
||||
continue;
|
||||
}
|
||||
if((pa = dlsym(dl, "applet")) == NULL)
|
||||
{
|
||||
dlclose(dl);
|
||||
|
@ -91,15 +117,20 @@ static int _test(char * applets[])
|
|||
pa->fill, 0);
|
||||
}
|
||||
free(p);
|
||||
gtk_container_add(GTK_CONTAINER(window), box);
|
||||
gtk_widget_show_all(window);
|
||||
gtk_container_add(GTK_CONTAINER(panel.window), box);
|
||||
gtk_widget_show_all(panel.window);
|
||||
gtk_main();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char const * _helper_config_get(Panel * panel, char const * section,
|
||||
char const * variable)
|
||||
{
|
||||
return NULL;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\")\n", __func__, section,
|
||||
variable);
|
||||
#endif
|
||||
return config_get(panel->config, section, variable);
|
||||
}
|
||||
|
||||
static int _helper_error(Panel * panel, char const * message, int ret)
|
||||
|
@ -109,6 +140,26 @@ static int _helper_error(Panel * panel, char const * message, int ret)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void _helper_position_menu(Panel * panel, GtkMenu * menu, gint * x,
|
||||
gint * y, gboolean * push_in)
|
||||
{
|
||||
GtkRequisition req;
|
||||
gint sx = 0;
|
||||
gint sy = 0;
|
||||
|
||||
gtk_widget_size_request(GTK_WIDGET(menu), &req);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() width=%d, height=%d\n", __func__,
|
||||
req.width, req.height);
|
||||
#endif
|
||||
if(req.height <= 0)
|
||||
return;
|
||||
gtk_window_get_position(GTK_WINDOW(panel->window), x, y);
|
||||
gtk_window_get_size(GTK_WINDOW(panel->window), &sx, &sy);
|
||||
*y += sy;
|
||||
*push_in = TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* test_list */
|
||||
static int _test_list(void)
|
||||
|
@ -137,6 +188,23 @@ static int _test_list(void)
|
|||
}
|
||||
|
||||
|
||||
/* config_get_filename */
|
||||
static char * _config_get_filename(void)
|
||||
{
|
||||
char const * homedir;
|
||||
size_t len;
|
||||
char * filename;
|
||||
|
||||
if((homedir = getenv("HOME")) == NULL)
|
||||
homedir = g_get_home_dir();
|
||||
len = strlen(homedir) + 1 + sizeof(PANEL_CONFIG_FILE);
|
||||
if((filename = malloc(len)) == NULL)
|
||||
return NULL;
|
||||
snprintf(filename, len, "%s/%s", homedir, PANEL_CONFIG_FILE);
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
/* error */
|
||||
static int _error(char const * message, int ret)
|
||||
{
|
||||
|
@ -175,6 +243,5 @@ int main(int argc, char * argv[])
|
|||
if(optind == argc)
|
||||
return _usage();
|
||||
_test(&argv[optind]);
|
||||
gtk_main();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user