Nico Golde ha scritto:
> Hi,
> it would be cool if there would be a plugin like
> Plugin {
> type = userscript
> config {
> script=/home/foobar/baz.sh
> }
> }
>
> which then just displays the output of the baz.sh script in
> the panel. That would be useful for example for notebook
> users, they could just run one of the text mode acpi tools
> via the script and could see battery amount in the panel
> without installing an extra dockapp which would waste more
> space.
Mmhh.. great idea!
What do you think about this?
# Generic Monitor
Plugin {
type = genmon
config {
Command = echo Battery: $(acpi -b | cut -f 2 -d ",")
CharLength = 20
PollingTime = 5
}
}
The plugin will be in the new version 4.9-2 of "fbpanel"[1].
The source of genmon-plugin is in attachment.
Bye.
Davide Truffa.
[1] http://mentors.debian.net/debian/pool/main/f/fbpanel/
P.S.: I'm sorry, I'm rushing. I have to write a RFS. ;)
/* genmon.c -- Generic monitor plugin for fbpanel
*
* Copyright (C) 2007 Davide Truffa <[EMAIL PROTECTED]>
*
* This plugin 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 2 dated June, 1991.
*
* It 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.
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "panel.h"
#include "misc.h"
#include "plugin.h"
// #define DEBUG
#include "dbg.h"
typedef struct {
char *command;
int size;
int time;
int timer;
GtkWidget *main;
} genmon;
static int
text_update(genmon *gm)
{
FILE *fp;
char text [gm->size+1];
ENTER;
fp = popen(gm->command, "r");
fgets(text, sizeof(text), fp);
pclose(fp);
if (text[strlen(text) - 1] == '\n') {
text[strlen(text) - 1] = '\0';
}
gtk_label_set_text (GTK_LABEL(gm->main), text) ;
RET(1);
}
static void
genmon_destructor(plugin *p)
{
genmon *gm = (genmon *)p->priv;
ENTER;
gm = (genmon *) p->priv;
if (gm->timer)
g_source_remove(gm->timer);
gtk_widget_destroy(gm->main);
g_free(gm);
RET();
}
static int
genmon_constructor(plugin *p)
{
genmon *gm;
line s;
ENTER;
gm = g_new0(genmon, 1);
g_return_val_if_fail(gm != NULL, 0);
p->priv = gm;
gm->size = 15 ;
gm->time = 1 ;
s.len = 256;
while (get_line(p->fp, &s) != LINE_BLOCK_END) {
if (s.type == LINE_NONE) {
ERR( "genmon-plugin: illegal token %s\n", s.str);
goto error;
}
if (s.type == LINE_VAR) {
if (!g_ascii_strcasecmp(s.t[0], "Command")) {
gm->command = g_strdup(s.t[1]);
} else if (!g_ascii_strcasecmp(s.t[0], "CharLength")) {
gm->size = atoi(s.t[1]);
} else if (!g_ascii_strcasecmp(s.t[0], "PollingTime")) {
gm->time = atoi(s.t[1]);
} else {
ERR( "genmon-plugin: unknown var %s\n", s.t[0]);
goto error;
}
}
}
gm->main = gtk_label_new("command");
text_update(gm);
gtk_container_set_border_width (GTK_CONTAINER (p->pwid), 1);
gtk_container_add(GTK_CONTAINER(p->pwid), gm->main);
gtk_widget_show_all(p->pwid);
gm->timer = g_timeout_add(gm->time*1000, (GSourceFunc) text_update, (gpointer)gm);
RET(1);
error:
genmon_destructor(p);
RET(0);
}
plugin_class genmon_plugin_class = {
fname: NULL,
count: 0,
type : "genmon",
name : "Generic Monitor",
version: "0.1",
description : "Display the output of a program/script into the panel",
constructor : genmon_constructor,
destructor : genmon_destructor,
};
signature.asc
Description: PGP signature

