52efb5e0b6fc2ea035dcc556efee9b5dd22dafac
[mtetherd] / status.c
1 /*
2   mtetherd
3   (c) 2010 Gregor Riepl <onitake@gmail.com>
4   
5   Tethering utility for Maemo
6   
7   This program is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11   
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16   
17   You should have received a copy of the GNU General Public License
18   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <pwd.h>
25 #include <sys/types.h>
26 #include <gtk/gtk.h>
27 #include <hildon/hildon.h>
28
29 #include "status.h"
30
31 #define MTETHERD_STATUS_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, TYPE_MTETHERD_STATUS_PLUGIN, MTetherDStatusPluginPrivate))
32
33 struct _MTetherDStatusPluginPrivate {
34         GtkWidget *button;
35         gboolean neton;
36 };
37
38 HD_DEFINE_PLUGIN_MODULE(MTetherDStatusPlugin, mtetherd_status_plugin, HD_TYPE_STATUS_MENU_ITEM);
39
40 static void mtetherd_status_plugin_class_finalize(MTetherDStatusPluginClass *klass) { }
41
42 static void mtetherd_status_plugin_class_init(MTetherDStatusPluginClass *klass) {
43         g_type_class_add_private(klass, sizeof(MTetherDStatusPluginPrivate));
44 }
45
46 static void set_button_text(GtkWidget *button, gboolean enabled) {
47         if (enabled) {
48                 gtk_button_set_label(GTK_BUTTON(button), "Disable USB Networking");
49         } else {
50                 gtk_button_set_label(GTK_BUTTON(button), "Enable USB Networking");
51         }
52 }
53
54 static void enable_usb_net_clicked(GtkWidget *button, gpointer user) {
55         MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(user);
56
57         if (button == plugin->priv->button) {
58                 plugin->priv->neton = !plugin->priv->neton;
59                 set_button_text(plugin->priv->button, plugin->priv->neton);
60                 if (plugin->priv->neton) {
61                         // enable
62                 } else {
63                         // disable
64                 }
65         }
66 }
67
68 static void mtetherd_status_plugin_init(MTetherDStatusPlugin *plugin) {
69         plugin->priv = MTETHERD_STATUS_PLUGIN_GET_PRIVATE(plugin);
70
71         plugin->priv->neton = FALSE;
72         plugin->priv->button = gtk_button_new();
73         set_button_text(plugin->priv->button, plugin->priv->neton);
74         g_signal_connect(plugin->priv->button, "clicked", G_CALLBACK(enable_usb_net_clicked), plugin);
75         gtk_container_add(GTK_CONTAINER(plugin), plugin->priv->button);
76         gtk_widget_show_all(plugin->priv->button);
77         gtk_widget_show(GTK_WIDGET(plugin));
78 }
79