Added a plug-in for GPRS-specific settings
This commit is contained in:
parent
daaf0a3f9d
commit
8dab5ea1ae
1
Makefile
1
Makefile
@ -78,6 +78,7 @@ dist:
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/blacklist.c \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/debug.c \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/engineering.c \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/gprs.c \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/openmoko.c \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/oss.c \
|
||||
$(PACKAGE)-$(VERSION)/src/plugins/panel.c \
|
||||
|
@ -1,4 +1,4 @@
|
||||
TARGETS = blacklist.so debug.so engineering.so openmoko.so oss.so panel.so profiles.so smscrypt.so
|
||||
TARGETS = blacklist.so debug.so engineering.so gprs.so openmoko.so oss.so panel.so profiles.so smscrypt.so
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
LIBDIR = $(PREFIX)/lib
|
||||
@ -39,6 +39,13 @@ engineering_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
engineering.so: $(engineering_OBJS)
|
||||
$(LD) -o engineering.so $(engineering_OBJS) $(engineering_LDFLAGS)
|
||||
|
||||
gprs_OBJS = gprs.o
|
||||
gprs_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
gprs_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
gprs.so: $(gprs_OBJS)
|
||||
$(LD) -o gprs.so $(gprs_OBJS) $(gprs_LDFLAGS)
|
||||
|
||||
openmoko_OBJS = openmoko.o
|
||||
openmoko_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) `pkg-config --cflags alsa`
|
||||
openmoko_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs alsa`
|
||||
@ -83,6 +90,9 @@ debug.o: debug.c ../../include/Phone.h
|
||||
engineering.o: engineering.c ../../include/Phone.h
|
||||
$(CC) $(engineering_CFLAGS) -c engineering.c
|
||||
|
||||
gprs.o: gprs.c
|
||||
$(CC) $(gprs_CFLAGS) -c gprs.c
|
||||
|
||||
openmoko.o: openmoko.c ../../include/Phone.h
|
||||
$(CC) $(openmoko_CFLAGS) -c openmoko.c
|
||||
|
||||
@ -99,7 +109,7 @@ smscrypt.o: smscrypt.c ../../include/Phone.h
|
||||
$(CC) $(smscrypt_CFLAGS) -c smscrypt.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(blacklist_OBJS) $(debug_OBJS) $(engineering_OBJS) $(openmoko_OBJS) $(oss_OBJS) $(panel_OBJS) $(profiles_OBJS) $(smscrypt_OBJS)
|
||||
$(RM) -- $(blacklist_OBJS) $(debug_OBJS) $(engineering_OBJS) $(gprs_OBJS) $(openmoko_OBJS) $(oss_OBJS) $(panel_OBJS) $(profiles_OBJS) $(smscrypt_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) -- $(TARGETS)
|
||||
@ -112,6 +122,8 @@ install: all
|
||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
||||
$(INSTALL) -m 0644 -- engineering.so $(DESTDIR)$(LIBDIR)/Phone/plugins/engineering.so
|
||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
||||
$(INSTALL) -m 0644 -- gprs.so $(DESTDIR)$(LIBDIR)/Phone/plugins/gprs.so
|
||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
||||
$(INSTALL) -m 0644 -- openmoko.so $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
|
||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
||||
$(INSTALL) -m 0644 -- panel.so $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
|
||||
@ -124,6 +136,7 @@ uninstall:
|
||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/blacklist.so
|
||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/debug.so
|
||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/engineering.so
|
||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/gprs.so
|
||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
|
||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
|
||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so
|
||||
|
207
src/plugins/gprs.c
Normal file
207
src/plugins/gprs.c
Normal file
@ -0,0 +1,207 @@
|
||||
/* $Id$ */
|
||||
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Phone */
|
||||
/* 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 <stdlib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <System.h>
|
||||
#include "Phone.h"
|
||||
|
||||
|
||||
/* GPRS */
|
||||
/* private */
|
||||
/* types */
|
||||
typedef struct _GPRS
|
||||
{
|
||||
GtkWidget * window;
|
||||
GtkWidget * attach;
|
||||
} GPRS;
|
||||
|
||||
|
||||
/* prototypes */
|
||||
/* plugins */
|
||||
static int _gprs_init(PhonePlugin * plugin);
|
||||
static int _gprs_destroy(PhonePlugin * plugin);
|
||||
static int _gprs_event(PhonePlugin * plugin, PhoneEvent event, ...);
|
||||
static void _gprs_settings(PhonePlugin * plugin);
|
||||
|
||||
static int _gprs_attach(PhonePlugin * plugin);
|
||||
|
||||
|
||||
/* public */
|
||||
/* variables */
|
||||
PhonePlugin plugin =
|
||||
{
|
||||
NULL,
|
||||
"GPRS",
|
||||
"network-wireless",
|
||||
_gprs_init,
|
||||
_gprs_destroy,
|
||||
_gprs_event,
|
||||
_gprs_settings,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* gprs_init */
|
||||
static int _gprs_init(PhonePlugin * plugin)
|
||||
{
|
||||
GPRS * gprs;
|
||||
|
||||
if((gprs = object_new(sizeof(*gprs))) == NULL)
|
||||
return 1;
|
||||
plugin->priv = gprs;
|
||||
gprs->window = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* gprs_destroy */
|
||||
static int _gprs_destroy(PhonePlugin * plugin)
|
||||
{
|
||||
GPRS * gprs = plugin->priv;
|
||||
|
||||
if(gprs->window != NULL)
|
||||
gtk_widget_destroy(gprs->window);
|
||||
object_delete(gprs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* gprs_event */
|
||||
static int _gprs_event_functional(PhonePlugin * plugin);
|
||||
|
||||
static int _gprs_event(PhonePlugin * plugin, PhoneEvent event, ...)
|
||||
{
|
||||
switch(event)
|
||||
{
|
||||
case PHONE_EVENT_FUNCTIONAL:
|
||||
return _gprs_event_functional(plugin);
|
||||
default: /* not relevant */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int _gprs_event_functional(PhonePlugin * plugin)
|
||||
{
|
||||
return _gprs_attach(plugin);
|
||||
}
|
||||
|
||||
|
||||
/* gprs_settings */
|
||||
static void _on_settings_cancel(gpointer data);
|
||||
static gboolean _on_settings_closex(gpointer data);
|
||||
static void _on_settings_ok(gpointer data);
|
||||
|
||||
static void _gprs_settings(PhonePlugin * plugin)
|
||||
{
|
||||
GPRS * gprs = plugin->priv;
|
||||
GtkWidget * vbox;
|
||||
GtkWidget * bbox;
|
||||
GtkWidget * widget;
|
||||
|
||||
if(gprs->window != NULL)
|
||||
{
|
||||
gtk_window_present(GTK_WINDOW(gprs->window));
|
||||
return;
|
||||
}
|
||||
gprs->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(gprs->window), 4);
|
||||
gtk_window_set_default_size(GTK_WINDOW(gprs->window), 200, 300);
|
||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||
gtk_window_set_icon_name(GTK_WINDOW(gprs->window), "network-wireless");
|
||||
#endif
|
||||
gtk_window_set_title(GTK_WINDOW(gprs->window), "GPRS preferences");
|
||||
g_signal_connect_swapped(G_OBJECT(gprs->window), "delete-event",
|
||||
G_CALLBACK(_on_settings_closex), plugin);
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
/* check button */
|
||||
gprs->attach = gtk_check_button_new_with_label("Always on");
|
||||
gtk_box_pack_start(GTK_BOX(vbox), gprs->attach, FALSE, TRUE, 0);
|
||||
/* button box */
|
||||
bbox = gtk_hbutton_box_new();
|
||||
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
||||
gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 4);
|
||||
widget = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "clicked", G_CALLBACK(
|
||||
_on_settings_cancel), plugin);
|
||||
gtk_container_add(GTK_CONTAINER(bbox), widget);
|
||||
widget = gtk_button_new_from_stock(GTK_STOCK_OK);
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "clicked", G_CALLBACK(
|
||||
_on_settings_ok), plugin);
|
||||
gtk_container_add(GTK_CONTAINER(bbox), widget);
|
||||
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(gprs->window), vbox);
|
||||
_on_settings_cancel(plugin);
|
||||
gtk_widget_show_all(gprs->window);
|
||||
}
|
||||
|
||||
static void _on_settings_cancel(gpointer data)
|
||||
{
|
||||
PhonePlugin * plugin = data;
|
||||
GPRS * gprs = plugin->priv;
|
||||
char const * p;
|
||||
|
||||
if((p = plugin->helper->config_get(plugin->helper->phone, "gprs",
|
||||
"attach")) != NULL
|
||||
&& strtoul(p, NULL, 10) != 0)
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gprs->attach),
|
||||
TRUE);
|
||||
else
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gprs->attach),
|
||||
FALSE);
|
||||
gtk_widget_hide(gprs->window);
|
||||
}
|
||||
|
||||
static gboolean _on_settings_closex(gpointer data)
|
||||
{
|
||||
PhonePlugin * plugin = data;
|
||||
|
||||
_on_settings_cancel(plugin);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void _on_settings_ok(gpointer data)
|
||||
{
|
||||
PhonePlugin * plugin = data;
|
||||
GPRS * gprs = plugin->priv;
|
||||
gboolean value;
|
||||
|
||||
value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||
gprs->attach));
|
||||
plugin->helper->config_set(plugin->helper->phone, "gprs",
|
||||
"attach", value ? "1" : "0");
|
||||
_gprs_attach(plugin);
|
||||
gtk_widget_hide(gprs->window);
|
||||
}
|
||||
|
||||
|
||||
/* gprs_attach */
|
||||
static int _gprs_attach(PhonePlugin * plugin)
|
||||
{
|
||||
char const * cmd = "AT+CGATT=0";
|
||||
char const * p;
|
||||
|
||||
if((p = plugin->helper->config_get(plugin->helper->phone, "gprs",
|
||||
"attach")) != NULL
|
||||
&& strtoul(p, NULL, 10) != 0)
|
||||
cmd = "AT+CGATT=1";
|
||||
if(plugin->helper->queue(plugin->helper->phone, cmd) != 0)
|
||||
return 1;
|
||||
return plugin->helper->queue(plugin->helper->phone, "AT+CGATT?");
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
targets=blacklist,debug,engineering,openmoko,oss,panel,profiles,smscrypt
|
||||
targets=blacklist,debug,engineering,gprs,openmoko,oss,panel,profiles,smscrypt
|
||||
cppflags_force=-I ../../include
|
||||
cppflags=
|
||||
cflags_force=-W `pkg-config --cflags gtk+-2.0`
|
||||
@ -29,6 +29,11 @@ install=$(LIBDIR)/Phone/plugins
|
||||
[engineering.c]
|
||||
depends=../../include/Phone.h
|
||||
|
||||
[gprs]
|
||||
type=plugin
|
||||
sources=gprs.c
|
||||
install=$(LIBDIR)/Phone/plugins
|
||||
|
||||
[openmoko]
|
||||
type=plugin
|
||||
sources=openmoko.c
|
||||
|
Loading…
Reference in New Issue
Block a user