2003-05-10 14:51:27 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2003-05-09 23:15:28 +00:00
|
|
|
#include "kernel/menu.h"
|
|
|
|
#include "kernel/timer.h"
|
|
|
|
#include "timed_menu.h"
|
|
|
|
#include "kernel/action.h"
|
|
|
|
|
2003-05-10 14:51:27 +00:00
|
|
|
#define TIMED_MENU(m) ((Menu *)m)
|
|
|
|
#define TIMED_MENU_DATA(m) ((Timed_Menu_Data *)((Menu *)m)->plugin_data)
|
2003-05-09 23:15:28 +00:00
|
|
|
static char *PLUGIN_NAME = "timed_menu";
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TIMED_MENU_PIPE
|
|
|
|
} Timed_Menu_Type;
|
|
|
|
|
|
|
|
/* we can use various GIO channels to support reading menus (can we add them to
|
|
|
|
the event loop? )
|
|
|
|
stat() based update
|
|
|
|
exec() based read
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
Timed_Menu_Type type;
|
|
|
|
Timer *timer; /* timer code handles free */
|
2003-05-10 14:51:27 +00:00
|
|
|
char *command; /* for the PIPE */
|
2003-05-09 23:15:28 +00:00
|
|
|
} Timed_Menu_Data;
|
|
|
|
|
|
|
|
|
|
|
|
void plugin_setup_config() { }
|
|
|
|
void plugin_startup()
|
|
|
|
{ }
|
|
|
|
void plugin_shutdown() { }
|
|
|
|
|
|
|
|
void timed_menu_timeout_handler(void *data)
|
|
|
|
{
|
|
|
|
Action *a;
|
|
|
|
((Menu *)data)->invalid = TRUE;
|
|
|
|
|
2003-05-10 14:51:27 +00:00
|
|
|
if (!TIMED_MENU(data)->shown) {
|
|
|
|
switch (TIMED_MENU_DATA(data)->type) {
|
|
|
|
case (TIMED_MENU_PIPE):
|
|
|
|
{
|
|
|
|
/* if the menu is not shown, run a process and use its output
|
|
|
|
as menu */
|
2003-05-10 15:12:27 +00:00
|
|
|
char *args[] = {"/bin/sh", "-c", TIMED_MENU_DATA(data)->command,
|
|
|
|
NULL};
|
2003-05-10 14:51:27 +00:00
|
|
|
GIOChannel *io;
|
|
|
|
char *line;
|
|
|
|
gint child, c_stdout, line_len, terminator_pos;
|
|
|
|
GIOStatus status;
|
|
|
|
/* this blocks for now, until the event stuff can handle it */
|
|
|
|
if (!g_spawn_async_with_pipes(NULL,
|
|
|
|
args,
|
|
|
|
NULL,
|
|
|
|
G_SPAWN_DO_NOT_REAP_CHILD,
|
|
|
|
NULL, NULL,
|
|
|
|
&child, NULL, &c_stdout, NULL,
|
|
|
|
NULL)) {
|
|
|
|
g_warning("%s: Unable to run timed_menu program",
|
|
|
|
__FUNCTION__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
io = g_io_channel_unix_new(c_stdout);
|
|
|
|
if (io == NULL) {
|
|
|
|
g_error("%s: Unable to get IO channel", __FUNCTION__);
|
|
|
|
break;
|
|
|
|
}
|
2003-05-09 23:15:28 +00:00
|
|
|
|
2003-05-10 14:51:27 +00:00
|
|
|
menu_clear(TIMED_MENU(data));
|
|
|
|
|
|
|
|
while ( G_IO_STATUS_NORMAL == (status =
|
|
|
|
g_io_channel_read_line
|
|
|
|
(io, &line, &line_len, &terminator_pos, NULL))
|
|
|
|
) {
|
|
|
|
/* the \n looks ugly */
|
|
|
|
line[terminator_pos] = '\0';
|
|
|
|
menu_add_entry(TIMED_MENU(data),
|
|
|
|
menu_entry_new_separator(line));
|
|
|
|
g_message("%s", line);
|
|
|
|
g_free(line);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-05-09 23:15:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *plugin_create()
|
|
|
|
{
|
|
|
|
Timed_Menu_Data *d = g_new(Timed_Menu_Data, 1);
|
|
|
|
Menu *m = menu_new("", PLUGIN_NAME, NULL);
|
|
|
|
|
|
|
|
m->plugin = PLUGIN_NAME;
|
|
|
|
|
|
|
|
d->type = TIMED_MENU_PIPE;
|
|
|
|
d->timer = timer_start(1000000, &timed_menu_timeout_handler, m);
|
2003-05-10 15:12:27 +00:00
|
|
|
d->command = "ls";
|
2003-05-09 23:15:28 +00:00
|
|
|
|
|
|
|
m->plugin_data = (void *)d;
|
|
|
|
|
|
|
|
return (void *)m;
|
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_destroy (void *m)
|
|
|
|
{
|
|
|
|
/* this will be freed by timer_* */
|
2003-05-10 14:51:27 +00:00
|
|
|
timer_stop( ((Timed_Menu_Data *)TIMED_MENU(m)->plugin_data)->timer);
|
2003-05-09 23:15:28 +00:00
|
|
|
|
2003-05-10 14:51:27 +00:00
|
|
|
g_free( TIMED_MENU(m)->plugin_data );
|
2003-05-09 23:15:28 +00:00
|
|
|
}
|