Added a GSM monitoring applet (very basic, for the Openmoko Freerunner)
This commit is contained in:
parent
065495f703
commit
ee8d9c944f
1
Makefile
1
Makefile
|
@ -37,6 +37,7 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/src/applets/cpufreq.c \
|
||||
$(PACKAGE)-$(VERSION)/src/applets/desktop.c \
|
||||
$(PACKAGE)-$(VERSION)/src/applets/gps.c \
|
||||
$(PACKAGE)-$(VERSION)/src/applets/gsm.c \
|
||||
$(PACKAGE)-$(VERSION)/src/applets/lock.c \
|
||||
$(PACKAGE)-$(VERSION)/src/applets/logout.c \
|
||||
$(PACKAGE)-$(VERSION)/src/applets/main.c \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
TARGETS = battery.so bluetooth.so clock.so cpu.so cpufreq.so desktop.so gps.so lock.so logout.so main.so memory.so pager.so systray.so tasks.so volume.so
|
||||
TARGETS = battery.so bluetooth.so clock.so cpu.so cpufreq.so desktop.so gps.so gsm.so lock.so logout.so main.so memory.so pager.so systray.so tasks.so volume.so
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
LIBDIR = $(PREFIX)/lib
|
||||
|
@ -67,6 +67,13 @@ gps_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
|||
gps.so: $(gps_OBJS)
|
||||
$(LD) -o gps.so $(gps_OBJS)
|
||||
|
||||
gsm_OBJS = gsm.o
|
||||
gsm_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
gsm_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
gsm.so: $(gsm_OBJS)
|
||||
$(LD) -o gsm.so $(gsm_OBJS)
|
||||
|
||||
lock_OBJS = lock.o
|
||||
lock_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
lock_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
@ -144,6 +151,9 @@ desktop.o: desktop.c ../../include/Panel.h
|
|||
gps.o: gps.c ../../include/Panel.h
|
||||
$(CC) $(gps_CFLAGS) -c gps.c
|
||||
|
||||
gsm.o: gsm.c ../../include/Panel.h
|
||||
$(CC) $(gsm_CFLAGS) -c gsm.c
|
||||
|
||||
lock.o: lock.c ../../include/Panel.h
|
||||
$(CC) $(lock_CFLAGS) -c lock.c
|
||||
|
||||
|
@ -169,7 +179,7 @@ volume.o: volume.c ../../include/Panel.h
|
|||
$(CC) $(volume_CFLAGS) -c volume.c
|
||||
|
||||
clean:
|
||||
$(RM) $(battery_OBJS) $(bluetooth_OBJS) $(clock_OBJS) $(cpu_OBJS) $(cpufreq_OBJS) $(desktop_OBJS) $(gps_OBJS) $(lock_OBJS) $(logout_OBJS) $(main_OBJS) $(memory_OBJS) $(pager_OBJS) $(systray_OBJS) $(tasks_OBJS) $(volume_OBJS)
|
||||
$(RM) $(battery_OBJS) $(bluetooth_OBJS) $(clock_OBJS) $(cpu_OBJS) $(cpufreq_OBJS) $(desktop_OBJS) $(gps_OBJS) $(gsm_OBJS) $(lock_OBJS) $(logout_OBJS) $(main_OBJS) $(memory_OBJS) $(pager_OBJS) $(systray_OBJS) $(tasks_OBJS) $(volume_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) $(TARGETS)
|
||||
|
@ -190,6 +200,8 @@ install: all
|
|||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Panel/applets
|
||||
$(INSTALL) -m 0644 gps.so $(DESTDIR)$(LIBDIR)/Panel/applets/gps.so
|
||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Panel/applets
|
||||
$(INSTALL) -m 0644 gsm.so $(DESTDIR)$(LIBDIR)/Panel/applets/gsm.so
|
||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Panel/applets
|
||||
$(INSTALL) -m 0644 lock.so $(DESTDIR)$(LIBDIR)/Panel/applets/lock.so
|
||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Panel/applets
|
||||
$(INSTALL) -m 0644 logout.so $(DESTDIR)$(LIBDIR)/Panel/applets/logout.so
|
||||
|
@ -214,6 +226,7 @@ uninstall:
|
|||
$(RM) $(DESTDIR)$(LIBDIR)/Panel/applets/cpufreq.so
|
||||
$(RM) $(DESTDIR)$(LIBDIR)/Panel/applets/desktop.so
|
||||
$(RM) $(DESTDIR)$(LIBDIR)/Panel/applets/gps.so
|
||||
$(RM) $(DESTDIR)$(LIBDIR)/Panel/applets/gsm.so
|
||||
$(RM) $(DESTDIR)$(LIBDIR)/Panel/applets/lock.so
|
||||
$(RM) $(DESTDIR)$(LIBDIR)/Panel/applets/logout.so
|
||||
$(RM) $(DESTDIR)$(LIBDIR)/Panel/applets/main.so
|
||||
|
|
160
src/applets/gsm.c
Normal file
160
src/applets/gsm.c
Normal file
|
@ -0,0 +1,160 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2010 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/>. */
|
||||
|
||||
|
||||
|
||||
#if defined(__linux__)
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <System.h>
|
||||
#include "Panel.h"
|
||||
|
||||
|
||||
/* GSM */
|
||||
/* private */
|
||||
/* types */
|
||||
typedef struct _GSM
|
||||
{
|
||||
PanelAppletHelper * helper;
|
||||
GtkWidget * image;
|
||||
guint timeout;
|
||||
#if defined(__linux__)
|
||||
int fd;
|
||||
#endif
|
||||
} GSM;
|
||||
|
||||
|
||||
/* prototypes */
|
||||
static GtkWidget * _gsm_init(PanelApplet * applet);
|
||||
static void _gsm_destroy(PanelApplet * applet);
|
||||
|
||||
static gboolean _gsm_get(GSM * gsm);
|
||||
static void _gsm_set(GSM * gsm, gboolean on);
|
||||
|
||||
/* callbacks */
|
||||
static gboolean _on_timeout(gpointer data);
|
||||
|
||||
|
||||
/* public */
|
||||
/* variables */
|
||||
PanelApplet applet =
|
||||
{
|
||||
NULL,
|
||||
_gsm_init,
|
||||
_gsm_destroy,
|
||||
PANEL_APPLET_POSITION_END,
|
||||
FALSE,
|
||||
TRUE,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* gsm_init */
|
||||
static GtkWidget * _gsm_init(PanelApplet * applet)
|
||||
{
|
||||
GSM * gsm;
|
||||
|
||||
if((gsm = malloc(sizeof(*gsm))) == NULL)
|
||||
return NULL;
|
||||
applet->priv = gsm;
|
||||
gsm->helper = applet->helper;
|
||||
gsm->timeout = 0;
|
||||
#if defined(__linux__)
|
||||
gsm->fd = -1;
|
||||
#endif
|
||||
/* XXX find a better image */
|
||||
gsm->image = gtk_image_new_from_icon_name("network-wireless",
|
||||
applet->helper->icon_size);
|
||||
gsm->timeout = g_timeout_add(1000, _on_timeout, gsm);
|
||||
_on_timeout(gsm);
|
||||
return gsm->image;
|
||||
}
|
||||
|
||||
|
||||
/* gsm_destroy */
|
||||
static void _gsm_destroy(PanelApplet * applet)
|
||||
{
|
||||
GSM * gsm = applet->priv;
|
||||
|
||||
if(gsm->timeout > 0)
|
||||
g_source_remove(gsm->timeout);
|
||||
#if defined(__linux__)
|
||||
if(gsm->fd != -1)
|
||||
close(gsm->fd);
|
||||
#endif
|
||||
free(gsm);
|
||||
}
|
||||
|
||||
|
||||
/* gsm_set */
|
||||
static void _gsm_set(GSM * gsm, gboolean on)
|
||||
{
|
||||
if(on == TRUE)
|
||||
gtk_widget_show(gsm->image);
|
||||
else
|
||||
gtk_widget_hide(gsm->image);
|
||||
}
|
||||
|
||||
|
||||
/* callbacks */
|
||||
/* on_timeout */
|
||||
#if defined(__linux__)
|
||||
static gboolean _gsm_get(GSM * gsm)
|
||||
{
|
||||
/* XXX currently hard-coded for the Openmoko Freerunner */
|
||||
const char dev[] = "/sys/bus/platform/devices/neo1973-pm-gsm.0/"
|
||||
"power_on";
|
||||
char on;
|
||||
|
||||
if(gsm->fd == -1 && (gsm->fd = open(dev, O_RDONLY)) == -1)
|
||||
{
|
||||
error_set("%s: %s", dev, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
errno = ENODATA; /* in case the pseudo-file is empty */
|
||||
if(lseek(gsm->fd, 0, SEEK_SET) != 0
|
||||
|| read(gsm->fd, &on, sizeof(on)) != 1)
|
||||
{
|
||||
error_set("%s: %s", dev, strerror(errno));
|
||||
close(gsm->fd);
|
||||
gsm->fd = -1;
|
||||
return FALSE;
|
||||
}
|
||||
return (on == '1') ? TRUE : FALSE;
|
||||
}
|
||||
#else
|
||||
static gboolean _gsm_get(GSM * gsm)
|
||||
{
|
||||
/* FIXME not supported */
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* callbacks */
|
||||
/* on_timeout */
|
||||
static gboolean _on_timeout(gpointer data)
|
||||
{
|
||||
GSM * gsm = data;
|
||||
|
||||
_gsm_set(gsm, _gsm_get(gsm));
|
||||
return TRUE;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
targets=battery,bluetooth,clock,cpu,cpufreq,desktop,gps,lock,logout,main,memory,pager,systray,tasks,volume
|
||||
targets=battery,bluetooth,clock,cpu,cpufreq,desktop,gps,gsm,lock,logout,main,memory,pager,systray,tasks,volume
|
||||
cppflags_force=-I $(PREFIX)/include -I ../../include
|
||||
#cppflags=-D EMBEDDED
|
||||
cflags_force=-W `pkg-config --cflags gtk+-2.0` -fPIC
|
||||
|
@ -61,6 +61,14 @@ install=$(LIBDIR)/Panel/applets
|
|||
[gps.c]
|
||||
depends=../../include/Panel.h
|
||||
|
||||
[gsm]
|
||||
type=plugin
|
||||
sources=gsm.c
|
||||
install=$(LIBDIR)/Panel/applets
|
||||
|
||||
[gsm.c]
|
||||
depends=../../include/Panel.h
|
||||
|
||||
[lock]
|
||||
type=plugin
|
||||
sources=lock.c
|
||||
|
|
|
@ -151,11 +151,12 @@ static gboolean _on_idle(gpointer data)
|
|||
/* FIXME load all plugins, a configuration file or ask the user */
|
||||
#ifndef EMBEDDED
|
||||
const char * plugins[] = { "volume", "systray", "battery", "bluetooth",
|
||||
"clock", "memory", "cpufreq", "cpu", "desktop", "gps", "lock",
|
||||
"logout", "main", "pager", "tasks", NULL };
|
||||
"clock", "memory", "cpufreq", "cpu", "desktop", "gps", "gsm",
|
||||
"lock", "logout", "main", "pager", "tasks", NULL };
|
||||
#else
|
||||
const char * plugins[] = { "volume", "systray", "battery", "bluetooth",
|
||||
"clock", "cpufreq", "desktop", "gps", "main", "tasks", NULL };
|
||||
"clock", "cpufreq", "desktop", "gps", "gsm", "main", "tasks",
|
||||
NULL };
|
||||
#endif
|
||||
size_t i;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user