From 472cda462a0c827bb0942fb9275690ecde18f22a Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Tue, 27 Jul 2010 22:21:08 +0200 Subject: [PATCH] Added header guard to device.h, wrote typedef in a cleaner way Added basic status menu plugin for enabling/disabling USB net (incomplete) --- .gitignore | 1 + Makefile | 24 ++++++++++---- device.h | 16 +++++++--- mtetherd-plugin.desktop | 6 ++++ status.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ status.h | 53 +++++++++++++++++++++++++++++++ 6 files changed, 168 insertions(+), 11 deletions(-) create mode 100644 mtetherd-plugin.desktop create mode 100644 status.c create mode 100644 status.h diff --git a/.gitignore b/.gitignore index e87a6c7..296a23d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o +*.so mtetherd diff --git a/Makefile b/Makefile index fa9330f..b2d6d0a 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,39 @@ +PREFIX = /usr CC = gcc CFLAGS = -Wall -O2 -g -D_GNU_SOURCE -INCLUDES = $(shell pkg-config dbus-1 --cflags) +INCLUDES = $(shell pkg-config --cflags dbus-1 libhildondesktop-1) LDFLAGS = -LIBS = $(shell pkg-config dbus-1 --libs) -PREFIX = /usr +LIBS_DBUS = $(shell pkg-config --libs dbus-1) +LIBS_HILDON = $(shell pkg-config --libs libhildondesktop-1) +HILDON_DESKTOP = $(shell pkg-config --variable=hildonstatusmenudesktopentrydir libhildondesktop-1) +HILDON_PLUGIN = $(shell pkg-config --variable=hildondesktoplibdir libhildondesktop-1) + +all: mtetherd mtetherd-plugin.so mtetherd: mtetherd.o device.o - $(CC) $(LDFLAGS) $(LIBS) -o $@ $^ + $(CC) $(LDFLAGS) $(LIBS_DBUS) -o $@ $^ + +mtetherd-plugin.so: status.o + $(CC) $(LDFLAGS) $(LIBS_HILDON) -shared -o $@ $^ %PHONY: clean install uninstall clean: - rm -f *.o mtetherd + rm -f *.o mtetherd mtetherd-plugin.so -install: mtetherd +install: mtetherd mtetherd-plugin.so install -m 755 -D mtetherd $(DESTDIR)/$(PREFIX)/sbin/mtetherd install -m 644 -D event.d-mtetherd $(DESTDIR)/etc/event.d/mtetherd install -m 644 -D README $(DESTDIR)/$(PREFIX)/share/doc/mtetherd/README + install -m 644 -D mtetherd-plugin.desktop $(DESTDIR)/$(HILDON_DESKTOP)/mtetherd-plugin.desktop + install -m 755 -D mtetherd-plugin.so $(DESTDIR)/$(HILDON_PLUGIN)/mtetherd-plugin.so uninstall: rm -f $(DESTDIR)/$(PREFIX)/sbin/mtetherd rm -f $(DESTDIR)/etc/event.d/mtetherd rm -rf $(DESTDIR)/$(PREFIX)/share/doc/mtetherd + rm -f $(DESTDIR)/$(HILDON_DESKTOP)/mtetherd-plugin.desktop + rm -f $(DESTDIR)/$(HILDON_PLUGIN)/mtetherd-plugin.so %.o: %.c $(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $^ diff --git a/device.h b/device.h index fe8c55c..b21cd3e 100644 --- a/device.h +++ b/device.h @@ -18,16 +18,19 @@ along with this program. If not, see . */ -struct Device; +#ifndef _MTETHERD_DEVICE_H +#define _MTETHERD_DEVICE_H -typedef struct Device { +typedef struct _Device Device; + +struct _Device { char *name; char *address; char *startaddress; char *endaddress; - struct Device *previous; - struct Device *next; -} Device; + Device *previous; + Device *next; +}; // Allocates memory for a device structure and copies the name Device *device_new(const char *name); @@ -60,3 +63,6 @@ int device_validate(Device *device); // Searches for a device name, starting from start and returns a pointer // to the matching node, or NULL if no name matches Device *device_search(Device *start, const char *name); + +#endif //_MTETHERD_DEVICE_H + diff --git a/mtetherd-plugin.desktop b/mtetherd-plugin.desktop new file mode 100644 index 0000000..3393567 --- /dev/null +++ b/mtetherd-plugin.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name=MTetherD USB Enabler +Comment=Maemo Tethering Daemon USB networking enabler +Category=permanent +Type=default +X-Path=mtetherd-plugin.so diff --git a/status.c b/status.c new file mode 100644 index 0000000..52efb5e --- /dev/null +++ b/status.c @@ -0,0 +1,79 @@ +/* + mtetherd + (c) 2010 Gregor Riepl + + Tethering utility for Maemo + + 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, either version 3 of the License, or + (at your option) any later version. + + 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 . +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "status.h" + +#define MTETHERD_STATUS_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, TYPE_MTETHERD_STATUS_PLUGIN, MTetherDStatusPluginPrivate)) + +struct _MTetherDStatusPluginPrivate { + GtkWidget *button; + gboolean neton; +}; + +HD_DEFINE_PLUGIN_MODULE(MTetherDStatusPlugin, mtetherd_status_plugin, HD_TYPE_STATUS_MENU_ITEM); + +static void mtetherd_status_plugin_class_finalize(MTetherDStatusPluginClass *klass) { } + +static void mtetherd_status_plugin_class_init(MTetherDStatusPluginClass *klass) { + g_type_class_add_private(klass, sizeof(MTetherDStatusPluginPrivate)); +} + +static void set_button_text(GtkWidget *button, gboolean enabled) { + if (enabled) { + gtk_button_set_label(GTK_BUTTON(button), "Disable USB Networking"); + } else { + gtk_button_set_label(GTK_BUTTON(button), "Enable USB Networking"); + } +} + +static void enable_usb_net_clicked(GtkWidget *button, gpointer user) { + MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(user); + + if (button == plugin->priv->button) { + plugin->priv->neton = !plugin->priv->neton; + set_button_text(plugin->priv->button, plugin->priv->neton); + if (plugin->priv->neton) { + // enable + } else { + // disable + } + } +} + +static void mtetherd_status_plugin_init(MTetherDStatusPlugin *plugin) { + plugin->priv = MTETHERD_STATUS_PLUGIN_GET_PRIVATE(plugin); + + plugin->priv->neton = FALSE; + plugin->priv->button = gtk_button_new(); + set_button_text(plugin->priv->button, plugin->priv->neton); + g_signal_connect(plugin->priv->button, "clicked", G_CALLBACK(enable_usb_net_clicked), plugin); + gtk_container_add(GTK_CONTAINER(plugin), plugin->priv->button); + gtk_widget_show_all(plugin->priv->button); + gtk_widget_show(GTK_WIDGET(plugin)); +} + diff --git a/status.h b/status.h new file mode 100644 index 0000000..3cdae45 --- /dev/null +++ b/status.h @@ -0,0 +1,53 @@ +/* + mtetherd + (c) 2010 Gregor Riepl + + Tethering utility for Maemo + + 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, either version 3 of the License, or + (at your option) any later version. + + 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 . +*/ + +#ifndef _MTETHERD_STATUS_H +#define _MTETHERD_STATUS_H + +#include + +G_BEGIN_DECLS + +#define TYPE_MTETHERD_STATUS_PLUGIN (mtetherd_status_plugin_get_type()) +#define MTETHERD_STATUS_PLUGIN(object) (G_TYPE_CHECK_INSTANCE_CAST((object), TYPE_MTETHERD_STATUS_PLUGIN, MTetherDStatusPlugin)) +#define MTETHERD_STATUS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_MTETHERD_STATUS_PLUGIN, MTetherDStatusPluginClass)) +#define IS_MTETHERD_STATUS_PLUGIN(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), TYPE_MTETHERD_STATUS_PLUGIN)) +#define IS_MTETHERD_STATUS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_MTETHERD_STATUS_PLUGIN)) +#define MTETHERD_STATUS_PLUGIN_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), TYPE_MTETHERD_STATUS_PLUGIN, MTetherDStatusPluginClass)) + +typedef struct _MTetherDStatusPluginClass MTetherDStatusPluginClass; +typedef struct _MTetherDStatusPlugin MTetherDStatusPlugin; +typedef struct _MTetherDStatusPluginPrivate MTetherDStatusPluginPrivate; + +struct _MTetherDStatusPluginClass { + HDStatusMenuItemClass parent; +}; + +struct _MTetherDStatusPlugin { + HDStatusMenuItem parent; + MTetherDStatusPluginPrivate *priv; +}; + +GType mtetherd_status_plugin_get_type(); + +G_END_DECLS + +#endif //_MTETHERD_STATUS_H + -- 1.7.9.5