Renamed panel_test to panel-test and added panel-notify
This commit is contained in:
parent
ba6bc608ea
commit
a2d487a7df
2
Makefile
2
Makefile
|
@ -101,8 +101,10 @@ dist:
|
||||||
$(PACKAGE)-$(VERSION)/src/applets/Makefile \
|
$(PACKAGE)-$(VERSION)/src/applets/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/src/applets/tasks.atoms \
|
$(PACKAGE)-$(VERSION)/src/applets/tasks.atoms \
|
||||||
$(PACKAGE)-$(VERSION)/src/applets/project.conf \
|
$(PACKAGE)-$(VERSION)/src/applets/project.conf \
|
||||||
|
$(PACKAGE)-$(VERSION)/tools/notify.c \
|
||||||
$(PACKAGE)-$(VERSION)/tools/test.c \
|
$(PACKAGE)-$(VERSION)/tools/test.c \
|
||||||
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
||||||
|
$(PACKAGE)-$(VERSION)/tools/helper.c \
|
||||||
$(PACKAGE)-$(VERSION)/tools/project.conf \
|
$(PACKAGE)-$(VERSION)/tools/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/COPYING \
|
$(PACKAGE)-$(VERSION)/COPYING \
|
||||||
$(PACKAGE)-$(VERSION)/Makefile \
|
$(PACKAGE)-$(VERSION)/Makefile \
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
panel_test
|
panel-notify
|
||||||
|
panel-test
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
TARGETS = panel_test
|
TARGETS = panel-notify panel-test
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
DESTDIR =
|
DESTDIR =
|
||||||
BINDIR = $(PREFIX)/bin
|
BINDIR = $(PREFIX)/bin
|
||||||
|
@ -16,27 +16,37 @@ INSTALL ?= install
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
panel_test_OBJS = test.o
|
panel-notify_OBJS = notify.o
|
||||||
panel_test_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) -D PREFIX=\"$(PREFIX)\" $(CFLAGSF) $(CFLAGS)
|
panel-notify_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) -D PREFIX=\"$(PREFIX)\" $(CFLAGSF) $(CFLAGS)
|
||||||
panel_test_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
panel-notify_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
panel_test: $(panel_test_OBJS)
|
panel-notify: $(panel-notify_OBJS)
|
||||||
$(CC) -o panel_test $(panel_test_OBJS) $(panel_test_LDFLAGS)
|
$(CC) -o panel-notify $(panel-notify_OBJS) $(panel-notify_LDFLAGS)
|
||||||
|
|
||||||
test.o: test.c ../src/panel.h ../config.h
|
panel-test_OBJS = test.o
|
||||||
$(CC) $(panel_test_CFLAGS) -c test.c
|
panel-test_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) -D PREFIX=\"$(PREFIX)\" $(CFLAGSF) $(CFLAGS)
|
||||||
|
panel-test_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
|
panel-test: $(panel-test_OBJS)
|
||||||
|
$(CC) -o panel-test $(panel-test_OBJS) $(panel-test_LDFLAGS)
|
||||||
|
|
||||||
|
notify.o: notify.c helper.c ../src/panel.h ../config.h
|
||||||
|
$(CC) $(panel-notify_CFLAGS) -c notify.c
|
||||||
|
|
||||||
|
test.o: test.c helper.c ../src/panel.h ../config.h
|
||||||
|
$(CC) $(panel-test_CFLAGS) -c test.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) -- $(panel_test_OBJS)
|
$(RM) -- $(panel-notify_OBJS) $(panel-test_OBJS)
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
$(RM) -- $(TARGETS)
|
$(RM) -- $(TARGETS)
|
||||||
|
|
||||||
install: $(TARGETS)
|
install: $(TARGETS)
|
||||||
$(MKDIR) $(DESTDIR)$(BINDIR)
|
$(MKDIR) $(DESTDIR)$(BINDIR)
|
||||||
$(INSTALL) -m 0755 -- panel_test $(DESTDIR)$(BINDIR)/panel_test
|
$(INSTALL) -m 0755 -- panel-notify $(DESTDIR)$(BINDIR)/panel-notify
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
$(RM) -- $(DESTDIR)$(BINDIR)/panel_test
|
$(RM) -- $(DESTDIR)$(BINDIR)/panel-notify
|
||||||
|
|
||||||
.PHONY: all clean distclean install uninstall
|
.PHONY: all clean distclean install uninstall
|
||||||
|
|
200
tools/helper.c
Normal file
200
tools/helper.c
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
/* $Id$ */
|
||||||
|
static char const _copyright[] =
|
||||||
|
"Copyright (c) 2009-2012 Pierre Pronchery <khorben@defora.org>";
|
||||||
|
/* This file is part of DeforaOS Desktop Panel */
|
||||||
|
static char const _license[] =
|
||||||
|
"This program is free software: you can redistribute it and/or modify\n"
|
||||||
|
"it under the terms of the GNU General Public License as published by\n"
|
||||||
|
"the Free Software Foundation, version 3 of the License.\n"
|
||||||
|
"\n"
|
||||||
|
"This program is distributed in the hope that it will be useful,\n"
|
||||||
|
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||||
|
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||||
|
"GNU General Public License for more details.\n"
|
||||||
|
"\n"
|
||||||
|
"You should have received a copy of the GNU General Public License\n"
|
||||||
|
"along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
||||||
|
/* TODO:
|
||||||
|
* - implement all remaining helpers */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <System.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* types */
|
||||||
|
struct _Panel
|
||||||
|
{
|
||||||
|
Config * config;
|
||||||
|
GtkWidget * window;
|
||||||
|
gint timeout;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* constants */
|
||||||
|
#ifndef PREFIX
|
||||||
|
# define PREFIX "/usr/local"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static char const * _authors[] =
|
||||||
|
{
|
||||||
|
"Pierre Pronchery <khorben@defora.org>",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* private */
|
||||||
|
/* prototypes */
|
||||||
|
static int _applet_list(void);
|
||||||
|
static char * _config_get_filename(void);
|
||||||
|
|
||||||
|
static int _error(char const * message, int ret);
|
||||||
|
|
||||||
|
|
||||||
|
/* helper */
|
||||||
|
/* essential */
|
||||||
|
static void _helper_init(PanelAppletHelper * helper, Panel * panel,
|
||||||
|
GtkIconSize iconsize);
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
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_about_dialog(Panel * panel);
|
||||||
|
static void _helper_position_menu(Panel * panel, GtkMenu * menu, gint * x,
|
||||||
|
gint * y, gboolean * push_in);
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
/* applet_list */
|
||||||
|
static int _applet_list(void)
|
||||||
|
{
|
||||||
|
char const path[] = PREFIX "/lib/Panel/applets";
|
||||||
|
DIR * dir;
|
||||||
|
struct dirent * de;
|
||||||
|
size_t len;
|
||||||
|
char const * sep = "";
|
||||||
|
|
||||||
|
puts("Applets available:");
|
||||||
|
if((dir = opendir(path)) == NULL)
|
||||||
|
return _error(path, 1);
|
||||||
|
while((de = readdir(dir)) != NULL)
|
||||||
|
{
|
||||||
|
len = strlen(de->d_name);
|
||||||
|
if(len < 4 || strcmp(&de->d_name[len - 3], ".so") != 0)
|
||||||
|
continue;
|
||||||
|
de->d_name[len - 3] = '\0';
|
||||||
|
printf("%s%s", sep, de->d_name);
|
||||||
|
sep = ", ";
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
closedir(dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
return _helper_error(NULL, message, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* helpers */
|
||||||
|
/* essential */
|
||||||
|
/* helper_init */
|
||||||
|
static void _helper_init(PanelAppletHelper * helper, Panel * panel,
|
||||||
|
GtkIconSize iconsize)
|
||||||
|
{
|
||||||
|
memset(helper, 0, sizeof(*helper));
|
||||||
|
helper->panel = panel;
|
||||||
|
helper->icon_size = iconsize;
|
||||||
|
helper->config_get = _helper_config_get;
|
||||||
|
helper->error = _helper_error;
|
||||||
|
helper->about_dialog = _helper_about_dialog;
|
||||||
|
helper->position_menu = _helper_position_menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
/* helper_config_get */
|
||||||
|
static char const * _helper_config_get(Panel * panel, char const * section,
|
||||||
|
char const * variable)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\")\n", __func__, section,
|
||||||
|
variable);
|
||||||
|
#endif
|
||||||
|
return config_get(panel->config, section, variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* helper_error */
|
||||||
|
static int _helper_error(Panel * panel, char const * message, int ret)
|
||||||
|
{
|
||||||
|
fputs(PACKAGE ": ", stderr);
|
||||||
|
perror(message);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* helper_about_dialog */
|
||||||
|
static void _helper_about_dialog(Panel * panel)
|
||||||
|
{
|
||||||
|
GtkWidget * dialog;
|
||||||
|
|
||||||
|
dialog = desktop_about_dialog_new();
|
||||||
|
desktop_about_dialog_set_authors(dialog, _authors);
|
||||||
|
desktop_about_dialog_set_copyright(dialog, _copyright);
|
||||||
|
desktop_about_dialog_set_logo_icon_name(dialog,
|
||||||
|
"panel-settings"); /* XXX */
|
||||||
|
desktop_about_dialog_set_license(dialog, _license);
|
||||||
|
desktop_about_dialog_set_program_name(dialog, "Panel test");
|
||||||
|
desktop_about_dialog_set_version(dialog, VERSION);
|
||||||
|
desktop_about_dialog_set_website(dialog,
|
||||||
|
"http://www.defora.org/");
|
||||||
|
gtk_window_set_position(GTK_WINDOW(dialog),
|
||||||
|
GTK_WIN_POS_CENTER_ALWAYS);
|
||||||
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* helper_position_menu */
|
||||||
|
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;
|
||||||
|
}
|
178
tools/notify.c
Normal file
178
tools/notify.c
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS Desktop Panel */
|
||||||
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <System.h>
|
||||||
|
#include <Desktop.h>
|
||||||
|
#include "Panel.h"
|
||||||
|
#include "panel.h"
|
||||||
|
#include "../config.h"
|
||||||
|
#ifdef PACKAGE
|
||||||
|
# undef PACKAGE
|
||||||
|
#endif
|
||||||
|
#define PACKAGE "panel-notify"
|
||||||
|
#include "helper.c"
|
||||||
|
|
||||||
|
|
||||||
|
/* private */
|
||||||
|
/* prototypes */
|
||||||
|
static int _notify(GtkIconSize iconsize, int timeout, char * applets[]);
|
||||||
|
/* callbacks */
|
||||||
|
static gboolean _notify_on_timeout(gpointer data);
|
||||||
|
|
||||||
|
static int _usage(void);
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
/* notify */
|
||||||
|
static int _notify(GtkIconSize iconsize, int timeout, char * applets[])
|
||||||
|
{
|
||||||
|
Panel panel;
|
||||||
|
char * filename;
|
||||||
|
char const path[] = PREFIX "/lib/Panel/applets/";
|
||||||
|
char const so[] = ".so";
|
||||||
|
GtkWidget * box;
|
||||||
|
GtkWidget * widget;
|
||||||
|
size_t i;
|
||||||
|
size_t len;
|
||||||
|
char * p = NULL;
|
||||||
|
char * q;
|
||||||
|
void * dl;
|
||||||
|
PanelAppletHelper helper;
|
||||||
|
PanelAppletDefinition * pad;
|
||||||
|
PanelApplet * pa;
|
||||||
|
|
||||||
|
if((panel.config = config_new()) == NULL)
|
||||||
|
return error_print("panel-notify");
|
||||||
|
if((filename = _config_get_filename()) != NULL
|
||||||
|
&& config_load(panel.config, filename) != 0)
|
||||||
|
error_print("panel-notify");
|
||||||
|
free(filename);
|
||||||
|
panel.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
gtk_container_set_border_width(GTK_CONTAINER(panel.window), 4);
|
||||||
|
gtk_window_set_accept_focus(GTK_WINDOW(panel.window), FALSE);
|
||||||
|
gtk_window_set_decorated(GTK_WINDOW(panel.window), FALSE);
|
||||||
|
gtk_window_set_position(GTK_WINDOW(panel.window),
|
||||||
|
GTK_WIN_POS_CENTER_ALWAYS);
|
||||||
|
g_signal_connect(G_OBJECT(panel.window), "delete-event", G_CALLBACK(
|
||||||
|
gtk_main_quit), NULL);
|
||||||
|
gtk_window_set_title(GTK_WINDOW(panel.window), "Applet notifier");
|
||||||
|
box = gtk_hbox_new(FALSE, 4);
|
||||||
|
_helper_init(&helper, &panel, iconsize);
|
||||||
|
for(i = 0; applets[i] != NULL; i++)
|
||||||
|
{
|
||||||
|
len = sizeof(path) + strlen(applets[i]) + sizeof(so);
|
||||||
|
if((q = realloc(p, len)) == NULL)
|
||||||
|
break;
|
||||||
|
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-notify",
|
||||||
|
applets[i], dlerror());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if((pad = dlsym(dl, "applet")) == NULL)
|
||||||
|
{
|
||||||
|
dlclose(dl);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
gtk_container_add(GTK_CONTAINER(panel.window), box);
|
||||||
|
gtk_widget_show_all(panel.window);
|
||||||
|
panel.timeout = 0;
|
||||||
|
if(timeout > 0)
|
||||||
|
panel.timeout = g_timeout_add(timeout * 1000,
|
||||||
|
_notify_on_timeout, &panel);
|
||||||
|
gtk_main();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* callbacks */
|
||||||
|
/* notify_on_timeout */
|
||||||
|
static gboolean _notify_on_timeout(gpointer data)
|
||||||
|
{
|
||||||
|
Panel * panel = data;
|
||||||
|
|
||||||
|
panel->timeout = 0;
|
||||||
|
gtk_main_quit();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* usage */
|
||||||
|
static int _usage(void)
|
||||||
|
{
|
||||||
|
fputs("Usage: panel-notify [-sx][-t timeout] applet...\n"
|
||||||
|
" panel-notify -l\n"
|
||||||
|
" -l Lists the plug-ins available\n", stderr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* functions */
|
||||||
|
/* main */
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
GtkIconSize iconsize = GTK_ICON_SIZE_LARGE_TOOLBAR;
|
||||||
|
int timeout = 3;
|
||||||
|
int o;
|
||||||
|
char * p;
|
||||||
|
|
||||||
|
gtk_init(&argc, &argv);
|
||||||
|
while((o = getopt(argc, argv, "lst:x")) != -1)
|
||||||
|
switch(o)
|
||||||
|
{
|
||||||
|
case 'l':
|
||||||
|
return _applet_list();
|
||||||
|
case 's':
|
||||||
|
iconsize = GTK_ICON_SIZE_SMALL_TOOLBAR;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
timeout = strtoul(optarg, &p, 0);
|
||||||
|
if(optarg[0] == '\0' || *p != '\0'
|
||||||
|
|| timeout < 0)
|
||||||
|
return _usage();
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
iconsize = GTK_ICON_SIZE_MENU;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return _usage();
|
||||||
|
}
|
||||||
|
if(optind == argc)
|
||||||
|
return _usage();
|
||||||
|
_notify(iconsize, timeout, &argv[optind]);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,15 +1,23 @@
|
||||||
targets=panel_test
|
targets=panel-notify,panel-test
|
||||||
cppflags_force=-I ../include -I ../src
|
cppflags_force=-I ../include -I ../src
|
||||||
cflags_force=-W `pkg-config --cflags libSystem libDesktop`
|
cflags_force=-W `pkg-config --cflags libSystem libDesktop`
|
||||||
cflags=-Wall -g -O2
|
cflags=-Wall -g -O2
|
||||||
ldflags_force=`pkg-config --libs libSystem libDesktop`
|
ldflags_force=`pkg-config --libs libSystem libDesktop`
|
||||||
dist=Makefile
|
dist=Makefile,helper.c
|
||||||
|
|
||||||
[panel_test]
|
[panel-notify]
|
||||||
|
type=binary
|
||||||
|
cppflags=-D PREFIX=\"$(PREFIX)\"
|
||||||
|
sources=notify.c
|
||||||
|
install=$(BINDIR)
|
||||||
|
|
||||||
|
[panel-test]
|
||||||
type=binary
|
type=binary
|
||||||
cppflags=-D PREFIX=\"$(PREFIX)\"
|
cppflags=-D PREFIX=\"$(PREFIX)\"
|
||||||
sources=test.c
|
sources=test.c
|
||||||
install=$(BINDIR)
|
|
||||||
|
[notify.c]
|
||||||
|
depends=helper.c,../src/panel.h,../config.h
|
||||||
|
|
||||||
[test.c]
|
[test.c]
|
||||||
depends=../src/panel.h,../config.h
|
depends=helper.c,../src/panel.h,../config.h
|
||||||
|
|
208
tools/test.c
208
tools/test.c
|
@ -1,21 +1,17 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
static char const _copyright[] =
|
/* Copyright (c) 2011-2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
"Copyright (c) 2011-2012 Pierre Pronchery <khorben@defora.org>";
|
|
||||||
/* This file is part of DeforaOS Desktop Panel */
|
/* This file is part of DeforaOS Desktop Panel */
|
||||||
static char const _license[] =
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
"This program is free software: you can redistribute it and/or modify\n"
|
* it under the terms of the GNU General Public License as published by
|
||||||
"it under the terms of the GNU General Public License as published by\n"
|
* the Free Software Foundation, version 3 of the License.
|
||||||
"the Free Software Foundation, version 3 of the License.\n"
|
*
|
||||||
"\n"
|
* This program is distributed in the hope that it will be useful,
|
||||||
"This program is distributed in the hope that it will be useful,\n"
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
* GNU General Public License for more details.
|
||||||
"GNU General Public License for more details.\n"
|
*
|
||||||
"\n"
|
* You should have received a copy of the GNU General Public License
|
||||||
"You should have received a copy of the GNU General Public License\n"
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
"along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
|
||||||
/* TODO:
|
|
||||||
* - implement all remaining helpers */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,46 +29,22 @@ static char const _license[] =
|
||||||
#include "Panel.h"
|
#include "Panel.h"
|
||||||
#include "panel.h"
|
#include "panel.h"
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
#ifdef PACKAGE
|
||||||
|
# undef PACKAGE
|
||||||
/* constants */
|
|
||||||
#ifndef PREFIX
|
|
||||||
# define PREFIX "/usr/local"
|
|
||||||
#endif
|
#endif
|
||||||
|
#define PACKAGE "panel-test"
|
||||||
static char const * _authors[] =
|
#include "helper.c"
|
||||||
{
|
|
||||||
"Pierre Pronchery <khorben@defora.org>",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
/* types */
|
|
||||||
struct _Panel
|
|
||||||
{
|
|
||||||
Config * config;
|
|
||||||
GtkWidget * window;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _test(char * applets[]);
|
static int _test(GtkIconSize iconsize, 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);
|
static int _usage(void);
|
||||||
|
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
static char const * _helper_config_get(Panel * panel, char const * section,
|
/* test */
|
||||||
char const * variable);
|
static int _test(GtkIconSize iconsize, char * applets[])
|
||||||
static int _helper_error(Panel * panel, char const * message, int ret);
|
|
||||||
static void _helper_about_dialog(Panel * panel);
|
|
||||||
static void _helper_position_menu(Panel * panel, GtkMenu * menu, gint * x,
|
|
||||||
gint * y, gboolean * push_in);
|
|
||||||
|
|
||||||
static int _test(char * applets[])
|
|
||||||
{
|
{
|
||||||
Panel panel;
|
Panel panel;
|
||||||
char * filename;
|
char * filename;
|
||||||
|
@ -90,23 +62,17 @@ static int _test(char * applets[])
|
||||||
PanelApplet * pa;
|
PanelApplet * pa;
|
||||||
|
|
||||||
if((panel.config = config_new()) == NULL)
|
if((panel.config = config_new()) == NULL)
|
||||||
return error_print("panel_test");
|
return error_print(PACKAGE);
|
||||||
if((filename = _config_get_filename()) != NULL
|
if((filename = _config_get_filename()) != NULL
|
||||||
&& config_load(panel.config, filename) != 0)
|
&& config_load(panel.config, filename) != 0)
|
||||||
error_print("panel_test");
|
error_print(PACKAGE);
|
||||||
free(filename);
|
free(filename);
|
||||||
panel.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
panel.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
g_signal_connect(G_OBJECT(panel.window), "delete-event", G_CALLBACK(
|
g_signal_connect(G_OBJECT(panel.window), "delete-event", G_CALLBACK(
|
||||||
gtk_main_quit), NULL);
|
gtk_main_quit), NULL);
|
||||||
gtk_window_set_title(GTK_WINDOW(panel.window), "Applet tester");
|
gtk_window_set_title(GTK_WINDOW(panel.window), "Applet tester");
|
||||||
box = gtk_hbox_new(FALSE, 4);
|
box = gtk_hbox_new(FALSE, 4);
|
||||||
memset(&helper, 0, sizeof(helper));
|
_helper_init(&helper, &panel, iconsize);
|
||||||
helper.panel = &panel;
|
|
||||||
helper.icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
|
|
||||||
helper.config_get = _helper_config_get;
|
|
||||||
helper.error = _helper_error;
|
|
||||||
helper.about_dialog = _helper_about_dialog;
|
|
||||||
helper.position_menu = _helper_position_menu;
|
|
||||||
for(i = 0; applets[i] != NULL; i++)
|
for(i = 0; applets[i] != NULL; i++)
|
||||||
{
|
{
|
||||||
len = sizeof(path) + strlen(applets[i]) + sizeof(so);
|
len = sizeof(path) + strlen(applets[i]) + sizeof(so);
|
||||||
|
@ -116,7 +82,7 @@ static int _test(char * applets[])
|
||||||
snprintf(p, len, "%s%s%s", path, applets[i], so);
|
snprintf(p, len, "%s%s%s", path, applets[i], so);
|
||||||
if((dl = dlopen(p, RTLD_LAZY)) == NULL)
|
if((dl = dlopen(p, RTLD_LAZY)) == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: %s: %s\n", "panel_test",
|
fprintf(stderr, "%s: %s: %s\n", "panel-test",
|
||||||
applets[i], dlerror());
|
applets[i], dlerror());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -134,126 +100,17 @@ static int _test(char * applets[])
|
||||||
free(p);
|
free(p);
|
||||||
gtk_container_add(GTK_CONTAINER(panel.window), box);
|
gtk_container_add(GTK_CONTAINER(panel.window), box);
|
||||||
gtk_widget_show_all(panel.window);
|
gtk_widget_show_all(panel.window);
|
||||||
|
panel.timeout = 0;
|
||||||
gtk_main();
|
gtk_main();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char const * _helper_config_get(Panel * panel, char const * section,
|
|
||||||
char const * variable)
|
|
||||||
{
|
|
||||||
#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)
|
|
||||||
{
|
|
||||||
fputs("panel_test: ", stderr);
|
|
||||||
perror(message);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _helper_about_dialog(Panel * panel)
|
|
||||||
{
|
|
||||||
GtkWidget * dialog;
|
|
||||||
|
|
||||||
dialog = desktop_about_dialog_new();
|
|
||||||
desktop_about_dialog_set_authors(dialog, _authors);
|
|
||||||
desktop_about_dialog_set_copyright(dialog, _copyright);
|
|
||||||
desktop_about_dialog_set_logo_icon_name(dialog,
|
|
||||||
"panel-settings"); /* XXX */
|
|
||||||
desktop_about_dialog_set_license(dialog, _license);
|
|
||||||
desktop_about_dialog_set_program_name(dialog, "Panel test");
|
|
||||||
desktop_about_dialog_set_version(dialog, VERSION);
|
|
||||||
desktop_about_dialog_set_website(dialog,
|
|
||||||
"http://www.defora.org/");
|
|
||||||
gtk_window_set_position(GTK_WINDOW(dialog),
|
|
||||||
GTK_WIN_POS_CENTER_ALWAYS);
|
|
||||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
|
||||||
gtk_widget_destroy(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
char const path[] = PREFIX "/lib/Panel/applets";
|
|
||||||
DIR * dir;
|
|
||||||
struct dirent * de;
|
|
||||||
size_t len;
|
|
||||||
char const * sep = "";
|
|
||||||
|
|
||||||
puts("Applets available:");
|
|
||||||
if((dir = opendir(path)) == NULL)
|
|
||||||
return _error(path, 1);
|
|
||||||
while((de = readdir(dir)) != NULL)
|
|
||||||
{
|
|
||||||
len = strlen(de->d_name);
|
|
||||||
if(len < 4 || strcmp(&de->d_name[len - 3], ".so") != 0)
|
|
||||||
continue;
|
|
||||||
de->d_name[len - 3] = '\0';
|
|
||||||
printf("%s%s", sep, de->d_name);
|
|
||||||
sep = ", ";
|
|
||||||
}
|
|
||||||
putchar('\n');
|
|
||||||
closedir(dir);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* 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)
|
|
||||||
{
|
|
||||||
fputs("panel_test: ", stderr);
|
|
||||||
perror(message);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fputs("Usage: panel_test applet...\n"
|
fputs("Usage: panel-test [-sx] applet...\n"
|
||||||
" panel_test -l\n"
|
" panel-test -l\n"
|
||||||
" -l Lists the plug-ins available\n", stderr);
|
" -l Lists the plug-ins available\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -264,19 +121,26 @@ static int _usage(void)
|
||||||
/* main */
|
/* main */
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
|
GtkIconSize iconsize = GTK_ICON_SIZE_LARGE_TOOLBAR;
|
||||||
int o;
|
int o;
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
while((o = getopt(argc, argv, "l")) != -1)
|
while((o = getopt(argc, argv, "lsx")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
return _test_list();
|
return _applet_list();
|
||||||
|
case 's':
|
||||||
|
iconsize = GTK_ICON_SIZE_SMALL_TOOLBAR;
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
iconsize = GTK_ICON_SIZE_MENU;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
if(optind == argc)
|
if(optind == argc)
|
||||||
return _usage();
|
return _usage();
|
||||||
_test(&argv[optind]);
|
_test(iconsize, &argv[optind]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user